some text here'; // print text area element * * $oEditor = BxDolEditor::getObjectInstance(); // get default editor object instance * if ($oEditor) // check if editor is available for using * echo $oEditor->attachEditor ('#my_textarea', BX_EDITOR_STANDARD); // output HTML which will automatically apply editor to textarea element by its id * @endcode * */ class BxDolEditor extends BxDolFactory implements iBxDolFactoryObject { protected $_sObject; protected $_aObject; protected $_sConfCustom = ''; protected $_sButtonsCustom = false; protected $_sPluginsCustom = false; protected $_sSkin; protected $_aSkins; /** * Constructor * @param $aObject array of editor options */ protected function __construct($aObject) { parent::__construct(); $this->_sObject = $aObject['object']; $this->_aObject = $aObject; $this->_sSkin = !empty($aObject['skin']) ? $aObject['skin']: ''; $this->_aSkins = array(); } /** * Get editor object instance by object name * @param $sObject object name * @return object instance or false on error */ static public function getObjectInstance($sObject = false, $oTemplate = false) { if (!$sObject) $sObject = getParam('sys_editor_default'); if (isset($GLOBALS['bxDolClasses']['BxDolEditor!'.$sObject])) return $GLOBALS['bxDolClasses']['BxDolEditor!'.$sObject]; $aObject = BxDolEditorQuery::getEditorObject($sObject); if (!$aObject || !is_array($aObject)) return false; if (empty($aObject['override_class_name'])) return false; $sClass = $aObject['override_class_name']; if (!empty($aObject['override_class_file'])) require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']); $o = new $sClass($aObject, $oTemplate); return ($GLOBALS['bxDolClasses']['BxDolEditor!'.$sObject] = $o); } /** * Get object name */ public function getObjectName () { return $this->_sObject; } /** * Set custom editor configuration options */ public function setCustomConf ($s) { $this->_sConfCustom = $s; } /** * Set custom plugins */ public function setCustomPlugins ($sPlugins) { $this->_sPluginsCustom = $sPlugins; } /** * Set custom toolbar */ public function setCustomToolbarButtons ($sButtons) { $this->_sButtonsCustom = $sButtons; } /** * Get minimal width which is neede for editor for the provided view mode */ public function getWidth ($iViewMode) { // override this function in particular editor class } /** * Get a list of available skins. */ public function getSkins($bFullInfo = false) { if($bFullInfo) return $this->_aSkins; $aResults = array(); foreach($this->_aSkins as $aSkin) $aResults[] = array('key' => $aSkin['name'], 'value' => _t($aSkin['title'])); return $aResults; } public function setSkin($sSkin) { if(!in_array($sSkin, array_keys($this->_aSkins))) return; $this->_sSkin = $sSkin; } /** * Attach editor to HTML element, in most cases - textarea. * @param $sSelector - jQuery selector to attach editor to. * @param $iViewMode - editor view mode: BX_EDITOR_STANDARD, BX_EDITOR_MINI, BX_EDITOR_FULL * @param $bDynamicMode - is AJAX mode or not, the HTML with editor area is loaded dynamically. * @param $aAttrs - array of additional attributes/parameters */ public function attachEditor ($sSelector, $iViewMode, $bDynamicMode = false, $aAttrs = []) { // override this function in particular editor class } /** * Get HTML editors info. * @param $sSelector - jQuery selector to attach editor to. * @param $iViewMode - editor view mode: BX_EDITOR_STANDARD, BX_EDITOR_MINI, BX_EDITOR_FULL * @param $bDynamicMode - is AJAX mode or not, the HTML with editor area is loaded dynamically. * @param $aAttrs - array of additional attributes/parameters */ public function getEditorInfo ($sSelector, $iViewMode, $bDynamicMode = false, $aAttrs = []) { // override this function in particular editor class return []; } /** * Add css/js files which are needed for editor display and functionality. */ protected function _addJsCss ($bDynamicMode = false) { // override this function in particular editor class } /** * Replace provided markers string. * @param $s - string to replace markers in * @param $a - markers array * @return string with replaces markers */ protected function _replaceMarkers ($s, $a) { if (empty($s) || empty($a) || !is_array($a)) return $s; return bx_replace_markers($s, $a); } } /** @} */