Exemplo n.º 1
0
 /**
  * Send the user to the authorisation page and redirect to the callback page on completion
  * 
  * @param string $callback_url The url to redirect the user to once they're logged in at Videojuicer
  * @param string $unauthorized_token_value The token value to use when signning the request (optional: if no value passed, the current one is retrieved from the Videojuicer class)
  */
 public static function get_authorize_url($callback_url, $unauthorized_token_value = null)
 {
     // If we weren't given a token to use, retrieve it from Videojuicer class
     if (is_null($unauthorized_token_value)) {
         $token = Videojuicer::get_token();
         if ($token instanceof Videojuicer_Token_Unauthorized) {
             $unauthorized_token_value = $token->get_token();
         }
     }
     $method = "oauth/tokens/new";
     $type = Videojuicer_Request::GET;
     $response_class = "Videojuicer_Token_Authorize_Response";
     $exception_class = "Videojuicer_Token_Authorize_Exception";
     $permission = Videojuicer_Permission::NONE;
     $request = new Videojuicer_Request($method, $type, $permission, $response_class, $exception_class);
     $request->set_authorized(true, $unauthorized_token_value);
     $request->set_vars(array("oauth_callback" => $callback_url));
     $request->use_extension(false);
     // Do the logic to decide what the components of the HTTP request should be
     Videojuicer_ClassLoader::load("Videojuicer_Call_Helper");
     $helper = new Videojuicer_Call_Helper($request);
     $helper->setup_components();
     // Retrieve the values determined
     $url = $helper->get_url();
     return $url;
 }
