コード例 #1
0
ファイル: API.class.php プロジェクト: nsystem1/tuneefy
 public static function lookup($query, $from = "site")
 {
     // query decoding
     $query = trim(urldecode($query));
     // So far, we have no item
     $lookedUpItem = null;
     // By default we assume this is a simple query
     $lookedUpPlatform = -1;
     // Return value (default)
     $retour = null;
     // For now we have not transformed
     $queryArray = array('initial' => $query, 'transformed' => $query);
     // Check that the request is well-formed
     if ($query) {
         $query = trim(strip_tags($query));
         // We remove the trailing slash for our regex to work
         if (substr($query, -1) == '/') {
             $query = substr($query, 0, -1);
         }
         // We log the search query
         DBLogger::logSearchQuery($query, $from);
         // We look for the permalink
         $platforms = API::getPlatforms();
         while (list($pId, $pObject) = each($platforms)) {
             if ($pObject->isActiveForLookup() || $from == "playlist") {
                 // Is the platform active for lookup ?
                 if ($pObject->hasPermalink($query)) {
                     // The permalink is correct for this platform
                     if ($from == "playlist") {
                         $lookedUpPlatform = $pObject->getId();
                         break;
                     }
                     try {
                         $result = $pObject->lookupPermalink($query);
                     } catch (PlatformTimeoutException $e) {
                         $result = null;
                     }
                     if ($result) {
                         // We have a non-null result
                         $queryArray['transformed'] = str_replace(" ", "+", trim($result['query']));
                         $lookedUpItem = $result['track'];
                         $lookedUpPlatform = $pObject->getId();
                     }
                     // We break anyway because we won't find anything else
                     // since this was a correct permalink
                     break;
                 }
             }
         }
         // We create the PHP array containing the good values
         $retour = array('lookedUpPlatform' => $lookedUpPlatform, 'query' => $queryArray, 'lookedUpItem' => $lookedUpItem);
     }
     return $retour;
 }