示例#1
0
 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);
 }
示例#2
0
 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);
 }
示例#3
0
文件: tags.php 项目: difra-org/difra
 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);
     }
 }
示例#4
0
 /**
  * Registration form submit (registration page version)
  * @param AjaxCheckbox $accept
  * @param AjaxCheckbox $redirect
  * @param AjaxString|null $email
  * @param AjaxString|null $password1
  * @param AjaxString|null $password2
  * @param AjaxString|null $login
  * @param AjaxString|null $capcha
  * @throws Exception
  */
 public function submitAjaxAction(AjaxCheckbox $accept, AjaxCheckbox $redirect, AjaxString $email = null, AjaxString $password1 = null, AjaxString $password2 = null, AjaxString $login = null, AjaxString $capcha = null)
 {
     $register = new Users\Register();
     $register->setEmail($email);
     $register->setLogin($login);
     $register->setPassword1($password1);
     $register->setPassword2($password2);
     $register->setCaptcha($capcha);
     if (!$register->validate()) {
         $register->callAjaxerEvents();
         return;
     }
     // EULA
     if (!$accept->val() and \Difra\Config::getInstance()->getValue('auth', 'eula')) {
         $this->root->appendChild($this->xml->createElement('eula'));
         Ajaxer::display(View::render($this->xml, 'auth-ajax', true));
         return;
     }
     $register->register();
     $this->afterSuccess();
 }
示例#5
0
 /**
  * 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;
             }
         }
     }
 }
示例#6
0
 /**
  * Recover password (ajax)
  * @param AjaxString $login Login or e-mail
  * @param AjaxString $captcha
  * @throws Exception
  */
 public function indexAjaxAction(AjaxString $login, AjaxString $captcha)
 {
     // show recover form
     if (is_null($login)) {
         $this->root->appendChild($this->xml->createElement('recover'));
         Ajaxer::display(View::render($this->xml, 'auth-ajax', true));
         return;
     }
     $error = false;
     // login's empty
     if ($login->val() === '') {
         Ajaxer::required('login');
         $error = true;
     }
     if (!$captcha or $captcha->val() == '') {
         Ajaxer::required('captcha');
         $error = true;
     }
     /** @var \Difra\Plugins\Capcha $captchaClass */
     $captchaClass = \Difra\Plugger::getClass('captcha');
     if (!$captchaClass::getInstance()->verifyKey($captcha->val())) {
         Ajaxer::invalid('captcha');
         $error = true;
     }
     if ($error) {
         return;
     }
     // recover
     try {
         Recover::send($login->val());
         Ajaxer::close();
         Ajaxer::notify(Locales::get('auth/login/recovered'));
     } catch (Exception $ex) {
         Ajaxer::status('email', Locales::get('auth/login/' . $ex->getMessage()), 'problem');
     }
 }
示例#7
0
 /**
  * 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);
 }
示例#8
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;
    }
示例#9
0
 /**
  * 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);
 }