Example #1
0
 private function __construct($fPath, $flgAppendData = true)
 {
     $this->fPath = $fPath;
     $dirs = dirname($fPath);
     if ($dirs) {
         FileSys::MakeDir($dirs);
     }
     if (!$flgAppendData) {
         fclose(fopen($fPath, 'a+'));
         $this->fHandle = fopen($fPath, 'r+');
         ftruncate($this->fHandle, 0);
     } else {
         if (file_exists($fPath)) {
             if (filesize($fPath) >= self::MAXSIZE_LOGFILE) {
                 if (self::FLG_CREATE_ARCHIVE) {
                     rename($fPath, $fPath . '-archive[' . date('Y-m-d') . ']');
                 }
                 fclose(fopen($fPath, 'a+'));
                 $this->fHandle = fopen($fPath, 'r+');
                 ftruncate($this->fHandle, 0);
             } else {
                 $this->fHandle = fopen($fPath, 'a+');
             }
         } else {
             $this->fHandle = fopen($fPath, 'a+');
         }
     }
     $this->time = microtime(true);
     $this->aLog = array();
 }
Example #2
0
 public function get_component_data()
 {
     $css = '';
     $css_path = ADMIN_ROOT . '/components/' . Request::get('component') . '/client/css';
     if (is_dir($css_path)) {
         foreach (FileSys::getFiles($css_path) as $css_file) {
             $css .= file_get_contents($css_path . '/' . $css_file);
         }
     }
     $js = '';
     $js_path = ADMIN_ROOT . '/components/' . Request::get('component') . '/client/js';
     if (is_dir($js_path)) {
         foreach (FileSys::getFiles($js_path) as $js_file) {
             $js .= file_get_contents($js_path . '/' . $js_file);
         }
     }
     $client_xml = '';
     $client_xml_path = ADMIN_ROOT . '/components/' . Request::get('component') . '/client.xml';
     if (is_readable($client_xml_path)) {
         $client_xml = file_get_contents($client_xml_path);
     }
     $com_title = (new Db())->getOne('SELECT `title` FROM ##extensions WHERE `name`=?s', Request::get('component'));
     $result = [preg_replace('/[\\t\\r\\n]+/', '', $client_xml), preg_replace('/[\\t\\r]+/', '', $js), preg_replace('/[\\t\\r\\n]+/', '', $css), $com_title];
     echo Json::encode($result);
 }
Example #3
0
 public function Files()
 {
     $files = get_included_files();
     $stat = array();
     foreach ($files as $file) {
         $stat[] = array('file' => $file, 'size' => FileSys::Size($file), 'lines' => count(file($file)));
     }
     return $stat;
 }
Example #4
0
 public static function start()
 {
     //если сайт отключен
     if (SConfig::SITE_DISABLED) {
         FileSys::includeFile(SITE_ROOT . '/client/pages/site_disabled.php');
         exit;
     }
     //в переменную $request_url заносим url без GET-параметров
     $request_url = explode('?', $_SERVER['REQUEST_URI'])[0];
     //проверяем url
     if (!preg_match('/^\\/(([-a-z0-9_]+\\/)*[-a-z0-9_]+\\.html)?(\\?.*)?$/', $request_url)) {
         Router::set404();
     }
     Request::setOriginalUrl($request_url);
     $db = (new Db())->setTable('url_redirects');
     //если у страницы есть новый адрес - перенаправляем, чтобы избежать дублей страниц
     if ($ou = $db->getOne('SELECT `old_url` FROM # WHERE new_url=?s AND type="I"', $request_url)) {
         Router::redirect($ou);
     }
     //проверяем, есть ли редиректы
     $r = $db->getRow('SELECT `new_url`,`type`,`comment` FROM # WHERE old_url=?s', $request_url);
     if ($r) {
         //если редирект внутренний
         if ($r[1] === 'I') {
             $request_url = $r[0];
         } elseif ($r[1] === 'E') {
             Router::redirect($r[0]);
         }
     }
     //получаем параметры пункта меню (если есть)
     $item = $db->getRow('SELECT * FROM ##menu_items WHERE `item_url`=?s', [Request::getOriginalUrl()], MYSQLI_ASSOC);
     if ($item) {
         if ($item['params']) {
             $item['params'] = Json::decode($item['params']);
         }
         Request::setItemParams($item);
     }
     Request::setRealUrl($request_url);
     Request::setUrlSegments(explode('/', substr($request_url, 1, -5)));
     //запускаем вывод страницы
     Document::generate();
 }
