$val) { if(!$clobber && isset($params[$key])) { echo "Error: attempting to clobber $key = $val\n"; exit(); } $params[$key] = $val; } return true; } else //meaning we are trying to retrieve a parameter { if($params[$param]) return $params[$param]; else return; } } //conf function error_results($param,$clobber=0) { static $params = array(); if(is_array($param)) //meaning we are setting values { foreach ($param as $key=>$val) { if(!$clobber && isset($params[$key])) { echo "Error: attempting to clobber $key = $val\n"; exit(); } $params[$key] = $val; } return true; } else //meaning we are trying to retrieve a parameter { if($params[$param]) return $params[$param]; else return; } } //error_results */ /** * session_exists * checks to make sure they've specified a valid session, can handle xmlrpc * @package General * @cataogry Verify * @todo Have XMLRPC check extend remote session * @todo actually check */ function session_exists($sid,$xml_rpc=0) { $found = true; $sql = "SELECT * FROM `session` WHERE `id` = '$sid'"; $db_results = Dba::query($sql); if (!Dba::num_rows($db_results)) { $found = false; } /* If we need to check the remote session */ if ($xml_rpc) { $server = rawurldecode($_GET['xml_server']); $path = "/" . rawurldecode($_GET['xml_path']) . "/server/xmlrpc.server.php"; $port = $_GET['xml_port']; $path = str_replace("//","/",$path); /* Create the XMLRPC client */ $client = new xmlrpc_client($path,$server,$port); /* Encode the SID of the incomming client */ $encoded_sid = new xmlrpcval($sid,"string"); $query = new xmlrpcmsg('remote_session_verify',array($encoded_sid) ); /* Log this event */ debug_event('xmlrpc-client',"Checking for Valid Remote Session:$sid",'3'); $response = $client->send($query,30); $value = $response->value(); if (!$response->faultCode()) { $data = php_xmlrpc_decode($value); $found = $data; } } // xml_rpc return $found; } // session_exists /*! @function extend_session @discussion just update the expire time */ function extend_session($sid) { $new_time = time() + Config::get('local_length'); if ($_COOKIE['amp_longsess'] == '1') { $new_time = time() + 86400*364; } $sql = "UPDATE `session` SET `expire`='$new_time' WHERE `id`='$sid'"; $db_results = Dba::query($sql); } // extend_session /** * get_tag_type * This takes the result set, and the the tag_order * As defined by your config file and trys to figure out * which tag type it should use, if your tag_order * doesn't match anything then it just takes the first one * it finds in the results. */ function get_tag_type($results) { /* Pull In the config option */ $order = Config::get('tag_order'); if (!is_array($order)) { $order = array($order); } /* Foreach through the defined key order * the first one we find is the first one we use */ foreach($order as $key) { if ($results[$key]) { $returned_key = $key; break; } } /* If we didn't find anything then default it to the * first in the results set */ if (!isset($returned_key)) { $keys = array_keys($results); $returned_key = $keys['0']; } return $returned_key; } // get_tag_type /** * clean_tag_info * This function takes the array from vainfo along with the * key we've decided on and the filename and returns it in a * sanatized format that ampache can actually use */ function clean_tag_info($results,$key,$filename) { $info = array(); $clean_array = array("\n","\t","\r","\0"); $wipe_array = array("","","",""); $info['file'] = $filename; $info['title'] = stripslashes(trim($results[$key]['title'])); $info['year'] = intval($results[$key]['year']); $info['track'] = intval($results[$key]['track']); $info['comment'] = Dba::escape(str_replace($clean_array,$wipe_array,$results[$key]['comment'])); /* This are pulled from the info array */ $info['bitrate'] = intval($results['info']['bitrate']); $info['rate'] = intval($results['info']['sample_rate']); $info['mode'] = $results['info']['bitrate_mode']; $info['size'] = $results['info']['filesize']; $info['mime'] = $results['info']['mime']; $into['encoding'] = $results['info']['encoding']; $info['time'] = intval($results['info']['playing_time']); $info['channels'] = intval($results['info']['channels']); /* These are used to generate the correct ID's later */ $info['artist'] = trim($results[$key]['artist']); $info['album'] = trim($results[$key]['album']); $info['genre'] = trim($results[$key]['genre']); return $info; } // clean_tag_info /*! @function scrub_in() @discussion Run on inputs, stuff that might get stuck in our db */ function scrub_in($str) { if (!is_array($str)) { return stripslashes( htmlspecialchars( strip_tags($str) ) ); } else { $ret = array(); foreach($str as $string) $ret[] = scrub_in($string); return $ret; } } // scrub_in /*! @function set_memory_limit @discussion this function attempts to change the php memory limit using init_set but it will never reduce it */ function set_memory_limit($new_limit) { /* Check their PHP Vars to make sure we're cool here */ // Up the memory $current_memory = ini_get('memory_limit'); $current_memory = substr($current_memory,0,strlen($current_memory)-1); if ($current_memory < $new_limit) { $php_memory = $new_limit . "M"; ini_set (memory_limit, "$php_memory"); unset($php_memory); } } // set_memory_limit /*! @function get_random_songs @discussion Returns a random set of songs/albums or artists matchlist is an array of the WHERE mojo and options defines special unplayed,album,artist,limit info */ function get_random_songs( $options, $matchlist) { $dbh = dbh(); /* Define the options */ $limit = intval($options['limit']); /* If they've passed -1 as limit then don't get everything */ if ($options['limit'] == "-1") { unset($options['limit']); } elseif ($options['random_type'] == 'length') { /* Rien a faire */ } else { $limit_sql = "LIMIT " . $limit; } $where = "1=1 "; if(is_array($matchlist)) foreach ($matchlist as $type => $value) { if (is_array($value)) { foreach ($value as $v) { $v = sql_escape($v); if ($v != $value[0]) { $where .= " OR $type='$v' "; } else { $where .= " AND ( $type='$v'"; } } $where .= " ) "; } elseif (strlen($value)) { $value = sql_escape($value); $where .= " AND $type='$value' "; } } if ($options['random_type'] == 'full_album') { $query = "SELECT album.id FROM song,album WHERE song.album=album.id AND $where GROUP BY song.album ORDER BY RAND() " . $limit_sql; $db_results = mysql_query($query, $dbh); while ($data = mysql_fetch_row($db_results)) { $albums_where .= " OR song.album=" . $data[0]; } $albums_where = ltrim($albums_where," OR"); $query = "SELECT song.id,song.size,song.time FROM song WHERE $albums_where ORDER BY song.album,song.track ASC"; } elseif ($options['random_type'] == 'full_artist') { $query = "SELECT artist.id FROM song,artist WHERE song.artist=artist.id AND $where GROUP BY song.artist ORDER BY RAND() " . $limit_sql; $db_results = mysql_query($query, $dbh); while ($data = mysql_fetch_row($db_results)) { $artists_where .= " OR song.artist=" . $data[0]; } $artists_where = ltrim($artists_where," OR"); $query = "SELECT song.id,song.size,song.time FROM song WHERE $artists_where ORDER BY RAND()"; } /* TEMP DISABLE */ // elseif ($options['random_type'] == 'unplayed') { // $uid = $GLOBALS['user']->id; // $query = "SELECT song.id,song.size FROM song LEFT JOIN object_count ON song.id = object_count.object_id " . // "WHERE ($where) AND ((object_count.object_type='song' AND user = '$uid') OR object_count.count IS NULL ) " . // "ORDER BY CASE WHEN object_count.count IS NULL THEN RAND() WHEN object_count.count > 4 THEN RAND()*RAND()*object_count.count " . // "ELSE RAND()*object_count.count END " . $limit_sql; // } // If unplayed else { $query = "SELECT id,size,time FROM song WHERE $where ORDER BY RAND() " . $limit_sql; } $db_result = mysql_query($query, $dbh); $songs = array(); while ( $r = mysql_fetch_assoc($db_result) ) { /* If they've specified a filesize limit */ if ($options['size_limit']) { /* Turn it into MB */ $new_size = ($r['size'] / 1024) / 1024; /* If we would go over the allowed size skip to the next song */ if (($total + $new_size) > $options['size_limit']) { continue; } $total = $total + $new_size; $songs[] = $r['id']; /* If we are within 4mb then that's good enough for Vollmer work */ if (($options['size_limit'] - floor($total)) < 4) { return $songs; } } // end if we are defining a size limit /* If they've specified a length */ if ($options['random_type'] == 'length') { /* Turn the length into min's */ $new_time = floor($r['time'] / 60); if ($fuzzy_count > 10) { return $songs; } /* If the new one would go over skip to the next song with a limit */ if (($total + $new_time) > $options['limit']) { $fuzzy_count++; continue; } $total = $total + $new_time; $songs[] = $r['id']; if (($options['limit'] - $total) < 2) { return $songs; } } // if length /* If we aren't using a limit */ else { $songs[] = $r['id']; } } // while we fetch results return $songs; } // get_random_songs /** * cleanup_and_exit * used specificly for the play/index.php file * this functions nukes now playing and then exits * @package Streaming * @catagory Clean */ function cleanup_and_exit($playing_id) { /* Clear now playing */ // 900 = 15 min $expire = time() - 900; $sql = "DELETE FROM now_playing WHERE now_playing.id='$lastid' OR now_playing.start_time < $expire"; $db_results = @mysql_query($sql, dbh()); exit(); } // cleanup_and_exit /** * get_global_popular * this function gets the current globally popular items * from the object_count table, depending on type passed * @package Web Interface * @catagory Get */ function get_global_popular($type) { $stats = new Stats(); $count = Config::get('popular_threshold'); $web_path = Config::get('web_path'); /* Pull the top */ $results = $stats->get_top($count,$type); foreach ($results as $r) { /* If Songs */ if ( $type == 'song' ) { $song = new Song($r['object_id']); $song->format(); $text = "$song->f_artist_full - $song->title"; /* Add to array */ $song->link = "id\" title=\"". scrub_out($text) ."\">" . scrub_out(truncate_with_ellipsis($text, Config::get('ellipsis_threshold_title')+3)) . " (" . $r['count'] . ")"; $items[] = $song; } // if it's a song /* If Artist */ elseif ( $type == 'artist' ) { $artist = new Artist($r['object_id']); $artist->format(); $artist->link = "full_name) ."\">" . truncate_with_ellipsis($artist->full_name, Config::get('ellipsis_threshold_artist')+3) . " (" . $r['count'] . ")"; $items[] = $artist; } // if type isn't artist /* If Album */ elseif ( $type == 'album' ) { $album = new Album($r['object_id']); $album->format(); $album->link = "name) ."\">" . scrub_out(truncate_with_ellipsis($album->name,Config::get('ellipsis_threshold_album')+3)) . " (" . $r['count'] . ")"; $items[] = $album; } // else not album elseif ($type == 'genre') { $genre = new Genre($r['object_id']); $genre->format(); $genre->link = "name) . "\">" . scrub_out(truncate_with_ellipsis($genre->name,Config::get('ellipsis_threshold_title')+3)) . " (" . $r['count'] . ")"; $items[] = $genre; } // end if genre } // end foreach /* if (count($items) == 0) { $itemis[''] = "