public function setScript(core\request $path, $sContext = '') { //$path->parse(); $bError = null; $parser = \Sylma::getManager('parser'); $messages = new html\context\Messages(); $contexts = new core\argument\Readable(array('errors' => $this->initMessages(), 'messages' => $messages, 'js-common' => new html\context\JS(), 'js' => new html\context\JS(array('load' => new template\binder\context\Load())))); $this->setContexts($contexts); $parser->setContext('messages', $messages); $debug = $this->getManager('init')->getArgument('window'); try { $result = $this->runScript($path->getFile(), $path->getArguments(), $this->getManager('init')->loadPOST(true), $debug); } catch (core\exception $e) { $result = ''; $e->save(false); $bError = true; $messages->add(array('content' => 'An error has occured')); } if (\Sylma::isAdmin()) { $errors = $contexts->get('errors'); } else { $errors = null; } $classes = $contexts->get('js/classes', false); $this->setSettings(array('content' => $this->formatContent($result), 'objects' => $contexts->get('js/load/objects', false), 'classes' => $classes ? $classes->asStringVar() : null, 'error' => $bError, 'errors' => $errors, 'messages' => $contexts->get('messages'))); }
public function build(fs\file $file, fs\directory $dir) { if (!\Sylma::isAdmin()) { //$this->throwException('This function is low performance and must not be used in production environnement'); $this->throwException('Unauthorized building access'); } $builder = $this->loadBuilder($file, $dir); $this->aBuilded[] = $file; return $builder->build($dir); }
public function asString() { $init = $this->getManager(); $file = $this->getFile(); if (\Sylma::isAdmin()) { $init->setHeaderCache(0); } else { $iCache = $this->getManager()->read('session/expires'); $init->setHeaderCache($iCache); } $init->setHeaderContent($init->getMime($file->getExtension())); return $file->checkRights(\Sylma::MODE_EXECUTE) ? $file->execute() : $file->read(); }
/** * @return array */ protected function getCache(array $aFiles, $aContent) { $sName = hash("crc32b", implode('', array_keys($aFiles))) . '.' . static::EXTENSION; $fs = \Sylma::getManager('fs/tmp'); $cache = $fs->getFile($sName, null, false); $dir = $fs->getDirectory(); $bUpdate = false; if ($cache && \Sylma::isAdmin()) { $bUpdate = $this->checkUpdate($cache, $aFiles); } if (!$cache || $bUpdate) { $cache = $dir->createFile($sName); $cache->saveText(implode("\n\n", $aContent)); } return $this->addFile($cache, true); }
public function load(fs\file $file, array $aArguments = array(), $bUpdate = null, $bRun = true, $bExternal = false) { $result = null; $cache = $this->loadCache($file, $bUpdate); if ($this->readArgument('debug/run') && $bRun) { if (!$cache) { $this->launchException('No cache file found', get_defined_vars()); } $result = $this->createCache($cache, $aArguments, $bExternal); if (\Sylma::isAdmin()) { $sPath = (string) $cache; if (isset(self::$aLoaded[$sPath])) { self::$aLoaded[$sPath]++; } else { self::$aLoaded[$sPath] = 1; } } } return $result; }
protected function loadMaintenance() { $sResult = ''; if ($this->readArgument('maintenance/enable') && !\Sylma::isAdmin()) { $sResult = $this->getFile($this->readArgument('maintenance/file'))->execute(); } return $sResult; }
public function save($bPrint = true, $bHTML = true, $bTrace = true) { $sResult = ''; $aPath = $this->getPath(); $aResult = array('message' => $this->parseString(htmlspecialchars($this->getMessage())) . '<br/>', 'paths' => $this->readPaths($aPath), 'vars' => $this->loadVariables($bHTML), 'trace' => 'no trace'); if ($bTrace) { $aResult['trace'] = $this->loadTraces($bHTML); } if (\Sylma::isAdmin() || \Sylma::read('exception/show')) { $this->show($aResult, $bPrint); } if (\Sylma::isAdmin()) { if (\Sylma::read('exception/send')) { $this->send($aResult); } } else { $this->send($aResult); } return $sResult; }
protected function buildWindowScript(array $aPaths) { $this->setDirectory(__FILE__); $args = $this->getArguments(); $post = $this->getPost(); if (!($file = $this->getFile(current($aPaths), false))) { if (\Sylma::isAdmin()) { dsp('Action not found'); } $this->send404(); $content = $this->getError(); } else { try { $content = $this->prepareMain($file, $args, $post); } catch (core\exception $e) { $e->save(false); $content = $this->getError(); } } while (next($aPaths)) { $sPath = current($aPaths); $args->set(self::CONTENT_SUB, $content); $content = $this->getScriptFile($this->getFile($sPath), array('arguments' => $args, 'post' => $post, 'contexts' => $this->getContexts())); } return $content; }
/** * Load the user, from either cookie, session or profil if authentication has been done */ public function load($bRemember = false) { $this->buildCookie(); if ($this->isValid() && $this->getName() && $this->getID()) { $this->save($bRemember); } else { if (!$this->loadSession() && !$this->loadCookie()) { $this->loadDefault(); } } if (\Sylma::isAdmin()) { $this->aGroups[] = self::GROUP_TEST; } }
public function prepare($sContent) { $doc = $this->createDocument($sContent); if ($doc && !$doc->isEmpty()) { $this->result = $doc; $doc->registerNamespaces($this->getNS()); if ($this->getControler('user')->isPrivate()) { $this->buildInfos($doc); } //$this->getContext('errors')->add(array('content' => $this->getManager('init')->getStats())); $this->loadContexts($doc); $result = $this->loadHeaders('text/html') . "\n" . $this->cleanResult($doc); } else { if (\Sylma::isAdmin()) { echo '<h2>No result document</h2>'; } } return $result; }