Example #5
0
 private function DebugErrorHook()
 {
     global $g_config;
     static $errorListner = NULL;
     $path = dirname(__FILE__) . '/Debug/ErrorHook/';
     require_once $path . 'Listener.php';
     require_once $path . 'Catcher.php';
     require_once $path . 'INotifier.php';
     require_once $path . 'Util.php';
     require_once $path . 'TextNotifier.php';
     require_once $path . 'MailNotifier.php';
     require_once $path . 'RemoveDupsWrapper.php';
     require_once $path . 'my/MyDebug_ErrorHook_TextNotifier.php';
     $cfgLog = $g_config['logErrors'];
     FileSys::MakeDir(dirname($cfgLog['repeatTmp']));
     $errorListner = new Debug_ErrorHook_Listener();
     $errorListner->addNotifier(new MyDebug_ErrorHook_TextNotifier(MyDebug_ErrorHook_TextNotifier::LOG_ALL));
     if (!empty($cfgLog['email'])) {
         $errorListner->addNotifier(new Debug_ErrorHook_RemoveDupsWrapper(new Debug_ErrorHook_MailNotifier($cfgLog['email'], Debug_ErrorHook_TextNotifier::LOG_ALL), $cfgLog['repeatTmp'] . "/email/", $cfgLog['emailTimeRepeat']));
     }
 }
Example #6
0
/**
 * Получает строку запроса к движку
 *
 * Так же данная функция занимается созданием параметров в $_GET если они были переданны в q и созданием константы LANG если ее еще не было
 *
 * @global array  $g_config
 * @global array  $g_arrLangs   - массив языков сайта
 *
 * @param  string $q            - строка запроса при ее отсутвии то что было в $_GET[q]
 *
 * @return string
 */
function GetQuery($q = NULL)
{
    global $g_config, $g_arrLangs;
    $langs = array_keys($g_arrLangs);
    $defPage = $g_config['defaultComponent'];
    require_once BASEPATH . 'lib/InputClean.php';
    $q = is_null($q) ? isset($_GET['q']) && !empty($_GET['q']) ? trim($_GET['q'], "/") : $defPage : $q;
    $q = _StrReplaceFirst('&', '?', $q);
    $parse = parse_url($q);
    $q = isset($parse['path']) ? FileSys::FilenameSecurity($parse['path']) : "";
    if (isset($parse['query'])) {
        foreach (explode('&', $parse['query']) as $elem) {
            if (strpos($elem, '=') !== false) {
                $elem = explode('=', $elem);
                $_GET[$elem[0]] = isset($elem[1]) ? $elem[1] : NULL;
            }
        }
    }
    $parts = explode('/', $q);
    $lang = isset($parts[0]) && in_array($parts[0], $langs) ? $parts[0] : DEF_LANG;
    if (!defined('LANG')) {
        define('LANG', $lang);
    }
    if (isset($parts[0]) && in_array($parts[0], $langs)) {
        $q = implode('/', array_splice($parts, 1));
    }
    $cleaner = new InputClean($g_config['charset']);
    return empty($q) ? $defPage : $cleaner->_clean_input_data($q);
}
Example #7
0
 protected static function generateModule($position)
 {
     $db = (new Db())->setTable('modules');
     $modules = $db->getAll('SELECT module_type,name,assignment_type,assignment_urls,show_header,params,id FROM # WHERE position=?s AND published=1 ORDER BY ordering', $position, MYSQLI_ASSOC);
     ob_start();
     foreach ($modules as $module) {
         //проверяем, должен ли модуль отображаться на данной странице
         if ($module['assignment_type'] != 'all') {
             $assig_urls = Json::decode($module['assignment_urls']);
             if ($module['assignment_type'] == 'on') {
                 if (!in_array(Request::getOriginalUrl(), $assig_urls)) {
                     continue;
                 }
             } elseif ($module['assignment_type'] == 'except') {
                 if (in_array(Request::getOriginalUrl(), $assig_urls)) {
                     continue;
                 }
             }
         }
         ob_start();
         FileSys::includeFile(SITE_ROOT . '/modules/' . $module['module_type'] . '/index.php', ['data' => $module, 'params' => Json::decode($module['params'])]);
         $module_output = ob_get_clean();
         FileSys::includeFile(SITE_ROOT . '/modules/common_template.php', ['data' => $module, 'module_output' => $module_output]);
     }
     return ob_get_clean();
 }
