first commit

This commit is contained in:
/usr/bin/nano
2017-04-15 01:34:36 +03:00
commit c715e2a604
5325 changed files with 329700 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
<?php
// Required: anonymous function reference number as explained above.
$funcNum = $_GET['CKEditorFuncNum'] ;
// Optional: instance name (might be used to load a specific configuration file or anything else).
$CKEditor = $_GET['CKEditor'] ;
// Optional: might be used to provide localized messages.
$langCode = $_GET['langCode'] ;
// Check the $_FILES array and save the file. Assign the correct path to a variable ($url).
$url = '';
// Usually you will only assign something here if the file could not be uploaded.
$message = '';
//xmp($_FILES); exit(0);
if (isset($_FILES) && isset($_FILES['upload']) && isset($_FILES['upload']['tmp_name']))
{
$err = true;
if (is_uploaded_file(realpath($_FILES['upload']["tmp_name"])))
{
$e = explode(".", $_FILES['upload']['name']);
$end = end($e);
$ext = strtolower($end);
$string = md5(uniqid(mt_rand())) . "." . $ext;
$subdir = "upl/ckeditor4_files/";
FileSys::MakeDir(BASEPATH . $subdir);
$path = BASEPATH . $subdir . $string;
$link = Root($subdir . $string);
$allowedTypes = array('bmp', 'gif', 'jpeg', 'jpe', 'jpg', 'png', 'tiff');
if (!in_array($ext, $allowedTypes))
{
$message = "Invalid file type";
}
else
{
move_uploaded_file($_FILES['upload']["tmp_name"], $path);
if (is_file($path))
{
$url = $link;
$err = false;
// Уменьшаем размер файла путем ресайза картинки
$wImg = WideImage::load($path);
if ($wImg->getWidth() > $g_config['ckeditor4']['resize_down_width'] ||
$wImg->getHeight() > $g_config['ckeditor4']['resize_down_height']) // Если просто делать resizeDown то gif пересохранится и у него пропадет анимация
{
$wImg->resizeDown($g_config['ckeditor4']['resize_down_width'],
$g_config['ckeditor4']['resize_down_height'])->saveToFile($path);
}
}
}
}
if ($err)
{
$message = "Cant upload file " . (isset($_FILES['upload']['error']) ? ("(Error: " . $_FILES['upload']['error'] . ")") : "");
}
}
echo "<script type='text/javascript'>" . (empty($message) ? "" : ("alert('" . $message . "'); ")) . "window.parent.CKEDITOR.tools.callFunction($funcNum, '$url', '$message');</script>";
exit(0);
?>

44
src/admin/login.php Executable file
View File

@@ -0,0 +1,44 @@
<?php
$admin = new AdminModel(NULL, true);
// Если человек уже залогинен, то редиректим его с этой страницы
if ($admin->IsAuth())
{
header("Location: " . SiteRoot($g_config['admin_sector']['after_login_page']));
exit();
}
$msg = '';
if (Post('is_login'))
{
$login = Post('login');
$pwd = Post('pwd');
$errs = array();
if (empty($login))
{
$errs[] = "Впишите логин";
}
if (empty($pwd))
{
$errs[] = "Впишите пароль";
}
if (!count($errs))
{
$isLogin = $admin->Login($login, $admin->MakeHash($pwd));
if ($isLogin)
{
header("Location: " . SiteRoot($g_config['admin_sector']['after_login_page']));
exit();
}
else
{
$errs[] = "Неверный логин или пароль";
}
}
$msg = MsgErr(implode('<br>', $errs));
}
?>

8
src/admin/logout.php Executable file
View File

@@ -0,0 +1,8 @@
<?php
$admin = new AdminModel(NULL, true);
$admin->Logout();
header("Location: " . SiteRoot($g_config['admin_sector']['after_logout_page']));
exit();
?>

22
src/admin/main_tpl.php Executable file
View File

@@ -0,0 +1,22 @@
<?php
if (!IS_ADMIN_AUTH)
{
$g_config['admin_menu'] = array();
$g_config['admin_menu'][] = array
(
'link' => SiteRoot('admin/login'),
'name' => 'Вход',
'label' => 'Войти в административный раздел',
'css' => '',
'list' => array()
);
}
$menu = $g_config['admin_menu'];
$logo = array
(
'href' => SiteRoot('admin'),
'logo' => '<span class="glyphicon glyphicon-home"></span>'
);
?>

90
src/admin/page_editor.php Executable file
View File

