Changeset 495757
- Timestamp:
- 01/26/2012 07:46:50 PM (14 years ago)
- Location:
- auto-more-tag
- Files:
-
- 5 added
- 2 edited
-
tags/3.0 (added)
-
tags/3.0/auto-more-options-page.php (added)
-
tags/3.0/auto-more.php (added)
-
tags/3.0/readme.txt (added)
-
tags/3.0/screenshot-1.png (added)
-
trunk/auto-more.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
auto-more-tag/trunk/auto-more.php
r471358 r495757 6 6 Author: Travis Weston 7 7 Author URI: http://travisweston.com/ 8 Version: 2.1.28 Version: 3.0 9 9 */ 10 10 … … 57 57 58 58 } 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; 59 67 60 68 switch($options['units']){ … … 87 95 88 96 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 90 132 return $data; 133 91 134 } 92 135 93 136 public function byCharacter($data, $length, $breakOn) { 94 137 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 } 109 157 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; 115 199 } 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 } 160 204 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 166 211 return $data; 167 212 … … 190 235 } 191 236 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 196 237 $input['credit_me'] = (isset($input['credit_me']) && ((bool)$input['credit_me'] == true)) ? true : false; 197 238 … … 203 244 204 245 $input['units'] = ((int)$input['units'] == 1) ? 1 : (((int)$input['units'] == 2) ? 2 : 3); 205 206 /*********************************207 * THIS IS TEMPORARY208 * ONLY HERE UNTIL WORD COUNT IS IMPLEMENTED209 **********************************/210 if($input['units'] == 2){211 $input['units'] = 1;212 }213 246 214 247 if($input['units'] == 3 && $input['quantity'] > 100){ 215 248 $input['messages']['notices'][] = 'While using Percentage breaking, you cannot us a number larger than 100%. This field has been reset to 50%.'; 216 249 $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 } 222 251 223 252 $input['break'] = (isset($input['break']) && (int)$input['break'] == 2) ? 2 : 1; -
auto-more-tag/trunk/readme.txt
r471357 r495757 5 5 Requires at least: 3.2.1 6 6 Tested up to: 3.2.1 7 Stable tag: 2.1.27 Stable tag: 3.0 8 8 9 9 Allows you to add a More tag to your post automatically upon publication. … … 27 27 = Have a question? = 28 28 29 If you do, you should probabley email tweston@travisweston.com, or visit http://travisweston.com/ auto-tag-wordpress-pluginand post it in the comments!29 If 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! 30 30 31 31 == Screenshots == … … 34 34 35 35 == Changelog == 36 = 3.0 = 37 Improved 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 = 40 Minor change to posting, so tag isn't placed as first character of post. 36 41 37 42 = 2.1.2 =
Note: See TracChangeset
for help on using the changeset viewer.