Example #1
0
function delegate($action)
{
    //cleanCache();
    $ds = dataSetName($_GET);
    $data = loadFromCache($ds);
    if ($data) {
        echo $data;
        exit(0);
    }
    switch ($action) {
        //Twitter
        case 'topTweets':
            $data = topTweets();
            break;
            //Google Analytics
        //Google Analytics
        case 'chart':
            $data = getChart();
            break;
            //Events
        //Events
        case 'events':
            $data = getEvents();
            break;
            //Statistics
        //Statistics
        case 'stats':
            $data = getStatistics();
            break;
            //Social badge
        //Social badge
        case 'social':
            $data = generateSocialBadge();
            break;
    }
    if (!empty($data)) {
        $val = storeInCache($ds, output($data));
        if (!$val) {
        }
    }
    echo output($data);
    exit(0);
}
Example #2
0
 function Get2($institutionCode, $collectionCode, $catalogNumber)
 {
     if ($collectionCode != '') {
         $institution = $institutionCode . "-" . $collectionCode;
     } else {
         $institution = $institutionCode;
     }
     $url = $this->buildDIGIRQuery($institution, $catalogNumber);
     //echo $url;
     curl_setopt($this->ch, CURLOPT_URL, $url);
     $this->Call();
     storeInCache($institution, $catalogNumber, $this->result, 'xml');
     $xml = $this->result;
     //echo $xml;
     $data = '';
     $ok = false;
     if (preg_match('/<\\?xml version/', $xml)) {
         // we have XML
         $xml = preg_replace("/<response xmlns='http:\\/\\/digir.net\\/schema\\/protocol\\/2003\\/1.0'/", '<response', $xml);
         // We got XML, but did we get a hit?
         $record_count = 0;
         if (PHP_VERSION >= 5.0) {
             $dom = new DOMDocument();
             $dom->loadXML($xml);
             $xpath = new DOMXPath($dom);
             $xpath_query = "//diagnostic[@code='RECORD_COUNT']";
             $nodeCollection = $xpath->query($xpath_query);
             foreach ($nodeCollection as $node) {
                 $record_count = $node->firstChild->nodeValue;
             }
         } else {
             $xpath = new XPath();
             $xpath->importFromString($xml);
             $xpath_query = "//diagnostic[@code='RECORD_COUNT']";
             $nodeCollection = $xpath->match($xpath_query);
             foreach ($nodeCollection as $node) {
                 $record_count = $xpath->getData($node);
             }
         }
         //echo "Record count=$record_count\n";
         if ($record_count != 0) {
             //echo $xml;
             $xml = str_replace('&quot;', '\\"', $xml);
             //echo $xml;
             $xp = new XsltProcessor();
             $xsl = new DomDocument();
             $xsl->load('xsl/digir2JSON.xsl');
             $xp->importStylesheet($xsl);
             $xml_doc = new DOMDocument();
             $xml_doc->loadXML($xml);
             $json = $xp->transformToXML($xml_doc);
             //echo $json;
             $json = str_replace("{,", "{", $json);
             $json = str_replace("\n", "", $json);
             $data = json_decode($json);
             //print_r($data);
             //echo $data->status, "\n";
             // Clean weird KU stuff where they have lat=long=0
             if (isset($data->record[0]->latitude) && isset($data->record[0]->longitude)) {
                 if ($data->record[0]->latitude == 0 && $data->record[0]->longitude == 0) {
                     unset($data->record[0]->latitude);
                     unset($data->record[0]->longitude);
                 }
             }
             //print_r($data);
             if (isset($data->status)) {
                 if ($data->status == 'ok') {
                     $ok = true;
                 }
             }
         } else {
             $data->status = 'no record found';
         }
     } else {
         $data->status = 'no XML returned';
     }
     return $data;
 }
Example #3
0
function APIstore($url, $params, $data)
{
    $ds = APIdsName($url, $params);
    storeInCache($ds, $data);
}