@@ -0,0 +1,90 @@
<?php
global $g_arrLangs;
$flashParam = new FlashParam();
$msg = $flashParam->Get('msg');
$removePage = trim(Post("remove_page"));
if ($removePage)
{
//if (!is_file(BASEPATH . "src/" . $removePage . ".php") &&
// !is_file(BASEPATH . "tpl/" . $removePage . ".php"))
//{
// $msg = MsgErr("Страница '{$removePage}' не существует.");
//}
//else
//{
$removedCount = 0;
if (is_file(BASEPATH . "src/" . $removePage . ".php"))
{
unlink(BASEPATH . "src/" . $removePage . ".php");
$removedCount++;
}
if (is_file(BASEPATH . "tpl/" . $removePage . ".php"))
{
unlink(BASEPATH . "tpl/" . $removePage . ".php");
$removedCount++;
}
foreach ($g_arrLangs as $lang => $v)
{
if (is_file(BASEPATH . "lang/{$lang}/" . $removePage . ".php"))
{
unlink(BASEPATH . "lang/{$lang}/" . $removePage . ".php");
$removedCount++;
}
}
$msg = $removedCount == 0 ?
MsgErr("Не удалось удалить страницу '{$removePage}'.") :
MsgOk("Страница '{$removePage}' была удалена (всего {$removedCount} файлов).");
$_POST = array();
//}
}
$all = array();
// Считываем все возможные файлы для всех языков
foreach ($g_arrLangs as $lang => $v)
{
$list = array();
PageEditorGetListFilesDirs(BASEPATH . "lang/" . $lang, $list);
// В $list у нас массив вида:
// Array
// (
// [0] => Z:/home/zcomp.page_editor/www/lang/en/404.php
// [1] => Z:/home/zcomp.page_editor/www/lang/en/autoload/
// [2] => Z:/home/zcomp.page_editor/www/lang/en/autoload/main.php
// )
foreach ($list as $l)
{
// Превращаем 'Z:/home/zcomp.page_editor/www/lang/en/autoload/main.php' в 'autoload/main.php'
$l = str_replace(BASEPATH . "lang/" . $lang . "/", "", $l);
foreach ($g_config['page_editor']['exceptions'] as $e)
{
if (strpos($l, $e) === 0)
{
continue 2;
}
}
if (empty($all[$l]))
{
$all[$l] = array();
}
$all[$l][] = $lang;
}
}
ksort($all);
// Теперь в $all у нас есть асоциативный массив вида:
// dev/
// en
// ru
// dev/404.php:
// en
// ru
// default.php:
// ru
?>

60
src/admin/page_editor_add.php Executable file
View File

@@ -0,0 +1,60 @@
<?php
global $g_arrLangs;
$flashParam = new FlashParam();
$msg = $flashParam->Get('msg');
// Добавление страницы
if (Post("is_add_page"))
{
$newPage = trim(Post("name"));
if (empty($newPage) || $newPage != preg_replace("~[^a-z0-9_]~", '', $newPage))
{
$msg = MsgErr("Некорректные символы");
}
else if (is_readable(BASEPATH . "src/{$newPage}.php") ||
is_readable(BASEPATH . "tpl/{$newPage}.php") ||
is_readable(BASEPATH . "lang/" . DEF_LANG . "/{$newPage}.php"))
{
$msg = MsgErr("Файл уже существует");
}
else
{
$path1 = BASEPATH . "tpl/{$newPage}.php";
$text = "";
$text .= "\n <h1><?= L('head_no_tags')?></h1>";
$text .= "\n <p><?= L('text')?></p>\n";
FileSys::MakeDir(dirname($path1)); // На всякий случай
$isWrite1 = FileSys::WriteFile($path1, $text, false);
//**
$path2 = BASEPATH . "lang/" . DEF_LANG . "/{$newPage}.php";
$text = "";
$text .= "<?php\n\n";
$text .= " $" . "g_lang['head_no_tags'] = 'Страница наполняется';\n";
$text .= " $" . "g_lang['text'] = '<p>Извините, но страница находится в стадии наполнения. Приносим свои изменения.</p>';\n";
$text .= "?>";
FileSys::MakeDir(dirname($path2)); // На всякий случай
$isWrite2 = FileSys::WriteFile($path2, $text, false);
if (!$isWrite1 || !$isWrite2 || !is_readable($path1) || !is_readable($path2))
{
$flashParam->Set('msg', MsgErr("Неизвестная ошибка"));
@unlink($path1);
@unlink($path2);
}
else
{
$flashParam->Set('msg', MsgOk("Страница '{$newPage}' успешно создана"));
Header("Location: " . SiteRoot("admin/page_editor"));
exit(0);
}
}
}
?>

109
src/admin/page_editor_page.php Executable file
View File

