コード例 #1
0
 /**
  * Given a hash of key/value pairs, generate a URL for this application.
  * It will try and select the best URL for the situation by first going
  * through all the routes and seeing which is the best match.  Then, any
  * remaining parameters are put into the querystring.
  *
  * Given the following and assuming the default route list:
  * @code
  * create_url(array('controller' => 'user', 'action' => 'list', 'some_param' => '1'))
  * @endcode
  *
  * Should generate:
  * @code
  * /user/list?some_param=1
  * @endcode
  *
  * @param array List of parameters used to create the url
  * @return string
  * @author Ted Kulp
  **/
 public static function create_url($params = array())
 {
     $new_url = '';
     foreach (SilkRoute::get_routes() as $one_route) {
         $route_params = SilkRoute::get_params_from_route($one_route->route_string);
         $diff = array_diff($route_params, array_keys($params));
         if (!count($diff)) {
             //This is the first route that should work ok for the given parameters
             //Even if it's short, we can add the rest on via the query string
             $new_url = $one_route->route_string;
             $similar = array_intersect($route_params, array_keys($params));
             foreach ($similar as $one_param) {
                 $new_url = str_replace(":{$one_param}", $params[$one_param], $new_url);
                 unset($params[$one_param]);
             }
             break;
         }
     }
     if (count($params)) {
         $new_url = $new_url . '?' . http_build_query($params, '', '&');
     }
     return SilkRequest::get_calculated_url_base(true, true) . $new_url;
 }
コード例 #2
0
 function login()
 {
     if ($_REQUEST['openid_mode']) {
         $consumer = $this->get_consumer();
         $response = $consumer->complete(SilkRequest::get_requested_uri(true));
         $msg = '';
         if ($response->status == Auth_OpenID_CANCEL) {
             // This means the authentication was cancelled.
             $this->validation_errors[] = 'Verification cancelled.';
         } else {
             if ($response->status == Auth_OpenID_FAILURE) {
                 // Authentication failed; display the error message.
                 $this->validation_errors[] = "OpenID authentication failed: " . $response->message;
             } else {
                 if ($response->status == Auth_OpenID_SUCCESS) {
                     $esc_identity = htmlentities($response->getDisplayIdentifier());
                     $user = orm('user')->find_by_openid($esc_identity);
                     if ($user != null) {
                         self::$current_user = $user;
                         $_SESSION['silk_user'] = $user;
                         return true;
                     } else {
                         $this->validation_errors[] = "No user associated to this login";
                     }
                 }
             }
         }
     } else {
         if ($this->params != null && is_array($this->params)) {
             if ($this->params['username'] != '' && $this->params['password'] != '') {
                 $user = orm('silk_user')->find_by_username($this->params['username']);
                 if ($user != null) {
                     //Add salt
                     if ($user->password == $this->encode_password($this->params['password'])) {
                         self::$current_user = $user;
                         $_SESSION['silk_user'] = $user;
                         return true;
                     }
                 }
                 $this->validation_errors[] = 'Username or password incorrect.';
             } else {
                 if ($this->params['openid'] != '') {
                     $consumer = $this->get_consumer();
                     $auth_request = $consumer->begin($this->params['openid']);
                     if ($auth_request) {
                         if ($auth_request->shouldSendRedirect()) {
                             $redirect_url = $auth_request->redirectURL(SilkRequest::get_calculated_url_base(true), SilkRequest::get_requested_uri(true));
                             redirect($redirect_url);
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
コード例 #3
0
function smarty_function_javascript($params, &$smarty)
{
    if ($params['file']) {
        return '<script type="text/javascript" src="' . join_url(SilkRequest::get_calculated_url_base(true), $params['file']) . '"></script>';
    }
}