MDL-24777 core function replace_smilies now uses emoticon_manager API
This commit is contained in:
@@ -6708,10 +6708,53 @@ function get_emoticon_manager() {
|
||||
* Provides core support for plugins that have to deal with
|
||||
* emoticons (like HTML editor or emoticon filter).
|
||||
*
|
||||
* Whenever this manager mentiones 'emoticon object', the following data
|
||||
* structure is expected: stdClass with properties text, imagename, imagecomponent,
|
||||
* altidentifier and altcomponent
|
||||
*
|
||||
* @see admin_setting_emoticons
|
||||
*/
|
||||
class emoticon_manager {
|
||||
|
||||
/**
|
||||
* Returns the currently enabled emoticons
|
||||
*
|
||||
* @return array of emoticon objects
|
||||
*/
|
||||
public function get_emoticons() {
|
||||
global $CFG;
|
||||
|
||||
if (empty($CFG->emoticons)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$emoticons = $this->decode_stored_config($CFG->emoticons);
|
||||
|
||||
if (!is_array($emoticons)) {
|
||||
// something is wrong with the format of stored setting
|
||||
debugging('Invalid format of emoticons setting, please resave the emoticons settings form', DEBUG_NORMAL);
|
||||
return array();
|
||||
}
|
||||
|
||||
return $emoticons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts emoticon object into renderable pix_emoticon object
|
||||
*
|
||||
* @param stdClass $emoticon emoticon object
|
||||
* @return pix_emoticon
|
||||
*/
|
||||
public function prepare_renderable_emoticon(stdClass $emoticon) {
|
||||
$stringmanager = get_string_manager();
|
||||
if ($stringmanager->string_exists($emoticon->altidentifier, $emoticon->altcomponent)) {
|
||||
$alt = get_string($emoticon->altidentifier, $emoticon->altcomponent);
|
||||
} else {
|
||||
$alt = $emoticon->text;
|
||||
}
|
||||
return new pix_emoticon($emoticon->imagename, $alt, $emoticon->imagecomponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the array of emoticon objects into a string storable in config table
|
||||
*
|
||||
|
||||
+13
-23
@@ -1629,38 +1629,28 @@ function cleanAttributes2($htmlArray){
|
||||
*/
|
||||
function replace_smilies(&$text) {
|
||||
global $CFG, $OUTPUT;
|
||||
static $emoticons = null;
|
||||
static $e = array(); // array of emoticon texts like ':-)'
|
||||
static $img = array(); // array of HTML to replace emoticon text with
|
||||
|
||||
if (empty($CFG->emoticons)) { /// No emoticons defined, nothing to process here
|
||||
$manager = get_emoticon_manager();
|
||||
|
||||
if (is_null($emoticons)) {
|
||||
$emoticons = $manager->get_emoticons();
|
||||
}
|
||||
|
||||
if (empty($emoticons)) { /// No emoticons defined, nothing to process here
|
||||
return;
|
||||
}
|
||||
|
||||
$lang = current_language();
|
||||
$emoticonstring = $CFG->emoticons;
|
||||
static $e = array();
|
||||
static $img = array();
|
||||
static $emoticons = null;
|
||||
|
||||
if (is_null($emoticons)) {
|
||||
$emoticons = array();
|
||||
if ($emoticonstring) {
|
||||
$items = explode('{;}', $CFG->emoticons);
|
||||
foreach ($items as $item) {
|
||||
$item = explode('{:}', $item);
|
||||
$emoticons[$item[0]] = $item[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($img[$lang])) { /// After the first time this is not run again
|
||||
$e[$lang] = array();
|
||||
$img[$lang] = array();
|
||||
foreach ($emoticons as $emoticon => $image){
|
||||
$alttext = get_string($image, 'pix');
|
||||
if ($alttext === '') {
|
||||
$alttext = $image;
|
||||
}
|
||||
$e[$lang][] = $emoticon;
|
||||
$img[$lang][] = '<img alt="'. $alttext .'" width="15" height="15" src="'. $OUTPUT->pix_url('s/' . $image) . '" />';
|
||||
foreach ($emoticons as $emoticon) {
|
||||
$e[$lang][] = $emoticon->text;
|
||||
$img[$lang][] = $OUTPUT->render($manager->prepare_renderable_emoticon($emoticon));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user