Exemplo n.º 1
0
/**
 * Smarty is_url modifier plugin
 *
 * Type:     modifier<br>
 * Name:     truncate<br>
 * Purpose:  Truncate a string to a certain length if necessary,
 *           optionally splitting in the middle of a word, and
 *           appending the $etc string or inserting $etc into the middle.
 * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
 *          truncate (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param integer
 * @param string
 * @param boolean
 * @param boolean
 * @return string
 */
function smarty_modifier_is_url($url, $origurl = null)
{
    if (empty($url)) {
        return false;
    }
    if (!isset($origurl)) {
        $origurl = urldecode($_SERVER['REQUEST_URI']);
    }
    return strings::strpos($origurl, $url) === 0 ? true : false;
}
Exemplo n.º 2
0
 /**
 * Login stuff
 */
 function login()
 {
     if ($this->_authed) {
         return;
     }
     $this->_in_login = true;
     core::dprint(array("[MW_LOGIN] %s:%s (%s)", $this->_acc->login, $this->_acc->password, $this->_acc->c_name));
     /** @var http */
     $http = $this->_http();
     $http->set_debug($this->_debug);
     $this->_in_login = false;
     /** @var sae_cacher */
     $sc = core::lib('sape_cacher');
     $http->wget(self::MOSWAR_URL);
     $this->sleep(5, 5);
     /*
     var_dump(           
         $http->post(self::MOSWAR_URL . 'login_mock.php', $this->_acc->as_array())
     );
     */
     $post_data = array('action' => 'login', 'email' => $this->_acc->login, 'password' => $this->_acc->password, 'remember' => 'on');
     //$buffer = $http->post(self::MOCK_URL /*MOSWAR_URL*/, $post_data);
     $buffer = $http->post(self::MOSWAR_URL, $post_data);
     $http->SaveCookies($cooks);
     if ($this->_debug) {
         file_put_contents('login-out.html', $buffer);
         file_put_contents('login-out-cookie.html', var_export($cooks, 1));
     }
     if ($cooks && strings::strpos($buffer, 'Неверно указан e-mail адрес или пароль') === false) {
         $sc->set('cookie', $this->_acc->id, $cooks);
         $this->_authed = true;
     } else {
         throw new moswar_exception('Cant login: ' . $this->_acc->login);
     }
 }
Exemplo n.º 3
0
 /**
  * Check route matched to uri
  * Extract params (only for regex <?Pname> routes)
  */
 private function _is_route_matched($route, &$params)
 {
     $match = isset($route['match']) ? $route['match'] : false;
     $uri = $this->_uri;
     // wildcard: /url/blabla/*
     if ($match) {
         if ($match == '*') {
             $match = '';
             $uri = '';
         } else {
             if (strings::strpos($match, '*') !== false) {
                 $match = strings::substr($match, 0, strings::strpos($match, '*'));
                 $uri = strings::substr($uri, 0, strings::strlen($match));
             }
         }
     }
     return isset($route['regex']) && preg_match($route['regex'], $this->_uri, $params) && array_shift($params) || $match !== false && $uri == $match;
 }