Ejemplo n.º 1
0
 /**
  *
  */
 public function contentGenerator($template)
 {
     while (preg_match(macro_regexp('chat'), $template, $match) > 0) {
         // parse template parameters into array
         $params = parse_plugin_template($match[0]);
         // generate menu HTML
         $html = '<div class="j-chat"><div>loading...</div><form><input type="text" /></form></div>';
         // replace it
         $template = str_replace($match[0], $html, $template);
     }
     return $template;
 }
Ejemplo n.º 2
0
 /**
  * This function parses input data for both requestParser and AJAXHandler
  * 
  * @param string $template page template for calling from requestParser
  * @param string &$redirect_target location to redirect to
  * @return string|bool modified template or true/false
  */
 private function takeAction($template, &$redirect_target)
 {
     $I = $this->getInput();
     switch ($I['action']) {
         // login
         case 'login':
             // check login/password
             $ok = $this->tryLogin($I['username'], $I['password'], $login_result_html);
             // different actions on different call methods (straight vs AJAX)
             if (get_array_value($I, 'module', false) == 'auth') {
                 while (preg_match(macro_regexp('auth'), $template, $match)) {
                     $params = parse_plugin_template($match[0]);
                     if (get_array_value($params, 'mode', false) == 'login-message') {
                         $template = str_replace($match, $login_result_html, $template);
                     }
                 }
                 return $template;
             }
             if (get_array_value($I, 'ajaxproxy', false) == 'auth') {
                 return ($ok ? 'OK' : 'NO') . ':' . $login_result_html;
             }
             break;
             // logout. always returns true
         // logout. always returns true
         case 'logout':
             $this->logout();
             $redirect_target = '.';
             return 'OK';
             break;
             // password change form. avoid calling it via "ajaxproxy"
         // password change form. avoid calling it via "ajaxproxy"
         case 'change_password':
             $template = content_replace_body($template, file_get_contents(__DIR__ . '/chpass.html'));
             $template = content_replace_title($template, 'Изменение пароля');
             return $template;
             break;
             // actual password changing
         // actual password changing
         case 'chpass':
             if (!user_allowed_to('change other passwords')) {
                 terminate('Forbidden', '', 403);
             }
             $ok = $this->tryChangePassword($I['username'], $I['password'], $I['password1'], $I['password2'], $chpass_result_html) ? 'OK' : 'NO';
             return $ok . ':' . $chpass_result_html;
             break;
     }
     return $template;
 }
Ejemplo n.º 3
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.º 4
0
 /**
  * Main content generator
  *
  */
 function contentGenerator($template)
 {
     // iterate all macros
     while (preg_match(macro_regexp('news'), $template, $match) > 0) {
         $menu_params = parse_plugin_template($match[0]);
         // determine template
         $template_name = get_array_value($menu_params, 'template', false, '~^[a-zA-Zа-яА-Я_][a-zA-Zа-яА-Я_0-9]*$~u') ?: 'default';
         $full_filename = __DIR__ . '/templates/' . $template_name . '.html';
         if (!file_exists($full_filename)) {
             popup_message_add('[ NEWS ] template not found (name: ' . get_array_value($menu_params, 'template', 'not set') . ', filename: ' . $full_filename . ')', JCMS_MESSAGE_ERROR);
             return $template;
         }
         // get news as HTML
         $str = $this->newsGenerate(file_get_contents($full_filename), get_array_value($menu_params, 'stream', 'default'), get_array_value($menu_params, 'count', -1));
         $template = str_replace($match[0], $str, $template);
     }
     return $template;
 }
Ejemplo n.º 5
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.º 6
0
 /**
  * Places feedback form from the file
  *
  * Macro parameters available:
  *  "form"     : specifies a file to get a form from (no extension, will be added automatically, "default" by default)
  *  "target"   : get recipient from the config list (first item by default)
  *  "template" : forces to add "template" hidden input to the form causing sender to use alternate email template
  *
  * @param string $template source template
  * @return string
  */
 function contentGenerator($template)
 {
     // look for macro
     while (preg_match(macro_regexp('feedback'), $template, $match) > 0) {
         $params = parse_plugin_template($match[0]);
         // now get form HTML. if no source found specified, try to use "default.html". Malformed values always generate an error
         if ($filename = get_array_value($params, 'form', 'default', REGEXP_IDENTIFIER)) {
             if (file_exists(__DIR__ . '/forms/' . $filename . '.html')) {
                 $form = file_get_contents(__DIR__ . '/forms/' . $filename . '.html');
             } else {
                 $form = '<b>[JuliaCMS][feedback] error:</b> form file &quot;' . $filename . '.html&quot; not found';
             }
         } else {
             $form = '<b>[JuliaCMS][feedback] error:</b> bad form name &quot;' . $params['form'] . '&quot;';
         }
         // let's determine form target (source form's one will be deleted automatically)
         $target = get_array_value($params, 'target', false);
         $address_keys = array_keys($this->CONFIG['addresses']);
         $recipient = isset($this->CONFIG['addresses'][$target]) ? $target : array_shift($address_keys);
         // ok, implant recipient field into a form (first, cut existing if any)
         $form = preg_replace('~<input\\s[^>]*?name="recipient"[^/>]*/?>~', '', $form);
         $form = str_insert_before('</form>', '<input type="hidden" name="recipient" value="' . $recipient . '" />', $form);
         // add (or replace) template identifier, if specified
         $message_template_name = get_array_value($params, 'template', '', REGEXP_IDENTIFIER);
         if ($message_template_name > '') {
             $form = preg_replace('~<input\\s[^>]*?name="template"[^/>]*/?>~', '', $form);
             $form = str_insert_before('</form>', '<input type="hidden" name="template" value="' . $message_template_name . '" />', $form);
         }
         // form ready, add it to template!
         $template = str_replace($match[0], $form, $template);
     }
     return $template;
 }