Ejemplo n.º 1
0
 /**	
  *
  */
 function contentGenerator($template)
 {
     if (!user_allowed_to('manage site')) {
         return $template;
     }
     // create XML with admin panel description
     $xml = new DOMDocument('1.0', 'utf-8');
     $root_node = $xml->createElement('admin-buttons');
     $xml->appendChild($root_node);
     // detect active module_definition. no active module means some content is displayd
     $root_node->appendChild($xml->createElement('active-module'))->nodeValue = isset($_GET['module']) ? $_GET['module'] : '';
     $root_node->appendChild($xml->createElement('cms-settings-phantom'))->nodeValue = self::CMS_SETTINGS_MODULE_PHANTOM;
     $root_node->appendChild($xml->createElement('active-page'))->nodeValue = isset($_GET['p_id']) ? $_GET['p_id'] : '';
     $root_node->appendChild($xml->createElement('edit-mode'))->nodeValue = isset($_GET['edit']) ? 'yes' : 'no';
     $root_node->appendChild($xml->createElement('show-config-link'))->nodeValue = empty($_GET['module']) || empty(CMS::$cache[$_GET['module']]['config']['config']) ? 'no' : 'yes';
     // get all modules' admin buttons, where exists
     foreach (CMS::$cache as $module_name => $module) {
         if (in_array($module_name, CMS::$R['modules_apply_order']) && isset($module['config']['admin_caption']) && $module['config']['admin_caption'] > '') {
             $root_node->appendChild($button_node = $xml->createElement('button'));
             $button_node->appendChild($xml->createElement('caption'))->nodeValue = $module['config']['admin_caption'];
             $button_node->appendChild($xml->createElement('module-name'))->nodeValue = $module_name;
         }
     }
     // if any module requests admin part, replace all the content with module's admin code and add CSS/JS
     // otherwise, display page editorial buttons // TAG_TODO move them to content module
     if (isset($_GET['module']) && isset(CMS::$cache[$_GET['module']]) && isset($_GET['action']) && $_GET['action'] == 'manage') {
         $module_name = $_GET['module'];
         module_init($module_name);
         $module = CMS::$cache[$module_name];
         // replace content
         $template = preg_replace('~<body(.*?)>.*</body>~smui', '<body$1><div class="admin-content">' . $module['object']->AdminGenerator() . '</div></body>', $template, 1);
         $template = preg_replace(macro_regexp('page_title'), 'администрирование: &quot;' . CMS::$cache[$_GET['module']]['config']['comment'] . '&quot;', $template, 1);
         // remove user's CSS from template
         $template = preg_replace('~<link[^>]*rel="stylesheet"[^>]*href="(\\./|)userfiles[^">]*"[^>]*>~', '', $template);
         $template = preg_replace('~<link[^>]*href="(\\./|)userfiles[^">]*"[^>]*rel="stylesheet"[^>]*>~', '', $template);
         // also add module's admin CSSes and scripts
         add_CSS(get_array_value($module['config'], 'admin_css', array()), MODULES_DIR . $module_name . '/');
         add_JS(get_array_value($module['config'], 'admin_js', array()), MODULES_DIR . $module_name . '/');
     }
     // add button box to the template
     $admin_box_html = XSLTransform($xml->saveXML($root_node), __DIR__ . '/admin_box.xsl');
     $template = preg_replace('~<body(.*?)>~', '<body$1>' . $admin_box_html, $template, 1);
     return $template;
 }
Ejemplo n.º 2
0
 /**
  * Content generator - creates table-formed report
  *
  */
 function contentGenerator($template)
 {
     // append userapi scripts and CSS
     if (is_dir('userapi/js/')) {
         $user_js_files = scandir('userapi/js/');
         foreach ($user_js_files as $user_js_file) {
             if (pathinfo($user_js_file, PATHINFO_EXTENSION) == 'js') {
                 add_JS('userapi/js/' . $user_js_file);
                 logthis('userAPI script added: ' . $user_js_file);
             }
         }
     }
     if (is_dir('userapi/css/')) {
         $user_css_files = scandir('userapi/css/');
         foreach ($user_css_files as $user_css_file) {
             if (pathinfo($user_css_file, PATHINFO_EXTENSION) == 'css') {
                 add_CSS('userapi/css/' . $user_css_file);
                 logthis('userAPI CSS added: ' . $user_css_file);
             }
         }
     }
     // replace all templates to generated content
     while (preg_match(macro_regexp('db'), $template, $match) > 0) {
         // parse template parameters into array
         $params = parse_plugin_template($match[0]);
         // generate HTML
         if (!isset($params['id'])) {
             $table_html = '<b>[JuliaCMS][db] error:</b> no ID specified for the table';
         } else {
             // all API/UI require "report_id" parameter
             $params['report_id'] = $params['id'];
             $table_html = J_DB_UI::generateTable($params, $this->DB);
         }
         // replace
         $template = str_replace($match[0], $table_html, $template);
     }
     // yeah we are ready
     return $template;
 }
