function lookup_link($symlink) { /* TODO: this pattern *has* to be moved to a central location */ $name_regexp = "/^\\[(.+)\\] \\[(.+)\\] \\[(.+)\\]\$/"; $target = readlink($symlink); /* the symlink could be targeting either a file inside a item's dir, or the dir itself */ if (preg_match($name_regexp, basename(dirname($target)), $matches) || preg_match($name_regexp, basename($target), $matches)) { $params = array('artist_name' => $matches[1], 'album_name' => $matches[2], 'item_quality' => $matches[3], 'update' => FALSE, 'insert' => FALSE); return mcm_action('lookup_item', $params); } }
function create_player($album_dirname) { global $mcm; $cwd = getcwd(); $full_path = "{$mcm['basedir']}/{$album_dirname}"; $stream_base = "/_cache/stream/" . session_id() . "/" . md5($album_dirname); $stream_path = $mcm['path'] . $stream_base; $stream_url = $mcm['url_path'] . $stream_base; $playlist_path = $stream_path . ".xspf"; $playlist_url = $stream_url . ".xspf"; if (!file_exists($playlist_path) || !is_dir($stream_path)) { @mkdir($mcm['path'] . "/_cache/stream/" . session_id()); $playlist = ""; $playlist .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $playlist .= "<playlist version=\"0\" xmlns = \"http://xspf.org/ns/0/\">\n"; $playlist .= "<title>" . utf8_encode($album_dirname) . "</title>\n"; $img = mcm_action('create_cover_url', $album_dirname); chdir($full_path); $mp3s = glob("*.mp3"); mkdir($stream_path); chdir($stream_path); $playlist .= "<image>{$img}</image>\n"; $playlist .= " <trackList>\n"; $index = 0; foreach ($mp3s as $mp3) { $index++; $symlink = str_pad($index, 2, "0", STR_PAD_LEFT) . ".mp3"; symlink("{$full_path}/{$mp3}", $symlink); $playlist .= " <track>\n"; $playlist .= " <location>{$stream_url}/{$symlink}</location>\n"; $playlist .= " <title>" . htmlentities(substr(substr($mp3, 5), 0, -4), ENT_COMPAT, 'UTF-8') . "</title>\n"; $playlist .= " <image>{$img}</image>\n"; $playlist .= " </track>\n"; } $playlist .= " </trackList>\n"; $playlist .= "</playlist>\n"; $hnd = fopen($playlist_path, 'w'); fwrite($hnd, $playlist); fclose($hnd); } chdir($cwd); return $playlist_url; }
function mcm_web_print_table($args) { global $mcm; extract($args, EXTR_PREFIX_ALL, 'arg'); /* * required: * * $arg_action - {prev,next} order * $arg_start - query start offset * $arg_item_status - {accepted,rejected,undefined} * $arg_item_type - user-defined item type * */ $limit = 6; /* TODO: set this as a config option */ $table_cols = 3; $start = $arg_start; $start = $arg_action == 'next' ? $start + $limit : $start; $start = $arg_action == 'prev' ? $start - $limit : $start; /* determine number of items available */ $params = array('user_id' => $mcm['user_id'], 'item_status' => $arg_item_status, 'item_type' => $arg_item_type, 'order' => 'artist_name, album_name, item_quality', 'limit' => "{$start}, {$limit}"); $items_list = mcm_action('lookup_itemlist', $params); $num_items = mcm_action('lookup_itemlist_count', $params); if ($num_items == 0) { mcm_web_nothing_to_review(); return; } ?> <form method="post" action="<?php echo $mcm['self']; ?> "> <table id="list-and-nav" class="center"> <tr> <td id="nav-left" class="nav"> <?php print_navigation($start, $limit, $num_items, 'left'); ?> </td> <td> <table id="list"> <input type="hidden" name="start" value="<?php echo $start; ?> "> <input type="hidden" name="item_status" value="<?php echo $arg_item_status; ?> "> <input type="hidden" name="item_type" value="<?php echo $arg_item_type; ?> "> <?php $row_number = 0; foreach ($items_list as $id => $row) { /* load current item status from db into session */ if (!isset($_SESSION['status'][$id])) { $_SESSION['status'][$id] = $arg_item_status; } $row_number++; $album_dirname = "[{$row['artist_name']}] [{$row['album_name']}] [{$row['item_quality']}]"; $cover_url = mcm_action('create_cover_url', $album_dirname); $playlist_url = create_player($album_dirname); echo ($row_number - 1) % $table_cols == 0 ? " <tr>\n" : ""; ?> <td class="item" id="id<?php echo $id; ?> -item"> <div id="id<?php echo $id; ?> -artist" class="artist"><?php echo $row['artist_name']; ?> </div> <div id="id<?php echo $id; ?> -album" class="album"><?php echo $row['album_name']; ?> </div> <div class="cover-container" onmouseover="if (isMouseLeaveOrEnter(event, this)) showOverlay('id<?php echo $id; ?> ')" onmouseout="if (isMouseLeaveOrEnter(event, this)) hideOverlay('id<?php echo $id; ?> ')"> <a href="#" onmousedown="loadPlaylist('<?php echo $playlist_url; ?> ', '<?php echo $cover_url; ?> '); return false;"> <img id="id<?php echo $id; ?> -overlay" src="images/overlay.png" class="overlay" alt=""> <img id="id<?php echo $id; ?> -cover" src="<?php echo $cover_url; ?> " class="cover<?php print_cover_class($id, $_SESSION['status'][$id]); ?> " alt="album cover" width="150" height="150"> </a> </div> <div class="choices"> <a href="#" onmousedown="clickRadio('id<?php echo $id; ?> ', 'add'); return false;"><img id="id<?php echo $id; ?> -img-add" src="images/add<?php print_button($id, 'accepted'); ?> .png" alt="Add" title="Add"></a> <input type="radio" id="id<?php echo $id; ?> -add" name="id<?php echo $id; ?> " value="accepted"<?php print_checkbox($id, 'accepted'); ?> > <a href="#" onmousedown="clickRadio('id<?php echo $id; ?> ', 'rem'); return false;"><img id="id<?php echo $id; ?> -img-rem" src="images/remove<?php print_button($id, 'rejected'); ?> .png" alt="Remove" title="Remove"></a> <input type="radio" id="id<?php echo $id; ?> -rem" name="id<?php echo $id; ?> " value="rejected"<?php print_checkbox($id, 'rejected'); ?> > <a href="#" onmousedown="clickRadio('id<?php echo $id; ?> ', 'und'); return false;"><img id="id<?php echo $id; ?> -img-und" src="images/undecided<?php print_button($id, 'undefined'); ?> .png" alt="Undecided" title="Undecided"></a> <input type="radio" id="id<?php echo $id; ?> -und" name="id<?php echo $id; ?> " value="undefined"<?php print_checkbox($id, 'undefined'); ?> > </div> </td> <?php echo $row_number % $table_cols == 0 ? " </tr>\n" : ""; } echo $row_number % $table_cols != 0 ? " </tr>\n" : ""; ?> </tr> </table> </td> <td id="nav-right" class="nav"> <?php print_navigation($start, $limit, $num_items, 'right'); ?> </td> </tr> </table> <div id="selected-artist"></div> <div id="selected-album"></div> <table id="player-table" class="center"> <tr> <td id="player-cover-container"> <img id="player-cover" src="images/player-cover.png" alt="Album Cover" width="100" height="100"> </td> <td rowspan="2" id="player-meta"> <div id="player-artist"></div> <div id="player-album"></div> <div id="player-title"></div> <div id="player-next"> <span id="player-next-label"></span><span id="player-next-title"></span> </div> </td> </tr> <tr> <td id="player-controls"> <a href="#" onmousedown="player.sendEvent('PREV'); return false;"><img src="images/rew.png" alt="Rewind" title="Previous Track"></a> <a href="#" onmousedown="player.sendEvent('PLAY'); return false;"><img src="images/play-pause.png" alt="Play/Pause" title="Play/Pause"></a> <a href="#" onmousedown="player.sendEvent('NEXT'); return false;"><img src="images/fwd.png" alt="Forward" title="Next Track"></a> </td> </tr> </table> <div id="toolbar"> <a href="#" onclick="alert('Help not implemented. Yet.'); return false;"><img src="images/help.png" title="Help" alt="Help"></a> | <input type="image" src="images/save-exit.png" name="submit" value="finish" title="Save and Exit"> | <input type="image" src="images/exit.png" name="submit" value="exit" title="Exit Without Saving" onclick="return confirm('You will lose all current selections!\n\nAre you sure you want to exit without saving?');"> </div> <p id="player" style="text-align: center;">Media player requires Adobe Flash Player to be installed. <a href="http://www.adobe.com/go/getflashplayer">Download now</a>.</p> </form> <?php }
/* this can be renamed/symlinked to index.php */ require_once '../core/init.php'; mcm_action('html_header'); $advanced = isset($_GET['advanced']) ? (bool) $_GET['advanced'] : FALSE; if (!mcm_action('web_login')) { mcm_action('web_login_form', array('advanced' => $advanced)); mcm_action('html_footer'); exit; } $action = isset($_POST['submit']) ? strtolower($_POST['submit']) : NULL; $start = isset($_POST['start']) ? abs(intval($_POST['start'])) : "0"; $item_type = isset($_POST['item_type']) ? strtoupper($_POST['item_type']) : 'MUSIC'; $item_status = isset($_POST['item_status']) ? strtolower($_POST['item_status']) : 'undefined'; switch ($action) { case 'finish': mcm_action('web_record_selections'); mcm_action('web_finish_selection'); break; case 'exit': mcm_action('web_exit_without_saving'); break; case 'enter': case 'next': case 'prev': default: mcm_action('web_record_selections'); mcm_action('web_print_table', array('action' => $action, 'start' => $start, 'item_status' => $item_status, 'item_type' => $item_type)); break; } mcm_action('html_footer');
echo "db update starting\n"; echo " reading directory list... "; $dirlist = mcm_action('read_dirlist'); echo count($dirlist) . " directories found\n"; echo " parsing directory list... "; $itemlist = mcm_action('parse_dirlist', $dirlist); echo count($itemlist) . " valid entries found\n"; $last_item = mcm_action('lookup_last_item'); /* proceed with update */ foreach ($itemlist as $item) { $params = array('artist_name' => $item['artist_name'], 'album_name' => $item['album_name'], 'item_quality' => $item['item_quality'], 'pun' => $item['pun'], 'log' => $item['log'], 'bad' => $item['bad'], 'update' => TRUE, 'insert' => TRUE); mcm_action('lookup_item', $params); } if ($count = mcm_action('lookup_last_item') - $last_item) { echo " " . $count . " new items found - notifying users\n"; $users = mcm_action('lookup_all_users'); foreach ($users as $user) { if (!empty($user['user_email'])) { $name = $user['user_name']; $email = $user['user_email']; $message = "Hello {$name}.\n\n"; $message .= "This is a reminder that there"; if ($count == 1) { $message .= " is one new album "; } else { $message .= " are " . $count . " new albums "; } $message .= "to be reviewed since the last time you visited the site.\n\n"; $message .= "Please stop by http://frink/music to decide if you want these new albums added to your music directory.\n\n"; $message .= "-- \n"; $message .= "The Management";
function update_all_users() { $users = mcm_action('lookup_all_users'); echo "superuser mode - updating symlinks for all users with default settings\n"; foreach ($users as $user) { $user['seteuid'] = TRUE; /* attempt to change uid to the sysname of the user */ update_user($user); } }