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)); }
/** * 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; }
/** * 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; }
/** * 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)); }
/** * 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"; }
/** * 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; }