Jump to content

Recommended Posts

Hey everyone, this sucks, but I have no idea what this script is and what it does, (Go figure), I also have no idea what this function does. Could anyone help me? =)

 

 

Error:

Fatal error: Call to undefined function curl_init() in C:\Documents and Settings\Compaq_Owner\Desktop\Server Files\XAMPP\xampp\htdocs\StickamPHP\Services\Stickam\API\Base.php on line 73

 

 


<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* PHP5 interface for Stickam API
*
* PHP version 5 or newer
*
* @category  Services
* @package   Services_Stickam
* @author    Advanced Video Communications Inc.
* @copyright 2008 Advanced Video Communications Inc.
* @license   
* @link      http://developer.stickam.com/
*/

require_once '../Services/Stickam/Common.php';

/**
* Services_Stickam_API_Base
*
* Abstract class for all Stickam API Classes
*
* @category  Services
* @package   Services_Stickam_API_Base
* @link      http://developer.stickam.com/
*/
abstract class Services_Stickam_API_Base
{
//{{{ request()
    /**
     * send a request to the API
     */
    protected function request($api, array $args = array(), $method = null)
    {
        $url = Services_Stickam_Common::$URL . $api;

        $args['key'] = Services_Stickam_Common::$API_KEY;
        $args['rid'] = round(microtime(true) * 1000);
        $args        = $this->sign($args);

        if ( $method == 'POST' ) {
            $result = $this->_http_post($url, $args);
        } else {
            $result = $this->_http_get($url, $args);
        }

        $this->debug($result . "\n");

        $xml = @simplexml_load_string($result);
        if ( ! $xml instanceof SimpleXmlElement ) {
            throw new Services_Stickam_Exception(
                'Could not parse XML response', 0
            );
        }

        return $xml;
    }
//}}}

//{{{ _http_get()
    /**
     * HTTP GET request
     */
    private function _http_get($url, array $args = array())
    {
        $url .= '?';
        foreach ( $args as $k => $v ) {
            $url .= '&' . $k . '=' . urlencode($v);
        }
        $this->debug($url . "\n");

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,            $url);
        curl_setopt($ch, CURLOPT_HEADER,         false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Services_Stickam_Common::$TIMEOUT);
        $result = curl_exec($ch);

        if ( curl_errno($ch) ) {
            throw new Services_Stickam_Exception(
                curl_error($ch), curl_errno($ch)
            );
        }

        $info = curl_getinfo($ch);
        if ( $info['http_code'] != 200 ) {
            throw new Services_Stickam_Exception(
                'Services not available.', $info['http_code']
            );
        }
        curl_close($ch);

        return $result;
    }
//}}}

//{{{ _http_post()
    /**
     * HTTP POST request
     */
    protected function _http_post($url, array $args = array())
    {
        $fields = '';
        foreach ( $args as $k => $v ) {
            $fields .= '&' . $k . '=' . urlencode($v);
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,            $url);
        curl_setopt($ch, CURLOPT_POST,           true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,     $fields);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Services_Stickam_Common::$TIMEOUT);
        $result = curl_exec($ch);

        if ( curl_errno($ch) ) {
            throw new Services_Stickam_Exception(
                curl_error($ch), curl_errno($ch)
            );
        }

        $info = curl_getinfo($ch);
        if ( $info['http_code'] != 200 ) {
            throw new Services_Stickam_Exception(
                'Services not available.', $info['http_code']
            );
        }
        curl_close($ch);

        return $result;
    }
//}}}

//{{{ sign()
    /**
     * Sign the request
     *
     * @link http://developer.stickam.com/index.php?title=Getting_Started#Validation
     */
    protected function sign(array $args)
    {
        if ( isset($args['sig']) ) {
            unset($args['sig']);
        }

        $sig = '';
        ksort($args);
        foreach ( $args as $k => $v ) {
            if ( $k == 'rid' ) continue;
            $sig .= $v;
        }
        $sig = $sig . Services_Stickam_Common::$SECRET_KEY . $args['rid'];
        $this->debug('sig: ' . $sig . "\n");

        $args['sig'] = md5($sig);
        return $args;
    }
//}}}

//{{{ debug()
    public function debug($s = '')
    {
        if ( Services_Stickam_Common::$DEBUG ) {
            echo $s;
        }
    }
//}}}
}
?>

 

Thanks for everyone's help =D

Link to comment
https://forums.phpfreaks.com/topic/140210-stickams-script-d/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.