if ( $data !== false ) return json_decode($data); return false; } /** * Get unsecured Url (no login / no IP check) to a private publication * * @param integer $pub_id Publication's ID * @param integer $page_nr (optional) Direct Url to a page * @param integer $expdelay (optional) Lifetime of the generated Url * @return void */ public function getUnsecuredUrl( $pub_id, $page_nr = 1, $expdelay = 0 ) { $pub_id = intval($pub_id); $page_nr = intval($page_nr); $page_nr = $page_nr < 1 ? 1 : $page_nr; $expdelay = intval($expdelay); $expdelay = $expdelay > 0 ? $expdelay : $this->expdelay; $time = self::timestamp(); $hash = self::hash( self::$accesskey, self::$secretkey, $time, $expdelay, $pub_id, ( $page_nr > 1 ? $page_nr : 1 ) ); return $url = self::$ppurl.'?cmd=uu&h='.$hash.'&aki='.self::$accesskey.'&time='.$time.'&exp='.$expdelay.'&pub='.$pub_id.( $page_nr > 1 ? '&page='.$page_nr : '' ); } /** * Set request expire delay in seconds * * @param integer $expdelay Keep the query alive to $expdelay seconds * @return void */ public function setExpDelay( $expdelay ) { $this->expdelay = intval($expdelay); } /** * Get server's timestamp in GMT +0000 timezon * * @return integer */ private static function timestamp() { $dtzone = new DateTimeZone('Europe/London'); $dtime = new DateTime( 'now', $dtzone ); return $dtime->getTimestamp(); } /** * Generate hash code from arguments * * @return string */ public static function hash() { $args = func_get_args(); return substr(self::sha3(implode('',$args)),0,16); } /** * Encode string with sha512 * * @param string $str * @return string */ private static function sha3($str) { return hash("sha512", $str); } /** * Get URL content * * @param string $url URL to get * @param number $timeout timeout to wait for response. * @return mixed Return value or false. */ public static function url( $url, $timeout = 5 ) { $result = false; //check if curl_init available if ( is_callable('curl_init') ) { try { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = @curl_exec($ch); curl_close($ch); } catch (Exception $e) { } } else { $context = stream_context_create( array( 'http'=> array( 'timeout' => $timeout, ), 'https'=> array( 'timeout' => $timeout, ), 'ssl' => array( 'verify_peer' => false, ) ) ); $result = @file_get_contents( $url, false, $context ); } return $result; } } ?>