Ejemplo n.º 3
0
 /**
  *
  */
 function contentGenerator($template)
 {
     // catalog mode: intercept _GET page alias, look in self elements, display child items list if exists
     $input_filter = array('p_id' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => REGEXP_ALIAS)));
     $_INPUT = get_filtered_input($input_filter, array(FILTER_GET_BY_LIST));
     if ($_INPUT['p_id'] > '') {
         // this will mean that nothing was found
         $id = -1;
         $query = CMS::$DB->query("select * from `{$this->CONFIG['table_menu']}` where alias = '{$_INPUT['p_id']}'");
         if ($row = $query->fetch(PDO::FETCH_ASSOC)) {
             $id = $row['id'];
             $css_content = $row['style_content'];
             $caption = $row['caption'];
             $title = $row['title'] ? $row['title'] : $row['caption'];
             $meta = $row['meta'];
         }
         // if we found something, insert it instead content
         if ($id >= 0) {
             while (preg_match(macro_regexp('content'), $template, $match) > 0) {
                 $params = parse_plugin_template($match[0]);
                 $html = $this->generateCatalogPageHTML($_INPUT['p_id'], $params);
                 // possibly we will need navigator from the current page
                 if (get_array_value($params, 'show-navigator', 'yes') == 'yes') {
                     $html = $this->generateNavigatorHTML($_INPUT['p_id'], $params) . $html;
                 }
                 $template = preg_replace(macro_regexp('content'), $html, $template);
                 $template = preg_replace(macro_regexp('page_title'), $title, $template);
                 // add meta. if only letter and digits, make "keywords" meta (!copy-paste detected!)
                 if (preg_match('~^[a-zA-Zа-яА-Я0-9,.\\-\\s]+$~ui', $meta, $match)) {
                     $template = add_meta($template, 'name', 'keywords', $match[0]);
                 } elseif (preg_match_all('~(\\(([a-zA-Z\\-]*)\\|([a-zA-Z\\-0-9]+)\\|([a-zA-Z\\-0-9а-яА-Я.,;:\\s+=!@#$%^&*\\(\\)]*)\\))~smui', $meta, $matches)) {
                     // не прокатило, попробуем структуру со скобками и пайпами
                     for ($i = 0; $i < count($matches[0]); $i++) {
                         $template = add_meta($template, $matches[2][$i], $matches[3][$i], $matches[4][$i]);
                     }
                 } elseif (preg_match_all('~<[a-zA-Z]+\\s[^<>]+>~smui', $meta, $matches)) {
                     // check if raw tags there
                     for ($i = 0; $i < count($matches[0]); $i++) {
                         $template = str_insert_before('</head>', $matches[0][$i] . PHP_EOL, $template);
                     }
                 }
                 // yeah, nice stylesheets
                 add_CSS($css_content, CMS::$R['USERFILES_DIRS']['css']['dir']);
             }
         }
     }
     // standard behavior - menu by macro
     while (preg_match(macro_regexp('menu'), $template, $match) > 0) {
         // parse template parameters into array
         $params = parse_plugin_template($match[0]);
         // generate menu HTML
         $xml = $this->generateMenuAsXML(get_array_value($params, 'start-from', ''));
         $xsl = get_array_value($params, 'menu-template', 'default');
         // now test with path
         $xsl_filename = __DIR__ . '/../../userfiles/_data_modules/menu/templates/menu/' . $xsl . '.xsl';
         if (!file_exists($xsl_filename)) {
             $xsl_filename = __DIR__ . '/templates/' . $catalog_dir . '/' . $xsl . '.xsl';
         }
         $html = XSLTransform($xml->saveXML($xml->documentElement), $xsl_filename);
         // replace it
         $template = str_replace($match[0], $html, $template);
     }
     // navigator mode
     while (preg_match(macro_regexp('menu-navigator'), $template, $match) > 0) {
         // parse template parameters into array
         $params = parse_plugin_template($match[0]);
         // generate navigator HTML
         $html = $this->generateNavigatorHTML(get_array_value($params, 'start-from', ''), $params);
         // replace it
         $template = str_replace($match[0], $html, $template);
     }
     // yeah we are ready
     return $template;
 }