Exemplo n.º 2
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_Response");
class Videojuicer_Asset_Video_Response extends Videojuicer_Response
{
    private $xml_object;
    /**
     * Process the result
     */
    public function __construct($xml)
    {
        $this->xml_object = simplexml_load_string($xml);
    }
    /**
     * Return the result
     */
    public function get_response()
    {
        return $this->xml_object;
    }
}
Exemplo n.º 3
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_Exception");
class Videojuicer_Response_Format_Exception extends Videojuicer_Exception
{
}
Exemplo n.º 4
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_Request");
Videojuicer_ClassLoader::load("Videojuicer_Permission");
Videojuicer_ClassLoader::load("Videojuicer_Request_Asset");
class Videojuicer_Request_Asset_Video extends Videojuicer_Request_Asset
{
    private static $asset_type = "video";
    public static function find($id)
    {
        return parent::find(self::$asset_type, $id);
    }
    public static function find_all($criteria = array())
    {
        return parent::find_all(self::$asset_type, $criteria);
    }
    public static function create($criteria = array(), $token_value, $token_secret)
    {
        return parent::create(self::$asset_type, $criteria, $token_value, $token_secret);
    }
    public static function update($id, $criteria = array(), $token_value, $token_secret)
    {
        return parent::update(self::$asset_type, $id, $criteria, $token_value, $token_secret);
    }
}
Exemplo n.º 5
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_Token_Unauthorized_Exception");
Videojuicer_ClassLoader::load("Videojuicer_Token_Abstract");
class Videojuicer_Token_Unauthorized extends Videojuicer_Token_Abstract
{
    private $token;
    private $secret;
    /**
     * Create an unauthorized token object from the oauth encodd string in the form
     * oauth_token=thetoken&oauth_token_secret=thesecret
     *
     * @param string $url_encoded oauth_token=thetoken&oauth_token_secret=thesecret
     */
    public function __construct($url_encoded)
    {
        // Extract the token/secret
        $components = $this->extract_components($url_encoded);
        // If we managed to extract a token/secret
        if (isset($components["token"]) && isset($components["secret"])) {
            echo "Setting secret: " . $components["secret"];
            // Store the data
            $this->set_token($components["token"]);
            $this->set_secret($components["secret"]);
        } else {
            throw new Videojuicer_Token_Unauthorized_Exception("Response format invalid");
        }
    }
    public function set_token($token)
    {
        $this->token = $token;
Exemplo n.º 6
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_Request");
Videojuicer_ClassLoader::load("Videojuicer_Permission");
class Videojuicer_Request_Presentation
{
    /**
     * Get the presentation with the provided ID
     *
     * @param int $id
     * @param boolean $oembed Whether to make this call as an OEmbed request
     * @param int $maxwidth The maximum width of the presentation if making an OEmbed request, if OEmbed this is mandatory
     * @param int $maxheight The maximum height of the presentation if making an OEmbed request, if OEmbed this is mandatory
     * @param string $oembed_format The format of the OEmbed response, by default is "xml" but also supports "json"
     * 
     * @return Videojuicer_Presentation_Response
     */
    public static function find($id, $oembed = false, $maxwidth = null, $maxheight = null, $oembed_format = "xml", $embed_attributes = array(), $flashvar_attributes = array())
    {
        $method = "presentations/{$id}";
        $type = Videojuicer_Request::GET;
        // Determine the response/exception based on whether it is an oembed call
        if ($oembed) {
            $response_class = "Videojuicer_Oembed_Presentation_Response";
            $exception_class = "Videojuicer_Oembed_Presentation_Exception";
        } else {
            $response_class = "Videojuicer_Presentation_Response";
            $exception_class = "Videojuicer_Presentation_Exception";
        }
        $permission = Videojuicer_Permission::NONE;
        $request = new Videojuicer_Request($method, $type, $permission, $response_class, $exception_class);
Exemplo n.º 7
0
 /**
  * Perform the retrieval using CURL
  *
  * @return SimpleXMLElement
  */
 private static function execute_call_curl($url, $type = "get", $post_vars = array(), $file = false)
 {
     // Determine how to make the request
     switch ($type) {
         // Make a POST request for POST, PUT and DELETE (not all servers support PUT and DELETE)
         case Videojuicer_Request::POST:
         case Videojuicer_Request::PUT:
         case Videojuicer_Request::DELETE:
             $make_post = true;
             break;
         case Videojuicer_Request::GET:
         default:
             $make_post = false;
             break;
     }
     if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
         echo "URL: {$url}<br />\n";
     }
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // Tell cURL if we're making a post request
     if ($make_post) {
         if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
             echo "POST VARS BEFORE HTTP_BUILD_QUERY: " . print_r($post_vars, true);
         }
         // If there is a file o be included, add it to the array and make the post data an array so cURL multiparts the transfer
         if ($file) {
             $post_vars["asset[file]"] = "@{$file}";
             $post_data = $post_vars;
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
             // Else doesn't need to be multipart so build post data into a string
         } else {
             $post_data = http_build_query($post_vars);
         }
         if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
             echo "POST DATA: {$post_data}<br />\n";
         }
         curl_setopt($ch, CURLOPT_VERBOSE, 1);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     }
     // Make the call
     $data = curl_exec($ch);
     if (curl_errno($ch)) {
         Videojuicer_ClassLoader::load("Videojuicer_Request_Exception");
         throw new Videojuicer_Request_Exception('execute_call_curl error: ' . curl_error($ch), curl_errno($ch));
     } else {
         curl_close($ch);
         if (!$data || strlen(trim($data)) < 2) {
             Videojuicer_ClassLoader::load("Videojuicer_Request_Exception");
             throw new Videojuicer_Request_Exception('API request error: No result returned.', 1);
         }
         return $data;
     }
 }
Exemplo n.º 8
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_Response");
Videojuicer_ClassLoader::load("Videojuicer_Token_Unauthorized");
class Videojuicer_Token_Unauthorized_Response extends Videojuicer_Response
{
    /**
     * Create a token object from the data
     */
    public function __construct($data)
    {
        parent::__construct($data);
        $unauthorized_token = new Videojuicer_Token_Unauthorized($data);
        Videojuicer::set_request_token($unauthorized_token);
    }
}
Exemplo n.º 9
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_Response");
Videojuicer_ClassLoader::load("Videojuicer_User_List");
class Videojuicer_User_List_Response extends Videojuicer_Response
{
    private $users;
    /**
     * Create the presentation list from the resulting xml
     */
    public function __construct($xml)
    {
        $xml = simplexml_load_string($xml);
        parent::__construct($xml);
        $list = new Videojuicer_User_List();
        $items = $xml->items->user;
        foreach ($items as $item) {
            $obj = new Videojuicer_User($item);
            $list->add($obj);
        }
        $this->users = $list;
    }
    /**
     * Get the users found
     *
     * @return Videojuicer_User_List
     */
    public function users()
    {
        return $this->users;
    }
Exemplo n.º 10
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_User");
Videojuicer_ClassLoader::load("Videojuicer_Entity_List");
class Videojuicer_User_List extends Videojuicer_Entity_List
{
    /**
     * Construct the List with some users in it (optional)
     *
     * @param array $users List of Videojuicer_User objects
     */
    public function __construct($users = null)
    {
        if (is_array($users)) {
            $this->items = $users;
        }
    }
    /**
     * Add a user to the list
     *
     * @param Videojuicer_User $p
     */
    public function add(Videojuicer_Entity $p)
    {
        $this->items[] = $p;
    }
}
Exemplo n.º 11
0
<?php

Videojuicer_ClassLoader::load("Videojuicer_Response");
Videojuicer_ClassLoader::load("Videojuicer_Presentation");
class Videojuicer_Presentation_Response extends Videojuicer_Response
{
    private $presentation;
    /**
     * Create the presentation list from the resulting xml
     */
    public function __construct($xml)
    {
        $xml = simplexml_load_string($xml);
        parent::__construct($xml);
        $presentation = new Videojuicer_Presentation($xml);
        $this->presentation = $presentation;
    }
    /**
     * Get the presentations found
     *
     * @return Videojuicer_Presentation
     */
    public function presentation()
    {
        return $this->presentation;
    }
}