Plugin Directory

Changeset 128209


Ignore:
Timestamp:
06/21/2009 06:57:37 PM (17 years ago)
Author:
getincss
Message:

All done.

Location:
target-visitors
Files:
8 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • target-visitors/tags/1.2.5/readme.txt

    r128160 r128209  
    55Requires at least: 2.3.2
    66Tested up to: 2.8
    7 Version: 1.2.4
     7Version: 1.2.5
    88Last Updated: 2009-06-21
    9 Stable tag: 1.2.4
     9Stable tag: 1.2.5
    1010
    1111Plugin shows a special message for users coming from search engines like Google, Yandex, MSN, Yahoo, etc.
     
    6464== Changelog ==
    6565
    66 = 1.2.4 =
     66= 1.2.5 =
    6767* Fixed russian lang.
    6868
  • target-visitors/tags/1.2.5/wp-target-visitors.php

    r128160 r128209  
    55Description: Plugin shows a special message for visitors coming from search engines: Google, Yandex, Mail, Yahoo, Liveinternet, Rambler, Altavista, Msn.
    66Author: Abanova Olga
    7 Version: 1.2.4
     7Version: 1.2.5
    88Author URI: http://www.getincss.ru
    99*/
    1010
    1111include_once ('functions.php');
    12 
    1312if ( ! defined( 'WP_CONTENT_URL' ) )
    1413      define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
     14
    1515if ( ! defined( 'WP_CONTENT_DIR' ) )
    1616      define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
     17
    1718if ( ! defined( 'WP_PLUGIN_URL' ) )
    1819      define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
    1920if ( ! defined( 'WP_PLUGIN_DIR' ) )
     21
    2022      define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
    21 
    2223
    2324// Adding stylesheet in head
     
    2526  echo "<link rel=\"stylesheet\" href=\"".WP_PLUGIN_URL."/target-visitors/target-visitors.css\" type=\"text/css\" media=\"screen\" />\n";
    2627}
    27 
    2828function autosetfunc($content) {
    2929    if(is_single()):
     
    3333    return $content;
    3434}
    35 
    36 
    3735//init on activate plugin
    3836if (!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
    4146        $autoset = '0';
    4247        if(@$_POST['target_visitors_update']):
     48
    4349                update_option("text_code", $_POST['text_code']);
     50
    4451                update_option("autoset", $_POST['autoset']);
    4552        else:
    4653            if(!get_option("text_code") or !get_option("autoset"))
     54
    4755                add_option("text_code", $text_code);
     56
    4857                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;
    6160           
    6261        add_action('wp_head','target_visitors_head');
    6362    }
    64 }
     63
     64}
     65
    6566
    6667//adding options in admin menu
     68
    6769function 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
    7076
    7177//plugin options
     78
    7279function target_visitors_options_page() {
     80
    7381    if (@$_POST['target_visitors_update']) {
     82   
     83   
     84
    7485       if (empty($_POST['text_code']) or empty($_POST['css_code'])) {
     86
    7587            if (empty($_POST['text_code'])) {
     88
    7689                  $text_code = "";
     90
    7791                  update_option('text_code', $text_code);
    78                   $msg_status = __("HTML code removed");
     92
     93                  $msg_status = __("HTML code removed","target_visitors");
     94
    7995            }
     96
    8097           
     98
    8199            if (empty($_POST['css_code'])){
     100
    82101                $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css";
     102
    83103                  if (is_writable($filename)) {
     104
    84105                        $css_open_file = fopen($filename, "w");                 
     106
    85107                        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
    87111                            exit;
     112
    88113                        }                   
     114
    89115                        fclose($css_open_file);                     
     116
    90117                        //remove_action('wp_head','target_visitors_head');
    91                         $msg_status.=__("CSS code removed");
     118
     119                        $msg_status.=__("CSS code removed","target_visitors");
     120
    92121                   } 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
    94132                       exit;
     133
    95134                   }                 
     135
    96136            ?>
     137
    97138            <div id="message" class="updated fade"><p><?=$msg_status?></p></div>
     139
    98140            <?
     141
    99142            }
     143
    100144        } else {   
     145
    101146            $text_code = stripcslashes($_POST['text_code']);
    102             update_option('text_code', $text_code);
     147
     148            update_option('text_code', $text_code);         
     149
    103150            $msg_status = "Text saved. ";
     151
    104152            $css_code = stripcslashes($_POST['css_code']);
     153
    105154            $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css";
     155
    106156              if (is_writable($filename)) {
     157
    107158                    $css_open_file = fopen($filename, "w");                 
     159
    108160                    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
    110164                        exit;
     165
    111166                    }                   
     167
    112168                    fclose($css_open_file);                     
    113                     $msg_status.=__("CSS code saved");
     169
     170                    $msg_status.=__("CSS code saved","target_visitors");
     171
    114172               } 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
    116176               }             
     177
    117178        }
     179
    118180       
     181
    119182        if ($_POST['autoset']) {
     183
    120184          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
    122188          add_filter('the_content', 'autosetfunc');
     189
    123190        } 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
    125194        }
     195
    126196       
     197
    127198        ?><div id="message" class="updated fade"><p><?=$msg_status?></p></div><?
     199
    128200    }
     201
    129202   
     203
    130204    else {
     205
    131206        // Fetch code from options
     207
    132208        $text_code = get_option('text_code');
     209
    133210        $text_code= stripcslashes($text_code); 
     211
    134212        $autoset=get_option('autoset');
     213
    135214        $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css";
     215
    136216          if (is_readable($filename)) {
     217
    137218                $css_open_file = fopen($filename, "r");
     219
    138220                $css_code = fread($css_open_file, filesize($filename));                 
     221
    139222                fclose($css_open_file);                     
     223
    140224           } else {
    141            $msg_status.=__("Css file is not readable.");
     225
     226           $msg_status.=__("Css file is not readable.","target_visitors");
     227
    142228           ?><div id="message" class="updated fade"><p><?=$msg_status?></p></div> <?
     229
    143230           }       
     231
    144232    }
     233
    145234?>
     235
    146236<div class="wrap">
     237
    147238     <h2>Target visitors</h2>
     239
    148240      <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
    151246        </div>
     247
    152248        <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>&lt;? if(function_exists(\"wp_target_visitors\")) wp_target_visitors(); ?&gt;</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>&lt;? if(function_exists(\"wp_target_visitors\")) wp_target_visitors(); ?&gt;</code></b><br> on pages: search.php, archive.php, etc, where you want to show a message for target visitors.","target_visitors"); ?>
     251
    154252            </p>                               
     253
    155254            <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
    159262            <p class="submit">
    160                 <input type="submit" name="target_visitors_update" value="<? _e("Save code &raquo;"); ?>" />
     263
     264                <input type="submit" name="target_visitors_update" value="<? _e("Save code &raquo;","target_visitors"); ?>" />
     265
    161266            </p>           
     267
    162268     </div>
     269
    163270</div>
     271
    164272<?   
    165 }
     273
     274}
     275
     276
     277
    166278
    167279
    168280function get_search_query_terms() {
     281
    169282    $query_array = array();
     283
    170284    if(@$_GET['s']):
     285
    171286        $se=$_GET['s'];
     287
    172288        while (ereg('%([0-9A-F]{2})',$se)){
     289
    173290            $val=ereg_replace('.*%([0-9A-F]{2}).*','\1',$se);
     291
    174292            $newval=chr(hexdec($val));
     293
    175294            $se=str_replace('%'.$val,$newval,$se);
     295
    176296        }
     297
    177298        if (strstr($se,"+")) $se = str_replace("+"," ",$se);
     299
    178300        $query_array = explode(" ", $se);
     301
    179302    else:
     303
    180304        $se=getenv("HTTP_REFERER");
     305
    181306        $se_array = array("?q="=>"3","&q="=>"3","text="=>"5","words="=>"6","ask="=>"4","&p="=>"3","?p="=>"3"); 
     307
    182308        foreach ($se_array as $se_item=>$se_item_num):
     309
    183310            if(strstr($se,$se_item)):
     311
    184312                while (ereg('%([0-9A-F]{2})',$se)){
     313
    185314                    $val=ereg_replace('.*%([0-9A-F]{2}).*','\1',$se);
     315
    186316                    $newval=chr(hexdec($val));
     317
    187318                    $se=str_replace('%'.$val,$newval,$se);
     319
    188320                }
     321
    189322                $text_pos = strpos($se,$se_item)+$se_item_num;
     323
    190324                break;
     325
    191326            endif;
     327
    192328        endforeach;
     329
    193330        if($text_pos):
     331
    194332            $text_pos_amp = strpos($se,"&",$text_pos);
     333
    195334            if (!$text_pos_amp) $text_pos_amp=strlen($se);
     335
    196336            $se=substr($se,$text_pos,($text_pos_amp-$text_pos));           
     337
    197338            if (strstr($se,"+")) $se = str_replace("+"," ",$se);
     339
    198340            if (!detect_utf($se)) $se = win_utf8($se);
     341
    199342            $query_array = explode(" ", $se);
     343
    200344        else:
     345
    201346            $query_array=false;
     347
    202348        endif;
     349
    203350    endif;
     351
    204352    return $query_array;
    205 }
     353
     354}
     355
     356
     357
    206358
    207359
    208360function html_words_highlight($s)
     361
    209362{
     363
    210364    $query_array = get_search_query_terms();
     365
    211366   
     367
    212368    if($query_array!=false):
     369
    213370        $new_query_array=array();
     371
    214372        foreach ($query_array  as $term):
     373
    215374            $term2=utf8_to_unicode($term);
     375
    216376            if((strlen($term2)/6)>1):
     377
    217378                 $new_query_array[]=$term;
     379
    218380            endif;
     381
    219382        endforeach;
     383
    220384        $words=$new_query_array;
     385
    221386       
     387
    222388        $is_match_case = false;
     389
    223390        $tpl = '<span class="hightlite">%s</span>';
     391
    224392        #оптимизация для пустых значений
     393
    225394        if (! strlen($s) || ! $words) return $s;
    226395
     396
     397
    227398    #оптимизация "Ту  134" = "Ту 134"
     399
    228400    #{{{
     401
    229402    $s2 = utf8_convert_case($s, CASE_LOWER);
     403
    230404    foreach ($words as $k => $word)
     405
    231406    {
     407
    232408        $word = utf8_convert_case(trim($word, "\x20\r\n\t*"), CASE_LOWER);
     409
    233410        if ($word == '' || strpos($s2, $word) === false) unset($words[$k]);
     411
    234412    }
     413
    235414    if (! $words) return $s;
     415
    236416    #}}}
    237417
     418
     419
    238420    #d($words);
     421
    239422    #кеширование построения рег. выражения для "подсвечивания" слов в функции при повторных вызовах
     423
    240424    static $func_cache = array();
     425
    241426    $cache_id = md5(serialize(array($words, $is_match_case)));
     427
    242428    if (! array_key_exists($cache_id, $func_cache))
     429
    243430    {
     431
    244432        #буквы в кодировке UTF-8 для разных языков:
     433
    245434        static $re_utf8_letter = '#английский алфавит:
     435
    246436                                  [a-zA-Z]
     437
    247438                                  #русский алфавит (A-я):
     439
    248440                                  | \xd0[\x90-\xbf\x81]|\xd1[\x80-\x8f\x91]
     441
    249442                                  #+ татарские буквы из кириллицы:
     443
    250444                                  | \xd2[\x96\x97\xa2\xa3\xae\xaf\xba\xbb]|\xd3[\x98\x99\xa8\xa9]
     445
    251446                                  #+ турецкие буквы из латиницы (татарский латиница):
     447
    252448                                  | \xc3[\x84\xa4\x87\xa7\x91\xb1\x96\xb6\x9c\xbc]|\xc4[\x9e\x9f\xb0\xb1]|\xc5[\x9e\x9f]
     449
    253450                                  ';
     451
    254452        #регулярное выражение для атрибутов тагов
     453
    255454        #корректно обрабатывает грязный и битый HTML в однобайтовой или UTF-8 кодировке!
     455
    256456        static $re_attrs_fast_safe =  '(?> (?>[\x20\r\n\t]+|\xc2\xa0)+  #пробельные символы (д.б. обязательно)
     457
    257458                                           (?>
     459
    258460                                             #правильные атрибуты
     461
    259462                                                                            [^>"\']+
     463
    260464                                             | (?<=[\=\x20\r\n\t]|\xc2\xa0) "[^"]*"
     465
    261466                                             | (?<=[\=\x20\r\n\t]|\xc2\xa0) \'[^\']*\'
     467
    262468                                             #разбитые атрибуты
     469
    263470                                             |                              [^>]+
     471
    264472                                           )*
     473
    265474                                       )?';
    266475
     476
     477
    267478        $re_words = array();
     479
    268480        foreach ($words as $word)
     481
    269482        {
     483
    270484            if ($is_mask = (substr($word, -1) === '*')) $word = rtrim($word, '*');
    271485
     486
     487
    272488            $is_digit = ctype_digit($word);
    273489
     490
     491
    274492            #рег. выражение для поиска слова с учётом регистра или цифр:
     493
    275494            $re_word = preg_quote($word, '/');
    276495
     496
     497
    277498            #рег. выражение для поиска слова НЕЗАВИСИМО от регистра:
     499
    278500            if (! $is_match_case && ! $is_digit)
     501
    279502            {
     503
    280504                #для латинских букв
     505
    281506                if (preg_match('/^[a-zA-Z]+$/', $word)) $re_word = '(?i:' . $re_word . ')';
     507
    282508                #для русских и др. букв
     509
    283510                else
     511
    284512                {
     513
    285514                    $re_word_cases = array(
     515
    286516                        'lowercase' => utf8_convert_case($re_word, CASE_LOWER),  #word
     517
    287518                        'ucfirst'   => utf8_ucfirst($re_word),                   #Word
     519
    288520                        'uppercase' => utf8_convert_case($re_word, CASE_UPPER),  #WORD
     521
    289522                    );
     523
    290524                    $re_word = '(?>' . implode('|', $re_word_cases) . ')';
     525
    291526                }
     527
    292528            }
    293529
     530
     531
    294532            #d($re_word);
     533
    295534            if ($is_digit) $append = $is_mask ? '(?>\d*)' : '(?!\d)';
     535
    296536            else $append = $is_mask ? '(?>' . $re_utf8_letter . ')*' : '(?! ' . $re_utf8_letter . ')';
     537
    297538            $re_words[$is_digit ? 'digits' : 'words'][] = $re_word . $append;
     539
    298540        }#foreach
     541
    299542        #d($re_words);
    300543
     544
     545
    301546        if (! empty($re_words['words']))
     547
    302548        {
     549
    303550            #поиск вхождения слова:
     551
    304552            $re_words['words'] = '(?<!' . $re_utf8_letter . ')  #просмотр назад
     553
    305554                                  (' . implode("\r\n|\r\n", $re_words['words']) . ')   #=$m[3]
     555
    306556                                  ';
     557
    307558        }
     559
    308560        if (! empty($re_words['digits']))
     561
    309562        {
     563
    310564            #поиск вхождения цифры:
     565
    311566            $re_words['digits'] = '(?<!\d)  #просмотр назад
     567
    312568                                   (' . implode("\r\n|\r\n", $re_words['digits']) . ')   #=$m[4]
     569
    313570                                   ';
     571
    314572        }
     573
    315574        #d($re_words);
    316575
     576
     577
    317578        $func_cache[$cache_id] = '/#встроенный PHP, Perl, ASP код:
     579
    318580                                   <([\?\%]) .*? \\1>
    319581
     582
     583
    320584                                   #блоки CDATA:
     585
    321586                                   | <\!\[CDATA\[ .*? \]\]>
    322587
     588
     589
    323590                                   #MS Word таги типа "<![if! vml]>...<![endif]>",
     591
    324592                                   #условное выполнение кода для IE типа "<!--[if lt IE 7]>...<![endif]-->":
     593
    325594                                   | <\! (?>--)?
     595
    326596                                         \[
     597
    327598                                         (?> [^\]"\']+ | "[^"]*" | \'[^\']*\' )*
     599
    328600                                         \]
     601
    329602                                         (?>--)?
     603
    330604                                     >
    331605
     606
     607
    332608                                   #комментарии:
     609
    333610                                   | <\!-- .*? -->
    334611
     612
     613
    335614                                   #парные таги вместе с содержимым:
     615
    336616                                   | <((?i:noindex|script|style|comment|button|map|iframe|frameset|object|applet))' . $re_attrs_fast_safe . '>.*?<\/(?i:\\2)>  #=$m[2]
    337617
     618
     619
    338620                                   #парные и непарные таги:
     621
    339622                                   | <[\/\!]?[a-zA-Z][a-zA-Z\d]*' . $re_attrs_fast_safe . '\/?>
    340623
     624
     625
    341626                                   #html сущности:
     627
    342628                                   | &(?> [a-zA-Z][a-zA-Z\d]+
     629
    343630                                        | \#(?> \d{1,4}
     631
    344632                                              | x[\da-fA-F]{2,4}
     633
    345634                                            )
     635
    346636                                      );
     637
    347638                                   | ' . implode("\r\n|\r\n", $re_words) . '  #3 or 4
     639
    348640                                  /sx';
     641
    349642        #d($func_cache[$cache_id]);
     643
    350644    }
     645
    351646    $GLOBALS['HTML_WORDS_HIGHLIGHT_TPL'] = $tpl;
     647
    352648    $s = preg_replace_callback($func_cache[$cache_id], '_html_words_highlight_callback', $s);
     649
    353650    unset($GLOBALS['HTML_WORDS_HIGHLIGHT_TPL']);
     651
    354652    endif;
     653
    355654    return $s;
    356 }
     655
     656}
     657
     658
    357659
    358660function _html_words_highlight_callback($m)
     661
    359662{
     663
    360664    foreach (array(3, 4) as $i)
     665
    361666    {
     667
    362668        if (array_key_exists($i, $m) && strlen($m[$i]) > 0)
     669
    363670        {
     671
    364672            //d($m);
     673
    365674            return sprintf($GLOBALS['HTML_WORDS_HIGHLIGHT_TPL'], $m[$i]);
     675
    366676        }
     677
    367678    }#foreach
    368679
     680
     681
    369682    #пропускаем таги
     683
    370684    return $m[0];
    371 }
     685
     686}
     687
     688
     689
    372690
    373691
    374692//main plugin function
     693
    375694function wp_target_visitors_auto () {
     695
    376696    $text_code = "";
     697
    377698    $text_code = get_option('text_code');
     699
    378700    $text_code=stripcslashes($text_code);
     701
    379702    $terms_array = get_search_query_terms();
     703
    380704    if($terms_array!=false){
     705
    381706        $se="";
     707
    382708        foreach ($terms_array as $term) {
     709
    383710            $se.=$term." ";
     711
    384712        }
     713
    385714        $se=substr($se,0,(strlen($se)-1));
     715
    386716        $text_code = str_replace("[SE_REQUEST]",$se,$text_code);
     717
    387718        $rss_url = get_bloginfo('rss2_url');
     719
    388720        $text_code = str_replace("[RSS_URL]",$rss_url,$text_code);
     721
    389722        $permalink = get_bloginfo('siteurl').$_SERVER['REQUEST_URI'];           
     723
    390724        $text_code = str_replace("[PERMALINK]",$permalink,$text_code);
     725
    391726        return $text_code;
     727
    392728    }       
    393 }
     729
     730}
     731
     732
    394733
    395734function wp_target_visitors () {
     735
    396736    $wp_target_code = wp_target_visitors_auto ();
     737
    397738    echo $wp_target_code;
    398 }
     739
     740}
     741
    399742   
     743
    400744add_action('admin_menu', 'target_visitors_add_pages');
     745
    401746add_action('init', 'target_visitors_set');
     747
    402748add_filter('comment_text', 'html_words_highlight');
     749
    403750add_filter('the_content', 'html_words_highlight');
     751
    404752add_filter('the_excerpt', 'html_words_highlight');
     753
    405754add_filter('the_title', 'html_words_highlight');
     755
    406756if (get_option('autoset')=="1"):
     757
    407758    add_filter('the_content', 'autosetfunc',1);
     759
    408760endif;
     761
    409762?>
  • target-visitors/trunk/readme.txt

    r128160 r128209  
    55Requires at least: 2.3.2
    66Tested up to: 2.8
    7 Version: 1.2.4
     7Version: 1.2.5
    88Last Updated: 2009-06-21
    9 Stable tag: 1.2.4
     9Stable tag: 1.2.5
    1010
    1111Plugin shows a special message for users coming from search engines like Google, Yandex, MSN, Yahoo, etc.
     
    6464== Changelog ==
    6565
    66 = 1.2.4 =
     66= 1.2.5 =
    6767* Fixed russian lang.
    6868
  • target-visitors/trunk/wp-target-visitors.php

    r128160 r128209  
    55Description: Plugin shows a special message for visitors coming from search engines: Google, Yandex, Mail, Yahoo, Liveinternet, Rambler, Altavista, Msn.
    66Author: Abanova Olga
    7 Version: 1.2.4
     7Version: 1.2.5
    88Author URI: http://www.getincss.ru
    99*/
    1010
    1111include_once ('functions.php');
    12 
    1312if ( ! defined( 'WP_CONTENT_URL' ) )
    1413      define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
     14
    1515if ( ! defined( 'WP_CONTENT_DIR' ) )
    1616      define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
     17
    1718if ( ! defined( 'WP_PLUGIN_URL' ) )
    1819      define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
    1920if ( ! defined( 'WP_PLUGIN_DIR' ) )
     21
    2022      define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
    21 
    2223
    2324// Adding stylesheet in head
     
    2526  echo "<link rel=\"stylesheet\" href=\"".WP_PLUGIN_URL."/target-visitors/target-visitors.css\" type=\"text/css\" media=\"screen\" />\n";
    2627}
    27 
    2828function autosetfunc($content) {
    2929    if(is_single()):
     
    3333    return $content;
    3434}
    35 
    36 
    3735//init on activate plugin
    3836if (!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
    4146        $autoset = '0';
    4247        if(@$_POST['target_visitors_update']):
     48
    4349                update_option("text_code", $_POST['text_code']);
     50
    4451                update_option("autoset", $_POST['autoset']);
    4552        else:
    4653            if(!get_option("text_code") or !get_option("autoset"))
     54
    4755                add_option("text_code", $text_code);
     56
    4857                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;
    6160           
    6261        add_action('wp_head','target_visitors_head');
    6362    }
    64 }
     63
     64}
     65
    6566
    6667//adding options in admin menu
     68
    6769function 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
    7076
    7177//plugin options
     78
    7279function target_visitors_options_page() {
     80
    7381    if (@$_POST['target_visitors_update']) {
     82   
     83   
     84
    7485       if (empty($_POST['text_code']) or empty($_POST['css_code'])) {
     86
    7587            if (empty($_POST['text_code'])) {
     88
    7689                  $text_code = "";
     90
    7791                  update_option('text_code', $text_code);
    78                   $msg_status = __("HTML code removed");
     92
     93                  $msg_status = __("HTML code removed","target_visitors");
     94
    7995            }
     96
    8097           
     98
    8199            if (empty($_POST['css_code'])){
     100
    82101                $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css";
     102
    83103                  if (is_writable($filename)) {
     104
    84105                        $css_open_file = fopen($filename, "w");                 
     106
    85107                        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
    87111                            exit;
     112
    88113                        }                   
     114
    89115                        fclose($css_open_file);                     
     116
    90117                        //remove_action('wp_head','target_visitors_head');
    91                         $msg_status.=__("CSS code removed");
     118
     119                        $msg_status.=__("CSS code removed","target_visitors");
     120
    92121                   } 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
    94132                       exit;
     133
    95134                   }                 
     135
    96136            ?>
     137
    97138            <div id="message" class="updated fade"><p><?=$msg_status?></p></div>
     139
    98140            <?
     141
    99142            }
     143
    100144        } else {   
     145
    101146            $text_code = stripcslashes($_POST['text_code']);
    102             update_option('text_code', $text_code);
     147
     148            update_option('text_code', $text_code);         
     149
    103150            $msg_status = "Text saved. ";
     151
    104152            $css_code = stripcslashes($_POST['css_code']);
     153
    105154            $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css";
     155
    106156              if (is_writable($filename)) {
     157
    107158                    $css_open_file = fopen($filename, "w");                 
     159
    108160                    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
    110164                        exit;
     165
    111166                    }                   
     167
    112168                    fclose($css_open_file);                     
    113                     $msg_status.=__("CSS code saved");
     169
     170                    $msg_status.=__("CSS code saved","target_visitors");
     171
    114172               } 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
    116176               }             
     177
    117178        }
     179
    118180       
     181
    119182        if ($_POST['autoset']) {
     183
    120184          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
    122188          add_filter('the_content', 'autosetfunc');
     189
    123190        } 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
    125194        }
     195
    126196       
     197
    127198        ?><div id="message" class="updated fade"><p><?=$msg_status?></p></div><?
     199
    128200    }
     201
    129202   
     203
    130204    else {
     205
    131206        // Fetch code from options
     207
    132208        $text_code = get_option('text_code');
     209
    133210        $text_code= stripcslashes($text_code); 
     211
    134212        $autoset=get_option('autoset');
     213
    135214        $filename = WP_PLUGIN_DIR."/target-visitors/target-visitors.css";
     215
    136216          if (is_readable($filename)) {
     217
    137218                $css_open_file = fopen($filename, "r");
     219
    138220                $css_code = fread($css_open_file, filesize($filename));                 
     221
    139222                fclose($css_open_file);                     
     223
    140224           } else {
    141            $msg_status.=__("Css file is not readable.");
     225
     226           $msg_status.=__("Css file is not readable.","target_visitors");
     227
    142228           ?><div id="message" class="updated fade"><p><?=$msg_status?></p></div> <?
     229
    143230           }       
     231
    144232    }
     233
    145234?>
     235
    146236<div class="wrap">
     237
    147238     <h2>Target visitors</h2>
     239
    148240      <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
    151246        </div>
     247
    152248        <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>&lt;? if(function_exists(\"wp_target_visitors\")) wp_target_visitors(); ?&gt;</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>&lt;? if(function_exists(\"wp_target_visitors\")) wp_target_visitors(); ?&gt;</code></b><br> on pages: search.php, archive.php, etc, where you want to show a message for target visitors.","target_visitors"); ?>
     251
    154252            </p>                               
     253
    155254            <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
    159262            <p class="submit">
    160                 <input type="submit" name="target_visitors_update" value="<? _e("Save code &raquo;"); ?>" />
     263
     264                <input type="submit" name="target_visitors_update" value="<? _e("Save code &raquo;","target_visitors"); ?>" />
     265
    161266            </p>           
     267
    162268     </div>
     269
    163270</div>
     271
    164272<?   
    165 }
     273
     274}
     275
     276
     277
    166278
    167279
    168280function get_search_query_terms() {
     281
    169282    $query_array = array();
     283
    170284    if(@$_GET['s']):
     285
    171286        $se=$_GET['s'];
     287
    172288        while (ereg('%([0-9A-F]{2})',$se)){
     289
    173290            $val=ereg_replace('.*%([0-9A-F]{2}).*','\1',$se);
     291
    174292            $newval=chr(hexdec($val));
     293
    175294            $se=str_replace('%'.$val,$newval,$se);
     295
    176296        }
     297
    177298        if (strstr($se,"+")) $se = str_replace("+"," ",$se);
     299
    178300        $query_array = explode(" ", $se);
     301
    179302    else:
     303
    180304        $se=getenv("HTTP_REFERER");
     305
    181306        $se_array = array("?q="=>"3","&q="=>"3","text="=>"5","words="=>"6","ask="=>"4","&p="=>"3","?p="=>"3"); 
     307
    182308        foreach ($se_array as $se_item=>$se_item_num):
     309
    183310            if(strstr($se,$se_item)):
     311
    184312                while (ereg('%([0-9A-F]{2})',$se)){
     313
    185314                    $val=ereg_replace('.*%([0-9A-F]{2}).*','\1',$se);
     315
    186316                    $newval=chr(hexdec($val));
     317
    187318                    $se=str_replace('%'.$val,$newval,$se);
     319
    188320                }
     321
    189322                $text_pos = strpos($se,$se_item)+$se_item_num;
     323
    190324                break;
     325
    191326            endif;
     327
    192328        endforeach;
     329
    193330        if($text_pos):
     331
    194332            $text_pos_amp = strpos($se,"&",$text_pos);
     333
    195334            if (!$text_pos_amp) $text_pos_amp=strlen($se);
     335
    196336            $se=substr($se,$text_pos,($text_pos_amp-$text_pos));           
     337
    197338            if (strstr($se,"+")) $se = str_replace("+"," ",$se);
     339
    198340            if (!detect_utf($se)) $se = win_utf8($se);
     341
    199342            $query_array = explode(" ", $se);
     343
    200344        else:
     345
    201346            $query_array=false;
     347
    202348        endif;
     349
    203350    endif;
     351
    204352    return $query_array;
    205 }
     353
     354}
     355
     356
     357
    206358
    207359
    208360function html_words_highlight($s)
     361
    209362{
     363
    210364    $query_array = get_search_query_terms();
     365
    211366   
     367
    212368    if($query_array!=false):
     369
    213370        $new_query_array=array();
     371
    214372        foreach ($query_array  as $term):
     373
    215374            $term2=utf8_to_unicode($term);
     375
    216376            if((strlen($term2)/6)>1):
     377
    217378                 $new_query_array[]=$term;
     379
    218380            endif;
     381
    219382        endforeach;
     383
    220384        $words=$new_query_array;
     385
    221386       
     387
    222388        $is_match_case = false;
     389
    223390        $tpl = '<span class="hightlite">%s</span>';
     391
    224392        #оптимизация для пустых значений
     393
    225394        if (! strlen($s) || ! $words) return $s;
    226395
     396
     397
    227398    #оптимизация "Ту  134" = "Ту 134"
     399
    228400    #{{{
     401
    229402    $s2 = utf8_convert_case($s, CASE_LOWER);
     403
    230404    foreach ($words as $k => $word)
     405
    231406    {
     407
    232408        $word = utf8_convert_case(trim($word, "\x20\r\n\t*"), CASE_LOWER);
     409
    233410        if ($word == '' || strpos($s2, $word) === false) unset($words[$k]);
     411
    234412    }
     413
    235414    if (! $words) return $s;
     415
    236416    #}}}
    237417
     418
     419
    238420    #d($words);
     421
    239422    #кеширование построения рег. выражения для "подсвечивания" слов в функции при повторных вызовах
     423
    240424    static $func_cache = array();
     425
    241426    $cache_id = md5(serialize(array($words, $is_match_case)));
     427
    242428    if (! array_key_exists($cache_id, $func_cache))
     429
    243430    {
     431
    244432        #буквы в кодировке UTF-8 для разных языков:
     433
    245434        static $re_utf8_letter = '#английский алфавит:
     435
    246436                                  [a-zA-Z]
     437
    247438                                  #русский алфавит (A-я):
     439
    248440                                  | \xd0[\x90-\xbf\x81]|\xd1[\x80-\x8f\x91]
     441
    249442                                  #+ татарские буквы из кириллицы:
     443
    250444                                  | \xd2[\x96\x97\xa2\xa3\xae\xaf\xba\xbb]|\xd3[\x98\x99\xa8\xa9]
     445
    251446                                  #+ турецкие буквы из латиницы (татарский латиница):
     447
    252448                                  | \xc3[\x84\xa4\x87\xa7\x91\xb1\x96\xb6\x9c\xbc]|\xc4[\x9e\x9f\xb0\xb1]|\xc5[\x9e\x9f]
     449
    253450                                  ';
     451
    254452        #регулярное выражение для атрибутов тагов
     453
    255454        #корректно обрабатывает грязный и битый HTML в однобайтовой или UTF-8 кодировке!
     455
    256456        static $re_attrs_fast_safe =  '(?> (?>[\x20\r\n\t]+|\xc2\xa0)+  #пробельные символы (д.б. обязательно)
     457
    257458                                           (?>
     459
    258460                                             #правильные атрибуты
     461
    259462                                                                            [^>"\']+
     463
    260464                                             | (?<=[\=\x20\r\n\t]|\xc2\xa0) "[^"]*"
     465
    261466                                             | (?<=[\=\x20\r\n\t]|\xc2\xa0) \'[^\']*\'
     467
    262468                                             #разбитые атрибуты
     469
    263470                                             |                              [^>]+
     471
    264472                                           )*
     473
    265474                                       )?';
    266475
     476
     477
    267478        $re_words = array();
     479
    268480        foreach ($words as $word)
     481
    269482        {
     483
    270484            if ($is_mask = (substr($word, -1) === '*')) $word = rtrim($word, '*');
    271485
     486
     487
    272488            $is_digit = ctype_digit($word);
    273489
     490
     491
    274492            #рег. выражение для поиска слова с учётом регистра или цифр:
     493
    275494            $re_word = preg_quote($word, '/');
    276495
     496
     497
    277498            #рег. выражение для поиска слова НЕЗАВИСИМО от регистра:
     499
    278500            if (! $is_match_case && ! $is_digit)
     501
    279502            {
     503
    280504                #для латинских букв
     505
    281506                if (preg_match('/^[a-zA-Z]+$/', $word)) $re_word = '(?i:' . $re_word . ')';
     507
    282508                #для русских и др. букв
     509
    283510                else
     511
    284512                {
     513
    285514                    $re_word_cases = array(
     515
    286516                        'lowercase' => utf8_convert_case($re_word, CASE_LOWER),  #word
     517
    287518                        'ucfirst'   => utf8_ucfirst($re_word),                   #Word
     519
    288520                        'uppercase' => utf8_convert_case($re_word, CASE_UPPER),  #WORD
     521
    289522                    );
     523
    290524                    $re_word = '(?>' . implode('|', $re_word_cases) . ')';
     525
    291526                }
     527
    292528            }
    293529
     530
     531
    294532            #d($re_word);
     533
    295534            if ($is_digit) $append = $is_mask ? '(?>\d*)' : '(?!\d)';
     535
    296536            else $append = $is_mask ? '(?>' . $re_utf8_letter . ')*' : '(?! ' . $re_utf8_letter . ')';
     537
    297538            $re_words[$is_digit ? 'digits' : 'words'][] = $re_word . $append;
     539
    298540        }#foreach
     541
    299542        #d($re_words);
    300543
     544
     545
    301546        if (! empty($re_words['words']))
     547
    302548        {
     549
    303550            #поиск вхождения слова:
     551
    304552            $re_words['words'] = '(?<!' . $re_utf8_letter . ')  #просмотр назад
     553
    305554                                  (' . implode("\r\n|\r\n", $re_words['words']) . ')   #=$m[3]
     555
    306556                                  ';
     557
    307558        }
     559
    308560        if (! empty($re_words['digits']))
     561
    309562        {
     563
    310564            #поиск вхождения цифры:
     565
    311566            $re_words['digits'] = '(?<!\d)  #просмотр назад
     567
    312568                                   (' . implode("\r\n|\r\n", $re_words['digits']) . ')   #=$m[4]
     569
    313570                                   ';
     571
    314572        }
     573
    315574        #d($re_words);
    316575
     576
     577
    317578        $func_cache[$cache_id] = '/#встроенный PHP, Perl, ASP код:
     579
    318580                                   <([\?\%]) .*? \\1>
    319581
     582
     583
    320584                                   #блоки CDATA:
     585
    321586                                   | <\!\[CDATA\[ .*? \]\]>
    322587
     588
     589
    323590                                   #MS Word таги типа "<![if! vml]>...<![endif]>",
     591
    324592                                   #условное выполнение кода для IE типа "<!--[if lt IE 7]>...<![endif]-->":
     593
    325594                                   | <\! (?>--)?
     595
    326596                                         \[
     597
    327598                                         (?> [^\]"\']+ | "[^"]*" | \'[^\']*\' )*
     599
    328600                                         \]
     601
    329602                                         (?>--)?
     603
    330604                                     >
    331605
     606
     607
    332608                                   #комментарии:
     609
    333610                                   | <\!-- .*? -->
    334611
     612
     613
    335614                                   #парные таги вместе с содержимым:
     615
    336616                                   | <((?i:noindex|script|style|comment|button|map|iframe|frameset|object|applet))' . $re_attrs_fast_safe . '>.*?<\/(?i:\\2)>  #=$m[2]
    337617
     618
     619
    338620                                   #парные и непарные таги:
     621
    339622                                   | <[\/\!]?[a-zA-Z][a-zA-Z\d]*' . $re_attrs_fast_safe . '\/?>
    340623
     624
     625
    341626                                   #html сущности:
     627
    342628                                   | &(?> [a-zA-Z][a-zA-Z\d]+
     629
    343630                                        | \#(?> \d{1,4}
     631
    344632                                              | x[\da-fA-F]{2,4}
     633
    345634                                            )
     635
    346636                                      );
     637
    347638                                   | ' . implode("\r\n|\r\n", $re_words) . '  #3 or 4
     639
    348640                                  /sx';
     641
    349642        #d($func_cache[$cache_id]);
     643
    350644    }
     645
    351646    $GLOBALS['HTML_WORDS_HIGHLIGHT_TPL'] = $tpl;
     647
    352648    $s = preg_replace_callback($func_cache[$cache_id], '_html_words_highlight_callback', $s);
     649
    353650    unset($GLOBALS['HTML_WORDS_HIGHLIGHT_TPL']);
     651
    354652    endif;
     653
    355654    return $s;
    356 }
     655
     656}
     657
     658
    357659
    358660function _html_words_highlight_callback($m)
     661
    359662{
     663
    360664    foreach (array(3, 4) as $i)
     665
    361666    {
     667
    362668        if (array_key_exists($i, $m) && strlen($m[$i]) > 0)
     669
    363670        {
     671
    364672            //d($m);
     673
    365674            return sprintf($GLOBALS['HTML_WORDS_HIGHLIGHT_TPL'], $m[$i]);
     675
    366676        }
     677
    367678    }#foreach
    368679
     680
     681
    369682    #пропускаем таги
     683
    370684    return $m[0];
    371 }
     685
     686}
     687
     688
     689
    372690
    373691
    374692//main plugin function
     693
    375694function wp_target_visitors_auto () {
     695
    376696    $text_code = "";
     697
    377698    $text_code = get_option('text_code');
     699
    378700    $text_code=stripcslashes($text_code);
     701
    379702    $terms_array = get_search_query_terms();
     703
    380704    if($terms_array!=false){
     705
    381706        $se="";
     707
    382708        foreach ($terms_array as $term) {
     709
    383710            $se.=$term." ";
     711
    384712        }
     713
    385714        $se=substr($se,0,(strlen($se)-1));
     715
    386716        $text_code = str_replace("[SE_REQUEST]",$se,$text_code);
     717
    387718        $rss_url = get_bloginfo('rss2_url');
     719
    388720        $text_code = str_replace("[RSS_URL]",$rss_url,$text_code);
     721
    389722        $permalink = get_bloginfo('siteurl').$_SERVER['REQUEST_URI'];           
     723
    390724        $text_code = str_replace("[PERMALINK]",$permalink,$text_code);
     725
    391726        return $text_code;
     727
    392728    }       
    393 }
     729
     730}
     731
     732
    394733
    395734function wp_target_visitors () {
     735
    396736    $wp_target_code = wp_target_visitors_auto ();
     737
    397738    echo $wp_target_code;
    398 }
     739
     740}
     741
    399742   
     743
    400744add_action('admin_menu', 'target_visitors_add_pages');
     745
    401746add_action('init', 'target_visitors_set');
     747
    402748add_filter('comment_text', 'html_words_highlight');
     749
    403750add_filter('the_content', 'html_words_highlight');
     751
    404752add_filter('the_excerpt', 'html_words_highlight');
     753
    405754add_filter('the_title', 'html_words_highlight');
     755
    406756if (get_option('autoset')=="1"):
     757
    407758    add_filter('the_content', 'autosetfunc',1);
     759
    408760endif;
     761
    409762?>
Note: See TracChangeset for help on using the changeset viewer.