WordPress.org

Plugin Directory

Changeset 629514


Ignore:
Timestamp:
11/24/12 21:59:38 (17 months ago)
Author:
Strictly Software
Message:

New features including deeplinking to related tags, changes to scoring, more SEO functions

Location:
strictly-autotags/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • strictly-autotags/trunk/readme.txt

    r468526 r629514  
    55Tags: tags, autotag, taxonomy, smarttag 
    66Requires at least: 2.0.2                     
    7 Tested up to: 3.1.0 
    8 Stable tag: 2.7 
     7Tested up to: 3.4.2 
     8Stable tag: 2.8 
    99 
    1010Strictly AutoTags is a plugin that automatically adds the most relevant tags to posts. 
     
    3434The plugin is designed to do one thing and one thing only which is to add the most relevant and appropriate tags to your posts as well as discovering new 
    3535tags on the way with as little effort as possible. 
    36 As this plugin doesn't rely on HTTP requests to 3rd party tag sites to obtain lists of tags it should be quicker and will find new tags that haven't already 
    37 been added to external lists e.g someones name in a news story for example. 
    3836 
    3937Please note this plugin is designed for the English language and will not work with UTF-8 characters. 
     
    68664. Some people have complained that they have added words to the stop/noise word list which still get tagged and think the plugin is broken. This is not the case and the problem is usually that the user hasn't removed any new noise words from the systems saved post tags first before re-scanning. The noise words are only used in the auto discovery stage of the auto tagging and if tags have already been saved then the site will use them in it's relevancy check whether or not they have been marked as noise. Version 2.0 has a new option to aid the easy removal of noise words from the saved post tag list and this option should be run whenever new noise words are added. 
    6967 
    70 5. If you have any error messages installing the plugin then please try the following to rule out conflicts with other plugins 
    71     -Disable all other plugins and then try to re-activate the Strictly AutoTag plugin - some caching plugins can cause issues. 
    72     -If that worked, re-enable the plugins one by one to find the plugin causing the problem. Decide which plugin you want to use. 
    73     -If that didn't work check you have the latest version of the plugin software (from Wordpress) and the latest version of Wordpress installed 
    74     -Check you have Javascript and Cookies enabled. 
    75     -If you can code turn on the DEBUG constant and debug the code to find the problem otherwise contact me and offer me some money to fix the issue :) 
    76     -Please remember that you get what you pay for so you cannot expect 24 hour support for a free product. Please bear that in mind if you decide to email me. A donation button 
    77      is on my site and in the plugin admin page. 
    78     -If you must email me and haven't chosen to donate even the smallest amount of money please read this >> http://blog.strictly-software.com/2011/10/naming-and-shaming-of-programming.html 
    79  
    8068== Changelog == 
    8169 
    8270= 1.1 = 
    83 * Changed internal members from private to protected. 
    84 * Fixed bug in which an empty post returned an unitialised array. 
    85 * Split up the main AutoTag method so that the 3 AutoDiscovery tests are in their own methods. 
    86 * Put compatibility functions into their own include file. 
    87 * Changed comments to phpdoc format. 
     71* Changed internal members from private to protected 
     72* Fixed bug in which an empty post returned an unitialised array 
     73* Split up the main AutoTag method so that the 3 AutoDiscovery tests are in their own methods 
     74* Put compatibility functions into their own include file 
     75* Changed comments to phpdoc format 
    8876 
    8977= 1.2 = 
    90 * Added Admin page description text into language specific text handler. 
    91 * Added continents and major regions into the MatchCountries method. 
    92 * Added noise word removal before name matching in the MatchNames method. 
    93 * strip all HTML tags from article content before parsing. 
    94 * updated regular expression that decapitalises words next to periods to only affect single capitalised words. 
     78* Added Admin page description text into language specific text handler 
     79* Added continents and major regions into the MatchCountries method 
     80* Added noise word removal before name matching in the MatchNames method 
     81* strip all HTML tags from article content before parsing 
     82* updated regular expression that decapitalises words next to periods to only affect single capitalised words 
    9583 
    9684= 1.3 = 
    97 * Added TrustTitle method to check whether it can be used to auto discover new tags or not. 
    98 * Removed all HTML entities before checking content. 
    99 * Added extra safety check to term parser to handle previosuly entered bad terms. 
    100 * Added IsNoiseWord function in to check for capitalised noise words. 
    101 * Changed regular expressions to remove all non word characters instead of some punctuation. 
     85* Added TrustTitle method to check whether it can be used to auto discover new tags or not 
     86* Removed all HTML entities before checking content 
     87* Added extra safety check to term parser to handle previosuly entered bad terms 
     88* Added IsNoiseWord function in to check for capitalised noise words 
     89* Changed regular expressions to remove all non word characters instead of some punctuation 
    10290 
    10391= 1.4 = 
    104 * Added new config option Ignore Percentage which sets the percentage of content when capitalised to ignore during auto discovery. 
    105 * Added new config option Noise Words which allows user to set the list of noise words to ignore during auto discovery. 
    106 * Added new config option Nested Tags which sets how multiple occurring nested tags such as New York, New York City, New York City Fire Department are handled. 
    107 * changed regular expression that matches names to match any number of words. 
    108 * Added new functions IsNoiseWord, CountCapitals, StripNonWords, ValidContent, SearchContent to strictlyautotags.class.php. 
    109 * Added new function IsNothing to strictlyautotagfuncs.php. 
    110 * Removed unneccessary rsort call. 
    111 * Changed the coding for merging the stored tags and newly discovered ones. 
     92* Added new config option Ignore Percentage which sets the percentage of content when capitalised to ignore during auto discovery 
     93* Added new config option Noise Words which allows user to set the list of noise words to ignore during auto discovery 
     94* Added new config option Nested Tags which sets how multiple occurring nested tags such as New York, New York City, New York City Fire Department are handled 
     95* changed regular expression that matches names to match any number of words 
     96* Added new functions IsNoiseWord, CountCapitals, StripNonWords, ValidContent, SearchContent to strictlyautotags.class.php 
     97* Added new function IsNothing to strictlyautotagfuncs.php 
     98* Removed unneccessary rsort call 
     99* Changed the coding for merging the stored tags and newly discovered ones 
    112100 
    113101= 1.5 = 
    114 * Added IsRomanNumeral function to skip values identified as Aconyms that are Roman Numerals. 
    115 * Modifed a few regular expressions using /u which cause errors in cerain cases. 
    116 * Added some error handling on some preg_match statements to prevent errors where unknowable tags or patterns cause issues. 
    117 * Updated the ShowDebug statement in the function library to handle arrays. 
     102* Added IsRomanNumeral function to skip values identified as Aconyms that are Roman Numerals 
     103* Modifed a few regular expressions using /u which cause errors in cerain cases 
     104* Added some error handling on some preg_match statements to prevent errors where unknowable tags or patterns cause issues 
     105* Updated the ShowDebug statement in the function library to handle arrays 
    118106 
    119107= 1.6 = 
    120 * Modified MatchNames method so that noise words are not removed from the auto discovery text before hand in one go but instead from each match. This prevent two seperate tags from being added together when they shouldn't have been due to a noise word separating the two. 
    121 * Updated the SearchContent method so that the noise words are removed before matching. 
    122 * Updated FormatContent so newlines are replaced with periods to reduce false combinations. 
    123 * Added a period between the title and content when creating initial search strings. 
     108* Modified MatchNames method so that noise words are not removed from the auto discover text before hand in one go but from each match instead. This prevent two seperate tags from being added together when they shouldn't have been due to a noise word separating the two. 
     109* Updated the SearchContent method so that the noise words are removed before matching 
     110* Updated FormatContent so newlines are replaced with periods to reduce false combinations 
     111* Added a period between the title and content when creating initial search strings 
    124112 
    125113= 1.7 = 
    126 * Added option to re-tag all existing posts or just those currently without tags. 
     114* Added option to re-tag all existing posts or just those currently without tags 
    127115* Modified the MatchNames function so that noise words are not removed from potential matches as this can make too many tags nonsensical. 
    128116 
    129117= 1.8 = 
    130 * Removed my own FormatRegEx method and replaced it's usage with preg_quote. 
    131 * Removed usage of the non standard add_actions and replaced it's usage with multiple add_action calls. 
    132 * Added some major cities to the MatchCountries method. 
    133 * Added nonces to admin page to improve security. 
    134 * Added esc_attr to HTML input values. 
     118* Removed my own FormatRegEx method and replaced it's usage with preg_quote 
     119* Removed usage of the non standard add_actions and replaced it's usage with multiple add_action calls 
     120* Added some major cities to the MatchCountries method 
     121* Added nonces to admin page to improve security 
     122* Added esc_attr to HTML input values 
    135123 
    136124= 1.9 = 
    137 * Added new admin option which allows users to remove under used tags and keep their saved tag list to a manageable size. 
    138 * Ability to specify how many articles a tag has to belong to when being cleaned. 
    139 * Added extra help text for noise word list to remind people that when they add noise words they should remove them from the saved post tags as well. 
     125* Added new admin option which allows users to remove under used tags and keep their saved tag list to a manageable size 
     126* Ability to specify how many articles a tag has to belong to when being cleaned 
     127* Added extra help text for noise word list to remind people that when they add noise words they should remove them from the saved post tags as well 
    140128 
    141129= 2.0 = 
    142 * Added new checkbox option to admin config page called "Remove Saved Noise Tags" which on saving will remove any noise words in the list that are currently saved as post tags. This should help the problem where people have thought the system wasn't working due to noise words being matched. 
    143 * Changed the format of the admin save page to make it look nicer. 
     130* Added new checkbox option to admin config page called "Remove Saved Noise Tags" which on saving will remove any noise words in the list 
     131that are currently saved as post tags. This should help the problem where people have thought the system wasn't working due to noise words being matched. 
     132* Changed the format of the admin save page to make it look nicer 
    144133 
    145134= 2.1 = 
    146135* Fixed issue with noise word validator in the admin area so that it handles apostrophes, numbers and dashes. 
    147 * Updated the text on the admin page to remind people that this plugin only works with English characters e.g A-Z. 
     136* Updated the text on the admin page to remind people that this plugin only works with English characters e.g A-Z 
    148137 
    149138= 2.2 = 
    150 * Added new "Rank Important Content" option which ranks matches inside certain HTML tags as more important. 
    151 * Added new AUTOTAG_LONG option to increase accuracy so that for content such as New York City Fire Department only an exact match is allowed rather than partials such as New York or New York City. 
    152 * Removed the RemoveNoiseWords function call from SearchContent and instead added a check for IsNoiseWord before saving tags. 
    153 * Added the RemoveNoiseWords function call to the main AutoTag method to remove noise words from the content used for new tag discovery. 
    154 * Updated the SearchContent method to increment hitcounts for previously matched tags. 
    155 * Fixed bug with noise word regular expression that was caused by using preg_quote which was adding a slash in front of the pipe delimiters. 
     139* Added new "Rank Important Content" option which ranks matches inside certain HTML tags as more important 
     140* Added new AUTOTAG_LONG option to increase accuracy so that for content such as New York City Fire Department only an exact match is allowed rather than partials such as New York or New York City 
     141* Removed the RemoveNoiseWords function call from SearchContent and instead added a check for IsNoiseWord before saving tags 
     142* Added the RemoveNoiseWords function call to the main AutoTag method to remove noise words from the content used for new tag discovery 
     143* Updated the SearchContent method to increment hitcounts for previously matched tags 
     144* Fixed bug with noise word regular expression that was caused by using preg_quote which was adding a slash in front of the pipe delimiters 
    156145 
    157146= 2.3 = 
    158 * Added question mark to the regular expression that matches names and looks for full tag matches. 
    159 * Added uninstall option. 
    160 * Added counter to show how many tags the plugin has saved since upgrade / installation. 
    161 * Added support Strictly-Software.com links to help users support the plugin more easily. 
    162 * Added date of installation / upgrade. 
    163 * Added register_activation_hook and register_deactivation_hook and the StrictlyAutoTagControl static class. 
     147* Added question mark to the regular expression that matches names and looks for full tag matches 
     148* Added uninstall option 
     149* Added counter to show how many tags the plugin has saved since upgrade / installation 
     150* Added support strictly links to help users support the plugin more easily 
     151* Added date of installation / upgrade 
     152* Added register_activation_hook and register_deactivation_hook and the StrictlyAutoTagControl static class 
    164153 
    165154= 2.4 = 
    166 * Added new "Max Tag Words" option which specifies the maximum number of words a tag can have to help prevent long capitalised sentences getting matched. 
    167 * Added new "Bold Tagged Words" option to wrap tagged words in strong tags to aid SEO. 
    168 * Modified code in the SearchContent method to handle the new Max Tag Words setting. 
    169 * Added a few more default locations to the the MatchCountries function including Palestine, Tel Aviv and Belfast. 
     155* Added new "Max Tag Words" option which specifies the maximum number of words a tag can have to help prevent long capitalised sentences getting matched 
     156* Added new "Bold Tagged Words" option to wrap tagged words in strong tags to aid SEO  
     157* Modified code in the SearchContent method to handle the new Max Tag Words setting 
     158* Added a few more default locations to the the MatchCountries function including Palestine, Tel Aviv and Belfast 
    170159 
    171160= 2.5 = 
    172 * Added new "Case Sensitive" Noise Word list so that words or phrases that should only be ignored if the exact case matches are handled e.g "it" is a noise word "IT" is an acronym. 
    173 * Fixed bug that prevented phrases from being added to the noise word list. 
     161* Added new "Case Sensitive" Noise Word list so that words or phrases that should only be ignored if the exact case matches are handled e.g it is a noise word IT is an acronym 
     162* Fixed bug that prevented phrases from being added to the noise word list 
    174163* Updated Bold function so only exact matches of the tag are wrapped in bold tags. This is to prevent incorrect case matches of a tag from being bolded. 
    175  
    176164 
    177165= 2.6 = 
     
    181169 
    182170= 2.7 = 
     171 
    183172* Removed the sponsorship message as per the issue outlined in http://gregsplugins.com/lib/2011/11/26/automattic-bullies/ 
     173 
     174= 2.8 = 
     175* Added new SEO deeplinking feature to link tags to their relevant tag page 
     176* New options to only deeplink a tag with a certain number of related articles 
     177* Option to set how many tags are deeplinked within a post. 
     178* Added new re-bold and re-deeplink posts function for SEO purposes 
     179* Added the ability to tag custom posts 
     180 
  • strictly-autotags/trunk/strictlyautotagfuncs.php

    r468526 r629514  
    33Compatibility functions for the strictlyautotags.class.php plugin  
    44*/ 
     5 
     6//error_reporting(E_ERROR); 
    57 
    68// set up constants used by the AutoTag method 
     
    3234         
    3335        // put your IP here 
    34         if($ip == "111.11.11.1"){ 
     36        if($ip == "81.110.25.86"){ 
    3537            return true; 
    3638        }else{ 
  • strictly-autotags/trunk/strictlyautotags.class.php

    r468533 r629514  
    33/** 
    44 * Plugin Name: Strictly Auto Tags 
    5  * Version: 2.7 
     5 * Version: 2.8 
    66 * Plugin URI: http://www.strictly-software.com/plugins/strictly-auto-tags/ 
    77 * Description: This plugin automatically detects tags to place against posts using existing tags as well as a simple formula that detects common tag formats such as Acronyms, names and countries. Whereas other smart tag plugins only detect a single occurance of a tag within a post this plugin will search for the most used tags within the content so that only the most relevant tags get added. 
     
    2626    * @var string 
    2727    */ 
    28     protected $version = "2.7"; 
     28    protected $version = "2.8"; 
    2929 
    3030    /** 
     
    168168    protected $boldtaggedwords; 
    169169 
     170 
     171    /** 
     172    * Whether or not to deeplink tags found in the article by linking them to the relevant tag pages 
     173    * 
     174    * @access protected 
     175    * @var bool 
     176    */ 
     177    protected $taglinks; 
     178 
     179    /** 
     180    * Max no of posts a tag must have to deeplink it within the post if enabled 
     181    * 
     182    * @access protected 
     183    * @var int 
     184    */ 
     185    protected $minpoststotaglink; 
     186 
     187    /** 
     188    * Max no of tags in a post to link 
     189    * 
     190    * @access protected 
     191    * @var int 
     192    */ 
     193    protected $maxtagstolink; 
     194 
     195    /** 
     196    * The array holding all tags that have already have the specified amount of tags for deeplinking 
     197    * 
     198    * @access protected 
     199    * @var int 
     200    */ 
     201    protected $deeplinkarray; 
     202 
     203    /** 
     204    * The title for any deeplinks including the placeholder for the tag 
     205    * 
     206    * @access protected 
     207    * @var int 
     208    */ 
     209    protected $deeplinktitle; 
     210 
     211 
     212    /** 
     213    * Whether the post we are looking at has had tags added to it manually already and if any have been bolded/linked 
     214    * 
     215    * @access protected 
     216    * @var bool 
     217    * 
     218    */ 
     219    protected $already_strictly_tagged_and_linked; 
     220 
     221    /** 
     222    * Whether we should always remove any deeplinks or bolded tags when re-saving so that removed tags are de-linked and de-bolded and we re-do it 
     223    * 
     224    * @access protected 
     225    * @var bool 
     226    * 
     227    */ 
     228    protected $remove_strictly_tags_and_links; 
     229 
     230 
     231    /** 
     232    * Whether we should not bother AutoTagging any posts that already have tags 
     233    * 
     234    * @access protected 
     235    * @var bool 
     236    * 
     237    */ 
     238    protected $skip_tagged_posts; 
     239     
    170240    public function __construct(){ 
    171241 
     
    176246        $this->GetOptions(); 
    177247 
     248        ShowDebugAutoTag("do we deeplink = " . intval($this->taglinks)); 
     249 
     250 
    178251        // create some regular expressions required by the parser 
    179252 
     
    201274         
    202275        // set a function to run whenever posts are saved that will call our AutoTag function 
    203         add_action('save_post'              , array(&$this, 'SaveAutoTags')); 
    204         add_action('publish_post'           , array(&$this, 'SaveAutoTags')); 
    205         add_action('post_syndicated_item'   , array(&$this, 'SaveAutoTags')); 
     276        add_action('save_post'              , array(&$this, 'SaveAutoTags'),1); 
     277        //add_action('publish_post'         , array(&$this, 'SaveAutoTags'),1); 
     278        //add_action('post_syndicated_item' , array(&$this, 'SaveAutoTags'),1); 
    206279 
    207280 
     
    226299            return false; 
    227300        } 
    228          
     301 
     302        // if we skip posts with tags already then leave now 
     303        if ( get_the_tags($object->ID) != false) { 
     304 
     305            ShowDebugAutoTag("this post has tags already do we skip it skip_tagged_posts = " . intval($this->skip_tagged_posts)); 
     306 
     307            if($this->skip_tagged_posts){ 
     308 
     309                ShowDebugAutoTag("We ignore posts already with tags"); 
     310 
     311                return false; 
     312            } 
     313 
     314        } 
     315         
     316        // have we already got tags against this post and if so do they contain strictly links and bold tags 
     317         
     318        // default content 
     319        $newcontent = $object->post_content; 
     320 
     321        ShowDebugAutoTag("Do we need to clean any Strictly Goodness?"); 
     322 
     323        $newcontent = $this->CheckAndCleanTags( $newcontent ); 
     324 
     325        ShowDebugAutoTag("do we deeplink = " . intval($this->taglinks)); 
     326 
     327        // if we are deep linking we only deep link on existing tags with the appropriate count 
     328        if($this->taglinks){ 
     329 
     330            ShowDebugAutoTag("We are deep linking for tags that already have " . $this->minpoststotaglink . " posts associaed with them"); 
     331 
     332            $sql = $wpdb->prepare("SELECT   name,slug 
     333                                    FROM    {$wpdb->terms} AS a 
     334                                    JOIN    {$wpdb->term_taxonomy} AS c ON a.term_id = c.term_id                 
     335                                    WHERE ( 
     336                                            c.taxonomy = 'post_tag'                                          
     337                                            AND  c.count >= %d 
     338                                        );",$this->minpoststotaglink); 
     339 
     340            // AND slug in('ron-paul','cia','fbi','newt-gingrich') 
     341 
     342            ShowDebugAutoTag($sql); 
     343 
     344            $this->deeplinkarray = $wpdb->get_results($sql);     
     345 
     346             
     347            ShowDebugAutoTag("there are " . count($this->deeplinkarray) . " tags with " .$this->minpoststotaglink . " or more posts against them"); 
     348 
     349        } 
     350         
     351 
     352        ShowDebugAutoTag("now auto tag"); 
     353 
     354        // get the relevant tags for the post 
    229355        $posttags = $this->AutoTag( $object ); 
    230356 
    231         // add tags to post 
     357         
    232358        // Append tags if tags to add 
    233359        if ( count($posttags) > 0) { 
     
    238364            ShowDebugAutoTag($posttags); 
    239365 
    240             if($this->boldtaggedwords){ 
    241  
    242                 ShowDebugAutoTag("call bold tags"); 
    243  
    244              
    245                 // help SEO by bolding our tags 
    246                 $newcontent = $this->AutoBold($object->post_content,$posttags); 
    247                  
    248  
    249                 ShowDebugAutoTag("our new content is === " . $newcontent); 
    250  
    251                 $sql = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = %s WHERE id = %d;", $newcontent,$object->ID); 
    252  
    253                 ShowDebugAutoTag("SQL is $sql"); 
    254  
    255                 // resave content 
    256                 // from what I read all params should be unsanitized so that wordpress can run a prepare itself 
    257                 $r = $wpdb->update( 
    258                   'posts', 
    259                   array( 'post_content' => $newcontent ), 
    260                   array( 'id' => $object->ID ) 
    261                 ); 
    262  
    263                 ShowDebugAutoTag("should have been updated rows = " . $r); 
    264  
    265  
    266                 $r = $wpdb->query($sql); 
    267                  
    268                 ShowDebugAutoTag("should have been updated rows = " . $r); 
    269  
    270              
    271  
    272             } 
    273              
     366            if ( count($posttags) > 0) { 
     367 
     368                ShowDebugAutoTag("do we bold tags? == " . intval($this->boldtaggedwords) . " or auto link tags = " . intval($this->taglinks)); 
     369                 
     370                ShowDebugAutoTag($posttags); 
     371 
     372                if($this->boldtaggedwords || $this->taglinks){ 
     373 
     374                    ShowDebugAutoTag("call bold or deeplink tags"); 
     375 
     376                    if($this->boldtaggedwords){ 
     377                        // help SEO by bolding our tags 
     378                        $newcontent = $this->AutoBold($newcontent,$posttags); 
     379                    } 
     380                     
     381                    ShowDebugAutoTag("auto link tags = " . intval($this->taglinks)); 
     382                 
     383                     
     384                    if($this->taglinks){ 
     385                         
     386                        ShowDebugAutoTag("lets auto link"); 
     387 
     388                        // help SEO by deeplinking our tags 
     389                        $newcontent = $this->AutoLink($newcontent,$posttags); 
     390                    } 
     391 
     392 
     393                    ShowDebugAutoTag("our new content is === " . $newcontent); 
     394 
     395                    $sql = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = %s WHERE id = %d;", $newcontent,$object->ID); 
     396 
     397                    ShowDebugAutoTag("SQL is $sql"); 
     398 
     399                    /* 
     400                    // resave content 
     401                    // from what I read all params should be unsanitized so that wordpress can run a prepare itself 
     402                    $r = $wpdb->update( 
     403                      'posts', 
     404                      array( 'post_content' => $newcontent ), 
     405                      array( 'id' => $object->ID ) 
     406                    ); 
     407 
     408                    ShowDebugAutoTag("should have been updated rows = " . $r); 
     409                    */ 
     410 
     411                    $r = $wpdb->query($sql); 
     412                     
     413                    ShowDebugAutoTag("should have been updated rows = " . $r); 
     414                 
     415 
     416                } 
     417            } 
     418 
    274419            // Add tags to posts 
    275420            wp_set_object_terms( $object->ID, $posttags, 'post_tag', true ); 
     
    290435    } 
    291436 
    292     /** Reformats the main article by highlighting the tagged words 
     437    /** Checks for existing bolded or linked tags and remove them if settings say so 
     438    * 
     439    * @param string $content; 
     440    * @returns string; 
     441    */ 
     442    protected function CheckAndCleanTags($content){ 
     443 
     444        ShowDebugAutoTag("IN CheckAndCleanTags"); 
     445 
     446        $newcontent = $content; 
     447 
     448        ShowDebugAutoTag("we have " . strlen($newcontent) . " of content"); 
     449 
     450 
     451        if(preg_match("@<(strong|a) class=['\"]StrictlyAutoTag@i",$content)){            
     452                 
     453            ShowDebugAutoTag("The content has signs of Strictly sprinkled in it do we remove = " . intval($this->remove_strictly_tags_and_links)); 
     454 
     455            // if we re-bold/re-link the article even if tags have been added manually then remove our ones first 
     456            if($this->remove_strictly_tags_and_links) 
     457            { 
     458 
     459                ShowDebugAutoTag("Content does have StrictlyAutoTag classes on strong or A tags"); 
     460 
     461                // remove it all so we can link any new tags that have been added as well 
     462                $newcontent = $this->RemoveBoldAndLinks($newcontent); 
     463 
     464                // so we can re-tag it, re-bold and re-link it al 
     465                $this->already_strictly_tagged_and_linked = false; 
     466            } 
     467            else 
     468            { 
     469                ShowDebugAutoTag("This content has Strictly Auto Tags/Links and we keep them there"); 
     470 
     471                $this->already_strictly_tagged_and_linked = true; 
     472            } 
     473        }else{ 
     474 
     475            ShowDebugAutoTag("no tags saved against post"); 
     476 
     477            // so we can re-tag it, re-bold and re-link it all 
     478            $this->already_strictly_tagged_and_linked = false; 
     479             
     480        } 
     481 
     482        ShowDebugAutoTag("return " . strlen($newcontent) . " of content"); 
     483 
     484        return $newcontent; 
     485    } 
     486 
     487    /** Removes any existing bold or linked tags 
    293488    * 
    294489    * @param string $content; 
    295490    * @returns string  
    296491    */ 
     492    protected function RemoveBoldAndLinks($content){ 
     493 
     494        ShowDebugAutoTag("IN RemoveBoldAndLinks"); 
     495 
     496        // as we now put classes on the tags its easier to find and replace 
     497        set_time_limit(200); 
     498 
     499        ShowDebug("b4 replace len is " . strlen($content)); 
     500 
     501        $content = preg_replace("@(<strong class='StrictlyAutoTagBold'>)([\s\S]+?)(</strong>)@","$2",$content); 
     502 
     503        ShowDebugAutoTag("after first replace len is " . strlen($content)); 
     504 
     505        $content = preg_replace("@(<a class=\"StrictlyAutoTagAnchor\"[^>]+?>)([\s\S]+?)(</a>)@","$2",$content); 
     506 
     507        ShowDebug("after 2nd replace len is " . strlen($content)); 
     508 
     509        return $content; 
     510 
     511    } 
     512 
     513 
     514    /** Reformats the main article by highlighting the tagged words 
     515    * 
     516    * @param string $content; 
     517    * @returns string  
     518    */ 
    297519    protected function AutoBold($content,$tags){ 
    298520 
     
    310532            foreach($tags as $tag){ 
    311533 
    312  
    313                 ShowDebugAutoTag("bold all matches of $tag"); 
     534                 
    314535 
    315536                // instead of doing negative lookaheads and entering a world of doom match and then clean    
    316537                // easier to do a positive match than a negative especially with nested matches 
    317538 
     539                $regex = "@\b(" . preg_quote($tag) . ")\b@"; 
     540 
     541                ShowDebugAutoTag("regex is $regex"); 
     542 
    318543                // wrap tags in strong and keep the formatting e.g dont upper case if the tag is lowercase as it might be inside 
    319544                // an href or src which might screw it up 
    320                 $content = preg_replace("@\b(" . preg_quote($tag) . ")\b@","<strong>$1</strong>",$content); 
    321  
     545                $content = preg_replace($regex,"<strong class='StrictlyAutoTagBold'>$1</strong>",$content); 
     546 
     547                 
    322548 
    323549                // remove bold tags that have been put inside attributes e.g <a href="http://www.<strong>MSNBC</strong>.com">    
     
    326552                // for me to match first (by bolding) and then clean up by looping through attributes and stripping than trying 
    327553                // to do it all in one negative lookahead regex. I've tried tightening it up and extending the timeout. 
    328                 $content = preg_replace_callback("@(\w+)(=['\"][^'\"]*?)(<strong>)([\s\S]+?)(</strong>)([^'\"]*['\"][/> ])@", 
     554                $content = preg_replace_callback("@(\w+)(=['\"][^'\"]*?)(<strong class='StrictlyAutoTagBold'>)([\s\S]+?)(</strong>)([^'\"]*['\"][/> ])@", 
    329555                            create_function( 
    330                             '$matches',                  
    331                             '$res = preg_replace("@<\/?strong>@","",$matches[0] );                   
     556                            '$matches',          
     557                            '$res = preg_replace("@<strong class=\'StrictlyAutoTagBold\'>@","",$matches[0] );                
     558                            $res = preg_replace("@</?strong>@","",$res );                    
    332559                            return $res;') 
    333560                        ,$content); 
    334561                 
    335562                 
     563                 
     564 
    336565                // remove any tags that are now in strong that are also inside other "bold" tags 
    337                 $content = preg_replace("@(<(h[1-6]|strong|b|em|i|a)[^>]*>[^<]*?)(<strong>" .  preg_quote($tag) . "<\/strong>)(.*?<\/?\\2>)@i","$1{$tag}$4",$content); 
    338  
    339              
    340  
    341                 ShowDebugAutoTag("look at current bolded content == $content"); 
    342  
    343             } 
    344  
    345         } 
     566                $content = preg_replace("@(<(h[1-6]|strong|b|em|i|a)[^>]*>[^<]*?)(<strong class='StrictlyAutoTagBold'>" .  preg_quote($tag) . "<\/strong>)(.*?<\/?\\2>)@i","$1{$tag}$4",$content); 
     567 
     568                 
     569            } 
     570 
     571        } 
     572 
     573        ShowDebugAutoTag("look at how it would appear"); 
     574         
    346575 
    347576        ShowDebugAutoTag("return $content"); 
     
    350579 
    351580    } 
     581 
     582     
     583 
     584    /** Reformats the main article by highlighting the tagged words in <A> tags to deeplink to the relevant tag page 
     585    * 
     586    * @param string $content; 
     587    * @returns string  
     588    */ 
     589    protected function AutoLink($content,$tags){ 
     590 
     591        ShowDebugAutoTag("IN AutoLink"); 
     592 
     593        global $wp_rewrite; 
     594 
     595     
     596        ShowDebugAutoTag("look at deeplink array"); 
     597 
     598        ShowDebugAutoTag($this->deeplinkarray); 
     599 
     600        set_time_limit(200); 
     601 
     602        $no =  count($this->deeplinkarray); 
     603 
     604        ShowDebugAutoTag("IN AutoLink $content we have " .  $no . " to deeplink"); 
     605 
     606        if(!empty($content) && is_array($this->deeplinkarray) && $no>0){ 
     607 
     608            ShowDebugAutoTag("lets loop through our deep linked tags"); 
     609 
     610            // get tag permalink structure and remove trailing slash so it can be added on correcly if needs be 
     611            $taglink = rtrim($wp_rewrite->get_tag_permastruct(),'/'); 
     612 
     613            ShowDebugAutoTag("tag link permastruct is " . $taglink); 
     614 
     615            // store whether trailing slashes need to be added  
     616            $this->addtrailingslash = $wp_rewrite->use_trailing_slashes; 
     617 
     618            ShowDebugAutoTag("tag permalink structure is $taglink"); 
     619 
     620            // ensure the start of the tag rewrite url has a / as for some reason 3.0+ stopped adding it 
     621            if(!empty($taglink)){ 
     622                if(substr($taglink,0,1) != "/"){ 
     623                    $taglink = "/" .  $taglink; 
     624                } 
     625            } 
     626 
     627 
     628            // set tag placeholder           
     629            $tagplaceholder = ($this->addtrailingslash) ? $taglink ."/" : $taglink; 
     630            $siteurl    = untrailingslashit(get_option('siteurl')); 
     631 
     632            ShowDebugAutoTag("site url is $siteurl"); 
     633 
     634            //$tagurl = "<a href=\"##TAGURL##\" class=\"StrictlyAutoTagAnchor\" title=\"" . str_replace($this->deeplinktitle,"%tag%",$tag) . "\">$tag</a>";       
     635 
     636            ShowDebugAutoTag("loop through array and deeplink"); 
     637 
     638            $lasttag = $lastslug = ""; 
     639            //loop and bold unless they are already inside a bold tag 
     640            foreach($this->deeplinkarray as $tag){ 
     641 
     642                $lasttag = $tag->name; 
     643                $lastslug = $tag->slug; 
     644 
     645                ShowDebugAutoTag("tag = " . $tag->name . " and slug = " . $tag->slug); 
     646 
     647                // we skip any that are nested in tagged links already 
     648                $testreg = "@<a class=\"StrictlyAutoTagAnchor\"[^>]+?>[^<]*?" . preg_quote($tag->name) . "[^<]*?</a>@"; 
     649 
     650                if(preg_match($testreg,$content)){ 
     651 
     652                    ShowDebugAutoTag("ignore this tag " . $tag->name . " as its already within a linked tag regex was == " . $testreg); 
     653                         
     654                }else{ 
     655 
     656                    ShowDebugAutoTag("this tag " . $tag->name . " is NOT already within a linked tag"); 
     657 
     658                 
     659                    // handle old and new 
     660                    $actualtitle = preg_replace("@%tag%@i",$tag->name,$this->deeplinktitle); 
     661                    $actualtitle = preg_replace("@%post_tag%@i",$tag->name,$actualtitle); 
     662                    $actualurl   = $siteurl . preg_replace('@%tag%@i',$tag->slug,$taglink); 
     663                    $actualurl   = preg_replace('@%post_tag%@i',$tag->slug,$actualurl); 
     664 
     665 
     666                    //ShowDebugAutoTag("did we already bold = " . intval($this->boldtaggedwords)); 
     667 
     668                    // as this runs after auto bold if thats enabled i can just use those markers as replacements 
     669                    if($this->boldtaggedwords){ 
     670 
     671                         
     672                        $link = "<a class=\"StrictlyAutoTagAnchor\" href=\"" . $actualurl . "\" title=\"" . $actualtitle . "\" >" . $tag->name . "</a>"; 
     673 
     674 
     675                        $regex = "@<strong class='StrictlyAutoTagBold'>" . preg_quote($tag->name) . "<\/strong>@"; 
     676 
     677                        // wrap tags in anchors and keep the formatting e.g dont upper case if the tag is lowercase as it might be inside 
     678                        // an href or src which might screw it up 
     679                        $content = preg_replace($regex,$link,$content,$this->maxtagstolink); 
     680 
     681                    }else{ 
     682 
     683                        $origcontent = $content; 
     684 
     685                        // instead of doing negative lookaheads and entering a world of doom match and then clean    
     686                        // easier to do a positive match than a negative especially with nested matches 
     687                        $link = "<a class=\"StrictlyAutoTagAnchor\" href=\"" . $actualurl  . "\" title=\"" . $actualtitle . "\" >$1</a>"; 
     688 
     689                         
     690 
     691                        // wrap tags in anchors and keep the formatting e.g dont upper case if the tag is lowercase as it might be inside 
     692                        // an href or src which might screw it up 
     693                        $content = preg_replace("@\b(" . preg_quote($tag->name) . ")\b@",$link,$content,$this->maxtagstolink); 
     694 
     695 
     696                        // remove anchor tags that have been put inside attributes e.g <a href="http://www.<a href="http://www.mysite.com/tags/MNSBC">MSNBC</a>>MSNBC</a>.com">  
     697                        // this can be a bit of killer on large pieces of content so if its causing problems then turn deeplinking off 
     698                        // anything that has to do negative lookaheads can kill webservers (see my blog for details) but its a lot better 
     699                        // for me to match first (by linking) and then clean up by looping through attributes and stripping than trying 
     700                        // to do it all in one negative lookahead regex. I've tried tightening it up and extending the timeout. 
     701                        $content = preg_replace_callback("@(\w+)(=['\"][^'\"]*?)(<a class=\"StrictlyAutoTagAnchor\" [^>]+?>)([\s\S]+?)(</a>)([^'\"]*['\"][/> ])@", 
     702                                    create_function( 
     703                                    '$matches',                  
     704                                    '$res = preg_replace("@<a [^>]+?>[\s\S]+?</a>@","",$matches[0] ); 
     705                                    return $res;') 
     706                                ,$content); 
     707                         
     708                         
     709 
     710                        // remove any anchor tags that are now in other anchors 
     711                        $content = preg_replace("@(<(a)[^>]*>[^<]*?)(<a class=\"StrictlyAutoTagAnchor\"[^>]+?>" .  preg_quote($tag->name) . "<\/a>)(.*?<\/?\\2>)@i","$1{$tag->name}$4",$content); 
     712 
     713                    } 
     714 
     715                     
     716                } 
     717            } 
     718 
     719        } 
     720 
     721        ShowDebugAutoTag("return $content"); 
     722 
     723        return $content; 
     724 
     725    } 
     726     
    352727                 
    353728    /** 
     
    395770            $sql = sprintf("DELETE a,c 
    396771                            FROM    {$wpdb->terms} AS a 
    397                             LEFT JOIN {$wpdb->term_taxonomy} AS c ON a.term_id = c.term_id               
     772                            JOIN {$wpdb->term_taxonomy} AS c ON a.term_id = c.term_id                
    398773                            WHERE ( 
    399774                                    c.taxonomy = 'post_tag' 
     
    498873 
    499874     
    500  
    501      
    502     /** 
    503      * Updates existing posts with tags 
     875    /** 
     876     * Updates existing posts by adding in deeplinks and new bold tags 
    504877     * The $all_posts param specifies whether all posts are re-tagged or only those without tags 
    505878     * 
     
    507880     * @return int 
    508881     */ 
    509     protected function ReTagPosts( $all_posts=false ) { 
    510          
     882    protected function ReLinkAndTagPosts( $all_posts=false ) { 
     883 
     884 
     885        ShowDebugAutoTag("IN ReLinkAndTagPosts " . intval( $all_posts)); 
     886 
    511887        set_time_limit(0); 
    512888 
     
    518894        // we only return from the DB those posts that have no tags 
    519895 
     896        // handle custom post types by allowing everything that isnt a page, attachment or revision 
    520897        $sql = "SELECT id  
    521898                FROM {$wpdb->posts} 
    522                 WHERE post_password='' AND post_status='publish' AND post_type='post'  
     899                WHERE post_password='' AND post_status='publish' AND post_type NOT IN('page', 'attachment', 'revision')  
    523900                ORDER BY post_modified_gmt DESC;"; 
    524901 
     
    538915                return false; 
    539916            }        
    540              
    541  
     917 
     918             
     919             
     920            // have we already got tags against this post and if so do they contain strictly links and bold tags and if they do - do we need to remove them?     
     921 
     922            ShowDebugAutoTag("Do we need to clean any Strictly Goodness?"); 
     923 
     924            $newcontent = $this->CheckAndCleanTags( $object->post_content ); 
     925             
     926            // find tags for this post 
    542927            $posttags = $this->AutoTag( $object,  $all_posts ); 
     928 
     929 
     930            ShowDebugAutoTag("do we bold and deeplink"); 
     931 
     932            if($this->boldtaggedwords || $this->taglinks){               
     933 
     934                ShowDebugAutoTag("call bold or deeplink tags"); 
     935 
     936                if($this->boldtaggedwords && count($posttags) > 0){ 
     937 
     938                    ShowDebugAutoTag("Auto Bold this content"); 
     939 
     940                    // help SEO by bolding our tags 
     941                    $newcontent = $this->AutoBold($newcontent,$posttags); 
     942 
     943                } 
     944 
     945                if($this->taglinks && count($posttags) > 0){ 
     946 
     947                    ShowDebugAutoTag("Auto Link this content"); 
     948 
     949                    // help SEO by deeplinking our tags 
     950                    $newcontent = $this->AutoLink($newcontent,$posttags); 
     951 
     952                } 
     953 
     954                // now save the new deeplinked bolded content 
     955 
     956                ShowDebugAutoTag("our new content is === " . $newcontent); 
     957 
     958                $sql = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = %s WHERE id = %d;", $newcontent,$object->ID); 
     959 
     960                ShowDebugAutoTag("SQL is $sql"); 
     961 
     962                $r = $wpdb->query($sql); 
     963                     
     964                ShowDebugAutoTag("should have been updated rows = " . $r);               
     965             
     966            } 
     967 
     968            ShowDebugAutoTag("did we find new tags to save?"); 
    543969 
    544970            if($posttags !== false){ 
     
    571997        return $updated; 
    572998    } 
     999     
     1000    /** 
     1001     * Updates existing posts with tags 
     1002     * The $all_posts param specifies whether all posts are re-tagged or only those without tags 
     1003     * 
     1004     * @param bool  $all_posts 
     1005     * @return int 
     1006     */ 
     1007    protected function ReTagPosts( $all_posts=false ) { 
     1008         
     1009        set_time_limit(0); 
     1010 
     1011        global $wpdb; 
     1012 
     1013        $updated = 0; 
     1014 
     1015        // in future rewrite this with a branch so that if we are looking at posts with no tags then 
     1016        // we only return from the DB those posts that have no tags 
     1017 
     1018        $sql = "SELECT id  
     1019                FROM {$wpdb->posts} 
     1020                WHERE post_password='' AND post_status='publish' AND post_type NOT IN('page', 'attachment', 'revision')  
     1021                ORDER BY post_modified_gmt DESC;"; 
     1022 
     1023 
     1024        ShowDebugAutoTag($sql); 
     1025 
     1026        $posts = $wpdb->get_results($sql); 
     1027         
     1028        foreach($posts as $post){ 
     1029 
     1030            // definitley a better way to do this but would involve a major rewrite! 
     1031 
     1032            ShowDebugAutoTag("get post id " . $post->id); 
     1033 
     1034            $object = get_post($post->id); 
     1035            if ( $object == false || $object == null ) { 
     1036                return false; 
     1037            }        
     1038             
     1039 
     1040 
     1041            ShowDebugAutoTag("Do we need to clean any Strictly Goodness?"); 
     1042 
     1043            $newcontent = $this->CheckAndCleanTags( $object->post_content ); 
     1044             
     1045            // find tags for this post 
     1046            $posttags = $this->AutoTag( $object,  $all_posts ); 
     1047 
     1048 
     1049            ShowDebugAutoTag("do we bold and deeplink"); 
     1050 
     1051            if($this->boldtaggedwords || $this->taglinks){               
     1052 
     1053                ShowDebugAutoTag("call bold or deeplink tags"); 
     1054 
     1055                if($this->boldtaggedwords && count($posttags) > 0){ 
     1056 
     1057                    ShowDebugAutoTag("Auto Bold this content"); 
     1058 
     1059                    // help SEO by bolding our tags 
     1060                    $newcontent = $this->AutoBold($newcontent,$posttags); 
     1061 
     1062                } 
     1063 
     1064                if($this->taglinks && count($posttags) > 0){ 
     1065 
     1066                    ShowDebugAutoTag("Auto Link this content"); 
     1067 
     1068                    // help SEO by deeplinking our tags 
     1069                    $newcontent = $this->AutoLink($newcontent,$posttags); 
     1070 
     1071                } 
     1072 
     1073                // now save the new deeplinked bolded content 
     1074 
     1075                ShowDebugAutoTag("our new content is === " . $newcontent); 
     1076 
     1077                $sql = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = %s WHERE id = %d;", $newcontent,$object->ID); 
     1078 
     1079                ShowDebugAutoTag("SQL is $sql"); 
     1080 
     1081                $r = $wpdb->query($sql); 
     1082                     
     1083                ShowDebugAutoTag("should have been updated rows = " . $r);               
     1084             
     1085            } 
     1086 
     1087 
     1088            if($posttags !== false){ 
     1089             
     1090                $updated++; 
     1091                 
     1092                ShowDebugAutoTag("we have " .  count($posttags) . " tags to add to this post"); 
     1093 
     1094                // add tags to post 
     1095                // Append tags if tags to add 
     1096                if ( count($posttags) > 0) { 
     1097                     
     1098                    // Add tags to posts 
     1099                    wp_set_object_terms( $object->ID, $posttags, 'post_tag', true ); 
     1100                     
     1101                    // Clean cache 
     1102                    if ( 'page' == $object->post_type ) { 
     1103                        clean_page_cache($object->ID); 
     1104                    } else { 
     1105                        clean_post_cache($object->ID); 
     1106                    }            
     1107                } 
     1108            } 
     1109 
     1110            unset($object,$posttags); 
     1111        } 
     1112 
     1113        unset($posts);       
     1114 
     1115        return $updated; 
     1116    } 
    5731117 
    5741118    /** 
     
    8291373 
    8301374        if(!$all_posts){ 
     1375 
    8311376            // skip posts with tags already added 
    832             if ( get_the_tags($object->ID) != false) { 
    833                 return false; 
     1377            if ( get_the_tags($object->ID) != false) {               
     1378                 
     1379                if(($this->boldtaggedwords || $this->taglinks) && $this->already_strictly_tagged_and_linked){ 
     1380                 
     1381                    ShowDebugAutoTag("No need to re tag as this is already tagged and linked"); 
     1382 
     1383                    return false; 
     1384                } 
    8341385            } 
    8351386        } 
     
    10161567 
    10171568                    if($match[1] == "h1"){ 
     1569                        $score = 900; 
     1570                    }elseif($match[1] == "h2"){ 
     1571                        $score = 650; 
     1572                    }elseif($match[1] == "h3"){ 
    10181573                        $score = 500; 
    1019                     }elseif($match[1] == "h2"){ 
    1020                         $score = 400; 
    1021                     }elseif($match[1] == "h3"){ 
     1574                    }elseif($match[1] == "h4"){ 
    10221575                        $score = 350; 
    1023                     }elseif($match[1] == "h4"){ 
    1024                         $score = 300; 
    10251576                    }elseif($match[1] == "h5"){ 
    1026                         $score = 275; 
     1577                        $score = 250; 
    10271578                    }elseif($match[1] == "h6"){ 
    1028                         $score = 250; 
     1579                        $score = 200; 
    10291580                    } 
    10301581 
     
    10511602                    $important_content = html_entity_decode(strip_tags($match[2])); 
    10521603 
    1053                     $this->SearchContent($important_content,$terms,$tagstack,200); 
     1604                    $this->SearchContent($important_content,$terms,$tagstack,100); 
    10541605                } 
    10551606 
     
    12921843        $options = get_option('strictlyautotags'); 
    12931844 
    1294          
     1845        ShowDebugAutoTag("IN GetOptions do we deeplink = " . intval($this->taglinks)); 
     1846 
    12951847        // if there are no saved options then use defaults 
    12961848        if ( !is_array($options) ) 
    12971849        { 
    12981850            // This array sets the default options for the plugin when it is first activated. 
    1299             $options = array('autodiscover'=>true, 'ranktitle'=>true, 'maxtags'=>4, 'ignorepercentage'=>50, 'noisewords'=>$this->defaultnoisewords, 'nestedtags'=>AUTOTAG_LONG, 'rankhtml'=>true, 'maxtagwords'=>3, 'boldtaggedwords' => false, 'noisewords_case_sensitive'=>$this->defaultnoisewords_case_sensitive); 
     1851            $options = array('autodiscover'=>true, 'ranktitle'=>true, 'maxtags'=>4, 'ignorepercentage'=>50, 'noisewords'=>$this->defaultnoisewords, 'nestedtags'=>AUTOTAG_LONG, 'rankhtml'=>true, 'maxtagwords'=>3, 'boldtaggedwords' => false, 'noisewords_case_sensitive'=>$this->defaultnoisewords_case_sensitive, 'taglinks'=>false, 'deeplinktitle'=>"View all articles about %post_tag% here", 'maxtagstolink'=>2, 'minpoststotaglink'=>4, 'removestrictlytagsandlinks'=>false, 'skiptaggedposts'=>false); 
     1852 
    13001853        }else{ 
    13011854 
     
    13291882            } 
    13301883 
    1331              
    1332              
     1884            ShowDebugAutoTag("IN GetOptions do we deeplink = " . intval($this->taglinks)); 
     1885 
     1886 
     1887            // paid for special options 
     1888            if(IsNothing($options['taglinks'])){ 
     1889 
     1890                ShowDebugAutoTag("options['taglinks'] is nothing set to false"); 
     1891 
     1892                $options['taglinks'] = false; 
     1893            } 
     1894 
     1895            ShowDebugAutoTag("IN GetOptions do we deeplink = " . intval($options['taglinks'])); 
     1896 
     1897            if(IsNothing($options['removestrictlytagsandlinks'])){ 
     1898 
     1899                ShowDebugAutoTag("options['removestrictlytagsandlinks'] is nothing set to false"); 
     1900 
     1901                $options['removestrictlytagsandlinks'] = false; 
     1902            } 
     1903             
     1904            if(IsNothing($options['skiptaggedposts'])){ 
     1905 
     1906                ShowDebugAutoTag("options['skiptaggedposts'] is nothing set to false"); 
     1907 
     1908                $options['skiptaggedposts'] = false; 
     1909            } 
     1910 
     1911             
     1912            if(IsNothing($options['deeplinktitle'])){ 
     1913                $options['deeplinktitle'] = "View all articles about %post_tag% here"; 
     1914            } 
     1915 
     1916            if(IsNothing($options['maxtagstolink'])){ 
     1917                $options['maxtagstolink'] = 2; 
     1918            } 
     1919             
     1920            if(IsNothing($options['minpoststotaglink'])){ 
     1921                $options['minpoststotaglink'] = 4; 
     1922            } 
     1923 
    13331924        } 
    13341925 
     
    13821973        $this->boldtaggedwords              = $options['boldtaggedwords']; 
    13831974 
     1975        ShowDebugAutoTag("IN GetOptions do we deeplink = " . intval($options['taglinks'])); 
     1976 
     1977 
     1978        $this->taglinks                     = $options['taglinks']; 
     1979 
     1980        ShowDebugAutoTag("IN GetOptions do we deeplink = " . intval($this->taglinks)); 
     1981 
     1982 
     1983        $this->deeplinktitle                = $options['deeplinktitle']; 
     1984 
     1985        $this->maxtagstolink                = $options['maxtagstolink']; 
     1986 
     1987        $this->minpoststotaglink            = $options['minpoststotaglink']; 
     1988 
     1989        $this->remove_strictly_tags_and_links= $options['removestrictlytagsandlinks']; 
     1990 
     1991        $this->skip_tagged_posts            = $options['skiptaggedposts']; 
     1992             
     1993 
     1994         
    13841995    } 
    13851996 
     
    13952006            die("You are not allowed to view this page"); 
    13962007        } 
     2008 
     2009        ShowDebugAutoTag("IN AdminOptions"); 
    13972010 
    13982011        // get saved options 
     
    14722085        } 
    14732086 
     2087        if ( $_POST['RelinkSubmit'] ) 
     2088        { 
     2089 
     2090            ShowDebugAutoTag("ReLink And ReTag Posts"); 
     2091 
     2092            // check nonce 
     2093            check_admin_referer("retag2","strictlyretagnonce"); 
     2094 
     2095            // do we retag all posts? 
     2096            $allposts   = (bool) strip_tags(stripslashes($_POST['strictlyautotags-tagless2']));  
     2097 
     2098            ShowDebugAutoTag("allposts = " . $allposts); 
     2099 
     2100            $updated = $this->ReLinkAndTagPosts($allposts); 
     2101 
     2102            if($updated == 0){ 
     2103                $msg = sprintf(__('No Posts were re-tagged or deeplinked','strictlyautotags'),$updated); 
     2104            }else if($updated == 1){ 
     2105                $msg = sprintf(__('1 Post was re-tagged and deeplinkedd','strictlyautotags'),$updated); 
     2106            }else{ 
     2107                $msg = sprintf(__('%d Posts have been re-tagged and deeplinked','strictlyautotags'),$updated); 
     2108            } 
     2109        } 
     2110         
     2111 
    14742112 
    14752113        // if our option form has been submitted then save new values 
     
    14792117            check_admin_referer("tagoptions","strictlytagoptionsnonce"); 
    14802118 
    1481             $this->uninstall            = (bool) strip_tags(stripslashes($_POST['strictlyautotags-uninstall'])); 
    1482  
    1483             $options['autodiscover']    = strip_tags(stripslashes($_POST['strictlyautotags-autodiscover'])); 
    1484             $options['ranktitle']       = strip_tags(stripslashes($_POST['strictlyautotags-ranktitle']));            
    1485             $options['nestedtags']      = strip_tags(stripslashes($_POST['strictlyautotags-nestedtags'])); 
    1486             $options['rankhtml']        = strip_tags(stripslashes($_POST['strictlyautotags-rankhtml'])); 
    1487             $options['boldtaggedwords'] = strip_tags(stripslashes($_POST['strictlyautotags-boldtaggedwords']));          
    1488             $options['maxtagwords']     = strip_tags(stripslashes($_POST['strictlyautotags-maxtagwords']));                  
    1489             $ignorepercentage           = trim(strip_tags(stripslashes($_POST['strictlyautotags-ignorepercentage'])));           
    1490             $noisewords                 = trim(strip_tags(stripslashes($_POST['strictlyautotags-noisewords'])));     
    1491             $noisewords_case_sensitive  = trim(strip_tags(stripslashes($_POST['strictlyautotags-noisewords-case-sensitive'])));  
    1492             $removenoise                = (bool) strip_tags(stripslashes($_POST['strictlyautotags-removenoise'])); 
     2119            ShowDebugAutoTag("get saved values"); 
     2120 
     2121            $this->uninstall                        = (bool) strip_tags(stripslashes($_POST['strictlyautotags-uninstall'])); 
     2122            $options['autodiscover']                = strip_tags(stripslashes($_POST['strictlyautotags-autodiscover'])); 
     2123            $options['skiptaggedposts']             = (bool)strip_tags(stripslashes($_POST['strictlyautotags-skip_tagged_posts']));              
     2124            $options['ranktitle']                   = strip_tags(stripslashes($_POST['strictlyautotags-ranktitle']));            
     2125            $options['nestedtags']                  = strip_tags(stripslashes($_POST['strictlyautotags-nestedtags'])); 
     2126            $options['rankhtml']                    = strip_tags(stripslashes($_POST['strictlyautotags-rankhtml'])); 
     2127            $options['boldtaggedwords']             = strip_tags(stripslashes($_POST['strictlyautotags-boldtaggedwords']));  
     2128            $options['taglinks']                    = (bool)strip_tags(stripslashes($_POST['strictlyautotags-taglinks'])); 
     2129            $options['deeplinktitle']               = strip_tags(stripslashes($_POST['strictlyautotags-deeplinktitle']));    
     2130            $options['removestrictlytagsandlinks']  = (bool)strip_tags(stripslashes($_POST['strictlyautotags-remove_strictly_tags_and_links']));                     
     2131 
     2132            $ignorepercentage                       = trim(strip_tags(stripslashes($_POST['strictlyautotags-ignorepercentage'])));           
     2133            $noisewords                             = trim(strip_tags(stripslashes($_POST['strictlyautotags-noisewords'])));     
     2134            $noisewords_case_sensitive              = trim(strip_tags(stripslashes($_POST['strictlyautotags-noisewords-case-sensitive'])));  
     2135            $removenoise                            = (bool) strip_tags(stripslashes($_POST['strictlyautotags-removenoise'])); 
    14932136                 
    14942137            // check format is word|word|word 
     
    14992142 
    15002143                // make sure the noise words don't start or end with pipes 
    1501                 if( preg_match("/^([-a-z'1-9 ]+\|[-a-z'1-9 ]*)+$/",$noisewords)){    
     2144                if( preg_match("/^([-a-z'1-9]+\|[-a-z'1-9]*)+$/",$noisewords)){  
    15022145                    $options['noisewords']  = $noisewords; 
    15032146 
     
    15242167            if(empty($noisewords_case_sensitive)){ 
    15252168                $noisewords_case_sensitive = $this->defaultnoisewords_case_sensitive; 
    1526             }else{           
     2169            }else{ 
     2170                $noisewords_case_sensitive = $noisewords_case_sensitive; 
    15272171 
    15282172                // make sure the noise words don't start or end with pipes 
     
    15732217                $options['ignorepercentage']    = 50; 
    15742218            } 
    1575              
     2219 
     2220            $maxtagstolink              = strip_tags(stripslashes($_POST['strictlyautotags-maxtagstolink'])); 
     2221            if(is_numeric($maxtagstolink) && $maxtagstolink >= 0 ){ 
     2222                $options['maxtagstolink']       = $maxtagstolink; 
     2223            }else{ 
     2224                $errmsg .= __('The value you entered for Max Tags to Link was invalid: (> 0)<br />','strictlyautotags'); 
     2225                $options['maxtagstolink']       = 0; 
     2226            } 
     2227 
     2228            $minpoststotaglink              = strip_tags(stripslashes($_POST['strictlyautotags-minpoststotaglink'])); 
     2229            if(is_numeric($minpoststotaglink) && $minpoststotaglink >= 0 ){ 
     2230                $options['minpoststotaglink']       = $minpoststotaglink; 
     2231            }else{ 
     2232                $errmsg .= __('The value you entered for Min no of Tagged Posts to Link was invalid: (> 0)<br />','strictlyautotags'); 
     2233                $options['minpoststotaglink']       = 0; 
     2234            } 
     2235             
     2236 
    15762237            if(!empty($errmsg)){ 
    15772238                $errmsg = substr($errmsg,0,strlen($errmsg)-6); 
     
    16402301                    margin-bottom: 15px; 
    16412302                } 
    1642                 </style>'; 
     2303                #strictlyautotags-deeplinktitle{ 
     2304                    width: 350px !important; 
     2305                } 
     2306                </style> 
     2307                 
     2308                '; 
    16432309 
    16442310        echo    '<div class="wrap" id="StrictlyAutoTagsAdmin">'; 
     
    17282394                <li>'.__('Handle badly formatted content by setting the Ignore Capitals Percentage to an appropiate amount.', 'strictlyautotags').'</li> 
    17292395                <li>'.__('Aid Search Engine Optimisation by bolding your matched tags to emphasis to search engines the important terms within your articles.', 'strictlyautotags').'</li> 
     2396                <li>'.__('Also help your internal SEO by deeplinking a certain number of tags per article to their related tag page.', 'strictlyautotags').'</li> 
    17302397                <li>'.__('Set the Max Tag Words setting to an appropriate value to prevent long capitalised sentences from matching during auto discovery.', 'strictlyautotags').'</li>                  
    17312398                <li>'.__('Only the most frequently occurring tags will be added against the post.', 'strictlyautotags').'</li> 
    17322399                <li>'.__('Re-Tag all your existing posts in one go or just those currently without tags.','strictlyautotags').'</li> 
     2400                <li>'.__('Re-Tag and Re-Link all your existing posts in one go or just those currently without tags.','strictlyautotags').'</li> 
    17332401                <li>'.__('Quickly clean up your system by removing under used saved tags or noise words that have already been tagged.','strictlyautotags').'</li></ul> 
    17342402                </div> 
    17352403                </div>'; 
    17362404 
     2405                 
    17372406         
    17382407 
     
    17512420                </div></div></form>'; 
    17522421 
    1753                  
     2422        echo    '<form name="retag2" id="retag2" method="post"> 
     2423                <div class="postbox">                        
     2424                    <h3 class="hndle">'.__('Re-Tag and Re-Link Existing Posts', 'strictlyautotags').'</h3>                   
     2425                    <div class="inside"> 
     2426                '. wp_nonce_field("retag2","strictlyretagnonce",false,false) .' 
     2427                <div class="tagopt"> 
     2428                <label for="strictlyautotags-tagless2">'.__('Re-Tag and Re-Link All Posts','strictlyautotags').'</label> 
     2429                <input type="checkbox" name="strictlyautotags-tagless2" id="strictlyautotags-tagless2" value="true" ' . ((!IsNothing($allposts)) ? 'checked="checked"' : '') . '/> 
     2430                <span class="notes">'.__('Checking this will option will mean that all your posts will be re-tagged and deeplinked otherwise only posts without any current tags will be parsed for appropriate tags.', 'strictlyautotags').'</span> 
     2431                </div> 
     2432                <p class="submit"><input value="'.__('Re-Link and Re-Tag Posts', 'strictlyautotags').'" type="submit" name="RelinkSubmit" id="RelinkSubmit"></p> 
     2433                </div></div></form>';        
    17542434 
    17552435        echo    '<form name="cleanup" id="cleanup" method="post"> 
     
    17862466 
    17872467        echo    '<div class="tagopt"> 
     2468                <label for="strictlyautotags-skip_tagged_posts">'.__('Skip Pre-Tagged Posts','strictlyautotags').'</label> 
     2469                <input type="checkbox" name="strictlyautotags-skip_tagged_posts" id="strictlyautotags-skip_tagged_posts" value="true" ' . (($options['skiptaggedposts']) ? 'checked="checked"' : '') . '/>               
     2470                <span class="notes">'.__('Don\'t AutoTag posts that already have been tagged. Ideally set this to true, then let the plugin tag your posts before manually adding any tags yourself and re-saving. On the second save the post won\'t be scanned for tags or have SEO work carried out on it.', 'strictlyautotags').'</span> 
     2471                </div>'; 
     2472         
     2473 
     2474 
     2475        echo    '<div class="tagopt"> 
    17882476                <label for="strictlyautotags-ranktitle">'.__('Rank Title','strictlyautotags').'</label> 
    17892477                <input type="checkbox" name="strictlyautotags-ranktitle" id="strictlyautotags-ranktitle" value="true" ' . (($options['ranktitle']) ? 'checked="checked"' : '') . '/>                 
     
    18192507                </div>'; 
    18202508 
    1821  
     2509        echo    '<div class="tagopt"> 
     2510                <label for="strictlyautotags-taglinks">'.__('Deeplink Tagged Words','strictlyautotags').'</label> 
     2511                <input type="checkbox" name="strictlyautotags-taglinks" id="strictlyautotags-taglinks" value="true" ' . (($options['taglinks']) ? 'checked="checked"' : '') . '/>                
     2512                <span class="notes">'.__('Wrap matched tags found within the post article with links to the relevant tag page. This aids SEO by deeplinking your site.', 'strictlyautotags').'</span> 
     2513                </div>'; 
     2514 
     2515 
     2516 
     2517        echo    '<div class="tagopt"> 
     2518                <label for="strictlyautotags-deeplinktitle">'.__('Deeplink Tagged Words','strictlyautotags').'</label> 
     2519                <input type="text" name="strictlyautotags-deeplinktitle" id="strictlyautotags-deeplinktitle" value="' . esc_attr($options['deeplinktitle']) . '" /> 
     2520                <span class="notes">'.__('The title to use for deeplinked anchor tags. Use %post_tag% for the placeholder where the tag word will appear e.g "View all posts for this %post_tag% here".', 'strictlyautotags').'</span> 
     2521                </div>'; 
     2522 
     2523 
     2524        echo    '<div class="tagopt"> 
     2525                <label for="strictlyautotags-maxtagstolink">'.__('Max Tags to Deeplink','strictlyautotags').'</label> 
     2526                <input type="text" name="strictlyautotags-maxtagstolink" id="strictlyautotags-maxtagstolink" value="' . esc_attr($options['maxtagstolink']) . '" /> 
     2527                <span class="notes">'.__('Set the maximum number of tags within a post to deeplink.', 'strictlyautotags').'</span> 
     2528                </div>'; 
     2529 
     2530        echo    '<div class="tagopt"> 
     2531                <label for="strictlyautotags-minpoststotaglink">'.__('Min no of Tags within a Post to deeplink to.','strictlyautotags').'</label> 
     2532                <input type="text" name="strictlyautotags-minpoststotaglink" id="strictlyautotags-minpoststotaglink" value="' . esc_attr($options['maxtagstolink']) . '" /> 
     2533                <span class="notes">'.__('Set the minimum number of tags tbat a post must have before deeplinking to their tag page.', 'strictlyautotags').'</span> 
     2534                </div>'; 
     2535 
     2536        echo    '<div class="tagopt"> 
     2537                <label for="strictlyautotags-remove_strictly_tags_and_links">'.__('Always Cleanup on Re-Save','strictlyautotags').'</label> 
     2538                <input type="checkbox" name="strictlyautotags-remove_strictly_tags_and_links" id="strictlyautotags-remove_strictly_tags_and_links" value="true" ' . (($options['removestrictlytagsandlinks']) ? 'checked="checked"' : '') . '/>                      
     2539                <span class="notes">'.__('Whether to always remove any deeplinked or bolded tags on re-saving a post in case those tags have been removed. Will take longer to run and not always required.', 'strictlyautotags').'</span> 
     2540                </div>'; 
     2541 
     2542     
    18222543        echo    '<div class="tagopt"> 
    18232544                <label for="strictlyautotags-ignorepercentage">'.__('Ignore Capitals Percentage','strictlyautotags').'</label> 
     
    18652586                <h3 class="hndle">'.__('Stictly Software Recommendations', 'strictlyautotags').'</h3>                    
    18662587                <div class="inside">                 
    1867                     <p>'.__('If you enjoy using this Wordpress plugin you might be interested in some other websites, tools and plugins I have developed.', 'strictlyautotags').'</p> 
     2588                    <p>'.__('If you enjoy using this Wordpress plugin you might be interested in some other websites, tools and plugins I have      developed.', 'strictlyautotags').'</p> 
    18682589                    <ul> 
    1869                         <li><a href="http://www.strictly-software.com/applications/twitter-hash-tag-hunter" title="'.__('Strictly Software Hash Tag Hunter Application','strictlyautotags').'">'.__('Twitter Hash Tag Hunter Application','strictlyautotags').'</a> 
    1870                             <p>'.__('Strictly Hash Tag Hunter is a Windows application that is designed to aid Auto Bloggers or Site Owners that make use of Strictly AutoTags and my <a href="http://wordpress.org/extend/plugins/strictly-tweetbot/">Strictly TweetBot plugin</a>. It allows people with new or existing Twitter accounts to find out the #HashTags and @Accounts relevant to the keywords and search terms that your website is based around. Don\'t waste time by Tweeting Hash Tags that aren\'t followed, or by following accounts that are not relevant to your sites content. Save yourself time and energy by letting the <a href="http://www.strictly-software.com/applications/twitter-hash-tag-hunter">Twitter Hash Tag Hunter</a> to do all the important SEO work for you, tracking down key #HashTags and @Accounts your site should be following and tweeting to.','strictlyautotags').'</p> 
    1871                         </li>    
    18722590                        <li><a href="http://www.strictly-software.com/plugins/strictly-google-sitemap">'.__('Strictly Google Sitemap','strictlyautotags').'</a> 
    18732591                            <p>'.__('Strictly Google Sitemap is a feature rich Wordpress plugin built for sites requiring high performance. Not only does it use a tiny number of database queries compared to other plugins it uses less memory and was designed specifically for under performing or low spec systems. As well as offering all the features of other sitemap plugins it brings all those missing features such as sitemap index files, XML validation, scheduled builds, configuration analysis and SEO reports.','strictlyautotags').'</p> 
     
    18822600                            <p>'.__('Strictly Online Tools is a suite of free online tools I have developed which include encoders, unpackers, translators, compressors, scanners and much more.','strictlyautotags').'</p> 
    18832601                        </li> 
    1884                         <li><a href="http://www.hattrickheaven.com">'.__('Hattrick Heaven','strictlyautotags').'</a> 
    1885                             <p>'.__('If you like football then this site is for you. Get the latest football news, scores and league standings from around the web on one site. All content is crawled, scraped and reformated in real time so there is no need to leave the site when following news links. Check it out for yourself. ','strictlyautotags').'</p> 
     2602                        <li><a href="http://www.ukhorseracingtipster.com">'.__('UK Horse Racing Tipster','strictlyautotags').'</a> 
     2603                            <p>'.__('If you like Horse Racing and earning BIG profits from betting on it then this is the site for you. Get the latest racing news, free tips by email and cheap membership by week, month and year for premium high ROI tips that have been proven again and again!','strictlyautotags').'</p> 
    18862604                        </li> 
    18872605                        <li><a href="http://www.fromthestables.com">'.__('From The Stables','strictlyautotags').'</a> 
Note: See TracChangeset for help on using the changeset viewer.