* @license PHP License * @package WB * @subpackage content */ /** * Load base class */ WBClass::load( 'WBContent' ); /** * Content component: Static * * @version 0.1.2 * @package WB * @subpackage content */ class WBContent_VCard extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'format' => 'html', 'datasource' => '', 'person' => '__all' ); /** * DS View * @var WBDatasource_View */ private $ds; /** * DS Renderer * @var WBDatasource_Renderer_Array */ private $randy; /** * run * * run component * * @return array parameter list */ public function run() { if (strstr($this->config['person'], '.')) { $tmp = explode('.', $this->config['person']); $ext = array_pop($tmp); switch (strtolower($ext)) { case 'vcard': case 'vcf': $this->config['format'] = 'vcf'; break; case 'html': $this->config['format'] = 'html'; break; default: array_push($tmp, $ext); $this->config['format'] = 'html'; break; } $this->config['person'] = implode('.', $tmp); } $this->randy = WBClass::create('WBDatasource_Renderer_Array'); $this->ds = WBClass::create('WBDatasource_View'); $this->ds->setRenderer($this->randy); $this->ds->render($this->config['datasource']); $list = $this->randy->getList(); if ('__all' == $this->config['person']) { $this->showList($list); } else { $this->showPerson($list); } if ('vcf' == $this->config['format']) { $this->download(); } return $this->config; } /** * Simply display list * * @param array list */ private function showList($list) { $tmpl = $this->config['format'] . 'list'; $this->loadTemplates($tmpl); $this->tmpl->addGlobalVars($this->config, 'CONFIG_'); $this->tmpl->addRows('list_entry', $list); } /** * Try to find person * * @param array $list */ private function showPerson($list) { $p = strtolower($this->config['person']); $v = array(); foreach ($list as $l) { if (strtolower($l['surname']) == $p) { $v = $l; break; } if (strtolower($l['surname'] . ',' . $l['forename']) == $p) { $v = $l; break; } if (strtolower($l['emaillocal']) == $p) { $v = $l; break; } } if (empty($v)) { $this->showList($list); } $tmpl = $this->config['format']; $this->loadTemplates($tmpl); $this->tmpl->addGlobalVars($this->config, 'CONFIG_'); $this->tmpl->addGlobalVars($v); } /** * Download VCard * * CAUTION: This method usually does not return! * If file exists, it will send file to browser and exit programme! */ protected function download() { $res = WBClass::create('WBResponse'); /** @var $res WBResponse */ // switch off compression - otherwise complete download files are loaded to RAM WBParam::set('wb/response/compress', 0); $res->addHeader('Content-Type', 'text/vcard; charset=utf-8'); $res->add($this->tmpl->getParsedTemplate('snippet')); $res->send($this->req); exit(0); } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { return $this->tmpl->getParsedTemplate('snippet'); } }