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; } } } }
/** * @param XenForo_View $view * @param $formCtrlName * @param $message * @param array $editorOptions * @param $showWysiwyg */ public static function editor_setup(XenForo_View $view, $formCtrlName, &$message, array &$editorOptions, &$showWysiwyg) { if ($showWysiwyg && XenForo_Application::getOptions()->sonnbXG_editorButtons) { $view->createOwnTemplateObject()->addRequiredExternal('css', 'sonnb_xengallery_editor'); $time = XenForo_Application::$time; $visitor = XenForo_Visitor::getInstance(); if ($formCtrlName !== 'signature' || $formCtrlName === 'signature' && $visitor->hasPermission('signature', 'sonnbXG_album')) { $editorOptions['json']['buttons']['insertAlbum'] = array('title' => new XenForo_Phrase('sonnb_xengallery_insert_album'), 'dialogUrl' => XenForo_Link::buildPublicLink('gallery/editor', null, array('type' => 'album', 'time' => $time))); } if ($formCtrlName !== 'signature' || $formCtrlName === 'signature' && ($visitor->hasPermission('signature', 'sonnbXG_photo') || $visitor->hasPermission('signature', 'sonnbXG_video'))) { $editorOptions['json']['buttons']['insertContent'] = array('title' => new XenForo_Phrase('sonnb_xengallery_insert_content'), 'dialogUrl' => XenForo_Link::buildPublicLink('gallery/editor', null, array('type' => 'content', 'time' => $time))); } } }