Example #1
0
function wfGetIMDBData($query = false, $callback = false, $count = 3)
{
    global $wgMemc;
    require_once "../common/HMAC.php";
    $query = urldecode($query);
    $secret_key = WISE_imdb_secretkey;
    $access_key = WISE_imdb_accesskey;
    $method = "Search";
    $timestamp = date("c");
    $timestamp = substr(strrev($timestamp), strpos($timestamp, "-") + 2);
    $timestamp = strrev($timestamp) . "Z";
    $string = $method . $timestamp;
    $hmac = new Crypt_HMAC($secret_key, "sha1");
    $hmac_digest = $hmac->hash(trim($string));
    $binary_hmac = pack("H40", $hmac_digest);
    $base64_hmac = base64_encode($binary_hmac);
    $hash = $base64_hmac;
    $client = new SoapClient(null, array('location' => "http://webservice.imdb.com/doc/2006-12-15/", 'uri' => "http://webservice.imdb.com/doc/2006-12-15/", 'trace' => 1, 'exceptions' => 0));
    $output = "";
    if ($query) {
        $strBodyComponent_Session = '<AWSAccessKeyId>' . $access_key . '</AWSAccessKeyId><Timestamp>' . $timestamp . '</Timestamp><Signature>' . $hash . '</Signature><Both>' . $query . '</Both><Action>' . $method . '</Action>';
        $params_var = new SoapVar($strBodyComponent_Session, XSD_ANYXML, null, null, null);
        $response = $client->Search($params_var);
        $variables = get_object_vars($response);
        if (isset($variables["faultstring"])) {
            $output .= "faultstring: " . $variables["faultstring"] . "<br/>";
            $output .= "faultcode: " . $variables["faultcode"] . "<br/>";
            $details = get_object_vars($variables["detail"]);
            foreach ($details as $key => $value) {
                $output .= $key . " : " . $value . "<br/>";
            }
            return $output;
        } else {
            $result_obj = array();
            if (isset($response["SearchResults"])) {
                $result_set = $response["SearchResults"];
                $result_array = get_object_vars($result_set);
                if (sizeof($result_array)) {
                    $result_temp = $result_array["Result"];
                    if (sizeof($result_temp)) {
                        $result = get_object_vars($result_temp[0]);
                        $type = $result["Type"];
                        $category = $result["Category"];
                        $result_obj["type"] = $type;
                        $result_obj["category"] = $category;
                        $result_obj["info"] = array();
                        $val_array = $result[$type . "Result"];
                        if (get_class($val_array) == "stdClass") {
                            $val_array = get_object_vars($val_array);
                        }
                        if (sizeof($val_array)) {
                            $result_item = $val_array;
                            if (isset($result_item[0])) {
                                $result_item = $result_item[0];
                            }
                            foreach ($result_item as $key => $value) {
                                if (get_class($value) == "stdClass") {
                                    $resobj_value_array = get_object_vars($value);
                                    foreach ($resobj_value_array as $result_key => $result_value) {
                                        $output .= "&nbsp;&nbsp;&nbsp;" . $result_key . " : " . (get_class($result_value) == "stdClass" ? get_class($result_value) : $result_value) . "<br/>";
                                        $result_obj["info"][$result_key] = $result_value;
                                    }
                                } else {
                                    $output .= $key . " : " . $value . "<br/>";
                                    $result_obj["info"][$key] = $value;
                                }
                            }
                        }
                    }
                }
            }
            if ($type == "Title") {
                $method = "LookupTitle";
                //$resp_groups = "Tagline,PlotSummary";
                $resp_groups = "";
                $string = $method . $timestamp;
                $hmac = new Crypt_HMAC($secret_key, "sha1");
                $hmac_digest = $hmac->hash(trim($string));
                $binary_hmac = pack("H40", $hmac_digest);
                $base64_hmac = base64_encode($binary_hmac);
                $hash = $base64_hmac;
                $strTitleLookup = '<AWSAccessKeyId>' . $access_key . '</AWSAccessKeyId><Timestamp>' . $timestamp . '</Timestamp><Signature>' . $hash . '</Signature><ResourceId>' . $result_obj["info"]["TitleId"] . '</ResourceId><Type>' . $type . '</Type><Action>' . $method . '</Action><ResponseGroups>' . $resp_groups . '</ResponseGroups>';
                $params_var = new SoapVar($strTitleLookup, XSD_ANYXML, null, null, null);
                $title_response = $client->LookupTitle($params_var);
                if (is_soap_fault($title_response)) {
                    echo $client->__getLastRequest();
                    //return "blah";
                }
                $variables = get_object_vars($title_response);
                if (isset($variables["faultstring"])) {
                    $output .= "faultstring: " . $variables["faultstring"] . "<br/>";
                    $output .= "faultcode: " . $variables["faultcode"] . "<br/>";
                    $details = get_object_vars($variables["detail"]);
                    foreach ($details as $key => $value) {
                        $output .= $key . " : " . $value . "<br/>";
                    }
                    return $output;
                } else {
                    foreach ($variables as $key => $value) {
                        $output .= $key . "<br/>";
                    }
                }
            }
            $output = ($callback ? $callback . "(" : "") . jsonify($result_obj) . ($callback ? ");" : "");
            return $output;
        }
    }
}