Plugin Directory

Changeset 495757


Ignore:
Timestamp:
01/26/2012 07:46:50 PM (14 years ago)
Author:
anubisthejackle
Message:

3.0 Update

Location:
auto-more-tag
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • auto-more-tag/trunk/auto-more.php

    r471358 r495757  
    66Author: Travis Weston
    77Author URI: http://travisweston.com/
    8 Version: 2.1.2
     8Version: 3.0
    99*/
    1010
     
    5757
    5858            }
     59
     60            // Sanitize the nasty characters out!
     61
     62            $data = str_replace(chr(160), chr(32), $data);
     63            $data = str_replace(chr(194), '', $data);
     64
     65            if(strlen(strip_tags($data)) <= 0)
     66                return $data;
    5967
    6068            switch($options['units']){
     
    8795
    8896        public function byWord($data, $length, $breakOn) {
    89             // UNUSED IN CURRENT VERSION
     97       
     98            $break = ($breakOn == 2) ? PHP_EOL : ' ';
     99            $data = str_replace('<!--more-->', '', $data);
     100            $stripped_data = strip_tags($data);
     101
     102            $fullLength = strlen($data);
     103
     104            $strippedLocation = 0;
     105            $wordCount = 0;
     106            for($i = 0; $i < $fullLength; $i++){
     107                if($stripped_data[$strippedLocation] != $data[$i]){
     108                    continue;
     109                }
     110
     111                if($wordCount >= $length){
     112                    if($stripped_data[$strippedLocation] == $break){
     113                        $insertSpot = $i;
     114                        break;
     115                    }
     116                }
     117
     118                if($stripped_data[$strippedLocation] == ' '){
     119                    $wordCount++;
     120                }
     121               
     122                $strippedLocation++;
     123
     124            }
     125
     126            $start = trim(substr($data, 0, $insertSpot));
     127            $end = trim(substr($data, $insertSpot));
     128
     129            if(strlen($start) > 0 && strlen($end) > 0)
     130                $data = $start.'<!--more-->'.$end;
     131
    90132            return $data;
     133
    91134        }
    92135
    93136        public function byCharacter($data, $length, $breakOn) {
    94137
    95             #$original = $data;
    96             #$data = strip_tags($data);
    97             if(strlen($data) > $length){
    98 
    99                 //Remove any old more tags.
    100 
    101                 $data = str_replace('<!--more-->', '', $data);
    102                 $break = ($breakOn === 2) ? PHP_EOL : ' ';
    103                 $pos = strpos($data, $break, $length);
    104                 $posHTMLStart = strpos($data, '<', $pos);
    105                 $posHTMLEnd = strpos($data, '>', $pos);
    106 
    107                 if($pos < $posHTMLEnd)
    108                     $pos = $posHTMLEnd + 1;
     138            $break = ($breakOn == 2) ? PHP_EOL : ' ';
     139            $data = str_replace('<!--more-->', '', $data);
     140            $stripped_data = strip_tags($data);
     141
     142            $fullLength = strlen($data);
     143
     144            $strippedLocation = 0;
     145
     146            for($i = 0; $i < $fullLength; $i++){
     147                if($stripped_data[$strippedLocation] != $data[$i]){
     148                    continue;
     149                }
     150
     151                if($strippedLocation >= $length){
     152                    if($stripped_data[$strippedLocation] == $break){
     153                        $insertSpot = $i;
     154                        break;
     155                    }
     156                }
    109157               
    110                 if($pos === false) {
    111 
    112                     $pos = strpos($data, '>', $length);
    113                     if($pos === false){
    114                         $pos = $length;
     158                $strippedLocation++;
     159
     160            }
     161
     162            $start = trim(substr($data, 0, $insertSpot));
     163            $end = trim(substr($data, $insertSpot));
     164
     165            if(strlen($start) > 0 && strlen($end) > 0)
     166                $data = $start.'<!--more-->'.$end;
     167
     168            return $data;
     169
     170        }
     171
     172        public function byPercent($data, $length, $breakon) {
     173
     174            $debug = null;
     175            $break = ($breakOn === 2) ? PHP_EOL : ' ';
     176            $data = str_replace('<!--more-->', '', $data);
     177            /* Strip Tags, get length */
     178            $stripped_data = strip_tags($data);
     179            $lengthOfPost = strlen($stripped_data);
     180            $fullLength = strlen($data);
     181
     182            /* Find location to insert */
     183
     184            $insert_location = $lengthOfPost * ($length / 100);
     185
     186            /* iterate through post, look for differences between stripped and unstripped. If found, continue*/
     187
     188            $strippedLocation = 0;     
     189
     190            for($i = 0; $i < $fullLength; $i++){
     191                if($stripped_data[$strippedLocation] != $data[$i]){
     192                    continue;
     193                }
     194       
     195                if($strippedLocation >= $insert_location){
     196                    if($stripped_data[$strippedLocation] == $break){
     197                        $insertSpot = $i;
     198                        break;
    115199                    }
    116 
    117                 }
    118 
    119                 $temp = substr($data, 0, $pos);
    120                 $temp_end = substr($data, $pos);
    121                 if(empty($temp_end) || trim($temp_end) == null || strlen($temp_end) <= 0)
    122                     return $data;
    123 
    124                 $data = $temp.'<!--more-->'.$temp_end;
    125 
    126             }
    127        
    128             return $data;
    129 
    130         }
    131 
    132         public function byPercent($data, $length, $breakon) {
    133 
    134             $lengthOfPost = strlen($data);
    135             $start = $lengthOfPost * ($length / 100);
    136 
    137             $data = str_replace('<!--more-->', '', $data);
    138             $break = ($breakOn === 2) ? PHP_EOL : ' ';
    139             $pos = strpos($data, $break, $start);
    140             $posHTMLStart = strpos($data, '<', $pos);
    141             $posHTMLEnd = strpos($data, '>', $pos);
    142 
    143             if($pos < $posHTMLEnd)
    144                 $pos = $posHTMLEnd + 1;
    145 
    146             if($pos === false){
    147 
    148                 $pos = strpos($data, '>', $start);
    149 
    150                 if($pos === false){
    151 
    152                     $pos = $start;
    153 
    154                 }
    155 
    156             }
    157 
    158             $temp = substr($data, 0, $pos);
    159             $temp_end = substr($data, $pos);
     200                }
     201
     202                $strippedLocation++;   
     203            }
    160204           
    161             if(empty($temp_end) || trim($temp_end) == null)
    162                 return $data;
    163 
    164             $data = $temp.'<!--more-->'.$temp_end;
    165 
     205            $start = trim(substr($data, 0, $insertSpot));
     206            $end = trim(substr($data, $insertSpot));
     207
     208            if(strlen($start) > 0 && strlen($end) > 0)
     209                $data = $start.'<!--more-->'.$end;         
     210           
    166211            return $data;
    167212
     
    190235            }
    191236
    192             if($input['units'] == 2){
    193                 $input['messages']['errors'][] = 'This version does not include capabilities for Word seperation. Units has been defaulted to Characters.';
    194             }
    195 
    196237            $input['credit_me'] = (isset($input['credit_me']) && ((bool)$input['credit_me'] == true)) ? true : false;
    197238
     
    203244
    204245            $input['units'] = ((int)$input['units'] == 1) ? 1 : (((int)$input['units'] == 2) ? 2 : 3);
    205 
    206             /*********************************
    207             * THIS IS TEMPORARY
    208             * ONLY HERE UNTIL WORD COUNT IS IMPLEMENTED
    209             **********************************/
    210             if($input['units'] == 2){
    211                 $input['units'] = 1;
    212             }
    213246
    214247            if($input['units'] == 3 && $input['quantity'] > 100){
    215248                $input['messages']['notices'][] = 'While using Percentage breaking, you cannot us a number larger than 100%. This field has been reset to 50%.';
    216249                $input['quantity'] = 50;
    217             }
    218 
    219             if($input['units'] == 1){
    220                 $input['messages']['warnings'][] = 'Using characters is not suggested. The more tag is added to the unfiltered HTML of the post, which means that this tag could cause your HTML to unvalidate.';
    221             }           
     250            }       
    222251           
    223252            $input['break'] = (isset($input['break']) && (int)$input['break'] == 2) ? 2 : 1;
  • auto-more-tag/trunk/readme.txt

    r471357 r495757  
    55Requires at least: 3.2.1
    66Tested up to: 3.2.1
    7 Stable tag: 2.1.2
     7Stable tag: 3.0
    88
    99Allows you to add a More tag to your post automatically upon publication.
     
    2727= Have a question? =
    2828
    29 If you do, you should probabley email tweston@travisweston.com, or visit http://travisweston.com/auto-tag-wordpress-plugin and post it in the comments!
     29If you do, you should probabley email tweston@travisweston.com, or visit http://travisweston.com/portfolio/wordpress-plugins/auto-tag-wordpress-plugin/ and post it in the comments!
    3030
    3131== Screenshots ==
     
    3434
    3535== Changelog ==
     36= 3.0 =
     37Improved intelligent placement, fixing glitch with HTML. Placement is now based on plaintext, and not HTML content. Added capabilities to place by word count.
     38
     39= 2.1.3 =
     40Minor change to posting, so tag isn't placed as first character of post.
    3641
    3742= 2.1.2 =
Note: See TracChangeset for help on using the changeset viewer.