/** * Prep a curl connection and run it * @param string $url url to fetch content from * @param array $headers HTTP header array * @param array $post post fields * @return array */ private function curl_execute($url, $headers, $post) { $ch = Hm_Functions::c_init(); $this->curl_setopt($ch, $url, $headers); $this->curl_setopt_post($ch, $post); return $this->curl_result($ch); }
/** * post to an oauth2 endpoint * @param string $url url to post to * @param array $flds post data * @return array */ private function curl_post($url, $flds) { $result = array(); $ch = Hm_Functions::c_init(); Hm_Functions::c_setopt($ch, CURLOPT_URL, $url); Hm_Functions::c_setopt($ch, CURLOPT_POST, 5); Hm_Functions::c_setopt($ch, CURLOPT_POSTFIELDS, $flds); Hm_Functions::c_setopt($ch, CURLOPT_RETURNTRANSFER, 1); Hm_Functions::c_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); $curl_result = Hm_Functions::c_exec($ch); if (substr($curl_result, 0, 1) == '{') { $result = @json_decode($curl_result, true); } return $result; }
public function process() { if (Hm_Page_Cache::get('nux_dev_news')) { $this->out('nux_dev_news', Hm_Page_Cache::get('nux_dev_news')); return; } $ch = Hm_Functions::c_init(); $res = array(); Hm_Functions::c_setopt($ch, CURLOPT_URL, 'http://cypht.org/git.txt'); Hm_Functions::c_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $curl_result = Hm_Functions::c_exec($ch); if (trim($curl_result)) { foreach (explode("\n", $curl_result) as $line) { if (preg_match("/^([a-z0-9]{40})\\|([a-z0-9]{7})\\|([^\\|]+)\\|([^\\|]+)\\|([^\\|]+)\$/", $line, $matches)) { $res[] = array('hash' => $matches[1], 'shash' => $matches[2], 'name' => $matches[3], 'age' => date('D, M d', strtotime($matches[4])), 'note' => $matches[5]); } } } Hm_Page_Cache::add('nux_dev_news', $res); $this->out('nux_dev_news', $res); }