* @copyright 2005 by http://wombat.exit0.net * @package wombatModule * @subpackage Blogger */ /** * Blogger can display simple lists * * @version 1.1.0 * @package wombatModule * @subpackage Blogger */ class wbModule_Blogger extends wbModule { /** * Blogger Parameters * * -tmpldir location of template files * -blog the blog to be used - this must be set! * * @access private * @var array $_params */ var $_params = array( 'tmpldir' => 'module/Blogger', 'blog' => null, 'id' => null, ); /** * some request defaults * * @access private * @var array $_params */ var $_requestDefaults = array( 'goto' => 'current', 'action' => 'list', 'id' => null ); /** * Blogger config * * @access private * @var array $_config */ var $_config = null; /** * configBlog * * @access private * @var array $_configBlog */ var $_configBlog = null; /** * datasource * * @access private * @var object $_ds */ var $_ds; /** * load required objects * * @access public * @return boolean $result true on success */ function __construct() { $this->_ds =& wbFactory::singleton( 'wbDatasource' ); $this->_ds->setCallback( $this ); $this->_tmpl =& wbFactory::singleton( 'patTemplate' ); $conf =& wbFactory::singleton( 'patConfiguration' ); $conf->loadConfig( 'blogger.xml' ); $this->_config = $conf->getConfigValue(); if( empty( $this->_config ) ) { wbDebugger::addMsg( 'Blogger', 'Empty configuration, check "blogger.xml"', 'Config' ); } } /** * constructor wrapper for PHP4 * * @access public * @see __construct() */ function wbModule_Blogger() { $this->__construct(); } /** * recieve content * * * * @return string $html */ function getHtml() { // blog must be set! if( empty( $this->_params['blog'] ) ) { return patErrorManager::raiseError( 'wbModule:Blogger:1', 'Cannot process Bloggger', 'Configuration error - parameter "blog" is required!' ); } if( !isset( $this->_config[$this->_params['blog']] ) ) { return patErrorManager::raiseError( 'wbModule:Blogger:2', 'Cannot process Bloggger', 'Could not find blog "'. $this->_params['blog'] .'" in configuratoin' ); } $this->_configBlog =& $this->_config[$this->_params['blog']]; // use preselected entry from parameter? if( $this->_params['id'] ) { return $this->_getView( $this->_params['id'] ); } switch( strtolower( $this->_request['action'] ) ) { case 'view': return $this->_getView( $this->_request['id'] ); break; default: return $this->_getList(); break; } // this should never happen return true; } /** * display details of news entry * * requires id, id may be either the primary key or "first" * * @access public * @param int $id * @return string $html */ function _getView( $id ) { if( !$id ) { wbDebugger::addMsg( 'Blogger', 'No id given - fallback to list-view', 'Details' ); return $this->_getList(); } // named ids? $entry = $this->_ds->getEntry( $this->_configBlog['table'], $id ); if( patErrorManager::isError( $entry ) ) { return $entry; } $this->_loadTemplates( 'view' ); $this->_tmpl->addVars( 'wbModule_Blogger', $entry ); return $this->_tmpl->getParsedTemplate( 'wbModule_Blogger' ); } /** * display list * * @access public * @return string $html */ function _getList() { $pager = $this->_ds->getPager( $this->_configBlog['table'], $this->_request['goto'] ); if( patErrorManager::isError( $pager ) ) { return $pager; } $this->_tmpl->addGlobalVars( $pager, 'PAGER_' ); $offset = $pager['offset'] * $pager['limit']; $list = $this->_ds->getEntries( $this->_configBlog['table'], null, array(), $offset ); if( patErrorManager::isError( $list ) ) { return $list; } $this->_loadTemplates( 'list' ); $this->_tmpl->addRows( 'list_entry', $list ); return $this->_tmpl->getParsedTemplate( 'wbModule_Blogger' ); } /** * callback function * * @access public * @param string $table * @param array $data * @param int $id * @return boolean true */ function callForGetentries( $table, &$data, $id ) { $data['id'] = $id; return true; } /** * callback function * * @access public * @param string $table * @param array $data * @param int $id * @return boolean true */ function callForGetentry( $table, &$data, $id ) { $data['id'] = $id; return true; } /** * callback function * * @access public * @param string $table * @param array $data * @param int $id * @return boolean true */ function callForSave( $table, &$data, $id ) { return true; } } ?>