/** * Returns HTML and JavaScript code for the editor * @returns string */ function getHtml() { $res = ''; $this->setDefaults(); if (SpawAgent::getAgent() != SPAW_AGENT_UNSUPPORTED) { // supported browser $head_res = ''; $js_res = ''; $html_res = ''; $ssent =& SpawEditor::scriptSent(); if (!$ssent) { $head_res .= '<script type="text/javascript" src="' . SpawConfig::getStaticConfigValue("SPAW_DIR") . 'js/spaw.js.php" charset="utf-8"></script>'; $js_res .= 'SpawEngine.setSpawDir("' . SpawConfig::getStaticConfigValue("SPAW_DIR") . '");'; $ssent = true; } $objname = $this->name . '_obj'; $js_res .= 'var ' . $objname . ' = new SpawEditor("' . $this->name . '");'; $js_res .= 'SpawEngine.registerEditor(' . $objname . ');'; $js_res .= $objname . '.setTheme(SpawTheme' . $this->theme->name . ');'; $js_res .= $objname . '.setLang("' . $this->lang->lang . '");'; $js_res .= $objname . '.setOutputCharset("' . $this->lang->getOutputCharset() . '");'; $js_res .= $objname . '.stylesheet = "' . $this->stylesheet . '";'; $js_res .= $objname . '.scid = "' . $this->config->storeSecureConfig() . '";'; // add javascript or request uri config items $reqstr = ''; foreach ($this->config->config as $cfg) { if ($cfg->transfer_type & SPAW_CFG_TRANSFER_JS && is_scalar($cfg->value)) { if (is_numeric($cfg->value)) { $js_res .= $objname . '.setConfigValue("' . $cfg->name . '", ' . $cfg->value . ');'; } else { if (is_bool($cfg->value)) { $js_res .= $objname . '.setConfigValue("' . $cfg->name . '", ' . ($cfg->value ? 'true' : 'false') . ');'; } else { // string $js_res .= $objname . '.setConfigValue("' . $cfg->name . '", "' . $cfg->value . '");'; } } } if ($cfg->transfer_type & SPAW_CFG_TRANSFER_REQUEST && is_scalar($cfg->value)) { if (is_bool($cfg->value)) { $reqstr .= '&' . $cfg->name . '=' . ($cfg->value ? 'true' : 'false'); } else { // string, number $reqstr .= '&' . $cfg->name . '=' . $cfg->value; } } } if ($reqstr != '') { } $js_res .= $objname . '.setConfigValue("__request_uri", "' . $reqstr . '");'; $tpl = ''; // template $fedtpl = ''; // editor template in floating mode $other_present = false; $tbfrom = $this->getToolbarFrom(); // parse template if (!$this->getFloatingMode()) { // standard mode $tpl = $this->theme->getTemplate(); } else { // floating mode $tpl = '<span id="' . $this->name . '_toolbox" '; $tpl .= ' style="z-index: 10000; position: absolute; cursor: move;"'; $tpl .= ' onMouseDown="' . $objname . '.floatingMouseDown(event);"'; $tpl .= ' >'; $tpl .= $this->theme->getTemplateToolbar(); $tpl .= '</span>'; $tpl .= $this->theme->getTemplateFloating(); } // if this is the main toolbar instance, add toolbars if ($tbfrom->name == $this->name) { foreach ($this->toolbars as $key => $tb) { if (strpos($tpl, '{SPAW TB=' . strtoupper($key) . '}')) { // toolbar placeholder found $tpl = preg_replace('/(\\{SPAW TB=' . strtoupper($key) . '\\})(.*)(\\{SPAW TOOLBAR\\})(.*)(\\{\\/SPAW TB\\})/sU', '$2' . $tb->renderToolbar($this->name, $this->theme) . '$4', $tpl); } else { // add to other toolbar placeholder $tpl = preg_replace('/(\\{SPAW TB=_OTHER\\})(.*)(\\{SPAW TOOLBAR\\})(.*)(\\{\\/SPAW TB\\})/sU', '$1$2' . $tb->renderToolbar($this->name, $this->theme) . '{SPAW TOOLBAR}$4$5', $tpl); $other_present = true; } } } elseif ($this->getFloatingMode() && $this->toolbar_from->name != $this->name) { // editor template for floating mode slave $tpl = $this->theme->getTemplateFloating(); } // replace all spaw dir references $tpl = str_replace("{SPAW DIR}", SpawConfig::getStaticConfigValue("SPAW_DIR"), $tpl); if ($this->getFloatingMode()) { $js_res .= $objname . '.floating_mode = true;'; } // register this editor as controlled by other editors toolbar $js_res .= $tbfrom->name . '_obj.addControlledEditor(' . $objname . ');' . "\n"; $js_res .= $objname . '.controlled_by = ' . $tbfrom->name . '_obj;' . "\n"; // remove unused toolbars if ($other_present) { // remove other toolbar tags leaving inner content intact $tpl = preg_replace('/(\\{SPAW TB=_OTHER\\})(.*)(\\{SPAW TOOLBAR\\})(.*)(\\{\\/SPAW TB\\})/sU', '$2$4', $tpl); } // remove all toolbar tags and inner code $tpl = preg_replace('/(\\{SPAW TB=[^\\}]*\\})(.*)(\\{\\/SPAW TB\\})/sU', '', $tpl); // pages and tabs // setup tab templates $tabtpl = ''; $atabtpl = ''; if (sizeof($this->pages) > 1) { // tab template if (preg_match("/(\\{SPAW TABSTRIP\\})(.*)(\\{SPAW TAB\\})(.*)(\\{\\/SPAW TAB\\})(.*)(\\{\\/SPAW TABSTRIP\\})/sU", $tpl, $matches)) { $tabtpl = $matches[4]; } // active tab template if (preg_match("/(\\{SPAW TABSTRIP\\})(.*)(\\{SPAW TAB ACTIVE\\})(.*)(\\{\\/SPAW TAB\\})(.*)(\\{\\/SPAW TABSTRIP\\})/sU", $tpl, $matches)) { $atabtpl = $matches[4]; } // remove tabstrip markers and mark tab place $tpl = preg_replace('/(\\{SPAW TABSTRIP\\})(.*)(\\{\\/SPAW TABSTRIP\\})/sU', '$2', $tpl); $tpl = preg_replace('/(\\{SPAW TAB ACTIVE\\})(.*)(\\{\\/SPAW TAB\\})/sU', '{SPAW TABS}', $tpl); $tpl = preg_replace('/(\\{SPAW TAB\\})(.*)(\\{\\/SPAW TAB\\})/sU', '', $tpl); } else { // tabs not needed, remove tab strip $tpl = preg_replace('/(\\{SPAW TABSTRIP\\})(.*)(\\{\\/SPAW TABSTRIP\\})/sU', '', $tpl); } // mode strip if (strpos($tpl, '{SPAW MODESTRIP}')) { if ($this->isModeStripVisible()) { // modestrip placeholder found $mstrip = SpawToolbar::getToolbar("mode_strip"); $mstrip->editor =& $this; $tpl = preg_replace('/(\\{SPAW MODESTRIP\\})(.*)(\\{SPAW MODES\\})(.*)(\\{\\/SPAW MODESTRIP\\})/sU', '$2' . $mstrip->renderToolbar($this->name, $this->theme) . '$4', $tpl); } else { // just remove the placeholder $tpl = preg_replace('/(\\{SPAW MODESTRIP\\})(.*)(\\{\\/SPAW MODESTRIP\\})/sU', '', $tpl); } } // statusbar if (strpos($tpl, '{SPAW STATUSBAR}')) { if ($this->isStatusBarVisible()) { // modestrip placeholder found if ($this->isResizingGripVisible() && $this->config->getConfigValue('resizing_directions') != 'none') { $grip = '<img src="' . SpawConfig::getStaticConfigValue("SPAW_DIR") . 'plugins/core/lib/theme/' . $this->theme->name . '/img/sizing_grip.gif" border="0" style="cursor: se-resize;"'; $grip .= ' onmousedown="' . $objname . '.resizingGripMouseDown(event);"'; $grip .= ' unselectable="on"'; $grip .= ' alt="" />'; } else { $grip = ''; } $tpl = preg_replace('/(\\{SPAW STATUSBAR\\})(.*)(\\{SPAW STATUS\\})(.*)(\\{SPAW SIZINGGRIP\\})(.*)(\\{\\/SPAW STATUSBAR\\})/sU', '$2<span id="' . $this->name . '_status"></span>$4' . $grip . '$6', $tpl); } else { // remove status bar placeholder $tpl = preg_replace('/(\\{SPAW STATUSBAR\\})(.*)(\\{\\/SPAW STATUSBAR\\})/sU', '', $tpl); } } $pagetpl = ''; $tabstpl = ''; foreach ($this->pages as $pname => $page) { $pagetpl .= '<textarea name="' . $page->inputName . '" id="' . $pname . '" style="width: 100%; height: ' . $this->height . '; display: none; overflow: scroll;" rows="10" cols="10">' . htmlspecialchars($page->value) . '</textarea>'; $js_res .= 'var ' . $pname . '_page = new SpawEditorPage("' . $pname . '","' . htmlspecialchars($page->caption) . '","' . $page->direction . '");' . "\n"; //$js_res .= $pname.'_page.value = "'.htmlspecialchars($page->value).'";'."\n"; $js_res .= $objname . '.addPage(' . $pname . '_page);' . "\n"; $js_res .= $objname . '.getTab("' . $pname . '").template = "' . addslashes(str_replace("{SPAW TAB CAPTION}", $page->caption, $tabtpl)) . '";' . "\n"; $js_res .= $objname . '.getTab("' . $pname . '").active_template = "' . addslashes(str_replace("{SPAW TAB CAPTION}", $page->caption, $atabtpl)) . '";' . "\n"; if ($this->name == $pname) { $js_res .= $objname . '.active_page =' . $pname . '_page;' . "\n"; } $pagetpl .= '<iframe name="' . $pname . '_rEdit" id="' . $pname . '_rEdit" style="width: 100%; height: ' . $this->height . '; display: ' . ($this->name == $pname ? 'inline' : 'none') . ';" frameborder="no" src="' . SpawConfig::getStaticConfigValue("SPAW_DIR") . 'empty/empty.html?' . microtime() . '"></iframe>'; $tabstpl .= '<span id="' . $pname . '_tab" style="cursor: default;" onclick="' . $objname . '.setActivePage(\'' . $pname . '\');">' . str_replace("{SPAW TAB CAPTION}", $page->caption, $pname == $this->name ? $atabtpl : $tabtpl) . '</span>'; } $tpl = str_replace('{SPAW EDITOR}', $pagetpl, $tpl); $tpl = str_replace('{SPAW TABS}', $tabstpl, $tpl); $html_res .= '<table border="0" cellpadding="0" cellspacing="0" id="' . $this->name . '_enclosure" class="' . $this->theme->name . '" style="padding: 0px 0px 0px 0px; width: ' . $this->width . ';"><tr><td>' . $tpl . '</td></tr></table>'; $js_res .= $objname . '.onLoadHookup();' . "\n"; $res = $head_res . '<script type="text/javascript">' . "\n<!--\n" . $js_res . "\n//-->\n" . '</script>' . $html_res; } else { // standard textarea fallback foreach ($this->pages as $pname => $page) { if (sizeof($this->pages) > 1) { $res .= '<label for="' . $pname . '">' . $page->caption . '</label><br />'; } $res .= '<textarea name="' . $pname . '" id="' . $pname . '" width="' . $this->width . '" height="' . $this->height . '" style="width: ' . $this->width . '; height: ' . $this->height . ';" wrap="off">' . htmlspecialchars($page->value) . '</textarea><br />'; } } return $res; }
/** * Returns string representation of current user agent to be used as part of file extension or dir name * @returns string * @static */ function getAgentName() { $result = ''; switch (SpawAgent::getAgent()) { case SPAW_AGENT_IE: $result = 'ie'; break; case SPAW_AGENT_GECKO: $result = 'gecko'; break; case SPAW_AGENT_OPERA: $result = 'opera'; break; case SPAW_AGENT_SAFARI: $result = 'safari'; break; default: $result = ''; break; } return $result; }
<?php /** * SPAW Editor v.2 Javascript file * * Outputs javascript code for the editor * @package spaw2 * @subpackage JavaScript * @author Alan Mendelevich <*****@*****.**> * @copyright UAB Solmetra */ header('Content-Type: application/x-javascript; charset=utf-8'); require_once str_replace('\\\\', '/', dirname(__FILE__)) . '/../config/config.php'; require_once str_replace('\\\\', '/', dirname(__FILE__)) . '/../class/util.class.php'; $spaw_root = SpawConfig::getStaticConfigValue("SPAW_ROOT"); $agent = SpawAgent::getAgentName(); // load main javascript for all browsers if (is_dir($spaw_root . 'js/common')) { if ($dh = opendir($spaw_root . 'js/common')) { while (($fn = readdir($dh)) !== false) { if ($fn != '.' && $fn != '..' && !is_dir($spaw_root . 'js/common/' . $fn)) { include $spaw_root . 'js/common/' . $fn; } } closedir($dh); } } // load main javascript specific for current browser if (is_dir($spaw_root . 'js/' . $agent)) { if ($dh = opendir($spaw_root . 'js/' . $agent)) { while (($fn = readdir($dh)) !== false) {
/** * Renders code for specified toolbar * @param string $prefix prefix to use for id's (editor name) * @param SpawTheme $theme theme/skin to use * @returns string */ function renderToolbar($prefix, $theme) { $js_res = ''; $html_res = '<span style="white-space: nowrap;">'; $pgdir = SpawConfig::getStaticConfigValue("SPAW_DIR") . 'plugins/'; $i = 0; if ($this->items) { foreach ($this->items as $obj) { if (is_object($obj) && $obj->agent & SpawAgent::getAgent()) { $id = $prefix . '_' . $this->name . '_' . $i; switch (strtolower(get_class($obj))) { case "spawtbimage": $js_res .= $prefix . '_obj.addToolbarItem(new SpawTbImage("' . $obj->module . '","' . $obj->name . '","' . $id . '"),"' . $this->name . '");'; $html_res .= '<img id="' . $id . '" src="' . $pgdir . $obj->module . '/lib/theme/' . $theme->name . '/img/tb_' . $obj->name . '.gif"'; if ($theme->isCustomStyleTbi($obj->name)) { $html_res .= ' style="' . $theme->getCustomTbiStyle($obj->name) . '"'; } elseif ($theme->getDefaultTbImageStyle()) { $html_res .= ' style="' . $theme->getDefaultTbImageStyle() . '"'; } if ($theme->isCustomCssClassTbi($obj->name)) { $html_res .= ' class="' . $theme->getCustomTbiCssClass($obj->name) . '"'; } elseif ($theme->getDefaultTbImageCssClass()) { $html_res .= ' class="' . $theme->getDefaultTbImageCssClass() . '"'; } $html_res .= ' alt="" />'; break; case "spawtbbutton": $img_src = $obj->module . '/lib/theme/' . $theme->name . '/img/tb_' . $obj->name . '.gif'; if (!file_exists(SpawConfig::getStaticConfigValue("SPAW_ROOT") . 'plugins/' . $img_src)) { // use default plugin button $img_src = 'core/lib/theme/' . $theme->name . '/img/tb__plugin.gif'; } $js_res .= $prefix . '_obj.addToolbarItem(new SpawTbButton("' . $obj->module . '","' . $obj->name . '","' . $id . '","' . $obj->on_enabled_check . '","' . $obj->on_pushed_check . '","' . $obj->on_click . '","' . $pgdir . $img_src . '",' . ($obj->show_in_context_menu ? "true" : "false") . '),"' . $this->name . '");'; $html_res .= '<img id="' . $id . '" src="' . $pgdir . $img_src . '"'; if ($theme->isCustomStyleTbi($obj->name)) { $html_res .= ' style="' . $theme->getCustomTbiStyle($obj->name) . ' cursor: default;"'; } elseif ($theme->getDefaultTbButtonStyle()) { $html_res .= ' style="' . $theme->getDefaultTbButtonStyle() . ' cursor: default;"'; } else { $html_res .= ' style="cursor: default;"'; } if ($theme->isCustomCssClassTbi($obj->name)) { $html_res .= ' class="' . $theme->getCustomTbiCssClass($obj->name) . '"'; } elseif ($theme->getDefaultTbButtonCssClass()) { $html_res .= ' class="' . $theme->getDefaultTbButtonCssClass() . '"'; } $html_res .= ' onclick="SpawPG' . $obj->module . '.' . $obj->on_click . '(' . $prefix . '_obj.getTargetEditor(),' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' onmouseover="' . $prefix . '_obj.theme.buttonOver(' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' onmouseout="' . $prefix . '_obj.theme.buttonOut(' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' onmousedown="' . $prefix . '_obj.theme.buttonDown(' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' onmouseup="' . $prefix . '_obj.theme.buttonUp(' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' alt="' . $this->editor->lang->m('title', $obj->name, $obj->module) . '"'; $html_res .= ' title="' . $this->editor->lang->m('title', $obj->name, $obj->module) . '"'; $html_res .= ' unselectable="on"'; $html_res .= ' />'; break; case "spawtbdropdown": if (empty($obj->data)) { // try getting data from config $obj->data = $this->editor->config->getConfigValue('dropdown_data_' . $obj->module . '_' . $obj->name); } if (is_array($obj->data)) { $js_res .= $prefix . '_obj.addToolbarItem(new SpawTbDropdown("' . $obj->module . '","' . $obj->name . '","' . $id . '","' . $obj->on_enabled_check . '","' . $obj->on_status_check . '","' . $obj->on_change . '"),"' . $this->name . '");'; $html_res .= '<select size="1" id="' . $id . '" '; if ($theme->isCustomStyleTbi($obj->name)) { $html_res .= ' style="' . $theme->getCustomTbiStyle($obj->name) . '"'; } elseif ($theme->getDefaultTbDropdownStyle()) { $html_res .= ' style="' . $theme->getDefaultTbDropdownStyle() . '"'; } if ($theme->isCustomCssClassTbi($obj->name)) { $html_res .= ' class="' . $theme->getCustomTbiCssClass($obj->name) . '"'; } elseif ($theme->getDefaultTbDropdownCssClass()) { $html_res .= ' class="' . $theme->getDefaultTbDropdownCssClass() . '"'; } $html_res .= ' onchange="SpawPG' . $obj->module . '.' . $obj->on_change . '(' . $prefix . '_obj.getTargetEditor(),' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' onmouseover="' . $prefix . '_obj.theme.dropdownOver(' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' onmouseout="' . $prefix . '_obj.theme.dropdownOut(' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' onmousedown="' . $prefix . '_obj.theme.dropdownDown(' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= ' onmouseup="' . $prefix . '_obj.theme.dropdownUp(' . $prefix . '_obj.getToolbarItem(\'' . $id . '\'), this);"'; $html_res .= '>'; $html_res .= '<option>' . $this->editor->lang->m('title', $obj->name, $obj->module) . '</option>'; foreach ($obj->data as $key => $value) { $html_res .= '<option value="' . $key . '">' . $value . '</option>'; } $html_res .= '</select>'; } } } $i++; } $html_res .= '</span>'; $res = '<script type="text/javascript">' . "\n<!--\n" . $js_res . "\n//-->\n" . '</script>' . $html_res; return $res; } }