/** * Change the emoji set used, either by merging or or overriding the default set. * * @param Emoji $emoji The emoji object to change. * @param string $emojiSetKey The name of the emoji set to enable. */ public function changeEmojiSet($emoji, $emojiSetKey) { if (!array_key_exists($emojiSetKey, $this->getEmojiSets())) { trigger_error("Emoji set not found: {$emojiSetKey}.", E_USER_NOTICE); return; } // First grab the manifest to the emoji. $emojiSet = $this->emojiSets[$emojiSetKey]; $manifest = $this->getManifest($emojiSet); if ($manifest) { $emoji->setFromManifest($manifest, $emojiSet['basePath']); } }
/** * Carry out an update using provided parameters * * @param int $id * @param array $inputParams * @return array */ public function update($id, $inputParams) { $emoji = Emoji::find($id); $params = $inputParams; foreach ($params as $key => $value) { $emoji->{$key} = $value; } date_default_timezone_set('Africa/Lagos'); $emoji->date_modified = date('Y-m-d H:i:s', time()); return $emoji->save() ? ["msg" => "update successful"] : ["msg" => "Nothing to update"]; }
public function Format($String) { $String = str_replace(array('"', ''', ':', 'Â'), array('"', "'", ':', ''), $String); $String = str_replace('<#EMO_DIR#>', 'default', $String); $String = str_replace('<{POST_SNAPBACK}>', '<span class="SnapBack">»</span>', $String); // There is an issue with using uppercase code blocks, so they're forced to lowercase here $String = str_replace(array('[CODE]', '[/CODE]'), array('[code]', '[/code]'), $String); /** * IPB inserts line break markup tags at line breaks. They need to be removed in code blocks. * The original newline/line break should be left intact, so whitespace will be preserved in the pre tag. */ $String = preg_replace_callback('/\\[code\\].*?\\[\\/code\\]/is', function ($CodeBlocks) { return str_replace(array('<br />'), array(''), $CodeBlocks[0]); }, $String); /** * IPB formats some quotes as HTML. They're converted here for the sake of uniformity in presentation. * Attribute order seems to be standard. Spacing between the opening of the tag and the first attribute is variable. */ $String = preg_replace_callback('#<blockquote\\s+class="ipsBlockquote" data-author="([^"]+)" data-cid="(\\d+)" data-time="(\\d+)">(.*?)</blockquote>#is', function ($BlockQuotes) { $Author = $BlockQuotes[1]; $Cid = $BlockQuotes[2]; $Time = $BlockQuotes[3]; $QuoteContent = $BlockQuotes[4]; // $Time will over as a timestamp. Convert it to a date string. $Date = date('F j Y, g:i A', $Time); return "[quote name=\"{$Author}\" url=\"{$Cid}\" date=\"{$Date}\"]{$QuoteContent}[/quote]"; }, $String); // If there is a really long string, it could cause a stack overflow in the bbcode parser. // Not much we can do except try and chop the data down a touch. // 1. Remove html comments. $String = preg_replace('/<!--(.*)-->/Uis', '', $String); // 2. Split the string up into chunks. $Strings = (array) $String; $Result = ''; foreach ($Strings as $String) { $Result .= $this->NBBC()->Parse($String); } // Linkify URLs in content $Result = Gdn_Format::links($Result); // Parsing mentions $Result = Gdn_Format::mentions($Result); // Handling emoji $Result = Emoji::instance()->translateToHtml($Result); // Make sure to clean filter the html in the end. $Config = array('anti_link_spam' => array('`.`', ''), 'comment' => 1, 'cdata' => 3, 'css_expression' => 1, 'deny_attribute' => 'on*', 'elements' => '*-applet-form-input-textarea-iframe-script-style', 'keep_bad' => 0, 'schemes' => 'classid:clsid; href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; style: nil; *:file, http, https', 'valid_xml' => 2); $Spec = 'object=-classid-type, -codebase; embed=type(oneof=application/x-shockwave-flash)'; $Result = htmLawed($Result, $Config, $Spec); return $Result; }
/** * encodeメソッド * * 文字列中の絵文字データをキャリア別の連番文字列へ変換する * * @param string $str 絵文字が格納されている可能性のある文字列 * @return string $returnStr 変換後の文字列を返す */ public function encode($str, $carrier = "docomo") { switch (strtolower($carrier)) { case "docomo": $returnStr = parent::docomoEncode($str); break; case "ezweb": $returnStr = parent::ezwebEncode($str); break; case "softbank": $returnStr = parent::softbankEncode($str); break; default: $returnStr = $str; break; } return $returnStr; }
/** * This method will grab the permissions array from getAllowedEditorActions, * build the "kitchen sink" editor toolbar, then filter out the allowed ones and return it. * * @param array $editorToolbar Holds the final copy of allowed editor actions * @param array $editorToolbarAll Holds the "kitchen sink" of editor actions * @return array Returns the array of allowed editor toolbar actions */ protected function getEditorToolbar($attributes = array()) { $editorToolbar = array(); $editorToolbarAll = array(); $allowedEditorActions = $this->getAllowedEditorActions(); $allowedEditorActions['emoji'] = Emoji::instance()->hasEditorList(); if (val('FileUpload', $attributes)) { $allowedEditorActions['uploads'] = true; $allowedEditorActions['images'] = false; } $fontColorList = $this->getFontColorList(); $fontFormatOptions = $this->getFontFormatOptions(); $fontFamilyOptions = $this->getFontFamilyOptions(); // Let plugins and themes override the defaults. $this->EventArguments['actions'] =& $allowedEditorActions; $this->EventArguments['colors'] =& $fontColorList; $this->EventArguments['format'] =& $fontFormatOptions; $this->EventArguments['font'] =& $fontFamilyOptions; $this->fireEvent('toolbarConfig'); // Order the specified dropdowns. $this->sortWeightedOptions($fontFormatOptions); // Build color dropdown from array $toolbarColorGroups = array(); $toolbarDropdownFontColor = array(); $toolbarDropdownFontColorHighlight = array(); foreach ($fontColorList as $fontColor) { // Fore color $editorDataAttr = '{"action":"color","value":"' . $fontColor . '"}'; $toolbarDropdownFontColor[] = array('edit' => 'basic', 'action' => 'color', 'type' => 'button', 'html_tag' => 'span', 'attr' => array('class' => 'color cell-color-' . $fontColor . ' editor-dialog-fire-close', 'data-wysihtml5-command' => 'foreColor', 'data-wysihtml5-command-value' => $fontColor, 'data-editor' => $editorDataAttr)); // Highlight color if ($fontColor == 'black') { $fontColor = 'white'; } $editorDataAttrHighlight = '{"action":"highlightcolor","value":"' . $fontColor . '"}'; $toolbarDropdownFontColorHighlight[] = array('edit' => 'basic', 'action' => 'highlightcolor', 'type' => 'button', 'html_tag' => 'span', 'attr' => array('class' => 'color cell-color-' . $fontColor . ' editor-dialog-fire-close', 'data-wysihtml5-command' => 'highlightcolor', 'data-wysihtml5-command-value' => $fontColor, 'data-editor' => $editorDataAttrHighlight)); } $toolbarColorGroups['text'] = $toolbarDropdownFontColor; if ($allowedEditorActions['highlightcolor']) { $toolbarColorGroups['highlight'] = $toolbarDropdownFontColorHighlight; } // Build formatting options $toolbarFormatOptions = array(); foreach ($fontFormatOptions as $editorAction => $actionValues) { $htmlTag = !empty($actionValues['html_tag']) ? $actionValues['html_tag'] : 'a'; $toolbarFormatOptions[] = array('edit' => 'format', 'action' => $editorAction, 'type' => 'button', 'text' => $actionValues['text'], 'html_tag' => $htmlTag, 'attr' => array('class' => "editor-action editor-action-{$editorAction} editor-dialog-fire-close {$actionValues['class']}", 'data-wysihtml5-command' => $actionValues['command'], 'data-wysihtml5-command-value' => $actionValues['value'], 'title' => $actionValues['text'], 'data-editor' => '{"action":"' . $editorAction . '","value":"' . $actionValues['value'] . '"}')); } // Build emoji dropdown from array. // Using CSS background images instead of img tag, because CSS images // do not download until actually displayed on page. display:none prevents browsers from loading the resources. $toolbarDropdownEmoji = array(); $emoji = Emoji::instance(); $emojiAliasList = $emoji->getEditorList(); foreach ($emojiAliasList as $emojiAlias => $emojiCanonical) { $emojiFilePath = $emoji->getEmojiPath($emojiCanonical); $editorDataAttr = '{"action":"emoji","value":' . json_encode($emojiAlias) . '}'; $toolbarDropdownEmoji[] = array('edit' => 'media', 'action' => 'emoji', 'type' => 'button', 'html_tag' => 'span', 'text' => $emoji->img($emojiFilePath, $emojiAlias), 'attr' => array('class' => 'editor-action emoji-' . $emojiCanonical . ' editor-dialog-fire-close emoji-wrap', 'data-wysihtml5-command' => 'insertHTML', 'data-wysihtml5-command-value' => ' ' . $emojiAlias . ' ', 'title' => $emojiAlias, 'data-editor' => $editorDataAttr)); } // Font family options. $toolbarFontFamilyOptions = array(); foreach ($fontFamilyOptions as $editorAction => $actionValues) { $htmlTag = !empty($actionValues['html_tag']) ? $actionValues['html_tag'] : 'a'; $toolbarFontFamilyOptions[] = array('edit' => 'fontfamily', 'action' => $editorAction, 'type' => 'button', 'text' => $actionValues['text'], 'html_tag' => $htmlTag, 'attr' => array('class' => "editor-action editor-action-{$editorAction} editor-dialog-fire-close {$actionValues['class']}", 'data-wysihtml5-command' => $actionValues['command'], 'data-wysihtml5-command-value' => $actionValues['value'], 'title' => $actionValues['text'], 'data-editor' => '{"action":"' . $actionValues['command'] . '","value":"' . $actionValues['value'] . '"}')); } // If enabled, just merge with current formatting dropdown. if ($allowedEditorActions['fontfamily']) { $toolbarFormatOptions = array_merge($toolbarFormatOptions, $toolbarFontFamilyOptions); } // Compile whole list of editor actions into single $editorToolbarAll array. // Once complete, loop through allowedEditorActions and filter out the actions that will not be allowed. $editorToolbarAll['bold'] = array('edit' => 'basic', 'action' => 'bold', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-bold editor-dialog-fire-close', 'data-wysihtml5-command' => 'bold', 'title' => t('Bold'), 'data-editor' => '{"action":"bold","value":""}')); $editorToolbarAll['italic'] = array('edit' => 'basic', 'action' => 'italic', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-italic editor-dialog-fire-close', 'data-wysihtml5-command' => 'italic', 'title' => t('Italic'), 'data-editor' => '{"action":"italic","value":""}')); $editorToolbarAll['strike'] = array('edit' => 'basic', 'action' => 'strike', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-strikethrough editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-command' => 'strikethrough', 'title' => t('Strikethrough'), 'data-editor' => '{"action":"strike","value":""}')); $editorToolbarAll['color'] = array('edit' => 'basic', 'action' => 'color', 'type' => $toolbarColorGroups, 'attr' => array('class' => 'editor-action icon icon-font editor-dd-color editor-optional-button', 'data-wysihtml5-command-group' => 'foreColor', 'title' => t('Color'), 'data-editor' => '{"action":"color","value":""}')); $editorToolbarAll['orderedlist'] = array('edit' => 'format', 'action' => 'orderedlist', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-list-ol editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-command' => 'insertOrderedList', 'title' => t('Ordered list'), 'data-editor' => '{"action":"orderedlist","value":""}')); $editorToolbarAll['unorderedlist'] = array('edit' => 'format', 'action' => 'unorderedlist', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-list-ul editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-command' => 'insertUnorderedList', 'title' => t('Unordered list'), 'data-editor' => '{"action":"unorderedlist","value":""}')); $editorToolbarAll['indent'] = array('edit' => 'format', 'action' => 'indent', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-indent-right editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-command' => 'indent', 'title' => t('Indent'), 'data-editor' => '{"action":"indent","value":""}')); $editorToolbarAll['outdent'] = array('edit' => 'format', 'action' => 'outdent', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-indent-left editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-command' => 'outdent', 'title' => t('Outdent'), 'data-editor' => '{"action":"outdent","value":""}')); $editorToolbarAll['sep-format'] = array('type' => 'separator', 'attr' => array('class' => 'editor-sep sep-headers editor-optional-button')); $editorToolbarAll['format'] = array('edit' => 'format', 'action' => 'headers', 'type' => $toolbarFormatOptions, 'attr' => array('class' => 'editor-action icon icon-paragraph editor-dd-format', 'title' => t('Format'), 'data-editor' => '{"action":"format","value":""}')); $editorToolbarAll['sep-media'] = array('type' => 'separator', 'attr' => array('class' => 'editor-sep sep-media editor-optional-button')); $editorToolbarAll['emoji'] = array('edit' => 'media', 'action' => 'emoji', 'type' => $toolbarDropdownEmoji, 'attr' => array('class' => 'editor-action icon icon-smile editor-dd-emoji', 'data-wysihtml5-command' => '', 'title' => t('Emoji'), 'data-editor' => '{"action":"emoji","value":""}')); $editorToolbarAll['links'] = array('edit' => 'media', 'action' => 'link', 'type' => array(), 'attr' => array('class' => 'editor-action icon icon-link editor-dd-link editor-optional-button', 'data-wysihtml5-command' => 'createLink', 'title' => t('Url'), 'data-editor' => '{"action":"url","value":""}')); $editorToolbarAll['images'] = array('edit' => 'media', 'action' => 'image', 'type' => array(), 'attr' => array('class' => 'editor-action icon icon-picture editor-dd-image', 'data-wysihtml5-command' => 'insertImage', 'title' => t('Image'), 'data-editor' => '{"action":"image","value":""}')); $editorToolbarAll['uploads'] = array('edit' => 'media', 'action' => 'upload', 'type' => array(), 'attr' => array('class' => 'editor-action icon icon-file editor-dd-upload', 'data-wysihtml5-command' => '', 'title' => t('Attach image/file'), 'data-editor' => '{"action":"upload","value":""}')); $editorToolbarAll['sep-align'] = array('type' => 'separator', 'attr' => array('class' => 'editor-sep sep-align editor-optional-button')); $editorToolbarAll['alignleft'] = array('edit' => 'format', 'action' => 'alignleft', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-align-left editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-command' => 'justifyLeft', 'title' => t('Align left'), 'data-editor' => '{"action":"alignleft","value":""}')); $editorToolbarAll['aligncenter'] = array('edit' => 'format', 'action' => 'aligncenter', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-align-center editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-command' => 'justifyCenter', 'title' => t('Align center'), 'data-editor' => '{"action":"aligncenter","value":""}')); $editorToolbarAll['alignright'] = array('edit' => 'format', 'action' => 'alignright', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-align-right editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-command' => 'justifyRight', 'title' => t('Align right'), 'data-editor' => '{"action":"alignright","value":""}')); $editorToolbarAll['sep-switches'] = array('type' => 'separator', 'attr' => array('class' => 'editor-sep sep-switches editor-optional-button')); $editorToolbarAll['togglehtml'] = array('edit' => 'switches', 'action' => 'togglehtml', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-source editor-toggle-source editor-dialog-fire-close editor-optional-button', 'data-wysihtml5-action' => 'change_view', 'title' => t('Toggle HTML view'), 'data-editor' => '{"action":"togglehtml","value":""}')); $editorToolbarAll['fullpage'] = array('edit' => 'switches', 'action' => 'fullpage', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-resize-full editor-toggle-fullpage-button editor-dialog-fire-close editor-optional-button', 'title' => t('Toggle full page'), 'data-editor' => '{"action":"fullpage","value":""}')); $editorToolbarAll['lights'] = array('edit' => 'switches', 'action' => 'lights', 'type' => 'button', 'attr' => array('class' => 'editor-action icon icon-adjust editor-toggle-lights-button editor-dialog-fire-close editor-optional-button', 'title' => t('Toggle lights'), 'data-editor' => '{"action":"lights","value":""}')); // Filter out disallowed editor actions foreach ($allowedEditorActions as $editorAction => $allowed) { if ($allowed && isset($editorToolbarAll[$editorAction])) { $editorToolbar[$editorAction] = $editorToolbarAll[$editorAction]; } } return $editorToolbar; }
/** * * * @param $Type * @param $ID * @param $QuoteData * @param bool $Format */ protected function formatQuote($Type, $ID, &$QuoteData, $Format = false) { // Temporarily disable Emoji parsing (prevent double-parsing to HTML) $emojiEnabled = Emoji::instance()->enabled; Emoji::instance()->enabled = false; if (!$Format) { $Format = c('Garden.InputFormatter'); } $Type = strtolower($Type); $Model = false; switch ($Type) { case 'comment': $Model = new CommentModel(); break; case 'discussion': $Model = new DiscussionModel(); break; default: break; } //$QuoteData = array(); if ($Model) { $Data = $Model->getID($ID); $NewFormat = $Format; if ($NewFormat == 'Wysiwyg') { $NewFormat = 'Html'; } $QuoteFormat = $Data->Format; if ($QuoteFormat == 'Wysiwyg') { $QuoteFormat = 'Html'; } // Perform transcoding if possible $NewBody = $Data->Body; if ($QuoteFormat != $NewFormat) { if (in_array($NewFormat, array('Html', 'Wysiwyg'))) { $NewBody = Gdn_Format::to($NewBody, $QuoteFormat); } elseif ($QuoteFormat == 'Html' && $NewFormat == 'BBCode') { $NewBody = Gdn_Format::text($NewBody, false); } elseif ($QuoteFormat == 'Text' && $NewFormat == 'BBCode') { $NewBody = Gdn_Format::text($NewBody, false); } else { $NewBody = Gdn_Format::plainText($NewBody, $QuoteFormat); } if (!in_array($NewFormat, array('Html', 'Wysiwyg'))) { Gdn::controller()->informMessage(sprintf(t('The quote had to be converted from %s to %s.', 'The quote had to be converted from %s to %s. Some formatting may have been lost.'), htmlspecialchars($QuoteFormat), htmlspecialchars($NewFormat))); } } $Data->Body = $NewBody; // Format the quote according to the format. switch ($Format) { case 'Html': // HTML $Quote = '<blockquote class="Quote" rel="' . htmlspecialchars($Data->InsertName) . '">' . $Data->Body . '</blockquote>' . "\n"; break; case 'BBCode': $Author = htmlspecialchars($Data->InsertName); if ($ID) { $IDString = ';' . htmlspecialchars($ID); } $QuoteBody = $Data->Body; // TODO: Strip inner quotes... // $QuoteBody = trim(preg_replace('`(\[quote.*/quote\])`si', '', $QuoteBody)); $Quote = <<<BQ [quote="{$Author}{$IDString}"]{$QuoteBody}[/quote] BQ; break; case 'Markdown': case 'Display': case 'Text': $QuoteBody = $Data->Body; // Strip inner quotes and mentions... $QuoteBody = self::_stripMarkdownQuotes($QuoteBody); $QuoteBody = self::_stripMentions($QuoteBody); $Quote = '> ' . sprintf(t('%s said:'), '@' . $Data->InsertName) . "\n" . '> ' . str_replace("\n", "\n> ", $QuoteBody) . "\n"; break; case 'Wysiwyg': $Attribution = sprintf(t('%s said:'), userAnchor($Data, null, array('Px' => 'Insert'))); $QuoteBody = $Data->Body; // TODO: Strip inner quotes... // $QuoteBody = trim(preg_replace('`(<blockquote.*/blockquote>)`si', '', $QuoteBody)); $Quote = <<<BLOCKQUOTE <blockquote class="Quote"> <div class="QuoteAuthor">{$Attribution}</div> <div class="QuoteText">{$QuoteBody}</div> </blockquote> BLOCKQUOTE; break; } $QuoteData = array_merge($QuoteData, array('status' => 'success', 'body' => $Quote, 'format' => $Format, 'authorid' => $Data->InsertUserID, 'authorname' => $Data->InsertName, 'type' => $Type, 'typeid' => $ID)); } // Undo Emoji disable. Emoji::instance()->enabled = $emojiEnabled; }
/** * Get the singleton instance of this class. * @return Emoji */ public static function instance() { if (Emoji::$instance === null) { Emoji::$instance = new Emoji(); } return Emoji::$instance; }
public static function Wysiwyg($Mixed) { static $CustomFormatter; if (!isset($CustomFormatter)) { $CustomFormatter = C('Garden.Format.WysiwygFunction', FALSE); } if (!is_string($Mixed)) { return self::To($Mixed, 'Wysiwyg'); } elseif (is_callable($CustomFormatter)) { return $CustomFormatter($Mixed); } else { // The text contains html and must be purified. $Formatter = Gdn::Factory('HtmlFormatter'); if (is_null($Formatter)) { // If there is no HtmlFormatter then make sure that script injections won't work. return self::Display($Mixed); } // HTML filter first $Mixed = $Formatter->Format($Mixed); // Links $Mixed = Gdn_Format::Links($Mixed); // Mentions & Hashes $Mixed = Gdn_Format::Mentions($Mixed); $Mixed = Emoji::instance()->translateToHtml($Mixed); return $Mixed; } }
/** * Default search functionality. * * @since 2.0.0 * @access public * @param int $Page Page number. */ public function index($Page = '') { $this->addJsFile('search.js'); $this->title(t('Search')); saveToConfig('Garden.Format.EmbedSize', '160x90', false); Gdn_Theme::section('SearchResults'); list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20)); $this->setData('_Limit', $Limit); $Search = $this->Form->getFormValue('Search'); $Mode = $this->Form->getFormValue('Mode'); if ($Mode) { $this->SearchModel->ForceSearchMode = $Mode; } try { $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit); } catch (Gdn_UserException $Ex) { $this->Form->addError($Ex); $ResultSet = array(); } catch (Exception $Ex) { LogException($Ex); $this->Form->addError($Ex); $ResultSet = array(); } Gdn::userModel()->joinUsers($ResultSet, array('UserID')); // Fix up the summaries. $SearchTerms = explode(' ', Gdn_Format::text($Search)); foreach ($ResultSet as &$Row) { $Row['Summary'] = SearchExcerpt(Gdn_Format::plainText($Row['Summary'], $Row['Format']), $SearchTerms); $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']); $Row['Format'] = 'Html'; } $this->setData('SearchResults', $ResultSet, true); $this->setData('SearchTerm', Gdn_Format::text($Search), true); if ($ResultSet) { $NumResults = count($ResultSet); } else { $NumResults = 0; } if ($NumResults == $Offset + $Limit) { $NumResults++; } // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More Results'; $this->Pager->LessCode = 'Previous Results'; $this->Pager->ClientID = 'Pager'; $this->Pager->configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::url($Search)); // if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { // $this->setJson('LessRow', $this->Pager->toString('less')); // $this->setJson('MoreRow', $this->Pager->toString('more')); // $this->View = 'results'; // } $this->canonicalUrl(url('search', true)); $this->render(); }
/** * Default search functionality. * * @since 2.0.0 * @access public * @param int $Page Page number. */ public function index($Page = '') { $this->addJsFile('search.js'); $this->title(t('Search')); saveToConfig('Garden.Format.EmbedSize', '160x90', false); Gdn_Theme::section('SearchResults'); list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20)); $this->setData('_Limit', $Limit); $Search = $this->Form->getFormValue('Search'); $Mode = $this->Form->getFormValue('Mode'); if ($Mode) { $this->SearchModel->ForceSearchMode = $Mode; } try { $ResultSet = $this->SearchModel->search($Search, $Offset, $Limit); } catch (Gdn_UserException $Ex) { $this->Form->addError($Ex); $ResultSet = array(); } catch (Exception $Ex) { LogException($Ex); $this->Form->addError($Ex); $ResultSet = array(); } Gdn::userModel()->joinUsers($ResultSet, array('UserID')); // Fix up the summaries. $SearchTerms = explode(' ', Gdn_Format::text($Search)); foreach ($ResultSet as &$Row) { $Row['Summary'] = searchExcerpt(htmlspecialchars(Gdn_Format::plainText($Row['Summary'], $Row['Format'])), $SearchTerms); $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']); $Row['Format'] = 'Html'; } $this->setData('SearchResults', $ResultSet, true); $this->setData('SearchTerm', Gdn_Format::text($Search), true); $this->setData('_CurrentRecords', count($ResultSet)); $this->canonicalUrl(url('search', true)); $this->render(); }
/** * Performs replacing operations on a HTML string. Usually for formatting posts. * Runs an HTML string through the links, mentions, emoji and spoilers formatters. * * @param $html An unparsed HTML string. * @return string The formatted HTML string. */ protected static function processHTML($html) { $html = Gdn_Format::links($html); $html = Gdn_Format::mentions($html); $html = Emoji::instance()->translateToHtml($html); $html = Gdn_Format::legacySpoilers($html); return $html; }
/** * Get the singleton instance of this class. * @return Emoji */ public static function instance() { if (Emoji::$instance === null) { Emoji::$instance = new Emoji(); Gdn::PluginManager()->CallEventHandlers(Emoji::instance(), 'Emoji', 'Init', 'Handler'); } return Emoji::$instance; }
function inputConvert($input = null) { App::import('Model', 'mobile_plugin.emoji'); $Emoji = new Emoji(); $carrier = $this->carrier; if (is_array($input)) { $output = array_map(array($this, __METHOD__), $input); } elseif ($carrier == 'PC') { $output = $input; } elseif ($carrier === 'docomo' || $carrier === 'softbank' || $carrier === 'kddi') { $carrierFields = array('docomo' => 'docomo_sjis', 'softbank' => 'softbank_utf', 'kddi' => 'kddi_sjis'); $field = $carrierFields[$carrier]; $cacheName = $field . 'ToUnicodes'; if (!($emojisAndUnicodes = Cache::read($cacheName))) { $tmpArray = $Emoji->find('all', array('fields' => array('id', $field))); $unicodes = Set::extract('/Emoji/id', $tmpArray); foreach ($unicodes as $value) { $emojisAndUnicodes['unicode'][] = '&#x' . $value . ';'; } unset($unicodes); $emojis = Set::extract('/Emoji/' . $field, $tmpArray); foreach ($emojis as $key => $value) { if (isset($value) && $value != '') { $emojisAndUnicodes['emoji'][] = 'BAD+' . $value; } else { $emojisAndUnicodes['emoji'][] = ''; } } unset($emojis); Cache::write($cacheName, $emojisAndUnicodes); } mb_substitute_character('long'); $output = mb_convert_encoding($input, 'UTF-8', 'SJIS'); $output = str_replace($emojisAndUnicodes['emoji'], $emojisAndUnicodes['unicode'], $output); $output = preg_replace('/BAD\\+([0-9A-F]{4})/', '', $output); } else { mb_substitute_character('long'); $output = mb_convert_encoding($input, 'UTF-8', 'SJIS'); $output = preg_replace('/BAD\\+([0-9A-F]{4})/', '', $output); } return $output; }