public function build() { $sSelect = $this->readx('@select'); $sMode = $this->readx('@mode'); if ($sXMode = $this->readx('@xmode')) { $this->getHandler()->startXMode($sXMode); } $aArguments = $this->getTemplate()->parseArguments($this->getNode()->getChildren()); if ($sReflector = $this->readx('@reflector')) { $result = $this->buildReflector($sReflector, $sSelect, $sMode, $aArguments); } else { if ($sImport = $this->readx('@import')) { $result = $this->buildImport($sImport, $sSelect, $sMode, $aArguments); } else { $result = $this->buildDefault($sSelect, $sMode, $sXMode, $aArguments); } } $aResult = $this->getWindow()->parse($result, true); if (\Sylma::read('template/required') && !$result && !$aResult && $this->readx('@required')) { $this->launchException('Apply require a template'); } if ($sXMode) { $this->getHandler()->stopXMode(); } return $aResult; }
public function __construct($sValue) { if (Sylma::read('dom/encoding/check') && !mb_check_encoding($sValue, 'UTF-8')) { //$sValue = utf8_encode($sContent); // TODO , result not always in utf-8 $this->getParent()->throwException('Bad encoding'); } parent::__construct($sValue); }
public function asDOM() { $result = null; if ($aStyles = $this->loadContent()) { $bChildren = false; $doc = $this->buildDocument($aStyles, \Sylma::read('namespaces/html'), $bChildren); $result = $bChildren ? $doc->getChildren() : $doc->getRoot(); } return $result; }
public function checkConfig() { if (\Sylma::read('debug/enable')) { $this->launchException('Cannot test in debug mode'); } if (!$this->login()) { $sUser = implode(':', $this->aUser); $this->launchException("Test need a user authenticated with '{$sUser}'"); } }
protected function cleanValid(dom\handler $doc) { require_once 'dom/handler.php'; $cleaner = $this->getTemplate((string) $this->getFile()); $cleaned = $cleaner->parseDocument($doc); $iMode = 0; if (\Sylma::read('initializer/output/indent')) { $iMode = dom\handler::STRING_INDENT; } return $cleaned->asString($iMode); // | dom\handler::STRING_HEAD }
public function importDocument(dom\handler $doc, fs\file $file) { $bElement = \Sylma::read('template/debug/source'); if (!$file->getControler()->getName()) { foreach ($doc->queryx('//*') as $el) { $el->createAttribute('build:source', (string) $file, $this->getNamespace()); if ($bElement) { $el->createAttribute('build:element', $this->getManager('formater')->buildLink($el->asLink()), $this->getNamespace()); } } } return $doc; }
protected function buildContent() { $el = $this->getNode(); if (\Sylma::read('template/debug/source')) { unset($this->aAvoidNamespaces['builder']); } foreach ($el->getAttributes() as $attr) { if (!in_array($attr->getNamespace(), $this->aAvoidNamespaces)) { $sName = $this->buildName($attr->getName(), $attr->getNamespace()); $this->setDefaultAttribute($sName, $attr->getValue()); } } $this->resetAttributes(); parent::buildContent(); }
/** * * @param string $sEmail * @param type $sSubject * @param type $sMessage * @return string */ public function send($sFrom, $sEmail, $sSubject, $sMessage, $bHTML = false) { $sHeaders = "From: {$sFrom}\n"; if ($bHTML) { $sHeaders .= "Content-type: text/html; charset= utf-8\n"; } else { $sHeaders .= 'Content-type: text/plain; charset=utf-8'; } // text if (\Sylma::read('debug/email/enable')) { $sEmail = \Sylma::read('debug/email/default'); } $this->getManager(self::PARSER_MANAGER)->getContext('messages')->add(array('content' => 'Mail sent to ' . $sEmail)); return mail($sEmail, $sSubject, $sMessage, $sHeaders); }
protected function show($mVar) { $result = $this->createDocument(); $root = $result->addElement('ul', null, array(), \Sylma::read('namespaces/html')); if (is_array($mVar)) { foreach ($mVar as $item) { $root->addElement('li', $this->parseString($item)); } } else { if (is_string($mVar)) { $root->addElement('li', $this->parseString($mVar)); } else { $this->launchException('Cannot show var', get_defined_vars()); } } return $result; }
public function __construct(core\argument $args, core\argument $post, core\argument &$contexts) { $this->setDirectory(__FILE__); $this->setArguments($args); $this->setPost($post); $this->setSettings($this->getManager('init')->getArgument('window')); $messages = $this->initMessages(); $fusion = $this->get('fusion'); $load = new binder\context\Load(); $js = new context\JS(array('load' => $load), $fusion); $contexts = $this->createArgument(array('title' => array(), 'css' => new less\Context(array(), $fusion, $js), 'js-common' => new context\JS(array(), $fusion), 'js' => $js, 'errors' => $messages)); $this->setContexts($contexts); $load->set('objects', new \sylma\template\binder\context\Objects()); $this->setPaths($this->getArgument(self::CONTENT_ARGUMENT)->query()); $this->setArgument(self::CONTENT_ARGUMENT, null); $this->sHTML = \Sylma::read('render/namespaces/shtml/uri'); $this->setNamespaces(array('html' => $this->sHTML)); }
public function asString() { if ($this->getArguments()->query()) { $sContent = '<div xmlns="' . \Sylma::read('namespaces/html') . '">'; foreach ($this->getArguments() as $message) { if (is_array($message)) { $sContent .= $this->show($message); } else { $sContent .= $message->read('content'); } } $sContent .= '</div>'; $doc = $this->createDocument($sContent); $this->loadDefaultArguments(); $this->setDirectory(__FILE__); $tpl = $this->getTemplate('/#sylma/modules/html/cleaner.xsl'); $sResult = $tpl->parseDocument($doc)->asString(); } else { $sResult = ''; } return $sResult; }
protected function setErrorReporting() { error_reporting(\Sylma::read('exception/level')); libxml_use_internal_errors(false); }
protected function useLog() { return \Sylma::read('debug/parser'); }
public function stringToDOM($sValue, $bCollection = false) { $result = null; $sHTML = \Sylma::read('namespaces/html'); $doc = $this->createDocument("<div xmlns='{$sHTML}'>" . $sValue . '</div>'); if (!$doc->isEmpty()) { if (!$bCollection) { $result = $doc->getRoot()->getFirst(); } if ($doc->getRoot()->countChildren() > 1) { $result = $doc->getRoot()->getChildren(); } else { $result = $doc->getRoot()->getFirst(); } } return $result; }
/** * @uses \sylma\view\parser\Elemented::parseFromChild() */ protected function createSpacer($sID) { $parser = $this->getParser()->getParent(); return $parser->parseFromChild($this->createElement('span', '.', array('class' => "{$sID} spacer"), \Sylma::read('namespaces/html'), false)); }
public function checkRights($iMode) { if (!$this->getControler()->mustSecure() || \Sylma::read('debug/rights')) { return true; } if ($iMode & $this->getUserMode()) { return true; } return false; }
protected function getSessionKey() { return \Sylma::read('modules/captcha/session'); }
/** * @usedby /#sylma/core/test/basic.xml "PHP Error" test * @return string */ public static function getLogPath() { return \Sylma::read('exception/file'); }
public function isPrivate() { if (\Sylma::read('debug/rights')) { return true; } return $this->bPrivate; }
public static function renderTree(array $aArray, $sPrefix = '', $iDepth = 0) { $dom = \Sylma::getManager('dom'); $doc = $dom->createDocument(); $result = $doc->addElement('div', null, array(), \Sylma::read('namespaces/html')); $iCount = 0; foreach ($aArray as $sKey => $mValue) { if (is_array($mValue)) { if (array_key_exists(0, $mValue)) { list($iRealCount, $children) = self::renderTree(array($sKey => $mValue[0]), $sPrefix, $iDepth + 1); $result->add($children); unset($mValue[0]); } else { $iRealCount = 0; } list($iSubCount, $children) = self::renderTree($mValue, $sPrefix . $sKey); if ($result && !$iRealCount) { $count = '#' . $iSubCount; $result->addElement('div', array($result->createElement('em', $sPrefix . $sKey), $count), array('style' => 'border-bottom: 1px dotted #eee')); } $result->add($children); $iCount += $iSubCount + $iRealCount; } else { if ($sKey) { $iCount += $mValue; if ($sPrefix) { $prefix = $result->createElement('em', $sPrefix); } else { $prefix = null; } if ($mValue > 1) { $value = $result->createElement('strong', '#' . $mValue); } else { $value = null; } $result->addElement('div', array($prefix, $sKey, $value)); } } } return array($iCount, $result); }
public static function format($sValue, array $aSettings) { $bSimple = isset($aSettings['simple']) && $aSettings['simple']; $sResult = $bSimple ? '' : \Sylma::read('schema/currency') . ' '; return $sResult . parent::format($sValue, $aSettings) . '.-'; }