* Copyright (c) 2001-2008 Platon Group, http://platon.sk/ * All rights reserved. * * See README file for more information about this software. * See COPYING file for license information. * * Download the latest version from * http://platon.sk/projects/Metafox/ */ /* $Platon: Metafox/subst.inc.php,v 1.65 2015/10/27 11:14:14 igor Exp $ */ require_once 'cfgldr.inc.php'; require_once 'error.inc.php'; require_once 'functions.inc.php'; require_once 'db-core/db-core.inc.php'; require_once 'db.inc.php'; if ($ezin_cfg['debug_level'] == 10) { ezin_cache_clear(''); } /* * Include libraries */ require_once 'HTML/Template/Platon.php'; HTML_Template_Platon::setLoadFunction('ezin_load_template'); if (isset($ezin_sys['weblog']['dsn']) && strlen($ezin_sys['weblog']['dsn']) > 0) { include_once 'lib/phpWebLogAnalyzer/phpWebLogAnalyzer.inc.php'; $ezin_weblog = new Web_Log($ezin_sys['weblog']['dsn'], $ezin_cfg['session_timeout'], 2 /* ident timeout */); } else { $ezin_weblog = false; } /* * Input parameters parsing */ ezin_cgi_parse(); /* * Mandatory HTTP host check */ $ezin_https = ezin_get_schema() == 'https'; switch ($ezin_cfg['https_admin']) { case 0: // Always OFF $https_admin_redirect = false; break; case 1: // Auto-detect $https_admin_redirect = ! $ezin_https && strlen($_SERVER['HTTP_HOST']) > 0; break; case 2: // Always ON $https_admin_redirect = true; break; } if ($ezin_cgi['output'] == 'admin' && $https_admin_redirect && ! $ezin_https) { $socket = @fsockopen('ssl://'.$_SERVER['HTTP_HOST'], 443); if (is_resource($socket)) { $req_str = sprintf("HEAD %s HTTP/1.1\r\n", $_SERVER['REQUEST_URI']); $req_str .= sprintf("Host: %s\r\n", $_SERVER['HTTP_HOST']); $req_str .= "Connection: close\r\n\r\n"; fwrite($socket, $req_str); stream_set_blocking($socket, true); stream_set_timeout($socket, 1); $data = fread($socket, 100); if (preg_match('/^HTTP.*\s*200\s*/', $data)) { Platon::redirect('https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); } } } $ezin_http_host = strtolower($_SERVER['HTTP_HOST']); // Set language by HTTP host if (strlen($ezin_cfg['http_host_language']) > 0) { preg_match_all('|(\w\w)[^\(]*\(([^\)]*)\)|', $ezin_cfg['http_host_language'], $matches); foreach ($matches[1] as $index => $lang) { $hosts = preg_split('/(\s+|\xc2\xa0)/', $matches[2][$index]); if (in_array($ezin_http_host, $hosts)) { $ezin_cgi['lang'] = $lang; break; } } } if (strlen($ezin_cfg['http_host_redirect']) > 0 && strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) { /* {{{ */ $ezin_redirect_ar = preg_split('/(\s+|\xc2\xa0)/', $ezin_cfg['http_host_redirect']); if (count($ezin_redirect_ar) > 1) { $ezin_redirect_new = array(); foreach ($ezin_redirect_ar as $val) { if (preg_match('|^(\w\w)\((.*)\)$|', $val, $matches)) { $ezin_redirect_new[strtolower($matches[1])] = $matches[2]; // if ($ezin_cgi['lang_init'] >= 2 && ! strcasecmp($matches[2], $ezin_http_host)) { // $ezin_cgi['lang'] = strtolower($matches[1]); // } } else { $ezin_redirect_new[''] = $val; } } if (isset($ezin_redirect_new[$ezin_cgi['lang']])) { $ezin_redirect_url = $ezin_redirect_new[$ezin_cgi['lang']]; } else { $ezin_redirect_url = @$ezin_redirect_new[$ezin_cgi['']]; } } else { $ezin_redirect_url = $ezin_redirect_ar[0]; } $ezin_redirect_ar = @parse_url($ezin_redirect_url); if (@strlen($ezin_redirect_ar['scheme']) <= 0) { $ezin_redirect_ar = @parse_url( ($ezin_https ? 'https' : 'http') .'://'.$ezin_redirect_url); } if (strlen($ezin_redirect_ar['host']) > 0 && strlen($ezin_http_host) > 0 && strcasecmp($ezin_redirect_ar['host'], $ezin_http_host)) { //die("here: ".$ezin_http_host.'-'.$ezin_redirect_ar['host']); $ezin_http_host_allowed_ar = preg_split('/(\s+|\xc2\xa0)/', $ezin_cfg['http_host_allowed']); $ezin_http_host_forbidden_ar = preg_split('/(\s+|\xc2\xa0)/', $ezin_cfg['http_host_forbidden']); if (count($ezin_http_host_forbidden_ar) <= 0 || in_array($ezin_http_host, $ezin_http_host_forbidden_ar)) { if (! in_array($ezin_http_host, $ezin_http_host_allowed_ar)) { if (! isset($ezin_redirect_ar['path'])) { $ezin_redirect_ar['path'] = '/'; } $append_path = Platon::str_replace_prefix( Platon::append_slash($ezin_cfg['url']), '', $_SERVER['REQUEST_URI']); $ezin_redirect_ar['path'] .= ($append_path == '/' && substr($ezin_redirect_ar['path'], -1) == '/') ? '' : $append_path; Platon::redirect(Platon::glue_url($ezin_redirect_ar)); } } } } /* }}} */ if ($ezin_cgi['lang'] != @$_COOKIE['ezin_lang']) { $expire_time = time() + (3600 * 24 * 30 * 12 * 2); // two years setcookie('ezin_lang', $ezin_cgi['lang'], $expire_time, $ezin_cfg['url']); } /* * Check number of articles after SYSDATE * (the same principle as 'version') */ $ezin_atodo_real = ezin_get_articles_todo(); $ezin_atodo_cached = ezin_cache_load_content('atodo'); if ($ezin_atodo_cached === false) { ezin_cache_save('atodo', $ezin_atodo_real); } elseif (intval($ezin_atodo_real) != intval($ezin_atodo_cached)) { ezin_cache_clear(''); ezin_cache_save('atodo', $ezin_atodo_real, 0, 0); } /* * Write counts */ ezin_update_counts_temp(); ezin_update_counts($ezin_cgi['author_id'], $ezin_cgi['section_id'], $ezin_cgi['article_id']); /* * Get section parameters */ $ezin_tmpl_key = ''; $ezin_db_author = ''; $ezin_db_section = ''; $ezin_db_article = ''; $ezin_db_poll = ''; if ($ezin_cgi['author_id'] > 0 || $ezin_cgi['output'] == 'author' || $ezin_cgi['output'] == 'author_edit') { /* {{{ */ //var_dump($ezin_cgi); $ezin_db_author = ezin_get_author($ezin_cgi['author_id']); if (! empty($ezin_db_author['author_template_key'])) { $ezin_tmpl_key .= $ezin_sys['tmpl']['delim'].$ezin_db_author['author_template_key']; } if (! empty($ezin_db_author['author_link']) && $ezin_cgi['output'] == 'author') { ezin_handle_author_link($ezin_db_author['author_link']); } $name = $ezin_db_author['author_name']; $ezin_db_author['search'] = $ezin_db_author['author_id']; if (strlen($name) > 0) { if (preg_match('|^(\S*)\s*(.*)|', $name, $matches)) { $ezin_db_author['search'] = $matches[2]; } else if (preg_match('|^(\S*),\s*(\S*)|', $name)) { $ezin_db_author['search'] = $matches[1]; } } $ezin_tmpl_key .= $ezin_sys['tmpl']['delim'].'author'; } /* }}} */ if (! empty($ezin_cgi['article_id'])) { /* {{{ */ $ezin_db_article = ezin_get_article($ezin_cgi['article_id']); if (! empty($ezin_db_article['article_template_key'])) { $ezin_tmpl_key .= $ezin_sys['tmpl']['delim'].$ezin_db_article['article_template_key']; } } /* }}} */ /* {{{ section - always (at least editorial is fetched) */ $ezin_db_section = ezin_get_section($ezin_cgi['section_id'], $ezin_cgi['article_id']); if (! empty($ezin_db_section['section_template_key'])) { /* What si not good here: if we have "author" page, we add also section template key, what is not neccessary and most-likely unwanted. */ $ezin_tmpl_key .= $ezin_sys['tmpl']['delim'].$ezin_db_section['section_template_key']; } if (! empty($ezin_db_section['section_link']) && $ezin_cgi['output'] == 'section') { ezin_handle_section_link($ezin_db_section['section_link']); } /* }}} */ /* * Main template object */ if (strlen($_REQUEST['ezin_template_key']) > 0) { $ezin_tmpl_key = $ezin_sys['tmpl']['delim'].$_REQUEST['ezin_template_key'].$ezin_tmpl_key; //$ezin_db_section['section_template_key'] = $_REQUEST['ezin_template_key']; //$ezin_db_author['author_template_key'] = $_REQUEST['ezin_template_key']; } if ($ezin_cgi['output'] == 'notfound' || ezin_exist_access_key_redirect($ezin_cgi['notfound_id'], $access_key_redirect['type'])) { $access_key_redirect = ezin_get_access_key_redirect($ezin_cgi['notfound_id'], $ezin_cgi['input']); if ($access_key_redirect == false) { foreach(array('section','article','author','print') as $type) { $access_key_redirect = ezin_get_access_key_redirect($ezin_cgi['notfound_id'], $type); if ($access_key_redirect !== false) { break; } } } switch($access_key_redirect['type']) { case 'section': ezin_redirect_section($access_key_redirect['id']); break; case 'article': ezin_redirect_article($access_key_redirect['id']); break; case 'author': ezin_redirect_author($access_key_redirect['id']); break; case 'print': ezin_redirect_print($access_key_redirect['id']); break; } } switch ($ezin_cgi['output']) { /* {{{ */ default: die('input method fatal error: '.$ezin_cgi['output']); break; case 'error': $ezin_tmpl_main_fname = $ezin_sys['tmpl']['error']; break; case 'notfound': $ezin_tmpl_main_fname = $ezin_sys['tmpl']['notfound']; break; case 'admin': // for admin section we need to include this early if (file_exists($ezin_cfg['theme']['dir'].'/'.$ezin_sys['tmpl']['fnc_file'])) { include_once $ezin_cfg['theme']['dir'].'/'.$ezin_sys['tmpl']['fnc_file']; } $ezin_tmpl_main_fname = $ezin_sys['tmpl']['admin']; $ezin_tmpl_main_fname .= $ezin_sys['tmpl']['delim']; $ezin_tmpl_main_fname .= $ezin_auth->getAuth() && $ezin_admin_action != 'logout' ? 'logged' : 'notlogged'; break; case 'message': $ezin_tmpl_main_fname = $ezin_sys['tmpl']['message_edit'].$ezin_tmpl_key; break; case 'message_full_list': case 'message_selected_list': $ezin_tmpl_main_fname = $ezin_sys['tmpl']['message'].$ezin_tmpl_key; break; case 'article_print': $ezin_tmpl_main_fname = $ezin_sys['tmpl']['article_print'].$ezin_tmpl_key; break; case 'article': $ezin_tmpl_main_fname = $ezin_sys['tmpl']['article'].$ezin_tmpl_key; break; case 'section': $ezin_tmpl_main_fname = $ezin_sys['tmpl']['section'].$ezin_tmpl_key; break; case 'author': if (strlen($ezin_tmpl_key) <= 0) { $ezin_tmpl_key = $ezin_sys['tmpl']['delim'].'author'; // TODO? } $ezin_tmpl_main_fname = $ezin_sys['tmpl']['author'].$ezin_tmpl_key; break; case 'author_edit': if (strlen($ezin_tmpl_key) <= 0) { $ezin_tmpl_key = $ezin_sys['tmpl']['delim'].'author_edit'; // TODO? } $ezin_tmpl_main_fname = $ezin_sys['tmpl']['author_edit'].$ezin_tmpl_key; break; } /* }}} */ $ezin_tmpl_main = new HTML_Template_Platon($ezin_tmpl_main_fname); /* * Try to include user defined function(s) file */ if (file_exists($ezin_cfg['theme']['dir'].'/'.$ezin_sys['tmpl']['fnc_file'])) { include_once $ezin_cfg['theme']['dir'].'/'.$ezin_sys['tmpl']['fnc_file']; } /* * Substitute current section parameters */ if ($ezin_db_author != '') { /* {{{ */ ezin_author_link_process($ezin_db_author); ezin_author_counts_process($ezin_db_author); // if author edit page, than do not modify description content // (because it adds
at the end of lines, etc.) if ($ezin_cgi['output'] != 'author_edit') { ezin_handle_special_tags($ezin_db_author['author_description'], $ezin_db_author['author_description_flags']); ezin_process_text_flags($ezin_db_author['author_description'], 'author'); } $ezin_tmpl_main->set($ezin_db_author); foreach ($ezin_db_author as $key => $val) { $ezin_tmpl_main->setAlias("ezin_$key", $key); } } /* }}} */ if ($ezin_db_section != '') { /* {{{ */ ezin_section_link_process($ezin_db_section); ezin_section_counts_process($ezin_db_section); $ezin_db_section['section_editorial_text'] =Platon::tilde_replace($ezin_db_section['section_editorial_text']); $ezin_db_section['section_editorial_title']=Platon::tilde_replace($ezin_db_section['section_editorial_title']); $ezin_db_section['section_parent_id2'] = explode('::', $ezin_db_section['section_id2']); $ezin_db_section['section_parent_id2'] = $ezin_db_section['section_parent_id2'][0]; if (isset($ezin_db_section['section_editorial_timestamp'])) { $ezin_db_section['section_editorial_date'] = date($ezin_cfg['format_date'], $ezin_db_section['section_editorial_timestamp']); $ezin_db_section['section_editorial_datetime'] = date($ezin_cfg['format_datetime'], $ezin_db_section['section_editorial_timestamp']); } else { $ezin_db_section['section_editorial_date'] = ''; $ezin_db_section['section_editorial_datetime'] = ''; } if (isset($ezin_db_section['section_editorial_text'])) { ezin_handle_special_tags($ezin_db_section['section_editorial_text'], $ezin_db_section['section_editorial_text_flags']); ezin_process_text_flags($ezin_db_section['section_editorial_text'], 'editorial'); } else { $ezin_db_section['section_editorial_text'] = ''; } $ezin_tmpl_main->set($ezin_db_section); foreach ($ezin_db_section as $key => $val) { $ezin_tmpl_main->setAlias("ezin_$key", $key); } } /* }}} */ /* * Build up sections list */ if ($ezin_tmpl_main->isVar('section_items')) { /* {{{ */ $cache_id = 'S'.@$ezin_cgi['lang'].$ezin_tmpl_key; $cache_ar = ezin_cache_load($cache_id); if (intval($cache_ar['timestamp']) <= 0) { $item = new HTML_Template_Platon($ezin_sys['tmpl']['section_item'].$ezin_tmpl_key, HTML_TEMPLATE_PLATON_METHOD_VAR_KEEP); $cache_ar['var_var'] = $item->isVar('section_selected') || $item->isVar('section_accesses_count') || $item->isVar('section_raw_accesses_count') || $item->isVar('section_sessions_count') || $item->isVar('section_raw_sessions_count'); $sections = ezin_get_section_list($ezin_cgi['lang'], $ezin_cgi['section_id']); $cache_ar['content'] = ''; for ($k = 0; $k < count($sections); $k++) { $item->reload(); ezin_section_link_process($sections[$k]); ezin_section_counts_process($sections[$k]); if ($cache_ar['var_var']) { $id = $sections[$k]['section_id']; $item->setVar('section_selected', 'section_selected_'.$id); $item->setVar('section_accesses_count', 'section_accesses_count_'.$id); $item->setVar('section_sessions_count', 'section_sessions_count_'.$id); $item->setVar('section_raw_accesses_count', 'section_raw_accesses_count_'.$id); $item->setVar('section_raw_sessions_count', 'section_raw_sessions_count_'.$id); } $item->set($sections[$k]); $cache_ar['content'] .= $item->getCode(); } //$cache_ar['content'] = Platon::tilde_replace($cache_ar['content']); unset($sections); ezin_cache_save($cache_id, $cache_ar['content'], $cache_ar['var_var']); } $ezin_tmpl_main->setCode('section_items', $cache_ar['content']); if ($cache_ar['var_var']) { $ezin_tmpl_main->set(ezin_get_section_list_counts($ezin_cgi['lang'], $ezin_cgi['section_id'])); } } /* }}} */ /* * Building articles list */ if ($ezin_tmpl_main->isVar('article_items') && ($ezin_db_section != '' || $ezin_db_author != '')) { /* {{{ */ $list_var_keep = $ezin_cgi['output'] != 'section'; $cache_id = $ezin_db_author != '' ? 'U'.@$ezin_db_author['author_id'].@$ezin_cgi['lang'].$ezin_tmpl_key : 'S'.@$ezin_db_section['section_id'].$ezin_tmpl_key.($list_var_keep ? '-VarKeep' : ''); $cache_ar = ezin_cache_load($cache_id); $section_id = $ezin_db_section != '' && (strpos($ezin_db_section['section_type2'], 'global') === false) ? $ezin_db_section['section_id'] : 0; $author_id = $ezin_db_author != '' ? $ezin_db_author['search'] : ''; $limit = $ezin_db_section != '' ? intval($ezin_db_section['section_limit']) : 0; // check sources in section $sources = ezin_get_sources($section_id); if (count($sources) > 0) { $min_time = $sources[0]['normal_refresh_time']; // minutes foreach($sources as $source) { $cache_rss_xml = ezin_cache_load('Source'.intval($source['id'])); $refresh_time = ($cache_rss_xml['var_var'] == 1) ? $source['fail_refresh_time'] : $source['normal_refresh_time']; $min_time = ($min_time > $refresh_time) ? $refresh_time : $min_time; } $min_time *= 60; // seconds // compare time of update for section update if (($cache_ar['timestamp'] + $min_time) < Time()) { ezin_cache_clear($cache_id); $cache_ar = array(); } } if (intval($cache_ar['timestamp']) <= 0) { $articles = ezin_get_article_list($section_id, $author_id, $limit, $ezin_cgi['lang']); $cache_ar['content'] = ezin_build_content_article($articles); global $ezin_cfg; if ($ezin_cfg['article_items_loadmore'] == 1) { $cache_ar['content'] .= '{ ?'.'>
setCode('article_items', $cache_ar['content']); if ($cache_ar['var_var']) { $ezin_tmpl_main->set(ezin_get_article_list_counts($section_id, $author_id, $limit, $ezin_cgi['lang'])); } } /* }}} */ function ezin_build_content_article($articles) { global $ezin_sys, $ezin_cfg, $ezin_tmpl_key; $item = new HTML_Template_Platon($ezin_sys['tmpl']['article_item'].$ezin_tmpl_key, /* article_items on article page? strange, but it *should* work, so we are going to save article variables before article_items vars */ $list_var_keep ? HTML_TEMPLATE_PLATON_METHOD_VAR_KEEP : HTML_TEMPLATE_PLATON_METHOD_NORMAL); $cache_ar['var_var'] = $item->isVar('article_accesses_count') || $item->isVar('article_sessions_count') || $item->isVar('article_message_count'); $content = ''; for ($k = 0; $k < count($articles); $k++) { $item->reload(); ezin_section_link_process($articles[$k], 'article_'); ezin_author_link_process($articles[$k], 'article_'); ezin_article_link_process($articles[$k], $ezin_db_author != ''); ezin_article_counts_process($articles[$k]); ezin_handle_special_tags($articles[$k]['article_ghometext'], $articles[$k]['article_ghometext_flags']); ezin_handle_special_tags($articles[$k]['article_hometext'], $articles[$k]['article_hometext_flags']); ezin_process_text_flags($articles[$k]['article_ghometext'], 'article_ghometext'); ezin_process_text_flags($articles[$k]['article_hometext'], 'article_hometext'); $articles[$k]['article_date'] = date($ezin_cfg['format_date'], $articles[$k]['article_timestamp']); $articles[$k]['article_datetime'] = date($ezin_cfg['format_datetime'], $articles[$k]['article_timestamp']); /* if atitle is empty, set it to title, but if title is empty, remains it unchanged */ if (empty($articles[$k]['article_atitle']) && ! empty($articles[$k]['article_title'])) $articles[$k]['article_atitle'] = $articles[$k]['article_title']; if ($cache_ar['var_var']) { $id = $articles[$k]['article_id']; $item->setVar('article_accesses_count', 'article_accesses_count_'.$id); $item->setVar('article_sessions_count', 'article_sessions_count_'.$id); $item->setVar('article_message_count', 'article_message_count_'.$id); } $item->set($articles[$k]); $content .= '$article_temp = ezin_store_prefix(\'article_\');' .$item->getCode() .'extract($article_temp);'; } //$cache_ar['content'] = Platon::tilde_replace($cache_ar['content']); unset($articles); return $content; } /* * Building featured articles list */ if ($ezin_tmpl_main->isVar('featured_articles_items')) { /* {{{ */ if ($ezin_cfg['featured_articles'] == '1') { $cache_id = 'featured_articles_'.$ezin_cgi['lang']; $cache_ar = ezin_cache_load($cache_id); if (intval($cache_ar['timestamp']) <= 0) { $featured_item = new HTML_Template_Platon($ezin_sys['tmpl']['featured_articles_item'].$ezin_tmpl_key, HTML_TEMPLATE_PLATON_METHOD_NORMAL); $featured_articles = ezin_get_featured_articles_list(intval($ezin_cfg['featured_articles_limit']) ,$ezin_cgi['lang']); $cache_ar['content'] = ''; for ($k = 0; $k < count($featured_articles); $k++) { $featured_item->reload(); ezin_section_link_process($featured_articles[$k], 'featured_article_'); ezin_author_link_process($featured_articles[$k], 'featured_article_'); ezin_article_link_process($featured_articles[$k], $ezin_db_author != '', 'featured_article_'); ezin_article_counts_process($featured_articles[$k]); ezin_handle_special_tags($featured_articles[$k]['featured_article_ghometext'], $featured_articles[$k]['featured_article_ghometext_flags']); ezin_handle_special_tags($featured_articles[$k]['featured_article_hometext'], $featured_articles[$k]['featured_article_hometext_flags']); ezin_process_text_flags($featured_articles[$k]['featured_article_ghometext'], 'featured_article_ghometext'); ezin_process_text_flags($featured_articles[$k]['featured_article_hometext'], 'featured_article_hometext'); $featured_articles[$k]['featured_article_date'] = date($ezin_cfg['format_date'], $featured_articles[$k]['featured_article_timestamp']); $featured_articles[$k]['featured_article_datetime'] = date($ezin_cfg['format_datetime'], $featured_articles[$k]['featured_article_timestamp']); /* if atitle is empty, set it to title, but if title is empty, remains it unchanged */ if (empty($featured_articles[$k]['featured_article_atitle']) && ! empty($featured_articles[$k]['featured_article_title'])) $featured_articles[$k]['featured_article_atitle'] = $featured_articles[$k]['featured_article_title']; $featured_item->set($featured_articles[$k]); $cache_ar['content'] .= $featured_item->getCode(); } //print_r($cache_ar); //$cache_ar['content'] = Platon::tilde_replace($cache_ar['content']); unset($featured_articles); unset($featured_item); ezin_cache_save($cache_id, $cache_ar['content']); } $ezin_tmpl_main->setCode('featured_articles_items', $cache_ar['content']); } else { // if disabled Feature articles in config $ezin_tmpl_main->set(array('featured_articles_items' => '' )); } } /* }}} */ /* * Building calendar */ if ($ezin_tmpl_main->isVar('calendar')) { global $ezin_cfg; global $ezin_db_article; if ($ezin_cfg['calendar'] == '1') { $url = 'http://'.$_SERVER['HTTP_HOST'].$ezin_cfg['url']; require_once 'libpub/calendar/calendar1.php'; $include_JS = ''."\n"; $include_JS .= ''."\n"; $include_JS .= ''."\n"; $include_JS .= ' '."\n"; // ak je clanok otvoreny z kalendara, kalendar ostane v tom mesiaci otvoreny $include_calendar = ($_GET['ezin_tmpl_calendar_source'] == '1') ? getCalendar($ezin_db_article['article_calendar_flag'], "calendar1") : getCalendar(null, "calendar1"); $ezin_tmpl_main->set(array('calendar' => $include_JS.$include_calendar)); } else { $ezin_tmpl_main->set(array('calendar' => '')); } } /* * Building boxes */ $ezin_tmpl_main_vars = $ezin_tmpl_main->getVars(); $boxes = array(); $box_prefix = 'box_'; foreach($ezin_tmpl_main_vars as $var) { if (substr($var, 0, strlen($box_prefix)) == $box_prefix) { $name = substr($var, strlen($box_prefix)); $cache_id = $box_prefix.$ezin_cfg['theme']['name'].'_'.$name; $cache_ar = ezin_cache_load($cache_id); if (ezin_cache_load($cache_id) == false) { $boxes[] = $name; } else { $ezin_tmpl_main->setCode($box_prefix.$name, $cache_ar['content']); } } } if (count($boxes) > 0) { $boxes_val = ezin_get_boxes($boxes); foreach($boxes_val as $val) { $cache_id = $box_prefix.$ezin_cfg['theme']['name'].'_'.$val['name']; $bodytext = $val['bodytext']; ezin_handle_special_tags($bodytext); ezin_process_text_flags($bodytext, 'article_bodytext'); $bodytext = Platon::tilde_replace($bodytext); $template_key = (strlen($val['template_key']) > 0) ? '.'.$val['template_key'] : ''; $box = new HTML_Template_Platon($ezin_sys['tmpl']['box'].$template_key, HTML_TEMPLATE_PLATON_METHOD_VAR_KEEP); $box->set('bodytext', $bodytext); $output = $box->getCode(); ezin_cache_save($cache_id, $output); $ezin_tmpl_main->setCode($box_prefix.$val['name'], $output); } } /* * Creating poll */ if ($ezin_tmpl_main->isVar('poll_question')) { /* {{{ */ // note that for various reasons $ezin_db_section can be empty (zero-length string) // for example when author page is called; so errors are supressed with '@' prefix $ezin_db_poll = ezin_get_poll(@intval($ezin_db_section['section_id']), $ezin_cgi['lang']); if ($ezin_db_poll != '') { $ezin_tmpl_main->set($ezin_db_poll); } if ($ezin_db_poll != '' && $ezin_tmpl_main->isVar('poll_answer_items')) { $cache_id = 'P'.@$ezin_db_poll['poll_id']; $cache_ar = ezin_cache_load($cache_id); if (intval($cache_ar['timestamp']) <= 0) { $item = new HTML_Template_Platon($ezin_sys['tmpl']['poll_answer_item'].$ezin_tmpl_key, HTML_TEMPLATE_PLATON_METHOD_VAR_KEEP); $cache_ar['var_var'] = $item->isVar('poll_answer_votes') || $item->isVar('poll_answer_pct'); $cache_ar['var_var'] = 0; // REMOVE ME / FIX ME $answers = ezin_get_poll_answer_list($ezin_db_poll['poll_id']); $cache_ar['content'] = ''; for ($k = 0; $k < count($answers); $k++) { $item->reload(); $answers[$k]['poll_answer_link'] = ezin_get_link('PA', $answers[$k]['poll_answer_id']); if ($cache_ar['var_var']) { $id = $answers[$k]['poll_answer_id']; $item->setVar('poll_answer_votes', 'poll_answer_votes_'.$id); $item->setVar('poll_answer_pct', 'poll_answer_pct_'.$id); } $item->set($answers[$k]); $cache_ar['content'] .= $item->getCode(); } //$cache_ar['content'] = Platon::tilde_replace($cache_ar['content']); unset($answers); ezin_cache_save($cache_id, $cache_ar['content'], $cache_ar['var_var']); } $ezin_tmpl_main->setCode('poll_answer_items', $cache_ar['content']); if ($cache_ar['var_var']) { $ezin_tmpl_main->set(ezin_get_poll_answer_list_counts($ezin_db_poll['poll_id'])); } } } /* }}} */ /* * Generate HTML map */ if ($ezin_tmpl_main->isVar('ezin_htmlmap')) { /* {{{ */ $ezin_tmpl_main->set(array('ezin_htmlmap' => ezin_get_htmlmap($ezin_cgi['lang']))); } /* }}} */ /* * Gets and substitute current article parameters (if article is set) */ if ($ezin_db_article != '' && ! empty($ezin_cgi['article_id'])) { /* {{{ */ ezin_handle_include($ezin_db_article); ezin_author_link_process($ezin_db_article, 'article_'); ezin_section_link_process($ezin_db_article, 'article_'); ezin_article_link_process($ezin_db_article); ezin_article_counts_process($ezin_db_article); // This removes width="..." attribute from tag at article_print page // if image is less than 10% smaller or bigger if ($ezin_cgi['output'] == 'article_print') { // {{{ preg_match_all('|\s]+)([^>]*width=([^>\s]+)[^>]*)>|i', $ezin_db_article['article_bodytext'], $matches, PREG_SET_ORDER); foreach ($matches as $key => $val) { $treshold = 10; // percent // TODO: should be configurable $scaleskip = false; $file = $val[2]; $width = $val[4]; $width = preg_replace('/["\']/', '', trim($width)); $pct = $width[strlen($width) - 1] == '%'; $width = intval($width); if ($width <= 0) { continue; } if ($pct) { if (abs(100 - $width) <= $treshold) { $scaleskip = true; } } else { $ori_width = ezin_get_upload_image_width($file); if ($width > 0 && $ori_width > 0) { $div = $width / $ori_width; if (abs(1 - $div) * 100 <= $treshold) { $scaleskip = true; } } } if ($scaleskip) { $ezin_db_article['article_bodytext'] = preg_replace( '#]*)(width=("[^<>"]+"|[^<>\s]+))(|\s+[^<>]*)>#i', '', $ezin_db_article['article_bodytext']); } } } // }}} ezin_handle_special_tags($ezin_db_article['article_hometext'], $ezin_db_article['article_hometext_flags']); ezin_handle_special_tags($ezin_db_article['article_bodytext'], $ezin_db_article['article_bodytext_flags']); ezin_process_text_flags($ezin_db_article['article_hometext'], 'article_hometext'); ezin_process_text_flags($ezin_db_article['article_bodytext'], 'article_bodytext'); $ezin_db_article['article_date'] = date($ezin_cfg['format_date'], $ezin_db_article['article_timestamp']); $ezin_db_article['article_datetime'] = date($ezin_cfg['format_datetime'], $ezin_db_article['article_timestamp']); /* if atitle is empty, set it to title, but if title is empty, remains it unchanged */ if (empty($ezin_db_article['article_atitle']) && ! empty($ezin_db_article['article_title'])) { $ezin_db_article['article_atitle'] = $ezin_db_article['article_title']; } $ezin_tmpl_main->set($ezin_db_article); /* * Build message list for current article. */ if ($ezin_tmpl_main->isVar('message_items')) { if ($ezin_cgi['output'] == 'message_selected_list') { // selected lists are not cached $items = ezin_message_process(0, 0, 0); } else if (($items = ezin_cache_load_content('a'.@$ezin_db_article['article_id'])) === false) { $items = ezin_message_process(0, 0, 0); ezin_cache_save('a'.@$ezin_db_article['article_id'], $items); } $ezin_tmpl_main->setCode('message_items', $items); } if ($ezin_tmpl_main->isVar('message_full_items')) { if ($ezin_cgi['output'] == 'message_selected_list') { // selected lists are not cached $items = ezin_message_process(1, 0, 0); } else if (($items = ezin_cache_load_content('AF'.@$ezin_db_article['article_id'])) === false) { $items = ezin_message_process(1, 0, 0); ezin_cache_save('AF'.@$ezin_db_article['article_id'], $items); } $ezin_tmpl_main->setCode('message_full_items', $items); } } /* }}} */ /* * Gets and substitute current message parameters (if message is set) */ if (! is_array($ezin_cgi['message_id']) && ! empty($ezin_cgi['message_id'])) { /* {{{ */ $ezin_db_message = ezin_get_message($ezin_cgi['message_id']); ezin_handle_special_tags($ezin_db_message['message_article_bodytext'], $ezin_db_message['message_article_bodytext_flags']); ezin_handle_special_tags($ezin_db_message['message_article_hometext'], $ezin_db_message['message_article_hometext_flags']); ezin_process_text_flags($ezin_db_message['message_message'], 'message'); ezin_process_text_flags($ezin_db_message['message_article_hometext'], 'article_hometext'); ezin_process_text_flags($ezin_db_message['message_article_bodytext'], 'article_bodytext'); $ezin_db_message['message_date'] = date($ezin_cfg['format_date'], $ezin_db_message['message_timestamp']); $ezin_db_message['message_datetime'] = date($ezin_cfg['format_datetime'], $ezin_db_message['message_timestamp']); $ezin_tmpl_main->set($ezin_db_message); if (strlen(trim(@$ezin_cgi['message_reply_subject'])) <= 0) { $ezin_cgi['message_reply_subject'] = $ezin_db_message['message_subject']; if (strncasecmp('RE:', $ezin_cgi['message_reply_subject'], 3)) $ezin_cgi['message_reply_subject'] = 'RE: ' . $ezin_cgi['message_reply_subject']; } } else { $ezin_tmpl_main->set('message_id', ''); } /* }}} */ if ($ezin_cgi['output'] == 'message') { /* {{{ */ $ezin_tmpl_main->set(array( // Message reply fields 'message_reply_subject' => @$ezin_cgi['message_reply_subject'], 'message_reply_message' => @$ezin_cgi['message_reply_message'], 'message_reply_author' => isset($ezin_cgi['message_reply_author']) ? $ezin_cgi['message_reply_author'] : @$_COOKIE['ezin_author_cookie'], 'message_reply_email' => isset($ezin_cgi['message_reply_email']) ? $ezin_cgi['message_reply_email'] : @$_COOKIE['ezin_email_cookie'], 'message_reply_homepage' => isset($ezin_cgi['message_reply_homepage']) ? $ezin_cgi['message_reply_homepage'] : (isset($_COOKIE['ezin_homepage_cookie']) ? $_COOKIE['ezin_homepage_cookie'] : 'http://'), // Message save flags 'message_save_ok' => intval(@$ezin_cgi['message_save_ok']), 'message_save_error' => intval(@$ezin_cgi['message_save_error']), 'message_save_unknown_error' => intval(@$ezin_cgi['message_save_unknown_error']), 'message_save_antispam_protection' => intval(@$ezin_cgi['message_save_antispam_protection']), 'message_save_flood_protection' => intval(@$ezin_cgi['message_save_flood_protection']), 'message_save_subject_missing' => intval(@$ezin_cgi['message_save_subject_missing']), 'message_save_author_missing' => intval(@$ezin_cgi['message_save_author_missing']), 'message_save_message_missing' => intval(@$ezin_cgi['message_save_message_missing']), )); } /* }}} */ ezin_substitute_basic_properties($ezin_tmpl_main); /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */ ?>