@@ -0,0 +1,109 @@
<?php
global $g_arrLangs;
$lang = Get('lang');
$file = Get('page');
$flashParam = new FlashParam();
$msg = $flashParam->Get('msg');
$showSEO = true;
if (strpos($file, "autoload/") === 0 && $file !== "autoload/main.php")
{
$showSEO = false;
}
foreach ($g_config['page_editor']['seo_exceptions'] as $e)
{
if (strpos($file, $e) === 0)
{
$showSEO = false;
break;
}
}
$seoVars = array("m_title", "m_keyWords", "m_description");
$srcPath = BASEPATH . "lang/{$lang}/{$file}";
if (!is_readable($srcPath))
{
trigger_error("File {$srcPath} not found.", E_USER_ERROR);
}
$t = $g_lang;
$g_lang = array();
require $srcPath;
$curLang = $g_lang;
$g_lang = $t;
if (Post('___is_apply'))
{
$prefix = "<?php\r\n\r\n";
$postfix = "\r\n?>";
$lines = array();
foreach ($curLang as $k => $v)
{
if (!in_array($k, $seoVars))
{
$v = $_POST[$k];
//$v = addslashes($v); Нельзя применить потому что добавит слеш и к ' и к " а считываться это будет неверно
$v = str_replace("\"", "\\\"", $v);
$v = str_replace("\r", '', $v);
$v = str_replace("\n", '\n', $v);
$lines[] = ' $g_lang["' . $k . '"] = "' . $v . '";';
}
}
if ($showSEO)
{
$lines[] = ''; // Вставляем пустую строку
foreach ($seoVars as $s)
{
if (strlen(Post($s)))
{
$lines[] = ' $g_lang["' . $s . '"] = "' . Post($s) . '";';
}
else if ($file == "autoload/main.php") // Если SEO переменная пустая, то пишем её только для autoload/main.php
{
$lines[] = ' $g_lang["' . $s . '"] = "";';
}
}
}
$text = $prefix . implode("\r\n", $lines) . $postfix;
$l2 = Post("___lang", $lang);
$savePath = BASEPATH . "lang/{$l2}/{$file}";
// Если нужно делать backup-ы изменений то сохраняем их
if (is_readable($srcPath) && $g_config['page_editor']['with_backup'])
{
$fileTo = BASEPATH . "lang/backup/{$lang}/{$file}";
$fileTo = str_replace(".php", "." . time() . ".php", $fileTo);
FileSys::MakeDir(dirname($fileTo));
copy($srcPath, $fileTo);
}
FileSys::MakeDir(dirname($savePath));
$isWrite = FileSys::WriteFile($savePath, $text, false);
$msg = $isWrite ? MsgOk("Файл {$file} успешно сохранен на языке " . $g_arrLangs[$l2]["name"]) : MsgErr("Ошибка сохранения файла");
if ($isWrite)
{
$flashParam->Set('msg', $msg);
if (Post("___no_return") != "1")
{
Header("Location: " . SiteRoot("admin/page_editor"));
}
else
{
Header("Location: " . GetCurUrl("lang={$l2}"));
}
exit(0);
}
$msg = MsgErr("Неизвестная ошибка сохранения");
}
?>

View File

@@ -0,0 +1,84 @@
<?php
include ("cgi-bin/saveGraphHelpers.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$examplesFilename = $g_config['graphSavePath'] . $g_config['graphExamplesFile'];
if (isset($_POST["source_id"]))
{
$sourceFileFullname = getXMLFileName($_POST["source_id"], true);
if (strlen($sourceFileFullname) > 0)
{
$graph = gzuncompress(file_get_contents($sourceFileFullname));
if (strlen($graph) > 0)
{
if (saveGraphXML($graph, $_POST["dest_id"], true))
{
$imageSource = getImageFileName($_POST["image"], true);
$imageDest = getImageFileName($_POST["dest_id"], true);
if ( copy($imageSource, $imageDest))
{
if (($handle = fopen($examplesFilename, "a")) !== FALSE)
{
$line = array();
$line[] = $_POST["dest_id"];
$line[] = $_POST["title_ru"];
$line[] = $_POST["title_en"];
fputcsv($handle, $line, "|");
fclose($handle);
$msg = "added";
}
else
{
$msg = "Cannot open data base";
}
}
else
{
$msg = "Cannot copy image";
}
}
else
{
$msg = "Cannot save dest file";
}
}
else
{
$msg = "Cannot open source file";
}
}
else
{
$msg = "Wrong source name";
}
}
$examples = array();
// Load from cvs
if (($handle = fopen($examplesFilename, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, "|")) !== FALSE)
{
$item = array();
$item["id"] = $data[0];
$item["title_ru"] = $data[1];
$item["title_en"] = $data[2];
$examples[] = $item;
}
fclose($handle);
}
?>

View File

@@ -0,0 +1,53 @@
<?php
function glob_recursive($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir)
{
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
function processFiles($mask, &$countFiles, &$sizeFiles, &$ageCount, $ageCallback)
{
// Process graph project files.
$files = glob_recursive($mask);
$countFiles = count($files);
foreach ($files as $file)
{
$sizeFiles += filesize($file) / 1024;
$fileAgeInMonth = (time() - filemtime($file)) / (3600 * 24 * 30);
if ($ageCallback($fileAgeInMonth))
{
$ageCount = $ageCount + 1;
}
}
}
$ageCallback = function($age)
{
return $age <= 6;
};
$graphTimes = array();
$totalGraphCount = 0;
$totalGraphSize = 0; // In Kb
$ageGraph = 0;
$totalImages = 0;
$totalImagesSize = 0; // In Kb
$ageImage = 0;
processFiles($g_config['graphSavePath'] . "*.xml", $totalGraphCount, $totalGraphSize, $ageGraph, $ageCallback);
processFiles($g_config['graphSavePath'] . "*.png", $totalImages, $totalImagesSize, $ageImage, $ageCallback);
$totalGraphSize = intval($totalGraphSize);
$totalImagesSize = intval($totalImagesSize);
?>