Esempio n. 1
0
 /**
  * Constructor
  */
 public function __construct()
 {
     if (!method_exists($this, 'isAvailable') or !$this::isAvailable()) {
         throw new Exception(__CLASS__ . ' requested, but that cache is not available!');
     }
     $this->version = Envi\Version::getBuild();
     $this->prefix = Envi::getSubsite() . ':';
     $this->sessionPrefix = 'session:';
 }
Esempio n. 2
0
 public function indexAction()
 {
     /** @var \DOMElement $statusNode */
     $statusNode = $this->root->appendChild($this->xml->createElement('status'));
     // stats/difra
     $statusNode->setAttribute('difra', \Difra\Envi\Version::getFrameworkVersion(true));
     $statusNode->setAttribute('cache', \Difra\Cache::getInstance()->adapter);
     $statusNode->setAttribute('webserver', $_SERVER['SERVER_SOFTWARE']);
     $statusNode->setAttribute('phpversion', phpversion());
     // stats/plugins
     /** @var $pluginsNode \DOMElement */
     $plugins = \Difra\Plugger::getAllPlugins();
     $enabledPlugins = $disabledPlugins = [];
     foreach ($plugins as $plugin) {
         if ($plugin->isEnabled()) {
             $enabledPlugins[] = $plugin->getName();
         } else {
             $disabledPlugins[] = $plugin->getName();
         }
     }
     $statusNode->setAttribute('enabledPlugins', implode(', ', $enabledPlugins));
     $statusNode->setAttribute('disabledPlugins', implode(', ', $disabledPlugins));
     // stats/extensions
     /** @var $extensionsNode \DOMElement */
     $extensionsNode = $statusNode->appendChild($this->xml->createElement('extensions'));
     $extensions = get_loaded_extensions();
     $extensionsOk = [];
     $extensionsExtra = [];
     $extensionsRequired = ['dom', 'SimpleXML', 'xsl', 'zlib', 'ctype', 'json', 'mbstring', 'Reflection', 'Phar', 'imagick'];
     foreach ($extensions as $extension) {
         if (in_array($extension, $extensionsRequired)) {
             $extensionsOk[] = $extension;
             unset($extensionsRequired[array_search($extension, $extensionsRequired)]);
         } else {
             $extensionsExtra[] = $extension;
         }
     }
     natcasesort($extensionsOk);
     natcasesort($extensionsRequired);
     natcasesort($extensionsExtra);
     $extensionsNode->setAttribute('ok', implode(', ', $extensionsOk));
     $extensionsNode->setAttribute('required', implode(', ', $extensionsRequired));
     $extensionsNode->setAttribute('extra', implode(', ', $extensionsExtra));
     /** @var $permNode \DOMElement */
     $permNode = $statusNode->appendChild($statusNode->ownerDocument->createElement('permissions'));
     if (!is_dir(DIR_DATA)) {
         $permNode->setAttribute('data', 'Directory ' . DIR_DATA . ' does not exist!');
     } elseif (!is_writable(DIR_DATA)) {
         $permNode->setAttribute('data', 'Directory ' . DIR_DATA . ' is not writeable!');
     }
 }
Esempio n. 3
0
 /**
  * Fill output XML with some common data
  * @param \DOMDocument|null $xml
  * @param null $instance
  */
 public static function fillXML(&$xml = null, $instance = null)
 {
     $controller = Controller::getInstance();
     if (is_null($xml)) {
         $xml = $controller->xml;
         $node = $controller->realRoot;
     } else {
         $node = $xml->documentElement;
     }
     Debugger::addLine('Filling XML data for render: Started');
     // TODO: sync this with Envi::getState()
     $node->setAttribute('lang', Envi\Setup::getLocale());
     $node->setAttribute('site', Envi::getSubsite());
     $node->setAttribute('host', $host = Envi::getHost());
     $node->setAttribute('mainhost', $mainhost = Envi::getHost(true));
     $node->setAttribute('protocol', Envi::getProtocol());
     $node->setAttribute('fullhost', Envi::getURLPrefix());
     $node->setAttribute('instance', $instance ? $instance : View::$instance);
     $node->setAttribute('uri', Envi::getUri());
     $node->setAttribute('controllerUri', Action::getControllerUri());
     if ($host != $mainhost) {
         $node->setAttribute('urlprefix', Envi::getURLPrefix(true));
     }
     // get user agent
     Envi\UserAgent::getUserAgentXML($node);
     // ajax flag
     $node->setAttribute('ajax', (Request::isAjax() or isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'SwitchPage') ? '1' : '0');
     $node->setAttribute('switcher', (!$controller->cache and isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'SwitchPage') ? '1' : '0');
     // build and version number
     $node->setAttribute('build', Version::getBuild());
     $node->setAttribute('framework', Version::getFrameworkVersion(false));
     $node->setAttribute('frameworkLong', Version::getFrameworkVersion(true));
     // date
     /** @var $dateNode \DOMElement */
     $dateNode = $node->appendChild($xml->createElement('date'));
     $dateKeys = ['d', 'e', 'A', 'a', 'm', 'B', 'b', 'Y', 'y', 'c', 'x', 'H', 'M', 'S'];
     $dateValues = explode('|', strftime('%' . implode('|%', $dateKeys)));
     $dateCombined = array_combine($dateKeys, $dateValues);
     $dateNode->setAttribute('ts', time());
     foreach ($dateCombined as $k => $v) {
         $dateNode->setAttribute($k, $v);
     }
     // debug flag
     $node->setAttribute('debug', Debugger::isEnabled() ? '1' : '0');
     // config values (for js variable)
     $configNode = $node->appendChild($xml->createElement('config'));
     Envi::getStateXML($configNode);
     // menu
     if ($menuResource = Resourcer::getInstance('menu')->compile(View::$instance)) {
         $menuXML = new \DOMDocument();
         $menuXML->loadXML($menuResource);
         $node->appendChild($xml->importNode($menuXML->documentElement, true));
     }
     // auth
     Auth::getInstance()->getAuthXML($node);
     // locale
     Locales::getInstance()->getLocaleXML($node);
     // Add config js object
     $config = Envi::getState();
     $confJS = '';
     foreach ($config as $k => $v) {
         $confJS .= "config.{$k}='" . addslashes($v) . "';";
     }
     $node->setAttribute('jsConfig', $confJS);
     Debugger::addLine('Filling XML data for render: Done');
     Debugger::debugXML($node);
 }
