Ejemplo n.º 1
0
 /**
  * Returns content escaped using the View's escape function with more parameters
  *
  * @return string
  */
 public function filter($item, $field = "content", $length = 0)
 {
     try {
         return Zoo::getService("filter")->filter($item, $field, $length);
     } catch (Zoo_Exception_Service $e) {
         return $this->view->escape($item);
     }
 }
Ejemplo n.º 2
0
 public function __toString()
 {
     $view = new Zend_View();
     $params = array('href' => $this->getHref(), 'id' => $this->getId(), 'class' => $this->getClass() . ($this->getActive() ? 'active' : ''));
     foreach ($params as $key => &$param) {
         if (empty($param)) {
             continue;
         }
         $param = $key . '="' . $view->escape($param) . '"';
     }
     return '<a ' . implode(' ', $params) . '>' . $view->escape($this->getLabel()) . '</a>';
 }
Ejemplo n.º 3
0
 /**
  * Switch lang
  *
  * @return string
  */
 public function langOptions($languages, $defaultLang, $onlyFront = true)
 {
     $result = "<option value=''> </option>";
     foreach ($languages as $langCode => $lang) {
         if ($onlyFront && !$lang['front_enabled']) {
             continue;
         }
         $result .= '<option value="' . $this->_view->escape($langCode) . '" ';
         if ($langCode == $defaultLang) {
             $result .= 'selected="selected"';
         }
         $result .= '>' . $this->_view->escape($lang['name']) . '</option>';
     }
     return $result;
 }
 public function getEmailOption(array $requestData, $name, $email, $extra = null, $disabledTitle = false, $menuFind = false)
 {
     if (!$email) {
         $email = $this->translate->_('no email adress');
     }
     $text = "\"{$name}\" <{$email}>";
     if (null !== $extra) {
         $text .= ": {$extra}";
     }
     if ($this->view) {
         if ($disabledTitle) {
             $el = \MUtil_Html::create()->span($text, array('class' => 'disabled'));
             if ($menuFind && is_array($menuFind)) {
                 $menuFind['allowed'] = true;
                 $menuItem = $this->menu->find($menuFind);
                 if ($menuItem) {
                     $href = $menuItem->toHRefAttribute($requestData);
                     if ($href) {
                         $el = \MUtil_Html::create()->a($href, $el);
                         $el->target = $menuItem->get('target', '_BLANK');
                     }
                 }
             }
             $el->title = $disabledTitle;
             $text = $el->render($this->view);
         } else {
             $text = $this->view->escape($text);
         }
     }
     return $text;
 }
Ejemplo n.º 5
0
 /**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     if (!Z_Acl::getInstance()->isAllowed(Z_Auth::getInstance()->getUser()->getRole(), $this->_z_resourceId)) {
         return;
     }
     $view = new Zend_View();
     $modelSeo = new Z_Model_Titles();
     $currentItem = $modelSeo->fetchRow(array('uri=?' => $_SERVER['REQUEST_URI']));
     if ($currentItem) {
         $adminUrl = '/admin/z_seo/edit/id/' . $currentItem->id;
         $adminLinkText = 'Изменить';
     } else {
         $adminUrl = '/admin/z_seo/add/uri/' . base64_encode($_SERVER['REQUEST_URI']);
         $adminLinkText = 'Добавить';
     }
     return '<h4>Текущие значения:</h4>' . '<strong>URI:</strong> ' . $_SERVER['REQUEST_URI'] . '<br />' . '<strong>Заголовок:</strong> ' . strip_tags($view->headTitle()) . '<br />' . '<strong>Мета:</strong> <br />' . nl2br($view->escape($view->headMeta())) . '<br />' . '<br /><a href="' . $adminUrl . '" target="_blank">' . $adminLinkText . '</a>';
 }
Ejemplo n.º 6
0
    public function save(array $data)
    {
        $keyAlgorithm = array_key_exists('algorithm', $data) ? $data['algorithm'] : 'hmac-md5';
        $keySecret = $data['secret'];
        $slaveIp = $data['ip'];
        $slavePort = array_key_exists('port', $data) ? $data['port'] : 953;
        $view = new Zend_View();
        $view->setScriptPath(pm_Context::getPlibDir() . 'views/scripts');
        $rndc = new Modules_SlaveDnsManager_Rndc();
        $pleskIp = $view->escape($rndc->getServerIP());
        $slaveConfiguration = $view->partial('index/slave-config.phtml', array('pleskIp' => $pleskIp, 'secret' => $keySecret));
        $slaveConfiguration = trim(html_entity_decode(strip_tags($slaveConfiguration)));
        $slaveConfiguration = preg_replace('/^/m', '    ', $slaveConfiguration);
        $configuration = <<<CONF
/*
{$slaveConfiguration}
*/

