* @copyright Activeunit Inc 2001-2004 * @version 1.0 */ include_once('./site_features.php'); Define('DB_HOST', 'localhost'); Define('DB_NAME', 'smartliving_connect'); Define('DB_USER', 'smartliving_conn'); Define('DB_PASSWORD', 'xZqKMixM4o'); Define('ROOT', "./"); Define('ROOTHTML', "/"); Define('DIR_TEMPLATES', "./templates/"); Define('DIR_MODULES', "./modules/"); // Define('DEBUG_TEMPLATES', 1); Define('DEBUG_MODE', 1); Define('PROJECT_DOMAIN', "connect.smartliving.ru"); Define('PROJECT_TITLE', PROJECT_DOMAIN); Define('PROJECT_BUGTRACK', "jey@activeunit.com"); Define('WM_SECRET_KEY', 'connect2'); Define('WM_PAYEE_PURSE_RU', 'R130683285076'); Define('WM_PAYEE_PURSE_USD', 'Z157268520239'); Define('YANDEX_SECRET', 'OFJtJOye/42W1rIA3v0XiaOJ'); * @copyright ActiveUnit, Inc. 2001-2003 * @version 2.2b * @modified 07-Jan-2004 */ class jTemplate { /** * @var array input data */ var $data; // data /** * @var string input template filename */ var $template; /** * @var string parsing result */ var $result; /** * @var object parser's owner (for correct [#module ...#] tags processing) */ var $owner; /** * Object constructor * * @access public * @param string $template input template filename * @param array $data input data * @param object $owner parser owner */ function jTemplate($template, &$data, &$owner) { // set current directory for template includes if (strpos($template, "/") !== FALSE) { $root=preg_replace("/\/[^\/]*?$/","",$template)."/"; } else { $root=""; } $this->data=&$data; $this->template=$template; if (Is_Object($owner)) { $this->owner=&$owner; } $template_file=$this->loadfile($template); $res=""; if (Defined("DEBUG_TEMPLATES")) { // creating layer for debugging purpose $res.="
"; } if ($this->owner->ajax) { $this->ajax=1; $this->div_id=$this->owner->name; if ($this->owner->owner->name) { $this->div_id=$this->div_id.'_'.$this->owner->owner->name; } $res.="
div_id."\">"; // dyn } $res.=$this->parse($template_file, $this->data, $root); if (strpos($res, '{#')) { //second pass $res=str_replace('{#', '[#', $res); $res=str_replace('#}', '#]', $res); $res=$this->parse($res, $this->data, $root); } if ($this->ajax) { $res.="
"; // dyn } if (Defined("DEBUG_TEMPLATES")) { $res.="
"; } $this->result=$res; } /** * Parsing routine * *Used to parse jTeplates-style templates and return plain html-pages *(for details read manual on jTempates) * * @access private * @param string $line template strings * @param array $hash data params * @param string $dir current template directory (for correct [#inc ...#] tags parsing) * @return string parsed template strings */ function parse($res, &$hash, $dir) { // $res=$line; // COMMENTS if (Is_Integer(strpos($res, '/is", "", $res); } //NOTE: compiler should be perfect for this template engine (����) // METHODS if (Is_Integer(strpos($res, '[#method '))) { $this->parseMethods($res, $hash); } // GLOBALS $this->parseGlobals($res, $hash); // BLOCKS if (Is_Integer(strpos($res, '[#block '))) { $this->parseBlocks($res, $hash, $dir); } // DYN LINKS if ($this->ajax && (Is_Integer(strpos($res, 'dnlnk') || Is_Integer(strpos($res, 'dnfrm'))))) { $this->parseDynLinks($res); } // ARRAYS if (Is_Integer(strpos($res, '[#begin '))) { $this->parseArrays($res, $hash, $dir); } // HASHES $this->parseHashes($res, $hash); // CONDITIONS if (Is_Integer(strpos($res, '[#if '))) { $this->parseIf($res, $hash); } // MODULES if (Is_Integer(strpos($res, '[#module '))) { $this->parseModules($res, $hash, $dir); } // INCLUDE FILES if (Is_Integer(strpos($res, '[#inc '))) { $this->parseIncludes($res, $hash, $dir); } // VARIABLES if (Is_Integer(strpos($res, '[#'))) { $this->parseVariables($res, $hash); } return $res; } /** * Dynlink parsing * * ... * * @access private * @param string $res template strings * @return string parsed template strings */ function parseDynLinks(&$res) { $res=str_replace('dnlnk', " onClick='return getBlockData(\"".$this->div_id."\", this.href);'", $res); $res=str_replace('dnfrm', " onClick='return getBlockDataForm(\"".$this->div_id."\", this.form);'", $res); } /** * Method tag parsing * * Used to process block content * * @access private * @param string $res template strings * @return string parsed template strings */ function parseMethods(&$res,&$hash){ if (preg_match_all('/\[#method (\w+?)#\](.+?)\[#endmethod#\]/is', $res, $matches)) { $count_matches_0=count($matches[0]); for($i=0;$i<$count_matches_0;$i++) { $method=$matches[1][$i]; $content=$matches[2][$i]; if (method_exists($this->owner, $method)) { $o=$this->owner->$method($content); } elseif (function_exists($method)) { $o=$method($content, $this->owner); } else { $o="".$content; } $res=str_replace($matches[0][$i], $o, $res); } } return $res; } /** * Block tag parsing * * Used to include template blocks with params [#block name param="value"#]..[#endblock name#] * * @access private * @param string $res template strings * @return string parsed template strings */ function parseBlocks(&$res,&$hash){ if (preg_match_all('/\[#block (.*?)#\]/', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_0=count($matches[0]); for($i=0;$i<$count_matches_0;$i++) { $raw=$matches[1][$i]; if (Is_Integer(strpos($raw, '="'))) { // inc file parameters $new_hash=$hash; preg_match_all('/(\w+?)="(.*?)"/', $raw, $matches1, PREG_PATTERN_ORDER); $count_matches1_0=count($matches1[0]); for($k=0;$k<$count_matches1_0;$k++) { $new_hash[$matches1[1][$k]]=$matches1[2][$k]; $raw=str_replace($matches1[0][$k], '', $raw); } } $block_name=$dir.trim($raw); $file_name=$block_name.".html"; if (!file_exists(ROOT."templates/blocks/".$file_name)) { $res=str_replace($matches[0][$i], "", $res); } else { $tmp=explode("[#...#]", LoadFile(ROOT."templates/blocks/".$file_name)); if (IsSet($new_hash) && (Is_Integer(strpos($tmp[0], '[#')) || Is_Integer(strpos($tmp[0], '<#')))) { // CONDITIONS $this->parseGlobals($tmp[0], $new_hash); $this->parseIf($tmp[0], $new_hash); // [#VARIABLE#] - general variables if (preg_match_all('/\[#(\w+?)#\]/', $tmp[0], $matches1, PREG_PATTERN_ORDER)) { for($l=0;$lparseGlobals($tmp[1], $new_hash); $this->parseIf($tmp[1], $new_hash); // [#VARIABLE#] - general variables if (preg_match_all('/\[#(\w+?)#\]/', $tmp[1], $matches1, PREG_PATTERN_ORDER)) { for($l=0;$l tag parsing * * @access private * @param string $res template strings * @param array $hash data params */ function parseGlobals(&$res, &$hash) { // <#VARIABLE#> - global variables if (preg_match_all('/[<#]#(\w+?)#[>#]/', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_1=count($matches[1]); for($i=0;$i<$count_matches_1;$i++) { if (defined($matches[1][$i])) { $res=str_replace($matches[0][$i], constant($matches[1][$i]), $res); } else { $res=str_replace($matches[0][$i], $hash[$matches[1][$i]], $res); } } } } /** * [#beging ...#]...[#end ...#] tag parsing * * @access private * @param string $res template strings * @param array $hash data params */ function parseArrays(&$res, &$hash, $dir) { // [#begin ARRAY#][#DATA#][#end ARRAY#] - arrays/blocks while (preg_match_all('/\[#begin (.*?)#\](.*?)\[#end \1#\]/is', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_0=count($matches[0]); for($i=0;$i<$count_matches_0;$i++) { $var=$hash[$matches[1][$i]]; $line1=$matches[2][$i]; $res1=""; if ((Is_array($var)) && (count($var)>0) && (!IsSet($var[0]))) { // hashtable if (preg_match_all("/<#{$matches[1][$i]}\.(\w+?)#>/", $line1, $matches2, PREG_PATTERN_ORDER)) { for($m=0;$mtemplateSafe($var[$matches2[1][$m]]), $line1); } } $res1.=$this->parse($line1, $var, $dir); } elseif ((Is_Array($var)) && (count($var)>0) && (Is_Array($var[0]))) { // echo $matches[1][$i]."
"; // index array $count_var=count($var); for ($k=0;$k<$count_var;$k++) { $line2=$line1; $matches1=array(); // <#ARRAY.VARIABLE#> - array variables if (preg_match_all("/<#{$matches[1][$i]}\.(\w+?)#>/", $line1, $matches1, PREG_PATTERN_ORDER)) { $count_matches1_1=count($matches1[1]); for($m=0;$m<$count_matches1_1;$m++) { @$line2=str_replace($matches1[0][$m], $this->templateSafe($var[$k][$matches1[1][$m]]), $line2); } } // IF operations if no sub-arrays if ((!Is_Integer(strpos($line2, "[#begin")))) { // CONDITIONS if (Is_Integer(strpos($line2, "[#if"))) { $this->parseIf($line2, $var[$k]); } $this->parseVariables($line2, $var[$k]); } // SELF-CALL FOR ARRAY ELEMENT $line2=str_replace("[#tree ".$matches[1][$i]."#]", "[#begin ".$matches[1][$i]."#]".$line1."[#end ".$matches[1][$i]."#]", $line2); if (Is_Integer(strpos($line2, "[#"))) { $res1.=$this->parse($line2, $var[$k], $dir); } else { $res1.=$line2; } } } elseif ((Is_array($var)) && (count($var)>0) && IsSet($var[0]) && (!Is_Array($var[0]))) { // NOT HASH TABLE - PLAIN ARRAY $this->parseHashes($line1,$hash); if (IsSet($hash['VALUE'])) $tmp=$hash['VALUE']; $hash['__Count__']=count($var); for ($k=0;$kparse($line1, $hash, $dir); } if (IsSet($tmp)) $hash['VALUE']=$tmp; unset($tmp); unset($hash['__Count__']); unset($hash['__Key__']); } $res=str_replace($matches[0][$i], $res1, $res); } } } /** * <#VARIABLE.VARIABLE#> tag parsing * * @access private * @param string $res template strings * @param array $hash data params */ function parseHashes(&$res, &$hash) { // <#VARIABLE.VALUE#> - hash variables (pre-conditions) if (preg_match_all('/<#(\w+?)\.(\w+?)#>/', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_1=count($matches[1]); for($i=0;$i<$count_matches_1;$i++) { $res=str_replace($matches[0][$i], $this->templateSafe($hash[$matches[1][$i]][$matches[2][$i]]), $res); } } } /** * If tag parsing * * @access private * @param string $res template strings * @param array $hash data params */ function parseIf(&$res, &$hash) { // removing old-slyle "else" and "endif" expressions $res=preg_replace("/\[#else .+?#\]/", "[#else#]", $res); $res=preg_replace("/\[#endif .+?#\]/", "[#endif#]", $res); $last_level=0; // looking through all if coditions $old_res=$res; $old_res_count=substr_count($old_res, "[#if"); for($k=1;$k<=$old_res_count;$k++) { $begin=0; $replaced=0; while (!$replaced) { $begin=strpos($res, "[#if", $begin); $end=strpos($res, "[#endif#]", $begin); $middle=strpos($res, "[#if", ($begin+1)); if ((Is_Integer($begin)) && (Is_Integer($end)) && ($end>$begin) && ((!Is_Integer($middle)) || ($middle>$end))) { $bdy=substr($res, $begin, ($end-$begin)); $bdy_old=$bdy."[#endif#]"; $tmp2=strpos($bdy, '#]'); $condition=trim(substr($bdy, 4, ($tmp2-4))); $body=substr($bdy, ($tmp2+2), strlen($bdy)); $true_part=""; $false_part=""; $temp=array(); $temp=explode("[#else#]", $body); $true_part=$temp[0]; $false_part=$temp[1]; $condition=preg_replace('/^!(\w+)$/', '!IsSet($hash[\'\\1\'])', $condition); $condition=preg_replace('/^(\w+)$/', 'IsSet($hash[\'\\1\'])', $condition); $condition=preg_replace('/(\w+)(?=[=!<>])/', '$hash[\'\\1\']', $condition); $condition=preg_replace('/\((\w+)\)/', '($hash[\'\\1\'])', $condition); $condition=preg_replace('/\]=(?=[^\w=])/', ']==', $condition); $str="if ($condition) {\$res1=\$true_part;} else {\$res1=\$false_part;}"; if ($_GET['debug']) { //echo $str."
"; } eval($str); $bdy=$res1; $res=str_replace($bdy_old, $bdy, $res); $replaced=1; } elseif ((Is_Integer($begin)) && (Is_Integer($end)) && ($end>$begin) && ((!Is_Integer($middle)) || ($middle<$end))) { $replaced=0; $begin=$middle; } else { $replaced=1; } } } } /** * Module tag parsing * * Used to include other object-modules in current workspace * * @access private * @param string $res template strings * @param array $hash data params * @param string $dir current template directory (for correct [#inc ...#] tags parsing) */ function parseModules(&$res, &$hash, $dir) { global $md; global $inst; $instance=$inst; if (preg_match_all('/\[#module (.*?)#\]/', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_0=count($matches[0]); for($i=0;$i<$count_matches_0;$i++) { $data=$matches[1][$i]; $tmp=""; // reading module data from module including directive $module_data=array(); if (preg_match_all('/(\w+?)="(.*?)"/i', $data, $matches1, PREG_PATTERN_ORDER)) { $count_matches1_0=count($matches1[0]); for($k=0;$k<$count_matches1_0;$k++) { $key=$matches1[1][$k]; $value=$matches1[2][$k]; if ($key=="template") { $value=$dir.$value; } $module_data[$key]=$value; } } if ((file_exists(DIR_MODULES.$module_data["name"].'/'.$module_data["name"].".class.php")) || (class_exists($module_data["name"]))) { // including module class if (!class_exists($module_data["name"])) { include_once(DIR_MODULES.$module_data["name"].'/'.$module_data["name"].".class.php"); } $object = new $module_data["name"]; $object->owner=$this->owner; foreach ($module_data as $k=>$v) { if ($k=='name') continue; $object->{$k}=$v; } // setting other module parameters // if current request is to this module, then run get params otherwise get params from encoded query if (($md!=$module_data["name"]) || (($module_data["instance"]!='') && ($module_data["instance"]!=$instance) && ($instance!=''))) { // restoring module params from coded string (module should not overwrite this method) $object->restoreParams(); } elseif (($module_data["name"]==$md) && (($module_data["instance"]=='') || ($module_data["instance"]==$instance) || ($instance==''))) { // getting module params from query string (every module should handle this method) $object->getParams(); } foreach ($module_data as $k=>$v) { if ($k=='name') continue; $object->{$k}=$v; } $object->run(); $tmp=$object->result; /* // creating code for module creation and running $obj="\$object$i"; $code=""; $code.="$obj=new ".$module_data["name"].";\n"; $code.=$obj."->owner=&\$this->owner;\n"; // setting module parameters from module including directive foreach ($module_data as $k=>$v) { if ($k=="name") continue; $code.=$obj."->".$k."='".addslashes($v)."';\n"; } // setting other module parameters // if current request is to this module, then run get params otherwise get params from encoded query if (($md!=$module_data["name"]) || (($module_data["instance"]!='') && ($module_data["instance"]!=$instance) && ($instance!=''))) { // restoring module params from coded string (module should not overwrite this method) $code.=$obj."->restoreParams();\n"; } elseif (($module_data["name"]==$md) && (($module_data["instance"]=='') || ($module_data["instance"]==$instance) || ($instance==''))) { // getting module params from query string (every module should handle this method) $code.=$obj."->getParams();\n"; } // repeating module set parameters for security reasons foreach ($module_data as $k=>$v) { if ($k=="name") continue; $code.=$obj."->".$k."='".addslashes($v)."';\n"; } // run module and insert module result in template $code.=$obj."->run();\n"; $code.="\$tmp=".$obj."->result;\n"; eval($code); */ } else { // module class file was not found global $current_installing_module; $rep_ext=''; if (preg_match('/\.dev/is', $_SERVER['HTTP_HOST'])) { $rep_ext='.dev'; $install_dir="/var/projects/repository/engine_2.x/modules/"; } if (preg_match('/\.jbk/is', $_SERVER['HTTP_HOST'])) { $rep_ext='.jbk'; $install_dir="d:/jey/projects/repository/engine_2.x/modules/"; } if (!$current_installing_module[$module_data["name"]] && $rep_ext!='' && (@Is_Dir($install_dir.$module_data["name"]))) { //$tmp="
"; $wnd_name="win".rand(1, 10000000); $tmp=""; $current_installing_module[$module_data["name"]]=1; echo $tmp; } else { $tmp="

