public function clearSylma(core\Initializer $init, core\user $user = null) { if (!$user) { $user = $this->createUser(); } $this->setManagers(\Sylma::getManagers()); \Sylma::setManagers(array('parser' => $this->read('parser') ? \Sylma::getManager('parser') : null, 'init' => $init, 'user' => $user)); }
public function readScript($sPath, $sUser) { $this->buildScript($sPath); $current = \Sylma::getManager('user'); \Sylma::setManager('user', $this->createUser($sUser)); $result = $this->getScript($sPath); \Sylma::setManager('user', $current); $this->set('result', $result); }
public function __construct() { $this->setNamespace(self::PARSER_PREFIX, self::PARSER_NS); parent::__construct(); $this->setDirectory(__FILE__); $cache = \Sylma::getManager('fs/cache'); $this->exportDirectory = $cache->getDirectory()->addDirectory((string) $this->getDirectory()); $this->setFiles(array($this->getFile('basic.xml'))); }
protected function addFile(fs\file $file, $bReal = false) { $aResult = parent::addFile($file, $bReal); if ($file->getExtension() === 'less') { $fs = \Sylma::getManager('fs'); $this->js->add($fs->getFile('less.js', $fs->extractDirectory(__FILE__))); $aResult['link']['@rel'] = 'stylesheet/less'; } return $aResult; }
public function __construct() { $this->setDirectory(__FILE__); $this->setNamespaces(array('self' => self::NS, self::PARSER_PREFIX => self::PARSER_NS)); $this->setManager($this->getManager('parser')); $cache = \Sylma::getManager('fs/cache'); $this->exportDirectory = $cache->getDirectory()->addDirectory((string) $this->getDirectory()); $this->setArguments(array()); $this->setFiles(array($this->getFile('basic.xml'))); }
protected function loadManager($sName, $bDebug = true) { $result = null; if (array_key_exists($sName, $this->aManagers)) { $result = $this->aManagers[$sName]; } else { $result = \Sylma::getManager($sName, $bDebug); } return $result; }
public function asString() { header('Vary: Accept'); if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) { \Sylma::getManager('init')->setHeaderContent('application/json'); } else { \Sylma::getManager('init')->setHeaderContent('text/plain'); } return $this->getSettings()->asJSON(); }
public function run($settings) { //print_r($settings->query('imports', false)); \Sylma::getManager(self::AUTOLOAD_MANAGER)->loadNamespaces($settings->query('autoload')); $this->setArguments($this->createArgument($settings->query())); $this->setSettings($this->getArguments()); //$this->setArguments($settings); $this->setErrorReporting(); //set_exception_handler("self::sendException"); $iLifetime = $this->readArgument('session/lifetime'); ini_set('session.gc_maxlifetime', $iLifetime); session_set_cookie_params($iLifetime); session_cache_expire($this->readArgument('session/cache')); $this->startSession(); // if (\Sylma::read('db/enable')) $this->loadXDB(); $this->setStartTime(microtime(true)); require_once 'storage/fs/Controler.php'; // load directory without security $fs = new fs\Controler(\Sylma::ROOT, false, false, false); $fs->loadDirectory(); \Sylma::setManager('fs', $fs); \Sylma::setManager('fs/free', $fs); // load user $user = \Sylma::getManager('user'); $user->load(); if (\Sylma::isAdmin()) { require_once 'debug/Functions.php'; } // load directory with security $fs = new fs\Controler(\Sylma::ROOT, false, true, true); $fs->loadDirectory(); \Sylma::setManager('fs', $fs); $this->setDirectory($fs->getDirectory()); // Check for maintenance mode if ($sMaintenance = $this->loadMaintenance()) { return $sMaintenance; } //$this->getDirectory()->getSettings()->loadDocument(); $path = $this->loadPath(); \Sylma::setManager('path', $path); // The extension specify the window type // Parse of the request_uri, creation of the window - $_GET // Reload last alternatives mime-type results - $_SESSION['results'] //self::loadResults(); if ($sFile = $path->asFile()) { $sResult = $this->createWindowBuilder()->createWindow($sFile, $this->get('images')); } else { $sResult = $this->runScript($path); } return $sResult; }
public function buildDocument(array $aArray, $sNamespace, &$bChildren = false) { $dom = \Sylma::getManager('dom'); $doc = $dom->create('handler'); $fragment = $doc->createFragment(); $root = $fragment->add($doc->createElement('root', null, array(), $sNamespace)); $this->buildNode($root, $aArray, $sNamespace); if ($root->countChildren() > 1) { $doc->set($root); $bChildren = true; } else { $doc->set($root->getFirst()); } return $doc; }
public static function setDevice($sValue) { $aHeader = array(); switch ($sValue) { case 'mobile': $aHeader = self::$aIphone; break; case 'desktop': $aHeader = self::$aUbuntu; break; } if ($aHeader) { \Sylma::getManager('device')->setHttpHeaders($aHeader); } }
protected function startString($sValue) { $bResult = false; if ($sValue[0] == '/') { $fs = \Sylma::getManager('fs'); $file = $fs->getFile($sValue); $this->setFile($file); $bResult = $this->loadFile(); } else { if ($sValue[0] == '<') { $bResult = $this->loadText($sValue); } else { $bResult = (bool) $this->set($this->createElement($sValue, null, array(), $this->getNamespace())); } } return $bResult; }
protected function parseURL($sValue, fs\directory $dir) { $fs = \Sylma::getManager('fs'); $sResult = preg_replace_callback("/url\\((?:'|\")?([^\\)'\"]+)('|\")?\\)/", function ($aMatches) use($fs, $dir) { $sMatch = $aMatches[1]; if (!preg_match('`https?://`', $sMatch)) { if ($sMatch[0] === '/') { $sURL = $sMatch; } else { $sURL = (string) $fs->getFile($sMatch, $dir); } } else { $sURL = $sMatch; } return "url('{$sURL}')"; }, $sValue); return $sResult; }
function extractDirectory($sFile, $bObject = true) { $sFile = substr($sFile, strlen(getcwd() . MAIN_DIRECTORY) + 1); if (\Sylma::isWindows()) { $sFile = str_replace('\\', '/', $sFile); } $sResult = substr($sFile, 0, strlen($sFile) - strlen(strrchr($sFile, '/'))); if ($bObject) { // object if (!($fs = \Sylma::getManager('fs'))) { Sylma::throwException(sprintf('File controler not yet loaded. Cannot extract path %s', $sFile)); } //echo $fs->getDirectory($sResult); return $fs->getDirectory($sResult); // return \Controler::getDirectory($sResult); } else { // string return $sResult; } }
public static function import($sPath) { $fs = \Sylma::getManager(self::FILE_MANAGER); $parser = \Sylma::getManager(self::PARSER_MANAGER); return $parser->load($fs->getFile($sPath)); }
public function buildLink($sFile) { $sDirectory = \Sylma::getManager('fs')->getDirectory()->getSystemPath(); return 'netbeans://' . $sDirectory . $sFile; }
protected function callFunction(\Closure $function) { return $function(\Sylma::getManager(self::FILE_MANAGER_ALIAS)); }
protected function getControler() { return \Sylma::getManager(self::CONTROLER_ALIAS); }
/** * Check rights arguments for update in @method updateRights() */ protected function checkRightsArguments($sOwner, $sGroup, $sMode) { if ($this->isOwner()) { $bOwner = $sOwner !== $this->getOwner(); $bGroup = $sGroup !== $this->getGroup(); $bMode = $sMode !== $this->getMode(); if ($bOwner || $bGroup || $bMode) { $user = \Sylma::getManager('user'); // Check validity if ($bOwner) { $this->throwException(t('Cannot change owner')); } if ($bGroup && !$user->isMember($sGroup)) { $this->throwException(sprintf('You have no rights on group %s or it doesn\'t exist', $sGroup)); } $iMode = $user->getMode($sOwner, $sGroup, $sMode); if ($bMode && $iMode === null) { $this->throwException(t('Arguments are not valid')); } if ($bMode && !($iMode & MODE_READ)) { $this->throwException(t('You cannot remove read access')); } // all datas are ok or not modified return true; } } else { $this->throwException(t('You are not the owner of this resource')); } return false; }
protected function insert($aContent) { $parser = \Sylma::getManager('parser'); $fs = \Sylma::getManager('fs'); $file = $fs->extractDirectory(__FILE__)->getFile('insert.vml'); return $parser->load($file, array('post' => new \sylma\core\argument\Readable(array('message' => $this->getMessage(), 'message_html' => $aContent['message'], 'context' => $aContent['paths'] . $aContent['vars'], 'backtrace' => $aContent['trace'], 'session' => $this->dump($_SESSION), 'request' => $this->dump($_REQUEST), 'files' => $this->dump($_FILES), 'server' => $this->dump($_SERVER)))), false); }
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); }
protected function createDocument($sElement = '') { return \Sylma::getManager('dom')->createDocument($sElement); }
protected function loadManager($sName, $bDebug = true) { $result = null; if ($sName == 'fs') { $result = \Sylma::getManager(static::FILE_MANAGER); } else { $result = parent::loadManager($sName, $bDebug); } return $result; }
/** * Determine if fs module is ready */ protected function getControler() { return \Sylma::getManager(self::FILE_CONTROLER, false, false); }