public static function preloader($templateName, array &$params, XenForo_Template_Abstract $template) { switch ($templateName) { case 'help_bb_codes': $template->preloadTemplate('help_bbm_bbcodes'); break; case 'editor': /*** Templates Preloader ***/ if (XenForo_Application::get('options')->get('Bbm_Bm_ShowControllerInfo')) { $template->preloadTemplate('bbm_editor_extra_info'); } /*** ADD PARAMS TO THE EDITOR TEMPLATE ***/ $options = XenForo_Application::get('options'); if ($template instanceof XenForo_Template_Admin && !$options->Bbm_Bm_SetInAdmin) { break; } $controllerName = self::getParam('controllerName', $params); $controllerAction = self::getParam('controllerAction', $params); $viewName = self::getParam('viewName', $params); $extraParams = BBM_Helper_Buttons::getConfig($controllerName, $controllerAction, $viewName); /*** Merge extra params to template params > The first method is to use the array + operator - params of first element overrides params of second element > The second method is to use the array_merge function - params of second element should overrides params of the first unless if the key is a figure (if I understood the php documentation) Selected method: first Reason: it is said to be faster **/ $params = $extraParams + $params; // First method //$params = array_merge($params,$extraParams); // Second method break; case 'forum_edit': if ($template instanceof XenForo_Template_Admin && XenForo_Application::get('options')->get('Bbm_Bm_Forum_Config')) { $template->preloadTemplate('bbm_forum_edit_bbm_editor'); } break; case 'home': if ($template instanceof XenForo_Template_Admin) { $template->preloadTemplate('bbm_admin_icon'); } break; } }
public static function addRedactorButtons(XenForo_View $view, $formCtrlName, &$message, array &$editorOptions, &$showWysiwyg) { if (!$showWysiwyg) { return false; } $xenOptions = XenForo_Application::get('options'); if ($xenOptions->bbm_debug_tinymcehookdisable) { return false; } $template = $view->createOwnTemplateObject(); $controllerName = $template->getParam('controllerName'); $controllerAction = $template->getParam('controllerAction'); $viewName = $template->getParam('viewName'); $bbmParams = BBM_Helper_Buttons::getConfig($controllerName, $controllerAction, $viewName); if (empty($bbmParams['bbmButtonsJsGridArray'])) { //We must be here with Quattro return false; } $bbmButtonsJsGrid = $bbmParams['bbmButtonsJsGridArray']; $bbmCustomButtons = $bbmParams['bbmCustomButtons']; if (!isset($editorOptions['json']['buttons'])) { //Make this as an array to avoid any errors below $editorOptions['json']['buttons'] = array(); } $jsonButtons =& $editorOptions['json']['buttons']; $extendedButtonsBackup = array(); /** * Filter buttons grid */ $allGridButtons = array(); if (!empty($bbmButtonsJsGrid)) { foreach ($bbmButtonsJsGrid as &$buttonGroup) { foreach ($buttonGroup as $key => $button) { if (!self::filterButton($button, $editorOptions, $editorOptions, $showWysiwyg)) { unset($buttonGroup[$key]); continue; } array_push($allGridButtons, $button); } } } /** * XenForo Custom BbCodes Manager Buttons */ if (!empty($editorOptions['json']['bbCodes'])) { $customBbCodesButtons = array(); foreach ($editorOptions['json']['bbCodes'] as $k => $v) { $customTag = "custom_{$k}"; if (!in_array($customTag, $allGridButtons) && self::filterButton($customTag, $editorOptions, $editorOptions, $showWysiwyg)) { $customBbCodesButtons[] = $customTag; } } if (!empty($customBbCodesButtons)) { $bbmButtonsJsGrid[] = $customBbCodesButtons; } } /** * Other addons Buttons Backup */ if (!empty($jsonButtons)) { $extendedButtonsBackup = $jsonButtons; } /** * Get BBM Custom Buttons */ if (is_array($bbmCustomButtons)) { foreach ($bbmCustomButtons as $button) { $tag = preg_replace('#^at_#', '', $button['tag']); $code = $button['code']; $desc = XenForo_Template_Helper_Core::jsEscape($button['description']); $opts = XenForo_Template_Helper_Core::jsEscape($button['tagOptions']); $content = XenForo_Template_Helper_Core::jsEscape($button['tagContent']); $separator = XenForo_Template_Helper_Core::jsEscape($button['separator']); $textButton = XenForo_Template_Helper_Core::jsEscape($button['textButton']); $faButton = XenForo_Template_Helper_Core::jsEscape($button['faButton']); $jsonButtons[$code] = array('title' => $desc, 'tag' => $tag, 'bbCodeOptions' => $opts, 'bbCodeOptionsSeparator' => $separator, 'bbCodeContent' => $content, 'textButton' => $textButton, 'faButton' => $faButton); } } /** * Let's put back the buttons from other addons at the end of the editor with the backup * Also check if some of these buttons have a bbm configuration to delete them from the backup */ if (!empty($extendedButtonsBackup) && is_array($extendedButtonsBackup)) { foreach ($jsonButtons as $buttonCode => $jsonButton) { if (isset($extendedButtonsBackup[$buttonCode])) { $jsonButtons[$buttonCode] = array_merge($jsonButtons[$buttonCode], $extendedButtonsBackup[$buttonCode]); unset($extendedButtonsBackup[$buttonCode]); } } if (!empty($extendedButtonsBackup)) { //Extend custom buttons $jsonButtons += $extendedButtonsBackup; //Extend buttons grid $extendedgrid = array(); foreach ($extendedButtonsBackup as $buttonCode => $extendedButton) { $extendedgrid[] = $buttonCode; } array_push($bbmButtonsJsGrid, $extendedgrid); } } if (empty($jsonButtons)) { //Let's put back as if it would have been if it was empty $jsonButtons = null; } /*Bbm Buttons Grid - will have to inject this with Javascript to be able to fully override the editor grid*/ $editorOptions['json']['bbmButtonConfig'] = $bbmButtonsJsGrid; /*** * Fallback if any problem occurs to have the most accurate editor configuration **/ if (empty($bbmButtonsJsGrid)) { return false; } if (empty($editorOptions['json']['buttonConfig'])) { $editorOptions['json']['buttonConfig'] = array(); } $xenDefaultButtonConfig =& $editorOptions['json']['buttonConfig']; if (XenForo_Application::get('options')->get('currentVersionId') < 1030031) { //XenForo 1.2 $xenConfigStack = array('basic' => array('bold', 'italic', 'underline', 'deleted'), 'extended' => array('fontcolor', 'fontsize', 'fontfamily'), 'link' => array('createlink', 'unlink'), 'align' => array('alignment'), 'list' => array('unorderedlist', 'orderedlist', 'outdent', 'indent'), 'indent' => array('outdent', 'indent'), 'block' => array('code', 'quote'), 'media' => array('media'), 'image' => array('image'), 'smilies' => array('smilies')); } else { //XenForo 1.3 beta1-beta2 $xenConfigStack = array('basic' => array('bold', 'italic', 'underline'), 'extended' => array('fontcolor', 'fontsize', 'fontfamily'), 'link' => array('createlink', 'unlink'), 'align' => array('alignment'), 'list' => array('unorderedlist', 'orderedlist', 'outdent', 'indent'), 'indent' => array('outdent', 'indent'), 'smilies' => array('smilies'), 'image' => array('image'), 'media' => array('media'), 'block' => array('insert')); } foreach ($xenConfigStack as $groupName => $stackBtnGroup) { foreach ($bbmButtonsJsGrid as $editorBtnGroup) { if (!is_array($editorBtnGroup)) { continue; } if (array_intersect($stackBtnGroup, $editorBtnGroup)) { /*** * At least one button has been found, the group then must be displayed, let's set the value to false to prevent to disable it **/ $xenConfigStack[$groupName] = false; break; } } } if (!empty($xenConfigStack)) { foreach ($xenConfigStack as $groupName => $stackBtnGroup) { if ($stackBtnGroup === false) { $xenDefaultButtonConfig[$groupName] = true; } else { $xenDefaultButtonConfig[$groupName] = false; } } } }
protected static function _mceOrXenDetectByConfigType($configs, $configType) { //May be not the best way to proceed but the easiest if (isset($configs['mce'][$configType])) { self::$editor = 'mce'; return 'mce'; } elseif (isset($configs['xen'][$configType])) { self::$editor = 'xen'; return 'xen'; } return false; }