3) { /* 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'), "..."); } } /* 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 return $text; } // truncate_with_ellipsis /** * show_header * This shows the header.inc.php, it may do something * more in the future */ function show_header() { require_once Config::get('prefix') . '/templates/header.inc.php'; } // show_header /** * show_footer * shows the footer of the page */ function show_footer() { require_once Config::get('prefix') . '/templates/footer.inc.php'; if ($_REQUEST['profiling']) { Dba::show_profile(); } } // show_footer /** * img_resize * this automaticly resizes the image for thumbnail viewing * only works on gif/jpg/png this function also checks to make * sure php-gd is enabled */ function img_resize($image,$size,$type,$album_id) { /* Make sure they even want us to resize it */ if (!Config::get('resize_images')) { return $image['raw']; } // Already resized if ($image['db_resized']) { debug_event('using_resized','using resized image for Album:' . $album_id,'2'); return $image['raw']; } $image = $image['raw']; if (!function_exists('gd_info')) { return false; } /* First check for php-gd */ $info = gd_info(); if ( ($type == 'jpg' OR $type == 'jpeg') AND !$info['JPG Support']) { return false; } elseif ($type == 'png' AND !$info['PNG Support']) { return false; } elseif ($type == 'gif' AND !$info['GIF Create Support']) { return false; } $src = imagecreatefromstring($image); if (!$src) { debug_event('IMG_RESIZE','Failed to create from string','3'); return false; } $width = imagesx($src); $height = imagesy($src); $new_w = $size['width']; $new_h = $size['height']; $img = imagecreatetruecolor($new_w,$new_h); if (!imagecopyresampled($img,$src,0,0,0,0,$new_w,$new_h,$width,$height)) { debug_event('IMG_RESIZE','Failed to copy resample image','3'); return false; } ob_start(); // determine image type and send it to the client switch ($type) { case 'jpg': case 'jpeg': imagejpeg($img,null,75); break; case 'gif': imagegif($img); break; case 'png': imagepng($img); break; } // Grab this image data and save it into the thumbnail $data = ob_get_contents(); ob_end_clean(); // If our image create failed don't save it, just return if (!$data) { debug_event('IMG_RESIZE','Failed to resize Art from Album:' . $album_id,'3'); return $image; } // Save what we've got Album::save_resized_art($data,'image/' . $type,$album_id); return $data; } // img_resize /** * 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 * 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) * @package General */ function get_location() { $location = array(); if (strlen($_SERVER['PHP_SELF'])) { $source = $_SERVER['PHP_SELF']; } else { $source = $_SERVER['REQUEST_URI']; } /* Sanatize the $_SERVER['PHP_SELF'] variable */ $source = str_replace(Config::get('raw_web_path'), "", $source); $location['page'] = preg_replace("/^\/(.+\.php)\/?.*/","$1",$source); switch ($location['page']) { case 'index.php': $location['title'] = _('Home'); break; case 'upload.php': $location['title'] = _('Upload'); break; case 'localplay.php': $location['title'] = _('Local Play'); break; case 'randomplay.php': $location['title'] = _('Random Play'); break; case 'playlist.php': $location['title'] = _('Playlist'); break; case 'search.php': $location['title'] = _('Search'); break; case 'preferences.php': $location['title'] = _('Preferences'); break; case 'admin/index.php': $location['title'] = _('Admin-Catalog'); $location['section'] = 'admin'; break; case 'admin/catalog.php': $location['title'] = _('Admin-Catalog'); $location['section'] = 'admin'; break; case 'admin/users.php': $location['title'] = _('Admin-User Management'); $location['section'] = 'admin'; break; case 'admin/mail.php': $location['title'] = _('Admin-Mail Users'); $location['section'] = 'admin'; break; case 'admin/access.php': $location['title'] = _('Admin-Manage Access Lists'); $location['section'] = 'admin'; break; case 'admin/preferences.php': $location['title'] = _('Admin-Site Preferences'); $location['section'] = 'admin'; break; case 'admin/modules.php': $location['title'] = _('Admin-Manage Modules'); $location['section'] = 'admin'; break; case 'browse.php': $location['title'] = _('Browse Music'); $location['section'] = 'browse'; break; case 'albums.php': $location['title'] = _('Albums'); $location['section'] = 'browse'; break; case 'artists.php': $location['title'] = _('Artists'); $location['section'] = 'browse'; break; case 'genre.php': $location['title'] = _('Genre'); $location['section'] = 'browse'; break; case 'stats.php': $location['title'] = _('Statistics'); break; default: $location['title'] = ''; break; } // switch on raw page location return $location; } // 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
tags */ function show_preference_box($preferences) { require Config::get('prefix') . '/templates/show_preference_box.inc.php'; } // 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 */ function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) { // Generate key to use for HTML element ID static $id_cnt; if ($song_id) { $key = "album_select_$song_id"; } else { $key = "album_select_c" . ++$id_cnt; } // Added ID field so we can easily observe this element echo "\n"; } // show_album_select /** * show_artist_select * This is the same as the 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 static $id_cnt; if ($song_id) { $key = "artist_select_$song_id"; } else { $key = "artist_select_c" . ++$id_cnt; } echo "\n"; } // show_artist_select /** * show_catalog_select * 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='') { echo "\n"; } // show_catalog_select /** * show_user_select * This one is for users! shows a select/option statement so you can pick a user * to blame */ function show_user_select($name,$selected='',$style='') { echo "\n"; } // show_user_select /** * show_playlist_select * This one is for users! shows a select/option statement so you can pick a user * to blame */ function show_playlist_select($name,$selected='',$style='') { echo "\n"; } // show_playlist_select /** * show_box_top * This function requires the top part of the box * it takes title as an optional argument */ function show_box_top($title='',$class='') { require Config::get('prefix') . '/templates/show_box_top.inc.php'; } // show_box_top /** * show_box_bottom * This function requires the bottom part of the box * it does not take any arguments */ function show_box_bottom() { require Config::get('prefix') . '/templates/show_box_bottom.inc.php'; } // show_box_bottom /** * get_user_icon * this function takes a name and a returns either a text representation * or an tag */ function get_user_icon($name,$title='',$id='') { /* Because we do a lot of calls cache the URLs */ static $url_cache = array(); // If our name is an array if (is_array($name)) { $hover_name = $name['1']; $name = $name['0']; } if (!$title) { $title = _(ucfirst($name)); } if ($id) { $id_element = 'id="' . $id . '"'; } if (isset($url_cache[$name])) { $img_url = $url_cache[$name]; $cache_url = true; } if (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'; /* Build the image url */ if (file_exists(Config::get('prefix') . Config::get('theme_path') . '/images/icons/' . $icon_name)) { $img_url = Config::get('web_path') . Config::get('theme_path') . '/images/icons/' . $icon_name; } else { $img_url = Config::get('web_path') . '/images/' . $icon_name; } /* If Hover, then build its url */ if (!empty($hover_name)) { $hover_icon = 'icon_' . $hover_name . '.png'; if (file_exists(Config::get('prefix') . Config::get('theme_path') . '/images/icons/' . $icon_name)) { $hov_url = Config::get('web_path') . Config::get('theme_path') . '/images/icons/' . $hover_icon; } else { $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;\""; } // end hover } // end if not cached $string = "\"""; return $string; } // get_user_icon /** * xml_from_array * This takes a one dimensional array and * creates a XML document form it for use * primarly 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 ''; } // 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\n"; } else { if ($key == "key"){ $string .= "\t\t<$key>$value\n"; } elseif (is_int($value)) { $string .= "\t\t\t$key$value\n"; } elseif ($key == "Date Added") { $string .= "\t\t\t$key$value\n"; } elseif (is_string($value)) { /* We need to escape the value */ $string .= "\t\t\t$key\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\n"; } else { if ($key == "key"){ $string .= "\t\t<$key>$value\n"; } elseif (is_numeric($value)) { $string .= "\t\t\t<$key>$value\n"; } elseif (is_string($value)) { /* We need to escape the value */ $string .= "\t\t\t<$key>\n"; } } } // end foreach return $string; break; default: foreach ($array as $key=>$value) { if (is_numeric($key)) { $key = 'item'; } if (is_array($value)) { $value = xml_from_array($value,1); $string .= "\t$value\n"; } else { /* We need to escape the value */ $string .= "\t\n"; } // end foreach elements } if (!$callback) { $string = "\n\n" . $string . "\n"; } return $string; break; } } // xml_from_array /** * xml_get_header * This takes the type and returns the correct xml header */ function xml_get_header($type){ switch ($type){ case 'itunes': $header = "\n" . "\n" . "\n" . "\n" . " Major Version1\n" . " Minor Version1\n" . " Application Version7.0.2\n" . " Features1\n" . " Show Content Ratings\n" . " Tracks\n" . " \n"; return $header; break; case 'xspf': $header = "\n" . ""; "\n ". "Ampache XSPF Playlist\n" . "" . Config::get('site_title') . "\n" . "" . Config::get('site_title') . "\n" . "". Config::get('web_path') ."\n" . "\n\n\n\n"; return $header; break; default: $header = "\n"; return $header; break; } } //xml_get_header /** * xml_get_footer * This takes the type and returns the correct xml footer */ function xml_get_footer($type){ switch ($type){ case 'itunes': $footer = " \n" . "\n" . "\n"; return $footer; break; case 'xspf': $footer = " \n" . "\n"; return $footer; break; default: break; } } // xml_get_footer /** * ajax_include * This does an ob_start, getcontents, clean * on the specified require, only works if you * don't need to pass data in */ function ajax_include($include) { ob_start(); require_once Config::get('prefix') . '/templates/' . $include; $results = ob_get_contents(); ob_end_clean(); return $results; } // ajax_include /** * toggle_visible * this is identicla to the javascript command that it actually calls */ function toggle_visible($element) { echo "\n"; } // toggle_visible /** * show_now_playing * This shows the now playing templates and does some garbage colleciont * this should really be somewhere else */ function show_now_playing() { Stream::gc_session(); Stream::gc_now_playing(); $web_path = Config::get('web_path'); $results = Stream::get_now_playing(); require_once Config::get('prefix') . '/templates/show_now_playing.inc.php'; } // show_now_playing ?>