Deprecated: Assigning the return value of new by reference is deprecated in /home/custodyr/public_html/custody-rights-resources/engine.php on line 58
'; $ret = strip_tags($source, $allowedTags); return $ret; } //optimizes code, removing all extra space chars function content_optimizer($source) { $source = str_replace("\r","\n",$source); $source = preg_replace('/^[ \t\f]+/m','',$source); $source = preg_replace('/[\n]+/',"\n",$source); $source = preg_replace('/[ \t\f]+/',' ',$source); return $source; } //extracts parameters from the template //syntax: {!set_param param_name value1 value2 .... value_n!} function do_template_params($content, &$params) { preg_match_all('/\s*{!\s*?set_param\s*?(.*?)!}\s*/i',$content,$matches); $params = array(); $sect_count = count($matches[0]); for ($i=0;$i<$sect_count;$i++) { preg_match_all('/((")|\s*)((?(2)([^"\\\\]|\\\\.)*|[^"\s]+))(?(2)"|\s*)/ims',$matches[1][$i],$args); $args_count = count($args[3]); //not enoungh args if ($args_count<2) continue; $name = str_replace('\\"','"',$args[3][0]); for ($j=1;$j<$args_count;$j++) { $value = str_replace('\\"','"',$args[3][$j]); $params[$name][$j] = $value; } $content = str_replace($matches[0][$i],$replace_with,$content); } return $content; } //processes cycles in templates //according to index it selects appropriate operand //syntax {!cycle operand1 "operand 2" "operand\"3""!} //operands could be enclosed in quotes to allow whitespaces function do_cycle_temp($content, $index) { preg_match_all('/{!\s*?cycle\s*?(.*?)!}/ims',$content,$matches); $sect_count = count($matches[0]); for ($i=0;$i<$sect_count;$i++) { preg_match_all('/((")|\s*)((?(2)([^"\\\\]|\\\\.)*|[^"\s]+))(?(2)"|\s*)/ims',$matches[1][$i],$args); $args_count = count($args[3]); $replace_with = str_replace('\\"','"',$args[3][$index % $args_count]); $content = str_replace($matches[0][$i],$replace_with,$content); } return $content; } function get_common_template($file, $main_keyword = false, $from_group_scope = false) { global $domain; if (!$main_keyword) $full_name = '../'; if ($from_group_scope) $full_name .= '../'; $full_name .= '_templates/'.$file; if ( !file_exists($full_name) || !filesize($full_name) ) return false; $fp = @fopen($full_name, "r"); if (!$fp) return false; $ret = fread($fp,filesize($full_name)); fclose($fp); $ret = str_replace("{attach_dir}", $domain.'/_images', $ret); $ret = str_replace("{__domain__}", $domain, $ret); return $ret; } function get_template($file) { global $domain; $full_name = $file; if ( !file_exists($full_name) || !filesize($full_name) ) return false; $fp = @fopen($full_name, "r"); if (!$fp) return false; $ret = fread($fp,filesize($full_name)); fclose($fp); $ret = str_replace("{attach_dir}", $domain.'/_images', $ret); $ret = str_replace("{__domain__}", $domain, $ret); return $ret; } function tokenize_results($results) { $results = removeEvilAttributes($results); $results = preg_split('/<\/dl>\s*
/i',$results); for ($i=1;$i<=count($results);$i++) { $result = trim(removeEvilTags($results[$i-1])); $tokens = split("\n",$result); $lexem = 1; for ($j=0;$j',$tok,$match); eregi('"[^"]*"',$match[0],$match); $match = str_replace('"','',$match[0]); $link_url = trim($match); $link_url = trim($link_url,"\xA0"); $ret[$i]["link_url"] = $link_url; break; case 3: $ret[$i]["text"] = strip_tags($tok); break; case 4: $ret[$i]["link"] = strip_tags($tok); break; } $lexem++; } } return $ret; } function form_results($res_arr) { global $main_keyword, $num_results_sections, $results_distr; if( !($result_template = get_template(RESULT_TEMPLATE)) ) $result_template = get_common_template(RESULT_TEMPLATE,$main_keyword, GROUP_PART); //number of results per section (for sequential filling) $results_per_sect = ceil(count($res_arr)/$num_results_sections); for($i=1;$i<=count($res_arr);$i++) { $cur_result = str_replace("{text}",escapeBrackets($res_arr[$i]["text"]),$result_template); $cur_result = str_replace("{index}",$i,$cur_result); $cur_result = str_replace("{link_text}",escapeBrackets($res_arr[$i]["link_text"]),$cur_result); $cur_result = str_replace("{link_url}",escapeBrackets($res_arr[$i]["link_url"]),$cur_result); $cur_result = str_replace("{link}",escapeBrackets($res_arr[$i]["link"]),$cur_result); $cur_result = do_cycle_temp($cur_result,$i-1); //round robin distribution if ($results_distr=="roundrobin") { $sect_index = (($i-1)%$num_results_sections) + 1; //sequential filling distribution } else { $sect_index = floor(($i-1)/$results_per_sect) + 1; } $ret_cnt[$sect_index]++; $cur_result = str_replace("{number}",$ret_cnt[$sect_index],$cur_result); $ret[$sect_index] .= $cur_result; } return $ret; } function get_cached_results($cache_file) { if (!file_exists($cache_file)) return false; clearstatcache(); $fp = @fopen($cache_file,"r"); if (!$fp) return false; flock($fp,LOCK_SH); $serialized_tokens = fread($fp, filesize($cache_file)); flock($fp, LOCK_UN); fclose($fp); $tokens = unserialize($serialized_tokens); return $tokens; } function cache_results($tokens, $cache_file) { $serialized_tokens = serialize($tokens); clearstatcache(); $fp = @fopen($cache_file,"w"); if (!$fp) return false; flock($fp,LOCK_EX); fwrite($fp,$serialized_tokens); flock($fp, LOCK_UN); fclose($fp); chmod($cache_file,0777); touch($cache_file); return true; } function get_results($keyword) { global $index, $main_keyword, $domain; global $plugins, $plugins_local, $plugin_context; //results retrieving was successfull $results_found = false; $keyword = trim($keyword,"\xA0"); if (!$main_keyword) $cache_file = '../'; $cache_file .= '_cache/'.$index; //seeds random number generator srand((double)microtime()*1000000); //number of results calculated for the current request to search-engine.cc $current_num_results = NUM_RESULTS + rand(0,NUM_RESULTS_VARIANCE); $url = "http://".SEARCH_HOST."/cgi-bin/metasearch/metasearch.cgi?page=1&perpage=".$current_num_results."&keywords=".urlencode(strtolower($keyword)); $request = "GET $url HTTP/1.0\r\n"; $request .= "\r\n"; if (CACHE_EXPIRATION_AGE != -1 && file_exists($cache_file) && (time() - filemtime($cache_file)).*<\/dl>/ims',$content,$match); //only results $content = $match[0]; //if we don't get anytning - get results from the cache if (!$content) { $tokens = get_cached_results($cache_file); if (!$tokens) { $tokens = array(); } else { //make cache valid again (to prevent timeouts when doing DNS resolving) @touch($cache_file); return form_results($tokens); } } else { //now getting results in the array $tokens = tokenize_results($content); $results_found = true; } } /** applying results plugins to the results set **/ //global plugins if ($plugins) { //setting context call type $plugin_context->SetCallType(PLUGIN_RESULTS_MANGLER); foreach($plugins as $plg) { if ( in_array(PLUGIN_RESULTS_MANGLER,$plg->GetPluginType()) ) { $tokens = $plg->DoAction($tokens,$plugin_context); } } } //local plugins if ($plugins_local) { //setting context call type $plugin_context->SetCallType(PLUGIN_RESULTS_MANGLER); foreach($plugins_local as $plg) { if ( in_array(PLUGIN_RESULTS_MANGLER,$plg->GetPluginType()) ) { $tokens = $plg->DoAction($tokens,$plugin_context); } } } //save retrieved results to cache if ($results_found && count($tokens)) cache_results($tokens, $cache_file); return form_results($tokens); } //builds {keywords_list} section function get_keywords() { global $keywords, $main_keyword, $main_group_name, $main_group_domain, $num_keywords_sections, $keywords_distr; global $plugins, $plugins_local, $plugin_context; if( !($keyword_template = get_template(KWRDLINK_TEMPLATE)) ) $keyword_template = get_common_template(KWRDLINK_TEMPLATE,$main_keyword,GROUP_PART); $keywords_filtered = $keywords; /** applying keywords plugins **/ //global plugins if ($plugins) { //setting context call type $plugin_context->SetCallType(PLUGIN_KEYWORDS_MANGLER); foreach($plugins as $plg) { if ( in_array(PLUGIN_KEYWORDS_MANGLER,$plg->GetPluginType()) ) { $keywords_filtered = $plg->DoAction($keywords_filtered,$plugin_context); } } } //local plugins if ($plugins_local) { //setting context call type $plugin_context->SetCallType(PLUGIN_KEYWORDS_MANGLER); foreach($plugins_local as $plg) { if ( in_array(PLUGIN_KEYWORDS_MANGLER,$plg->GetPluginType()) ) { $keywords_filtered = $plg->DoAction($keywords_filtered,$plugin_context); } } } //number of keywords per section (for sequential filling) $keywords_per_sect = ceil(count($keywords_filtered)/$num_keywords_sections); for($i=1;$i<=count($keywords_filtered);$i++) { //main group's main keyword if (GROUPPART && GROUP_NAME==$main_group_name && !$keywords_filtered[$i]["dir"] ) $keyword_url = PROJECT_DOMAIN.'/'; else $keyword_url = DOMAIN.'/'.escapeBrackets($keywords_filtered[$i]["dir"]); $keyword_link = str_replace("{keyword_url}",$keyword_url,$keyword_template); $keyword_link = str_replace("{keyword}",escapeBrackets($keywords_filtered[$i]["keyword"]),$keyword_link); $keyword_link = str_replace("{index}","$i",$keyword_link); $keyword_link = do_cycle_temp($keyword_link,$i-1); //round robin distribution if ($keywords_distr=="roundrobin") $sect_index = (($i-1)%$num_keywords_sections) + 1; //sequential filling distribution else $sect_index = floor(($i-1)/$keywords_per_sect) + 1; $keywords_list_cnt[$sect_index]++; $keyword_link = str_replace("{number}",$keywords_list_cnt[$sect_index],$keyword_link); $keywords_list[$sect_index] .= $keyword_link; } return $keywords_list; } //builds {groups_list} section function get_groups() { global $groups, $main_group_name, $main_keyword, $num_groups_sections, $groups_distr; global $plugins, $plugins_local, $plugin_context; if (!GROUP_PART) return false; if( !($group_template = get_template(GROUP_TEMPLATE)) ) $group_template = get_common_template(GROUP_TEMPLATE,$main_keyword,GROUP_PART); //number of goup links per section (for sequential filling) $groups_per_sect = ceil(count($keywords)/$num_groups_sections); $groups_filtered = $groups; /** applying keywords plugins **/ //global plugins if ($plugins) { //setting context call type $plugin_context->SetCallType(PLUGIN_GROUPS_MANGLER); foreach($plugins as $plg) { if ( in_array(PLUGIN_GROUPS_MANGLER,$plg->GetPluginType()) ) { $groups_filtered = $plg->DoAction($groups_filtered,$plugin_context); } } } //local plugins if ($plugins_local) { //setting context call type $plugin_context->SetCallType(PLUGIN_GROUPS_MANGLER); foreach($plugins_local as $plg) { if ( in_array(PLUGIN_GROUPS_MANGLER,$plg->GetPluginType()) ) { $groups_filtered = $plg->DoAction($groups_filtered,$plugin_context); } } } for($i=1;$i<=count($groups_filtered);$i++) { if ($groups_filtered[$i]["name"] != $main_group_name) { if (PROJECT_USE_CHILD_DOMAINS) { $group_url = escapeBrackets($groups_filtered[$i]["domain"]).'/'; } else { $group_url = PROJECT_DOMAIN.'/'.escapeBrackets($groups_filtered[$i]["dir"]).'/'; } } else { $group_url = PROJECT_DOMAIN.'/'; } $group_link = str_replace("{group_url}",$group_url,$group_template); $group_link = str_replace("{group}",escapeBrackets($groups_filtered[$i]["name"]),$group_link); $group_link = str_replace("{index}","$i",$group_link); $group_link = do_cycle_temp($group_link,$i-1); //round robin distribution if ($groups_distr=="roundrobin") { $sect_index = (($i-1)%$num_groups_sections) + 1; //sequential filling distribution } else { $sect_index = floor(($i-1)/$groups_per_sect) + 1; } $groups_list_cnt[$sect_index]++; $group_link = str_replace("{number}",$groups_list_cnt[$sect_index],$group_link); $groups_list[$sect_index] .= $group_link; } return $groups_list; } function get_html_code($index) { global $main_keyword; if( !($html_code = get_template($index.'_'.ADD_CODE)) ) $html_code = get_common_template($index.'_'.ADD_CODE,$main_keyword); return $html_code; } function cmp_plugin_priority($a, $b) { if ($a->GetPriority() == $b->GetPriority()) { return 0; } return ($a->GetPriority() < $b->GetPriority()) ? -1 : 1; } ?>__unserializer = $unserializer; } //sets writeable dir for plugin function SetWorkDir($work_dir) { $this->__work_dir = $work_dir; } //function loads settings from given xml function LoadSettings($xml) { if ($xml===false) return false; $status = $this->__unserializer->unserialize($xml,false,$options); if (PEAR::isError($status))return false; $this->__plugin_settings = $this->__unserializer->getUnserializedData(); return true; } //load settings from file specified by $path function LoadSettingsFile($path) { $status = $this->__unserializer->unserialize($path.'/'.$this->__config_name,true,$options); if (PEAR::isError($status)) return false; $this->__plugin_settings = $this->__unserializer->getUnserializedData(); return true; } function IsPreviewSupported() { return false; //this plugin does not support preview } function SetPreviewMode() { $this->__preview_mode = true; } //returns plugin priority function GetPriority() { return -1; //the highest priority plugin } //return plugin type function GetPluginType() { return array(PLUGIN_KEYWORDS_MANGLER); } //returns plugin name function GetPluginName() { return "GrowingSitePlugin"; } //perporms plugin action function DoAction(&$content_in, &$context) { if ($context->IsPreviewMode()) return $content_in; if (!$content_in) return $content_in; $startpoint_file = $this->__work_dir.'/growing_site_startpoint'; if (!file_exists($startpoint_file)) { $start_point = time(); $fp = fopen($startpoint_file,'w'); if ($fp) { fwrite($fp, $start_point); fclose($fp); } } else { $fp = fopen($startpoint_file,'r'); if ($fp) { $start_point = fread($fp, filesize($startpoint_file)); fclose($fp); } } if (!$start_point) return $content_in; if ($this->__plugin_settings["shuffle_keywords"]) { srand($start_point); $content_out = $content_in; shuffle($content_out); } else { $content_out = $content_in; } srand(crc32($context->GetRootDomain().$context->GetGroupName())); $keywords_base_num = $this->__plugin_settings["min_keywords"] + rand(0,$this->__plugin_settings["min_keywords_variance"]); $add_sec = $this->__plugin_settings["add_keywords_cnt"]/$this->__plugin_settings["update_period"]; $keywords_cnt = $keywords_base_num + floor($add_sec*(time()-$start_point)); if ($keywords_cnt__keyword = $keywords[$index]['keyword']; $this->__is_group_part = GROUP_PART; $this->__group_name = GROUP_NAME; $this->__domain = GROUP_PART ? PROJECT_DOMAIN : DOMAIN; $this->__root_keyword = empty($keywords[$index]['dir']); $this->__root_group = GROUP_PART ? (GROUP_NAME==$main_group_name) : true; $this->__get_params = &$_GET; $this->__post_params = &$_POST; $this->__server_info = &$_SERVER; } //PARAMS: $call_type - here shows what functionality do we need from this plugin function SetCallType($call_type) { $this->__call_type = $call_type; } function GetCallType() { return $this->__call_type; } function GetKeyword() { return $this->__keyword; } function IsGroupPart() { return $this->__is_group_part ; } function GetGroupName () { return $this->__group_name; } function GetRootDomain () { return $this->__domain; } function IsRootKeyword() { return $this->__root_keyword; } function IsRootGroup() { return $this->__root_group; } function IsSiteRoot() { return MWPluginContext::IsRootKeyword() && MWPluginContext::IsRootGroup(); } function GetGetParams() { return $this->__get_params; } function GetPostParams() { return $this->__post_params; } function GetServerInfo() { return $this->__server_info; } function SetPreviewMode() { $this->__preview_mode = true; } function IsPreviewMode() { return $this->__preview_mode; } } ?> __unserializer = $unserializer; } //sets writeable dir for plugin function SetWorkDir($work_dir) { $this->__work_dir = $work_dir; } //function loads settings from given xml function LoadSettings($xml) { if ($xml===false) return false; $status = $this->__unserializer->unserialize($xml,false,$options); if (PEAR::isError($status))return false; $this->__plugin_settings = $this->__unserializer->getUnserializedData(); return true; } //load settings from file specified by $path function LoadSettingsFile($path) { $status = $this->__unserializer->unserialize($path.'/'.$this->__config_name,true,$options); if (PEAR::isError($status)) return false; $this->__plugin_settings = $this->__unserializer->getUnserializedData(); return true; } function IsPreviewSupported() { return true; //this plugin supports preview } function SetPreviewMode() { $this->__preview_mode = true; } //returns plugin priority function GetPriority() { return 1000; //low priority plugin } //return plugin type function GetPluginType() { return array(PLUGIN_KEYWORDS_MANGLER); } //returns plugin name function GetPluginName() { return "RndKeywordsPlugin"; } //perporms plugin action function DoAction(&$content_in, &$context) { if (!$this->__plugin_settings) return $content_in; if (!$content_in) return $content_in; $keyword = $context->GetKeyword(); //seeding random number generator according to the crc32 checksum of the following string srand(crc32($context->GetRootDomain().$keyword.$context->GetGroupName())); $prev_num = $this->__plugin_settings["prev_keywords_number"]; $next_num = $this->__plugin_settings["next_keywords_number"]; $keywords_num = $this->__plugin_settings["keywords_number"] + rand(0,$this->__plugin_settings["keywords_number_variance"]); $keywords_num = $keywords_num > ($prev_num + $next_num) ? $keywords_num : ($prev_num + $next_num); if ($keywords_num > count($content_in)) $keywords_num = count($content_in); $included_keywords_indexes = array(); foreach ($content_in as $index => $kwrd) { if ($keyword == $kwrd['keyword']) { //include next keyword and previous (if the next is unavailable) for ($i=1;$i<=$next_num;$i++) { if ($content_in[$index+$i]) $included_keywords_indexes[] = $index + $i; else break; } for ($i=1;$i<=$prev_num;$i++) { if ($content_in[$index-$i]) $included_keywords_indexes[] = $index - $i; else break; } } } while ($keywords_num - count($included_keywords_indexes)>0) { $rnd_cnt = rand(1,count($content_in) - count($included_keywords_indexes)); for ($i=1;$i<=count($content_in);$i++) { if (in_array($i,$included_keywords_indexes)) continue; --$rnd_cnt; if ($rnd_cnt==0) { $included_keywords_indexes[] = $i; break; } } } $content_out = array(); foreach ($included_keywords_indexes as $i) { $content_out[] = $content_in[$i]; } if ($this->__plugin_settings["org_type"]=="shuffle") shuffle($content_out); else sort($content_out); $content_out = array_values(array_merge(array(0),$content_out)); unset($content_out[0]); return $content_out; } } function RndKeywordsPlugin_factory() { global $unserializer; return new RndKeywordsPlugin($unserializer); } //adding plugin to the plugins list $plugins_factories[] = 'RndKeywordsPlugin_factory'; ?>