* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBFormProcessor'); /** * Wxml Dialog Module * * @version 1.0.0 * @package WB * @subpackage base */ abstract class WBWxml_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 * @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() { $name = substr(get_class($this), strlen(__CLASS__) +1); $this->tmplDir = 'Wxml/dialog/' . strtolower($name); WBClass::load('WBUser_Auth'); $this->user = WBUser_Auth::getCurrent(); $this->req = WBClass::create('WBRequest'); $this->tmpl = WBClass::create('patTemplate'); $this->tmpl->addGLobalVar('PROCESSOR', 'WB.Wxml.Dialog.get()'); $this->tmpl->addGlobalVar('DIALOG_NAME', $name); } /** * Set value string, if any * * This ist just a helper value that eases parsing of selected areas * * @param string $value */ final public function setValue($value) { $this->value = $value; $this->tmpl->addGlobalVar('DIALOG_VALUE', $value); } /** * Set selected stirng * * Tell dialog what is currently selected in the editor * * @param $select */ final public function setSelect($select) { $this->select = $select; $this->tmpl->addGlobalVar('DIALOG_SELECT', $select); } /** * set attributes * * @param $attributes */ final public function setAttributes($attributes) { $this->att = array_merge($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 */ final 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 */ final 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; } /** * Start dialog * * @return bool whehther dialog was successful and may be closed */ public function start() { return $this->submit(); } /** * Submit function * * Default implementation: process form * @param array $values */ public function submit($values = array()) { $clazz = strtolower(substr(get_class($this), strlen(__CLASS__) +1)); $this->processForm($clazz, $values); } /** * get dialog HTML * * HTML snippet to be inserted in form * * @return string */ public function getHtml() { return $this->tmpl->getParsedTemplate('snippet'); } /** * load templates from file * * @param string $tmpl */ final 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/wxml/deliag/*.xml * * @return string folder */ final protected function getFormConfigDir() { return 'wxml/dialog'; } }