* @license PHP License
* @package WB
* @subpackage service
*/
WBClass::load('WBService');
/**
* Deliver site's html
*
* @version 0.6.0
* @package WB
* @subpackage service
*/
class WBService_Site extends WBService
{
/**
* decide whether to select locale settings from path
* @var bool
*/
protected $useI18nFromPath = true;
/**
* Display
*
* @param int $status
* @param mixed $data to be send
* @param string $checksum
* @return bool true
*/
public function run(&$status, &$data, &$checksum = null)
{
// browser must revalidate
$this->res->setCacheControl(WBResponse::CACHECONTROL_MUSTREVALIDATE);
$this->res->setMaxAge(null);
// load page config
$params = $this->conf->get('content');
// keep path in session
$this->sess->set('wb.service.path.site', $this->req->path);
$this->processPath($params, $this->path);
$this->processPathRequest($params, $this->path);
$this->processEvents($params);
$this->addJavaScript();
$tmpl = WBClass::create('patTemplate');
/** @var $tmpl patTemplate */
$tmpl->readTemplatesFromInput($this->conf->get('skin/tmpl', 'main') . '.tmpl');
$this->cont = WBClass::create('WBContent_Composite');
$this->cont->configure( '', $params, array() );
$params = $this->cont->run();
$tmpl->addGlobalVar('area_content', $this->cont->getString());
$tmpl->addGlobalVars($this->cont->getBubbles());
$tmpl->addGlobalVar('area_head', WBHtml::get(WBHtml::AREA_HEAD));
$tmpl->addGlobalVar('area_foot', WBHtml::get(WBHtml::AREA_FOOT));
$tmpl->addGlobalVar('area_js_onload', WBHtml::get(WBHtml::AREA_JS_ONLOAD));
$data = $tmpl->getParsedTemplate('page');
$status = $this->cont->getStatusCode();
$this->res->useCache($this->cont->isCachable());
// save parameters in session which allows to continue using AJAX
$paramName = md5($this->part . ':params:' . WBParam::get('wb/dir/base'));
$this->sess->set($paramName, $params);
$stat = WBClass::create('WBStatistic_View');
$stat->addPath(implode('/', $this->path));
$lt = WBClass::create('WBStatistic_LinkTracker');
$lt->add();
return true;
}
/**
* load prototypish javascipt files
*
* Originally Wombat used prootype.js. Hence all classes are
* base on prototype features. Still you can override this method
* to implement some custom WB-classes.
*
* This method loads the list of javascript includes from site.xml
* (depending on current part)
*
* @todo consider addeing more str_replace textes
*/
protected function addJavaScript()
{
WBClass::load('WBHtml_JS');
$javascript = $this->conf->get('javascript', array());
if (isset($javascript['include'])) {
if (!is_array($javascript['include'])) {
$javascript['include'] = array();
}
foreach ($javascript['include'] as $inc) {
WBHtml_JS::add($inc);
}
}
if (isset($javascript['onload'])) {
$search = array();
$replace = array();
if ($this->useI18n) {
$search[] = '{LANG_COMPLETE}';
$replace[] = patI18n::getLocale(patI18n::LOCALE_TYPE_COMPLETE);
}
$onload = str_replace($search, $replace, $javascript['onload']);
WBHtml_JS::add($onload, WBHtml_JS::AREA_ONLOAD);
}
}
/**
* process queued events
*
* @param array $params
* @return bool always true
*/
protected function processEvents(&$params)
{
$queue = $this->getEventQueue();
if (empty($queue)) {
return true;
}
$log = array(
'process' => 'event',
'part' => $this->part,
'path' => implode('/', $this->path),
'event' => '',
);
$allowed = $this->conf->get('events', array());
if (!is_array($allowed)) {
$allowed = array($allowed);
}
$conf = WBClass::create('WBConfig');
/** @var $conf WBConfig */
$conf->setLoader($this->conf->getLoader()->getName());
foreach ($queue as $q) {
if (!isset($allowed[$q['name']])) {
continue;
}
// override
if (!isset($allowed[$q['name']]['override'])) {
continue;
}
if (!$conf->load($this->part . '/event/' . $q['name'], true)) {
continue;
}
$log['event'] = $q['name'];
$this->log->notice($log);
$page = $conf->get();
$this->overrideAreas($params, $page, array());
}
$this->flushEventQueue();
return true;
}
}
?>