/** * Fetch emoticons as JSON for editors, etc * * @param mixed Number of emoticons to fetch (false to fetch all, or an int limit) * @return string JSON */ public function fetchEmoticons($fetchFirstX = false) { $emoDir = IPSText::getEmoticonDirectory(); $emoString = ''; $smilie_id = 0; $total = 0; foreach (ipsRegistry::cache()->getCache('emoticons') as $elmo) { if ($elmo['emo_set'] != $emoDir) { continue; } $total++; if ($fetchFirstX !== false && $smilie_id + 1 > $fetchFirstX) { continue; } // ----------------------------------------- // Make single quotes as URL's with html entites in them // are parsed by the browser, so ' causes JS error :o // ----------------------------------------- if (strstr($elmo['typed'], "'")) { $in_delim = '"'; } else { $in_delim = "'"; } $emoArray[$smilie_id] = array('src' => $elmo['image'], 'text' => addslashes($elmo['typed'])); $smilie_id++; } return array('total' => $total, 'count' => $smilie_id, 'emoticons' => $emoArray); }
/** * Convert IMG codes into text smilies * * @param text $txt * @return text $txt */ public function emoticonImgtoCode($txt) { if (count($this->cache->getCache('emoticons')) > 0) { $emoDir = IPSText::getEmoticonDirectory(); $txt = str_replace('<#EMO_DIR#>', $this->registry->output->skin['set_emo_dir'], $txt); foreach ($this->cache->getCache('emoticons') as $row) { if ($row['emo_set'] != $emoDir) { continue; } /* This can shave a lot of loading time off of a site if there is a lot of large text being parsed, especially if there are a lot of emoticons too */ if (strpos($txt, $row['image']) === false) { continue; } /* BBCode */ $txt = preg_replace('#(\\s)?\\[img\\]' . preg_quote($this->settings['public_cdn_url'] . 'style_emoticons/' . $this->registry->output->skin['set_emo_dir'] . '/' . $row['image'], '#') . '\\[/img\\]#', ' ' . $row['typed'], $txt); /* HTML */ $txt = preg_replace('#(\\s)?<img([^>]+?)src=(?:[\'"])' . preg_quote($this->settings['public_cdn_url'] . 'style_emoticons/' . $this->registry->output->skin['set_emo_dir'] . '/' . $row['image'], '#') . '(?:[\'"])(?:[^>]+?)?>#', ' ' . $row['typed'], $txt); } } return $txt; }