Ejemplo n.º 4
0
 function contentGenerator($template)
 {
     $USERFILES_DIRS = CMS::$R['USERFILES_DIRS'];
     // если этот флажок есть, будет вызван редактор вместо отображения контента
     $edit_mode = isset($_GET['edit']);
     // идентификатор странички, которую надо вставить в шаблон. валидация не нужна - делается поиск в массиве
     // собираем список имеющихся страниц
     $pages = array();
     $query = CMS::$DB->query("select * from `{$this->CONFIG['table']}`");
     while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
         $pages[$row['alias']] = $row;
     }
     $page_id = isset($_GET['p_id']) ? $_GET['p_id'] : DEFAULT_PAGE_ALIAS;
     // ок, берем стандартную страницу, если таковая есть
     $page_found = false;
     if (isset($pages[$page_id])) {
         $page_found = true;
         $page_info = $pages[$page_id];
     } else {
         // если нужного идентификатора нет в страницах, посмотрим в меню, если там найдется - пускай сами разбираются
         if (module_get_config('menu', $menu_module_config) === true) {
             $query = CMS::$DB->query("select alias from `{$menu_module_config['config']['table_menu']}` where alias > ''");
             while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
                 if ($page_id == $row['alias']) {
                     $page_found = true;
                     return $template;
                 }
             }
         }
     }
     // если страница не найдена, попробуем использовать то, что указано в настройках для страницы 404,
     // если и там нету - тупо заменяем макрос на строку и вываливаемся
     if (!$page_found) {
         header('HTTP/1.1 404 Not found');
         if (isset($pages[$this->CONFIG['page_404']])) {
             $page_info = $pages[$this->CONFIG['page_404']];
         } else {
             $template = preg_replace(macro_regexp('content'), 'Страница не найдена', $template);
             return $template;
         }
     }
     // имя файла с контентом
     $content_filename = isset($page_info['filename']) && file_exists($USERFILES_DIRS['pages']['dir'] . $page_info['filename']) ? $USERFILES_DIRS['pages']['dir'] . $page_info['filename'] : $this->CONFIG['page_404'];
     // в режиме редактирования текст/xml не генерируем, а показываем в редакторе (textarea)
     if ($edit_mode && user_allowed_to('edit pages')) {
         switch (pathinfo($page_info['filename'], PATHINFO_EXTENSION)) {
             case 'php':
             case 'xml':
                 $pagehtml = sprintf(MODULE_CONTENT_TEXTAREA_WRAPPER_PHP, $page_id, @file_get_contents($content_filename));
                 break;
             default:
                 $pagecontent = @file_get_contents($content_filename);
                 // при редактировании заменим макросы на защищенную версию, иначе следующие модули на них среагируют
                 // и заменят на свой контент, что наи не нужно. ядро само заменит их обратно потом
                 $pagecontent = str_replace('<macro', '<protected-macro', $pagecontent);
                 $pagecontent = str_replace('[macro', '[protected-macro', $pagecontent);
                 $pagecontent = str_replace('</macro', '</protected-macro', $pagecontent);
                 $pagecontent = str_replace('[/macro', '[/protected-macro', $pagecontent);
                 $pagehtml = sprintf(MODULE_CONTENT_TEXTAREA_WRAPPER, $page_id, $pagecontent);
                 break;
         }
     } else {
         // если html, тащим как есть, иначе формируем с помошью генератора или XSLT
         switch ($ext = pathinfo($content_filename, PATHINFO_EXTENSION)) {
             case 'php':
                 include_once $content_filename;
                 $pagehtml = call_user_func($page_info['generator']);
                 break;
             case 'xml':
                 $pagehtml = XSLTransform($content_filename, $USERFILES_DIRS['xsl']['dir'] . $page_info['xsl'], false, false);
                 break;
             default:
                 ($pagehtml = file_get_contents($content_filename)) !== false or $pagehtml = 'error reading page content (code CONTENT/001)';
                 break;
         }
     }
     // если есть BODY, берем его внутреннее содержимое, иначе весь файл целиком
     if (preg_match(self::REGEXP_HTML_BODY, $pagehtml, $page_body) > 0) {
         $replace = $page_body[1];
     } else {
         $replace = $pagehtml;
     }
     if (isset($_GET['print'])) {
         $template = str_replace('%content%', $replace, MODULE_CONTENT_PRINT_FORM);
     } else {
         $template = preg_replace(macro_regexp('content'), $replace, $template);
     }
     // мета в заголовке. если только буквы-цифры, делаем мету keywords
     if (preg_match('~^[a-zA-Zа-яА-Я0-9,.\\-\\s]+$~ui', $page_info['meta'], $match)) {
         $template = add_meta($template, 'name', 'keywords', $match[0]);
     } elseif (preg_match_all('~(\\(([a-zA-Z\\-]*)\\|([a-zA-Z\\-0-9]+)\\|([a-zA-Z\\-0-9а-яА-Я.,;:\\s+=!@#$%^&*\\(\\)]*)\\))~smui', $page_info['meta'], $matches)) {
         // не прокатило, попробуем структуру со скобками и пайпами
         for ($i = 0; $i < count($matches[0]); $i++) {
             $template = add_meta($template, $matches[2][$i], $matches[3][$i], $matches[4][$i]);
         }
     } elseif (preg_match_all('~<meta\\s[^>]+>~smui', $page_info['meta'], $matches)) {
         // проверим, возможно вписали сырые теги
         for ($i = 0; $i < count($matches[0]); $i++) {
             $template = str_insert_before('</head>', $matches[0][$i] . PHP_EOL, $template);
         }
     }
     // заменяем залоговок страницы, если определен
     if (isset($page_info['title']) && ($replace = $page_info['title']) > '') {
         $template = preg_replace(macro_regexp('page_title'), $replace, $template, 1);
     }
     // кастомный CSS, если указан
     if (isset($page_info['custom_css']) && ($css = $page_info['custom_css']) > '') {
         add_CSS(CMS::$R['USERFILES_DIRS']['css']['dir'] . $css);
     }
     // кастомный JS, если указан
     if (isset($page_info['custom_js']) && ($js = $page_info['custom_js']) > '') {
         add_JS(CMS::$R['USERFILES_DIRS']['js']['dir'] . $js);
     }
     return $template;
 }
