Changeset 643365
- Timestamp:
- 12/22/2012 10:59:22 AM (13 years ago)
- Location:
- font-emoticons/trunk
- Files:
-
- 2 edited
-
font-emoticons.php (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
font-emoticons/trunk/font-emoticons.php
r642815 r643365 4 4 Plugin URI: 5 5 Description: Replace the standard WP Smileys with font icons. 6 Version: 1. 0.06 Version: 1.1 7 7 Author: Sebastian Krysmanski 8 8 Author URI: http://manski.net … … 12 12 private $name; 13 13 private $text_reps; 14 private $regex; 14 15 15 16 public function __construct($name, $text_reps) { 16 17 $this->name = $name; 17 18 $this->text_reps = $text_reps; 19 20 $this->regex = ''; 21 $is_first = true; 22 foreach ($text_reps as $smiley) { 23 if ($is_first) { 24 $is_first = false; 25 } 26 else { 27 $this->regex .= '|'; 28 } 29 $this->regex .= preg_quote($smiley, '/'); 30 } 31 32 $this->regex = '/(\s+)(?:'.$this->regex.')(\s+)/U'; 18 33 } 19 34 20 35 public function insert_emots($post_text) { 21 $code = ' <span class="icon-emo-'.$this->name.'"/>';22 return str_replace($this->text_reps, $code, $post_text);36 $code = '\\1<span class="icon-emo-'.$this->name.'"/>\\2'; 37 return preg_replace($this->regex, $code, $post_text); 23 38 } 24 39 } … … 99 114 100 115 public function replace_emots($content) { 116 # surround content with white space so that regexps match emoticons at the beginning and the end 117 # of the content correctly. 118 $content = ' '.$content.' '; 119 120 #echo "<!--$content-->"; 121 101 122 $content = $this->mask_content($content); 123 124 #echo "<!--$content-->"; 102 125 103 126 foreach ($this->emots as $emot) { … … 106 129 107 130 $content = $this->unmask_content($content); 131 132 # Remove spaces added at the beginning. 133 $content = substr($content, 1, -1); 108 134 109 135 return $content; … … 118 144 119 145 public function mask_content_replace_callback($matches) { 146 $matched_text = $matches[0]; 120 147 $id = count($this->placeholders); 121 $this->placeholders[] = $matches[0]; 122 return $this->SECTION_MASKING_START_DELIM.$id.$this->SECTION_MASKING_END_DELIM; 148 $this->placeholders[] = $matched_text; 149 $ret = $this->SECTION_MASKING_START_DELIM.$id.$this->SECTION_MASKING_END_DELIM; 150 151 # At this stage, line break characters have already been replaced with <p> and <br> elements. Surround them with 152 # spaces to enable emoticon detection. Also, surround HTML comments with spaces. 153 # 154 # NOTE: At the moment I can't imagine a reason where adding white space around those element would cause any 155 # trouble. I might be wrong though. 156 # 157 # NOTE 2: The first regexp must match <p>, </p> as well as <br />. 158 if (preg_match('#^<[/]?(?:p|br)\s*(?:/\s*)?>$#iU', $matched_text) || preg_match('/<!--.*-->/sU', $matched_text)) { 159 $ret = ' '.$ret.' '; 160 } 161 return $ret; 123 162 } 124 163 -
font-emoticons/trunk/readme.txt
r642815 r643365 4 4 Requires at least: 3.0.0 5 5 Tested up to: 3.5.0 6 Stable tag: 1. 06 Stable tag: 1.1 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 59 59 == Changelog == 60 60 61 = 1.1 = 62 * Emoticons are no longer replaced in URLs. Instead they now require surrounding white space. 63 * Emoticons at the beginning and the end of posts are recognized now. 64 61 65 = 1.0 = 62 66 * First release.
Note: See TracChangeset
for help on using the changeset viewer.