Example #8
0
    }
    //если запрошена главная страница админки - выводим ее шаблон
    if ($_SERVER['REQUEST_URI'] === '/admin/') {
        FileSys::includeFile(ADMIN_ROOT . '/templates/default/index.php');
    } else {
        $com = Request::get('com');
        if (!is_dir(ADMIN_ROOT . '/components/' . $com)) {
            Router::set404();
        }
        if (is_file(ADMIN_ROOT . '/components/' . $com . '/config.php')) {
            require_once ADMIN_ROOT . '/components/' . $com . '/config.php';
        }
        if (is_file(ADMIN_ROOT . '/components/' . $com . '/SectionController.php')) {
            Load::controller(ADMIN_ROOT . '/components/' . $com . '/SectionController.php', Request::get('section', false));
        } else {
            $com_dirs = FileSys::getDirs(ADMIN_ROOT . '/components/' . $com);
            $forbidden_dir = ['client'];
            $section = Request::get('section');
            if (in_array($section, $com_dirs) && !in_array($section, $forbidden_dir)) {
                Load::manager(ADMIN_ROOT . '/components/' . $com . '/' . $section . '/' . toCamelCase($section) . 'Manager.php');
            } else {
                Router::set404();
            }
        }
    }
} catch (SystemException $e) {
    header('HTTP/1.0 500 Internal Server Error');
    echo $e->getError();
} catch (ValidatorException $e) {
    header('HTTP/1.0 400 Bad Request');
    echo $e->getError();
Example #9
0
<!DOCTYPE html>
<html>
<head lang="ru">
	<meta charset="UTF-8">
	<script src="/client/js/jquery/jquery-1.11.3.min.js" type="text/javascript"></script>
	<script src="/client/js/jquery/polyfills.js" type="text/javascript"></script>
	<script src="/client/js/site_config.js" type="text/javascript"></script>

	<?php 
foreach (FileSys::getDirs(SITE_ROOT . '/client/js/jquery_plugins') as $plugin) {
    ?>
		<script type="text/javascript" src="/client/js/jquery_plugins/<?php 
    echo $plugin;
    ?>
/<?php 
    echo $plugin;
    ?>
.js"></script>
	    <?php 
    if (is_readable(SITE_ROOT . '/client/js/jquery_plugins/' . $plugin . '/' . $plugin . '.css')) {
        ?>
	        <link rel="stylesheet" type="text/css" href="/client/js/jquery_plugins/<?php 
        echo $plugin;
        ?>
/<?php 
        echo $plugin;
        ?>
.css">
	    <?php 
    }
    ?>
Example #10
0
 public static function js($path, $url)
 {
     foreach (FileSys::getFiles($path) as $js) {
         echo '<script type="text/javascript" src="' . $url . $js . '"></script>';
     }
 }
Example #11
0
        $errors[] = 'Неверно введены <b>символы с картинки</b>';
    }
    if (isset($_SESSION['captcha'])) {
        unset($_SESSION['captcha']);
    }
}
//если ошибок нет
if (!$errors) {
    //отправляем письмо
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $headers .= 'From: ' . $sender . "\r\n";
    $headers .= 'Reply-To: ' . $sender . "\r\n";
    //генерируем тело письма
    ob_start();
    FileSys::includeFile(SITE_ROOT . '/components/feedback/message.php', ['data' => $data]);
    $message = ob_get_clean();
    if ($subject === '') {
        $subject = 'Без темы';
    }
    if (!mail($form_data['addressee_email'], '=?UTF-8?B?' . base64_encode($subject) . '?=', $message, $headers)) {
        $errors[] = 'Ошибка при отправке письма';
    }
}
if (isset($_POST['_ajax_mode_'])) {
    if ($errors) {
        throw new ValidatorException(implode('<br />', $errors));
    } else {
        echo 'Сообщение успешно отправлено';
    }
    exit;