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

4
src/404.php Executable file
View File

@@ -0,0 +1,4 @@
<?php
header(Php::Status(404));
?>

11
src/500.php Executable file
View File

@@ -0,0 +1,11 @@
<?php
header(Php::Status(500));
ob_start();
IncludeCom('_500');
$content = ob_get_clean();
echo $content;
exit;
?>

5
src/admin.php Executable file
View File

@@ -0,0 +1,5 @@
<?php
header("Location: " . SiteRoot('admin/login'));
exit();
?>

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);
?>

5
src/dev/ckeditor4.php Executable file
View File

@@ -0,0 +1,5 @@
<?php
$mode = empty($mode) ? "full" : $mode;
$value = empty($value) ? "" : $value;
?>

18
src/dev/ckeditor4_head.php Executable file
View File

@@ -0,0 +1,18 @@
<?php
$contentCss = NULL;
if ($g_config['extrapacker']['packCss'] && $g_config['extrapacker']['dir'])
{
// Если мы в админке, то директория может быть переопределена, но изначальная должна быть сохранена в $g_config['extrapacker']['non_admin_dir']
$dir = isset($g_config['extrapacker']['non_admin_dir']) ? $g_config['extrapacker']['non_admin_dir'] : $g_config['extrapacker']['dir'];
$path = "tmp/{$dir}/css/";
$files = glob(BASEPATH . $path . "*.css");
if (count($files) > 0)
{
sort($files);
$file = end($files);
$contentCss = "/" . $path . basename($file);
}
}
?>

4
src/dev/debug_panel.php Executable file
View File

@@ -0,0 +1,4 @@
<?php
$debug = new DebugPanel();
?>

9
src/dev/richtext.php Executable file
View File

@@ -0,0 +1,9 @@
<?php
IncludeCom("dev/ckeditor4", array
(
"name" => empty($name) ? NULL : $name,
"value" => empty($value) ? NULL : $value,
"mode" => empty($mode) ? NULL : $mode
));
?>

13
src/donate.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
$totalDonate = trim(file_get_contents($g_config['donateTotal']));
$lines = file($g_config['donateTransactions']);
$donates = 0;
$lastDonate = 0;
foreach ($lines as $line)
{
$donates = $donates + $line;
$lastDonate = $line;
}
?>

57
src/feedback.php Executable file
View File

@@ -0,0 +1,57 @@
<?
/*
Sample page
*/
print_r ($_POST);
$dateFile = "./tmp/dateFeedback.txt";
$mymail = "soft_support@list.ru";
$fh = fopen($dateFile, "r");
$lastTime = 0;
$lastTime = fread($fh, filesize($dateFile));
fclose($fh);
$secondsForPost = 5;
$error = "";
$accept = "";
if (time() - $lastTime > $secondsForPost)
{
$text = $_POST['message'];
$name = $_POST['name'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
$headers .= "From: support@freeanalogs.ru \r\n";
if (mail($mymail, "Graph feedback", $text . "\n\n" . $name, $headers))
{
$accept = "Ваше предложение отправлено модераторам.<br>";
}
else
{
$error = "Неопределенная ошибка. Свяжитесь с администратором по адресу soft_support@list.ru<br>";
}
$fh = fopen($dateFile, "w");
fwrite($fh, time());
fclose($fh);
$STitle = "";
$softDetail = "";
$webSite = "";
$TTitle = "";
}
else
{
echo (3);
$error = "Сервер перегружен, повторите попытку через 30 секунд.<br>";
}
echo ($error);
echo ($accept);
?>

21
src/graphs_examples.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
$examples = array();
// Load from cvs
$examplesFilename = $g_config['graphSavePath'] . $g_config['graphExamplesFile'];
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];
$g_lang["m_keyWords"] .= ", " . $item["title_" . $g_lang["current_language"]];
$examples[] = $item;
}
fclose($handle);
}
?>

38
src/home.php Executable file
View File

@@ -0,0 +1,38 @@
<?php
include ("./src/donate.php");
$graphName = "";
if (isset($_GET["graph"]))
{
$graphId = $_GET["graph"];
$graphSampleListFile = $g_config['graphSavePath'] . $g_config['graphExamplesFile'];
$graphSampleList = array();
$cvsFile = fopen($graphSampleListFile, "r");
if ($cvsFile)
{
while (($data = fgetcsv($cvsFile, 1000, "|")) !== FALSE)
{
if ($graphId == $data[0])
{
$graphName = ($g_lang["current_language"] == "en") ? $data[2] : $data[1];
break;
}
}
fclose($cvsFile);
}
}
if (strlen($graphName) > 0)
{
$g_lang["m_title"] = $graphName;
$g_lang["m_keyWords"] = $graphName . ", " . $g_lang["m_keyWords"];
$g_lang["m_description"] = $g_lang["title_notg"] . ": " . $graphName;
}
?>

67
src/main_tpl.php Executable file
View File

@@ -0,0 +1,67 @@
<?php
AutoTDKW($content);
$title = L('m_title');
$description = L('m_description');
$keyWords = L('m_keyWords');
$menu = array();
$menu[] = array
(
"title" => L("menu_0"),
"link" => SiteRoot(),
);
$menu[] = array
(
"title" => L("menu_1"),
"link" => "",
"list" => array(
array(
"title" => L("menu_4"),
"link" => SiteRoot("create_graph_by_matrix"),),
array(
"title" => L("menu_5"),
"link" => SiteRoot("create_graph_by_incidence_matrix"),),
array(
"title" => L("menu_9"),
"link" => SiteRoot("graphs_examples"),)
),
);
$menu[] = array
(
"title" => L("menu_2"),
"link" => "",
"list" => array(
array(
"title" => L("menu_7"),
"link" => SiteRoot("help"),),
array(
"title" => L("menu_6"),
"link" => SiteRoot("wiki"),)
),
);
$menu[] = array
(
"title" => L("menu_8"),
"link" => SiteRoot("news"),
);
$menu[] = array
(
"title" => L("menu_3"),
"link" => SiteRoot("contacts"),
);
// Помечаем текущую страницу если она есть среди пунктов меню:
foreach ($menu as $k => $v)
{
$v["is_active"] = SiteRoot(GetQuery()) == $v["link"];
$menu[$k] = $v;
}
// redirect to new domen.
// header("HTTP/1.1 301 Moved Permanently");
// header("Location: http://graphonline.ru" . $_SERVER['REQUEST_URI']);
// return;
?>