Plugin Directory

Changeset 643365


Ignore:
Timestamp:
12/22/2012 10:59:22 AM (13 years ago)
Author:
manski
Message:

Fixed some bugs

Location:
font-emoticons/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • font-emoticons/trunk/font-emoticons.php

    r642815 r643365  
    44Plugin URI:
    55Description: Replace the standard WP Smileys with font icons.
    6 Version: 1.0.0
     6Version: 1.1
    77Author: Sebastian Krysmanski
    88Author URI: http://manski.net
     
    1212  private $name;
    1313  private $text_reps;
     14  private $regex;
    1415
    1516  public function __construct($name, $text_reps) {
    1617    $this->name = $name;
    1718    $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';
    1833  }
    1934
    2035  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);
    2338  }
    2439}
     
    99114
    100115  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
    101122    $content = $this->mask_content($content);
     123
     124    #echo "<!--$content-->";
    102125
    103126    foreach ($this->emots as $emot) {
     
    106129
    107130    $content = $this->unmask_content($content);
     131
     132    # Remove spaces added at the beginning.
     133    $content = substr($content, 1, -1);
    108134
    109135    return $content;
     
    118144
    119145  public function mask_content_replace_callback($matches) {
     146    $matched_text = $matches[0];
    120147    $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;
    123162  }
    124163
  • font-emoticons/trunk/readme.txt

    r642815 r643365  
    44Requires at least: 3.0.0
    55Tested up to: 3.5.0
    6 Stable tag: 1.0
     6Stable tag: 1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5959== Changelog ==
    6060
     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
    6165= 1.0 =
    6266* First release.
Note: See TracChangeset for help on using the changeset viewer.