key "rndc-key" {
    algorithm {$keyAlgorithm};
    secret "{$keySecret}";
};

options {
    default-key "rndc-key";
    default-server {$slaveIp};
    default-port {$slavePort};
};
CONF;
        if (null === $this->_config) {
            $this->_config = "slave_{$slaveIp}.conf";
        }
        $result = file_put_contents($this->getConfigPath(), $configuration);
        if (false === $result) {
            throw new pm_Exception("Failed to save configuration {$this->_config}");
        }
        $acl = new Modules_SlaveDnsManager_Acl();
        $acl->add($slaveIp);
    }
Ejemplo n.º 7
0
 private function _doCustomAuth($controller, $viewfile)
 {
     $login_view = new Zend_View();
     $login_view->setScriptPath(APPLICATION_PATH . dirname($viewfile));
     // тут мы выдаем сообщения об ошибках
     // а не выкидываем эксепшны
     if ($controller->getRequest()->isPost()) {
         $data = $controller->getRequest()->getPost();
         $user = Evil_Structure::getObject('user');
         $user->where('nickname', '=', $data['username']);
         if ($user->load()) {
             if ($user->getValue('password') == md5($data['password'])) {
                 return $user->getId();
             } else {
                 $login_view->error_message = _('Password incorrect');
             }
         } else {
             $login_view->error_message = _('User not found');
         }
         $login_view->username = $login_view->escape($data['username']);
     }
     $controller->view->form = $login_view->render(basename($viewfile));
     return -1;
 }
Ejemplo n.º 8
0
 /**
  * @group ZF-9595
  */
 public function testEscapeShouldAllowAndUseMoreThanOneArgument()
 {
     $view = new Zend_View();
     $view->setEscape(array($this, 'escape'));
     $this->assertEquals('foobar', $view->escape('foo', 'bar'));
 }
Ejemplo n.º 9
0
 public function testCustomEscape()
 {
     $view = new Zend_View();
     $view->setEscape('strip_tags');
     $original = "<p>Some text</p>";
     $escaped  = $view->escape($original);
     $this->assertNotEquals($original, $escaped);
     $this->assertEquals("Some text", $escaped);
 }
