Changeset 128209
- Timestamp:
- 06/21/2009 06:57:37 PM (17 years ago)
- Location:
- target-visitors
- Files:
-
- 8 added
- 4 edited
- 1 copied
-
tags/1.2.5 (copied) (copied from target-visitors/trunk)
-
tags/1.2.5/lang (added)
-
tags/1.2.5/lang/target-visitors.pot (added)
-
tags/1.2.5/lang/target_visitors-ru_RU.mo (added)
-
tags/1.2.5/lang/target_visitors-ru_RU.po (added)
-
tags/1.2.5/readme.txt (modified) (2 diffs)
-
tags/1.2.5/wp-target-visitors.php (modified) (3 diffs)
-
trunk/lang (added)
-
trunk/lang/target-visitors.pot (added)
-
trunk/lang/target_visitors-ru_RU.mo (added)
-
trunk/lang/target_visitors-ru_RU.po (added)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/wp-target-visitors.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
target-visitors/tags/1.2.5/readme.txt
r128160 r128209 5 5 Requires at least: 2.3.2 6 6 Tested up to: 2.8 7 Version: 1.2. 47 Version: 1.2.5 8 8 Last Updated: 2009-06-21 9 Stable tag: 1.2. 49 Stable tag: 1.2.5 10 10 11 11 Plugin shows a special message for users coming from search engines like Google, Yandex, MSN, Yahoo, etc. … … 64 64 == Changelog == 65 65 66 = 1.2. 4=66 = 1.2.5 = 67 67 * Fixed russian lang. 68 68 -
target-visitors/tags/1.2.5/wp-target-visitors.php
r128160 r128209 5 5 Description: Plugin shows a special message for visitors coming from search engines: Google, Yandex, Mail, Yahoo, Liveinternet, Rambler, Altavista, Msn. 6 6 Author: Abanova Olga 7 Version: 1.2. 47 Version: 1.2.5 8 8 Author URI: http://www.getincss.ru 9 9 */ 10 10 11 11 include_once ('functions.php'); 12 13 12 if ( ! defined( 'WP_CONTENT_URL' ) ) 14 13 define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' ); 14 15 15 if ( ! defined( 'WP_CONTENT_DIR' ) ) 16 16 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); 17 17 18 if ( ! defined( 'WP_PLUGIN_URL' ) ) 18 19 define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' ); 19 20 if ( ! defined( 'WP_PLUGIN_DIR' ) ) 21 20 22 define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); 21 22 23 23 24 // Adding stylesheet in head … … 25 26 echo "<link rel=\"stylesheet\" href=\"".WP_PLUGIN_URL."/target-visitors/target-visitors.css\" type=\"text/css\" media=\"screen\" />\n"; 26 27 } 27 28 28 function autosetfunc($content) { 29 29 if(is_single()): … … 33 33 return $content; 34 34 } 35 36 37 35 //init on activate plugin 38 36 if (!function_exists('target_visitors_set')) { 39 function target_visitors_set() { 40 $text_code = "<div class=\"se_request\">".__("You were come by request").": <a href=\"[PERMALINK]\"><b>[SE_REQUEST]</b></a>.<br />".__("Find interesting information? You can easy follow my blog through")." <a href=\"[RSS_URL]\"><b>RSS</b></a>.</div>"; 37 function target_visitors_set() { 38 $currentLocale = get_locale(); 39 if(!empty($currentLocale) && $currentLocale="ru_RU") { 40 $moFile = "target-visitors/lang"; 41 load_plugin_textdomain('target_visitors',false,$moFile); 42 } 43 44 $text_code = "<div class=\"se_request\">".__("You were come by request","target_visitors").": <a href=\"[PERMALINK]\"><b>[SE_REQUEST]</b></a>.<br />".__("Find interesting information? You can easy follow my blog through","target_visitors")." <a href=\"[RSS_URL]\"><b>RSS</b></a>.</div>"; 45 41 46 $autoset = '0'; 42 47 if(@$_POST['target_visitors_update']): 48 43 49 update_option("text_code", $_POST['text_code']); 50 44 51 update_option("autoset", $_POST['autoset']); 45 52 else: 46 53 if(!get_option("text_code") or !get_option("autoset")) 54 47 55 add_option("text_code", $text_code); 56 48 57 add_option("autoset", $autoset); 49 endif; 50 51 $currentLocale = get_locale(); 52 53 if(!empty($currentLocale) && $currentLocale="ru_RU") { 54 $currentLocale="RU"; 55 56 $moFile = dirname(__FILE__) . "/lang/target-visitors_" . $currentLocale . ".mo"; 57 58 if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('target-visitors', $moFile); 59 60 } 58 59 endif; 61 60 62 61 add_action('wp_head','target_visitors_head'); 63 62 } 64 } 63 64 } 65 65 66 66 67 //adding options in admin menu 68 67 69 function target_visitors_add_pages() { 68 add_options_page(__('Target Visitors options'), 'Target Visitors', 8, __FILE__, 'target_visitors_options_page'); 69 } 70 71 add_options_page(__('Target Visitors options',"target_visitors"), 'Target Visitors', 8, __FILE__, 'target_visitors_options_page'); 72 73 } 74 75 70 76 71 77 //plugin options 78 72 79 function target_visitors_options_page() { 80 73 81 if (@$_POST['target_visitors_update']) { 82 83 84 74 85 if (empty($_POST['text_code']) or empty($_POST['css_code'])) { 86 75 87 if (empty($_POST['text_code'])) { 88 76 89 $text_code = ""; 90 77 91 update_option('text_code', $text_code); 78 $msg_status = __("HTML code removed"); 92 93 $msg_status = __("HTML code removed","target_visitors"); 94 79 95 } 96 80 97 98 81 99 if (empty($_POST['css_code'])){ 100 82 101 $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css"; 102 83 103 if (is_writable($filename)) { 104 84 105 $css_open_file = fopen($filename, "w"); 106 85 107 if (fwrite($css_open_file, $css_code) === FALSE) { 86 $msg_status = __("Error writing css file."); 108 109 $msg_status = __("Error writing css file.","target_visitors"); 110 87 111 exit; 112 88 113 } 114 89 115 fclose($css_open_file); 116 90 117 //remove_action('wp_head','target_visitors_head'); 91 $msg_status.=__("CSS code removed"); 118 119 $msg_status.=__("CSS code removed","target_visitors"); 120 92 121 } else { 93 $msg_status = __("CSS file is not allowed for writing"); 122 123 124 125 $msg_status = __("CSS file is not allowed for writing","target_visitors"); 126 127 128 129 130 131 94 132 exit; 133 95 134 } 135 96 136 ?> 137 97 138 <div id="message" class="updated fade"><p><?=$msg_status?></p></div> 139 98 140 <? 141 99 142 } 143 100 144 } else { 145 101 146 $text_code = stripcslashes($_POST['text_code']); 102 update_option('text_code', $text_code); 147 148 update_option('text_code', $text_code); 149 103 150 $msg_status = "Text saved. "; 151 104 152 $css_code = stripcslashes($_POST['css_code']); 153 105 154 $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css"; 155 106 156 if (is_writable($filename)) { 157 107 158 $css_open_file = fopen($filename, "w"); 159 108 160 if (fwrite($css_open_file, $css_code) === FALSE) { 109 $msg_status.=__("Error writing css file."); 161 162 $msg_status.=__("Error writing css file.","target_visitors"); 163 110 164 exit; 165 111 166 } 167 112 168 fclose($css_open_file); 113 $msg_status.=__("CSS code saved"); 169 170 $msg_status.=__("CSS code saved","target_visitors"); 171 114 172 } else { 115 $msg_status.=__("CSS file is not allowed for writing."); 173 174 $msg_status.=__("CSS file is not allowed for writing.","target_visitors"); 175 116 176 } 177 117 178 } 179 118 180 181 119 182 if ($_POST['autoset']) { 183 120 184 update_option('autoset', $_POST['autoset']); 121 $msg_status.=__("Plugin will autoset to single.php"); 185 186 $msg_status.=__("Plugin will autoset to single.php","target_visitors"); 187 122 188 add_filter('the_content', 'autosetfunc'); 189 123 190 } else { 124 $msg_status.=__("Plugin will not autoset to single.php"); 191 192 $msg_status.=__("Plugin will not autoset to single.php","target_visitors"); 193 125 194 } 195 126 196 197 127 198 ?><div id="message" class="updated fade"><p><?=$msg_status?></p></div><? 199 128 200 } 201 129 202 203 130 204 else { 205 131 206 // Fetch code from options 207 132 208 $text_code = get_option('text_code'); 209 133 210 $text_code= stripcslashes($text_code); 211 134 212 $autoset=get_option('autoset'); 213 135 214 $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css"; 215 136 216 if (is_readable($filename)) { 217 137 218 $css_open_file = fopen($filename, "r"); 219 138 220 $css_code = fread($css_open_file, filesize($filename)); 221 139 222 fclose($css_open_file); 223 140 224 } else { 141 $msg_status.=__("Css file is not readable."); 225 226 $msg_status.=__("Css file is not readable.","target_visitors"); 227 142 228 ?><div id="message" class="updated fade"><p><?=$msg_status?></p></div> <? 229 143 230 } 231 144 232 } 233 145 234 ?> 235 146 236 <div class="wrap"> 237 147 238 <h2>Target visitors</h2> 239 148 240 <div style="float:right; width:250px; border:solid 1px #ccc; padding:10px;"> 149 <h3 style="font-size:16px; background:#eee"><? _e("Support");?></h3> 150 <p><? _e("If you have any ideas or questions about this plugin, write a comment at plugin homepage <a href=\"http://www.getincss.ru/wp-target-visitors_en/\">Target Visitors</a>.<br /><br />You can also e-mail me: webmaster(dog)getincss.ru<br /><br /><b>Do you like this plugin?</b><br />I'll glad for your donations. Webmoney:<br />Z102896061935<br />R144897054561"); ?></p> 241 242 <h3 style="font-size:16px; background:#eee"><? _e("Support","target_visitors");?></h3> 243 244 <p><? _e("If you have any ideas or questions about this plugin, write a comment at plugin homepage <a href=\"http://www.getincss.ru/wp-target-visitors_en/\">Target Visitors</a>.<br /><br />You can also e-mail me: webmaster(dog)getincss.ru<br /><br /><b>Do you like this plugin?</b><br />I'll glad for your donations. Webmoney:<br />Z102896061935<br />R144897054561","target_visitors"); ?></p> 245 151 246 </div> 247 152 248 <div style="margin-right:300px;"> 153 <p><? _e("Plugin \"Target Visitors\" allow to show special message for visitors coming from search engines: Google, Yandex, Mail, Yahoo, Liveinternet, Rambler, Altavista, Msn. You can use this tags in text:<br /><br><b>[PERMALINK]</b> - current page's URL<br><br><b style=\"color:red\">[SE_REQUEST]</b> - search engine request that user coming by<br><br><b>[RSS_URL]</b> - URL for your RSS<br><br>After saving data you can to put this code:<br><b><code><? if(function_exists(\"wp_target_visitors\")) wp_target_visitors(); ?></code></b><br> on pages: search.php, archive.php, etc, where you want to show a message for target visitors."); ?> 249 250 <p><? _e("Plugin \"Target Visitors\" allow to show special message for visitors coming from search engines: Google, Yandex, Mail, Yahoo, Liveinternet, Rambler, Altavista, Msn. You can use this tags in text:<br /><br><b>[PERMALINK]</b> - current page's URL<br><br><b style=\"color:red\">[SE_REQUEST]</b> - search engine request that user coming by<br><br><b>[RSS_URL]</b> - URL for your RSS<br><br>After saving data you can to put this code:<br><b><code><? if(function_exists(\"wp_target_visitors\")) wp_target_visitors(); ?></code></b><br> on pages: search.php, archive.php, etc, where you want to show a message for target visitors.","target_visitors"); ?> 251 154 252 </p> 253 155 254 <form name="form_target_visitors" method="post" action="<?=$_SERVER['REQUEST_URI']?>"> 156 <p><? _e("Your Message");?>:<br /><textarea name="text_code" id="text_code" cols="40" rows="10" style="width: 80%; font-size: 14px;" class="code"><?=stripslashes($text_code);?></textarea></p> 157 <p><? _e("CSS code (CSS file in <b>target-visitors</b> directory must be writable)"); ?>:<br /><textarea name="css_code" id="css_code" cols="40" rows="10" style="width: 80%; font-size: 14px;" class="code"><?=stripslashes($css_code);?></textarea></p> 158 <p><input type="checkbox" name="autoset" value="1" <? if (get_option('autoset')=="1") echo "checked";?> /> <? _e("Autoset plugin's display message function on single.php page"); ?></p> 255 256 <p><? _e("Your Message","target_visitors");?>:<br /><textarea name="text_code" id="text_code" cols="40" rows="10" style="width: 80%; font-size: 14px;" class="code"><?=stripslashes($text_code);?></textarea></p> 257 258 <p><? _e("CSS code (CSS file in <b>target-visitors</b> directory must be writable)","target_visitors"); ?>:<br /><textarea name="css_code" id="css_code" cols="40" rows="10" style="width: 80%; font-size: 14px;" class="code"><?=stripslashes($css_code);?></textarea></p> 259 260 <p><input type="checkbox" name="autoset" value="1" <? if (get_option('autoset')=="1") echo "checked";?> /> <? _e("Autoset plugin's display message function on single.php page","target_visitors"); ?></p> 261 159 262 <p class="submit"> 160 <input type="submit" name="target_visitors_update" value="<? _e("Save code »"); ?>" /> 263 264 <input type="submit" name="target_visitors_update" value="<? _e("Save code »","target_visitors"); ?>" /> 265 161 266 </p> 267 162 268 </div> 269 163 270 </div> 271 164 272 <? 165 } 273 274 } 275 276 277 166 278 167 279 168 280 function get_search_query_terms() { 281 169 282 $query_array = array(); 283 170 284 if(@$_GET['s']): 285 171 286 $se=$_GET['s']; 287 172 288 while (ereg('%([0-9A-F]{2})',$se)){ 289 173 290 $val=ereg_replace('.*%([0-9A-F]{2}).*','\1',$se); 291 174 292 $newval=chr(hexdec($val)); 293 175 294 $se=str_replace('%'.$val,$newval,$se); 295 176 296 } 297 177 298 if (strstr($se,"+")) $se = str_replace("+"," ",$se); 299 178 300 $query_array = explode(" ", $se); 301 179 302 else: 303 180 304 $se=getenv("HTTP_REFERER"); 305 181 306 $se_array = array("?q="=>"3","&q="=>"3","text="=>"5","words="=>"6","ask="=>"4","&p="=>"3","?p="=>"3"); 307 182 308 foreach ($se_array as $se_item=>$se_item_num): 309 183 310 if(strstr($se,$se_item)): 311 184 312 while (ereg('%([0-9A-F]{2})',$se)){ 313 185 314 $val=ereg_replace('.*%([0-9A-F]{2}).*','\1',$se); 315 186 316 $newval=chr(hexdec($val)); 317 187 318 $se=str_replace('%'.$val,$newval,$se); 319 188 320 } 321 189 322 $text_pos = strpos($se,$se_item)+$se_item_num; 323 190 324 break; 325 191 326 endif; 327 192 328 endforeach; 329 193 330 if($text_pos): 331 194 332 $text_pos_amp = strpos($se,"&",$text_pos); 333 195 334 if (!$text_pos_amp) $text_pos_amp=strlen($se); 335 196 336 $se=substr($se,$text_pos,($text_pos_amp-$text_pos)); 337 197 338 if (strstr($se,"+")) $se = str_replace("+"," ",$se); 339 198 340 if (!detect_utf($se)) $se = win_utf8($se); 341 199 342 $query_array = explode(" ", $se); 343 200 344 else: 345 201 346 $query_array=false; 347 202 348 endif; 349 203 350 endif; 351 204 352 return $query_array; 205 } 353 354 } 355 356 357 206 358 207 359 208 360 function html_words_highlight($s) 361 209 362 { 363 210 364 $query_array = get_search_query_terms(); 365 211 366 367 212 368 if($query_array!=false): 369 213 370 $new_query_array=array(); 371 214 372 foreach ($query_array as $term): 373 215 374 $term2=utf8_to_unicode($term); 375 216 376 if((strlen($term2)/6)>1): 377 217 378 $new_query_array[]=$term; 379 218 380 endif; 381 219 382 endforeach; 383 220 384 $words=$new_query_array; 385 221 386 387 222 388 $is_match_case = false; 389 223 390 $tpl = '<span class="hightlite">%s</span>'; 391 224 392 #оптимизация для пустых значений 393 225 394 if (! strlen($s) || ! $words) return $s; 226 395 396 397 227 398 #оптимизация "Ту 134" = "Ту 134" 399 228 400 #{{{ 401 229 402 $s2 = utf8_convert_case($s, CASE_LOWER); 403 230 404 foreach ($words as $k => $word) 405 231 406 { 407 232 408 $word = utf8_convert_case(trim($word, "\x20\r\n\t*"), CASE_LOWER); 409 233 410 if ($word == '' || strpos($s2, $word) === false) unset($words[$k]); 411 234 412 } 413 235 414 if (! $words) return $s; 415 236 416 #}}} 237 417 418 419 238 420 #d($words); 421 239 422 #кеширование построения рег. выражения для "подсвечивания" слов в функции при повторных вызовах 423 240 424 static $func_cache = array(); 425 241 426 $cache_id = md5(serialize(array($words, $is_match_case))); 427 242 428 if (! array_key_exists($cache_id, $func_cache)) 429 243 430 { 431 244 432 #буквы в кодировке UTF-8 для разных языков: 433 245 434 static $re_utf8_letter = '#английский алфавит: 435 246 436 [a-zA-Z] 437 247 438 #русский алфавит (A-я): 439 248 440 | \xd0[\x90-\xbf\x81]|\xd1[\x80-\x8f\x91] 441 249 442 #+ татарские буквы из кириллицы: 443 250 444 | \xd2[\x96\x97\xa2\xa3\xae\xaf\xba\xbb]|\xd3[\x98\x99\xa8\xa9] 445 251 446 #+ турецкие буквы из латиницы (татарский латиница): 447 252 448 | \xc3[\x84\xa4\x87\xa7\x91\xb1\x96\xb6\x9c\xbc]|\xc4[\x9e\x9f\xb0\xb1]|\xc5[\x9e\x9f] 449 253 450 '; 451 254 452 #регулярное выражение для атрибутов тагов 453 255 454 #корректно обрабатывает грязный и битый HTML в однобайтовой или UTF-8 кодировке! 455 256 456 static $re_attrs_fast_safe = '(?> (?>[\x20\r\n\t]+|\xc2\xa0)+ #пробельные символы (д.б. обязательно) 457 257 458 (?> 459 258 460 #правильные атрибуты 461 259 462 [^>"\']+ 463 260 464 | (?<=[\=\x20\r\n\t]|\xc2\xa0) "[^"]*" 465 261 466 | (?<=[\=\x20\r\n\t]|\xc2\xa0) \'[^\']*\' 467 262 468 #разбитые атрибуты 469 263 470 | [^>]+ 471 264 472 )* 473 265 474 )?'; 266 475 476 477 267 478 $re_words = array(); 479 268 480 foreach ($words as $word) 481 269 482 { 483 270 484 if ($is_mask = (substr($word, -1) === '*')) $word = rtrim($word, '*'); 271 485 486 487 272 488 $is_digit = ctype_digit($word); 273 489 490 491 274 492 #рег. выражение для поиска слова с учётом регистра или цифр: 493 275 494 $re_word = preg_quote($word, '/'); 276 495 496 497 277 498 #рег. выражение для поиска слова НЕЗАВИСИМО от регистра: 499 278 500 if (! $is_match_case && ! $is_digit) 501 279 502 { 503 280 504 #для латинских букв 505 281 506 if (preg_match('/^[a-zA-Z]+$/', $word)) $re_word = '(?i:' . $re_word . ')'; 507 282 508 #для русских и др. букв 509 283 510 else 511 284 512 { 513 285 514 $re_word_cases = array( 515 286 516 'lowercase' => utf8_convert_case($re_word, CASE_LOWER), #word 517 287 518 'ucfirst' => utf8_ucfirst($re_word), #Word 519 288 520 'uppercase' => utf8_convert_case($re_word, CASE_UPPER), #WORD 521 289 522 ); 523 290 524 $re_word = '(?>' . implode('|', $re_word_cases) . ')'; 525 291 526 } 527 292 528 } 293 529 530 531 294 532 #d($re_word); 533 295 534 if ($is_digit) $append = $is_mask ? '(?>\d*)' : '(?!\d)'; 535 296 536 else $append = $is_mask ? '(?>' . $re_utf8_letter . ')*' : '(?! ' . $re_utf8_letter . ')'; 537 297 538 $re_words[$is_digit ? 'digits' : 'words'][] = $re_word . $append; 539 298 540 }#foreach 541 299 542 #d($re_words); 300 543 544 545 301 546 if (! empty($re_words['words'])) 547 302 548 { 549 303 550 #поиск вхождения слова: 551 304 552 $re_words['words'] = '(?<!' . $re_utf8_letter . ') #просмотр назад 553 305 554 (' . implode("\r\n|\r\n", $re_words['words']) . ') #=$m[3] 555 306 556 '; 557 307 558 } 559 308 560 if (! empty($re_words['digits'])) 561 309 562 { 563 310 564 #поиск вхождения цифры: 565 311 566 $re_words['digits'] = '(?<!\d) #просмотр назад 567 312 568 (' . implode("\r\n|\r\n", $re_words['digits']) . ') #=$m[4] 569 313 570 '; 571 314 572 } 573 315 574 #d($re_words); 316 575 576 577 317 578 $func_cache[$cache_id] = '/#встроенный PHP, Perl, ASP код: 579 318 580 <([\?\%]) .*? \\1> 319 581 582 583 320 584 #блоки CDATA: 585 321 586 | <\!\[CDATA\[ .*? \]\]> 322 587 588 589 323 590 #MS Word таги типа "<![if! vml]>...<![endif]>", 591 324 592 #условное выполнение кода для IE типа "<!--[if lt IE 7]>...<![endif]-->": 593 325 594 | <\! (?>--)? 595 326 596 \[ 597 327 598 (?> [^\]"\']+ | "[^"]*" | \'[^\']*\' )* 599 328 600 \] 601 329 602 (?>--)? 603 330 604 > 331 605 606 607 332 608 #комментарии: 609 333 610 | <\!-- .*? --> 334 611 612 613 335 614 #парные таги вместе с содержимым: 615 336 616 | <((?i:noindex|script|style|comment|button|map|iframe|frameset|object|applet))' . $re_attrs_fast_safe . '>.*?<\/(?i:\\2)> #=$m[2] 337 617 618 619 338 620 #парные и непарные таги: 621 339 622 | <[\/\!]?[a-zA-Z][a-zA-Z\d]*' . $re_attrs_fast_safe . '\/?> 340 623 624 625 341 626 #html сущности: 627 342 628 | &(?> [a-zA-Z][a-zA-Z\d]+ 629 343 630 | \#(?> \d{1,4} 631 344 632 | x[\da-fA-F]{2,4} 633 345 634 ) 635 346 636 ); 637 347 638 | ' . implode("\r\n|\r\n", $re_words) . ' #3 or 4 639 348 640 /sx'; 641 349 642 #d($func_cache[$cache_id]); 643 350 644 } 645 351 646 $GLOBALS['HTML_WORDS_HIGHLIGHT_TPL'] = $tpl; 647 352 648 $s = preg_replace_callback($func_cache[$cache_id], '_html_words_highlight_callback', $s); 649 353 650 unset($GLOBALS['HTML_WORDS_HIGHLIGHT_TPL']); 651 354 652 endif; 653 355 654 return $s; 356 } 655 656 } 657 658 357 659 358 660 function _html_words_highlight_callback($m) 661 359 662 { 663 360 664 foreach (array(3, 4) as $i) 665 361 666 { 667 362 668 if (array_key_exists($i, $m) && strlen($m[$i]) > 0) 669 363 670 { 671 364 672 //d($m); 673 365 674 return sprintf($GLOBALS['HTML_WORDS_HIGHLIGHT_TPL'], $m[$i]); 675 366 676 } 677 367 678 }#foreach 368 679 680 681 369 682 #пропускаем таги 683 370 684 return $m[0]; 371 } 685 686 } 687 688 689 372 690 373 691 374 692 //main plugin function 693 375 694 function wp_target_visitors_auto () { 695 376 696 $text_code = ""; 697 377 698 $text_code = get_option('text_code'); 699 378 700 $text_code=stripcslashes($text_code); 701 379 702 $terms_array = get_search_query_terms(); 703 380 704 if($terms_array!=false){ 705 381 706 $se=""; 707 382 708 foreach ($terms_array as $term) { 709 383 710 $se.=$term." "; 711 384 712 } 713 385 714 $se=substr($se,0,(strlen($se)-1)); 715 386 716 $text_code = str_replace("[SE_REQUEST]",$se,$text_code); 717 387 718 $rss_url = get_bloginfo('rss2_url'); 719 388 720 $text_code = str_replace("[RSS_URL]",$rss_url,$text_code); 721 389 722 $permalink = get_bloginfo('siteurl').$_SERVER['REQUEST_URI']; 723 390 724 $text_code = str_replace("[PERMALINK]",$permalink,$text_code); 725 391 726 return $text_code; 727 392 728 } 393 } 729 730 } 731 732 394 733 395 734 function wp_target_visitors () { 735 396 736 $wp_target_code = wp_target_visitors_auto (); 737 397 738 echo $wp_target_code; 398 } 739 740 } 741 399 742 743 400 744 add_action('admin_menu', 'target_visitors_add_pages'); 745 401 746 add_action('init', 'target_visitors_set'); 747 402 748 add_filter('comment_text', 'html_words_highlight'); 749 403 750 add_filter('the_content', 'html_words_highlight'); 751 404 752 add_filter('the_excerpt', 'html_words_highlight'); 753 405 754 add_filter('the_title', 'html_words_highlight'); 755 406 756 if (get_option('autoset')=="1"): 757 407 758 add_filter('the_content', 'autosetfunc',1); 759 408 760 endif; 761 409 762 ?> -
target-visitors/trunk/readme.txt
r128160 r128209 5 5 Requires at least: 2.3.2 6 6 Tested up to: 2.8 7 Version: 1.2. 47 Version: 1.2.5 8 8 Last Updated: 2009-06-21 9 Stable tag: 1.2. 49 Stable tag: 1.2.5 10 10 11 11 Plugin shows a special message for users coming from search engines like Google, Yandex, MSN, Yahoo, etc. … … 64 64 == Changelog == 65 65 66 = 1.2. 4=66 = 1.2.5 = 67 67 * Fixed russian lang. 68 68 -
target-visitors/trunk/wp-target-visitors.php
r128160 r128209 5 5 Description: Plugin shows a special message for visitors coming from search engines: Google, Yandex, Mail, Yahoo, Liveinternet, Rambler, Altavista, Msn. 6 6 Author: Abanova Olga 7 Version: 1.2. 47 Version: 1.2.5 8 8 Author URI: http://www.getincss.ru 9 9 */ 10 10 11 11 include_once ('functions.php'); 12 13 12 if ( ! defined( 'WP_CONTENT_URL' ) ) 14 13 define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' ); 14 15 15 if ( ! defined( 'WP_CONTENT_DIR' ) ) 16 16 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); 17 17 18 if ( ! defined( 'WP_PLUGIN_URL' ) ) 18 19 define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' ); 19 20 if ( ! defined( 'WP_PLUGIN_DIR' ) ) 21 20 22 define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); 21 22 23 23 24 // Adding stylesheet in head … … 25 26 echo "<link rel=\"stylesheet\" href=\"".WP_PLUGIN_URL."/target-visitors/target-visitors.css\" type=\"text/css\" media=\"screen\" />\n"; 26 27 } 27 28 28 function autosetfunc($content) { 29 29 if(is_single()): … … 33 33 return $content; 34 34 } 35 36 37 35 //init on activate plugin 38 36 if (!function_exists('target_visitors_set')) { 39 function target_visitors_set() { 40 $text_code = "<div class=\"se_request\">".__("You were come by request").": <a href=\"[PERMALINK]\"><b>[SE_REQUEST]</b></a>.<br />".__("Find interesting information? You can easy follow my blog through")." <a href=\"[RSS_URL]\"><b>RSS</b></a>.</div>"; 37 function target_visitors_set() { 38 $currentLocale = get_locale(); 39 if(!empty($currentLocale) && $currentLocale="ru_RU") { 40 $moFile = "target-visitors/lang"; 41 load_plugin_textdomain('target_visitors',false,$moFile); 42 } 43 44 $text_code = "<div class=\"se_request\">".__("You were come by request","target_visitors").": <a href=\"[PERMALINK]\"><b>[SE_REQUEST]</b></a>.<br />".__("Find interesting information? You can easy follow my blog through","target_visitors")." <a href=\"[RSS_URL]\"><b>RSS</b></a>.</div>"; 45 41 46 $autoset = '0'; 42 47 if(@$_POST['target_visitors_update']): 48 43 49 update_option("text_code", $_POST['text_code']); 50 44 51 update_option("autoset", $_POST['autoset']); 45 52 else: 46 53 if(!get_option("text_code") or !get_option("autoset")) 54 47 55 add_option("text_code", $text_code); 56 48 57 add_option("autoset", $autoset); 49 endif; 50 51 $currentLocale = get_locale(); 52 53 if(!empty($currentLocale) && $currentLocale="ru_RU") { 54 $currentLocale="RU"; 55 56 $moFile = dirname(__FILE__) . "/lang/target-visitors_" . $currentLocale . ".mo"; 57 58 if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('target-visitors', $moFile); 59 60 } 58 59 endif; 61 60 62 61 add_action('wp_head','target_visitors_head'); 63 62 } 64 } 63 64 } 65 65 66 66 67 //adding options in admin menu 68 67 69 function target_visitors_add_pages() { 68 add_options_page(__('Target Visitors options'), 'Target Visitors', 8, __FILE__, 'target_visitors_options_page'); 69 } 70 71 add_options_page(__('Target Visitors options',"target_visitors"), 'Target Visitors', 8, __FILE__, 'target_visitors_options_page'); 72 73 } 74 75 70 76 71 77 //plugin options 78 72 79 function target_visitors_options_page() { 80 73 81 if (@$_POST['target_visitors_update']) { 82 83 84 74 85 if (empty($_POST['text_code']) or empty($_POST['css_code'])) { 86 75 87 if (empty($_POST['text_code'])) { 88 76 89 $text_code = ""; 90 77 91 update_option('text_code', $text_code); 78 $msg_status = __("HTML code removed"); 92 93 $msg_status = __("HTML code removed","target_visitors"); 94 79 95 } 96 80 97 98 81 99 if (empty($_POST['css_code'])){ 100 82 101 $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css"; 102 83 103 if (is_writable($filename)) { 104 84 105 $css_open_file = fopen($filename, "w"); 106 85 107 if (fwrite($css_open_file, $css_code) === FALSE) { 86 $msg_status = __("Error writing css file."); 108 109 $msg_status = __("Error writing css file.","target_visitors"); 110 87 111 exit; 112 88 113 } 114 89 115 fclose($css_open_file); 116 90 117 //remove_action('wp_head','target_visitors_head'); 91 $msg_status.=__("CSS code removed"); 118 119 $msg_status.=__("CSS code removed","target_visitors"); 120 92 121 } else { 93 $msg_status = __("CSS file is not allowed for writing"); 122 123 124 125 $msg_status = __("CSS file is not allowed for writing","target_visitors"); 126 127 128 129 130 131 94 132 exit; 133 95 134 } 135 96 136 ?> 137 97 138 <div id="message" class="updated fade"><p><?=$msg_status?></p></div> 139 98 140 <? 141 99 142 } 143 100 144 } else { 145 101 146 $text_code = stripcslashes($_POST['text_code']); 102 update_option('text_code', $text_code); 147 148 update_option('text_code', $text_code); 149 103 150 $msg_status = "Text saved. "; 151 104 152 $css_code = stripcslashes($_POST['css_code']); 153 105 154 $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css"; 155 106 156 if (is_writable($filename)) { 157 107 158 $css_open_file = fopen($filename, "w"); 159 108 160 if (fwrite($css_open_file, $css_code) === FALSE) { 109 $msg_status.=__("Error writing css file."); 161 162 $msg_status.=__("Error writing css file.","target_visitors"); 163 110 164 exit; 165 111 166 } 167 112 168 fclose($css_open_file); 113 $msg_status.=__("CSS code saved"); 169 170 $msg_status.=__("CSS code saved","target_visitors"); 171 114 172 } else { 115 $msg_status.=__("CSS file is not allowed for writing."); 173 174 $msg_status.=__("CSS file is not allowed for writing.","target_visitors"); 175 116 176 } 177 117 178 } 179 118 180 181 119 182 if ($_POST['autoset']) { 183 120 184 update_option('autoset', $_POST['autoset']); 121 $msg_status.=__("Plugin will autoset to single.php"); 185 186 $msg_status.=__("Plugin will autoset to single.php","target_visitors"); 187 122 188 add_filter('the_content', 'autosetfunc'); 189 123 190 } else { 124 $msg_status.=__("Plugin will not autoset to single.php"); 191 192 $msg_status.=__("Plugin will not autoset to single.php","target_visitors"); 193 125 194 } 195 126 196 197 127 198 ?><div id="message" class="updated fade"><p><?=$msg_status?></p></div><? 199 128 200 } 201 129 202 203 130 204 else { 205 131 206 // Fetch code from options 207 132 208 $text_code = get_option('text_code'); 209 133 210 $text_code= stripcslashes($text_code); 211 134 212 $autoset=get_option('autoset'); 213 135 214 $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css"; 215 136 216 if (is_readable($filename)) { 217 137 218 $css_open_file = fopen($filename, "r"); 219 138 220 $css_code = fread($css_open_file, filesize($filename)); 221 139 222 fclose($css_open_file); 223 140 224 } else { 141 $msg_status.=__("Css file is not readable."); 225 226 $msg_status.=__("Css file is not readable.","target_visitors"); 227 142 228 ?><div id="message" class="updated fade"><p><?=$msg_status?></p></div> <? 229 143 230 } 231 144 232 } 233 145 234 ?> 235 146 236 <div class="wrap"> 237 147 238 <h2>Target visitors</h2> 239 148 240 <div style="float:right; width:250px; border:solid 1px #ccc; padding:10px;"> 149 <h3 style="font-size:16px; background:#eee"><? _e("Support");?></h3> 150 <p><? _e("If you have any ideas or questions about this plugin, write a comment at plugin homepage <a href=\"http://www.getincss.ru/wp-target-visitors_en/\">Target Visitors</a>.<br /><br />You can also e-mail me: webmaster(dog)getincss.ru<br /><br /><b>Do you like this plugin?</b><br />I'll glad for your donations. Webmoney:<br />Z102896061935<br />R144897054561"); ?></p> 241 242 <h3 style="font-size:16px; background:#eee"><? _e("Support","target_visitors");?></h3> 243 244 <p><? _e("If you have any ideas or questions about this plugin, write a comment at plugin homepage <a href=\"http://www.getincss.ru/wp-target-visitors_en/\">Target Visitors</a>.<br /><br />You can also e-mail me: webmaster(dog)getincss.ru<br /><br /><b>Do you like this plugin?</b><br />I'll glad for your donations. Webmoney:<br />Z102896061935<br />R144897054561","target_visitors"); ?></p> 245 151 246 </div> 247 152 248 <div style="margin-right:300px;"> 153 <p><? _e("Plugin \"Target Visitors\" allow to show special message for visitors coming from search engines: Google, Yandex, Mail, Yahoo, Liveinternet, Rambler, Altavista, Msn. You can use this tags in text:<br /><br><b>[PERMALINK]</b> - current page's URL<br><br><b style=\"color:red\">[SE_REQUEST]</b> - search engine request that user coming by<br><br><b>[RSS_URL]</b> - URL for your RSS<br><br>After saving data you can to put this code:<br><b><code><? if(function_exists(\"wp_target_visitors\")) wp_target_visitors(); ?></code></b><br> on pages: search.php, archive.php, etc, where you want to show a message for target visitors."); ?> 249 250 <p><? _e("Plugin \"Target Visitors\" allow to show special message for visitors coming from search engines: Google, Yandex, Mail, Yahoo, Liveinternet, Rambler, Altavista, Msn. You can use this tags in text:<br /><br><b>[PERMALINK]</b> - current page's URL<br><br><b style=\"color:red\">[SE_REQUEST]</b> - search engine request that user coming by<br><br><b>[RSS_URL]</b> - URL for your RSS<br><br>After saving data you can to put this code:<br><b><code><? if(function_exists(\"wp_target_visitors\")) wp_target_visitors(); ?></code></b><br> on pages: search.php, archive.php, etc, where you want to show a message for target visitors.","target_visitors"); ?> 251 154 252 </p> 253 155 254 <form name="form_target_visitors" method="post" action="<?=$_SERVER['REQUEST_URI']?>"> 156 <p><? _e("Your Message");?>:<br /><textarea name="text_code" id="text_code" cols="40" rows="10" style="width: 80%; font-size: 14px;" class="code"><?=stripslashes($text_code);?></textarea></p> 157 <p><? _e("CSS code (CSS file in <b>target-visitors</b> directory must be writable)"); ?>:<br /><textarea name="css_code" id="css_code" cols="40" rows="10" style="width: 80%; font-size: 14px;" class="code"><?=stripslashes($css_code);?></textarea></p> 158 <p><input type="checkbox" name="autoset" value="1" <? if (get_option('autoset')=="1") echo "checked";?> /> <? _e("Autoset plugin's display message function on single.php page"); ?></p> 255 256 <p><? _e("Your Message","target_visitors");?>:<br /><textarea name="text_code" id="text_code" cols="40" rows="10" style="width: 80%; font-size: 14px;" class="code"><?=stripslashes($text_code);?></textarea></p> 257 258 <p><? _e("CSS code (CSS file in <b>target-visitors</b> directory must be writable)","target_visitors"); ?>:<br /><textarea name="css_code" id="css_code" cols="40" rows="10" style="width: 80%; font-size: 14px;" class="code"><?=stripslashes($css_code);?></textarea></p> 259 260 <p><input type="checkbox" name="autoset" value="1" <? if (get_option('autoset')=="1") echo "checked";?> /> <? _e("Autoset plugin's display message function on single.php page","target_visitors"); ?></p> 261 159 262 <p class="submit"> 160 <input type="submit" name="target_visitors_update" value="<? _e("Save code »"); ?>" /> 263 264 <input type="submit" name="target_visitors_update" value="<? _e("Save code »","target_visitors"); ?>" /> 265 161 266 </p> 267 162 268 </div> 269 163 270 </div> 271 164 272 <? 165 } 273 274 } 275 276 277 166 278 167 279 168 280 function get_search_query_terms() { 281 169 282 $query_array = array(); 283 170 284 if(@$_GET['s']): 285 171 286 $se=$_GET['s']; 287 172 288 while (ereg('%([0-9A-F]{2})',$se)){ 289 173 290 $val=ereg_replace('.*%([0-9A-F]{2}).*','\1',$se); 291 174 292 $newval=chr(hexdec($val)); 293 175 294 $se=str_replace('%'.$val,$newval,$se); 295 176 296 } 297 177 298 if (strstr($se,"+")) $se = str_replace("+"," ",$se); 299 178 300 $query_array = explode(" ", $se); 301 179 302 else: 303 180 304 $se=getenv("HTTP_REFERER"); 305 181 306 $se_array = array("?q="=>"3","&q="=>"3","text="=>"5","words="=>"6","ask="=>"4","&p="=>"3","?p="=>"3"); 307 182 308 foreach ($se_array as $se_item=>$se_item_num): 309 183 310 if(strstr($se,$se_item)): 311 184 312 while (ereg('%([0-9A-F]{2})',$se)){ 313 185 314 $val=ereg_replace('.*%([0-9A-F]{2}).*','\1',$se); 315 186 316 $newval=chr(hexdec($val)); 317 187 318 $se=str_replace('%'.$val,$newval,$se); 319 188 320 } 321 189 322 $text_pos = strpos($se,$se_item)+$se_item_num; 323 190 324 break; 325 191 326 endif; 327 192 328 endforeach; 329 193 330 if($text_pos): 331 194 332 $text_pos_amp = strpos($se,"&",$text_pos); 333 195 334 if (!$text_pos_amp) $text_pos_amp=strlen($se); 335 196 336 $se=substr($se,$text_pos,($text_pos_amp-$text_pos)); 337 197 338 if (strstr($se,"+")) $se = str_replace("+"," ",$se); 339 198 340 if (!detect_utf($se)) $se = win_utf8($se); 341 199 342 $query_array = explode(" ", $se); 343 200 344 else: 345 201 346 $query_array=false; 347 202 348 endif; 349 203 350 endif; 351 204 352 return $query_array; 205 } 353 354 } 355 356 357 206 358 207 359 208 360 function html_words_highlight($s) 361 209 362 { 363 210 364 $query_array = get_search_query_terms(); 365 211 366 367 212 368 if($query_array!=false): 369 213 370 $new_query_array=array(); 371 214 372 foreach ($query_array as $term): 373 215 374 $term2=utf8_to_unicode($term); 375 216 376 if((strlen($term2)/6)>1): 377 217 378 $new_query_array[]=$term; 379 218 380 endif; 381 219 382 endforeach; 383 220 384 $words=$new_query_array; 385 221 386 387 222 388 $is_match_case = false; 389 223 390 $tpl = '<span class="hightlite">%s</span>'; 391 224 392 #оптимизация для пустых значений 393 225 394 if (! strlen($s) || ! $words) return $s; 226 395 396 397 227 398 #оптимизация "Ту 134" = "Ту 134" 399 228 400 #{{{ 401 229 402 $s2 = utf8_convert_case($s, CASE_LOWER); 403 230 404 foreach ($words as $k => $word) 405 231 406 { 407 232 408 $word = utf8_convert_case(trim($word, "\x20\r\n\t*"), CASE_LOWER); 409 233 410 if ($word == '' || strpos($s2, $word) === false) unset($words[$k]); 411 234 412 } 413 235 414 if (! $words) return $s; 415 236 416 #}}} 237 417 418 419 238 420 #d($words); 421 239 422 #кеширование построения рег. выражения для "подсвечивания" слов в функции при повторных вызовах 423 240 424 static $func_cache = array(); 425 241 426 $cache_id = md5(serialize(array($words, $is_match_case))); 427 242 428 if (! array_key_exists($cache_id, $func_cache)) 429 243 430 { 431 244 432 #буквы в кодировке UTF-8 для разных языков: 433 245 434 static $re_utf8_letter = '#английский алфавит: 435 246 436 [a-zA-Z] 437 247 438 #русский алфавит (A-я): 439 248 440 | \xd0[\x90-\xbf\x81]|\xd1[\x80-\x8f\x91] 441 249 442 #+ татарские буквы из кириллицы: 443 250 444 | \xd2[\x96\x97\xa2\xa3\xae\xaf\xba\xbb]|\xd3[\x98\x99\xa8\xa9] 445 251 446 #+ турецкие буквы из латиницы (татарский латиница): 447 252 448 | \xc3[\x84\xa4\x87\xa7\x91\xb1\x96\xb6\x9c\xbc]|\xc4[\x9e\x9f\xb0\xb1]|\xc5[\x9e\x9f] 449 253 450 '; 451 254 452 #регулярное выражение для атрибутов тагов 453 255 454 #корректно обрабатывает грязный и битый HTML в однобайтовой или UTF-8 кодировке! 455 256 456 static $re_attrs_fast_safe = '(?> (?>[\x20\r\n\t]+|\xc2\xa0)+ #пробельные символы (д.б. обязательно) 457 257 458 (?> 459 258 460 #правильные атрибуты 461 259 462 [^>"\']+ 463 260 464 | (?<=[\=\x20\r\n\t]|\xc2\xa0) "[^"]*" 465 261 466 | (?<=[\=\x20\r\n\t]|\xc2\xa0) \'[^\']*\' 467 262 468 #разбитые атрибуты 469 263 470 | [^>]+ 471 264 472 )* 473 265 474 )?'; 266 475 476 477 267 478 $re_words = array(); 479 268 480 foreach ($words as $word) 481 269 482 { 483 270 484 if ($is_mask = (substr($word, -1) === '*')) $word = rtrim($word, '*'); 271 485 486 487 272 488 $is_digit = ctype_digit($word); 273 489 490 491 274 492 #рег. выражение для поиска слова с учётом регистра или цифр: 493 275 494 $re_word = preg_quote($word, '/'); 276 495 496 497 277 498 #рег. выражение для поиска слова НЕЗАВИСИМО от регистра: 499 278 500 if (! $is_match_case && ! $is_digit) 501 279 502 { 503 280 504 #для латинских букв 505 281 506 if (preg_match('/^[a-zA-Z]+$/', $word)) $re_word = '(?i:' . $re_word . ')'; 507 282 508 #для русских и др. букв 509 283 510 else 511 284 512 { 513 285 514 $re_word_cases = array( 515 286 516 'lowercase' => utf8_convert_case($re_word, CASE_LOWER), #word 517 287 518 'ucfirst' => utf8_ucfirst($re_word), #Word 519 288 520 'uppercase' => utf8_convert_case($re_word, CASE_UPPER), #WORD 521 289 522 ); 523 290 524 $re_word = '(?>' . implode('|', $re_word_cases) . ')'; 525 291 526 } 527 292 528 } 293 529 530 531 294 532 #d($re_word); 533 295 534 if ($is_digit) $append = $is_mask ? '(?>\d*)' : '(?!\d)'; 535 296 536 else $append = $is_mask ? '(?>' . $re_utf8_letter . ')*' : '(?! ' . $re_utf8_letter . ')'; 537 297 538 $re_words[$is_digit ? 'digits' : 'words'][] = $re_word . $append; 539 298 540 }#foreach 541 299 542 #d($re_words); 300 543 544 545 301 546 if (! empty($re_words['words'])) 547 302 548 { 549 303 550 #поиск вхождения слова: 551 304 552 $re_words['words'] = '(?<!' . $re_utf8_letter . ') #просмотр назад 553 305 554 (' . implode("\r\n|\r\n", $re_words['words']) . ') #=$m[3] 555 306 556 '; 557 307 558 } 559 308 560 if (! empty($re_words['digits'])) 561 309 562 { 563 310 564 #поиск вхождения цифры: 565 311 566 $re_words['digits'] = '(?<!\d) #просмотр назад 567 312 568 (' . implode("\r\n|\r\n", $re_words['digits']) . ') #=$m[4] 569 313 570 '; 571 314 572 } 573 315 574 #d($re_words); 316 575 576 577 317 578 $func_cache[$cache_id] = '/#встроенный PHP, Perl, ASP код: 579 318 580 <([\?\%]) .*? \\1> 319 581 582 583 320 584 #блоки CDATA: 585 321 586 | <\!\[CDATA\[ .*? \]\]> 322 587 588 589 323 590 #MS Word таги типа "<![if! vml]>...<![endif]>", 591 324 592 #условное выполнение кода для IE типа "<!--[if lt IE 7]>...<![endif]-->": 593 325 594 | <\! (?>--)? 595 326 596 \[ 597 327 598 (?> [^\]"\']+ | "[^"]*" | \'[^\']*\' )* 599 328 600 \] 601 329 602 (?>--)? 603 330 604 > 331 605 606 607 332 608 #комментарии: 609 333 610 | <\!-- .*? --> 334 611 612 613 335 614 #парные таги вместе с содержимым: 615 336 616 | <((?i:noindex|script|style|comment|button|map|iframe|frameset|object|applet))' . $re_attrs_fast_safe . '>.*?<\/(?i:\\2)> #=$m[2] 337 617 618 619 338 620 #парные и непарные таги: 621 339 622 | <[\/\!]?[a-zA-Z][a-zA-Z\d]*' . $re_attrs_fast_safe . '\/?> 340 623 624 625 341 626 #html сущности: 627 342 628 | &(?> [a-zA-Z][a-zA-Z\d]+ 629 343 630 | \#(?> \d{1,4} 631 344 632 | x[\da-fA-F]{2,4} 633 345 634 ) 635 346 636 ); 637 347 638 | ' . implode("\r\n|\r\n", $re_words) . ' #3 or 4 639 348 640 /sx'; 641 349 642 #d($func_cache[$cache_id]); 643 350 644 } 645 351 646 $GLOBALS['HTML_WORDS_HIGHLIGHT_TPL'] = $tpl; 647 352 648 $s = preg_replace_callback($func_cache[$cache_id], '_html_words_highlight_callback', $s); 649 353 650 unset($GLOBALS['HTML_WORDS_HIGHLIGHT_TPL']); 651 354 652 endif; 653 355 654 return $s; 356 } 655 656 } 657 658 357 659 358 660 function _html_words_highlight_callback($m) 661 359 662 { 663 360 664 foreach (array(3, 4) as $i) 665 361 666 { 667 362 668 if (array_key_exists($i, $m) && strlen($m[$i]) > 0) 669 363 670 { 671 364 672 //d($m); 673 365 674 return sprintf($GLOBALS['HTML_WORDS_HIGHLIGHT_TPL'], $m[$i]); 675 366 676 } 677 367 678 }#foreach 368 679 680 681 369 682 #пропускаем таги 683 370 684 return $m[0]; 371 } 685 686 } 687 688 689 372 690 373 691 374 692 //main plugin function 693 375 694 function wp_target_visitors_auto () { 695 376 696 $text_code = ""; 697 377 698 $text_code = get_option('text_code'); 699 378 700 $text_code=stripcslashes($text_code); 701 379 702 $terms_array = get_search_query_terms(); 703 380 704 if($terms_array!=false){ 705 381 706 $se=""; 707 382 708 foreach ($terms_array as $term) { 709 383 710 $se.=$term." "; 711 384 712 } 713 385 714 $se=substr($se,0,(strlen($se)-1)); 715 386 716 $text_code = str_replace("[SE_REQUEST]",$se,$text_code); 717 387 718 $rss_url = get_bloginfo('rss2_url'); 719 388 720 $text_code = str_replace("[RSS_URL]",$rss_url,$text_code); 721 389 722 $permalink = get_bloginfo('siteurl').$_SERVER['REQUEST_URI']; 723 390 724 $text_code = str_replace("[PERMALINK]",$permalink,$text_code); 725 391 726 return $text_code; 727 392 728 } 393 } 729 730 } 731 732 394 733 395 734 function wp_target_visitors () { 735 396 736 $wp_target_code = wp_target_visitors_auto (); 737 397 738 echo $wp_target_code; 398 } 739 740 } 741 399 742 743 400 744 add_action('admin_menu', 'target_visitors_add_pages'); 745 401 746 add_action('init', 'target_visitors_set'); 747 402 748 add_filter('comment_text', 'html_words_highlight'); 749 403 750 add_filter('the_content', 'html_words_highlight'); 751 404 752 add_filter('the_excerpt', 'html_words_highlight'); 753 405 754 add_filter('the_title', 'html_words_highlight'); 755 406 756 if (get_option('autoset')=="1"): 757 407 758 add_filter('the_content', 'autosetfunc',1); 759 408 760 endif; 761 409 762 ?>
Note: See TracChangeset
for help on using the changeset viewer.