* 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/functions.inc.php,v 1.145 2026/11/06 11:25:59 nepto Exp $ */ function ezin_eval($evalcode) /* {{{ */ { return @eval($evalcode); } /* }}} */ function ezin_str_rev_args() /* {{{ */ { $str = ''; $cnt = func_num_args(); for ($i = 0; $i < $cnt; $i++) { $str = func_get_arg($i).$str; } return $str; } /* }}} */ /* * Line wrap function */ function ezin_process_text_flags(&$str, $type, $special = 0) /* {{{ */ { global $ezin_cfg; $http_substs = stristr(@$ezin_cfg['flags_'.$type], 'H') != false; $www_substs = stristr(@$ezin_cfg['flags_'.$type], 'W') != false; $email_substs = stristr(@$ezin_cfg['flags_'.$type], 'E') != false; $line_wrap_p = stristr(@$ezin_cfg['flags_'.$type], 'P') != false; $line_wrap_br = stristr(@$ezin_cfg['flags_'.$type], 'B') != false; $max_word_size = intval($ezin_cfg['message_max_word_size']); if ($max_word_size <= 0) { $max_word_size = 60; // set to 60 even if disabled } /* Links substitution code borrowed from phpBB2, http://www.phpbb.com/ See make_clickable() in includes/bbcode.php for more info. */ // pad it with a space so we can match things at the start of the 1st line. $str = ' ' . $str; $http_substs && $str = preg_replace_callback( "#([\n ])([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#i", function($matches) { return $matches[1].''.$matches[2].'://'.Platon::pretty_substr($matches[3],$max_word_size).''; }, $str); $www_substs && $str = preg_replace( "#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", "\\1www.\\2.\\3\\4", $str); $email_substs && $str = preg_replace_callback( "#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+)#i", function($matches) { return $matches[1].Platon::escape_email($matches[2].'@'.$matches[3], 'hypertext_link'); }, $str); if ($line_wrap_p) { if ($special) { $str = preg_replace('/[\n\r]{3,}/m', "\n

", $str); $str = preg_replace('/[\n]{2,}/m', "\n

", $str); } else { $str = preg_replace('/[\n\r]{3,}/m', "\n

", $str); } } if ($line_wrap_br) { $str = nl2br($str); } // Remove our padding $str = substr($str, 1); } /* }}} */ function ezin_get_special_tags_flags($str) /* {{{ */ { $ret = ''; preg_match('|]+>|i', $str) && $ret .= 'G'.'I'; // we need as well preg_match('|]+>|i', $str) && $ret .= 'f'; preg_match('|]+>|i', $str) && $ret .= 'i'; preg_match('|]+>|i', $str) && $ret .= 'I'; preg_match('|]+>|i', $str) && $ret .= 'L'; preg_match('|]+>|i', $str) && $ret .= 'E'; preg_match('|]+>|i', $str) && $ret .= 'R'; preg_match('|]+>|i', $str) && $ret .= 'M'; preg_match('|]+>|i', $str) && $ret .= 'U'; preg_match('|]+>|i', $str) && $ret .= 'S'; preg_match('|]+>|i', $str) && $ret .= 'A'; preg_match('|]+>|i', $str) && $ret .= 'A'; // same as articles preg_match('|]+>|i', $str) && $ret .= 'P'; preg_match('|]+>|i', $str) && $ret .= 'P'; preg_match('|]+>|i', $str) && $ret .= 'N'; return $ret; } /* }}} */ function ezin_handle_include(&$article_ar) /* {{{ */ { // TODO: made INCLUDE works with ACCESS_KEY (not only ID) while (preg_match_all('|\s]+)>|si', @$article_ar['article_bodytext'], $matches)) { $matches = array_unique($matches[1]); if (count($matches) <= 0) { break; } $pattern = array(); $replacement = array(); foreach ($matches as $article_id) { $subst_article = ezin_get_article($article_id); $pattern[] = '||i'; $replacement[] = @$subst_article['article_bodytext']; $article_ar['article_bodytext_flags'] .= @$subst_article['article_bodytext_flags']; } $article_ar['article_bodytext'] = preg_replace($pattern, $replacement, $article_ar['article_bodytext']); } } /* }}} */ function ezin_handle_special_tags(&$str, $mask = 'GfiILERMUSAP') /* {{{ */ { static $ezin_url = null; static $repository_url = null; static $link_file_type = null; global $ezin_cgi; if ($ezin_url == null) { global $ezin_sys; global $ezin_cfg; $ezin_url = Platon::append_slash($ezin_cfg['url']); $repository_url = Platon::append_slash($ezin_url.$ezin_sys['dir']['upload']); $link_file_type = $ezin_cfg['link_file_type']; } $pattern = array(); $replace = array(); $rpttr = array(); $rrplc = array(); $included_jquery = false; $jquery = ''."\n"; $included_lightbox = false; $lightbox = ''."\n" .''."\n" .''."\n"; if (strpos($mask, 'G') !== false) { /* {{{ */ global $ezin_sys, $ezin_cfg; /* TODO: caching is required here */ preg_match_all('|\s]+)([^>]*)>|i', $str, $matches, PREG_SET_ORDER); foreach ($matches as $key => $val) { $directory = $val[1]; $attrs = $val[2]; $g_pattern = '||i'; $g_replace = ''; $directory = Platon::append_slash($directory); $full_path = Platon::append_slash($ezin_sys['dir']['root']); $full_path.= Platon::append_slash($ezin_cfg['upload']['dir']).$directory; if (!is_dir($full_path) || !is_readable($full_path)) { continue; } $handler = opendir($full_path); $img_ar = array(); while ($file = readdir($handler)) { $img_ar[] = $file; } sort($img_ar); foreach ($img_ar as $file) { // if $file isn't this directory or its parent, // add it to the replacement if ($file[0] != '.' && is_readable($full_path.$file) && ! is_dir($full_path.$file)) { $g_replace .= "$file\n"; } } $id = 'gal-'.rand(1,999999); switch ($ezin_cfg['gallery_type']) { case 'javascript': $include_jquery = ''; if (!$included_jquery) { $include_jquery = $jquery; $included_jquery = true; } $include_lightbox = ''; if (!$included_lightbox) { $include_lightbox = $lightbox; $included_lightbox = true; } $g_replace = $include_jquery .$include_lightbox .''."\n" .'

'."\n" .$g_replace .'
'."\n"; break; case 'default': default: } unset($img_ar); closedir($handler); $str = preg_replace($g_pattern, $g_replace, $str); } } /* }}} */ // Resize images if neccessary if (strpos(strtolower($mask), 'i') !== false) { /* {{{ */ preg_match_all('/\s]+)([^<>]*width=([^<>\s]+)[^<>]*)>/i', $str, $matches, PREG_SET_ORDER); foreach ($matches as $key => $val) { $old_file = $val[2]; $width = $val[4]; $new_file = ezin_scale_upload_image($old_file, $width); if ($new_file != false && $new_file != $old_file) { switch (strtolower($val[1])) { case '-link': $id_image = 'img-'.rand(1,999999); switch ($ezin_cfg['gallery_type']) { case 'javascript': $include_jquery = ''; if (!$included_jquery) { $include_jquery = $jquery; $included_jquery = true; } $include_lightbox = ''; if (!$included_lightbox) { $include_lightbox = $lightbox; $included_lightbox = true; } $include_js = $include_jquery .$include_lightbox .''."\n"; break; case 'default': default: $include_js = ''; } $pattern[] = '|]*)width='.$width.'([^<>]*)>([^<>]*)|i'; $replace[] = $include_js."\\3"; $pattern[] = '|]*)width='.$width.'([^<>]*)>|i'; $replace[] = $include_js.""; $mask .= 'R'; break; case '-link-gal': $pattern[] = '|]*)width='.$width.'([^<>]*)>([^<>]*)|i'; $replace[] = "\\3"; $pattern[] = '|]*)width='.$width.'([^<>]*)>|i'; $replace[] = ""; $mask .= 'R'; break; default: $pattern[] = '|]*)width='.$width.'([^<>]*)>|i'; $replace[] = ""; } } //echo "FILE: $val[2], WIDTH: $val[3], newfile: $new_file, RET: $ret
"; } } /* }}} */ if (strpos($mask, 'f') !== false) { /* {{{ */ // URL in http:// form $opentag = ezin_str_rev_args(strrev('\s]+//:\w{3,6})','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = strrev(''."\n" .'1\\'); $rrplc[] = strrev(''."\n" .''); // URL without http:// $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = strrev(''."\n" .'1\\'); $rrplc[] = strrev(''."\n" .''); } /* }}} */ if (strpos($mask, 'I') !== false) { /* {{{ */ $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*([^<>]*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = strrev('1\\'); $rrplc[] = strrev(''); } /* }}} */ if (strpos(strtolower($mask), 'i') !== false) { /* {{{ */ // URL in http:// form $opentag = ezin_str_rev_args(strrev('\s]+//:\w{3,6})','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*([^<>]*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('1\\'); $rrplc[] = ezin_str_rev_args(strrev(''); // URL in /something form $opentag = ezin_str_rev_args(strrev('\s]*)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*([^<>]*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('1\\'); $rrplc[] = ezin_str_rev_args(strrev(''); // URL without http:// $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*([^<>]*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('1\\'); $rrplc[] = ezin_str_rev_args(strrev(''); } /* }}} */ if (strpos($mask, 'L') !== false) { /* {{{ */ // URL in http:// form $opentag = ezin_str_rev_args(strrev('\s]+//:\w{3,6})','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); // URL in /something form $opentag = ezin_str_rev_args(strrev('\s]*)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); // URL without http:// $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); } /* }}} */ if (strpos($mask, 'E') !== false) { /* {{{ */ // URL in http:// form $opentag = ezin_str_rev_args(strrev('\s]+//:\w{3,6})','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); // URL in /something form -- Bit problematic... $opentag = ezin_str_rev_args(strrev('\s]*)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); // URL without http:// $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); } /* }}} */ if (strpos($mask, 'R') !== false) { /* {{{ */ $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); } /* }}} */ if (strpos($mask, 'M') !== false) { /* {{{ */ $str2 = strrev($str); $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $str2_pattern = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $str2 = preg_replace_callback($str2_pattern, function($matches) { return ezin_str_rev_args(strrev('',$matches[1],strrev('')); }, $str2); $str2_pattern = sprintf('|%s|i', $opentag); $str2 = preg_replace_callback($str2_pattern, function($matches) { return strrev(Platon::escape_email(strrev($matches[2]), 'hypertext_link', $matches[1])); }, $str2); $str = strrev($str2); } /* }}} */ if (strpos($mask, 'S') !== false) { /* {{{ */ switch($link_file_type) { case 0: $sub_url = '?ezin_section_id='; break; case 1: $sub_url = 'section.php?'; break; case 2: $sub_url = ''; break; } $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); } /* }}} */ if (strpos($mask, 'A') !== false) { /* {{{ */ switch($link_file_type) { case 0: $sub_url = '?ezin_article_id='; break; case 1: $sub_url = 'article.php?'; break; case 2: $sub_url = ''; break; } $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); } /* }}} */ if (strpos($mask, 'P') !== false) { /* {{{ */ switch($link_file_type) { case 0: $sub_url = '?ezin_print=1&ezin_article_id='; break; case 1: $sub_url = 'print.php?'; break; case 2: $sub_url = 'print/'; break; } $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); } /* }}} */ if (strpos($mask, 'U') !== false) { /* {{{ */ switch($link_file_type) { case 0: $sub_url = '?ezin_author_id='; break; case 1: $sub_url = 'author.php?'; break; case 2: $sub_url = 'author/'; break; } $opentag = ezin_str_rev_args(strrev('\s]+)','([^<>]*?)','>'); $rpttr[] = sprintf('|%s\s*(.*?)\s*%s|si', strrev(''), $opentag); $rpttr[] = sprintf('|%s|i', $opentag); $rrplc[] = ezin_str_rev_args(strrev('','\\1',strrev('')); $rrplc[] = ezin_str_rev_args(strrev('','\\2',strrev('')); } /* }}} */ // Normal replacement if (count($pattern) > 0) { $str = preg_replace($pattern, $replace, $str); } // Reversed replacement if (count($rpttr) > 0) { $str = strrev($str); $cnt = count($rpttr); for ($i = 0; $i < $cnt; $i++) { $snew = preg_replace($rpttr[$i], $rrplc[$i], $str); if (strlen($snew) > 0) { $str = $snew; } } $str = strrev($str); } } /* }}} */ function ezin_message_html_process(&$text) /* {{{ */ { global $ezin_cfg; if (! is_array($ezin_cfg['message_allowed_tags'])) { $ezin_cfg['message_allowed_tags'] = ezin_parse_allowed_tags($ezin_cfg['message_allowed_tags']); } $max_word_size = intval($ezin_cfg['message_max_word_size']); $ar = preg_split('|(<[^<>]+>)|', $text, -1, PREG_SPLIT_DELIM_CAPTURE); $text = ''; for ($k = 0; $k < count($ar); $k++) { if ($k & 1) { $ar2 = preg_split('|\s+|', trim(substr($ar[$k], 1, strlen($ar[$k]) - 2))); $tag = strtolower(trim($ar2[0])); $opt = array(); $close = $tag[0] == '/'; $close && $tag = substr($tag, 1); if (in_array($tag, array_keys($ezin_cfg['message_allowed_tags']))) { if ($close) { $text .= ""; continue; } $text .= '<'.$tag; foreach ($ar2 as $attr) { @list($attr_name, $attr_value) = explode('=', $attr, 2); $attr_name = strtolower($attr_name); $attr_value = str_replace('"', '', $attr_value); if (in_array($attr_name, $ezin_cfg['message_allowed_tags'][$tag]['allowed'])) { $text .= " $attr_name=\"$attr_value\""; } } count($ezin_cfg['message_allowed_tags'][$tag]['append']) && $text .= ' '.join(' ', $ezin_cfg['message_allowed_tags'][$tag]['append']); $text .= '>'; continue; } } if ($max_word_size > 0) { $last_space_pos = -1; $cur_space_pos = 0; while ($cur_space_pos + 1 < strlen($ar[$k])) { $cur_space_pos = strpos($ar[$k], ' ', $last_space_pos + 1); $cur_space_pos === false && $cur_space_pos = strlen($ar[$k]); if ($cur_space_pos - $last_space_pos - 1 > $max_word_size) { $ar[$k] = substr($ar[$k], 0, $last_space_pos + $max_word_size + 1) .' '.substr($ar[$k], $last_space_pos + $max_word_size + 1); $cur_space_pos = $last_space_pos = $last_space_pos + $max_word_size + 1; } else { $last_space_pos = $cur_space_pos; } } } $text .= Platon::htmlspecialchars($ar[$k]); } // TODO: optimalization using arrays $text = str_replace('&#8220;', '“', $text); // left quotes $text = str_replace('&#8221;', '”', $text); // right quotes $text = str_replace('&#8211;', '–', $text); // nice long dash $text = str_replace('&#8230;', '…', $text); // hellip (...) $text = str_replace('&#8222;', '„', $text); // ? } /* }}} */ function ezin_parse_allowed_tags($str) /* {{{ */ { $ret = array(); $tmp_ar = preg_split('|\s+|', $str); foreach ($tmp_ar as $val) { $tmp_ar2 = preg_split('|([:;])|', $val, -1, PREG_SPLIT_DELIM_CAPTURE); $tag_opts = array('allowed' => array(), 'append' => array()); $tag_name = trim($tmp_ar2[0]); if ($tag_name == '') continue; for ($i = 1; $i < count($tmp_ar2); $i++) { $mode = $tmp_ar2[$i]; $i++; $opt = trim($tmp_ar2[$i]); if ($opt == '') continue; $tag_opts[$mode == ';' ? 'append' : 'allowed'][] = $opt; } $ret[$tag_name] = $tag_opts; } return $ret; } /* }}} */ function ezin_store_prefix($prefix) /* {{{ */ { $ret = array(); $len = strlen($prefix); foreach ($GLOBALS as $key => $val) { if (substr($key, 0, $len) == $prefix) { $ret[$key] = $val; } } return $ret; } /* }}} */ function ezin_normalize_rss2_string($string) /* {{{ */ { $string = strip_tags($string); $string = Platon::undo_htmlspecialchars($string); $string = str_replace('&', '&', $string); return $string; } /* }}} */ function ezin_remove_encoding($string) /* {{{ */ { global $ezin_cfg; // UTF-8 migrated to ISO-8859-2 $encoding = strtolower($ezin_cfg['encoding']); if ($encoding == 'utf-8') { $string = function_exists('recode') ? recode('utf-8..iso-8859-2', $string) : iconv('UTF-8', 'ISO-8859-2', $string); $encoding = 'iso-8859-2'; //echo "/$string/"; } // copy/paste from libplaton library // TODO fix chars 'windows-1250' and `iso-8859-2' static $charsets = array( 'ascii' => 'aAaAcCdDeEeEiIlLlLnNoOoOoOrRrRsStTuUuUuUyYzZ', // 'windows-1250' => '���������������ž������������ؚ����������ݞ�', // 'iso-8859-2' => '���������������ŵ������������ع����������ݾ�' 'windows-1250' => 'ၤĨȯϩɫ˭ͥž¼򒳓��8ؚŠúڼܹٽݞŽ', 'iso-8859-2' => 'ၤĨȯϩɬ̭ͥŵ¥򒳓��8ع©»«úڼܹٽݾ®' ); if (isset($charsets[$encoding])) { $string = strtr($string, $charsets[$encoding], $charsets['ascii']); } else { // this is most likely not working :-) $string = function_exists('recode') ? recode($ezin_cfg['encoding'].'..ascii', $string) : iconv(strtoupper($ezin_cfg['encoding']), 'ASCII', $string); } return $string; } /* }}} */ /* * Register access function */ function ezin_register_access($destroy = 1, $print = 1) /* {{{ */ { global $ezin_cfg; global $ezin_cgi; global $ezin_weblog; $start_time = Platon::get_mtime(); $value = 'ezin:'.$ezin_cfg['abbreviation'] .':'; if (! empty($ezin_cgi['author_id'])) { $value .= 'U:'.$ezin_cgi['section_id']; } else { $value .= $ezin_cgi['section_id']; $value .= ! empty($ezin_cgi['article_id']) ? ','.$ezin_cgi['article_id'] : ''; } $ezin_weblog->enableRawLog(); $ezin_weblog->registerAccess($value); if ($destroy) { $ezin_weblog->destroy(); } if ($print) { printf(''."\n", Platon::get_mtime() - $start_time); } } /* }}} */ /* * Weblog counts getting */ function ezin_get_weblog_count($count_type, $id) /* {{{ */ { global $ezin_cfg; global $ezin_weblog; $weblog_count = 0; if ($ezin_weblog != false) { $section_type = ! strncmp($count_type, 'section', 7); $accesses_type = substr($count_type, -14) == 'accesses_count'; $raw_type = ! strncmp(substr($count_type, -18), 'raw', 3); $value = 'ezin:'.$ezin_cfg['abbreviation'].':'; $value .= ! $section_type ? '%,'.$id : ($raw_type ? $id.',%' : $id); //echo 'value = '.$value; $ezin_weblog->enableRawLog(); for ($j = 0; $j < 2; $j++) { $weblog_count += ($accesses_type ? $ezin_weblog->getAccessesCount(array('value' => $value)) : $ezin_weblog->getSessionsCount(array('value' => $value))); if (is_object($weblog_count)) { /* PEAR error object */ $weblog_count = 0; break; } $ezin_weblog->disableRawLog(); } } return $weblog_count; } /* }}} */ /* * Link changing */ function ezin_get_schema() /* {{{ */ { if (! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') { return 'https'; } return @$_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http'; } /* }}} */ function ezin_get_link($type = 'S', $id = 0, $full_url = 0, $lang = '', $force_lang = 0) /* {{{ */ { global $ezin_cfg; $url_prefix = $full_url ? 'http://'.$_SERVER['HTTP_HOST'] : ''; if (! empty($id)) { $append_params = ''; $append_url = ''; switch ($type) { default: case 'A-show-all': $script = 'article'; $append_params = '&ezin_show_all=1'; break; case 'A-add-new': $script = 'article'; $append_params = '&ezin_add_new=1'; break; case 'A': $script = 'article'; $append_url = 'sekcia/'; break; case 'S': $script = 'section'; break; case 'U': $script = 'author'; $append_url = 'author/'; break; case 'P': $script = 'print'; $append_url = 'print/'; break; case 'M': $script = 'message'; $append_url = 'message/'; break; case 'PA': $script = 'poll_answer'; break; } if ($ezin_cfg['link_file_type'] == 1 && $type != 'PA') { return $url_prefix.$ezin_cfg['url'] .$script.'.php' .'?'.Platon::htmlspecialchars($id) .Platon::htmlspecialchars($append_params) .($force_lang && $lang != '' ? Platon::htmlspecialchars('&ezin_lang='.$lang) : ''); } if ($ezin_cfg['link_file_type'] == 2 && $type != 'PA') { $append_url = ''; switch ($type) { default: case 'A-show-all': case 'A-add-new': case 'A': $ar = ezin_validate_IDs(array( 'section_id' => 0, 'article_id' => $id, 'message_id' => 0)); $append_url = strlen($ar['section_access_key']) > 0 ? $ar['section_access_key'].'/' : $ar['section_id'].'/'; if ($ar['section_access_key'] == $id) { $append_url = ''; } break; case 'S': break; case 'U': $append_url = 'author/'; break; case 'P': $append_url = 'print/'; break; case 'M': $append_url = 'message/'; break; } return $url_prefix.$ezin_cfg['url'] .$append_url.Platon::htmlspecialchars($id) .($force_lang && $lang != '' ? Platon::htmlspecialchars('&ezin_lang='.$lang) : ''); } return $url_prefix.$ezin_cfg['url'].'?ezin_' .($script == 'print' ? 'article' : $script) .(intval($id) > 0 ? '_id=' : '_key=').Platon::htmlspecialchars($id) .Platon::htmlspecialchars($append_params) .($force_lang && $lang != '' ? Platon::htmlspecialchars('&ezin_lang='.$lang) : '') .($script == 'print' ? Platon::htmlspecialchars('&ezin_print=1') : ''); } return $url_prefix.$ezin_cfg['url'] .($lang != '' ? Platon::htmlspecialchars('?ezin_lang='.$lang) : ''); } /* }}} */ function ezin_adjust_link($link, $full_url = 0, $lang_var = 0) /* {{{ */ { if (! (strncmp($link, 'http://', 7) && strncmp($link, 'https://', 8))) return $link; global $ezin_cgi; global $ezin_cfg; /* NOTE/TODO: There was some errors in the past: * error_message: Undefined index: HTTP_HOST */ $url_prefix = $full_url ? 'http://'.$_SERVER['HTTP_HOST'] : ''; if ($link[0] == '/') { $link = $ezin_cfg['url'] . substr($link, 1); } else if ($full_url) { if (($pos = strrpos($_SERVER['REQUEST_URI'], '/')) !== false) { $url_prefix .= substr($_SERVER['REQUEST_URI'], 0, $pos + 1); } } $link = $url_prefix . $link; if ($lang_var && strlen(@$ezin_cgi['lang']) > 0) { $link .= strpos($link, '?') === false ? '?' : '&'; $link .= 'ezin_lang='.$ezin_cgi['lang']; } return $link; } /* }}} */ /* * Elements link handling */ function ezin_author_link_process(&$author, $prefix = '') /* {{{ */ { $author[$prefix.'author_id2'] = empty($author[$prefix.'author_access_key']) ? $author[$prefix.'author_id'] : $author[$prefix.'author_access_key']; $author[$prefix.'author_link'] = ezin_get_link('U', $author[$prefix.'author_id2']); $author[$prefix.'author_name'] = Platon::tilde_replace($author[$prefix.'author_name']); if (isset($author[$prefix.'author_description'])) { $author[$prefix.'author_description'] = Platon::tilde_replace($author[$prefix.'author_description']); } } /* }}} */ function ezin_author_counts_process(&$author) /* {{{ */ { $ar = null; foreach (array('author_sessions_count', 'author_accesses_count') as $key) { if (! isset($author[$key])) { $ar[$key] = 0; } } if ($ar !== null) { ezin_set_author_counts($author['author_id'], $ar); } } /* }}} */ function ezin_handle_section_link($section_link) /* {{{ */ { $relative_link = ezin_adjust_link($section_link, 0); $request_uri = $_SERVER['REQUEST_URI']; if (strncmp($request_uri, $relative_link, strlen($relative_link))) { // current URL doesn't compliant section link, make HTTP/1.1 redirect $absolute_link = ezin_adjust_link($section_link, 1, 1 /* not needed, just for sure */); Platon::redirect($absolute_link); } } /* }}} */ function ezin_section_link_process(&$section, $prefix = '') /* {{{ */ { $section[$prefix.'section_id2'] = empty($section[$prefix.'section_access_key']) ? $section[$prefix.'section_id'] : $section[$prefix.'section_access_key']; $section[$prefix.'section_link'] = empty($section[$prefix.'section_link']) ? ezin_get_link('S', $section[$prefix.'section_id2']) : ezin_adjust_link($section[$prefix.'section_link']); $section[$prefix.'section_name'] = Platon::tilde_replace($section[$prefix.'section_name']); $section[$prefix.'section_loadmore'] = 'ezin_section_loadmore(this, '.$section[$prefix.'section_id'].');'; } /* }}} */ function ezin_section_counts_process(&$section) /* {{{ */ { $weblog_ar = array(); foreach (array('section_sessions_count', 'section_accesses_count', 'section_raw_sessions_count', 'section_raw_accesses_count') as $weblog_val) { /* raw counts must go after normal counts */ if (intval(@$section[$weblog_val]) < 0) { $weblog_ar[$weblog_val] = ezin_get_weblog_count($weblog_val, $section['section_id']); if (preg_match('/^section_raw_(.*)$/', $weblog_val, $matches)) { $weblog_ar[$weblog_val] += $section['section_'.$matches[1]]; } $section[$weblog_val] = $weblog_ar[$weblog_val]; } } if (count($weblog_ar) > 0) { ezin_set_section_counts($section['section_id'], $weblog_ar); } } /* }}} */ function ezin_article_link_process(&$article, $author_page = 0, $prefix = 'article_') /* {{{ */ { $article[$prefix.'id2'] = empty($article[$prefix.'access_key']) ? $article[$prefix.'id'] : $article[$prefix.'access_key']; $article[$prefix.'add_new_link'] = ezin_get_link('A-add-new', $article[$prefix.'id2']); $article[$prefix.'show_all_link'] = ezin_get_link('A-show-all', $article[$prefix.'id2']); $article[$prefix.'link'] = (strtolower(substr($article[$prefix.'access_key'], 0, 7)) == 'http://' || strtolower(substr($article[$prefix.'access_key'], 0, 8)) == 'https://') ? $article[$prefix.'access_key'] : ezin_get_link('A', $article[$prefix.'id2']); $article[$prefix.'print_link'] = ezin_get_link('P', $article[$prefix.'id2']); $article[$prefix.'title'] = Platon::tilde_replace($article[$prefix.'title']); $article[$prefix.'atitle'] = Platon::tilde_replace($article[$prefix.'atitle']); $article[$prefix.'hometext'] = Platon::tilde_replace($article[$prefix.'hometext']); if (isset($article[$prefix.'bodytext'])) { $article[$prefix.'bodytext'] = Platon::tilde_replace($article[$prefix.'bodytext']); } if ($author_page) { $article[$prefix.'link'] .= '&ezin_author_id='.$article[$prefix.'author_id']; } if (strtolower(substr($article[$prefix.'id'], 0, 6)) == 'source') { $article[$prefix.'external'] = $article[$prefix.'link']; $article[$prefix.'link'] = ezin_get_link('A', $article[$prefix.'id']); } } /* }}} */ function ezin_article_counts_process(&$article) /* {{{ */ { $weblog_ar = null; foreach (array('article_sessions_count', 'article_accesses_count') as $weblog_val) { if (intval(@$article[$weblog_val]) < 0) { $weblog_ar[$weblog_val] = ezin_get_weblog_count($weblog_val, $article['article_id']); $article[$weblog_val] = $weblog_ar[$weblog_val]; } } if (isset($weblog_ar)) { ezin_set_article_counts($article['article_id'], $weblog_ar); } if (intval(@$article['article_message_count']) < 0) { $message_count = ezin_get_message_count($article['article_id']); ezin_update_message_count($article['article_id'], 0, $message_count); $article['article_message_count'] = $message_count; } } /* }}} */ /* * Upload directory manipulation functions */ function ezin_lookup_upload_file($file, $default_str = false) /* {{{ */ { global $ezin_cfg; $real_file = Platon::append_slash($ezin_cfg['upload']['dir']).$file; if (file_exists($real_file) && is_file($real_file)) { return Platon::append_slash($ezin_cfg['upload']['url']).$file; } return $default_str; } /* }}} */ function ezin_lookup_upload_file_ext_ar($dir, $file_wo_ext = '', $default_str = false, $extensions = array()) /* {{{ */ { if (strlen($file_wo_ext) <= 0) { // just filename was passed return ezin_lookup_upload_file($dir, $default_str); } $dir = Platon::append_slash($dir); foreach ($extensions as $ext) { $file = $dir.$file_wo_ext; strlen($ext) > 0 && $file .= ".$ext"; $url = ezin_lookup_upload_file($file); if (strlen($url) > 0) { return $url; } } return $default_str; } /* }}} */ function ezin_lookup_upload_image($dir, $file_wo_ext = '', $default_str = false) /* {{{ */ { static $extensions = array('', 'png', 'gif', 'jpg', 'PNG', 'GIF', 'JPG'); return ezin_lookup_upload_file_ext_ar($dir, $file_wo_ext, $default_str, $extensions); } /* }}} */ function ezin_lookup_upload_flash($dir, $file_wo_ext = '', $default_str = false) /* {{{ */ { static $extensions = array('', 'swf', 'SWF'); return ezin_lookup_upload_file_ext_ar($dir, $file_wo_ext, $default_str, $extensions); } /* }}} */ function ezin_get_upload_image_html($dir, $file_wo_ext, $default_str = '') /* {{{ */ { $url = ezin_lookup_upload_image($dir, $file_wo_ext); if (strlen($url) > 0) { return sprintf('', $url); } return $default_str; } /* }}} */ function ezin_get_upload_image_width($input_image) /* {{{ */ { global $ezin_cfg; $uni_prefix = $ezin_cfg['upload']['dir'].'/'; if (! file_exists($uni_prefix.$input_image)) { return -1; } list($width, $height, $type, $attr) = @getimagesize($uni_prefix.$input_image); return intval($width); } /* }}} */ function ezin_scale_upload_image($input_image, $width) /* {{{ */ { global $ezin_cfg, $ezin_sys; $width = preg_replace('/["\']/', '', trim($width)); $width_int = intval($width); $width_pct = $width[strlen($width) - 1] == '%'; $cache_dir = '_cache'; $uni_prefix = $ezin_sys['dir']['root'].$ezin_cfg['upload']['dir'].'/'; $input_image = rawurldecode($input_image); if ($width_int <= 0 || preg_match('|.bmp$|i', $input_image)) { return $input_image; } if (! file_exists($uni_prefix.$input_image)) { return $input_image; } if (! is_dir($uni_prefix.$cache_dir)) { if (mkdir($uni_prefix.$cache_dir) == false) { return $input_image; } } $filemtime = filemtime($uni_prefix.$input_image); $output_image .= "$cache_dir/$width_int"; $output_image .= ($width_pct ? 'pct' : 'abs').'--'; $output_image .= "$filemtime--"; $output_image .= str_replace('/','--', $input_image); if (file_exists($uni_prefix.$output_image)) { return str_replace('%2F', '/', rawurlencode($output_image)); } include_once 'Image/Transform.php'; $img = Image_Transform::factory('GD'); if (PEAR::isError(@$img->load($uni_prefix.$input_image))) { return $input_image; } if ($width_pct) { $img->scalebyPercentage($width_int); } else { $img->scaleByX($width_int); } $img->save($uni_prefix.$output_image); return str_replace('%2F', '/', rawurlencode($output_image)); } /* }}} */ /* * Message process function */ function ezin_message_process($full, $message_id, $level = 0) /* {{{ */ { global $ezin_sys; global $ezin_cfg; global $ezin_cgi; global $ezin_tmpl_key; $filename = $ezin_sys['tmpl']['message_'.($full?'full_':'').'item']; $filename .= $ezin_tmpl_key; $items = ''; $item = new HTML_Template_Platon($filename); $messages = ezin_get_message_list($ezin_cgi['article_id'], $message_id); for ($i = 0; $i < count($messages); $i++) { if ($ezin_cgi['output'] == 'message_selected_list' && is_array($ezin_cgi['message_id']) && ! in_array($messages[$i]['message_id'], $ezin_cgi['message_id'])) { // skip this message // note that you cannot use `continue' here } else { $item->reload(); $messages[$i]['message_date'] = date($ezin_cfg['format_date'], $messages[$i]['message_timestamp']); $messages[$i]['message_datetime'] = date($ezin_cfg['format_datetime'], $messages[$i]['message_timestamp']); $messages[$i]['message_level'] = $level; $messages[$i]['message_link'] = ezin_get_link('M', $messages[$i]['message_id']); $messages[$i]['message_author'] = Platon::htmlspecialchars($messages[$i]['message_author']); $messages[$i]['message_homepage'] = Platon::htmlspecialchars($messages[$i]['message_homepage']); $messages[$i]['message_subject'] = Platon::htmlspecialchars($messages[$i]['message_subject']); ezin_message_html_process($messages[$i]['message_message']); ezin_process_text_flags($messages[$i]['message_message'], 'message', 1); /* if atitle is empty, set it to title, but if title is empty, remains it unchanged */ if (empty($messages[$i]['message_article_atitle']) && ! empty($messages[$i]['message_article_title'])) { $messages[$i]['message_article_atitle'] = $messages[$i]['message_article_title']; } $item->set($messages[$i]); $items .= $item->getCode(); } $items .= ezin_message_process($full, $messages[$i]['message_id'], $level + 1); } return $items; } /* }}} */ /* * E-mail sending */ function ezin_core_send_notify_email($data, $type = 'feedback') /* {{{ */ { global $ezin_sys, $ezin_cfg, $ezin_tmpl_key; $from = ''; $to = ''; $subject = ''; $encoding = ''; $message = ''; // TODO: the problem here is, that $ezin_tmpl_key not initialized yet // thus customized feedback form e-mails are not possible this way $template = $ezin_sys['tmpl']['e-mail'][$type].$ezin_tmpl_key; $tmpl = ezin_load_template($template, 1); if ($tmpl != false) { $tmpl = new HTML_Template_Platon($template); } if ($tmpl == false || $tmpl->isVar('content')) { if ($type == 'feedback') { $custom_part = 'Feedback form was submited on your portal at server time '; $custom_part .= date($ezin_cfg['format_datetime']) . '.'; } else if ($type == 'author') { $custom_part = 'New user/author has joined your portal at server time '; $custom_part .= date($ezin_cfg['format_datetime']) . '.'; } $message .= 'Dear administrator of '; $message .= $ezin_sys['software']['name']." on $ezin_cfg[name]\n\n"; $message .= "$custom_part\n"; $message .= "Full information follows on the next lines.\n\n"; foreach ($data as $key => $val) { $val = trim($val); if (strpos($val, "\n") === false) { $message .= sprintf("* %s: %s\n", $key, $val); } else { $message .= sprintf("* %s:\n\n%s\n\n", $key, $val); } } $message .= "\nHoping the message above is a good one."; $message .= "\n\nYours,\n\n"; $message .= $ezin_sys['software']['name']." on $ezin_cfg[name]\n\n"; if ($tmpl != false) { $tmpl->set('content', $message); } } if ($tmpl != false) { foreach ($data as $key => $val) { $tmpl->set($type.'_'.$key, $val); } ezin_substitute_basic_properties($tmpl); ob_start(); @$tmpl->Output(); $message = ob_get_contents(); ob_end_clean(); $message = ezin_email_template_parse($message, $from, $to, $subject, $encoding); } empty($subject) && $subject = sprintf('%s: feedback', $ezin_cfg['name']); if (strlen($to) <= 0) { $to = $ezin_cfg[$type.'_email']; } return ezin_email_send($to, $from, $subject, $encoding, $message); } /* }}} */ function ezin_feedback_send_notify_email($data) /* {{{ */ { ezin_core_send_notify_email($data, 'feedback'); } /* }}} */ function ezin_author_send_notify_email($data) /* {{{ */ { ezin_core_send_notify_email($data, 'author'); } /* }}} */ /* * Template load function */ function ezin_load_template($template_key, $test_only = 0) /* {{{ */ { global $ezin_sys; global $ezin_cfg; global $ezin_cgi; $theme_dir = $ezin_sys['dir']['root'].'/'.$ezin_sys['dir']['themes'].'/'.$ezin_cfg['theme']['name'].'/'; if (isset($ezin_cgi['lang']) && $ezin_cgi['lang'] != '') { $template_key .= $ezin_sys['tmpl']['delim'].$ezin_cgi['lang']; } $additional_append_lang = true; while (1) { $filename = $theme_dir . $template_key . $ezin_sys['tmpl']['delimext']; if (@file_exists($filename) && $f = @fopen($filename, 'r')) { if ($test_only) { fclose($f); return true; } $data = ''; while ($tmp_data = fread($f, 1024)) { $data .= $tmp_data; } fclose($f); return $data; } else if ($template_key == 'section.rss2' || $template_key == 'article.rss2') { /* {{{ */ return '<| "<" |>?xml version="1.0" encoding="<|$ezin_encoding|>" ?<| ">\n" |> <| ezin_normalize_rss2_string($ezin_name) |> <| ezin_normalize_rss2_string("http://$_SERVER[HTTP_HOST]$ezin_url") |> <| ezin_normalize_rss2_string(strlen($ezin_description)>0?$ezin_description:$ezin_name) |> <| ezin_normalize_rss2_string($ezin_software_signature) |> <|CMD| if (strlen($ezin_lang) > 0): |> <|$ezin_lang|> <|CMD| endif; |> <|$article_items|> '."\n"; } /* }}} */ else if ($template_key == 'author.rss2') { /* {{{ */ return '<| "<" |>?xml version="1.0" encoding="<|$ezin_encoding|>" ?<| ">\n" |> <| ezin_normalize_rss2_string("$ezin_name: $author_name") |> <| ezin_normalize_rss2_string("http://$_SERVER[HTTP_HOST]$author_link") |> <| ezin_normalize_rss2_string($author_description) |> <| ezin_normalize_rss2_string($ezin_software_signature) |> <|CMD| if (strlen($ezin_lang) > 0): |> <|$ezin_lang|> <|CMD| endif; |> <|CMD| if (strlen($author_email) > 0): |> <| ezin_normalize_rss2_string($author_email) |> <|CMD| endif; |> <|$article_items|> '."\n"; } /* }}} */ else if ($template_key == 'article_item.rss2') { /* {{{ */ return ' <| ezin_normalize_rss2_string($article_atitle) |> <| ezin_normalize_rss2_string("http://$_SERVER[HTTP_HOST]$article_link") |> <| gmdate("D, d M Y H:i:s", intval($article_timestamp)) |> GMT article-item-<|$article_id|> <|CMD| if ($article_messages > 0): |> <| ezin_normalize_rss2_string("http://$_SERVER[HTTP_HOST]$article_show_all_link") |> <|CMD| endif; |> <|CMD| if (strlen($article_author_email) > 0): |> <| ezin_normalize_rss2_string($article_author_name) |> <<| ezin_normalize_rss2_string($article_author_email) |>> <|CMD| endif; |> <| ezin_normalize_rss2_string($article_hometext) |> '."\n"; } /* }}} */ else if (($template_key == 'section.soap' || $template_key == 'article.soap') && ($ezin_cfg['soap_server_enabled'] == 1)) { require_once 'soap/soap_server.php'; ob_clean(); header("content-type: text/xml; charset=utf-8"); return $soap_out; } else if ($template_key == 'section.platon_newsletter' || $template_key == 'article.platon_newsletter') { if ($ezin_cfg['platon_newsletter_enabled'] != 1) { die('Platon Newsletter Source is disabled'); exit(); } if (strlen($ezin_cfg['platon_newsletter_password']) <= 0) { die('Password for Platon Newsletter Source is empty'); exit(); } require_once 'PlatonNewsletter.php'; ob_clean(); header("content-type: text/html; charset=utf-8"); $emails = ezin_get_newsletter_emails(); new PlatonNewsletter($ezin_cfg['platon_newsletter_password'], $emails); exit(); } else if ($template_key == 'section.section_loadmore' || $template_key == 'article.section_loadmore') { if (!isset($_GET['section_id'])) { return 'Error: not set SECTION_ID'; } if (!isset($_GET['page'])) { return 'Error: not set PAGE'; } ob_clean(); header("content-type: text/html; charset=".$ezin_cfg['encoding']); echo ezin_get_section_page($_GET['section_id'], $_GET['page']); exit(); } else if ($template_key == 'section.sitemap' || $template_key == 'article.sitemap') { ob_clean(); header("content-type: text/xml; charset=utf-8"); return ezin_get_sitemap(); } else if ($template_key == 'section.htmlmap' || $template_key == 'article.htmlmap') { ob_clean(); return ezin_get_htmlmap(); } if (($pos = strrpos($template_key, '.')) === false) { break; } $template_key = substr($template_key, 0, $pos); if (($pos = strrpos($template_key, '.')) === false && $additional_append_lang == true) { $template_key .= $ezin_sys['tmpl']['delim'].$ezin_cgi['lang']; $additional_append_lang = false; } } return false; } /* }}} */ function ezin_email_template_parse($message, &$from, &$to, &$subject, &$encoding) /* {{{ */ { $match = array(); preg_match("/^(From:(.*?)[\r\n]+?)?(To:(.*?)[\r\n]+?)?(Subject:(.*?)[\r\n]+?)?(Charset:(.*?)[\r\n]+?)?(.*?)$/is", $message, $match); $message = ( isset($match[9]) ) ? trim($match[9]) : ''; $from = ( trim($match[2]) != '' ) ? trim($match[2]) : ''; $to = ( trim($match[4]) != '' ) ? trim($match[4]) : ''; $subject = ( trim($match[6]) != '' ) ? trim($match[6]) : ''; $encoding = ( trim($match[8]) != '' ) ? trim($match[8]) : ''; return $message; } /* }}} */ function ezin_email_send($emails, $from, $subject, $encoding, $message) /* {{{ */ { global $ezin_cfg, $ezin_sys; if (! is_array($emails)) { $emails = preg_split('|\s+|', $emails); } foreach (array_keys($emails) as $key) { $emails[$key] = trim($emails[$key]); if (empty($emails[$key]) || strpos($emails[$key], '@') === false) { unset($emails[$key]); } } if (count($emails) <= 0) { return true; // no e-mails, nothing to do more } $emails = array_unique($emails); $message .= "\n\n--\n"; $message .= $ezin_sys['software']['name'].' - '.$ezin_sys['software']['description']; $message .= "\nversion ".$ezin_sys['software']['version']; $message .= "\n\n\"".$ezin_sys['software']['motto'].'" (tm)'; $message .= "\n\n".$ezin_sys['software']['url']; empty($subject) && $subject = sprintf('%s issues', $ezin_cfg['name']); empty($encoding) && $encoding = $ezin_cfg['encoding']; empty($encoding) && $encoding = 'iso-8859-1'; empty($from) && $from = sprintf('"%s on %s" ', $ezin_sys['software']['name'], $ezin_cfg['name'], $_SERVER['SERVER_NAME']); include_once 'Mail.php'; include_once 'Mail/mime.php'; $mime = new Mail_mime(); $mime->setTXTBody($message); $atts = array(); // this is prepared for atts sending if (count($atts) > 0) { foreach ($atts as $file => $mime_type) { if (strlen($mime_type) <= 0) { $mime_type = 'application/octet-stream'; } $mime->addAttachment($file, $mime_type, basename($file)); } } $message = $mime->get(array( 'text_charset' => $encoding, 'html_charset' => $encoding, 'head_charset' => $encoding )); $site_key = $ezin_sys['software']['name'].'.'.@$ezin_cfg['abbreviation'].'.'.md5(@$ezin_cfg['name']); if (strlen($_SERVER['HTTP_HOST']) > 0) { $site_key .= '@'.$_SERVER['HTTP_HOST']; } $headers = array( //'MIME-Version: 1.0', //'Content-type: text/plain; charset='.$encoding, //'Content-transfer-encoding: 8bit', //'Date' => gmdate('D, d M Y H:i:s', time()).' UT', 'From' => $from, 'To' => is_array($emails) ? join(', ', $emails) : $emails, 'Subject' => $subject, 'In-Reply-To' => "<$site_key>", 'References' => "<$site_key>", 'Message-ID' => "<$site_key>", 'X-Mailer' => $ezin_sys['software']['name'].'/'.$ezin_sys['software']['version'], 'X-Mail-Prefered-Method' => $ezin_cfg['mail_method'], 'X-Mail-Used-Method' => 'undefined', 'X-Mail-Failed-Methods' => 'none', ); $headers = $mime->headers($headers); $methods = array($ezin_cfg['mail_method'], 'mail', 'sendmail', 'smtp'); $methods = array_unique($methods); $params = array( 'sendmail_path' => '/usr/sbin/sendmail', 'host' => '127.0.0.1', 'port' => 25 ); if (strlen(trim($ezin_cfg['mail_sendmail_path'])) > 0) { $params['sendmail_path'] = trim($ezin_cfg['mail_sendmail_path']); } if (strlen(trim($ezin_cfg['mail_smtp_host_port'])) > 0) { @list($host, $port) = explode(':', trim($ezin_cfg['mail_smtp_host_port'])); strlen($host) > 0 && $params['host'] = $host; strlen($port) > 0 && $params['port'] = $port; } PEAR::pushErrorHandling(PEAR_ERROR_RETURN); foreach ($methods as $method) { $headers['X-Mail-Used-Method'] = $method; if ($method == 'mail') { $mail =& Mail::factory($method); } else { $mail =& Mail::factory($method, $params); } $ret = $mail->send($emails, $headers, $message); if ($ret === true) { //echo "method $method returned true
"; return true; } //echo "method $method returned false
"; unset($mail); @$headers['X-Mail-Failed-Methods'] .= ", $method"; } PEAR::popErrorHandling(); return false; } /* }}} */ function ezin_get_section_page($section_id, $page) { global $ezin_cfg, $ezin_sys, $ezin_cgi, $ezin_tmpl_key; $section = ezin_get_section($section_id); $limit = $section['section_limit']; if ($limit == 0) { // all articles were printed return ''; } $ezin_tmpl_key = $ezin_sys['tmpl']['delim'].$section['section_template_key']; $articles = $articles = ezin_get_article_list($section_id, 0, $limit, $ezin_cgi['lang'], $page*$limit); eval(ezin_build_content_article($articles)); return ''; } /* * Basic template substitutions */ function ezin_substitute_basic_properties(&$tmpl_obj) /* {{{ */ { global $ezin_sys, $ezin_cfg, $ezin_cgi, $ezin_user; $antispam = ezin_get_antispam(); $tmpl_obj->set(array( // Configuration 'ezin_name' => @$ezin_cfg['name'], 'ezin_description' => @$ezin_cfg['description'], 'ezin_url' => @$ezin_cfg['url'], 'ezin_encoding' => @$ezin_cfg['encoding'], 'ezin_charset' => @$ezin_cfg['encoding'], 'ezin_count' => 'N/A', 'ezin_theme_dir' => @$ezin_cfg['theme']['dir'], 'ezin_theme_url' => @$ezin_cfg['theme']['url'], 'ezin_upload_dir' => @$ezin_cfg['upload']['dir'], 'ezin_upload_url' => @$ezin_cfg['upload']['url'], 'ezin_debug' => intval(@$ezin_cfg['debug_level']), 'ezin_datetime' => date($ezin_cfg['format_datetime']), 'ezin_date' => date($ezin_cfg['format_date']), 'ezin_time' => sprintf('%.2f', Platon::get_mtime() - @$ezin_sys['time']['start']), // Antispam 'ezin_antispam_question' => ezin_check_antispam() ? $antispam['question'] : '', 'ezin_antispam_answer' => ezin_check_antispam() ? $antispam['answer'] : '', // Ezin software 'ezin_software_name' => @$ezin_sys['software']['name'], 'ezin_software_version' => @$ezin_sys['software']['version'], 'ezin_software_description' => @$ezin_sys['software']['description'], 'ezin_software_motto' => @$ezin_sys['software']['motto'], 'ezin_software_url' => @$ezin_sys['software']['url'], 'ezin_software_signature' => @$ezin_sys['software']['name'] .'/'.@$ezin_sys['software']['version'], // CGI parameters 'ezin_cgi_input' => @$ezin_cgi['input'], 'ezin_cgi_output' => @$ezin_cgi['output'], 'ezin_message_id' => @is_array($ezin_cgi['message_id']) ? 0 : $ezin_cgi['message_id'], 'ezin_article_id' => @$ezin_cgi['article_id'], 'ezin_section_id' => @$ezin_cgi['section_id'], 'ezin_lang' => @$ezin_cgi['lang'], 'ezin_user' => @$ezin_user['username'] )); if (is_array($ezin_user)) foreach ($ezin_user as $key => $val) { if (! strncmp($key, 'pass', 4)) { continue; } if (! strncmp($key, 'author_', 7) && $key != 'author_id') { $key = str_replace('author_', 'user_', $key); } if (is_array($val)) { $val = join(',', $val); } $tmpl_obj->set($key, $val); $tmpl_obj->set("ezin_$key", $val); } if (is_array($ezin_cgi)) foreach ($ezin_cgi as $key => $val) { if (strncmp($key, 'email_', 6) && strncmp($key, 'message_', 8) && strncmp($key, 'feedback_', 9) && strncmp($key, 'author_', 7)) { continue; } if (is_array($val)) { $val = join(',', $val); } //echo "$key:$val"; $tmpl_obj->set($key, $val); $tmpl_obj->set("ezin_$key", $val); } // Language variables if (isset($ezin_cgi['lang_bind']) && is_array($ezin_cgi['lang_bind'])) { foreach ($ezin_cgi['lang_bind'] as $ezin_lang_key => $ezin_lang_val) { $tmpl_obj->set('ezin_lang_'.$ezin_lang_key, intval($ezin_lang_key == $ezin_cgi['lang'])); $tmpl_obj->set('ezin_lang_'.$ezin_lang_key.'_link', $ezin_lang_key == $ezin_cgi['lang'] || strlen($ezin_lang_val) <= 0 ? '#' : $ezin_lang_val); } } 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]); $tmpl_obj->set('ezin_lang_'.$lang.'_host', $hosts[0]); } } } /* }}} */ /* * Input parameters parsing * TODO: this should be probably completely rewritten */ function ezin_cgi_parse() /* {{{ */ { global $ezin_cfg; global $ezin_cgi; global $ezin_user; /* $ezin_cgi['lang_init'] schema 0 - uninitialized 1 - initialized by CGI 2 - initialized by cookie 3 - initialized by negotiation */ $expire_time = time() + (3600 * 24 * 30 * 12 * 2); // two years $lang_cookie = strtolower(@$_COOKIE['ezin_lang']); $ezin_cgi['lang_init'] = 0; if (is_array($ezin_cfg['languages'])) { $ezin_cgi['lang_init'] = 1; $lang = strtolower(Platon::parse_id_param('ezin_lang', false)); if (! in_array($lang, $ezin_cfg['languages'])) { $ezin_cgi['lang_init'] = 2; $lang = $lang_cookie; if (! in_array($lang, $ezin_cfg['languages'])) { $ezin_cgi['lang_init'] = 3; $lang = Platon::negotiate_language($ezin_cfg['languages']); } } } else { $lang = ''; } switch ($ezin_cgi['input']) { case 'admin': $ezin_cgi['author_id'] = 0; $ezin_cgi['section_id'] = 0; $ezin_cgi['article_id'] = 0; $ezin_cgi['message_id'] = 0; return; case 'author': if (! isset($ezin_cgi['author_id']) || empty($ezin_cgi['author_id'])) { $ezin_cgi['author_id'] = Platon::parse_id_param('id', $ezin_cgi['query_string']); if (empty($ezin_cgi['author_id'])) { $ezin_cgi['author_id'] = Platon::parse_id_param('key', $ezin_cgi['query_string']); } if (!empty($ezin_cgi['author_id'])) { $ezin_cgi['output'] = $ezin_cgi['input']; } } break; case 'section': if (! isset($ezin_cgi['section_id']) || empty($ezin_cgi['section_id'])) { $ezin_cgi['section_id'] = Platon::parse_id_param('id', $ezin_cgi['query_string']); if (empty($ezin_cgi['section_id'])) { $ezin_cgi['section_id'] = Platon::parse_id_param('key', $ezin_cgi['query_string']); } if (!empty($ezin_cgi['section_id'])) { $ezin_cgi['output'] = $ezin_cgi['input']; } } break; case 'article': case 'print': if (! isset($ezin_cgi['article_id']) || empty($ezin_cgi['article_id'])) { $ezin_cgi['article_id'] = Platon::parse_id_param('id', $ezin_cgi['query_string']); if (empty($ezin_cgi['article_id'])) { $ezin_cgi['article_id'] = Platon::parse_id_param('key', $ezin_cgi['query_string']); } if (!empty($ezin_cgi['article_id'])) { $ezin_cgi['output'] = $ezin_cgi['input']; } } break; case 'message': if (! isset($ezin_cgi['message_id']) || empty($ezin_cgi['message_id'])) { $ezin_cgi['message_id'] = Platon::parse_id_param('id', $ezin_cgi['query_string']); } if (!empty($ezin_cgi['message_id'])) { $ezin_cgi['output'] = $ezin_cgi['input']; } break; } if (! isset($ezin_cgi['message_id']) || empty($ezin_cgi['message_id'])) { $ezin_cgi['message_id'] = Platon::parse_id_param('ezin_message_id', false); } if (! isset($ezin_cgi['article_id']) || empty($ezin_cgi['article_id'])) { $ezin_cgi['article_id'] = Platon::parse_id_param('ezin_article_id', false); if (empty($ezin_cgi['article_id'])) { $ezin_cgi['article_id'] = Platon::parse_id_param('ezin_article_key', false); } } if (! isset($ezin_cgi['section_id']) || empty($ezin_cgi['section_id'])) { $ezin_cgi['section_id'] = Platon::parse_id_param('ezin_section_id', false); if (empty($ezin_cgi['section_id'])) { $ezin_cgi['section_id'] = Platon::parse_id_param('ezin_section_key', false); } } if (! isset($ezin_cgi['author_id']) || empty($ezin_cgi['author_id'])) { $ezin_cgi['author_id'] = Platon::parse_id_param('ezin_author_id', false); if (empty($ezin_cgi['author_id'])) { $ezin_cgi['author_id'] = Platon::parse_id_param('ezin_author_key', false); } } $notfound_id = ''; $notfound_id = (strlen($notfound_id) <= 0) ? @$ezin_cgi['author_id'] : $notfound_id; $notfound_id = (strlen($notfound_id) <= 0) ? @$ezin_cgi['section_id'] : $notfound_id; $notfound_id = (strlen($notfound_id) <= 0) ? @$ezin_cgi['article_id'] : $notfound_id; $notfound_id = (strlen($notfound_id) <= 0) ? strval(@$ezin_cgi['message_id']) : $notfound_id; $notfound_id = (strlen($notfound_id) <= 0) ? @$ezin_cgi['section_access_key'] : $notfound_id; $notfound_id = (strlen($notfound_id) <= 0) ? @$ezin_cgi['article_access_key'] : $notfound_id; $ezin_cgi['notfound_id'] = $notfound_id; $ar = ezin_validate_IDs(array( 'author_id' => $ezin_cgi['author_id'], 'section_id' => $ezin_cgi['section_id'], 'article_id' => $ezin_cgi['article_id'], 'message_id' => $ezin_cgi['message_id'], 'lang' => $lang)); $lang_new = $ar['lang']; $lang_tbl_type = 'S'; $lang_tbl = ezin_get_bind_lang_table_wrapper($lang_tbl_type, $ar['section_bind_lang'], $ar['article_bind_lang']); while (intval($ar['author_id']) + intval($ar['section_id']) + intval($ar['article_id']) + intval($ar['message_id']) <= 0) { global $ezin_cfg; $ezin_cgi['output'] = 'notfound'; $redirect_data = $ezin_cfg[ $ezin_cgi['input'] == 'index' ? 'redirect_index' : 'redirect_others']; $redirect_http = $redirect_data[0] == '+'; $redirect_data = $redirect_http ? substr($redirect_data, 1) : $redirect_data; $redirect_type = $redirect_data[0]; $redirect_id = substr($redirect_data, 1); $redirect_section_id = $redirect_type == 'S' ? $redirect_id : 0; $redirect_article_id = $redirect_type == 'A' ? $redirect_id : 0; $ar = ezin_validate_IDs(array( 'section_id' => $redirect_section_id, 'article_id' => $redirect_article_id, 'author_id' => 0, 'message_id' => 0, 'lang' => $lang)); $lang_new = $ar['lang']; $lang_tbl = ezin_get_bind_lang_table_wrapper($lang_tbl_type, $ar['section_bind_lang'], $ar['article_bind_lang']); /* === FUNNY CODE (c) Nepto === */ if ($lang != '' && $lang_new != '' && $ezin_cgi['lang_init'] < 3 /* !!! */ && $lang != $lang_new) { if (! empty($lang_tbl[$lang])) { if (intval($ar['article_bind_lang']) > 0) { $ar = ezin_validate_IDs(array( 'section_id' => $redirect_section_id, 'article_id' => $lang_tbl[$lang], 'author_id' => 0, 'message_id' => 0, 'lang' => $lang)); $redirect_id = $ar['article_id']; } else { $redirect_id = $ar['section_id'] = $lang_tbl[$lang]; } $lang_new = $lang; } } /* ============================ */ if ($ar['section_id'] + $ar['article_id'] + (int)$ar['message_id'] > 0) { if ($redirect_http) { Platon::redirect(ezin_get_link($redirect_type, $redirect_id, 1), true /* temporary redirect */); } $ezin_cgi['output'] = $redirect_type == 'S' ? 'section' : 'article'; } break; } /* === FUNNY CODE (c) Nepto === */ if ($lang != '' && $lang_new != '' && $ezin_cgi['lang_init'] < 2 && $lang != $lang_new) { if (! empty($lang_tbl[$lang])) { if (intval($ar['article_bind_lang']) > 0) { $ar = ezin_validate_IDs(array( 'section_id' => $ezin_cgi['section_id'], 'article_id' => $lang_tbl[$lang], 'author_id' => 0, 'message_id' => 0, 'lang' => $lang)); } else { $ar['section_id'] = $lang_tbl[$lang]; } $lang_new = $lang; } } /* ============================ */ if (is_array($ezin_cfg['languages'])) { $ezin_cgi['lang'] = $lang_new != '' ? $lang_new : $lang; } else { $ezin_cgi['lang'] = ''; } $ezin_cgi['message_id'] = $ar['message_id']; $ezin_cgi['article_id'] = $ar['article_id']; $ezin_cgi['section_id'] = $ar['section_id']; $ezin_cgi['author_id'] = $ar['author_id']; $ezin_cgi['article_id2'] = empty($ar['article_access_key']) ? $ar['article_id'] : $ar['article_access_key']; $ezin_cgi['section_id2'] = empty($ar['section_access_key']) ? $ar['section_id'] : $ar['section_access_key']; $ezin_cgi['author_id2'] = empty($ar['author_access_key']) ? $ar['author_id'] : $ar['author_access_key']; if ($ezin_cfg['user_create_role_id'] > 0) { /* {{{ */ include_once 'Auth/AuthDB.php'; global $ezin_auth_options; $ezin_auth = new AuthDB($ezin_auth_options); $ezin_login_author = Platon::parse_id_param('ezin_login_author', false); $ezin_logout_author = Platon::parse_id_param('ezin_logout_author', false); if ($ezin_logout_author) { $ezin_auth = new AuthDB($ezin_auth_options); if ($ezin_auth->getAuth()) { $ezin_auth->logout(); } } if (! $ezin_auth->getAuth()) { // not logged in case switch ($ezin_auth->getStatus()) { case AUTH_DB_NOT_LOGGED: break; case AUTH_DB_LOGGED_OUT: break; case AUTH_DB_FAILED: break; case AUTH_DB_TIMEOUT: break; case AUTH_DB_EXPIRED: break; default: echo '
'; echo '

