예제 #1
0
파일: Post.php 프로젝트: eghojansu/web
 public function slug($slug)
 {
     $slug || ($slug = Web::instance()->slug($this->title));
     $that = clone $this;
     $that->findBySlugBegin($slug)->get();
     return $slug . ($that->dry() ? '' : '-' . ($that->count() + 1));
 }
예제 #2
0
파일: Geo.php 프로젝트: eghojansu/moe
 /**
  *	Return weather data based on specified latitude/longitude
  *	@return array|FALSE
  *	@param $latitude float
  *	@param $longitude float
  **/
 function weather($latitude, $longitude)
 {
     $fw = Base::instance();
     $web = Web::instance();
     $query = array('lat' => $latitude, 'lon' => $longitude);
     $req = $web->request('http://api.openweathermap.org/data/2.5/weather?' . http_build_query($query));
     return ($req = $web->request('http://api.openweathermap.org/data/2.5/weather?' . http_build_query($query))) ? json_decode($req['body'], TRUE) : FALSE;
 }
예제 #3
0
파일: StaticMap.php 프로젝트: eghojansu/moe
 /**
  *	Generate map
  *	@return string
  **/
 function dump()
 {
     $fw = Base::instance();
     $web = Web::instance();
     $out = '';
     return ($req = $web->request(self::URL_Static . '?' . array_reduce($this->query, function ($out, $item) {
         return $out .= ($out ? '&' : '') . urlencode($item[0]) . '=' . urlencode($item[1]);
     }))) && $req['body'] ? $req['body'] : FALSE;
 }
예제 #4
0
파일: PingBack.php 프로젝트: eghojansu/moe
 /**
  *	Receive ping, check if local page is pingback-enabled, verify
  *	source contents, and return XML-RPC response
  *	@return string
  *	@param $func callback
  *	@param $path string
  **/
 function listen($func, $path = NULL)
 {
     $fw = Base::instance();
     if (PHP_SAPI != 'cli') {
         header('X-Powered-By: ' . $fw->get('PACKAGE'));
         header('Content-Type: application/xml; ' . 'charset=' . ($charset = $fw->get('ENCODING')));
     }
     if (!$path) {
         $path = $fw->get('BASE');
     }
     $web = Web::instance();
     $args = xmlrpc_decode_request($fw->get('BODY'), $method, $charset);
     $options = array('encoding' => $charset);
     if ($method == 'pingback.ping' && isset($args[0], $args[1])) {
         list($source, $permalink) = $args;
         $doc = new DOMDocument('1.0', $fw->get('ENCODING'));
         // Check local page if pingback-enabled
         $parts = parse_url($permalink);
         if ((empty($parts['scheme']) || $parts['host'] == $fw->get('HOST')) && preg_match('/^' . preg_quote($path, '/') . '/' . ($fw->get('CASELESS') ? 'i' : ''), $parts['path']) && $this->enabled($permalink)) {
             // Check source
             $parts = parse_url($source);
             if ((empty($parts['scheme']) || $parts['host'] == $fw->get('HOST')) && ($req = $web->request($source)) && $doc->loadhtml($req['body'])) {
                 $links = $doc->getelementsbytagname('a');
                 foreach ($links as $link) {
                     if ($link->getattribute('href') == $permalink) {
                         call_user_func_array($func, array($source, $req['body']));
                         // Success
                         die(xmlrpc_encode_request(NULL, $source, $options));
                     }
                 }
                 // No link to local page
                 die(xmlrpc_encode_request(NULL, 0x11, $options));
             }
             // Source failure
             die(xmlrpc_encode_request(NULL, 0x10, $options));
         }
         // Doesn't exist (or not pingback-enabled)
         die(xmlrpc_encode_request(NULL, 0x21, $options));
     }
     // Access denied
     die(xmlrpc_encode_request(NULL, 0x31, $options));
 }
예제 #5
0
파일: Markdown.php 프로젝트: eghojansu/moe
 /**
  *	Process setext-style heading
  *	@return string
  *	@param $str string
  *	@param $type string
  **/
 protected function _setext($str, $type)
 {
     $level = strpos('=-', $type) + 1;
     return '<h' . $level . ' id="' . Web::instance()->slug($str) . '">' . $this->scan($str) . '</h' . $level . '>' . "\n\n";
 }
예제 #6
0
파일: OpenID.php 프로젝트: eghojansu/moe
 /**
  *	Return TRUE if OpenID verification was successful
  *	@return bool
  *	@param $proxy string
  **/
 function verified($proxy = NULL)
 {
     preg_match_all('/(?<=^|&)openid\\.([^=]+)=([^&]+)/', $_SERVER['QUERY_STRING'], $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $this->args[$match[1]] = urldecode($match[2]);
     }
     if (isset($this->args['mode']) && $this->args['mode'] != 'error' && ($this->url = $this->discover($proxy))) {
         $this->args['mode'] = 'check_authentication';
         $var = array();
         foreach ($this->args as $key => $val) {
             $var['openid.' . $key] = $val;
         }
         $req = Web::instance()->request($this->url, array('method' => 'POST', 'content' => http_build_query($var), 'proxy' => $proxy));
         return (bool) preg_match('/is_valid:true/i', $req['body']);
     }
     return FALSE;
 }