Ejemplo n.º 10
0
 /**
  * Custom Auth
  * @param Zend_Controller_Action $controller
  * @param String $viewfile
  */
 private function _doCustomAuth($controller, $viewfile)
 {
     $login_view = new Zend_View();
     $login_view->setScriptPath(APPLICATION_PATH . dirname($viewfile));
     $config = Zend_Registry::get('config');
     $config = is_object($config) ? $config->toArray() : $config;
     // require http post method
     if ($controller->getRequest()->isPost()) {
         $data = $controller->getRequest()->getPost();
         // FIXME change to 'timeout' => $config['evil']['auth']['soa']['timeout']
         $timeout = 3000;
         if (isset($config['evil']['auth']['soa']['timeout'])) {
             $timeout = $config['evil']['auth']['soa']['timeout'];
         }
         $timeout = 999999999999;
         // @todo create new method
         // auth on SOA_Service_Auth
         $call = array('service' => 'Auth', 'method' => 'keyGet', 'data' => array('login' => $data['username'], 'password' => $data['password'], 'timeout' => $timeout));
         //$result = $controller->rpc->make($call);
         //$result = new SOA_Result();
         $result = $this->_makeSOACall($call);
         if (SOA_Result::Success == $result->getStatus()) {
             $res = $result->getArgs();
             $key = $res['key'];
             // get user info
             $call = array('service' => 'Auth', 'method' => 'userInfo', 'data' => array('key' => $key, 'array' => 1));
             $result = $this->_makeSOACall($call);
             if (SOA_Result::Success == $result->getStatus()) {
                 $res = $result->getArgs();
                 $user = isset($res['user']) ? $res['user'] : array();
                 $role = empty($user['role']) ? 'citizen' : $user['role'];
                 $login = $user['login'];
                 $evilUser = Evil_Structure::getObject('user');
                 $evilUser->where('nickname', '=', $user['login']);
                 /**
                  * возьмем все данные что пришли нам от сервиса
                  *
                  * @author NuR
                  * @var array
                  */
                 $data = array_merge($user, array('nickname' => $login, 'password' => $key));
                 // cache user info in local system
                 if ($evilUser->load()) {
                     $evilUser->update($data);
                     return $evilUser->getId();
                 } else {
                     $data['uid'] = uniqid();
                     //  var_dump($user);die();
                     $evilUser->create($data['id'], $data);
                     // reload for get id
                     $evilUser->where('nickname', '=', $user['login']);
                     if ($evilUser->getId()) {
                         return $evilUser->getId();
                     }
                 }
             }
         }
         $login_view->error_message = _('User not found');
         $login_view->username = $login_view->escape($data['username']);
     }
     $userid = Zend_Registry::get('userid');
     $evilUser = Evil_Structure::getObject('user');
     $evilUser->where('id', '=', $userid);
     if ($evilUser->load()) {
         $login_view->username = $evilUser->getValue('nickname');
     }
     $controller->view->form = $login_view->render(basename($viewfile));
     return $userid;
     //return -1;
 }
Ejemplo n.º 11
0
 /**
  * Converts an associative array to a string of tag attributes.
  *
  * This function is clone from Zend_View_Helper_HtmlElement
  *
  * @param array $attribs From this array, each key-value pair is
  *                       converted to an attribute name and value.
  *
  * @return string The XHTML for the attributes.
  */
 public static function htmlAttribs($attribs)
 {
     $view = new Zend_View();
     $xhtml = '';
     foreach ((array) $attribs as $key => $val) {
         $key = $view->escape($key);
         if ('on' == substr($key, 0, 2) || 'constraints' == $key) {
             // Don't escape event attributes; _do_ substitute double quotes with singles
             if (!is_scalar($val)) {
                 // non-scalar data should be cast to JSON first
                 include_once 'Zend/Json.php';
                 $val = self::encodeJson($val);
             }
             $val = preg_replace('/"([^"]*)":/', '$1:', $val);
         } else {
             if (is_array($val)) {
                 $val = implode(' ', $val);
             }
             $val = $view->escape($val);
         }
         if (strpos($val, '"') !== false) {
             $xhtml .= " {$key}='{$val}'";
         } else {
             $xhtml .= " {$key}=\"{$val}\"";
         }
     }
     return $xhtml;
 }
Ejemplo n.º 12
0
 /**
  * Get the error markup for the given set of messages
  *
  * @param  array $messages
  * @param  View  $view
  * @return string
  */
 public function getErrorMarkup(array $messages, View $view)
 {
     if (empty($messages)) {
         array_push($messages, $this->getFallbackMessage());
     }
     $messageSeparator = $this->getMessageSeparator();
     $errorTemplate = $this->getErrorWrapperTemplate();
     $messageTemplate = $this->getMessageTemplate();
     array_walk($messages, function (&$message) use($view, $messageTemplate) {
         $message = sprintf($messageTemplate, $view->escape($message));
     });
     return sprintf($errorTemplate, implode($messageSeparator, $messages));
 }