Unknown status ('; // ) echo $ezin_auth->getStatus().')'; echo '

'; break; } } else { // logged in case $ezin_user = $ezin_auth->getUserInfo(); $author = ezin_get_author($ezin_user['author_id']); foreach ($author as $key => $val) { $ezin_user[$key] = $val; } } if (($ezin_login_author || $ezin_logout_author) && @strlen($_SERVER['HTTP_REFERER']) > 0) { $referer = $_SERVER['HTTP_REFERER']; $referer = preg_replace('/ezin_log(in|out)_author=[^&]*/', '', $referer); header('Location: '.$referer); exit; } } /* }}} */ if (! empty($ezin_cgi['article_id'])) { $ezin_cgi['output'] = 'article'; if (! empty($ezin_cgi['message_id'])) { $ezin_cgi['output'] = 'message'; } $ezin_save_message = Platon::parse_id_param('ezin_save_message', false); if (! empty($ezin_save_message)) { foreach (array('author', 'email', 'homepage', 'subject', 'message') as $var) { $ezin_cgi["message_reply_$var"] = trim(stripslashes(Platon::parse_id_param("ezin_$var", false))); } if (! preg_match('/^.+(:\/\/|:).+\..+$/', $ezin_cgi['message_reply_homepage'])) { if (preg_match("/^.+\..+$/", $ezin_cgi['message_reply_homepage'])) { $ezin_cgi['message_reply_homepage'] = 'http://' . $ezin_cgi['message_reply_homepage']; } else { $ezin_cgi['message_reply_homepage'] = ''; } } $result = true; if (!ezin_check_antispam('M')) { $ezin_cgi['message_save_antispam_protection'] = 1; $result = false; } if (ezin_check_message_flood()) { $ezin_cgi['message_save_flood_protection'] = 1; $result = false; } if (strlen($ezin_cgi['message_reply_subject']) <= 0) { $ezin_cgi['message_save_subject_missing'] = 1; $result = false; } if (strlen($ezin_cgi['message_reply_author']) <= 0) { $ezin_cgi['message_save_author_missing'] = 1; $result = false; } if (strlen($ezin_cgi['message_reply_message']) <= 0) { $ezin_cgi['message_save_message_missing'] = 1; $result = false; } if ($result) { $result = ezin_save_message(array( 'parent' => $ezin_cgi['message_id'], 'article_id' => $ezin_cgi['article_id'], 'author' => $ezin_cgi['message_reply_author'], 'email' => $ezin_cgi['message_reply_email'], 'homepage' => $ezin_cgi['message_reply_homepage'], 'subject' => $ezin_cgi['message_reply_subject'], 'message' => $ezin_cgi['message_reply_message'] )); if ($result == false) { $ezin_cgi['message_save_unknown_error'] = 1; } else { ezin_cache_clear('a'.@$ezin_cgi['article_id']); ezin_cache_clear('AF'.@$ezin_cgi['article_id']); } } if ($result == false) { $ezin_cgi['output'] = 'message'; $ezin_cgi['message_save_error'] = 1; } else { ezin_update_message_count($ezin_cgi['article_id'], 1, 1); $ezin_cgi['output'] = 'article'; $ezin_cgi['message_id'] = 0; $ezin_cgi['message_save_ok'] = 1; setcookie('ezin_author_cookie', $ezin_cgi['message_reply_author'], $expire_time); setcookie('ezin_email_cookie', $ezin_cgi['message_reply_email'], $expire_time); setcookie('ezin_homepage_cookie', $ezin_cgi['message_reply_homepage'], $expire_time); } } $ezin_show_selected = Platon::parse_id_param('ezin_show_selected', false); $ezin_show_all = Platon::parse_id_param('ezin_show_all', false); if (! empty($ezin_show_selected)) { $ezin_cgi['output'] = 'message_selected_list'; } if (! empty($ezin_show_all)) { $ezin_cgi['output'] = 'message_full_list'; } $ezin_add_new = Platon::parse_id_param('ezin_add_new', false); if (! empty($ezin_add_new)) { $ezin_cgi['output'] = 'message'; $ezin_cgi['message_id'] = 0; } $ezin_print = Platon::parse_id_param('ezin_print', false); if (($ezin_cgi['output'] == 'article' && ! empty($ezin_print)) || $ezin_cgi['input'] == 'print') { $ezin_cgi['output'] = 'article_print'; } } if (! empty($ezin_cgi['section_id']) || ! empty($ezin_cgi['author_id'])) { $ezin_save_feedback = Platon::parse_id_param('ezin_save_feedback', false); $ezin_save_email = Platon::parse_id_param('ezin_save_email', false); $ezin_save_author = Platon::parse_id_param('ezin_save_author', false); if (! empty($ezin_save_feedback)) { /* {{{ */ if (!ezin_check_antispam('F')) { $ezin_cgi['feedback_save_antispam_protection'] = 1; $ezin_cgi['feedback_save_error'] = 1; } else if (ezin_check_feedback_flood()) { $ezin_cgi['feedback_save_flood_protection'] = 1; $ezin_cgi['feedback_save_error'] = 1; } else { $data = array(); foreach ($_POST + $_GET as $key => $val) { if (in_array($key, array('ezin_save_feedback', 'ezin_fragment', 'ezin_section_id', 'ezin_section_key', 'ezin_antispam'))) { continue; } if (preg_match('|^ezin_(.+)$|', $key, $matches)) { $data[$matches[1]] = stripslashes($val); } } $required_items = ezin_feedback_required_items(); $required_items_approved = true; if (count($required_items) > 0) { foreach ($required_items as $required_item) { if ((isset($data[$required_item]) && strlen($data[$required_item]) > 0) || (isset($data['ezin_'.$required_item]) && strlen($data['ezin_'.$required_item]) > 0)) { continue; } if (substr($required_item, 0, 5) == 'ezin_' && isset($data[substr($required_item, 5)]) && strlen($data[substr($required_item, 5)]) > 0) { continue; } $required_items_approved = false; break; } } if ($required_items_approved) { ezin_feedback_send_notify_email($data); if (ezin_save_feedback($ezin_cgi['section_id'], $data)) { $ezin_cgi['feedback_save_ok'] = 1; } else { $ezin_cgi['feedback_save_unknown_error'] = 1; $ezin_cgi['feedback_save_error'] = 1; } } else { $ezin_cgi['feedback_save_unknown_error'] = 2; $ezin_cgi['feedback_save_error'] = 2; } } } /* }}} */ if (! empty($ezin_save_email)) { /* {{{ */ if (!ezin_check_antispam('N')) { $ezin_cgi['email_save_antispam_protection'] = 1; $ezin_cgi['email_save_error'] = 1; } else { $email = trim($_REQUEST['ezin_email']); $phone = trim($_REQUEST['ezin_phone']); include_once 'Validate.php'; if ((@Validate::email($email) || strlen($phone) > 0) && ezin_save_email($ezin_cgi['section_id'], $email, $phone)) { $ezin_cgi['email_save_ok'] = 1; } else { $ezin_cgi['email_save_unknown_error'] = 1; $ezin_cgi['email_save_error'] = 1; } } } /* }}} */ if (! empty($ezin_save_author) && $ezin_cfg['user_create_role_id'] > 0) { /* {{{ */ if (!ezin_check_antispam('A')) { $ezin_cgi['author_save_antispam_protection'] = 1; $ezin_cgi['author_save_error'] = 1; } else { $logged_in = strlen($ezin_user['username']) > 0; $data = array(); foreach ($_POST + $_GET as $key => $val) { if (in_array($key, array('ezin_save_author', 'ezin_fragment', 'ezin_section_id', 'ezin_section_key', 'ezin_antispam'))) { continue; } if (preg_match('|^ezin_(.+)$|', $key, $matches)) { $data[$matches[1]] = Platon::htmlspecialchars(stripslashes($val)); } } if ($logged_in) { $data['username'] = $ezin_user['username']; $data['author_id'] = $ezin_user['author_id']; if (! ezin_exists_author($data['username'])) { $ezin_cgi['author_save_error'] = 1; $ezin_cgi['author_save_not_exists'] = 1; } elseif (strlen($data['password'].$data['password_repeat']) > 0 && $data['password'] != $data['password_repeat']) { $ezin_cgi['author_save_password_not_match'] = 1; $ezin_cgi['author_save_error'] = 1; } elseif (strlen($data['password'].$data['password_repeat']) > 0 && strlen($data['password']) < 4) { $ezin_cgi['author_save_password_too_short'] = 1; $ezin_cgi['author_save_error'] = 1; } else { if (ezin_update_author($data)) { $ezin_cgi['author_save_ok'] = 1; } else { $ezin_cgi['author_save_unknown_error'] = 1; $ezin_cgi['author_save_error'] = 1; } } } else { if (ezin_exists_author($data['username'])) { $ezin_cgi['author_save_error'] = 1; $ezin_cgi['author_save_already_exists'] = 1; } elseif (! preg_match('|^[a-z][a-z0-9-]{1,32}$|', $data['username'])) { $ezin_cgi['author_save_bad_username'] = 1; $ezin_cgi['author_save_error'] = 1; } elseif ($data['password'] != $data['password_repeat']) { $ezin_cgi['author_save_password_not_match'] = 1; $ezin_cgi['author_save_error'] = 1; } elseif (strlen($data['password']) < 4) { $ezin_cgi['author_save_password_too_short'] = 1; $ezin_cgi['author_save_error'] = 1; } else { if (ezin_insert_author($data)) { $ezin_cgi['author_save_ok'] = 1; } else { $ezin_cgi['athor_save_unknown_error'] = 1; $ezin_cgi['author_save_error'] = 1; } } } ezin_author_send_notify_email($data); } } /* }}} */ } if (! empty($ezin_cgi['author_id']) && empty($ezin_cgi['article_id'])) { $ezin_cgi['output'] = 'author'; } $ezin_edit_author = Platon::parse_id_param('ezin_edit_author', false); if (! empty($ezin_edit_author)) { $ezin_cgi['output'] = 'author_edit'; if ($ezin_user != false) { if (empty($ezin_user['author_id'])) { die('Critical constraint violation: array $ezin_user exists, but $ezin_user["author_id"] is empty'); } $ezin_cgi['author_id'] = $ezin_user['author_id']; } } $poll_answer_id = Platon::parse_id_param('ezin_poll_answer_id', 0); if ($poll_answer_id > 0 && @strlen($_SERVER['HTTP_REFERER']) > 0) { $poll_id = ezin_is_valid_poll($poll_answer_id); $poll_cookie = 'ezin_poll_'.$poll_id; if (! isset($_COOKIE[$poll_cookie])) { ezin_poll_answer_vote($poll_answer_id, $poll_id); ezin_cache_clear("P$poll_id"); setcookie($poll_cookie, $poll_answer_id); } header('Location: '.$_SERVER['HTTP_REFERER']); exit; } /* This part creates $ezin_cgi['lang_bind'] array, which will be used for template language variables substitution. */ if (is_array($ezin_cfg['languages'])) { $type = $ezin_cgi['output'] == 'section' ? 'S' : 'A'; foreach ($ezin_cfg['languages'] as $val) { if (empty($lang_tbl[$val])) { $id = $type == 'S' ? $ezin_cgi['section_id2'] : $ezin_cgi['article_id2']; $ezin_cgi['lang_bind'][$val] = ezin_get_link($type, $id, 0, $val, 1); } else { if (is_null($lang_tbl[$val.'3'])) { $ezin_cgi['lang_bind'][$val] = ezin_get_link($lang_tbl_type, $lang_tbl[$val.'2'], 0, $val); } else { $url_prefix = (substr($lang_tbl[$val.'3'], 0, 1) == '/' && substr($ezin_cfg['url'], -1) == '/') ? substr($ezin_cfg['url'], 0, -1) : $ezin_cfg['url']; $ezin_cgi['lang_bind'][$val] = $url_prefix.$lang_tbl[$val.'3']; } } } } else { $ezin_cgi['lang_bind'] = ''; } /* * Redirects are here * (all of them should be here) */ $do_redirect = false || ($ezin_cgi['message_save_ok'] && $ezin_cfg['message_save_redirect']) || ($ezin_cgi['feedback_save_ok'] && $ezin_cfg['feedback_save_redirect']) || ($ezin_cfg['author_save_ok']); if ($do_redirect) { $request_uri = $_SERVER['REQUEST_URI']; $location = ezin_get_schema().'://'.$_SERVER['HTTP_HOST'].$request_uri; if (strpos($request_uri, '?') === false) { if (intval($ezin_cgi['article_id']) > 0) { $location = ezin_get_link('A', $ezin_cgi['article_id'], 1, @$ezin_cgi['lang']); } else { $location = ezin_get_link('S', $ezin_cgi['section_id'], 1, @$ezin_cgi['lang']); } } $success = 'thanks=1'; if (strpos($location, '?') !== false) { $location .= (substr($location, -1) == '?') ? $success : '&'.$success; } else { $location .= '?'.$success; } if (strlen(@$_POST['ezin_fragment']) > 0) { $location .= '#'.$_POST['ezin_fragment']; } Platon::redirect($location, true /* temporary redirect */); } } /* }}} */ function ezin_check_antispam($flag = '') /* {{{ */ { global $ezin_cfg, $ezin_cgi; if (strlen($flag) > 0) { /* we have flag, so we are going to check answer */ $antispam = ezin_get_antispam(); return (stristr($ezin_cfg['antispam_flags'], $flag) == false || $antispam['correct_answer']); } /* we do not have any flag */ switch ($ezin_cgi['output']) { case 'message': case 'message_edit': return stristr($ezin_cfg['antispam_flags'], 'M'); case 'author_edit': return stristr($ezin_cfg['antispam_flags'], 'A'); case 'section': // feedback? return stristr($ezin_cfg['antispam_flags'], 'F'); // newletter not implemented and is always true } return true; } /* }}} */ function ezin_get_antispam() { global $ezin_cfg; global $ezin_cgi; global $ezin_runtime_cache; if (!is_null($ezin_runtime_cache['ezin_get_antispam'])) { return $ezin_runtime_cache['ezin_get_antispam']; } $submit_name = 'ezin_save_feedback'; if (strlen(Platon::parse_id_param('ezin_save_message', false)) > 0 || strlen(Platon::parse_id_param('ezin_add_new', false)) > 0 || in_array($ezin_cgi['input'], array('message', 'message_edit', 'message_full_list', 'message_selected_list'))) { $submit_name = 'ezin_save_message'; } if (strlen(Platon::parse_id_param('ezin_save_author', false)) > 0 || in_array($ezin_cgi['input'], array('author', 'author_edit'))) { $submit_name = 'ezin_save_author'; } $ret = array(); switch($ezin_cfg['antispam_type']) { case 'rotate': require_once 'libpub/RotateAntispam/RotateAntispam.php'; $opts = array( 'debug' => $ezin_cfg['debug_level'] > 0, 'submit_name' => $submit_name, 'answer_name' => 'ezin_antispam_answer', 'image' => 'libpub/RotateAntispam/images/obrazok.png', 'url' => $ezin_cfg['url'].'libpub/RotateAntispam/RotateAntispam.php', 'encoding' => $ezin_cfg['encoding'] ); $antispam = new RotateAntispam($opts); $ret['correct_answer'] = $antispam->correctAnswer(); $antispam = new RotateAntispam($opts); $texts = isset($ezin_cgi['antispam_texts'][$ezin_cgi['lang']]) ? $ezin_cgi['antispam_texts'][$ezin_cgi['lang']] : $ezin_cgi['antispam_texts']['en']; foreach ($texts as $key => $val) { $antispam->setText($key, $val); } $ret['question'] = '' .$antispam->getAntispamHtml(); $ret['answer'] = '*****'; break; case 'empty': $ret['question'] = $ezin_cfg['antispam_question']; $ret['answer'] = $ezin_cfg['antispam_answer']; $ret['correct_answer'] = (bool)(strlen($_REQUEST['ezin_antispam']) == 0); break; case 'timetoken': $ret['question'] = '' .''; $ret['answer'] = '*****'; $ret['correct_answer'] = ezin_timetoken_check($_REQUEST['ezin_antispam']); break; case 'default': default: $ret['question'] = $ezin_cfg['antispam_question']; $ret['answer'] = $ezin_cfg['antispam_answer']; $ret['correct_answer'] = (bool)(strlen(trim($ezin_cfg['antispam_answer'])) > 0 && strcasecmp(trim($ezin_cfg['antispam_answer']), trim($_REQUEST['ezin_antispam'])) == 0); break; } $ezin_runtime_cache['ezin_get_antispam'] = $ret; return $ret; } function ezin_timetoken_generate() { $trans = array( '0' => 'a', '1' => 'b', '2' => 'c', '3' => 'd', '4' => 'e', '5' => 'f', '6' => 'g', '7' => 'h', '8' => 'i', '9' => 'j' ); $str = (string)Time(); $str_trans = ''; for ($i = 0; $i < strlen($str); $i++) { $str_trans .= $trans[substr($str, $i, 1)]; } $ret = base64_encode($str_trans); return $ret; } function ezin_timetoken_check($token) { $str_trans = base64_decode($token); $trans = array( 'a' => '0', 'b' => '1', 'c' => '2', 'd' => '3', 'e' => '4', 'f' => '5', 'g' => '6', 'h' => '7', 'i' => '8', 'j' => '9' ); $str = ''; for ($i = 0; $i < strlen($str_trans); $i++) { $str .= $trans[substr($str_trans, $i, 1)]; } $time = (int)$str; return (strlen($str) > 0 && $time >= (Time() - (30*60)) // 30 minutes && $time <= Time()); } /* * dir_app - directory application related functions */ function ezin_dir_app_error_handler() /* {{{ */ { // // nothing to see here :-) // } /* }}} */ function ezin_dir_app_get_evalcode($url_part, $lib2_dir = null) /* {{{ */ { if (strlen($lib2_dir) <= 0) { $lib2_dir = $url_part; } $ret =<< $rewrite) { $vals = array_values($rewrite); if (in_array($action, $rewrite)) { return $key; } } return null; } function ezin_redirect_special($redirect) { global $ezin_cfg; $redirect_temporary = false; $redirect_code_map = array(1 => 301, 2 => 302, 3 => 303); if ($ezin_cfg['debug_level'] > 0) { $redirect_temporary = true; } if ($ezin_cfg['debug_level'] > 1) { echo 'Debug: Redirect '.$redirect.'
'; } else { Platon::redirect($redirect, $redirect_temporary, $redirect_code_map[$ezin_cfg['link_redirect']]); } } function ezin_redirect_section($section_id, $type = null) { global $ezin_cfg; if ($type == null) { $type = $ezin_cfg['link_file_type']; } $ar = ezin_validate_IDs(array('section_id' => $section_id)); $section_key = strlen($ar['section_access_key']) > 0 ? $ar['section_access_key'] : $ar['section_id']; switch($type) { case 0: $redirect = $ezin_cfg['url'].'index.php?ezin_section_key='.$section_key; break; case 1: $redirect = $ezin_cfg['url'].'section.php?'.$section_key; break; case 2: $redirect = $ezin_cfg['url'].$section_key; break; } ezin_redirect_special($redirect); } function ezin_redirect_article($article_id, $type = null) { global $ezin_cfg; if ($type == null) { $type = $ezin_cfg['link_file_type']; } $ar = ezin_validate_IDs(array('article_id' => $article_id)); $section_key = strlen($ar['section_access_key']) > 0 ? $ar['section_access_key'] : $ar['section_id']; $article_key = strlen($ar['article_access_key']) > 0 ? $ar['article_access_key'] : $ar['article_id']; switch($type) { case 0: $redirect = $ezin_cfg['url'].'index.php?ezin_article_key='.$article_key; break; case 1: $redirect = $ezin_cfg['url'].'article.php?'.$article_key; break; case 2: $redirect = $ezin_cfg['url'].$section_key.'/'.$article_key; break; } ezin_redirect_special($redirect); } function ezin_redirect_author($author_id, $type = null) { global $ezin_cfg; if ($type == null) { $type = $ezin_cfg['link_file_type']; } $ar = ezin_validate_IDs(array('author_id' => $author_id)); $author_key = strlen($ar['author_access_key']) > 0 ? $ar['author_access_key'] : $ar['author_id']; switch($type) { case 0: $redirect = $ezin_cfg['url'].'index.php?ezin_author_key='.$author_key; break; case 1: $redirect = $ezin_cfg['url'].'author.php?'.$author_key; break; case 2: $redirect = $ezin_cfg['url'].ezin_get_rewrite_action('author').'/'.$author_key; break; } ezin_redirect_special($redirect); } function ezin_redirect_print($article_id, $type = null) { global $ezin_cfg; if ($type == null) { $type = $ezin_cfg['link_file_type']; } $ar = ezin_validate_IDs(array('article_id' => $article_id)); $article_key = strlen($ar['article_access_key']) > 0 ? $ar['article_access_key'] : $ar['article_id']; switch($type) { case 0: $redirect = $ezin_cfg['url'].'index.php?ezin_article_key='.$article_key.'&ezin_print=1'; break; case 1: $redirect = $ezin_cfg['url'].'print.php?'.$article_key; break; case 2: $redirect = $ezin_cfg['url'].ezin_get_rewrite_action('print').'/'.$article_key; break; } ezin_redirect_special($redirect); } function ezin_redirect_message($message_id, $type = null) { global $ezin_cfg; if ($type == null) { $type = $ezin_cfg['link_file_type']; } switch($type) { case 0: $redirect = $ezin_cfg['url'].'index.php?ezin_message_id='.$message_id; break; case 1: $redirect = $ezin_cfg['url'].'message.php?'.$message_id; break; case 2: $redirect = $ezin_cfg['url'].ezin_get_rewrite_action('message').'/'.$message_key; break; } ezin_redirect_special($redirect); } function ezin_redirect_auto($ar) { if (isset($ar['article_id']) && intval($ar['article_id']) > 0) { return ezin_redirect_article($ar['article_id']); } if (isset($ar['section_id']) && intval($ar['section_id']) > 0) { return ezin_redirect_section($ar['section_id']); } if (isset($ar['author_id']) && intval($ar['author_id']) > 0) { return ezin_redirect_author($ar['author_id']); } } /* * Miscellaneous Site Maps */ /* Implementation http://www.sitemaps.org/protocol.html */ function ezin_get_sitemap() { $cache_id = 'ezin_sitemap'; $cache_ar = ezin_cache_load($cache_id); if (intval($cache_ar['timestamp']) <= 0) { $host = 'http://'.$_SERVER['HTTP_HOST']; $ret = '<| "<" |>?xml version="1.0" encoding="<|$ezin_encoding|>" ?<| ">\n" |> '."\n"; $oldest_dt = ezin_get_oldest_dt(); $sections = ezin_get_section_list(); foreach($sections as $section) { ezin_section_link_process($section); $changed_dt = ''; $changed_dt = (strlen($changed_dt) <= 0) ? $section['section_changed_dt'] : $changed_dt; $changed_dt = (strlen($changed_dt) <= 0) ? $section['section_created_dt'] : $changed_dt; $changed_dt = (strlen($changed_dt) <= 0 || strtotime($oldest_dt) > strtotime($changed_dt)) ? $oldest_dt : $changed_dt; $separator = (substr($host, -1) != '/' && substr($article['section_link'], 0, 1) != '/') ? '/' : ''; $ret .= ' '.$host.$separator.$section['section_link'].' '.date("Y-m-d", strtotime($changed_dt)).' '."\n"; } $articles = ezin_get_available_articles(); foreach($articles as $article) { ezin_article_link_process($article); $changed_dt = ''; $changed_dt = (strlen($changed_dt) <= 0) ? $article['article_changed_dt'] : $changed_dt; $changed_dt = (strlen($changed_dt) <= 0) ? $article['article_created_dt'] : $changed_dt; $changed_dt = (strlen($changed_dt) <= 0) ? $oldest_dt : $changed_dt; $separator = (substr($host, -1) != '/' && substr($article['article_link'], 0, 1) != '/') ? '/' : ''; $ret .= ' '.$host.$separator.$article['article_link'].' '.date("Y-m-d", strtotime($changed_dt)).' '."\n"; } $ret .= ''."\n"; ezin_cache_save($cache_id, $ret); $cache_ar['content'] = $ret; } return $cache_ar['content']; } /* Basic HTML list of all section and articles */ function ezin_get_htmlmap($lang = null) { global $ezin_cfg; $cache_id = (strlen($lang) > 0) ? 'ezin_htmlmap_'.$lang : 'ezin_htmlmap'; $cache_ar = ezin_cache_load($cache_id); if (intval($cache_ar['timestamp']) <= 0) { $host = 'http://'.$_SERVER['HTTP_HOST']; $ret = '
    '."\n"; $articles = ezin_get_available_articles($lang); function compare_article($a, $b) { if ($a['article_access_key'] == $b['article_access_key']) { return strcmp($a['article_title'], $b['article_title']); } else { return strcmp($a['article_access_key'], $b['article_access_key']); } } usort($articles, "compare_article"); $articles_html = ''; foreach($articles as $article) { ezin_article_link_process($article); $separator = (substr($host, -1) != '/' && substr($article['article_link'], 0, 1) != '/') ? '/' : ''; $articles_html[$article['article_section_id']] .= "\t\t\t".'
  • '."\n" ."\t\t\t\t".''.$article['article_title'].''."\n" ."\t\t\t".'
  • '."\n"; } $sections = ezin_get_section_list($lang); foreach($sections as $section) { ezin_section_link_process($section); $separator = (substr($host, -1) != '/' && substr($article['section_link'], 0, 1) != '/') ? '/' : ''; $ret .= "\t".'
  • '."\n" ."\t\t".''.$section['section_name'].''."\n"; if (isset($articles_html[$section['section_id']]) && strlen($articles_html[$section['section_id']]) > 0) { $ret .= "\t\t".'
      '."\n".$articles_html[$section['section_id']] ."\t\t".'
    '."\n"; unset($articles_html[$section['section_id']]); } $ret .= "\t".'
  • '."\n"; } if (is_array($articles_html) && count($articles_html) > 0) { // Last $ret .= "\t".'
  • '."\n" ."\t\t".$ezin_cfg['name']."\n"; foreach($articles_html as $article) { $ret .= "\t\t".'
      ' ."\n".$article ."\t\t".'
    '."\n"; } $ret .= "\t".'
  • '."\n"; } $ret .= '
