Exemple #1
0
/**
 * Handle a search query from the GET/POST variables.
 * @author Ben Dodson
 */
function handleSearch($search_string = false, $search_type = false)
{
    global $jzUSER;
    $root =& new jzMediaNode();
    $timer = microtime_float();
    if ($search_string === false) {
        $search_string = $_GET['search_query'];
    }
    if ($search_type === false) {
        $search_type = $_GET['search_type'];
    }
    $string_array = splitKeywords($search_string);
    $keywords = $string_array['keywords'];
    $string = $string_array['search'];
    if (isset($keywords['genres'])) {
        $locations[sizeof($locations)] = 'genre';
        $search_type = "genres";
    }
    if (isset($keywords['artists'])) {
        $locations[sizeof($locations)] = 'artist';
        $search_type = "artists";
    }
    if (isset($keywords['albums'])) {
        $locations[sizeof($locations)] = 'album';
        $search_type = "albums";
    }
    if (isset($keywords['tracks'])) {
        $locations[sizeof($locations)] = 'track';
        $search_type = "tracks";
    }
    if (isset($keywords['lyrics'])) {
        $search_type = "lyrics";
    }
    if (isset($keywords['radio'])) {
        $search_type = "artists";
        $max_res = 1;
    } else {
        if (isset($keywords['limit'])) {
            $max_res = $keywords['limit'];
        } else {
            $max_res = 100;
        }
    }
    switch (strtolower($search_type)) {
        case "all":
            $stype = "both";
            $distance = -1;
            break;
        case "genres":
        case "genre":
            $stype = "nodes";
            $distance = distanceTo("genre");
            break;
        case "artists":
        case "artist":
            $stype = "nodes";
            $distance = distanceTo("artist");
            break;
        case "albums":
        case "album":
            $stype = "nodes";
            $distance = distanceTo("album");
            break;
        case "tracks":
        case "track":
            $stype = "tracks";
            $distance = -1;
            break;
        case "lyrics":
        case "lyric":
            $stype = "lyrics";
            $distance = -1;
            break;
        case "best":
        default:
            $stype = "both";
            $distance = -1;
            $keywords['best'] = true;
    }
    if ($distance === false) {
        die("Could not search for {$search_type}.");
    }
    // Are they searching by ID explicitly?
    if (isset($keywords['id'])) {
        $stype = "id";
        // We handle this differently than above in
        // case they set @genre and @id (or whatever).
    }
    /* if we have 2 locations,
         the closest to the root is our anchor
         and the further is our return type.
      */
    if (sizeof($locations) > 1) {
        if ($locations[1] == 'track') {
            $r = 'tracks';
        } else {
            $r = 'nodes';
        }
        $limit = 1;
        if (isset($keywords['limit'])) {
            $limit = $keywords['limit'];
        }
        $results = $root->search($string, "nodes", distanceTo($locations[0]), 1, 'exact');
        if (sizeof($results) > 0) {
            $results = $results[0]->getSubNodes($r, distanceTo($locations[1], $results[0]), true, $limit);
        } else {
            $results = $root->search($string, "nodes", distanceTo($locations[0]), 1);
            if (sizeof($results) > 0) {
                $results = $results[0]->getSubNodes($r, distanceTo($locations[1], $results[0]), true, $limit);
            }
        }
    } else {
        if (isset($keywords['play']) || isset($keywords['radio'])) {
            $results = $root->search($string, $stype, $distance, 1, 'exact');
            if (sizeof($results) == 0) {
                $results = $root->search($string, $stype, $distance, 1);
                // better to limit 1 or $max_res?
            }
        } else {
            if (isset($keywords['best'])) {
                $results = $root->search($string, $stype, $distance, -1, 'exact');
                if (sizeof($results) == 0) {
                    $results = $root->search($string, $stype, $distance, $max_res);
                    // better to limit 1 or $max_res?
                }
            } else {
                $results = $root->search($string, $stype, $distance, $max_res);
            }
        }
    }
    if (sizeof($results) == 0) {
        // Maybe a search by ID will work...
        $results = $root->search($string, "id", $distance, $max_res);
        if (sizeof($results) == 0) {
            return $results;
        }
    }
    $timer = round(microtime_float() - $timer, 2);
    writeLogData('search', "searched '{$search_type}' for '{$string}' in {$timer} seconds.");
    // What about keywords?
    if (isset($keywords['play']) && sizeof($results) > 0) {
        $pl = new jzPlaylist();
        $pl->add($results);
        //    if (isset($keywords['limit'])) {
        //  $pl->flatten();
        //}
        if (isset($keywords['random'])) {
            $pl = $pl->getSmartPlaylist($max_res);
        } else {
            if (isset($keywords['limit'])) {
                $pl->flatten();
                $pl->truncate($max_res);
            }
        }
        $pl->play();
        exit;
    } else {
        if (isset($keywords['radio'])) {
            $pl = new jzPlaylist();
            $pl->add($results);
            $pl = $pl->getSmartPlaylist(50, "radio");
            $pl->play();
            exit;
        }
    }
    return $results;
}
Exemple #2
0
                             $blocks = new jzBlocks();
                             $blocks->playlistDisplay();
                             exit;
                         }
                     } else {
                         $pl = $jzUSER->loadPlaylist();
                         $pl->add($guy);
                         $jzUSER->storePlaylist($pl);
                         if (!defined('NO_AJAX_JUKEBOX')) {
                             $blocks = new jzBlocks();
                             $blocks->playlistDisplay();
                             exit;
                         }
                     }
                 } else {
                     $pl = new jzPlaylist();
                     $pl->addFromForm();
                     $pl->flatten();
                     if (isset($_POST['limit'])) {
                         $pl->truncate($_POST['limit']);
                     }
                     if (isset($_POST['sendListRandom'])) {
                         $pl->shuffle();
                     }
                     $pl->play();
                 }
             }
         }
     }
 }
 if ($exit) {
Exemple #3
0
 /** 
  * 'Intelligently' creates a random playlist from the given list.
  * 
  * @author Ben Dodson
  * @param The number of elements to return
  * @param type the type of the playlist.
  *
  * false - equally weights tracks
  * radio - creates a radio from the given artist playlist should only contain 1 artist)
  */
 function getSmartPlaylist($count = 0, $type = "equi-track")
 {
     global $max_playlist_length, $jzSERVICES;
     if ($type == "radio") {
         if ($count == 0) {
             $lim = false;
         } else {
             $lim = $count;
         }
         $el = $this->getAt(0);
         $mainArray = $el->getSubNodes("tracks", -1, true, $lim);
         // Now let's get the top 5 similar artists
         $simArray = $jzSERVICES->getSimilar($el);
         $simArray = seperateSimilar($simArray);
         $i = 0;
         $limit = 6;
         // Now let's shuffle
         $similarArray = array();
         for ($e = 0; $e < count($simArray['matches']); $e++) {
             if (isset($simArray['matches'][$e])) {
                 // Ok, this is one that we want, let's get it's path
                 $simArt = $simArray['matches'][$e];
                 if ($lim) {
                     $subArray = $simArt->getSubNodes("tracks", -1, true, ceil($lim / 4));
                 } else {
                     $subArray = $simArt->getSubNodes("tracks", -1, true);
                 }
                 $similarArray = array_merge($similarArray, $subArray);
                 $i++;
                 if ($limit) {
                     if ($i > $limit) {
                         break;
                     }
                 }
             }
         }
         $finArray = array_merge($similarArray, $mainArray);
         $pl =& new jzPlaylist($finArray);
         $pl->shuffle();
         $pl->truncate($lim);
         return $pl;
     }
     //*****************//
     // default 'smartPlaylist'
     $trackcount = $this->getTrackCount();
     if ($count <= 0) {
         $count = $trackcount;
     }
     if ($trackcount <= $count) {
         $pl = $this;
         $pl->flatten();
         $pl->shuffle();
         $pl->truncate($max_playlist_length);
         return $pl;
     }
     $pl = new jzPlaylist();
     $numbers = range(0, $trackcount - 1);
     srand((double) microtime() * 1000000);
     $numbers = array_rand($numbers, $count);
     $size_list = array();
     $list = $this->getList();
     if ($list[0]->getType() == "jzMediaTrack") {
         $size_list[0] = 1;
     } else {
         if ($list[0]->getType() == "jzMediaNode") {
             $size_list[0] = $list[0]->getSubNodeCount("tracks", -1);
         } else {
             $size_list[0] = $list[0]->getTrackCount();
         }
     }
     for ($i = 1; $i < sizeof($list); $i++) {
         if ($list[$i]->getType() == "jzMediaTrack") {
             $size_list[$i] = 1 + $size_list[$i - 1];
         } else {
             if ($list[$i]->getType() == "jzMediaNode") {
                 $size_list[$i] = $size_list[$i - 1] + $list[$i]->getSubNodeCount("tracks", -1);
             } else {
                 $size_list[$i] = $size_list[$i - 1] + $list[$i]->getTrackCount();
             }
         }
     }
     $element_count = array();
     for ($i = 0; $i < sizeof($list); $i++) {
         $element_count[$i] = 0;
     }
     $j = 0;
     for ($i = 0; $i < sizeof($numbers); $i++) {
         if ($numbers[$i] < $size_list[$j]) {
             $element_count[$j]++;
         } else {
             $j++;
             $i--;
         }
     }
     $final = array();
     for ($i = 0; $i < sizeof($list); $i++) {
         if ($element_count[$i] > 0) {
             switch ($list[$i]->getType()) {
                 case "jzMediaNode":
                     $final = array_merge($final, $list[$i]->getSubNodes("tracks", -1, true, $element_count[$i]));
                     break;
                 case "jzMediaTrack":
                     $final[] = $list[$i];
                     break;
                 default:
                     $more = $list[$i];
                     $more->flatten();
                     $more->shuffle();
                     $more->truncate($element_count[$i]);
                     $final = array_merge($final, $more);
                     break;
             }
         }
     }
     $pl->add($final);
     $pl->shuffle();
     return $pl;
     // for ($i = 0; $i < $count; $i++) {
     // $pl->add($this->getAt($numbers[$i],"track"));
     // Too slow...
     //}
 }
Exemple #4
0
/**
 * Play histories for users
 */
function userHistories()
{
    global $api_page;
    $be = new jzBackend();
    if (!isset($_REQUEST['forUser'])) {
        $users = $be->getUsersWithHistories();
        $type = getFormatFromRequest();
        switch ($type) {
            case "xml":
                echoXMLHeader();
                echo "  <search>\n";
                echo "    <tracks>\n";
                echo "    </tracks>\n";
                echo "    <nodes>\n";
                foreach ($users as $u) {
                    $playlink = xmlentities($api_page . '&request=userhistories&doplaylist=true&forUser='******'&ext=pl.m3u');
                    echo "      <node>\n";
                    echo "        <name>" . xmlentities("Played By " . $u) . "</name>\n";
                    echo "        <type>" . xmlentities(ucwords("User-History")) . "</type>\n";
                    echo "        <playlink>" . $playlink . "</playlink>\n";
                    echo "        <image>";
                    echo "        </image>\n";
                    //echo "        <playlistid>";
                    //echo "        </playlistid>\n";
                    echo "        <thumbnail>";
                    echo "        </thumbnail>\n";
                    //echo "        <path>". xmlentities($pname). "</path>\n";
                    echo "        <browse>" . xmlentities($api_page . '&request=userhistories&forUser='******'jsoncallback'] . '(';
                }
                $jt = array();
                $jn = array();
                foreach ($users as $u) {
                    // hack for now. TODO: merge play histories into core.
                    $playlink = $api_page . '&request=userhistories&doplaylist=true&forUser='******'&ext=pl.m3u';
                    $a = array();
                    $a['name'] = "Played By " . $u;
                    $a['type'] = ucwords("User-History");
                    $a['playlink'] = $playlink;
                    $a['image'] = "";
                    //$a['playlistid'] = $id;
                    $a['thumbnail'] = "";
                    $a['browse'] = $api_page . '&request=userhistories&forUser='******'tracks' => $jt, 'nodes' => $jn));
                if ($type == "jsonp") {
                    echo ')';
                }
                break;
        }
        return;
    } else {
        $for = $_REQUEST['forUser'];
        $h = $be->getPlayHistory($for);
        if ($_REQUEST['doplaylist']) {
            $pl = new jzPlaylist();
            $pl->add($h);
            $pl->stream();
        } else {
            $trackfields = isset($_REQUEST['track_fields']) ? explode(',', $_REQUEST['track_fields']) : false;
            $nodefields = isset($_REQUEST['node_fields']) ? explode(',', $_REQUEST['node']) : false;
            print_results($h, getFormatFromRequest(), $trackfields, $nodefields);
        }
    }
}
Exemple #5
-1
 function jzPopup()
 {
     global $jzUSER;
     // Now let's se if they selected a Genre, Artist, or Album:
     if (isset($_POST['chosenPath'])) {
         if (isset($_POST['jz_type']) && $_POST['jz_type'] == "track") {
             if (checkPermission($jzUSER, 'play', $_POST['chosenPath']) === false) {
                 $this->closeWindow(false);
             }
             $e = new jzMediaTrack($_POST['chosenPath']);
             $pl = new jzPlaylist();
             $pl->add($e);
             $pl->play();
             exit;
         } else {
             $return = $this->returnGoBackPage($_POST['return']);
         }
         //$url = $return. "&" . jz_encode("path") . "=". jz_encode(urlencode($_POST['chosenPath']));
         $link = array();
         $link['jz_path'] = $_POST['chosenPath'];
         // Now let's fix that if we need to
         // Ok, now that we've got the URL let's refresh the parent and close this window
         echo '<body onload="opener.location.href=\'' . urlize($link) . '\';window.close();">';
         exit;
     }
 }