* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBEvent_Handler'); /** * WBEvent_Handler_Dereferencer * * Update references of some WXML content * * @version 0.4.0 * @package Wombat * @subpackage base */ class WBEvent_Handler_Dereferencer extends WBEvent_Handler { /** * handler config * * - source name of source (like "blog" or "wxmlarticle" resp. "wxmlarticletranslation") * * @var array */ protected $config = array( 'source' => '', ); /** * markup scanner * @var WBMarkup_Scanner */ private $scanner; /** * markup scanner handler dereferer * @var WBMarkup_Hander_Dereferer */ private $dref; /** * update column in table * * Update exactly one column in one table for one row using primary key * Hence primary key is required, as well as column and table name. * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { $url = $this->getUrlAndPath($e); $this->scanner = WBClass::create( 'WBMarkup_Scanner' ); $this->dref = WBClass::create( 'WBMarkup_Handler_Dereferer' ); $this->scanner->setHandler($this->dref); $this->scanner->scan($e->get('body')); $this->dref->setUrl($url[0], $url[1]); $this->dref->save(); return true; } /** * get URL and path * * Tell URL and path for current source * * @param WBEvent $e * @return array */ private function getUrlAndPath(WBEvent $e) { if (empty($this->config['source'])) { WBClass::load('WBException_Config'); throw new WBException_Config('Source must not be empty!', 1, __CLASS__); } $url = ''; $path = ''; switch ($this->config['source']) { case 'blog': $url = $this->getUrl4Blog($e); break; case 'wxmlarticle': case 'wxmlarticletranslation': $url = $e->get('url'); $path = $e->get('cs') . '/' . $e->get('lang', 'C'); break; default: WBClass::load('WBException_Config'); throw new WBException_Config('Source name is invalid!', 2, __CLASS__); break; } return array($url, $path); } /** * get blog article's URL * * Use blog-config to build proper URL * * @return string */ private function getUrl4Blog(WBEvent $e) { WBClass::load('WBString'); $blog = WBClass::create('WBBlog_Tool'); /** @var $blog WBBlog_Tool */ $blog->loadArticleByData($e->get()); $url = $blog->getArticleUrl(); return WBString::replaceSuperPlaceholders($url); } } ?>