'."\n"; ezin_cache_save($cache_id, $ret); $cache_ar['content'] = $ret; } return $cache_ar['content']; } /* * Admin API */ function ezin_admin_init_app($apps_dir) { if (!file_exists($apps_dir)) { return false; } global $_ezin_admin; $apps_dirs = scandir($apps_dir); if (is_array($apps_dirs)) foreach($apps_dirs as $app_dir) { $app_init_file = $apps_dir.'/'.$app_dir.'/init.inc.php'; if (!in_array($app_dir, array('.','..')) && is_dir($apps_dir.'/'.$app_dir) && file_exists($app_init_file) && is_readable($app_init_file)) { $_ezin_admin['appsdir_curr'] = $apps_dir; $_ezin_admin['app_curr'] = $app_dir; require_once $app_init_file; } } } function ezin_admin_db_check($title, $test, $test_output, $fix) { global $_ezin_admin; if (!is_array($_ezin_admin['db_check'])) { $_ezin_admin['db_check'] = array(); } $_ezin_admin['db_check'][] = array( 'app' => $_ezin_admin['app_curr'], 'title' => $title, 'test' => $test, 'test_output' => $test_output, 'fix' => $fix, ); } function ezin_admin_db_check_run() { global $_ezin_admin; global $ezin_sys; global $ezin_db_handle; if (!is_array($_ezin_admin['db_check'])) { $_ezin_admin['db_check'] = array(); } $ret = array(); foreach ($_ezin_admin['db_check'] as $check) { $result = mysqli_query($ezin_db_handle, $check['test']) or ezin_db_error('ezin_admin_db_check_run() [1]'); $row = mysqli_fetch_array($result, MYSQLI_NUM); mysqli_free_result($result); if ($row == null || (is_array($row) && $row[0] != $check['test_output'])) { mysqli_query($ezin_db_handle, $check['fix']) or ezin_db_error('ezin_admin_db_check_run() [2]'); // TEST again $result = mysqli_query($ezin_db_handle, $check['test']) or ezin_db_error('ezin_admin_db_check_run() [1]'); $row = mysqli_fetch_array($result, MYSQLI_NUM); mysqli_free_result($result); if ($row == null || (is_array($row) && $row[0] != $check['test_output'])) { $result = -1; // Test after fix FAILED } else { $result = 2; // Test after fix SUCCESSFUL } } else { $result = 1; // TEST OK } $ret[] = array( 'app' => $check['app'], 'title' => $check['title'], 'result' => $result, ); } return $ret; } function ezin_admin_menu_add($action, $caption, $link, $inc_file, $column, $after_action = null, $visible = true) { global $_ezin_admin; if (!is_array($_ezin_admin['menu'])) { $_ezin_admin['menu'] = array(); } if (!is_array($_ezin_admin['menu_hashes'])) { $_ezin_admin['menu_hashes'] = array(); } $menu_hash = $action.'/'.$link; if (in_array($menu_hash, $_ezin_admin['menu_hashes'])) { echo 'Error: Duplicate menu links "'.$menu_hash.'"'; return false; } $_ezin_admin['menu_hashes'][] = $menu_hash; $_ezin_admin['menu'][] = array( 'action' => $action, 'caption' => $caption, 'link' => $link, 'inc_file' => $inc_file, 'column' => $column, 'after_action' => $after_action, 'visible' => $visible, 'apps_dir' => $_ezin_admin['appsdir_curr'], 'app_dir' => $_ezin_admin['app_curr'], ); } function ezin_admin_menu_get() { global $_ezin_admin; if (!is_array($_ezin_admin['menu'])) { $_ezin_admin['menu'] = array(); } return $_ezin_admin['menu']; } function ezin_admin_menu_info($app, $link) { global $_ezin_admin; if (!is_array($_ezin_admin['menu'])) { $_ezin_admin['menu'] = array(); } foreach ($_ezin_admin['menu'] as $menu) { if ($menu['app_dir'] == $app && $menu['link'] == $link) { return $menu; } } return false; } function ezin_admin_app_url($app, $link) { $info = ezin_admin_menu_info($app, $link); if ($info == false) { return false; } global $ezin_cfg, $ezin_sys; return $ezin_cfg['url'].$ezin_sys['dir']['admin'].'/app/'.$info['app_dir'].'/'.$info['link'].'/'; } /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */ ?>