public function indexAction() { if ($this->hasUnusedParameters()) { throw new \Difra\View\HttpError(404); } \Difra\View::redirect('/adm/status'); }
/** * Set instance to adm */ public function dispatch() { View::$instance = 'adm'; if (!$this->root->getAttribute('title')) { $this->root->setAttribute('title', Envi::getHost() . '/adm'); } }
private function renderWindow() { $xml = new \DOMDocument(); $node = $xml->appendChild($xml->createElement('DirectoryWindow')); $search = new \Difra\Unify\Search('WidgetsDirectory'); $search->addCondition('directory', static::directory); $search->getListXML($node); return \Difra\View::render($xml, 'widget_directory', true); }
public function test_render_echo() { $xml = new \DOMDocument(); $realRoot = $xml->appendChild($xml->createElement('root')); $realRoot->appendChild($xml->createElement('content')); ob_start(); \Difra\View::render($xml, 'main'); $html = ob_get_clean(); $this->assertNotEmpty($html); }
public function editAjaxAction(\Difra\Param\AnyString $module, \Difra\Param\AnyInt $tagId) { $tagData = \Difra\Plugins\Tags::getInstance()->getTag($module->val(), $tagId->val()); if (!empty($tagData)) { /** @var \DOMElement $mainNode */ $mainNode = $this->root->appendChild($this->xml->createElement('tagsEditForm')); $mainNode->setAttribute('id', $tagData['id']); $mainNode->setAttribute('module', $module->val()); $mainNode->setAttribute('tag', $tagData['tag']); $html = \Difra\View::render($this->xml, 'forms', true); $this->ajax->display($html); } }
private function _showEvent($link) { $Announcements = \Difra\Plugins\Announcements::getInstance(); $Announce = $Announcements->getByLink($link); if ($Announce === false) { throw new \Difra\View\HttpError(404); return; } if ($link != $Announce->getShortLink()) { \Difra\View::redirect($Announce->getShortLink()); } $Announce->getXML($this->eventRoot); $additionalsFieldsNode = $this->eventRoot->appendChild($this->eventRoot->ownerDocument->createElement('additionalsFields')); \Difra\Plugins\Announcements\Additionals::getListXML($additionalsFieldsNode); }
/** * Choose view depending on request type */ public static final function start() { $controller = Controller::getInstance(); if (Controller::hasUnusedParameters()) { $controller->putExpires(true); throw new HttpError(404); } elseif (!is_null(self::$output)) { $controller->putExpires(); header('Content-Type: ' . self::$outputType . '; charset="utf-8"'); echo self::$output; View::$rendered = true; } elseif (Debugger::isEnabled() and isset($_GET['xml']) and $_GET['xml']) { if ($_GET['xml'] == '2') { View\XML::fillXML(); } header('Content-Type: text/xml; charset="utf-8"'); $controller->xml->formatOutput = true; $controller->xml->encoding = 'utf-8'; echo rawurldecode($controller->xml->saveXML()); View::$rendered = true; } elseif (!View::$rendered and Request::isAjax()) { $controller->putExpires(); // should be application/json, but opera doesn't understand it and offers to save file to disk header('Content-type: text/plain'); echo Ajaxer::getResponse(); View::$rendered = true; } elseif (!View::$rendered) { $controller->putExpires(); try { View::render($controller->xml); } catch (HttpError $ex) { if (!Debugger::isConsoleEnabled()) { throw new HttpError(500); } else { echo Debugger::debugHTML(true); die; } } } }
/** * Set X-Accel-Expires header for web server-side caching * @param bool|int $ttl */ public function putExpires($ttl = null) { if (Debugger::isEnabled()) { return; } if (is_null($ttl)) { $ttl = $this->cache; } if ($ttl === true) { $ttl = self::DEFAULT_CACHE; } if (!$ttl or !is_numeric($ttl) or $ttl < 0) { return; } View::addExpires($ttl); }
/** * Render message body from template * @param string $template * @param array $data */ public function render($template, $data) { $xml = new \DOMDocument(); /** @var \DOMelement $root */ $root = $xml->appendChild($xml->createElement('mail')); $root->setAttribute('host', Envi::getHost(true)); Locales::getInstance()->getLocaleXML($root); if (!empty($data)) { foreach ($data as $k => $v) { $root->setAttribute($k, $v); } } $this->body = View::render($xml, $template, true); }
/** * Password recovery link (stub) * @param AnyString $code */ public function codeActionAuth(AnyString $code) { Cookies::getInstance()->notify(Locales::get('auth/recover/already_logged'), true); View::redirect('/'); }
/** * 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; }
/** * Render debug console HTML * @param bool $standalone Render console standalone page (looks like full screen console) * @return string */ public static function debugHTML($standalone = false) { static $alreadyDidIt = false; if ($alreadyDidIt) { return ''; } /** @var $root \DOMElement */ $xml = new \DOMDocument(); $root = $xml->appendChild($xml->createElement('root')); self::debugXML($root, $standalone); return View::render($xml, 'all', true, true); }
/** * Log out */ public function indexAction() { User::logout(); \Difra\View::redirect('/'); }
/** * Output resource * @param $instance * @return bool * @throws Exception */ public function view($instance) { if (!$this->isPrintable()) { throw new Exception("Resource of type '{$this->type}' is not printable"); } // Cut extension $parts = explode('.', $instance); if (sizeof($parts) == 2) { if ($parts[1] == $this->type) { $instance = $parts[0]; } } if (!$instance or !$this->checkInstance($instance)) { return false; } /* * Disabled due to nginx doesn't support Vary in fastcgi_cache implementation at the moment * // Detect if browser supports gzip compression $enc = false; if( !empty( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { $encTypes = $_SERVER['HTTP_ACCEPT_ENCODING']; if( strpos( $encTypes, ',' ) ) { $encTypes = explode( ',', $encTypes ); } else { $encTypes = array( $encTypes ); } foreach( $encTypes as $type ) { $type = trim( $type ); switch( $type ) { case 'gzip': $enc = 'gzip'; break 2; } } } */ $enc = 'gzip'; if ($enc == 'gzip' and $data = $this->compileGZ($instance)) { // header( 'Vary: Accept-Encoding' ); header('Content-Encoding: gzip'); } else { $data = $this->compile($instance); } if (!$data) { return false; } header('Content-Type: ' . $this->contentType); if (!($modified = Cache::getInstance()->get("{$instance}_{$this->type}_modified"))) { $modified = gmdate('D, d M Y H:i:s') . ' GMT'; } View::addExpires(Controller::DEFAULT_CACHE); header('Last-Modified: ' . $modified); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + self::CACHE_TTL) . ' GMT'); echo $data; return true; }
/** * Resource (JS, CSS, etc.) request processor * @param string[] $parts * @throws \Difra\View\HttpError * @return bool */ private static function getResource($parts) { if (sizeof($parts) != 2) { return false; } $resourcer = Resourcer::getInstance($parts[0], true); if ($resourcer and $resourcer->isPrintable()) { try { if (!$resourcer->view($parts[1])) { throw new HttpError(404); } View::$rendered = true; die; } catch (Exception $ex) { throw new HttpError(404); } } return false; }
/** * Redefine this method if you want custom actions after activation */ protected function afterActivate() { Cookies::getInstance()->notify(Locales::get('auth/activate/done')); \Difra\View::redirect('/'); }