Beispiel #1
0
 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;
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 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}'");
     }
 }
Beispiel #5
0
 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
 }
Beispiel #6
0
 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;
 }
Beispiel #7
0
 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();
 }
Beispiel #8
0
 /**
  *
  * @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);
 }
Beispiel #9
0
 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;
 }
Beispiel #10
0
 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));
 }
Beispiel #11
0
 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;
 }
Beispiel #12
0
 protected function setErrorReporting()
 {
     error_reporting(\Sylma::read('exception/level'));
     libxml_use_internal_errors(false);
 }
Beispiel #13
0
 protected function useLog()
 {
     return \Sylma::read('debug/parser');
 }
Beispiel #14
0
 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;
 }
Beispiel #15
0
 /**
  * @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));
 }
Beispiel #16
0
 public function checkRights($iMode)
 {
     if (!$this->getControler()->mustSecure() || \Sylma::read('debug/rights')) {
         return true;
     }
     if ($iMode & $this->getUserMode()) {
         return true;
     }
     return false;
 }
Beispiel #17
0
 protected function getSessionKey()
 {
     return \Sylma::read('modules/captcha/session');
 }
Beispiel #18
0
 /**
  * @usedby /#sylma/core/test/basic.xml "PHP Error" test
  * @return string
  */
 public static function getLogPath()
 {
     return \Sylma::read('exception/file');
 }
Beispiel #19
0
 public function isPrivate()
 {
     if (\Sylma::read('debug/rights')) {
         return true;
     }
     return $this->bPrivate;
 }
Beispiel #20
0
 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);
 }
Beispiel #21
0
 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) . '.-';
 }