Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * Returns toolbar object
  * @param string $name toolbar name
  * @returns SpawToolbar
  * @static
  */
 function getToolbar($name)
 {
     $tb = new SpawToolbar($name);
     $tb->loadData();
     return $tb;
 }