function trackTable($tracks, $purpose = false) { global $media_dir, $jinzora_skin, $hierarchy, $album_name_truncate, $row_colors, $img_more, $img_email, $img_rate, $img_discuss, $num_other_albums, $enable_ratings, $this_site, $allow_clips, $root_dir, $jzUSER, $hide_id3_comments, $max_song_length, $enable_discussion, $max_song_name_length, $show_lyrics_links, $allow_send_email, $handle_compilations, $video_types, $show_track_numbers; if (sizeof($tracks) == 0) { return; } // Let's setup the new display object $display =& new jzDisplay(); $tracks_only = array(); foreach ($tracks as $track) { if (is_object($track)) { $tracks_only[] = $track; } } // Now let's see if this is a Audio, Video, or Photo node $video = true; foreach ($tracks_only as $track) { if (!preg_match("/\\.({$video_types})\$/i", $track->getDataPath())) { $video = false; } } if ($video) { $this->videoTable($tracks_only, $purpose); return; } // Let's figure out our settings: // First, set the defaults. $showNumbers = false; if ($show_track_numbers == "true") { $showNumbers = true; } $showArtist = false; $showAlbum = false; $showCheck = false; $showInfo = false; $showEmail = false; $showRate = false; $showDisc = false; $showAlbumNames = false; $trackTruncate = false; $showPlayCount = false; if ($enable_discussion == "true") { $showDisc = true; } $trackTruncate = $max_song_name_length; // Now adjust as needed: switch ($purpose) { case "generic": $showNumbers = false; break; case "album": $showCheck = true; $showInfo = true; $showPlayCount = true; $showEmail = true; break; case "search": $showCheck = true; $showArtist = true; $showInfo = true; $showEmail = true; $trackTruncate = 100; break; case "sample": // We only want to show album thumbs IF this artist has more than 1 album $parent = $tracks_only[0]->getParent(); $gParent = $parent->getParent(); $nodes = $gParent->getSubNodes("nodes"); $showNumbers = false; $showAlbum = true; break; case "sample-all": $showNumbers = false; $showCheck = true; $showAlbumNames = true; $trackTruncate = 20; break; } if ($allow_send_email == "false") { $showEmail = false; } // Do we need to start the form if ($showCheck) { $node = $tracks_only[0]->getParent(); ?> <form name="albumForm" action="<?php echo urlize(); ?> " method="POST"> <input type="hidden" name="<?php echo jz_encode("action"); ?> " value="<?php echo jz_encode("mediaAction"); ?> "> <?php if ($purpose != "search") { ?> <input type="hidden" name="<?php echo jz_encode("jz_path"); ?> " value="<?php echo htmlentities(jz_encode($node->getPath("String"))); ?> "> <?php } ?> <input type="hidden" name="<?php echo jz_encode("jz_list_type"); ?> " value="<?php echo jz_encode("tracks"); ?> "> <?php } // Now let's setup the big table to display everything $i = 0; ?> <table class="jz_track_table" width="100%" cellpadding="3" cellspacing="0" border="0"> <?php $artists = array(); if ($handle_compilations == "true") { foreach ($tracks_only as $child) { $a = $child->getMeta(); if (!isNothing($a['artist'])) { $artists[$a['artist']] = true; } } } else { foreach ($tracks_only as $child) { $a = $child->getAncestor('artist'); if ($a !== false) { $artists[strtoupper($a->getName())] = true; } } } if (sizeof($artists) > 1) { $multiArtist = true; } else { $multiArtist = false; } $first_label = true; foreach ($tracks as $child) { // is it a header? if (is_string($child)) { if (!$first_label) { echo '<tr><td colspan="100"> </td></tr>'; } echo '<tr><td colspan="100">' . $child . '</td></tr>'; $first_label = false; continue; } // Let's make sure this isn't a lofi track if (substr($child->getPath("String"), -9) == ".lofi.mp3" or substr($child->getPath("String"), -9) == ".clip.mp3") { continue; } // First let's grab all the tracks meta data $metaData = $child->getMeta(); $album = $child->getParent(); if (findPType($album) == "disk") { $album = $album->getParent(); } $gParent = $album->getParent(); $artist = getInformation($album, "artist"); ?> <tr class="<?php echo $row_colors[$i]; ?> "> <?php if ($showCheck and $jzUSER->getSetting('stream')) { $value = htmlentities(jz_encode($child->getPath("String"))); ?> <td width="1%" valign="top" class="jz_track_table_songs_td"> <input type="checkbox" name="jz_list[]" value="<?php echo $value; ?> "> </td> <?php } ?> <td width="99%" valign="top" class="jz_track_table_songs_td" nowrap> <?php echo $display->playButton($child); ?> <?php // Now, is there a lofi version? $loFile = substr($child->getDataPath("String"), 0, -4) . ".lofi.mp3"; if (is_file($loFile) and $jzUSER->getSetting('stream')) { $lofi = new jzMediaTrack(substr($child->getPath("String"), 0, -4) . ".lofi.mp3"); //echo '<td width="1%" valign="top" class="jz_track_table_songs_td">'; echo $display->lofiPlayButton($lofi); //echo '</td>'; } ?> <?php // Now, is there a clip version? $loFile = substr($child->getDataPath("String"), 0, -4) . ".clip.mp3"; if (is_file($loFile) || $allow_clips == "true") { //echo '<td width="1%" valign="top" class="jz_track_table_songs_td">'; echo $display->clipPlayButton($child); //echo '</td>'; } ?> <?php echo $display->downloadButton($child); ?> <?php // Do they want ratings? if ($enable_ratings == "true") { $display->rateButton($child); } if ($showInfo) { echo " "; $display->infoButton($child); } if ($showEmail and $jzUSER->getSetting('stream')) { $display->emailButton($child); } ?> <?php if ($showDisc) { ?> <a class="jz_track_table_songs_href" href=""><?php $display->displayDiscussIcon($child); ?> </a> <?php } ?> <?php if ($showArtist !== false) { $j = 0; while ($j < sizeof($hierarchy) && $hierarchy[$j] != 'artist') { $j++; } if ($j < sizeof($hierarchy)) { $parent = $child; while ($parent->getLevel() > $j + 1) { $parent = $parent->getParent(); } $display->link($parent, $parent->getName(), $parent->getName(), "jz_track_table_songs_href"); echo " / "; } } // This is where we display the name if ($multiArtist) { if ($handle_compilations == "true") { $artistName = $metaData['artist']; if (isNothing($artistName)) { $artist = $child->getAncestor("artist"); if ($artist !== false) { $artistName = $artist->getName(); } } } else { $artist = $child->getAncestor("artist"); if ($artist !== false) { $artistName = $artist->getName(); } } if (isset($artistName)) { $tName = $child->getName(); unset($artistName); } else { $tName = $child->getName(); } } else { $tName = $child->getName(); } if ($trackTruncate) { $tName = returnItemShortName($tName, $trackTruncate); } if ($purpose == "search") { $album = $child->getAncestor("album"); $display->link($album, $album->getName(), $album->getName(), "jz_track_table_songs_href"); echo " / "; } if ($showNumbers) { echo $metaData['number'] . " - "; } if ($jzUSER->getSetting('stream')) { if ($showAlbum) { $descName = $album->getName() . " - " . $child->getName(); } else { $descName = $child->getName(); } // $tName = $child->getName(); $display->link($child, $tName, $descName, "jz_track_table_songs_href"); } else { echo $tName; } // Did they want to see lyrics links? if ($show_lyrics_links == "true") { if ($metaData['lyrics'] != "") { $urlArr = array(); $urlArr['jz_path'] = $child->getPath("String"); $urlArr['action'] = "popup"; $urlArr['ptype'] = "viewlyricsfortrack"; echo '<a href="' . urlize($urlArr) . '" onclick="openPopup(this, 450, 450); return false;"> - ' . word("Lyrics") . '</a>'; } } // Now let's show the description if there is one if ($short_desc = $child->getShortDescription() and $hide_id3_comments == "false") { echo "<br>" . $short_desc; } if ($description = $child->getDescription()) { echo "<br>" . $description; } // Do they want ratings? /*if ($enable_ratings == "true"){ //$rating = $display->displayRating($child,true); if ($rating){ //echo "<br>". $rating; } //unset($rating); }*/ ?> </td> <?php $lyricsSearch = false; if (isset($_POST['search_type'])) { if ($_POST['search_type'] == "lyrics") { $lyricsSearch = $_POST['search_query']; } } if (isset($_GET['search_type'])) { if ($_GET['search_type'] == "lyrics") { $lyricsSearch = $_GET['search_query']; } } if ($lyricsSearch) { // Now let's get the lyrics back $lyrics = $child->getLyrics(); // Now let's parse it out $lyrics = str_replace("Lyrics Provided by: Leo's Lyrics\nhttp://www.leoslyrics.com", "", $lyrics); $start = strpos(strtolower($lyrics), strtolower($lyricsSearch)) - 20; if ($start < 0) { $start = 0; } $lyrics = " (..." . substr($lyrics, $start, strlen($lyricsSearch) + 40) . "...)"; $lyrics = highlight($lyrics, $lyricsSearch); echo '<td width="6%" align="center" valign="top" class="jz_track_table_songs_td" nowrap>'; echo $lyrics; echo '</td>'; } ?> <?php if ($showAlbumNames) { echo '<td width="1%" class="jz_track_table_songs_td" nowrap>'; $display->link($album, returnItemShortName($album->getName(), 20), $album->getName(), "jz_track_table_songs_href"); echo '</td>'; } ?> <?php if ($showPlayCount) { echo '<td width="1%" align="center" valign="top" class="jz_track_table_songs_td" nowrap>'; if ($child->getPlayCount() != 0) { echo $child->getPlayCount() . " " . word("Plays"); } else { echo " - "; } echo '</td>'; } ?> <td width="6%" align="center" valign="top" class="jz_track_table_songs_td" nowrap> <?php echo convertSecMins($metaData['length']); ?> </td> </tr> <?php $i = 1 - $i; unset($gParent); unset($album); } // Now let's set a field with the number of checkboxes that were here echo "</table>"; // Now let's show the playlist bar if we should if ($showCheck) { $this->blockSpacer(); $this->playlistBar(); echo "</form>"; } }
/** * Injects a leaf or a node into $this. * If sizeof($path) > 1, does so 'recursively' * * @author Ben Dodson * @version 10/15/04 * @since 10/15/04 */ function oldInject($path, $filepath, $type = "leaf") { global $sql_type, $sql_pw, $sql_usr, $sql_socket, $sql_db, $media_dir, $hierarchy; if (is_string($path)) { // todo: be more flexible (be carefully of '://') return false; } if (!($link = jz_db_connect())) { die("could not connect to database."); } if ($type == "track") { $type = "leaf"; } // Handle $path[0]. if ($path == array()) { return $this; } else { $head = array_shift($path); $nextpath = $this->getPath(); $nextpath[] = $head; $nexttrack =& new jzMediaTrack($nextpath); $nextnode =& new jzMediaNode($nextpath); $ptype = findPType($this); $media_path = "." . $media_dir; if (file_exists($filepath)) { $date = filemtime($filepath); } else { $date = 0; } if (sizeof($path) == 0) { // just add $next to cache. $tlevel = $this->getLevel() + 1; $tpath = jz_db_escape(implode("/", $nextpath)); $tfilepath = jz_db_escape($filepath); $thead = jz_db_escape($head); $tptype = jz_db_escape($hierarchy[$this->getLevel()]); if ($tptype == "track") { $tptype = "disk"; } if ($type == "leaf") { $mid = uniqid("T"); $sql = "INSERT INTO jz_nodes(path,ptype,level,name,leaf,date_added,filepath,valid,my_id)"; $sql .= " VALUES('{$tpath}','track',{$tlevel},'{$thead}','true','{$date}','{$tfilepath}','perm','" . $mid . "')"; jz_db_query($link, $sql); $sql = "INSERT INTO jz_tracks(path,level,name,filepath,valid,my_id) VALUES('{$tpath}','{$tlevel}','{$thead}','{$tfilepath}','perm','" . $mid . "')"; if (jz_db_query($link, $sql)) { $ppath = jz_db_escape($this->getPath("String")); $sql = "UPDATE jz_nodes SET leafcount = leafcount+1 WHERE path = '{$ppath}'"; jz_db_query($link, $sql); return $nexttrack; } else { return false; } } else { // Remember, INSERT will fail if the path already exists. // this is ok. $sql = "INSERT INTO jz_nodes(path,ptype,level,name,leaf,date_added,valid,my_id)"; $sql .= " VALUES('{$tpath}','{$tptype}',{$tlevel},'{$thead}','false','{$date}','perm','" . uniqid("T") . "')"; if (jz_db_query($link, $sql)) { $ppath = jz_db_escape($this->getPath("String")); $sql = "UPDATE jz_nodes SET nodecount = nodecount+1 WHERE path = '{$ppath}'"; jz_db_query($link, $sql); } return $nextnode; } } else { $npath = jz_db_escape($nextnode->getPath("String")); $nlevel = $nextnode->getLevel(); $nhead = jz_db_escape($head); $nptype = findPType($nextnode); $sql = "INSERT INTO jz_nodes(path,ptype,level,name,leaf,date_added,valid,my_id)"; $sql .= " VALUES('{$npath}','{$nptype}',{$nlevel},'{$nhead}','false','{$date}','perm','" . uniqid("T") . "')"; if (jz_db_query($link, $sql)) { $ppath = jz_db_escape($this->getPath("String")); if ($this->getLevel() == 0) { $sql = "UPDATE jz_nodes SET nodecount = nodecount+1 WHERE level = 0"; } else { $sql = "UPDATE jz_nodes SET nodecount = nodecount+1 WHERE path = '{$ppath}'"; } jz_db_query($link, $sql); } return $nextnode->oldInject($path, $filepath, $type); } } }
/** * Displays a table of the given tracks. * * @author Ross Carlson * @version 11/30/04 * @since 01/11/05 * @param array $tracks The array of objects of each track * @param $purpose The type of this track table. One of: * generic|album|search|sample|sample-all */ function trackTable($tracks, $purpose = false) { global $media_dir, $jinzora_skin, $hierarchy, $album_name_truncate, $row_colors, $img_more, $img_email, $img_rate, $img_discuss, $num_other_albums, $enable_ratings, $this_site, $root_dir; if (sizeof($tracks) == 0) { return; } // Let's setup the new display object $display =& new jzDisplay(); // Let's figure out our settings: // First, set the defaults. $showNumbers = true; $showArtist = false; $showAlbum = false; $showCheck = false; $showInfo = false; $showEmail = false; $showRate = false; $showDisc = false; $albumArtThumbs = false; $showAlbumNames = false; $trackTruncate = false; $showPlayCount = false; // Now adjust as needed: switch ($purpose) { case "generic": $showNumbers = false; break; case "album": $showCheck = true; $showNumbers = false; $showInfo = true; $showPlayCount = true; $showEmail = true; break; case "search": $showArtist = true; break; case "sample": // We only want to show album thumbs IF this artist has more than 1 album $parent = $tracks[0]->getParent(); $gParent = $parent->getParent(); $nodes = $gParent->getSubNodes("nodes"); if (count($nodes) > 1) { $albumArtThumbs = true; } $showNumbers = false; $showAlbum = true; break; case "sample-all": $showNumbers = false; $showCheck = true; $showAlbumNames = true; $trackTruncate = 20; break; } // Do we need to start the form if ($showCheck) { $node = $tracks[0]->getParent(); ?> <form name="albumForm" action="<?php echo urlize(); ?> " method="POST"> <input type="hidden" name="<?php echo jz_encode("action"); ?> " value="<?php echo jz_encode("mediaAction"); ?> "> <input type="hidden" name="<?php echo jz_encode("jz_path"); ?> " value="<?php echo htmlentities(jz_encode($node->getPath("String"))); ?> "> <input type="hidden" name="<?php echo jz_encode("jz_list_type"); ?> " value="<?php echo jz_encode("tracks"); ?> "> <?php } // Now let's setup the big table to display everything $i = 0; ?> <table class="jz_track_table" width="100%" cellpadding="3" cellspacing="0" border="0"> <?php foreach ($tracks as $child) { // First let's grab all the tracks meta data $metaData = $child->getMeta(); $album = $child->getParent(); if (findPType($album) == "disk") { $album = $album->getParent(); } $gParent = $album->getParent(); $artist = getInformation($album, "artist"); ?> <tr class="<?php echo $row_colors[$i]; ?> "> <?php if ($showCheck) { ?> <td width="1%" valign="top" class="jz_track_table_songs_td"> <input type="checkbox" name="jz_list[]" value="<?php echo jz_encode($child->getPath("String")); ?> "> </td> <td width="1%" valign="top" class="jz_track_table_songs_td"> <?php echo $display->playButton($child); ?> </td> <td width="1%" valign="top" class="jz_track_table_songs_td"> <?php echo $display->downloadButton($child); ?> </td> <?php } // Do they want ratings? if ($enable_ratings == "true") { echo '<td width="1%" valign="top" class="jz_track_table_songs_td">'; $display->rateButton($child); echo '</td>'; } ?> <?php if ($showInfo) { $arr = array(); $arr['action'] = "popup"; $arr['ptype'] = "trackinfo"; $arr['jz_path'] = $child->getPath("String"); $link = urlize($arr); ?> <td width="1%" valign="top" class="jz_track_table_songs_td"> <a href="<?php echo $link; ?> " target="_blank" onclick="openPopup(this, 375, 650); return false;"><?php echo $img_more; ?> </a> </td> <?php } ?> <?php if ($showEmail) { ?> <td width="1%" valign="top" class="jz_track_table_songs_td"> <?php $arr = array(); $arr['action'] = "playlist"; $arr['jz_path'] = $child->getPath("String"); $arr['type'] = "track"; $link = $this_site . $root_dir . "/" . str_replace("&", "%26", urlize($arr)); $mailLink = "mailto:?subject=" . $artist . " - " . $album->getName() . "&body=Click to play " . $artist . " - " . $album->getName() . ":%0D%0A%0D%0A" . $link . "%0D%0A%0D%0APowered%20by%20Jinzora%20%0D%0AJinzora%20::%20Free%20Your%20Media%0D%0Ahttp://www.jinzora.org"; ?> <a class="jz_track_table_songs_href" href="<?php echo $mailLink; ?> "><?php echo $img_email; ?> </a> </td> <?php } ?> <?php if ($showDisc) { ?> <td width="1%" valign="top" class="jz_track_table_songs_td"> <a class="jz_track_table_songs_href" href=""><?php echo $img_discuss; ?> </a> </td> <?php } ?> <td nowrap width="100%" valign="top" class="jz_track_table_songs_td"> <?php // Do they want tiny thumbnails? if ($albumArtThumbs) { if (($art = $album->getMainArt()) !== false) { $display->link($album, $display->returnImage($art, $album->getName(), 25, 25, "limit", false, false, "left", "2", "2"), $album->getName(), "jz_track_table_songs_href"); } } if ($showArtist !== false) { $j = 0; while ($j < sizeof($hierarchy) && $hierarchy[$j] != 'artist') { $j++; } if ($j < sizeof($hierarchy)) { $parent = $child; while ($parent->getLevel() > $j + 1) { $parent = $parent->getParent(); } $display->link($parent, $parent->getName(), $parent->getName(), "jz_track_table_songs_href"); echo " / "; } } if (!$trackTruncate) { $tName = $child->getName(); } else { $tName = returnItemShortName($child->getName(), $trackTruncate); } $display->link($child, $tName, $child->getName(), "jz_track_table_songs_href"); if ($showAlbum) { echo "<br>From: "; $display->link($album, returnItemShortName($album->getName(), 20), $album->getName(), "jz_track_table_songs_href"); } // Do they want ratings? if ($enable_ratings == "true") { $rating = $display->displayRating($child, true); if ($rating) { echo "<br>" . $rating; } unset($rating); } ?> </td> <?php $lyricsSearch = false; if (isset($_POST['search_type'])) { if ($_POST['search_type'] == "lyrics") { $lyricsSearch = $_POST['search_query']; } } if (isset($_GET['search_type'])) { if ($_GET['search_type'] == "lyrics") { $lyricsSearch = $_GET['search_query']; } } if ($lyricsSearch) { // Now let's get the lyrics back $lyrics = $child->getLyrics(); // Now let's parse it out $lyrics = str_replace("Lyrics Provided by: Leo's Lyrics\nhttp://www.leoslyrics.com", "", $lyrics); $start = strpos(strtolower($lyrics), strtolower($lyricsSearch)) - 20; if ($start < 0) { $start = 0; } $lyrics = " (..." . substr($lyrics, $start, strlen($lyricsSearch) + 40) . "...)"; $lyrics = highlight($lyrics, $lyricsSearch); echo '<td width="6%" align="center" valign="top" class="jz_track_table_songs_td">'; echo "<nobr>" . $lyrics . "</nobr>"; echo '</td>'; } ?> <?php if ($showAlbumNames) { echo '<td width="1%" align="center" valign="top" class="jz_track_table_songs_td"><nobr>'; $display->link($gParent, returnItemShortName($gParent->getName(), 20), $gParent->getName(), "jz_track_table_songs_href"); echo '</nobr></td>'; } ?> <?php if ($showPlayCount) { echo '<td width="1%" align="center" valign="top" class="jz_track_table_songs_td">'; echo $child->getPlayCount(); echo '</td>'; } ?> <td width="6%" align="center" valign="top" class="jz_track_table_songs_td"> <nobr> <?php echo convertSecMins($metaData['length']); ?> </nobr> </td> </tr> <?php $i = 1 - $i; unset($gParent); unset($album); } // Now let's set a field with the number of checkboxes that were here echo "</table>"; // Now let's show the playlist bar if we should if ($showCheck) { $blocks = new jzBlocks(); $blocks->blockSpacer(); $blocks->playlistBar(); echo "</form>"; } }
/** * Gets the node's natural parent (self if root) * This is the 'inverse' of the naturalDepth. * * @author Ben Dodson * @version 9/18/04 * @since 9/18/04 */ function getNaturalParent() { global $jzUSER; if ($this->getLevel() == 0 || $this->getPath("String") == $jzUSER->getSetting("home_dir")) { return $this; } $newpath = $this->path; array_pop($newpath); $node =& new jzMediaNode($newpath); if (findPType($node) == "hidden") { return $node->getNaturalParent(); } return $node; }
/** * 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); } } }