/** * Writes out the meta data of an album * * @author Ross Carlson * @version 08/10/04 * @param $node The node we are looking at * @param $year The year of the album * @param $image The URL of the image for the album * @param $tracks The list of tracks for the album (an array) * @param $review The review or discription of the album * @param $rating The rating of the album in number of stars (1-5) * @param $price The price of the album * @param $genre The genre of the album * @param $displayOutput Should we display output while writing? */ function writeAlbumMetaData($node, $year = false, $image = false, $tracks = false, $review = false, $rating = false, $price = false, $genre = false, $displayOutput = false, $write_now = false) { global $web_root, $root_dir, $media_dir, $audio_types, $allow_id3_modify, $allow_filesystem_modify, $include_path, $backend; // Ok, now let's write out the description if ($review) { if ($displayOutput) { ?> <SCRIPT LANGUAGE=JAVASCRIPT><!--\ ars.innerHTML = 'Status: Writing Review'; --> </SCRIPT> <?php flushdisplay(); } // Now let's write this data to the node $node->addDescription($review); // Now let's write it to a file if we should if ($allow_filesystem_modify == "true" and !stristr($backend, "id3")) { $bioFile = $node->getFilePath() . "/album-desc.txt"; $handle = @fopen($bioFile, "w"); @fwrite($handle, $review); @fclose($handle); } } // Now let's write out the image if (stristr($image, ".jpg")) { include_once $include_path . "lib/snoopy.class.php"; $snoopy = new Snoopy(); $snoopy->fetch($image); $imageData = $snoopy->results; unset($snoopy); // Now let's make sure that was valid if (strlen($imageData) < 1000) { $imageData = ""; } } else { $imageData = ""; } // Now let's write it out if ($imageData != "") { if ($displayOutput) { ?> <SCRIPT LANGUAGE=JAVASCRIPT><!--\ ars.innerHTML = 'Status: Writing Album Image'; --> </SCRIPT> <?php flushdisplay(); } // Ok, now can we write to the filesystem? if ($allow_filesystem_modify == "false" or stristr($backend, "id3")) { $imgFile = $include_path . "data/images/" . pathize(str_replace("/", "--", $node->getPath("String")), '') . "--" . pathize($node->getName(), '') . ".jpg"; } else { $imgFile = $node->getFilePath() . "/" . $node->getName() . ".jpg"; } // Now let's write it out if (writeImage($imgFile, $imageData)) { $node->addMainArt($imgFile); } if ($displayOutput) { ?> <SCRIPT LANGUAGE=JAVASCRIPT><!--\ ars.innerHTML = 'Status: Writing Album Image - Success'; --> </SCRIPT> <?php flushdisplay(); } $retVal = 1; } // Now let's write the rating if ($rating != "" and is_numeric($rating)) { $node->addRating($rating); if ($displayOutput) { ?> <SCRIPT LANGUAGE=JAVASCRIPT><!--\ ars.innerHTML = 'Status: Rating Album'; --> </SCRIPT> <?php flushdisplay(); } } if ($displayOutput) { ?> <SCRIPT LANGUAGE=JAVASCRIPT><!--\ ars.innerHTML = 'Status: Writing data to files...'; --> </SCRIPT> <?php flushdisplay(); } // Did they want to write this to the id3 tags? if ($allow_id3_modify == "true" and $write_now == true) { // Now let's set the meta fields so they get updated for all the tracks $meta['albumYear'] = $year; $meta['image-data'] = $imageData; $meta['image-file'] = $imgFile; $meta['image-ext'] = ".jpg"; $meta['image-name'] = $imgShortName; $node->bulkMetaUpdate($meta, false, $displayOutput); if ($displayOutput) { ?> <SCRIPT LANGUAGE=JAVASCRIPT><!--\ ars.innerHTML = 'Status: Complete!'; --> </SCRIPT> <?php flushdisplay(); } } }
/** * Shows the chart system * * @author Ross Carlson * @version 01/26/05 * @since 01/26/05 * @param $node The node we are viewing so we can filter * @param $types The charts to display. Comma seperated list of: * topplayalbum, topplayartist, topdownalbum, newalbums, newartists, newtracks * recentplayalbum, recentplayartist, recentplaytrack, * topratedalbum, topratedartist, topviewartist, topplaytrack * @param $numItems The number of items we want to return (defaults to 5) * @param $format Should we format this or return raw data (defaults to true) * @param $opts an array of extra options (transitioning to new parameter scheme) * */ function showCharts($node, $types = false, $numItems = false, $format = true, $vertAlign = false, $opts = false) { global $album_name_truncate, $img_tiny_play, $img_tiny_play_dis, $jzUSER, $img_rss, $root_dir, $advanced_tooltips, $rss_in_charts, $num_items_in_charts, $chart_timeout_days, $chart_types; $be = new jzBackend(); if ($be->hasFeature('charts') === false) { return; } // Let's setup our objects $blocks = new jzBlocks(); $display = new jzDisplay(); $nobr = true; if ($opts !== false) { if (isset($opts['allow_breaks'])) { $nobr = false; } else { $nobr = true; } } // Now let's do a loop creating all our blocks if ($types === false || $types == "") { if (isset($chart_types) && !isNothing($chart_types)) { $b = $chart_types; } else { $b = "topplayalbum,topplayartist,topviewartist,newalbums"; } } else { $b = $types; } $bArray = explode(",", $b); for ($e = 0; $e < count($bArray); $e++) { // Now let's create our blocks $showPlays = false; switch ($bArray[$e]) { case "topplayalbum": $func = "getMostPlayed"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "played-albums"; $title = word("Top Played Albums"); $distance = "album"; $showPlays = true; $showDownload = false; $rss = "most-played"; break; case "topplayartist": $func = "getMostPlayed"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "played-artists"; $title = word("Top Played Artists"); $distance = "artist"; $showPlays = true; $showDownload = false; $rss = "most-played-artist"; break; case "topdownalbum": $func = "getMostDownloaded"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "downloaded-albums"; $title = word("Top Downloaded Albums"); $distance = "album"; $showDownload = true; $rss = "most-downloaded"; break; case "newalbums": $func = "getRecentlyAdded"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "new-albums"; $title = word("New Albums"); $distance = "album"; $showDownload = false; $rss = "last-added"; break; case "newartists": $func = "getRecentlyAdded"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "new-artists"; $title = word("New Artists"); $distance = "artist"; $showDownload = false; $rss = "last-added-artists"; break; case "newtracks": $func = "getRecentlyAdded"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "new-tracks"; $title = word("New Tracks"); $distance = "track"; $showDownload = false; $rss = "last-added-tracks"; break; case "recentplaytrack": $func = "getRecentlyPlayed"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "recentplayed-tracks"; $title = word("Recently Played Tracks"); $distance = "track"; $showDownload = false; $rss = "recentplayed-track"; break; case "topplaytrack": $func = "getMostPlayed"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "played-tracks"; $title = word("Top Played Tracks"); $distance = "track"; $showDownload = false; $rss = "most-played-tracks"; break; case "recentplayalbum": $func = "getRecentlyPlayed"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "recentplayed-albums"; $title = word("Recently Played Albums"); $distance = "album"; $showDownload = false; $rss = "recentplayed-album"; break; case "recentplayartist": $func = "getRecentlyPlayed"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "recentplayed-artists"; $title = word("Recently Played Artists"); $distance = "artist"; $showDownload = false; $rss = "recentplayed-artist"; break; case "topratedalbum": $func = "getTopRated"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "toprated-albums"; $title = word("Top Rated Albums"); $distance = "album"; $showDownload = false; $rss = "toprated-album"; break; case "topratedartist": $func = "getTopRated"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "toprated-artists"; $title = word("Top Rated Artists"); $distance = "artist"; $showDownload = false; $rss = "toprated-artist"; break; case "topviewartist": $func = "getMostViewed"; $arr['action'] = "popup"; $arr['ptype'] = "topstuff"; $arr['tptype'] = "topviewed-artists"; $title = word("Most Viewed Artists"); $distance = "artist"; $showDownload = false; $rss = "topviewed-artist"; break; default: continue; } // Now let's get the data if ($distance == "track") { $returnType = "tracks"; } else { $returnType = "nodes"; } if ($numItems) { $num_items_in_charts = $numItems; } if ($chart_timeout_days > 0) { $be = new jzBackend(); $data_id .= pathize('chart-' . $node->getPath("String")) . "-{$func}-{$distance}-{$num_items_in_charts}"; if (($recent = $be->loadData($data_id, true)) === false) { $recent = $node->{$func}($returnType, distanceTo($distance, $node), $num_items_in_charts); $be->storeData($data_id, $recent, $chart_timeout_days); } } else { $recent = $node->{$func}($returnType, distanceTo($distance, $node), $num_items_in_charts); } // Now let's see if we got data if (count($recent) == 0) { continue; } ?> <td width="25%" valign="top"> <?php if ($format) { echo '<div id="slickMainBlockBody">'; } ?> <table width="95%" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="100%" valign="middle"> <?php if ($nobr) { echo '<nobr>'; } ?> <?php if ($format) { // Now let's display the link to the FULL top played list echo '<a onclick="openPopup(this, 300, 450); return false;" title="' . $title . '" href="' . urlize($arr) . '"><strong>' . $title . '</strong></a>'; // Let's link to the RSS feed if ($rss_in_charts == "true") { echo ' - <a href="' . $root_dir . '/rss.php?type=' . $rss; if ($node->getLevel() != 0) { echo '&root=' . $node->getPath("String"); } echo '">' . $img_rss . '</a>'; } echo '<br>'; } // Now let's loop through the results for ($i = 0; $i < count($recent); $i++) { // Now let's create our node and get the properties $item = $artnode = $recent[$i]; $album = $item->getName(); $parent = $item->getAncestor("artist"); if ($parent !== false) { $artist = $parent->getName(); } $albumDLCount = $item->getDownloadCount(); $year = $item->getYear(); $dispYear = ""; if ($year != "-") { $dispYear = " (" . $year . ")"; } // Now let's create our links if ($distance == "track") { $artnode = $item->getAncestor("album"); if (is_object($artnode)) { $albumArr['jz_path'] = $artnode->getPath("String"); $gp = $item->getAncestor("artist"); if (is_object($gp)) { $artistArr['jz_path'] = $gp->getPath("String"); } else { $artistArr['jz_path'] = ''; } } else { $albumArr['jz_path'] = ''; $artistArr['jz_path'] = ''; } } else { $albumArr['jz_path'] = $item->getPath("String"); if ($parent !== false) { $artistArr['jz_path'] = $parent->getPath("String"); } } // Now let's create our short names $artistTitle = returnItemShortName($artist, $album_name_truncate); $albumTitle = returnItemShortName($album, $album_name_truncate); // Now let's display it if ($nobr) { echo "<nobr>"; } if (!$jzUSER->getSetting('stream')) { echo $img_tiny_play_dis; } else { $display->playLink($item, $img_tiny_play, $album); } // Ok, did they want advanced tooltips? if ($advanced_tooltips == "true") { // Now let's set the hover code $innerOver = ""; $showTip = false; if (($art = $artnode->getMainArt("75x75")) != false) { $innerOver .= $display->returnImage($art, $artnode->getName(), 75, 75, "limit", false, false, "left", "3", "3"); $showTip = true; $bTitle = $artist . " - " . $album . $dispYear; } else { // Ok, no art so let's make this look better $innerOver .= "<strong>" . $artist . "<br>" . $album . $dispYear . "</strong><br>"; $bTitle = $album . $dispYear; } $desc_truncate = 200; $desc = $item->getDescription(); if (!isNothing($desc)) { $innerOver .= $display->returnShortName($desc, $desc_truncate); $showTip = true; } // Now let's fix up $innerOver = str_replace("'", "", str_replace('"', "", $innerOver)); $bTitle = str_replace("'", "", str_replace('"', "", $bTitle)); if ($showTip) { $title = $display->returnToolTip($innerOver, $bTitle); } else { $title = ' title="' . $artist . ' - ' . $album . $dispYear . '"'; } } else { // Standard tooltips $title = ' title="' . $artist . ' - ' . $album . $dispYear . '"'; } echo ' <a ' . $title . ' href="' . urlize($albumArr) . '">' . $albumTitle; if ($showPlays) { if ($bArray[$e] == "topplayalbum") { $albumPlayCount = $item->getSubNodeCount('tracks', -1); if ($albumPlayCount > 0) { $albumPlayCount = ceil($item->getPlayCount() / $albumPlayCount); } } else { $albumPlayCount = $item->getPlayCount(); } echo ' (' . $albumPlayCount . ')'; } if ($showDownload) { echo ' (' . $albumDLCount . ')'; } echo "</a><br>"; if ($nobr) { echo "</nobr>"; } } if ($nobr) { echo '</nobr>'; } ?> </td> </tr> </table> <?php if ($format) { echo '</div>'; } ?> </td> <?php if ($vertAlign) { echo '</tr><tr>'; } ?> <?php } }
function resultsToArray(&$results, $type = false) { global $backend; if ($type === false) { $arr = array(); $hash = array(); for ($i = 0; $i < $results->rows; $i++) { if (isset($results->data[$i]['leaf']) && $results->data[$i]['leaf'] == "false") { $me =& new jzMediaNode(jz_db_unescape($results->data[$i]['path'])); $me->leafcount = $results->data[$i]['leafcount']; $me->nodecount = $results->data[$i]['nodecount']; $me->artpath = jz_db_unescape($results->data[$i]['main_art']); $me->myid = $results->data[$i]['my_id']; if ($me->artpath == "") { $me->artpath = false; } $me->playcount = $results->data[$i]['playcount']; $me->dlcount = $results->data[$i]['dlcount']; $me->longdesc = jz_db_unescape($results->data[$i]['longdesc']); $me->ptype = jz_db_unescape($results->data[$i]['ptype']); // Gross hack to follow; // Fixes case where an album is in 2 genres from 1 artist: if ($backend == "id3-database") { if (!isset($hash[pathize(strtolower($me->getName()))])) { $arr[] = $me; $hash[pathize(strtolower($me->getName()))] = true; } } else { $arr[] = $me; } } else { $r = $results->data[$i]; $track =& new jzMediaTrack(jz_db_unescape($r['path'])); // we never query for just bitrate, so if it's returned, we have all meta. if (isset($r['bitrate']) && $r['bitrate'] != '-') { $meta = array(); $meta['title'] = jz_db_unescape($r['trackname']); $meta['bitrate'] = jz_db_unescape($r['bitrate']); $meta['frequency'] = jz_db_unescape($r['frequency']); $meta['filename'] = jz_db_unescape($r['name']); $meta['size'] = jz_db_unescape($r['filesize']); $meta['year'] = jz_db_unescape($r['year']); if (isset($r['descr'])) { $meta['comment'] = jz_db_unescape($r['descr']); } $meta['length'] = jz_db_unescape($r['length']); $meta['number'] = jz_db_unescape($r['number']); $meta['genre'] = jz_db_unescape($r['genre']); $meta['artist'] = jz_db_unescape($r['artist']); $meta['album'] = jz_db_unescape($r['album']); $meta['lyrics'] = jz_db_unescape($r['lyrics']); $meta['type'] = jz_db_unescape($r['extension']); $track->meta = $meta; } $arr[] = $track; } } return $arr; } else { if ($type == 'tracks') { $arr = array(); for ($i = 0; $i < $results->rows; $i++) { $me =& new jzMediaTrack(jz_db_unescape($results->data[$i]['path'])); // FILL META HERE. ***// if (isset($results->data[$i]['filepath']) && $results->data[$i]['filepath'] != "") { $me->playpath = $results->data[$i]['filepath']; } if ($results->data[$i]['trackname'] != "" && $results->data[$i]['trackname'] != "-") { $me->title = jz_db_unescape($results->data[$i]['trackname']); } $arr[] = $me; } return $arr; } } }
function resultsToArray(&$results, $type = false) { global $backend; if ($type === false) { $arr = array(); $hash = array(); for ($i = 0; $i < $results->rows; $i++) { if (isset($results->data[$i]['leaf']) && $results->data[$i]['leaf'] == "false") { $me =& new jzMediaNode(jz_db_unescape($results->data[$i]['path'])); $me->leafcount = $results->data[$i]['leafcount']; $me->nodecount = $results->data[$i]['nodecount']; $me->artpath = jz_db_unescape($results->data[$i]['main_art']); $me->myid = $results->data[$i]['my_id']; if ($me->artpath == "") { $me->artpath = false; } $me->playcount = $results->data[$i]['playcount']; $me->dlcount = $results->data[$i]['dlcount']; $me->longdesc = jz_db_unescape($results->data[$i]['longdesc']); // Gross hack to follow; // Fixes case where an album is in 2 genres from 1 artist: if ($backend == "id3-database") { if (!isset($hash[pathize(strtolower($me->getName()))])) { $arr[] = $me; $hash[pathize(strtolower($me->getName()))] = true; } } else { $arr[] = $me; } } else { $arr[] =& new jzMediaTrack(jz_db_unescape($results->data[$i]['path'])); } } return $arr; } else { if ($type == 'tracks') { $arr = array(); for ($i = 0; $i < $results->rows; $i++) { $me =& new jzMediaTrack(jz_db_unescape($results->data[$i]['path'])); // FILL META HERE. ***// if (isset($results->data[$i]['filepath']) && $results->data[$i]['filepath'] != "") { $me->playpath = $results->data[$i]['filepath']; } if ($results->data[$i]['trackname'] != "" && $results->data[$i]['trackname'] != "-") { $me->title = jz_db_unescape($results->data[$i]['trackname']); } $arr[] = $me; } return $arr; } } }
/** * Searches media * * @author Ben Dodson * @version 12/26/04 * @since 9/21/04 */ function search($searchArray2, $type = 'both', $depth = -1, $limit = 0, $op = "and", $metasearch = array(), $exclude = array()) { global $sql_type, $sql_pw, $sql_usr, $sql_socket, $sql_db, $backend; // alias: if ($type == "tracks") { $type = "leaves"; } if ($depth === false) { $depth = $this->getNaturalDepth(); } // allow strings as well as arrays for searching: if (is_string($searchArray2) && $op != "exact") { if (stristr($searchArray2, "\"") === false) { if ($searchArray2 == "") { $searchArray = array(); } else { $searchArray = explode(" ", $searchArray2); } } else { // gets nasty.. $open_quote = false; $searchArray = array(); $word = ""; for ($i = 0; $i < strlen($searchArray2); $i++) { if ($searchArray2[$i] == ' ' && $open_quote == false) { $searchArray[] = $word; $word = ""; } else { if ($searchArray2[$i] == '"') { $open_quote = !$open_quote; } else { $word .= $searchArray2[$i]; } } } if ($word != "") { $searchArray[] = jz_db_escape($word); } } } else { $searchArray = $searchArray2; } // exclude array, too: if (is_string($exclude)) { if ($exclude == "") { $excludeArray = array(); } else { if (stristr($exclude, "\"") === false) { if ($exclude == "") { $excludeArray = array(); } else { $excludeArray = explode(" ", $exclude); } } else { // gets nasty.. $open_quote = false; $excludeArray = array(); $word = ""; for ($i = 0; $i < strlen($exclude); $i++) { if ($exclude[$i] == ' ' && $open_quote == false) { $excludeArray[] = $word; $word = ""; } else { if ($exclude[$i] == '"') { $open_quote = !$open_quote; } else { $word .= jz_db_escape($exclude[$i]); } } } if ($word != "") { $excludeArray[] = $word; } } } } else { $excludeArray = $exclude; } // Now that we have search array, let's jz_db_escape here so we don't have to later. for ($i = 0; $i < sizeof($searchArray); $i++) { $searchArray[$i] = jz_db_escape($searchArray[$i]); } // Clean up: $tmp = array(); if (is_array($searchArray)) { foreach ($searchArray as $term) { if (!($term == "" || $term == " ")) { $tmp[] = $term; } } $searchArray = $tmp; } $tmp = array(); foreach ($excludeArray as $term) { if (!($term == "" || $term == " ")) { $tmp[] = $term; } } $excludeArray = $tmp; // INSENSITIVE OPERATION: $INSOP = jz_db_case_insensitive(); // SEARCH: $constraints = array(); // LYRICS: a different kind of search. if ($type == "lyrics") { if ($this->getLevel() > 0) { $constraints[] = "path LIKE '" . jz_db_escape($this->getPath("String")) . "/%'"; } // Level if ($depth < 0) { $lvl = $this->getLevel(); $constraints[] = "level > {$lvl}"; } else { $lvl = $this->getLevel() + $depth; $constraints[] = "level = {$lvl}"; } if ($op == "exact") { $constraints[] = "lyrics {$INSOP} '%{$searchArray2}'%"; } else { if ($op == "or") { $OPR = "OR"; } else { // and $OPR = "AND"; } $string = ""; if (sizeof($searchArray) > 0) { $string .= "lyrics {$INSOP} '%{$searchArray['0']}%'"; } for ($i = 1; $i < sizeof($searchArray); $i++) { $string .= "{$OPR} lyrics {$INSOP} '%{$searchArray[$i]}%'"; } $constraints[] = $string; } // TERMS TO EXCLUDE if ($excludeArray != array()) { $string = "(lyrics NOT {$INSOP}"; $string .= " '%{$excludeArray['0']}%'"; for ($i = 1; $i < sizeof($excludeArray); $i++) { $string .= " AND lyrics NOT {$INSOP} '%{$excludeArray[$i]}%'"; } $string .= ")"; $constraints[] = $string; } if ($constraints == array()) { die("Error: no constraints in search."); } $sql = "SELECT path FROM jz_tracks WHERE"; $sql .= " ({$constraints['0']})"; for ($i = 1; $i < sizeof($constraints); $i++) { $sql .= " AND ({$constraints[$i]})"; } if ($limit > 0) { $sql .= " LIMIT {$limit}"; } if (!($link = jz_db_connect())) { die("could not connect to database."); } $results = jz_db_query($link, $sql); jz_db_close($link); $return = array(); if ($results === false) { return $return; } foreach ($results->data as $row) { $return[] =& new jzMediaTrack(jz_db_unescape($row['path'])); } return $return; } // MEDIA SEARCH (not lyrics) if ($this->getLevel() > 0) { $constraints[] = "path LIKE '" . jz_db_escape($this->getPath("String")) . "/%'"; } // Type if ($type == "leaves") { $constraints[] = "leaf = 'true'"; } else { if ($type == "nodes") { $constraints[] = "leaf = 'false'"; } } // Level if ($depth < 0) { $lvl = $this->getLevel(); $constraints[] = "level > {$lvl}"; } else { $lvl = $this->getLevel() + $depth; $constraints[] = "level = {$lvl}"; } // ID search: if ($type == "id") { if (sizeof($searchArray) > 1) { // for now. Maybe search on all terms? return array(); } $mid = jz_db_escape($searchArray[0]); $string = "my_id = '{$mid}'"; $constraints[] = $string; } else { // String search: if ($op == "exact") { $searchArray2 = str_replace("\"", "", $searchArray2); $constraints[] = "name {$INSOP} '{$searchArray2}'"; } else { if ($op == "or") { // "or" if (sizeof($searchArray) > 0) { $string = "name {$INSOP}"; $string .= " '%{$searchArray['0']}%'"; for ($i = 1; $i < sizeof($searchArray); $i++) { $string .= " OR name {$INSOP} '%{$searchArray[$i]}%'"; } } $constraints[] = $string; } else { // "and" // first match at least part in our name: if (sizeof($searchArray) > 0) { $string = "((name {$INSOP}"; // if at a specific level, don't worry about full path: if ($lvl > 0) { $string .= " '%{$searchArray['0']}%')"; // Otherwise, let's try to avoid repeat results: } else { $string .= " '%{$searchArray['0']}%' AND path NOT {$INSOP} '%{$searchArray['0']}%/%')"; } for ($i = 1; $i < sizeof($searchArray); $i++) { $string .= " OR (name {$INSOP} '%{$searchArray[$i]}%' AND path NOT {$INSOP} '%{$searchArray[$i]}%/%')"; } $string .= ")"; // Now require the rest to be in the path. $string .= " AND (path {$INSOP}"; $string .= " '%{$searchArray['0']}%'"; for ($i = 1; $i < sizeof($searchArray); $i++) { $string .= " AND path {$INSOP} '%{$searchArray[$i]}%'"; } $string .= ")"; $constraints[] = $string; } } } // Stuff to exclude: if ($excludeArray != array()) { $string = "(path NOT {$INSOP}"; $string .= " '%{$excludeArray['0']}%'"; for ($i = 1; $i < sizeof($excludeArray); $i++) { $string .= " AND path NOT {$INSOP} '%{$excludeArray[$i]}%'"; } $string .= ")"; $constraints[] = $string; } } // Put it all together. if ($constraints == array()) { die("Error: no constraints in search."); } $sql = "SELECT path,leaf FROM jz_nodes WHERE"; $sql .= " ({$constraints['0']})"; for ($i = 1; $i < sizeof($constraints); $i++) { $sql .= " AND ({$constraints[$i]})"; } if ($limit > 0) { $sql .= " LIMIT {$limit}"; } if (!($link = jz_db_connect())) { die("could not connect to database."); } $results = jz_db_query($link, $sql); jz_db_close($link); $return = array(); $hash = array(); if ($results === false) { return $return; } for ($i = 0; $i < $results->rows; $i++) { if ($results->data[$i]['leaf'] == "true") { $me =& new jzMediaTrack(jz_db_unescape($results->data[$i]['path'])); } else { $me =& new jzMediaNode(jz_db_unescape($results->data[$i]['path'])); } if ($default_importer == "id3tags") { if (!isset($hash[pathize(strtolower($me->getName()))])) { $return[] = $me; $hash[pathize(strtolower($me->getName()))] = true; } } else { $return[] = $me; } } if ($type == "leaves" && $metasearch != array()) { $return = filterSearchResults($return, $metasearch); } return $return; }
function removeDeadFiles($folder = false, $recursive = true) { $root = new jzMediaNode(); $recursive_repeat = false; if ($folder !== false) { $fbase = "REG-" . pathize($folder); } else { $fbase = "REG"; } $handle = opendir($this->data_dir); while ($file = readdir($handle)) { $fullpath = $this->data_dir . '/' . $file; if (false !== stristr($file, $fbase)) { if ($recursive || $file == $fbase) { $modified = false; $arr = unserialize(file_get_contents($fullpath)); foreach ($arr as $f => $info) { if ($info['fs_sync'] == "true" && !file_exists($f)) { $modified = true; unset($arr[$f]); if ($info['type'] == "track") { $root->removeMedia(new jzMediaTrack($info['path'])); } else { $root->removeMedia(new jzMediaNode($info['path'])); $recursive_repeat = true; } } } if ($modified) { if (sizeof($arr) == 0) { unlink($fullpath); } else { $handle2 = fopen($fullpath, "w"); fwrite($handle2, serialize($arr)); fclose($handle2); } } } } } if ($recursive_repeat) { $this->removeDeadFiles($folder, true); } }
/** * Injects a leaf or a node into $this. * If sizeof($path) > 1, does so 'recursively' * If the element path is found, do nothing and return false. * * @author Ben Dodson * @version 10/14/04 * @since 10/14/04 */ function oldInject($path, $filepath, $type = "leaf") { global $hierarchy; if (is_string($path)) { // todo: be more flexible (be carefully of '://') return false; } if ($type == "track") { $type = "leaf"; } // Handle $path[0]. if ($path == array()) { return false; } else { $rawhead = array_shift($path); $head = pathize($rawhead); $nextpath = $this->getPath(); $nextpath[] = $head; $nexttrack =& new jzMediaTrack($nextpath); $nexttrack->playpath = $filepath; $nextnode =& new jzMediaNode($nextpath); if (file_exists($filepath)) { $date = jz_filemtime($filepath); } else { $date = 0; } // add $next to cache, add its child, and continue. $cache = $this->readCache("nodes"); if ($cache[15] == "-") { $ptype = findPType($this); $cache[15] = $ptype; } if (sizeof($path) == 0 && $type == "leaf") { $found = false; foreach ($cache[8] as $el) { if ($el == $rawhead) { return false; } } if (!$found) { $cache[8][] = $rawhead; } natcasesort($cache[8]); } else { $found = false; if (!is_array($cache[7])) { //print_r($this); die; } foreach ($cache[7] as $el) { if (strtolower($el) == strtolower($head)) { $found = true; } } if (!$found) { $cache[7][] = $head; } natcasesort($cache[7]); } $this->writeCache($cache, "nodes"); if (sizeof($path) == 0) { // gets its own cache. if ($type == "leaf") { $cache = $nexttrack->readCache(); $cache[6] = $date; $cache[0] = $filepath; $cache[2] = $rawhead; $nexttrack->playpath = $filepath; $nexttrack->writeCache($cache); return $nexttrack; } else { $cache = $nextnode->readCache(); $cache[6] = $cache[6] < $date ? $date : $cache[6]; // Don't need filepath. Writing to filesystem in id3 mode is stupid- // everything will go in the data_dir. $nextnode->writeCache($cache); return $nextnode; } } else { return $nextnode->oldInject($path, $filepath, $type); } } }