* @copyright 2004 by http://wombat.exit0.net * @package wombatSite * @subpackage */ /** * CMS Browser * * This is part of the administration area. This derived class is capable to display * pages like in the normal view mode. Additionally all content managed by SiteMaker CMS * is marked as editable. Hence a "button" which invokes the content editor allows * any administrator to change the content while browsing the "normal" web site. * * @version 1.3.0 * @package wombatSite * @subpackage admin */ class wbSite_Cms extends wbSite { /** * template folders * @var array $_tmplDir */ var $_tmplDir = array(); /** * content language * @var array $_contentLang */ var $_contentLang = 'C'; /** * constructor * * overwrites auth-confiuration (partially) * @access public */ function __construct() { parent::__construct(); $this->_tmplDir['site'] = wbFactory::getParam( 'baseDir' ) . '/templates'; $this->_tmplDir['admin'] = wbFactory::getParam( 'systemDir' ) . '/'. wbFactory::getParam( 'adminDir' ) . '/templates/SiteMaker'; // load special config $conf =& wbFactory::singleton( 'patConfiguration' ); $conf->loadConfig( 'siteMaker.xml' ); $auth = $conf->getConfigValue( 'auth' ); $conf->clearConfigValue(); foreach( $auth as $key => $value ) { $this->_config['auth'][$key] = $value; } } /** * run cms-editor * * @access public * @return boolean $result true on success * @todo add error handling! */ function process() { if( !isset( $this->_request['wbcm'] ) || !isset( $this->_request['action'] ) ) { // run in display mode return parent::process(); } // display editor $page = $this->_selectPage(); $this->_authenticate(); $this->_localize( 'wombat' ); $this->_authorize(); // shortcut to copyright notes if( $this->_request['action'] == 'copyright' ) { $this->_loadTemplates( 'cmHtml/copyright' ); $this->_tmpl->displayParsedTemplate( 'cmHtml' ); return true; } $this->_addGlobalContent(); if( !isset( $this->_request['part'] ) ) { // error handling } if( !isset( $this->_request['href'] ) ) { // error handling } $part = $this->_request['part']; $conf = $this->_page['content'][$part]; $href = $this->_request['href']; $cm =& wbFactory::singleton( 'wbContentManager' ); if( patErrorManager::isError( $cm ) ) { return $cm; } // use fake-tags! $res = $cm->setFetchmode( 'fake' ); if( patErrorManager::isError( $res ) ) { return $res; } $this->_tmpl->addGlobalVar( 'page', $page ); $this->_tmpl->addGlobalVar( 'part', $part ); $this->_tmpl->addGlobalVar( 'href', $href ); $this->_tmpl->addGlobalVar( 'title', $href ); $this->_loadTemplates( 'cmHtml/page' ); $action = $this->_request['action']; // select language if necessary if( count( $this->_config['languages'] ) > 1 ) { // changed language on user request if( isset( $this->_request['contentlang'] ) && in_array( $this->_request['contentlang'], $this->_config['languages'] ) ) { $this->_contentLang = $this->_request['contentlang']; $this->_sess->set( 'wb:contentlang', $this->_contentLang ); $this->_tmpl->addGlobalVar( 'content_lang', $this->_contentLang ); } // keep current langauge in session else if( $this->_sess->has( 'wb:contentlang' ) ) { $this->_contentLang = $this->_sess->get( 'wb:contentlang' ); $this->_tmpl->addGlobalVar( 'content_lang', $this->_contentLang ); } // start language selector as falback else { $action = 'language'; } } $cm->setLang( $this->_contentLang ); switch( $action ) { case 'copyright': // done in shortcut - see above break; case 'language': // langauge selector $this->_loadTemplates( 'cmHtml/language' ); $langs = array(); foreach( $this->_config['languages'] as $l ) { $flag = $l; if( $l != 'C' ) { $flag = substr( $l, 0, 2 ); } array_push( $langs, array( 'lang' => $l, 'flag' => $flag ) ); } $this->_tmpl->addRows( 'language_entry', $langs ); break; case 'activate': // activate content $result = $this->_checkEditorChief(); if( patErrorManager::isError( $result ) ) { return $result; } // authorisation completed if( $result ) { $cm->activateDraft( $href ); $eventCode = 'site:cms:activated:other'; $eventData = array( 'page' => $page, 'part' => $part, 'href' => $href ); $eventLink = array( 'app' => 'SiteMaker/Jump', 'page' => $page, 'part' => $part, 'href' => $href ); $eventMsg = _( 'Content of page "{PAGE}", part "{PART}" (name: {HREF}) activated.' ); if( $this->_config['locale'] == $this->_contentLang ) { $eventCode = 'site:cms:activated:lead'; $eventMsg = _( 'Leading content of page "{PAGE}", part "{PART}" (name: {HREF}) activated.' ); } wbEvent::trigger( $eventCode, $eventMsg, $eventData, $eventLink ); $this->_loadTemplates( 'cmHtml/activate' ); break; } wbDebugger::addMsg( WBSITE_DEBUG_SECTION, 'Not a editorchief! Module: "'. $module.'" Parameter: "'. $param.'"', 'Authorisation' ); break; case 'save': $title = $href; $html = $this->_request['html']; if( ini_get( 'magic_quotes_gpc' ) ) { $html = stripslashes( $html ); } $user = wbFactory::singleton( 'wbUser' ); $author = $user->getUserId(); $cm->saveContent( $title, $html, $author ); wbEvent::trigger( 'site:cms:saved', _( 'Content of page "{PAGE}", part "{PART}" (name: {HREF}) saved.' ), array( 'page' => $page, 'part' => $part, 'href' => $href, 'edtior' => $author ) ); $this->_loadTemplates( 'cmHtml/save' ); $result = $this->_checkEditorChief(); if( patErrorManager::isError( $result ) ) { return $result; } // authorisation completed if( $result ) { $this->_tmpl->addVar( 'cmHtml_content', 'auth', '_authorized' ); break; } break; case 'edit': default: $title = $href; $select = 'active'; // check if there is a draft already if( $cm->isDraft( $title ) ) { // display selector insted of editor if( !isset( $this->_request['select'] ) ) { $this->_displaySelect( $title ); break; } if( $this->_request['select'] === 'draft' ) { $select = 'draft'; } } // get content for editor if( $select === 'draft' ) { $con = $cm->getDraft( $title ); } else { $con = $cm->getContent( $title ); } // display editor $this->_loadTemplates( 'cmHtml/' . $part, true ); $config = $this->_tmpl->getParsedTemplate( 'cmHtml_editor' ); wbJSTools::includeJavascript( $config, 'code' ); wbJSTools::includeJavascript( 'initEditor();', 'onload' ); $this->_loadTemplates( 'cmHtml/edit' ); $this->_tmpl->addVars( 'cmHtml_content', $con ); break; } $this->_insertJavascript(); $this->_tmpl->displayParsedTemplate( 'cmHtml' ); // debug output if( wbDebugger::isActive() ) { if( $this->_sess->isNew() ) { wbDebugger::addMsg( WBSITE_DEBUG_SECTION, 'New session started', 'Session' ); } else { wbDebugger::addMsg( WBSITE_DEBUG_SECTION, $this->_sess->getCounter() . ' requests', 'Session' ); } wbDebugger::addMsg( WBSITE_DEBUG_SECTION, wbDebugger::getUtime( 'genesis', 1000, 6 ) . ' ms', 'Time elapsed' ); wbDebugger::printMsg(); } } /** * check whether user satisfy editor-chief authorisation * * * @access private * @return boolean $result true on success */ function _checkEditorChief() { if( !isset( $this->_config['auth']['editorchief'] ) ) { // no special chief is needed to approve the content return true; } $module = $this->_config['auth']['editorchief']['module']; $param = $this->_config['auth']['editorchief']['param']; $auth =& wbFactory::singleton( 'wbAuthorize' ); $auth->setRule( $module, $param ); if( $auth->checkAuthorisation() ) { return true; } wbDebugger::addMsg( WBSITE_DEBUG_SECTION, 'Not a editorchief! Module: "'. $module.'" Parameter: "'. $param.'"', 'Authorisation' ); return false; } /** * display selector * * * @access private * @param string $title * @return boolean $result true on success */ function _displaySelect( $title ) { $cm =& wbFactory::singleton( 'wbContentManager' ); $draft = $cm->getDraft( $title ); $con = $cm->getContent( $title ); $this->_loadTemplates( 'cmHtml/select' ); $this->_tmpl->addVar( 'cmHtml_content', 'title', $con['title'] ); $this->_tmpl->addVar( 'cmHtml_content', 'content', $con['content'] ); $this->_tmpl->addVar( 'cmHtml_content', 'draft', $draft['content'] ); return true; } /** * get content for action cmsHtml * * @access protected * @param array $conf confiuration for this part * @param string $part named content part * @param string $page named page * @return string $html */ function getContentCmsHtml( $conf, $part, $page ) { $cm =& wbFactory::singleton( 'wbContentManager' ); $cm->setLang( $this->_lang['lang'] ); if( patErrorManager::isError( $cm ) ) { return $cm; } if( !$this->_tmpl->exists( 'cmHtml_startbutton' ) ) { // add Javascript ... wbJSTools::includeJavascript( 'dom.js' ); wbJSTools::includeJavascript( '/admin/js/wbNut.js' ); wbJSTools::includeJavascript( 'nut.placeNuts();', 'onload' ); // read template $this->_loadTemplates( 'cmHtml/display' ); } $con = $cm->getContent( $conf['href'] ); if( patErrorManager::isError( $con ) ) { return $con; } $this->_tmpl->clearTemplate( 'cmHtml_startbutton', true ); $this->_tmpl->addVars( 'cmHtml_startbutton', $con ); $this->_tmpl->addVar( 'cmHtml_startbutton', 'part', $part ); $this->_tmpl->addVar( 'cmHtml_startbutton', 'href', urlencode( $conf['href'] ) ); $html = $this->_tmpl->getParsedTemplate( 'cmHtml_startbutton' ); unset( $con['content'] ); $this->_tmpl->addGlobalVars( $con, $part . '_' ); return $html; } /** * load templates * - wrapper for patTemplate-readTemplateFromInput() * allows to load tempaltes from systemDir admin-folder * * @access protected * @param string $name name of template file, without trailing '.tmpl' * @param boolean $site load templats from site folder * @return boolean $result true on success */ function _loadTemplates( $name, $site = false ) { if( $site ) { $this->_tmpl->readTemplatesFromInput( $name . '.tmpl' ); return true; } $this->_tmpl->setRoot( $this->_tmplDir['admin'] ); $this->_tmpl->readTemplatesFromInput( $name . '.tmpl' ); $this->_tmpl->setRoot( $this->_tmplDir['site'] ); return true; } } ?>