values tried to make it smart, fast */ function giggle_autolink($string,$arr_keywords=-1,$b_noprint=0) { if($arr_keywords == -1 ) { $config = new Config(phpgiggle_wordsfile); if(is_array($config->param)) { $arr_keywords = $config->param; } else { return $string; } } // allow single keyword if(!is_array($arr_keywords)) { $match = preg_split('/ = /', $arr_keywords); unset($arr_keywords); $arr_keywords[$match[0]]=$match[1]; } /* regular expressions */ require(phpGiggle_ABSPATH.'includes/phpgiggle-regexp.inc.php'); // pre-procesor - get rid of unneeded key words // saves time for potentially large lists foreach($arr_keywords as $giggle_word => $giggle_link ) { $temp_word = str_replace("_"," ",$giggle_word); //get rid of evil chars if(preg_match("/".$valid_key_regexp."/i", $temp_word)) { unset($arr_keywords[$giggle_word]); } if(! preg_match("/$l_regexp($temp_word)$r_regexp/i", $string)) { unset($arr_keywords[$giggle_word]); } } if (is_array($arr_keywords)) { // if keyword array still has elements, matches have been found foreach($arr_keywords as $giggle_word => $giggle_link) // for each keyword { if(is_array($giggle_word)) { $temp_word=$giggle_word[0]; unset($giggle_word); $giggle_word=$temp_word; } if(is_array($giggle_link)) { $temp_link=$giggle_link[0]; unset($giggle_link); $giggle_link=$temp_link; } $giggle_word = str_replace("_"," ",$giggle_word); // matches all text between "> <" in HTML foreach(preg_split("/$no_tags_regexp/", $string) as $match) { // no point to continue if $match is empty or cointains garbage if(($match<" ") || (strlen($match) < 2) || (!preg_match("/\w/", $match)) || ( preg_match("/http\:\/\//", $match)) ) { continue; } // avoid some tags preg_match('/('.$no_tags_regexp.')('.preg_quote($match,'/').')('.$no_tags_regexp.')/U',$string, $out); if(preg_match('/^\<'.$avoid_tags_regexp.'/i',$out[1])) { continue; } // opening tags to avoid if(preg_match('/^\<\/'.$avoid_tags_regexp.'/i',$out[3])) { continue; } // closing tags to avoid $match_left = $out[1]; $match_right = $out[3]; if(preg_match("/$l_regexp($giggle_word)$r_regexp/i", $match, $out)) { $case_sensitive_search_word = $out[1]; if (preg_match('/(.*?)\[(.+)\]/', $giggle_link, $matches) ) { $title = "title='$matches[2]'"; $giggle_link = $matches[1]; } else { $title = ""; } switch ($giggle_link) { // phpGiggle template case function_exists("phpgiggle_".$giggle_link): $giggle_function = "phpgiggle_".$giggle_link; $newtext = str_replace($case_sensitive_search_word, $giggle_function($case_sensitive_search_word), $match); break; // highlight case (eregi("$valid_html_color", $giggle_link)?$giggle_link:!$giggle_link): $newtext = str_replace($case_sensitive_search_word,"$case_sensitive_search_word", $match); break; // just link case (eregi("$valid_url_regexp", $giggle_link)?$giggle_link:!$giggle_link): $newtext = str_replace($case_sensitive_search_word,"".$case_sensitive_search_word."", $match); break; // Acronym or just alt-text default: $newtext = str_replace($case_sensitive_search_word,''.$case_sensitive_search_word.'', $match); } $string = str_replace($match_left.$match.$match_right, $match_left.$newtext.$match_right, $string); // replace $match with $newtext in $string } // if keyword found } // for each HTML match } // for each keyword } // if config has elements unset($arr_keywords); if($b_noprint) { return $string; } else { echo $string; } } function giggle_pivot ($text) { return giggle_autolink($text,-1,1); } function giggle_smarty ($text, &$smarty) { return giggle_autolink($text,-1,1); } function giggle_wordpress ($text) { return giggle_autolink($text,-1,1); } ?>