示例#1
0
 public function test_menu()
 {
     $oldUri = \Difra\Envi::getUri();
     \Difra\Envi::setUri('/adm/development/plugins');
     $menu = \Difra\Resourcer::getInstance('menu')->compile('adm', true);
     $this->assertNotEmpty($menu);
     \Difra\Envi::setUri($oldUri);
 }
示例#2
0
 public function test_getUri()
 {
     \Difra\Envi::setUri('/normal/request/uri/');
     $this->assertEquals(\Difra\Envi::getUri(), '/normal/request/uri');
     \Difra\Envi::setUri('/normal/request/uri/?some=strange?request');
     $this->assertEquals(\Difra\Envi::getUri(), '/normal/request/uri');
     \Difra\Envi::setUri('/webserver/path');
     $this->assertEquals(\Difra\Envi::getUri(), '/webserver/path');
     \Difra\Envi::setUri(null);
     $this->assertNull(\Difra\Envi::getUri());
 }
示例#3
0
文件: XML.php 项目: difra-org/difra
 /**
  * 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);
 }
示例#4
0
 /**
  * Get menu element data as XML node
  * @param \DOMElement $node
  * @return bool
  */
 public function getXML($node)
 {
     if (!$this->load()) {
         return false;
     }
     $node->setAttribute('id', $this->id);
     $node->setAttribute('id', $this->id);
     $node->setAttribute('menu', $this->menu);
     $node->setAttribute('parent', $this->parent);
     $controllerUri = Action::getControllerUri();
     $uri = Envi::getUri();
     $href = '';
     if ($this->page) {
         // page
         if (empty($this->pageData)) {
             $page = Page::get($this->page);
             $this->pageData = ['id' => $page->getId(), 'tag' => $page->getUri(), 'hidden' => $page->getHidden(), 'title' => $page->getTitle()];
         }
         $hidden = (!$this->visible or $this->pageData['hidden']) ? '1' : '0';
         $node->setAttribute('type', 'page');
         $node->setAttribute('label', $this->pageData['title']);
         $node->setAttribute('link', $href = $this->pageData['tag']);
         $node->setAttribute('hidden', $hidden);
         $node->setAttribute('page', $this->pageData['id']);
     } elseif ($this->link) {
         // link
         $node->setAttribute('type', 'link');
         $node->setAttribute('label', $this->linkLabel);
         $node->setAttribute('link', $href = $this->link);
         $node->setAttribute('hidden', !$this->visible ? '1' : '0');
     } else {
         // empty
         $node->setAttribute('type', 'empty');
         $node->setAttribute('label', $this->linkLabel);
         $node->setAttribute('hidden', !$this->visible ? '1' : '0');
     }
     if ($href) {
         if ($href == $uri) {
             $node->setAttribute('match', 'exact');
         } elseif ($href == $controllerUri) {
             $node->setAttribute('match', 'partial');
         } elseif (strpos($uri, $href) !== false) {
             $node->setAttribute('match', 'partial');
         }
     }
     return true;
 }
示例#5
0
    /**
     * If page rendered too long, report to developers
     * @throws Exception
     */
    public static function checkSlow()
    {
        // TODO: merge this method with Exception::sendNotification()
        $time = self::getTimer();
        if (!$time <= 1) {
            return;
        }
        // don't send notifications on development environment
        if (!Envi::isProduction()) {
            return;
        }
        $notificationMail = self::getNotificationMail();
        // no notification mail is set
        if (!$notificationMail) {
            return;
        }
        $output = '<pre>';
        foreach (self::$output as $line) {
            if (!isset($line['type'])) {
                $line['type'] = null;
            }
            $output .= "{$line['timer']}\t{$line['class']}\t{$line['type']}\t{$line['message']}\n";
        }
        $date = date('r');
        $server = print_r($_SERVER, true);
        $post = print_r($_POST, true);
        $cookie = print_r($_COOKIE, true);
        $host = Envi::getHost();
        $uri = Envi::getUri();
        $user = Auth::getInstance()->getEmail();
        $output .= <<<MSG

Page:\t{$uri}
Time:\t{$date}
Host:\t{$host}
User:\t{$user}

\$_SERVER:
{$server}

\$_POST:
{$post}

\$_COOKIE:
{$cookie}
MSG;
        $output .= '</pre>';
        Mailer::getInstance()->sendMail(self::getNotificationMail(), 'Slow script', print_r($output, true));
    }
示例#6
0
文件: Page.php 项目: difra-org/difra
 /**
  * Detect page matching current URL
  * @static
  * @return int|false
  */
 public static function find()
 {
     $uri = Envi::getUri();
     $cache = Cache::getInstance();
     if (!($data = $cache->get('cms_tags'))) {
         try {
             $data1 = CMS::getDB()->fetch('SELECT `id`,`tag` FROM `cms` WHERE `hidden`=0');
         } catch (Exception $ex) {
             return false;
         }
         $data = [];
         if (!empty($data1)) {
             foreach ($data1 as $v) {
                 $data[$v['tag']] = $v['id'];
             }
         }
         $cache->put('cms_tags', $data);
     }
     return isset($data[$uri]) ? $data[$uri] : false;
 }
示例#7
0
 /**
  * Get cache record key
  * @return string
  */
 private static function getCacheKey()
 {
     return 'action:uri:' . Envi::getUri();
 }
示例#8
0
 /**
  * Returns URI
  * @return string
  */
 protected static function getUri()
 {
     return \Difra\Envi::getUri(true);
 }