示例#1
0
文件: mod_esi.php 项目: poef/ariadne
 function esiExpression($expression)
 {
     /*  Regexp now matches $(HTTP_COOKIE{stuff});
     			TODO:
     			Add matching for:
     				[v] $(HTTP_COOKIE{stuff}|default)
     				[v] $(HTTP_COOKIE{stuff}|'default blah')
     
     			Add variable replacement for:
     				[v] HTTP_ACCEPT_LANGUAGE
     				[v] HTTP_HOST
     				[v] HTTP_REFERER
     				[v] QUERY_STRING
     
     				HTTP_USER_AGENT
     			FIXME: ariadne cookies are serialized by default, which would break HTTP_COOKIE usage in other ESI processors
     		*/
     $result = preg_replace_callback('!\\$\\(([^)|{]*)(\\{(([^}]*))\\})?(\\|([^)]*))?\\)!', function ($matches) {
         // print_r($matches);
         switch ($matches[1]) {
             case 'HTTP_COOKIE':
                 $cookie = ldGetUserCookie($matches[3]);
                 $default = preg_replace("/^'(.*?)'\$/", "\$1", $matches[6]);
                 return $cookie ? $cookie : $default;
                 break;
             case 'HTTP_HOST':
                 $host = ldGetServerVar('HTTP_HOST');
                 $default = preg_replace("/^'(.*?)'\$/", "\$1", $matches[6]);
                 return $host ? $host : $default;
                 break;
             case 'HTTP_REFERER':
                 $referer = ldGetServerVar('HTTP_REFERER');
                 $default = preg_replace("/^'(.*?)'\$/", "\$1", $matches[6]);
                 return $referer ? $referer : $default;
                 break;
             case 'HTTP_ACCEPT_LANGUAGE':
                 $acceptLanguage = ldGetServerVar('HTTP_ACCEPT_LANGUAGE');
                 $acceptLanguage = strtolower(str_replace(", ", ",", $acceptLanguage));
                 $languages = explode(",", $acceptLanguage);
                 if (in_array(strtolower($matches[3]), $languages)) {
                     return 1;
                 }
                 return 0;
                 break;
             case 'QUERY_STRING':
                 $value = ar_loader::getvar($matches[3], "GET");
                 $default = preg_replace("/^'(.*?)'\$/", "\$1", $matches[6]);
                 return isset($value) ? $value : $default;
                 break;
         }
     }, $expression);
     return $result;
 }
示例#2
0
文件: html.php 项目: poef/ariadne
 public static function link($content, $attributes = array(), $path = null, $url = null)
 {
     if (self::$editMode) {
         $url = ar_loader::makeURL($path);
         $attributes['href'] = $url . self::$editTemplate;
         $attributes['target'] = self::$editTarget;
     } else {
         if (!isset($url)) {
             $url = ar_loader::makeURL($path);
         }
         $attributes['href'] = $url;
     }
     return ar_html::tag('a', $attributes, $content);
 }
示例#3
0
文件: twitter.php 项目: poef/ariadne
 public function login($consumerKey = null, $consumerSecret = null, $callback = '', $redirect = true)
 {
     // FIXME: $redirect should probably be allowed to be an object that implements a redirect() method
     $session = ar_loader::session();
     //FIXME: allow different session object to be passed
     if (!$session->id()) {
         $session->start();
     }
     if (isset($callback) && substr((string) $callback, 0, 4) != 'http' && $callback != 'oob') {
         $callback = ar_loader::makeURL() . $callback;
     }
     if (!$this->client instanceof ar_connect_oauthClient) {
         ////FIXME: a real OAuth is also ok
         // FIXME: what if you want a caching client?
         $this->client = ar_connect_oauth::client($consumerKey, $consumerSecret);
         if (ar_error::isError($this->client)) {
             return $this->client;
         }
     }
     $access_token = $session->getvar('access_token');
     $access_token_secret = $session->getvar('access_token_secret');
     if ($access_token && $access_token_secret) {
         $this->client->setToken($access_token, $access_token_secret);
         return true;
     }
     $oauth_verifier = $session->getvar('oauth_verifier');
     $oauth_token = $session->getvar('oauth_token');
     $oauth_token_secret = $session->getvar('oauth_token_secret');
     if (!$oauth_verifier) {
         $oauth_verifier = ar::getvar('oauth_verifier');
         if ($oauth_verifier) {
             $session->putvar('oauth_verifier', $oauth_verifier);
         } else {
             if (!$callback) {
                 $callback = 'oob';
             }
             $info = $this->client->getRequestToken('https://api.twitter.com/oauth/request_token', (string) $callback);
             if (ar_error::isError($info)) {
                 $info->debugInfo = $this->client->debugInfo;
                 return $info;
             }
             $this->client->setToken($info['oauth_token'], $info['oauth_token_secret']);
             $session->putvar('oauth_token', $info['oauth_token']);
             $session->putvar('oauth_token_secret', $info['oauth_token_secret']);
             if ($redirect) {
                 ar_loader::redirect('https://api.twitter.com/oauth/authorize?oauth_token=' . RawUrlEncode($info['oauth_token']));
                 return false;
             } else {
                 return 'https://api.twitter.com/oauth/authorize?oauth_token=' . RawUrlEncode($info['oauth_token']);
             }
         }
     }
     if ($oauth_verifier) {
         $this->client->setToken($oauth_token, $oauth_token_secret);
         $info = $this->client->getAccessToken('https://api.twitter.com/oauth/access_token', '', $oauth_verifier);
         if (ar_error::isError($info)) {
             $info->debugInfo = $this->client->debugInfo;
             return $info;
         }
         $access_token = $info['oauth_token'];
         $access_token_secret = $info['oauth_token_secret'];
         $this->client->setToken($access_token, $access_token_secret);
         $session->putvar('access_token', $access_token);
         $session->putvar('access_token_secret', $access_token_secret);
         return $info;
     }
     return false;
 }
示例#4
0
文件: ar.php 项目: poef/ariadne
 public static function getLoader($options = array())
 {
     //FIXME: move code from ar_loader to here
     return ar_loader::getLoader();
 }
示例#5
0
文件: loader.php 项目: poef/ariadne
 public static function session()
 {
     if (!self::$session) {
         self::$session = new ar_loaderSession();
     }
     return self::$session;
 }