Module \"".$module_data["name"]."\" not found (".str_replace('#', '', $matches[0][$i]).")

"; } } //echo $matches[0][$i]; //echo htmlspecialchars($tmp)."\n\n"; $res=str_replace($matches[0][$i], $tmp, $res); } } } /** * [#inc ...#] tag parsing * * @access private * @param string $res template strings * @param array $hash data params * @param string $dir current template directory (for correct [#inc ...#] tags parsing) */ function parseIncludes(&$res, &$hash, $dir) { if (preg_match_all('/\[#inc (.*?)#\]/', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_0=count($matches[0]); for($i=0;$i<$count_matches_0;$i++) { $raw=$matches[1][$i]; if (Is_Integer(strpos($raw, '="'))) { // inc file parameters $new_hash=$hash; preg_match_all('/(\w+?)="(.*?)"/', $raw, $matches1, PREG_PATTERN_ORDER); $count_matches1_0=count($matches1[0]); for($k=0;$k<$count_matches1_0;$k++) { $new_hash[$matches1[1][$k]]=$matches1[2][$k]; $raw=str_replace($matches1[0][$k], '', $raw); } } else { $new_hash=&$hash; } $file_name=$dir.trim($raw); if (!file_exists($file_name)) { $res=str_replace($matches[0][$i], "", $res); } else { $new_root=dirname($file_name)."/"; $new_hash=array_merge($this->data,$new_hash); // for global variables (by gusev) if ((Defined("DEBUG_TEMPLATES")) && !Is_Integer(StrPos($file_name, ".js"))) { $id="block".(int)rand(0, 100000); $res=str_replace($matches[0][$i], "
".$this->parse($this->loadfile($file_name), $new_hash, $new_root)."
", $res); } else { if (strstr($file_name,'.tpl')) { global $smarty; smarty_init(); $smarty->clear_all_assign(); foreach ($new_hash as $k=>$v) $smarty->assign($k,$v); $smarty->work_template=$file_name; $smarty->save_this=$this; $res=str_replace($matches[0][$i],$smarty->fetch(str_replace('./templates/','',$file_name)), $res); } else { $res=str_replace($matches[0][$i], $this->parse($this->loadfile($file_name), $new_hash, $new_root), $res); } } } } } return $res; } /** * [#VARIABLE#] tag parsing * * @access private * @param string $res template strings * @param array $hash data params */ function parseVariables(&$res, &$hash) { // [#VARIABLE#] - general variables if (preg_match_all('/\[#(\w+?)#\]/', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_1=count($matches[1]); for($i=0;$i<$count_matches_1;$i++) { $res=str_replace($matches[0][$i], $this->templateSafe($hash[$matches[1][$i]]), $res); } } // [#VARIABLE.VALUE#] - hash variables if (preg_match_all('/\[#(\w+?)\.(\w+?)#\]/', $res, $matches, PREG_PATTERN_ORDER)) { $count_matches_1=count($matches[1]); for($i=0;$i<$count_matches_1;$i++) { $res=str_replace($matches[0][$i], $this->templateSafe($hash[$matches[1][$i]][$matches[2][$i]]), $res); } } } /** * Title * * Description * * @access private */ function templateSafe($val) { $res=$val; $res=str_replace('[#', '[#', $res); $res=str_replace('#]', '#]', $res); $res=str_replace('{#', '{#', $res); $res=str_replace('#}', '#}', $res); $res=str_replace('<#', '<#', $res); $res=str_replace('#>', '#>', $res); return $res; } /** * File loading * * Simple text-file loader * * @access private * @param string $filename filename to load * @return string file content */ function loadfile($filename) { global $preload; $data=""; /* if (@$preload[$filename]!="") { return $preload[$filename]; } */ if (!is_file($filename)) return ''; $f=fopen("$filename", "r"); $data=""; if ($f) { $fsize=filesize($filename); if ($fsize==0) { fclose($f); return ''; } $data=fread($f, $fsize); $preload[$filename]=$data; fclose($f); } return $data; } } // -------------------------------------------------------------------- ?> * @copyright ActiveUnit, Inc * @version 1.1 */ class parser { var $data; // data var $template; // template-file var $result; // result var $owner; // parser's owner object /************************************************************** * Class constructor * * Used to parse templates with data provided * Based on template file extention: * .xslt - XSLT-parser used * .tpl - SMARTY-parser used * all other extensions - jTemplates-parser used * * @param string Template filename * @param mixed Data * @param object Process owner * @return parsing result * @access public */ function parser($template, &$data, $owner="") { // constructor // set current directory for template includes $this->data=&$data; $this->template=$template; if (Is_Object($owner)) { $this->owner=&$owner; } if (strpos($template, ".xslt")==TRUE) { // xslt-Templates $this->result=$this->xslt_parse($template_file, $this->data); } elseif (strpos($template, ".tpl")==TRUE) { // smarty-Templates $this->result=$this->smarty_parse($template, $this->data); } else { // j-Templates $this->result=$this->jtemplate_parse($template, $this->data); } if (Is_Object($this->owner)) { // links parsing for all results (framework support) $this->result=$this->owner->parseLinks($this->result); } } /************************************************************** * jTemplates-parser * * Used to parse jTemplates * * @param string jTemplate filename * @param mixed Data * @access private */ function jtemplate_parse($template, &$data) { /* $compl=new jTemplateCompiler($template, "out", $this->owner); $out=&$data; include($compl->compiled_file); return $result; */ $jTempl=new jTemplate($template, $data, $this->owner); $result=$jTempl->result; return $result; } /************************************************************** * XSLT-parser * * Used to parse xslt-templates * * @param string XSLT-rules * @param mixed Data * @access private */ function xslt_parse($template, &$data) { $new_data["ROOT"]=$data; $xml=new xml_data($new_data); $arguments = array( '/_xml' => $xml->string, '/_xsl' => $template ); $xh=xslt_create(); $result=xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); xslt_free($xh); return $result; } /************************************************************** * SMARTY-parser * * Used to parse SMARTY templates * * param string Template filename * @param mixed Data * @access private */ function smarty_parse($template_file, &$data) { global $smarty; smarty_init(); $smarty->clear_all_assign(); foreach ((array)$data as $k=>$v) $smarty->assign_by_ref($k,$v); $smarty->work_template=$template_file; $result=$smarty->fetch(str_replace('./templates/','',$template_file)); return $result; } } function smarty_init() { static $already; if ($already) return; global $smarty; require ROOT.'smarty/libs/Smarty.class.php'; $smarty = new Smarty(); $smarty->template_dir = ROOT.'templates'; $smarty->compile_dir = ROOT.'smarty/templates_c'; $smarty->cache_dir = ROOT.'smarty/cache'; $smarty->config_dir = ROOT.'smarty/configs'; $smarty->left_delimiter = '[#'; $smarty->right_delimiter = '#]'; $smarty->save_this=&$this; $already=1; $smarty->register_function("inc", "smarty_functions_inc"); $smarty->register_function("module", "smarty_functions_module"); } function smarty_functions_inc($params) { global $smarty; if (!$params['file']) { return "Need set a filename"; } else { $template_file=dirname($smarty->work_template).'/'.$params['file']; $p=new parser($template_file, $smarty->_tpl_vars, $this); return $p->result; } } function smarty_functions_module($params) { global $smarty; if (!$params['name']) { return "Need set a module name"; } else { // function parseModules(&$res, &$hash, $dir) { global $md; global $inst; $instance=$inst; $tmp=""; // reading module data from module including directive $module_data=$params; if ((file_exists(DIR_MODULES.$module_data["name"].'/'.$module_data["name"].".class.php")) || (class_exists($module_data["name"]))) { if (!class_exists($module_data["name"])) { include_once(DIR_MODULES.$module_data["name"].'/'.$module_data["name"].".class.php"); } $object = new $module_data["name"]; $object->owner=$smarty->save_this->owner; foreach ($module_data as $k=>$v) { if ($k=='name') continue; $object->{$k}=$v; } // setting other module parameters // if current request is to this module, then run get params otherwise get params from encoded query if (($md!=$module_data["name"]) || (($module_data["instance"]!='') && ($module_data["instance"]!=$instance) && ($instance!=''))) { // restoring module params from coded string (module should not overwrite this method) $object->restoreParams(); } elseif (($module_data["name"]==$md) && (($module_data["instance"]=='') || ($module_data["instance"]==$instance) || ($instance==''))) { // getting module params from query string (every module should handle this method) $object->getParams(); } foreach ($module_data as $k=>$v) { if ($k=='name') continue; $object->{$k}=$v; } $object->run(); $tmp=$object->result; } return $tmp; } } ?> * @copyright Activeunit Inc 2001-2004 * @version 1.0 */ /* xml_data.class.php - simple XML parser example: $test="MyName(123)123456"; $xml=new xml_data(); // or $xml->set($test[0]); $xml->string $xml->hash */ class xml_data { var $string; // string-style xml data var $hash; // HASH-style xml dat var $ndx; // temporary variable // -------------------------------------------------------------------- function xml_data($in="") { // class constructor if ($in=="") return; if (is_array($in)) { $this->hash=$in; $this->string=$this->toXML($in); } else { $this->string=$in; $this->hash=$this->fromXML($in); } } /** * @access private */ function set($in="") { // set data to object if ($in=="") return; if (is_array($in)) { $this->hash=$in; $this->string=$this->toXML($in); } else { $this->string=$in; $this->hash=$this->fromXML($in); } } /** * Create XML-string from hash-data * * * @param mixed Hash * @access public */ function toXML($hash, $level=0) { // converts from hash to xml $res=""; if (!Is_Array($hash)) { return $res; } foreach($hash as $k=>$v) { if (substr($k, -5)!="_list") { // skip NAME_list variables if ((Is_Array($v)) && IsSet($v[0])) { // array if (IsSet($hash[$k."_list"])) { $v=$hash[$k."_list"]; } for($i=0;$i\n"; $res.=$this->toXML($v[$i], $level+1); $res.=str_repeat(" ", $level)."\n"; } } elseif ((Is_Array($v)) && (!IsSet($v[0]))) { // hash $res.=str_repeat(" ", $level)."<$k>\n".$this->toXML($v, $level+1).str_repeat(" ", $level)."\n"; } else { // variable $res.=str_repeat(" ", $level)."<$k>".$v."\n"; } } } return $res; } /** * Used to create hash-data from XML-based string * * * * @param string XML-data * @access public */ function fromXML($raw, $prev="") { // converts from xml to hash global $ndx; if ($prev=="") { $this->ndx=array(); } $raw = preg_replace('/\<\?.+?\?\>\s*/s', '', $raw); //removes xml tag $i=0; $xml=array(); $pattern='(\s*?)<([^\?]+?)>(.*?)\1<\/\2>'; // tag-pattern if (preg_match_all('/'.$pattern.'/s', $raw, $matches, PREG_PATTERN_ORDER)) { for($m=0;$mfromXML($v, $prev.$k.$i); if (IsSet($this->ndx["$prev"."$k"])) { if ($ndx["$prev"."$k"]==0) { $vv=$xml["$k"]; $xml["$k"]=array(); $xml["$k"][0]=$vv; } $this->ndx["$prev"."$k"]++; $xml["$k"][$this->ndx["$prev"."$k"]]=$res; } else { $this->ndx["$prev"."$k"]=0; $xml["$k"]=$res; } $xml["$k"."_list"][$this->ndx["$prev"."$k"]]=$res; $i++; } } if ($i==0) { return $raw; } else { return $xml; } } // -------------------------------------------------------------------- } // -------------------------------------------------------------------- // RELATIVE GENERAL FUNCTIONS // -------------------------------------------------------------------- function toXML($hash) { $tmp=new xml_data($hash); return $tmp->string; } // -------------------------------------------------------------------- function fromXML($str) { $tmp=new xml_data($str); return $tmp->hash; } // -------------------------------------------------------------------- ?>2 ) ); * $arrTree=$objXml->xml2array( $strXml ); * codepage is latinian, register of $arrTree is lower * * @package framework * @author Rodion Konnov * @version 1.4 */ class parse_xml { /*** constructor ***/ function parse_xml( $arrSetting='' ) { $this->setting['CODING']=( isSet( $arrSetting['CODING'] ) )? $arrSetting['CODING'] : 0; // default - lat; 1 - cp1251(winrus) $this->setting['REGISTER']=( isSet( $arrSetting['REGISTER'] ) )? $arrSetting['REGISTER'] : 1; // default - upper; 2 - lower } /*** xml2array ***/ function xml2array( $strXml ) { $this->mode='xml2array'; if ( !preg_match( '/^/i', $strXml ) ) { $strXml='<'.$this->ApplyTagRegister( 'xml' ).'>'.$strXml.'ApplyTagRegister( 'xml' ).'>'; } $hdlParser=xml_parser_create(); xml_parser_set_option( $hdlParser, XML_OPTION_SKIP_WHITE, 1 ); xml_parse_into_struct( $hdlParser, $strXml, $arrVals, $arrIndex ); xml_parser_free( $hdlParser ); $arrTree=array(); $i=0; $arrTree=$this->fromXml( $arrVals, $i ); return $arrTree; } function fromXml( $arrVals, &$i ) { $arrChildren=array(); if ( $arrVals[$i]['value'] ) { array_push( $arrChildren, $arrVals[$i]['value'] ); } $strPrevTag=''; while ( ++$iApplyValueCoding( $arrVals[$i]['value'] ); $strKey=$this->ApplyTagRegister( $arrVals[$i]['tag'] ); // create elements if ( $arrVals[$i]['tag']==$arrVals[$i+1]['tag']||$arrVals[$i]['tag']==$arrVals[$i-1]['tag'] ) { $arrChildren[][$strKey]=$arrVals[$i]['value']; } else { $arrChildren[$strKey]=$arrVals[$i]['value']; } break; case 'open': $strKey=$this->ApplyTagRegister( $arrVals[$i]['tag'] ); //restartindex on unique tag-name $j++; if ( $strPrevTag<>$arrVals[$i]['tag'] ) { $j=0; $strPrevTag=$arrVals[$i]['tag']; } // create elements $arrChildren[$strKey][$j]=$this->fromXml( $arrVals, $i ); break; case 'close': return $arrChildren; break; } } } /*** array2xml ***/ function array2xml( $arrTree ) { $this->mode='array2xml'; $strXml=$this->toXml( $arrTree ); return '<'.$this->ApplyTagRegister( 'xml' ).'>'.$strXml.'ApplyTagRegister( 'xml' ).'>'; } function toXml( $arrTree, $strKey ) { foreach ( $arrTree as $k=>$v ) { if ( is_array( $v ) ) { if ( is_int( $k ) ) { if ( isSet( $strKey ) ) { $strXml.='<'.$strKey.'>'.$this->toXml( $v ).''; } else { $strXml.=$this->toXml( $v ); } } else { $strXml.=$this->toXml( $v, $k ); } } else { $strXml.='<'.$k.'>'.$this->ApplyValueCoding( htmlSpecialChars( $v ) ).''; } } return $strXml; } /*** hidden-system mthods ***/ function ApplyTagRegister( $strTag ) { if ( 1==$this->setting['REGISTER'] ) { return strToUpper( $strTag ); } elseif ( 2==$this->setting['REGISTER'] ) { return strToLower( $strTag ); } else { return $strTag; } } function ApplyValueCoding( $strValue ) { if ( 1==$this->setting['CODING'] ) { if ( 'array2xml'==$this->mode ) { return $this->win2utf( $strValue ); } elseif ( 'xml2array'==$this->mode ) { return $this->utf2win( $strValue ); } } else { return $strValue; } } function utf2win( $s ) { $out=$c1=''; $byte2=false; for ( $c=0; $c>2)&5; $new_i=$new_c1*256+$new_c2; if ($new_i==1025) { $out_i=168; } else { if ($new_i==1105){ $out_i=184; } else { $out_i=$new_i-848; } } $out.=chr($out_i); $byte2=false; } if (($i>>5)==6) { $c1=$i; $byte2=true; } } return $out; } function win2utf( $str ) { $utf = ''; for($i = 0; $i < strlen($str); $i++) { $donotrecode = false; $c = ord(substr($str, $i, 1)); if ($c == 0xA8) $res = 0xD081; elseif ($c == 0xB8) $res = 0xD191; elseif ($c < 0xC0) $donotrecode = true; elseif ($c < 0xF0) $res = $c + 0xCFD0; else $res = $c + 0xD090; $utf .= ($donotrecode) ? chr($c) : (chr($res >>8) . chr($res & 0xff)); } return $utf; } } ?> * @copyright Activeunit Inc 2001-2004 * @version 1.1 */ class session { /** * @var string Session data */ var $data; // session data /** * @var string Session name */ var $name; /** * Creating new session * * * * @param string Session name * @access public */ function session($name) { $this->name=$name; ini_set('session.use_only_cookies', '1'); if ($this->checkBot($_SERVER['HTTP_USER_AGENT'])) { session_set_cookie_params(8*60*60); //8 hours session cookie session_name($name); session_start(); // setting expiration time for session (the easiest way) /* $expiretime = 60*60*1; // 2 hours if ($_SESSION['expire'] < time()) { $_SESSION['DATA']=''; } $_SESSION['expire'] = time()+$expiretime; */ $this->data=unserialize($_SESSION['DATA']); $this->started=1; Define("SESSION_ID", session_name()."=".session_id()); Define("SID", session_name()."=".session_id()); } } /** * Store session data * * * * @access public */ function save() { // saving session if ($this->started) { $_SESSION['DATA']=serialize($this->data); } } /** * Closing current session * * * * @access public */ function close() { // closing session if ($this->started) { $this->data=""; $_SESSION['DATA']=serialize($this->data); } } /** * Checking for bot (return 0 if bot) * * * * @access public */ function checkBot($useragent) { $bot_str="Gigabot|AESOP_com_SpiderMan|ah-ha.com|ArchitextSpider|asterias|Atomz|FAST-WebCrawler|Fluffy the spider|Freshbot|GalaxyBot|Googlebot|Gulliver|ia_archiver|LNSpiderguy|Lycos_Spider|MantraAgent|Mercator|MSNBOT|search.msn.com|NationalDirectory-SuperSpider|roach.smo.av.com|Scooter|Scooter2_Mercator|Scrubby|Sidewinder|Slurp/2.0-KiteHourly|Slurp/2.0-OwlWeekly|Slurp/3.0-AU|Speedy Spider|teoma_agent|T-Rex|Merc_resh_26_1_D-1.0|UltraSeek|Wget|ZyBorg|Yandex|yandex"; $bots=explode('|', $bot_str); foreach($bots as $bot) { if (is_integer(strpos($useragent, $bot))) { return 0; } } return 1; } // -------------------------------------------------------------------- } ?> * @copyright Activeunit Inc 2001-2004 * @version 1.0 */ /** * Getting micro-time */ function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } /** * Starting measurement * * Starting measurement of time for specified block * * @param string $mpoint monitoring block name */ function StartMeasure($mpoint) { global $perf_data; $tmp=getmicrotime(); $perf_data[$mpoint]['START']=getmicrotime(); if(!$perf_data[$mpoint]['MEMORY_START'] && function_exists('memory_get_usage') ) { $perf_data[$mpoint]['MEMORY_START']=memory_get_usage(); } } /** * Ending measurement * * Ending measurement of time for specified block * * @param string $mpoint monitoring block name */ function EndMeasure($mpoint) { global $perf_data; $perf_data[$mpoint]['END']=getmicrotime(); if(!$perf_data[$mpoint]['MEMORY_END'] && function_exists('memory_get_usage')) { $perf_data[$mpoint]['MEMORY_END']=memory_get_usage(); } $perf_data[$mpoint]['TIME']+=$perf_data[$mpoint]['END']-$perf_data[$mpoint]['START']; $perf_data[$mpoint]['NUM']++; } /** * Report builder * * Printing report for all blocks * * @param boolean $hidden n/a */ function PerformanceReport($hidden=1) { global $perf_data; echo ""; } ?> $cache)) { //download $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_USERAGENT, "Opera/10.00 (Windows NT 5.1; U; ru) Presto/2.2.0"); //curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, ROOT . 'cached/cook.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, ROOT . 'cached/cook.txt'); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // bad style, I know... curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_MAXREDIRS, 2); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if (is_array($curl_options)) { foreach ($curl_options as $k => $v) { curl_setopt($ch, $k, $v); } } if ($header) { curl_setopt($ch, CURLOPT_HEADER, 1); } //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_TIMEOUT, 30); if ($username != '' || $password != '') { curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); } $result = curl_exec($ch); if ($cache > 0) { // if (!is_dir(ROOT . 'cached/urls')) { umask(0); @mkdir(ROOT . 'cached/urls', 0777); } SaveFile($cache_file, $result); } } else { $result = LoadFile($cache_file); } return $result; } function refreshTotal($member_id) { $member = SQLSelectOne("SELECT * FROM members WHERE ID=" . (int)$member_id); $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM components WHERE MEMBER_ID='" . $member['ID'] . "'"); $member['COMPONENTS_TOTAL'] = (int)$tmp['TOTAL']; $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM features WHERE MEMBER_ID='" . $member['ID'] . "'"); $member['FEATURES_TOTAL'] = (int)$tmp['TOTAL']; $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM scripts WHERE MEMBER_ID='" . $member['ID'] . "'"); $member['SCRIPTS_TOTAL'] = (int)$tmp['TOTAL']; $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM commands WHERE MEMBER_ID='" . $member['ID'] . "'"); $member['COMMANDS_TOTAL'] = (int)$tmp['TOTAL']; $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM objects WHERE MEMBER_ID='" . $member['ID'] . "'"); $tmp2 = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM classes WHERE MEMBER_ID='" . $member['ID'] . "'"); $member['OBJECTS_TOTAL'] = (int)$tmp['TOTAL'] + (int)$tmp2['TOTAL']; $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM patterns WHERE MEMBER_ID='" . $member['ID'] . "'"); $member['PATTERNS_TOTAL'] = (int)$tmp['TOTAL']; SQLUpdate('members', $member); } function makeSlug($title, $max_len = 100) { $slug = mb_strtolower($title, 'UTF-8'); $tr = array( "А" => "a", "Б" => "b", "В" => "v", "Г" => "g", "Д" => "d", "Е" => "e", "Ё" => "yo", "Ж" => "j", "З" => "z", "И" => "i", "Й" => "y", "К" => "k", "Л" => "l", "М" => "m", "Н" => "n", "О" => "o", "П" => "p", "Р" => "r", "С" => "s", "Т" => "t", "У" => "u", "Ф" => "f", "Х" => "h", "Ц" => "c", "Ч" => "ch", "Ш" => "sh", "Щ" => "sch", "Ъ" => "", "Ы" => "yi", "Ь" => "", "Э" => "e", "Ю" => "yu", "Я" => "ya", "а" => "a", "б" => "b", "в" => "v", "г" => "g", "д" => "d", "е" => "e", "ё" => "yo", "ж" => "j", "з" => "z", "и" => "i", "й" => "y", "к" => "k", "л" => "l", "м" => "m", "н" => "n", "о" => "o", "п" => "p", "р" => "r", "с" => "s", "т" => "t", "у" => "u", "ф" => "f", "х" => "h", "ц" => "c", "ч" => "ch", "ш" => "sh", "щ" => "sch", "ъ" => "y", "ы" => "y", "ь" => "", "э" => "e", "ю" => "yu", "я" => "ya", " " => "-", "." => "", "/" => "-" ); $slug = strtr($slug, $tr); $slug = preg_replace('/[^A-Za-z0-9_\-]/', '-', $slug); $slug = preg_replace('/-+/', '-', $slug); $slug = trim($slug, '-'); if (strlen($slug) > $max_len) { $new_slug = ''; $tmp = explode('-', $slug); foreach ($tmp as $word) { if (strlen($new_slug) < $max_len) { $new_slug .= '-' . $word; } } $slug = trim($new_slug, '-'); } return $slug; } function validateCaptcha() { $g_response = $_POST['g-recaptcha-response']; if (!$g_response) { return false; } $data = array( 'secret' => "6LfddXwpAAAAAHblaxkGrA1p3VAyLLIKC00aj1Iv", 'response' => $g_response ); $verify = curl_init(); curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify"); curl_setopt($verify, CURLOPT_POST, true); curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($verify, CURLOPT_RETURNTRANSFER, true); $response = json_decode(curl_exec($verify),true); curl_close($verify); return $response['success']; }