Esempio n. 4
0
 /**
  * Fill information about missing requirements, old versions, etc.
  */
 public static function fillMissingReq()
 {
     static $didIt = false;
     if ($didIt) {
         return;
     }
     $didIt = true;
     foreach (self::$pluginsData as $name => $data) {
         if (!$data['loaded'] and !empty($data['require'])) {
             foreach ($data['require'] as $req) {
                 if (empty(self::$provisions[$req])) {
                     self::$pluginsData[$name]['missingReq'][] = $req;
                     self::$pluginsData[$name]['disabled'] = true;
                 }
             }
         }
         if ($data['version'] < (double) Envi\Version::getFrameworkVersion(false)) {
             self::$pluginsData[$name]['old'] = true;
         }
     }
 }
Esempio n. 5
0
    /**
     * Construct
     * @param string $message
     * @param int $code
     * @param \Exception $previous
     */
    public function __construct($message, $code = 0, \Exception $previous = null)
    {
        //parent::__construct( $message, $code, $previous );
        if (isset(self::$errors[$message])) {
            $err = $message;
            $error = self::$errors[$err];
            $msg = '';
        } elseif (isset(self::$errors[$code])) {
            $err = $code;
            $error = self::$errors[$err];
            $msg = $message;
        } else {
            $err = self::E_INTERNAL_SERVER_ERROR;
            $error = self::$errors[$err];
            $msg = $message;
        }
        self::$error = $err;
        header("HTTP/1.1 {$err} {$error}");
        /*
        if( $ttl and is_numeric( $ttl ) and $ttl >= 0 ) {
            self::addExpires( $ttl );
        }
        */
        try {
            $xml = new \DOMDocument();
            /** @var $root \DOMElement */
            $root = $xml->appendChild($xml->createElement('error' . $err));
            $root->setAttribute('host', Envi::getSubsite());
            $root->setAttribute('hostname', $host = Envi::getHost());
            $root->setAttribute('mainhost', $mainHost = Envi::getHost(true));
            if ($host != $mainHost) {
                $root->setAttribute('urlprefix', 'http://' . $mainHost);
            }
            $root->setAttribute('build', Version::getBuild());
            $configNode = $root->appendChild($xml->createElement('config'));
            Envi::getStateXML($configNode);
            View::render($xml, 'error_' . $err);
        } catch (\Difra\Exception $ex) {
            echo <<<ErrorPage
<html>
\t<head>
\t\t<title>{$error}</title>
\t</head>
\t<body>
\t\t<center>
\t\t\t<h1 style="padding:350px 0 0 0">Error {$err}: {$error}</h1>
\t\t\t{$msg}
\t\t</center>
\t</body>
</html>
ErrorPage;
        }
        View::$rendered = true;
        die;
    }
Esempio n. 6
0
 /**
  * Get compiled resource
  * @param      $instance
  * @param bool $withSources
  * @return bool|null
  */
 public function compile($instance, $withSources = false)
 {
     if (!$this->checkInstance($instance)) {
         return false;
     }
     // get compiled from cache if available
     $cache = Cache::getInstance();
     if ($cache->adapter != Cache::INST_NONE) {
         $cacheKey = "{$instance}_{$this->type}";
         if (!is_null($cached = $cache->get($cacheKey))) {
             if ($cache->get($cacheKey . '_build') == Version::getBuild()) {
                 return $cached;
             }
         }
         // wait for updated data, try to get lock
         $busyKey = "{$cacheKey}_busy";
         $busyValue = rand(100000, 999999);
         while (true) {
             if (!($currentBusy = $cache->get($busyKey))) {
                 // got updated data?
                 if (!is_null($cached = $cache->get($cacheKey)) and $cache->get($cacheKey . '_build') == Version::getBuild()) {
                     return $cached;
                 }
                 // try to lock cache
                 $cache->put($busyKey, $busyValue, 7);
                 usleep(5000);
             } else {
                 // is cache locked by me?
                 if ($currentBusy == $busyValue) {
                     break;
                 }
                 usleep(19111);
             }
         }
         // compile resource
         $resource = $this->realCompile($instance, $withSources);
         // cache data
         $cache->put($cacheKey, $resource, self::CACHE_TTL);
         $cache->put($cacheKey . '_build', Version::getBuild(), self::CACHE_TTL);
         $cache->put($cacheKey . '_modified', gmdate('D, d M Y H:i:s') . ' GMT', self::CACHE_TTL);
         // unlock cache
         $cache->remove($busyKey);
         return $resource;
     } else {
         return $this->realCompile($instance, $withSources);
     }
 }