* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBFormProcessor'); /** * Xinha Dialog Module * * * * @version 0.2.0 * @package WB * @subpackage base */ abstract class WBXinha_Dialog extends WBFormProcessor { /** * session object * @var WBUser_Auth */ protected $user; /** * whether to use template engine or not * @var bool */ protected $withFormTmpl = true; /** * template engine * @var patTemplate */ protected $tmpl; /** * template folder to use * @var string */ protected $tmplDir; /** * selected HTML (in editor) * @var string */ protected $select; /** * current string value, if any (this is just a helper...) * @var string */ protected $value; /** * HTML node's attributes * @var array */ protected $att = array(); /** * HTML to insert into editor * @var string */ protected $insert; /** * constructor * * Configure template folder by class name * * Instantiate a vew standard objects * - req: request object * - tmpl: template engine patTemplate * - user: current user * * Make sure all subclasses execute this constructor */ public function __construct() { $this->tmplDir = 'Xinha/dialog/' . strtolower(substr(get_class($this), strlen(__CLASS__) +1)); $this->tmplDir = $this->tmplDir; WBClass::load('WBUser_Auth'); $this->user = WBUser_Auth::getCurrent(); $this->req = WBClass::create('WBRequest'); $this->tmpl = WBClass::create('patTemplate'); } /** * set selected stirng * * Tell dialog what is currently selected in the editor * * @param $select */ public function setSelect($select) { $this->select = $select; $this->tmpl->addGlobalVar('DIALOG_SELECT', $select); } /** * set attributes * * @param $attributes */ public function setAttributes($attributes) { if (empty($attributes)) { return; } $this->att = $attributes; } /** * get HTML note attribute, if there is any * * Get attribute value, if set return default value ohterwise * * @param string $name * @param string $dafault * @return string */ protected function getAttribute($name, $default = '') { if (!isset($this->att[$name])) { return $default; } return $this->att[$name]; } /** * get style attribute * * Extract named style attribute. Optionally, remove suffix and use default * value if style is not set. * * @param string $name * @param string suffix to strip * @param string $default value * @return string */ protected function getStyle($name, $suffix = null, $default = null) { $style = trim($this->getAttribute('style', '')); if (empty($style)) { return $default; } $style = explode(';', $style); $style = array_map('trim', $style); foreach ($style as $t) { $s = array_map('trim', explode(':', $t)); if ($s[0]!= $name) { continue; } if (count($s) == 1) { return true; } if (!empty($suffix) && substr($s[1], -strlen($suffix)) == $suffix) { return substr($s[1], 0, -strlen($suffix)); } return $s[1]; } return $default; } /** * set value string, if any * * This ist just a helper value that eases parsing of selected areas * * @param string $value */ public function setValue($value) { $this->value = $value; $this->tmpl->addGlobalVar('DIALOG_VALUE', $value); } /** * Run dialog * * @param bool $submit * @return bool whehther dialog was successful and may be closed */ abstract public function run($submit = true); /** * get HTML to insert * * @return string */ public function getInsertHtml() { return $this->insert; } /** * get dialog HTML * * HTML snippet to be inserted in form * * @return string */ public function getHtml() { return $this->tmpl->getParsedTemplate('snippet'); } protected function requireUser() { if ($this->user->isAuthenticated()) { return true; } $this->tmpl->readTemplatesFromInput('Xinha/anonymous.tmpl'); return false; } /** * load templates from file * * @param string $tmpl */ protected function loadTemplates($tmpl) { $tmpl = $this->tmplDir . '/' . $tmpl; return $this->tmpl->readTemplatesFromInput($tmpl . '.tmpl'); } /** * location of form config * * Form definitions are located in etc-default/xinha/deliag/*.xml * * @return string folder */ protected function getFormConfigDir() { return 'xinha/dialog'; } } ?>