summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/flag.php29
-rw-r--r--lib/general.lib.php323
-rw-r--r--lib/ui.lib.php313
-rw-r--r--templates/show_debug.inc.php12
-rw-r--r--templates/show_install_check.inc.php4
-rw-r--r--templates/show_localplay_status.inc.php8
-rw-r--r--templates/show_test.inc.php2
7 files changed, 248 insertions, 443 deletions
diff --git a/admin/flag.php b/admin/flag.php
index 8eaf310a..cd4d52d8 100644
--- a/admin/flag.php
+++ b/admin/flag.php
@@ -35,19 +35,12 @@ switch ($_REQUEST['action']) {
$new_song = new Song();
/* Setup the vars so we can use the update_song function */
- $new_song->title = revert_string(scrub_in($_REQUEST['title']));
- $new_song->track = revert_string(scrub_in($_REQUEST['track']));
- $new_song->year = revert_string(scrub_in($_REQUEST['year']));
- $new_song->comment = revert_string(scrub_in($_REQUEST['comment']));
+ $new_song->title = unhtmlentities(scrub_in($_REQUEST['title']));
+ $new_song->track = unhtmlentities(scrub_in($_REQUEST['track']));
+ $new_song->year = unhtmlentities(scrub_in($_REQUEST['year']));
+ $new_song->comment = unhtmlentities(scrub_in($_REQUEST['comment']));
/* If no change in string take Drop down */
- if (strcasecmp(stripslashes($_REQUEST['genre_string']),$song->get_genre_name()) == 0) {
- $genre = $song->get_genre_name($_REQUEST['genre']);
- }
- else {
- $genre = scrub_in($_REQUEST['genre_string']);
- }
-
if (strcasecmp(stripslashes($_REQUEST['album_string']),$song->get_album_name()) == 0) {
$album = $song->get_album_name($_REQUEST['album']);
}
@@ -63,15 +56,13 @@ switch ($_REQUEST['action']) {
}
/* Use the check functions to get / create ids for this info */
- $new_song->genre = $catalog->check_genre(revert_string($genre));
- $new_song->album = $catalog->check_album(revert_string($album));
- $new_song->artist = $catalog->check_artist(revert_string($artist));
+ $new_song->album = $catalog->check_album(unhtmlentities($album));
+ $new_song->artist = $catalog->check_artist(unhtmlentities($artist));
/* Update this mofo, store an old copy for cleaning */
$old_song = new Song();
$old_song->artist = $song->artist;
$old_song->album = $song->album;
- $old_song->genre = $song->genre;
$song->update_song($song->id,$new_song);
/* Now that it's been updated clean old junk entries */
@@ -203,18 +194,14 @@ switch ($_REQUEST['action']) {
$old_song = new Song();
$old_song->artist = $new_song->artist;
$old_song->album = $new_song->album;
- $old_song->genre = $new_song->genre;
/* Restrict which fields can be updated */
switch ($object) {
- case 'genre':
- $new_song->genre = $catalog->check_genre(revert_string($_REQUEST['update_value']));
- break;
case 'album':
- $new_song->album = $catalog->check_album(revert_string($_REQUEST['update_value']));
+ $new_song->album = $catalog->check_album(unhtmlentities($_REQUEST['update_value']));
break;
case 'artist':
- $new_song->artist = $catalog->check_artist(revert_string($_REQUEST['update_value']));
+ $new_song->artist = $catalog->check_artist(unhtmlentities($_REQUEST['update_value']));
break;
case 'year':
$new_song->year = intval($_REQUEST['update_value']);
diff --git a/lib/general.lib.php b/lib/general.lib.php
index 692dbad5..8033c927 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -20,241 +20,121 @@
*/
-
-/**
- * session_exists
- * checks to make sure they've specified a valid session, can handle xmlrpc
- */
-function session_exists($sid,$xml_rpc=0) {
-
- $found = true;
-
- $sql = "SELECT * FROM `session` WHERE `id` = '$sid'";
- $db_results = Dba::read($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 XML_RPC_Client($path,$server,$port);
-
- /* Encode the SID of the incomming client */
- $encoded_sid = new XML_RPC_Value($sid,"string");
-
- $query = new XML_RPC_Message('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 = XML_RPC_Decode($value);
- $found = $data;
- }
-
- } // xml_rpc
-
- return $found;
-
-} // session_exists
-
/**
- * extend_session
- * just updates the expire time of the specified session this
- * is used by the the play script after a song finishes
+ * set_memory_limit
+ * This function attempts to change the php memory limit using init_set.
+ * Will never reduce it below the current setting.
*/
-function extend_session($sid) {
-
- $new_time = time() + Config::get('session_length');
-
- if ($_COOKIE['amp_longsess'] == '1') { $new_time = time() + 86400*364; }
-
- $sql = "UPDATE `session` SET `expire`='$new_time' WHERE `id`='$sid'";
- $db_results = Dba::write($sql);
-
-} // extend_session
-
-/*!
- @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);
+ $php_memory = $new_limit . "M";
+ ini_set (memory_limit, "$php_memory");
+ unset($php_memory);
}
} // set_memory_limit
/**
- * 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 = "<a href=\"$web_path/stream.php?action=single_song&amp;song_id=$song->id\" title=\"". scrub_out($text) ."\">" .
- scrub_out(truncate_with_ellipsis($text, Config::get('ellipse_threshold_title')+3)) . "&nbsp;(" . $r['count'] . ")</a>";
- $items[] = $song;
- } // if it's a song
-
- /* If Artist */
- elseif ( $type == 'artist' ) {
- $artist = new Artist($r['object_id']);
- $artist->format();
- $artist->link = "<a href=\"$web_path/artists.php?action=show&amp;artist=" . $r['object_id'] . "\" title=\"". scrub_out($artist->full_name) ."\">" .
- truncate_with_ellipsis($artist->full_name, Config::get('ellipse_threshold_artist')+3) . "&nbsp;(" . $r['count'] . ")</a>";
- $items[] = $artist;
- } // if type isn't artist
-
- /* If Album */
- elseif ( $type == 'album' ) {
- $album = new Album($r['object_id']);
- $album->format();
- $album->link = "<a href=\"$web_path/albums.php?action=show&amp;album=" . $r['object_id'] . "\" title=\"". scrub_out($album->name) ."\">" .
- scrub_out(truncate_with_ellipsis($album->name,Config::get('ellipse_threshold_album')+3)) . "&nbsp;(" . $r['count'] . ")</a>";
- $items[] = $album;
- } // else not album
-
- } // end foreach
-
- return $items;
-
-} // get_global_popular
-
-/**
* generate_password
- * This generates a random password, of the specified
- * length
+ * This generates a random password of the specified length
*/
function generate_password($length) {
- $vowels = 'aAeEuUyY12345';
- $consonants = 'bBdDgGhHjJmMnNpPqQrRsStTvVwWxXzZ6789';
- $password = '';
+ $vowels = 'aAeEuUyY12345';
+ $consonants = 'bBdDgGhHjJmMnNpPqQrRsStTvVwWxXzZ6789';
+ $password = '';
- $alt = time() % 2;
+ $alt = time() % 2;
- for ($i = 0; $i < $length; $i++) {
- if ($alt == 1) {
- $password .= $consonants[(rand(0,strlen($consonants)-1))];
- $alt = 0;
- } else {
- $password .= $vowels[(rand(0,strlen($vowels)-1))];
- $alt = 1;
- }
- }
+ for ($i = 0; $i < $length; $i++) {
+ if ($alt == 1) {
+ $password .= $consonants[(rand(0,strlen($consonants)-1))];
+ $alt = 0;
+ }
+ else {
+ $password .= $vowels[(rand(0,strlen($vowels)-1))];
+ $alt = 1;
+ }
+ }
- return $password;
+ return $password;
} // generate_password
/**
+ * scrub_in
+ * Run on inputs, stuff that might get stuck in our db
+ */
+function scrub_in($input) {
+
+ if (!is_array($input)) {
+ return stripslashes(htmlspecialchars(strip_tags($input)));
+ }
+ else {
+ $results = array();
+ foreach($input as $item) {
+ $results[] = scrub_in($item);
+ }
+ return $results;
+ }
+} // scrub_in
+
+/**
* scrub_out
* This function is used to escape user data that is getting redisplayed
* onto the page, it htmlentities the mojo
*/
-function scrub_out($str) {
+function scrub_out($string) {
//This feature has been DEPRECATED as of PHP 5.3.0
if(version_compare(PHP_VERSION, '5.3.0', '<=') AND ini_get('magic_quotes_gpc') != 'Off') {
- $str = stripslashes($str);
+ $string = stripslashes($string);
}
- $str = htmlentities($str,ENT_QUOTES,Config::get('site_charset'));
+ $string = htmlentities($string, ENT_QUOTES, Config::get('site_charset'));
- return $str;
+ return $string;
} // scrub_out
/**
- * revert_string
- * This returns a scrubed string to it's most normal state
- * Uhh yea better way to do this please?
+ * unhtmlentities
+ * Undoes htmlentities()
*/
-function revert_string($string) {
+function unhtmlentities($string) {
- $string = unhtmlentities($string,ENT_QUOTES,conf('site_charset'));
- return $string;
+ return html_entity_decode($string, ENT_QUOTES, Config::get('site_charset'));
-} // revert_string
+} //unhtmlentities
/**
* make_bool
- * This takes a value and returns what I consider to be the correct boolean value
- * This is used instead of settype alone because settype considers 0 and "false" to
- * be true
+ * This takes a value and returns what we consider to be the correct boolean
+ * value. We need a special function because PHP considers "false" to be true.
* @package General
*/
function make_bool($string) {
if (strcasecmp($string,'false') == 0) {
- return '0';
+ return false;
}
- if ($string == '0') {
- return '0';
- }
+ return (bool)$string;
- if (strlen($string) < 1) {
- return '0';
- }
+} // make_bool
- return settype($string,"bool");
+/**
+ * invert_bool
+ * This returns the opposite of what you've got
+ */
+function invert_bool($value) {
-} // make_bool
+ return make_bool($value) ? false : true;
+
+} // invert_bool
/**
* get_languages
@@ -353,8 +233,9 @@ function is_rtl($locale) {
/**
* translate_pattern_code
- * This just contains a key'd array which it checks against to give you the 'tag' name
- * that said pattern code corrasponds to, it returns false if nothing is found
+ * This just contains a keyed array which it checks against to give you the
+ * 'tag' name that said pattern code corrasponds to. It returns false if nothing
+ * is found.
*/
function translate_pattern_code($code) {
@@ -371,82 +252,32 @@ function translate_pattern_code($code) {
return $code_array[$code];
}
-
return false;
} // translate_pattern_code
/**
- * print_boolean
- * This function takes a boolean value and then print out a friendly
- * text message, usefull if you have a 0/1 that you need to turn into
- * a "Off" "On"
- */
-function print_boolean($value) {
-
-
- if ($value) {
- $string = '<span class="item_on">' . _('On') . '</span>';
- }
- else {
- $string = '<span class="item_off">' . _('Off') . '</span>';
- }
-
- return $string;
-
-} // print_boolean
-
-/**
- * invert_boolean
- * This returns the opposite of what you've got
- */
-function invert_boolean($value) {
-
- if (make_bool($value)) {
- return '0';
- }
- else {
- return '1';
- }
-
-} // invert_boolean
-
-/**
- * unhtmlentities
- * This is required to make thing work.. but holycrap is it ugly
- */
-function unhtmlentities ($string) {
-
- $trans_tbl = get_html_translation_table (HTML_ENTITIES);
- $trans_tbl = array_flip ($trans_tbl);
- $ret = strtr ($string, $trans_tbl);
- return preg_replace('/&#(\d+);/me', "chr('\\1')",$ret);
-
-} // unhtmlentities
-
-/**
* __autoload
- * This function automatically loads any missing
- * classes as they are called so that we don't have to have
- * a million include statements, and load more then we need
+ * This function automatically loads any missing classes as they are needed so
+ * that we don't use a million include statements which load more than we need.
*/
function __autoload($class) {
// Lowercase the class
- $class = strtolower($class);
+ $class = strtolower($class);
$file = Config::get('prefix') . "/lib/class/$class.class.php";
// See if it exists
- if (is_readable($file)) {
- require_once $file;
- if (is_callable($class . '::_auto_init')) {
- call_user_func(array($class, '_auto_init'));
- }
- }
+ if (is_readable($file)) {
+ require_once $file;
+ if (is_callable($class . '::_auto_init')) {
+ call_user_func(array($class, '_auto_init'));
+ }
+ }
// Else log this as a fatal error
- else {
- debug_event('__autoload', "'$class' not found!",'1');
- }
+ else {
+ debug_event('__autoload', "'$class' not found!",'1');
+ }
} // __autoload
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index fd13da90..6c1d56fa 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -29,7 +29,7 @@
*/
/**
- * show_confirmation
+ * show_confirmation
* shows a confirmation of an action
* $next_url Where to go next
* $title The Title of the message
@@ -50,10 +50,9 @@ function show_confirmation($title,$text,$next_url,$cancel=0,$form_name='confirma
} // show_confirmation
/**
- * flip_class
- * takes an array of 2 class names
- * and flips them back and forth and
- * then echo's out [0]
+ * flip_class
+ * First called with an array of 2 class names. Subsequent calls reverse the
+ * array then return the first element.
*/
function flip_class($array=0) {
@@ -70,9 +69,9 @@ function flip_class($array=0) {
} // flip_class
/**
- * _
- * checks to see if the alias _ is defined
- * if it isn't it defines it as a simple return
+ * _
+ * Check to see if the gettext alias _ is defined. If it isn't we define it as
+ * a noop.
*/
if (!function_exists('_')) {
@@ -93,9 +92,8 @@ if (!function_exists('ngettext')) {
} // if no ngettext
/**
- * access_denied
- * throws an error if they try to do something
- * that they aren't allowed to
+ * access_denied
+ * Throws an error if they try to do something that they aren't allowed to.
*/
function access_denied() {
@@ -107,7 +105,7 @@ function access_denied() {
} // access_denied
/**
- * return_referer
+ * return_referer
* returns the script part of the referer address passed by the web browser
* this is not %100 accurate. Also because this is not passed by us we need
* to clean it up, take the filename then check for a /admin/ and dump the rest
@@ -115,14 +113,14 @@ function access_denied() {
function return_referer() {
$referer = $_SERVER['HTTP_REFERER'];
- if (substr($referer, -1)=='/'){
- $file = 'index.php';
- }
- else {
- $file = basename($referer);
+ if (substr($referer, -1)=='/'){
+ $file = 'index.php';
+ }
+ else {
+ $file = basename($referer);
/* Strip off the filename */
- $referer = substr($referer,0,strlen($referer)-strlen($file));
- }
+ $referer = substr($referer,0,strlen($referer)-strlen($file));
+ }
if (substr($referer,strlen($referer)-6,6) == 'admin/') {
$file = 'admin/' . $file;
@@ -134,34 +132,33 @@ function return_referer() {
/**
* truncate_with_ellipsis
- * Correct Spelling function that truncates text to a specific lenght
- * and appends three dots, or an ellipsis to the end
- * @package Web Interface
- * @catagory General
- * @author Nedko Arnaudov
+ * Function that truncates text to a specific length and appends an ellipsis to
+ * the end.
*/
function truncate_with_ellipsis($text, $max='') {
$max = $max ? $max : '27';
- /* If we want it to be shorter than three, just throw it back */
- if ($max > 3) {
+ /* If they want it to be shorter than three, just throw it back */
+ if ($max <= 3) {
+ return $text;
+ }
- /* Make sure the functions exist before doing the iconv mojo */
- if (function_exists('iconv') && function_exists('iconv_substr') && function_exists('iconv_strlen')) {
- if (iconv_strlen($text, Config::get('site_charset')) > $max) {
- $text = iconv_substr($text, 0, $max-3, Config::get('site_charset'));
- $text .= iconv("ISO-8859-1", Config::get('site_charset'), "...");
- }
+ /* Make sure the functions exist before doing the iconv mojo */
+ if (function_exists('iconv') &&
+ function_exists('iconv_substr') &&
+ function_exists('iconv_strlen')) {
+ $charset = Config::get('site_charset');
+ if (iconv_strlen($text, $charset) > $max) {
+ $text = iconv_substr($text, 0, $max-3, $charset);
+ $text .= iconv("ISO-8859-1", $charset, "...");
}
-
- /* Do normal substr if we don't have iconv */
- else {
- if (strlen($text) > $max) {
- $text = substr($text,0,$max-3)."...";
- }
- } // else no iconv
- } // else greater than 3
+ }
+ else { // Use normal substr if we don't have iconv
+ if (strlen($text) > $max) {
+ $text = substr($text,0,$max-3)."...";
+ }
+ } // else no iconv
return $text;
@@ -179,13 +176,13 @@ function show_header() {
} // show_header
/**
- * show_footer
+ * show_footer
* shows the footer of the page
*/
function show_footer() {
require_once Config::get('prefix') . '/templates/footer.inc.php';
- if ($_REQUEST['profiling']) {
+ if (isset($_REQUEST['profiling'])) {
Dba::show_profile();
}
@@ -193,13 +190,14 @@ function show_footer() {
/**
* get_location
- * This function gets the information about said persons currently location
- * this is used for A) Sidebar highlighting & submenu showing and B) Titlebar information
- * it returns an array of information about what they are currently doing
+ * This function gets the information about a person's current location.
+ * This is used for A) sidebar highlighting & submenu showing and B) titlebar
+ * information. It returns an array of information about what they are currently
+ * doing.
* Possible array elements
* ['title'] Text name for the page
* ['page'] actual page name
- * ['section'] name of the section we are in, admin, browse etc (submenu control)
+ * ['section'] name of the section we are in, admin, browse etc (submenu)
* @package General
*/
function get_location() {
@@ -293,9 +291,7 @@ function get_location() {
/**
* show_preference_box
- * This shows the preference box for the preferences pages
- * it takes a chunck of the crazy preference array and then displays it out
- * it does not contain the <form> </form> tags
+ * This shows the preference box for the preferences pages.
*/
function show_preference_box($preferences) {
@@ -304,44 +300,9 @@ function show_preference_box($preferences) {
} // show_preference_box
/**
- * good_email
- * Don't get me started... I'm sure the indenting is still wrong on this
- * it shouldn't be named this, it should be documented, yea this needs
- * some serious MOJO work
- */
-function good_email($email) {
- // First check that there's one @ symbol, and that the lengths are good
- if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $email)) {
- // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
- return false;
- }
-
- // Split it into sections
- $email_array = explode("@", $email);
- $local_array = explode(".", $email_array[0]);
- for ($i = 0; $i < sizeof($local_array); $i++) {
- if (!preg_match("/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) {
- return false;
- }
- }
- if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
- $domain_array = explode(".", $email_array[1]);
- if (sizeof($domain_array) < 2) {
- return false; // Not enough parts to domain
- }
- for ($i = 0; $i < sizeof($domain_array); $i++) {
- if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) {
- return false;
- }
- }
- }
- return true;
-} //good_email
-
-/**
* show_album_select
- * This displays a select of every album that we've got in Ampache, (it can be hella long) it's used
- * by the Edit page, it takes a $name and a $album_id
+ * This displays a select of every album that we've got in Ampache (which can be
+ * hella long). It's used by the Edit page and takes a $name and a $album_id
*/
function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) {
// Generate key to use for HTML element ID
@@ -380,7 +341,8 @@ function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) {
/**
* show_artist_select
- * This is the same as the album select except it's *gasp* for artists how inventive!
+ * This is the same as show_album_select except it's *gasp* for artists! How
+ * inventive!
*/
function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id=0) {
// Generate key to use for HTML element ID
@@ -418,7 +380,8 @@ function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id
/**
* show_catalog_select
- * Yet another one of these buggers. this shows a drop down of all of your catalogs
+ * Yet another one of these buggers. this shows a drop down of all of your
+ * catalogs.
*/
function show_catalog_select($name='catalog',$catalog_id=0,$style='') {
@@ -471,8 +434,7 @@ function show_user_select($name,$selected='',$style='') {
/**
* show_playlist_select
- * This one is for users! shows a select/option statement so you can pick a user
- * to blame
+ * This one is for playlists!
*/
function show_playlist_select($name,$selected='',$style='') {
@@ -536,20 +498,23 @@ function get_user_icon($name,$title='',$id='') {
if (!$title) { $title = _(ucfirst($name)); }
if ($id) {
- $id_element = 'id="' . $id . '"';
+ $id = ' id="' . $id . '" ';
}
if (isset($url_cache[$name])) {
$img_url = $url_cache[$name];
$cache_url = true;
}
- if (isset($url_cache[$hover_name])) {
+
+ if (empty($hover_name)) {
+ $cache_hover = true;
+ $hov_txt = '';
+ }
+ elseif (isset($url_cache[$hover_name])) {
$hover_url = $url_cache[$hover_name];
$cache_hover = true;
}
- if (empty($hover_name)) { $cache_hover = true; }
-
if (!isset($cache_url) OR !isset($cache_hover)) {
$icon_name = 'icon_' . $name . '.png';
@@ -562,6 +527,8 @@ function get_user_icon($name,$title='',$id='') {
$img_url = Config::get('web_path') . '/images/' . $icon_name;
}
+ $url_cache[$name] = $img_url;
+
/* If Hover, then build its url */
if (!empty($hover_name)) {
$hover_icon = 'icon_' . $hover_name . '.png';
@@ -572,12 +539,13 @@ function get_user_icon($name,$title='',$id='') {
$hov_url = Config::get('web_path') . '/images/' . $hover_icon;
}
- $hov_txt = "onmouseover=\"this.src='$hov_url'; return true;\" onmouseout=\"this.src='$img_url'; return true;\"";
+ $hov_txt = " onmouseover=\"this.src='$hov_url'; return true;\" onmouseout=\"this.src='$img_url'; return true;\" ";
+ $url_cache[$hover_name] = $hov_txt;
} // end hover
} // end if not cached
- $string = "<img src=\"$img_url\" $id_element alt=\"" . $title . "\" title=\"" . $title . "\" $hov_txt/>";
+ $string = '<img src="' . $img_url . '"' . $id . 'alt="' . $title . '" title="' . $title . '"' . $hov_txt . '/>';
return $string;
@@ -585,58 +553,59 @@ function get_user_icon($name,$title='',$id='') {
/**
* xml_from_array
- * This takes a one dimensional array and
- * creates a XML document form it for use
- * primarly by the ajax mojo
+ * This takes a one dimensional array and creates a XML document from it. For
+ * use primarily by the ajax mojo.
*/
function xml_from_array($array,$callback=0,$type='') {
- // If we weren't passed an array then return a blank string
- if (!is_array($array)) { return ''; }
+ $string = '';
+
+ // If we weren't passed an array then return
+ if (!is_array($array)) { return $string; }
// The type is used for the different XML docs we pass
switch ($type) {
case 'itunes':
- foreach ($array as $key=>$value) {
- if (is_array($value)) {
- $value = xml_from_array($value,1,$type);
- $string .= "\t\t<$key>\n$value\t\t</$key>\n";
- }
- else {
- if ($key == "key"){
- $string .= "\t\t<$key>$value</$key>\n";
- } elseif (is_int($value)) {
- $string .= "\t\t\t<key>$key</key><integer>$value</integer>\n";
- } elseif ($key == "Date Added") {
- $string .= "\t\t\t<key>$key</key><date>$value</date>\n";
- } elseif (is_string($value)) {
- /* We need to escape the value */
- $string .= "\t\t\t<key>$key</key><string><![CDATA[$value]]></string>\n";
- }
- }
-
- } // end foreach
+ foreach ($array as $key=>$value) {
+ if (is_array($value)) {
+ $value = xml_from_array($value,1,$type);
+ $string .= "\t\t<$key>\n$value\t\t</$key>\n";
+ }
+ else {
+ if ($key == "key"){
+ $string .= "\t\t<$key>$value</$key>\n";
+ } elseif (is_int($value)) {
+ $string .= "\t\t\t<key>$key</key><integer>$value</integer>\n";
+ } elseif ($key == "Date Added") {
+ $string .= "\t\t\t<key>$key</key><date>$value</date>\n";
+ } elseif (is_string($value)) {
+ /* We need to escape the value */
+ $string .= "\t\t\t<key>$key</key><string><![CDATA[$value]]></string>\n";
+ }
+ }
+
+ } // end foreach
return $string;
break;
case 'xspf':
- foreach ($array as $key=>$value) {
- if (is_array($value)) {
- $value = xml_from_array($value,1,$type);
- $string .= "\t\t<$key>\n$value\t\t</$key>\n";
- }
- else {
- if ($key == "key"){
- $string .= "\t\t<$key>$value</$key>\n";
- } elseif (is_numeric($value)) {
- $string .= "\t\t\t<$key>$value</$key>\n";
- } elseif (is_string($value)) {
- /* We need to escape the value */
- $string .= "\t\t\t<$key><![CDATA[$value]]></$key>\n";
- }
- }
-
- } // end foreach
+ foreach ($array as $key=>$value) {
+ if (is_array($value)) {
+ $value = xml_from_array($value,1,$type);
+ $string .= "\t\t<$key>\n$value\t\t</$key>\n";
+ }
+ else {
+ if ($key == "key"){
+ $string .= "\t\t<$key>$value</$key>\n";
+ } elseif (is_numeric($value)) {
+ $string .= "\t\t\t<$key>$value</$key>\n";
+ } elseif (is_string($value)) {
+ /* We need to escape the value */
+ $string .= "\t\t\t<$key><![CDATA[$value]]></$key>\n";
+ }
+ }
+
+ } // end foreach
return $string;
break;
@@ -652,7 +621,7 @@ function xml_from_array($array,$callback=0,$type='') {
$string .= "\t<content div=\"$key\"><![CDATA[$value]]></content>\n";
}
// end foreach elements
- }
+ }
if (!$callback) {
$string = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<root>\n" . $string . "</root>\n";
}
@@ -670,28 +639,28 @@ function xml_get_header($type){
switch ($type){
case 'itunes':
$header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
- "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"\n" .
- "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" .
- "<plist version=\"1.0\">\n" .
- "<dict>\n" .
- " <key>Major Version</key><integer>1</integer>\n" .
- " <key>Minor Version</key><integer>1</integer>\n" .
- " <key>Application Version</key><string>7.0.2</string>\n" .
- " <key>Features</key><integer>1</integer>\n" .
- " <key>Show Content Ratings</key><true/>\n" .
- " <key>Tracks</key>\n" .
- " <dict>\n";
+ "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"\n" .
+ "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" .
+ "<plist version=\"1.0\">\n" .
+ "<dict>\n" .
+ " <key>Major Version</key><integer>1</integer>\n" .
+ " <key>Minor Version</key><integer>1</integer>\n" .
+ " <key>Application Version</key><string>7.0.2</string>\n" .
+ " <key>Features</key><integer>1</integer>\n" .
+ " <key>Show Content Ratings</key><true/>\n" .
+ " <key>Tracks</key>\n" .
+ " <dict>\n";
return $header;
break;
case 'xspf':
- $header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" .
+ $header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" .
"<!-- XML Generated by Ampache v." . Config::get('version') . " -->";
- "<playlist version = \"1\" xmlns=\"http://xspf.org/ns/0/\">\n ".
- "<title>Ampache XSPF Playlist</title>\n" .
- "<creator>" . Config::get('site_title') . "</creator>\n" .
- "<annotation>" . Config::get('site_title') . "</annotation>\n" .
- "<info>". Config::get('web_path') ."</info>\n" .
- "<trackList>\n\n\n\n";
+ "<playlist version = \"1\" xmlns=\"http://xspf.org/ns/0/\">\n ".
+ "<title>Ampache XSPF Playlist</title>\n" .
+ "<creator>" . Config::get('site_title') . "</creator>\n" .
+ "<annotation>" . Config::get('site_title') . "</annotation>\n" .
+ "<info>". Config::get('web_path') ."</info>\n" .
+ "<trackList>\n\n\n\n";
return $header;
break;
default:
@@ -708,14 +677,14 @@ function xml_get_header($type){
function xml_get_footer($type){
switch ($type){
case 'itunes':
- $footer = " </dict>\n" .
- "</dict>\n" .
- "</plist>\n";
+ $footer = " </dict>\n" .
+ "</dict>\n" .
+ "</plist>\n";
return $footer;
break;
case 'xspf':
- $footer = " </trackList>\n" .
- "</playlist>\n";
+ $footer = " </trackList>\n" .
+ "</playlist>\n";
return $footer;
break;
default:
@@ -743,7 +712,7 @@ function ajax_include($include) {
/**
* toggle_visible
- * this is identicla to the javascript command that it actually calls
+ * This is identical to the javascript command that it actually calls
*/
function toggle_visible($element) {
@@ -754,8 +723,26 @@ function toggle_visible($element) {
} // toggle_visible
/**
+ * print_bool
+ * This function takes a boolean value and then prints out a friendly text
+ * message.
+ */
+function print_bool($value) {
+
+ if ($value) {
+ $string = '<span class="item_on">' . _('On') . '</span>';
+ }
+ else {
+ $string = '<span class="item_off">' . _('Off') . '</span>';
+ }
+
+ return $string;
+
+} // print_bool
+
+/**
* show_now_playing
- * This shows the now playing templates and does some garbage colleciont
+ * This shows the now playing templates and does some garbage collecion
* this should really be somewhere else
*/
function show_now_playing() {
diff --git a/templates/show_debug.inc.php b/templates/show_debug.inc.php
index f575850f..38b978cb 100644
--- a/templates/show_debug.inc.php
+++ b/templates/show_debug.inc.php
@@ -59,7 +59,7 @@
</tr>
<tr class="<?php echo flip_class(); ?>">
<td><?php echo _('Safe Mode'); ?></td>
- <td><?php echo print_boolean(ini_get('safe_mode')); ?></td>
+ <td><?php echo print_bool(ini_get('safe_mode')); ?></td>
</tr>
<tr class="<?php echo flip_class(); ?>">
<td>Open Basedir</td>
@@ -67,19 +67,19 @@
</tr>
<tr class="<?php echo flip_class(); ?>">
<td><?php echo _('Zlib Support'); ?></td>
- <td><?php echo print_boolean(function_exists('gzcompress')); ?></td>
+ <td><?php echo print_bool(function_exists('gzcompress')); ?></td>
</tr>
<tr class="<?php echo flip_class(); ?>">
<td><?php echo _('GD Support'); ?></td>
- <td><?php echo print_boolean(function_exists('ImageCreateFromString')); ?></td>
+ <td><?php echo print_bool(function_exists('ImageCreateFromString')); ?></td>
</tr>
<tr class="<?php echo flip_class(); ?>">
<td><?php echo _('Iconv Support'); ?></td>
- <td><?php echo print_boolean(function_exists('iconv')); ?></td>
+ <td><?php echo print_bool(function_exists('iconv')); ?></td>
</tr>
<tr class="<?php echo flip_class(); ?>">
<td><?php echo _('Gettext Support'); ?></td>
- <td><?php echo print_boolean(function_exists('bindtextdomain')); ?></td>
+ <td><?php echo print_bool(function_exists('bindtextdomain')); ?></td>
</tr>
</table>
<?php show_box_bottom(); ?>
@@ -104,7 +104,7 @@
$value = $string;
}
if (Preference::is_boolean($key)) {
- $value = print_boolean($value);
+ $value = print_bool($value);
}
?>
<tr class="<?php echo flip_class(); ?>">
diff --git a/templates/show_install_check.inc.php b/templates/show_install_check.inc.php
index db67fdc2..08952496 100644
--- a/templates/show_install_check.inc.php
+++ b/templates/show_install_check.inc.php
@@ -20,7 +20,7 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
?>
-<?php if (INSTALL != '1') { exit; } ?>
+<?php if (!defined('INSTALL')) { exit; } ?>
<h4><?php echo _('Required'); ?></h4>
<table border="0" cellspacing="0" cellpadding="3">
<tr>
@@ -49,7 +49,7 @@
else {
$version_string = phpversion() . " ";
}
- $string = $version_string . _('Hash Function Exists') . " " . print_boolean(function_exists('hash_algos')) . " " . _('SHA256 Support') . " " . print_boolean(in_array('sha256',$algos));
+ $string = $version_string . _('Hash Function Exists') . " " . print_bool(function_exists('hash_algos')) . " " . _('SHA256 Support') . " " . print_bool(in_array('sha256',$algos));
echo debug_result($string,false);
Error::add('install',_('PHP Version'));
}
diff --git a/templates/show_localplay_status.inc.php b/templates/show_localplay_status.inc.php
index 3117efc1..173d9124 100644
--- a/templates/show_localplay_status.inc.php
+++ b/templates/show_localplay_status.inc.php
@@ -35,13 +35,13 @@ $now_playing = $status['track_title'] ? $status['track_title'] . ' - ' . $status
<?php echo _('Volume'); ?>:<?php echo $status['volume']; ?>%
</li>
<li>
- <?php echo print_boolean($status['repeat']); ?> |
- <?php echo Ajax::text('?page=localplay&action=repeat&value=' . invert_boolean($status['repeat']),print_boolean(invert_boolean($status['repeat'])),'localplay_repeat'); ?>
+ <?php echo print_bool($status['repeat']); ?> |
+ <?php echo Ajax::text('?page=localplay&action=repeat&value=' . invert_bool($status['repeat']), print_bool(invert_bool($status['repeat'])), 'localplay_repeat'); ?>
<?php echo _('Repeat'); ?>
</li>
<li>
- <?php echo print_boolean($status['random']); ?> |
- <?php echo Ajax::text('?page=localplay&action=random&value=' . invert_boolean($status['random']),print_boolean(invert_boolean($status['random'])),'localplay_random'); ?>
+ <?php echo print_bool($status['random']); ?> |
+ <?php echo Ajax::text('?page=localplay&action=random&value=' . invert_bool($status['random']), print_bool(invert_bool($status['random'])), 'localplay_random'); ?>
<?php echo _('Random'); ?>
</li>
<li>
diff --git a/templates/show_test.inc.php b/templates/show_test.inc.php
index 20fe97c5..cbf97f0f 100644
--- a/templates/show_test.inc.php
+++ b/templates/show_test.inc.php
@@ -49,7 +49,7 @@
if (!check_php_ver()) {
echo debug_result('',false);
if (function_exists('hash_algos')) { $algos = hash_algos(); }
- $string = "<strong>" . phpversion() . " " . _('Hash Function Exists') . " " . print_boolean(function_exists('hash_algos')) . " " . _('SHA256 Support') . " " . print_boolean(in_array('sha256',$algos)) . "</strong>";
+ $string = "<strong>" . phpversion() . " " . _('Hash Function Exists') . " " . print_bool(function_exists('hash_algos')) . " " . _('SHA256 Support') . " " . print_bool(in_array('sha256',$algos)) . "</strong>";
}
else {
echo debug_result('',true);