Ejemplo n.º 5
0
// immediately add core libraries and stylesheets to ensure their minimal priority
add_JS(array('lib/jquery.js', 'lib/jquery-ui.js', 'lib/jquery.tablesorter.min.js', 'tinymce/tinymce.min.js', 'tinymce/jquery.tinymce.min.js', 'lib/lib.js'));
add_CSS(array('lib/jquery-ui.css', 'lib/tablesorter.css', 'lib/bootstrap.min.css', 'lib/core.css'));
// first loop: add modules' CSS and JS links
foreach ($modules_apply_order as $module_name) {
    // check if module OK
    if (!isset(CMS::$cache[$module_name])) {
        logthis('module description not loaded: ' . $module_name, ZLogger::LOG_LEVEL_WARNING);
        continue;
    }
    // also module may be disabled
    if (get_array_value(CMS::$cache[$module_name]['config'], 'disabled', false) === true) {
        continue;
    }
    logthis('connecting external files for module: ' . $module_name);
    add_CSS(get_array_value(CMS::$cache[$module_name]['config'], 'css', array()), MODULES_DIR . $module_name . '/');
    add_JS(get_array_value(CMS::$cache[$module_name]['config'], 'js', array()), MODULES_DIR . $module_name . '/');
    // check if we should stop here
    if (get_array_value(CMS::$cache[$module_name]['config'], 'break_after', false)) {
        break;
    }
}
// second loop: input parsers
// look previous loop for comments
foreach ($modules_apply_order as $module_name) {
    logthis('trying input parser for module: ' . $module_name);
    if (!isset(CMS::$cache[$module_name])) {
        logthis('module description not loaded: ' . $module_name, ZLogger::LOG_LEVEL_WARNING);
        continue;
    }
    if (get_array_value(CMS::$cache[$module_name]['config'], 'disabled', false) === true) {