From 9c28ed5ad1adf15f868d181b9cfca26a801550ad Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Fri, 25 Jan 2013 19:54:11 -0500 Subject: Consistently use _ in two-word class names --- admin/mail.php | 2 +- lib/class/ampache_mail.class.php | 214 +++++++++++ lib/class/ampache_rss.class.php | 253 +++++++++++++ lib/class/ampachemail.class.php | 214 ----------- lib/class/ampacherss.class.php | 253 ------------- lib/class/api.class.php | 122 +++--- lib/class/registration.class.php | 2 +- lib/class/stream_playlist.class.php | 8 +- lib/class/xml_data.class.php | 659 +++++++++++++++++++++++++++++++++ lib/class/xmldata.class.php | 659 --------------------------------- lostpassword.php | 2 +- rss.php | 2 +- server/xml.server.php | 8 +- templates/show_now_playing.inc.php | 2 +- templates/show_recently_played.inc.php | 2 +- 15 files changed, 1201 insertions(+), 1201 deletions(-) create mode 100644 lib/class/ampache_mail.class.php create mode 100644 lib/class/ampache_rss.class.php delete mode 100644 lib/class/ampachemail.class.php delete mode 100644 lib/class/ampacherss.class.php create mode 100644 lib/class/xml_data.class.php delete mode 100644 lib/class/xmldata.class.php diff --git a/admin/mail.php b/admin/mail.php index c0fa4f9b..ca974ff2 100644 --- a/admin/mail.php +++ b/admin/mail.php @@ -43,7 +43,7 @@ switch ($_REQUEST['action']) { mb_language("uni"); } - $mailer = new AmpacheMail(); + $mailer = new Ampache_Mail(); // Set the vars on the object $mailer->subject = $_REQUEST['subject']; diff --git a/lib/class/ampache_mail.class.php b/lib/class/ampache_mail.class.php new file mode 100644 index 00000000..8c1d363b --- /dev/null +++ b/lib/class/ampache_mail.class.php @@ -0,0 +1,214 @@ +sender = $user . '@' . $domain; + $this->sender_name = $fromname; + } // set_default_sender + + /** + * get_users + * This returns an array of userids for people who have e-mail + * addresses based on the passed filter + */ + public static function get_users($filter) { + + switch ($filter) { + default: + case 'all': + $sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL"; + break; + case 'users': + $sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL"; + break; + case 'admins': + $sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL"; + break ; + case 'inactive': + $inactive = time() - (30*86400); + $sql = "SELECT * FROM `user` WHERE `last_seen` <= '$inactive' AND `email` IS NOT NULL"; + break; + } // end filter switch + + $db_results = Dba::read($sql); + + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']); + } + + return $results; + + } // get_users + + /** + * add_statistics + * This should be run if we want to add some statistics to this e-mail, + * appends to self::$message + */ + public function add_statistics($methods) { + + + + } // add_statistics + + /** + * send + * This actually sends the mail, how amazing + */ + public function send($phpmailer = null) { + + $mailtype = Config::get('mail_type'); + + if ($phpmailer == null) { + $mail = new PHPMailer(); + + $recipient_name = $this->recipient_name; + if(function_exists('mb_encode_mimeheader')) { + $recipient_name = mb_encode_mimeheader($recipient_name); + } + $mail->AddAddress($this->recipient, $recipient_name); + } + else { + $mail = $phpmailer; + } + + $mail->CharSet = Config::get('site_charset'); + $mail->Encoding = 'base64'; + $mail->From = $this->sender; + $mail->Sender = $this->sender; + $mail->FromName = $this->sender_name; + $mail->Subject = $this->subject; + + if(function_exists('mb_eregi_replace')) { + $this->message = mb_eregi_replace("\r\n", "\n", $this->message); + } + $mail->Body = $this->message; + + $sendmail = Config::get('sendmail_path'); + $sendmail = $sendmail ? $sendmail : '/usr/sbin/sendmail'; + $mailhost = Config::get('mail_host'); + $mailhost = $mailhost ? $mailhost : 'localhost'; + $mailport = Config::get('mail_port'); + $mailport = $mailport ? $mailport : 25; + $mailauth = Config::get('mail_auth'); + $mailuser = Config::get('mail_auth_user'); + $mailuser = $mailuser ? $mailuser : ''; + $mailpass = Config::get('mail_auth_pass'); + $mailpass = $mailpass ? $mailpass : ''; + + switch($mailtype) { + case 'smtp': + $mail->IsSMTP(); + $mail->Host = $mailhost; + $mail->Port = $mailport; + if($mailauth == true) { + $mail->SMTPAuth = true; + $mail->Username = $mailuser; + $mail->Password = $mailpass; + } + if ($mailsecure = Config::get('mail_secure_smtp')) { + $mail->SMTPSecure = ($mailsecure == 'ssl') ? 'ssl' : 'tls'; + } + break; + case 'sendmail': + $mail->IsSendmail(); + $mail->Sendmail = $sendmail; + break; + case 'php': + default: + $mail->IsMail(); + break; + } + + $retval = $mail->send(); + if( $retval == true ) { + return true; + } else { + return false; + } + } // send + + public function send_to_group($group_name) { + $mail = new PHPMailer(); + + foreach(self::get_users($group_name) as $member) { + if(function_exists('mb_encode_mimeheader')) { + $member['fullname'] = mb_encode_mimeheader($member['fullname']); + } + $mail->AddBCC($member['email'], $member['fullname']); + } + + return $this->send($mail); + } + +} // Ampache_Mail class +?> diff --git a/lib/class/ampache_rss.class.php b/lib/class/ampache_rss.class.php new file mode 100644 index 00000000..3b567937 --- /dev/null +++ b/lib/class/ampache_rss.class.php @@ -0,0 +1,253 @@ +type = self::validate_type($type); + + } // constructor + + /** + * get_xml + * This returns the xmldocument for the current rss type, it calls a sub function that gathers the data + * and then uses the xmlDATA class to build the document + */ + public function get_xml() { + + // Function call name + $data_function = 'load_' . $this->type; + $pub_date_function = 'pubdate_' . $this->type; + + $data = call_user_func(array('Ampache_RSS',$data_function)); + $pub_date = call_user_func(array('Ampache_RSS',$pub_date_function)); + + XML_Data::set_type('rss'); + $xml_document = XML_Data::rss_feed($data,$this->get_title(),$this->get_description(),$pub_date); + + return $xml_document; + + } // get_xml + + /** + * get_title + * This returns the standardized title for the rss feed based on this->type + */ + public function get_title() { + + $titles = array('now_playing' => T_('Now Playing'), + 'recently_played' => T_('Recently Played'), + 'latest_album' => T_('Newest Albums'), + 'latest_artist' => T_('Newest Artists')); + + return scrub_out(Config::get('site_title')) . ' - ' . $titles[$this->type]; + + } // get_title + + /** + * get_description + * This returns the standardized description for the rss feed based on this->type + */ + public function get_description() { + + //FIXME: For now don't do any kind of translating + return 'Ampache RSS Feeds'; + + } // get_description + + /** + * validate_type + * this returns a valid type for an rss feed, if the specified type is invalid it returns a default value + */ + public static function validate_type($type) { + + $valid_types = array('now_playing','recently_played','latest_album','latest_artist','latest_song', + 'popular_song','popular_album','popular_artist'); + + if (!in_array($type,$valid_types)) { + return 'now_playing'; + } + + return $type; + + } // validate_type + + /** + * get_display + * This dumps out some html and an icon for the type of rss that we specify + */ + public static function get_display($type='now_playing') { + + // Default to now playing + $type = self::validate_type($type); + + $string = '' . get_user_icon('feed', T_('RSS Feed')) . ''; + + return $string; + + } // get_display + + // type specific functions below, these are called semi-dynamically based on the current type // + + /** + * load_now_playing + * This loads in the now playing information. This is just the raw data with key=>value pairs that could be turned + * into an xml document if we so wished + */ + public static function load_now_playing() { + + $data = Stream::get_now_playing(); + + $results = array(); + $format = Config::get('rss_format') ?: '%t - %a - %A'; + $string_map = array( + '%t' => 'title', + '%a' => 'artist', + '%A' => 'album' + ); + foreach ($data as $element) { + $song = $element['media']; + $client = $element['user']; + $title = $format; + $description = $format; + foreach($string_map as $search => $replace) { + $trep = 'f_' . $replace; + $drep = 'f_' . $replace . '_full'; + $title = str_replace($search, $song->$trep, $title); + $description = str_replace($search, $song->$drep, $description); + } + $xml_array = array( + 'title' => $title, + 'link' => $song->link, + 'description' => $description, + 'comments' => $client->fullname . ' - ' . $element['agent'], + 'pubDate' => date('r', $element['expire']) + ); + $results[] = $xml_array; + } // end foreach + + return $results; + + } // load_now_playing + + /** + * pubdate_now_playing + * this is the pub date we should use for the now playing information, + * this is a little specific as it uses the 'newest' expire we can find + */ + public static function pubdate_now_playing() { + + // Little redundent, should be fixed by an improvement in the get_now_playing stuff + $data = Stream::get_now_playing(); + + $element = array_shift($data); + + return $element['expire']; + + } // pubdate_now_playing + + /** + * load_recently_played + * This loads in the recently played information and formats it up real nice like + */ + public static function load_recently_played() { + + //FIXME: The time stuff should be centralized, it's currently in two places, lame + + $time_unit = array('', T_('seconds ago'), T_('minutes ago'), T_('hours ago'), T_('days ago'), T_('weeks ago'), T_('months ago'), T_('years ago')); + $data = Song::get_recently_played(); + + $results = array(); + + foreach ($data as $item) { + $client = new User($item['user']); + $song = new Song($item['object_id']); + $song->format(); + $amount = intval(time() - $item['date']+2); + $time_place = '0'; + while ($amount >= 1) { + $final = $amount; + $time_place++; + if ($time_place <= 2) { + $amount = floor($amount/60); + } + if ($time_place == '3') { + $amount = floor($amount/24); + } + if ($time_place == '4') { + $amount = floor($amount/7); + } + if ($time_place == '5') { + $amount = floor($amount/4); + } + if ($time_place == '6') { + $amount = floor ($amount/12); + } + if ($time_place > '6') { + $final = $amount . '+'; + break; + } + } // end while + + $time_string = $final . ' ' . $time_unit[$time_place]; + + $xml_array = array('title'=>$song->f_title . ' - ' . $song->f_artist . ' - ' . $song->f_album, + 'link'=>str_replace('&', '&', $song->link), + 'description'=>$song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full . ' - ' . $time_string, + 'comments'=>$client->username, + 'pubDate'=>date("r",$item['date'])); + $results[] = $xml_array; + + } // end foreach + + return $results; + + } // load_recently_played + + /** + * pubdate_recently_played + * This just returns the 'newest' recently played entry + */ + public static function pubdate_recently_played() { + + $data = Song::get_recently_played(); + + $element = array_shift($data); + + return $element['date']; + + } // pubdate_recently_played + +} // end Ampache_RSS class diff --git a/lib/class/ampachemail.class.php b/lib/class/ampachemail.class.php deleted file mode 100644 index 812c6769..00000000 --- a/lib/class/ampachemail.class.php +++ /dev/null @@ -1,214 +0,0 @@ -sender = $user . '@' . $domain; - $this->sender_name = $fromname; - } // set_default_sender - - /** - * get_users - * This returns an array of userids for people who have e-mail - * addresses based on the passed filter - */ - public static function get_users($filter) { - - switch ($filter) { - default: - case 'all': - $sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL"; - break; - case 'users': - $sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL"; - break; - case 'admins': - $sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL"; - break ; - case 'inactive': - $inactive = time() - (30*86400); - $sql = "SELECT * FROM `user` WHERE `last_seen` <= '$inactive' AND `email` IS NOT NULL"; - break; - } // end filter switch - - $db_results = Dba::read($sql); - - $results = array(); - - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']); - } - - return $results; - - } // get_users - - /** - * add_statistics - * This should be run if we want to add some statistics to this e-mail, - * appends to self::$message - */ - public function add_statistics($methods) { - - - - } // add_statistics - - /** - * send - * This actually sends the mail, how amazing - */ - public function send($phpmailer = null) { - - $mailtype = Config::get('mail_type'); - - if ($phpmailer == null) { - $mail = new PHPMailer(); - - $recipient_name = $this->recipient_name; - if(function_exists('mb_encode_mimeheader')) { - $recipient_name = mb_encode_mimeheader($recipient_name); - } - $mail->AddAddress($this->recipient, $recipient_name); - } - else { - $mail = $phpmailer; - } - - $mail->CharSet = Config::get('site_charset'); - $mail->Encoding = 'base64'; - $mail->From = $this->sender; - $mail->Sender = $this->sender; - $mail->FromName = $this->sender_name; - $mail->Subject = $this->subject; - - if(function_exists('mb_eregi_replace')) { - $this->message = mb_eregi_replace("\r\n", "\n", $this->message); - } - $mail->Body = $this->message; - - $sendmail = Config::get('sendmail_path'); - $sendmail = $sendmail ? $sendmail : '/usr/sbin/sendmail'; - $mailhost = Config::get('mail_host'); - $mailhost = $mailhost ? $mailhost : 'localhost'; - $mailport = Config::get('mail_port'); - $mailport = $mailport ? $mailport : 25; - $mailauth = Config::get('mail_auth'); - $mailuser = Config::get('mail_auth_user'); - $mailuser = $mailuser ? $mailuser : ''; - $mailpass = Config::get('mail_auth_pass'); - $mailpass = $mailpass ? $mailpass : ''; - - switch($mailtype) { - case 'smtp': - $mail->IsSMTP(); - $mail->Host = $mailhost; - $mail->Port = $mailport; - if($mailauth == true) { - $mail->SMTPAuth = true; - $mail->Username = $mailuser; - $mail->Password = $mailpass; - } - if ($mailsecure = Config::get('mail_secure_smtp')) { - $mail->SMTPSecure = ($mailsecure == 'ssl') ? 'ssl' : 'tls'; - } - break; - case 'sendmail': - $mail->IsSendmail(); - $mail->Sendmail = $sendmail; - break; - case 'php': - default: - $mail->IsMail(); - break; - } - - $retval = $mail->send(); - if( $retval == true ) { - return true; - } else { - return false; - } - } // send - - public function send_to_group($group_name) { - $mail = new PHPMailer(); - - foreach(self::get_users($group_name) as $member) { - if(function_exists('mb_encode_mimeheader')) { - $member['fullname'] = mb_encode_mimeheader($member['fullname']); - } - $mail->AddBCC($member['email'], $member['fullname']); - } - - return $this->send($mail); - } - -} // AmpacheMail class -?> diff --git a/lib/class/ampacherss.class.php b/lib/class/ampacherss.class.php deleted file mode 100644 index 02cc6477..00000000 --- a/lib/class/ampacherss.class.php +++ /dev/null @@ -1,253 +0,0 @@ -type = self::validate_type($type); - - } // constructor - - /** - * get_xml - * This returns the xmldocument for the current rss type, it calls a sub function that gathers the data - * and then uses the xmlDATA class to build the document - */ - public function get_xml() { - - // Function call name - $data_function = 'load_' . $this->type; - $pub_date_function = 'pubdate_' . $this->type; - - $data = call_user_func(array('AmpacheRSS',$data_function)); - $pub_date = call_user_func(array('AmpacheRSS',$pub_date_function)); - - xmlData::set_type('rss'); - $xml_document = xmlData::rss_feed($data,$this->get_title(),$this->get_description(),$pub_date); - - return $xml_document; - - } // get_xml - - /** - * get_title - * This returns the standardized title for the rss feed based on this->type - */ - public function get_title() { - - $titles = array('now_playing' => T_('Now Playing'), - 'recently_played' => T_('Recently Played'), - 'latest_album' => T_('Newest Albums'), - 'latest_artist' => T_('Newest Artists')); - - return scrub_out(Config::get('site_title')) . ' - ' . $titles[$this->type]; - - } // get_title - - /** - * get_description - * This returns the standardized description for the rss feed based on this->type - */ - public function get_description() { - - //FIXME: For now don't do any kind of translating - return 'Ampache RSS Feeds'; - - } // get_description - - /** - * validate_type - * this returns a valid type for an rss feed, if the specified type is invalid it returns a default value - */ - public static function validate_type($type) { - - $valid_types = array('now_playing','recently_played','latest_album','latest_artist','latest_song', - 'popular_song','popular_album','popular_artist'); - - if (!in_array($type,$valid_types)) { - return 'now_playing'; - } - - return $type; - - } // validate_type - - /** - * get_display - * This dumps out some html and an icon for the type of rss that we specify - */ - public static function get_display($type='now_playing') { - - // Default to now playing - $type = self::validate_type($type); - - $string = '' . get_user_icon('feed', T_('RSS Feed')) . ''; - - return $string; - - } // get_display - - // type specific functions below, these are called semi-dynamically based on the current type // - - /** - * load_now_playing - * This loads in the now playing information. This is just the raw data with key=>value pairs that could be turned - * into an xml document if we so wished - */ - public static function load_now_playing() { - - $data = Stream::get_now_playing(); - - $results = array(); - $format = Config::get('rss_format') ?: '%t - %a - %A'; - $string_map = array( - '%t' => 'title', - '%a' => 'artist', - '%A' => 'album' - ); - foreach ($data as $element) { - $song = $element['media']; - $client = $element['user']; - $title = $format; - $description = $format; - foreach($string_map as $search => $replace) { - $trep = 'f_' . $replace; - $drep = 'f_' . $replace . '_full'; - $title = str_replace($search, $song->$trep, $title); - $description = str_replace($search, $song->$drep, $description); - } - $xml_array = array( - 'title' => $title, - 'link' => $song->link, - 'description' => $description, - 'comments' => $client->fullname . ' - ' . $element['agent'], - 'pubDate' => date('r', $element['expire']) - ); - $results[] = $xml_array; - } // end foreach - - return $results; - - } // load_now_playing - - /** - * pubdate_now_playing - * this is the pub date we should use for the now playing information, - * this is a little specific as it uses the 'newest' expire we can find - */ - public static function pubdate_now_playing() { - - // Little redundent, should be fixed by an improvement in the get_now_playing stuff - $data = Stream::get_now_playing(); - - $element = array_shift($data); - - return $element['expire']; - - } // pubdate_now_playing - - /** - * load_recently_played - * This loads in the recently played information and formats it up real nice like - */ - public static function load_recently_played() { - - //FIXME: The time stuff should be centralized, it's currently in two places, lame - - $time_unit = array('', T_('seconds ago'), T_('minutes ago'), T_('hours ago'), T_('days ago'), T_('weeks ago'), T_('months ago'), T_('years ago')); - $data = Song::get_recently_played(); - - $results = array(); - - foreach ($data as $item) { - $client = new User($item['user']); - $song = new Song($item['object_id']); - $song->format(); - $amount = intval(time() - $item['date']+2); - $time_place = '0'; - while ($amount >= 1) { - $final = $amount; - $time_place++; - if ($time_place <= 2) { - $amount = floor($amount/60); - } - if ($time_place == '3') { - $amount = floor($amount/24); - } - if ($time_place == '4') { - $amount = floor($amount/7); - } - if ($time_place == '5') { - $amount = floor($amount/4); - } - if ($time_place == '6') { - $amount = floor ($amount/12); - } - if ($time_place > '6') { - $final = $amount . '+'; - break; - } - } // end while - - $time_string = $final . ' ' . $time_unit[$time_place]; - - $xml_array = array('title'=>$song->f_title . ' - ' . $song->f_artist . ' - ' . $song->f_album, - 'link'=>str_replace('&', '&', $song->link), - 'description'=>$song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full . ' - ' . $time_string, - 'comments'=>$client->username, - 'pubDate'=>date("r",$item['date'])); - $results[] = $xml_array; - - } // end foreach - - return $results; - - } // load_recently_played - - /** - * pubdate_recently_played - * This just returns the 'newest' recently played entry - */ - public static function pubdate_recently_played() { - - $data = Song::get_recently_played(); - - $element = array_shift($data); - - return $element['date']; - - } // pubdate_recently_played - -} // end AmpacheRSS class diff --git a/lib/class/api.class.php b/lib/class/api.class.php index 002eff2d..841d3534 100644 --- a/lib/class/api.class.php +++ b/lib/class/api.class.php @@ -204,7 +204,7 @@ class Api { $db_results = Dba::read($sql); $catalog = Dba::fetch_assoc($db_results); - echo xmlData::keyed_array(array('auth'=>$token, + echo XML_Data::keyed_array(array('auth'=>$token, 'api'=>self::$version, 'session_expire'=>date("c",time()+Config::get('session_length')-60), 'update'=>date("c",$row['update']), @@ -222,7 +222,7 @@ class Api { } // end while debug_event('API','Login Failed, unable to match passphrase','1'); - xmlData::error('401', T_('Error Invalid Handshake - ') . T_('Invalid Username/Password')); + XML_Data::error('401', T_('Error Invalid Handshake - ') . T_('Invalid Username/Password')); } // handshake @@ -244,7 +244,7 @@ class Api { debug_event('API','Ping Received from ' . $_SERVER['REMOTE_ADDR'] . ' :: ' . $input['auth'],'5'); ob_end_clean(); - echo xmlData::keyed_array($xmldata); + echo XML_Data::keyed_array($xmldata); } // ping @@ -266,13 +266,13 @@ class Api { Api::set_filter('update',$input['update']); // Set the offset - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); $artists = self::$browse->get_objects(); // echo out the resulting xml document ob_end_clean(); - echo xmlData::artists($artists); + echo XML_Data::artists($artists); } // artists @@ -284,7 +284,7 @@ class Api { public static function artist($input) { $uid = scrub_in($input['filter']); - echo xmlData::artists(array($uid)); + echo XML_Data::artists(array($uid)); } // artist @@ -299,10 +299,10 @@ class Api { $albums = $artist->get_albums(); // Set the offset - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::albums($albums); + echo XML_Data::albums($albums); } // artist_albums @@ -316,10 +316,10 @@ class Api { $songs = $artist->get_songs(); // Set the offset - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::songs($songs); + echo XML_Data::songs($songs); } // artist_songs @@ -340,10 +340,10 @@ class Api { $albums = self::$browse->get_objects(); // Set the offset - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::albums($albums); + echo XML_Data::albums($albums); } // albums @@ -354,7 +354,7 @@ class Api { public static function album($input) { $uid = scrub_in($input['filter']); - echo xmlData::albums(array($uid)); + echo XML_Data::albums(array($uid)); } // album @@ -368,11 +368,11 @@ class Api { $songs = $album->get_songs(); // Set the offset - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::songs($songs); + echo XML_Data::songs($songs); } // album_songs @@ -391,11 +391,11 @@ class Api { $tags = self::$browse->get_objects(); // Set the offset - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::tags($tags); + echo XML_Data::tags($tags); } // tags @@ -407,7 +407,7 @@ class Api { $uid = scrub_in($input['filter']); ob_end_clean(); - echo xmlData::tags(array($uid)); + echo XML_Data::tags(array($uid)); } // tag @@ -419,11 +419,11 @@ class Api { $artists = Tag::get_tag_objects('artist',$input['filter']); - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::artists($artists); + echo XML_Data::artists($artists); } // tag_artists @@ -435,11 +435,11 @@ class Api { $albums = Tag::get_tag_objects('album',$input['filter']); - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::albums($albums); + echo XML_Data::albums($albums); } // tag_albums @@ -451,11 +451,11 @@ class Api { $songs = Tag::get_tag_objects('song',$input['filter']); - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::songs($songs); + echo XML_Data::songs($songs); } // tag_songs @@ -477,11 +477,11 @@ class Api { $songs = self::$browse->get_objects(); // Set the offset - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::songs($songs); + echo XML_Data::songs($songs); } // songs @@ -494,7 +494,7 @@ class Api { $uid = scrub_in($input['filter']); ob_end_clean(); - echo xmlData::songs(array($uid)); + echo XML_Data::songs(array($uid)); } // song @@ -508,7 +508,7 @@ class Api { $song_id = Song::parse_song_url($input['url']); ob_end_clean(); - echo xmlData::songs(array($song_id)); + echo XML_Data::songs(array($song_id)); } // url_to_song @@ -527,11 +527,11 @@ class Api { $playlist_ids = self::$browse->get_objects(); - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::playlists($playlist_ids); + echo XML_Data::playlists($playlist_ids); } // playlists @@ -544,7 +544,7 @@ class Api { $uid = scrub_in($input['filter']); ob_end_clean(); - echo xmlData::playlists(array($uid)); + echo XML_Data::playlists(array($uid)); } // playlist @@ -563,10 +563,10 @@ class Api { } } // end foreach - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); ob_end_clean(); - echo xmlData::songs($songs); + echo XML_Data::songs($songs); } // playlist_songs @@ -582,12 +582,12 @@ class Api { ob_end_clean(); - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); $results = Search::run($array); - echo xmlData::songs($results); + echo XML_Data::songs($results); } // search_songs @@ -606,10 +606,10 @@ class Api { $video_ids = self::$browse->get_objects(); - xmlData::set_offset($input['offset']); - xmlData::set_limit($input['limit']); + XML_Data::set_offset($input['offset']); + XML_Data::set_limit($input['limit']); - echo xmlData::videos($video_ids); + echo XML_Data::videos($video_ids); } // videos @@ -621,7 +621,7 @@ class Api { $video_id = scrub_in($input['filter']); - echo xmlData::videos(array($video_id)); + echo XML_Data::videos(array($video_id)); } // video @@ -643,11 +643,11 @@ class Api { case 'stop': $result_status = $localplay->$input['command'](); $xml_array = array('localplay'=>array('command'=>array($input['command']=>make_bool($result_status)))); - echo xmlData::keyed_array($xml_array); + echo XML_Data::keyed_array($xml_array); break; default: // They are doing it wrong - echo xmlData::error('405', T_('Invalid Request')); + echo XML_Data::error('405', T_('Invalid Request')); break; } // end switch on command @@ -668,7 +668,7 @@ class Api { $type = 'song'; $media = new $type($input['oid']); if (!$media->id) { - echo xmlData::error('400', T_('Media Object Invalid or Not Specified')); + echo XML_Data::error('400', T_('Media Object Invalid or Not Specified')); break; } $democratic->add_vote(array( @@ -680,13 +680,13 @@ class Api { // If everything was ok $xml_array = array('action'=>$input['action'],'method'=>$input['method'],'result'=>true); - echo xmlData::keyed_array($xml_array); + echo XML_Data::keyed_array($xml_array); break; case 'devote': $type = 'song'; $media = new $type($input['oid']); if (!$media->id) { - echo xmlData::error('400', T_('Media Object Invalid or Not Specified')); + echo XML_Data::error('400', T_('Media Object Invalid or Not Specified')); } $uid = $democratic->get_uid_from_object_id($media->id,$type); @@ -694,21 +694,21 @@ class Api { // Everything was ok $xml_array = array('action'=>$input['action'],'method'=>$input['method'],'result'=>true); - echo xmlData::keyed_array($xml_array); + echo XML_Data::keyed_array($xml_array); break; case 'playlist': $objects = $democratic->get_items(); Song::build_cache($democratic->object_ids); Democratic::build_vote_cache($democratic->vote_ids); - xmlData::democratic($objects); + XML_Data::democratic($objects); break; case 'play': $url = $democratic->play_url(); $xml_array = array('url'=>$url); - echo xmlData::keyed_array($xml_array); + echo XML_Data::keyed_array($xml_array); break; default: - echo xmlData::error('405', T_('Invalid Request')); + echo XML_Data::error('405', T_('Invalid Request')); break; } // switch on method diff --git a/lib/class/registration.class.php b/lib/class/registration.class.php index 1544e01e..d22a23ab 100644 --- a/lib/class/registration.class.php +++ b/lib/class/registration.class.php @@ -43,7 +43,7 @@ class Registration { * This sends the confirmation e-mail for the specified user */ public static function send_confirmation($username, $fullname, $email, $password, $validation) { - $mailer = new AmpacheMail(); + $mailer = new Ampache_Mail(); // We are the system $mailer->set_default_sender(); diff --git a/lib/class/stream_playlist.class.php b/lib/class/stream_playlist.class.php index 0892386a..a8e66c62 100644 --- a/lib/class/stream_playlist.class.php +++ b/lib/class/stream_playlist.class.php @@ -338,14 +338,14 @@ class Stream_Playlist { $xml['track']['album'] = $url->album; } - $result .= xmlData::keyed_array($xml, true); + $result .= XML_Data::keyed_array($xml, true); } // end foreach - xmlData::set_type('xspf'); - echo xmlData::header(); + XML_Data::set_type('xspf'); + echo XML_Data::header(); echo $result; - echo xmlData::footer(); + echo XML_Data::footer(); } // create_xspf diff --git a/lib/class/xml_data.class.php b/lib/class/xml_data.class.php new file mode 100644 index 00000000..da3c98c2 --- /dev/null +++ b/lib/class/xml_data.class.php @@ -0,0 +1,659 @@ +" . self::_footer(); + return $string; + + } // error + + /** + * single_string + * + * This takes two values, first the key second the string + * + * @param string $key (description here...) + * @param string $string xml data + * @return string return xml + */ + public static function single_string($key,$string) { + + $final = self::_header() . "\t<$key>" . self::_footer(); + + return $final; + + } // single_string + + /** + * header + * + * This returns the header + * + * @see _header() + * @return string return xml + */ + public static function header() { + + return self::_header(); + + } // header + + /** + * footer + * + * This returns the footer + * + * @see _footer() + * @return string return xml + */ + public static function footer() { + + return self::_footer(); + + } // footer + + /** + * tags_string + * + * This returns the formatted 'tags' string for an xml document + * + */ + private static function tags_string($tags) { + + $string = ''; + + if (is_array($tags)) { + + foreach ($tags as $tag_id => $data) { + $tag = new Tag($tag_id); + $string .= "\tid . + '" count="' . count($data['users']) . + '">name . "]]>\n"; + } + } + + return $string; + + } // tags_string + + /** + * keyed_array + * + * This will build an xml document from a key'd array, + * + * @param array $array (description here...) + * @param boolean $callback (description here...) + * @return string return xml + */ + public static function keyed_array($array,$callback='') { + + $string = ''; + + // Foreach it + foreach ($array as $key=>$value) { + $attribute = ''; + // See if the key has attributes + if (is_array($value) AND isset($value[''])) { + $attribute = ' ' . $value['']; + $key = $value['value']; + } + + // If it's an array, run again + if (is_array($value)) { + $value = self::keyed_array($value,1); + $string .= "<$key$attribute>\n$value\n\n"; + } + else { + $string .= "\t<$key$attribute>\n"; + } + + } // end foreach + + if (!$callback) { + $string = self::_header() . $string . self::_footer(); + } + + return $string; + + } // keyed_array + + /** + * tags + * + * This returns tags to the user, in a pretty xml document with the information + * + * @param array $tags (description here...) + * @return string return xml + */ + public static function tags($tags) { + + if (count($tags) > self::$limit OR self::$offset > 0) { + $tags = array_splice($tags,self::$offset,self::$limit); + } + + $string = ''; + + foreach ($tags as $tag_id) { + $tag = new Tag($tag_id); + $counts = $tag->count(); + $string .= "\n" . + "\tname]]>\n" . + "\t" . intval($counts['album']) . "\n" . + "\t" . intval($counts['artist']) . "\n" . + "\t" . intval($counts['song']) . "\n" . + "\t" . intval($counts['video']) . "\n" . + "\t" . intval($count['playlist']) . "\n" . + "\t" . intval($count['live_stream']) . "\n" . + "\n"; + } // end foreach + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // tags + + /** + * artists + * + * This takes an array of artists and then returns a pretty xml document with the information + * we want + * + * @param array $artists (description here...) + * @return string return xml + */ + public static function artists($artists) { + + if (count($artists) > self::$limit OR self::$offset > 0) { + $artists = array_splice($artists,self::$offset,self::$limit); + } + + $string = ''; + + Rating::build_cache('artist',$artists); + + foreach ($artists as $artist_id) { + $artist = new Artist($artist_id); + $artist->format(); + + $rating = new Rating($artist_id,'artist'); + $tag_string = self::tags_string($artist->tags); + + $string .= "id\">\n" . + "\tf_full_name]]>\n" . + $tag_string . + "\t$artist->albums\n" . + "\t$artist->songs\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_average_rating() . "\n" . + "\n"; + } // end foreach artists + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // artists + + /** + * albums + * + * This echos out a standard albums XML document, it pays attention to the limit + * + * @param array $albums (description here...) + * @return string return xml + */ + public static function albums($albums) { + + if (count($albums) > self::$limit OR self::$offset > 0) { + $albums = array_splice($albums,self::$offset,self::$limit); + } + + Rating::build_cache('album',$albums); + + foreach ($albums as $album_id) { + $album = new Album($album_id); + $album->format(); + + $rating = new Rating($album_id,'album'); + + // Build the Art URL, include session + $art_url = Config::get('web_path') . '/image.php?id=' . $album->id . '&auth=' . scrub_out($_REQUEST['auth']); + + $string .= "id\">\n" . + "\tname]]>\n"; + + // Do a little check for artist stuff + if ($album->artist_count != 1) { + $string .= "\t\n"; + } + else { + $string .= "\tartist_id\">artist_name]]>\n"; + } + + $string .= "\t$album->year\n" . + "\t$album->song_count\n" . + "\t$album->disk\n" . + self::tags_string($album->tags) . + "\t\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_average_rating() . "\n" . + "\n"; + } // end foreach + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // albums + + /** + * playlists + * + * This takes an array of playlist ids and then returns a nice pretty XML document + * + * @param array $playlists (description here...) + * @return string return xml + */ + public static function playlists($playlists) { + + if (count($playlists) > self::$limit OR self::$offset > 0) { + $playlists = array_slice($playlists,self::$offset,self::$limit); + } + + $string = ''; + + // Foreach the playlist ids + foreach ($playlists as $playlist_id) { + $playlist = new Playlist($playlist_id); + $playlist->format(); + $item_total = $playlist->get_song_count(); + + // Build this element + $string .= "id\">\n" . + "\tname]]>\n" . + "\tf_user]]>\n" . + "\t$item_total\n" . + "\t$playlist->type\n" . + "\n"; + + + } // end foreach + + // Build the final and then send her off + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // playlists + + /** + * songs + * + * This returns an xml document from an array of song ids. + * (Spiffy isn't it!) + */ + public static function songs($songs) { + + if (count($songs) > self::$limit OR self::$offset > 0) { + $songs = array_slice($songs, self::$offset, self::$limit); + } + + Song::build_cache($songs); + Stream::set_session($_REQUEST['auth']); + + // Foreach the ids! + foreach ($songs as $song_id) { + $song = new Song($song_id); + + // If the song id is invalid/null + if (!$song->id) { continue; } + + $tag_string = self::tags_string(Tag::get_top_tags('song', $song_id)); + $rating = new Rating($song_id, 'song'); + $art_url = Art::url($song->album, 'album', $_REQUEST['auth']); + + $string .= "id\">\n" . + "\t<![CDATA[$song->title]]>\n" . + "\tartist . + '">get_artist_name() . + "]]>\n" . + "\talbum . + '">get_album_name(). + "]]>\n" . + $tag_string . + "\t$song->track\n" . + "\t\n" . + "\t$song->year\n" . + "\t$song->bitrate\n". + "\t$song->mode\n". + "\t$song->mime\n" . + "\tid) . "]]>\n" . + "\t$song->size\n". + "\t$song->mbid\n". + "\t$song->album_mbid\n". + "\t$song->artist_mbid\n". + "\t\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_average_rating() . "\n" . + "\n"; + + } // end foreach + + return self::_header() . $string . self::_footer(); + + } // songs + + /** + * videos + * + * This builds the xml document for displaying video objects + * + * @param array $videos (description here...) + * @return string return xml + */ + public static function videos($videos) { + + if (count($videos) > self::$limit OR self::$offset > 0) { + $videos = array_slice($videos,self::$offset,self::$limit); + } + + $string = ''; + + foreach ($videos as $video_id) { + $video = new Video($video_id); + $video->format(); + + $string .= "\n"; + + } // end foreach + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // videos + + /** + * democratic + * + * This handles creating an xml document for democratic items, this can be a little complicated + * due to the votes and all of that + * + * @param array $object_ids Object IDs + * @return string return xml + */ + public static function democratic($object_ids=array()) { + + if (!is_array($object_ids)) { $object_ids = array(); } + + $democratic = Democratic::get_current_playlist(); + + $string = ''; + + foreach ($object_ids as $row_id=>$data) { + $song = new $data['object_type']($data['object_id']); + $song->format(); + + //FIXME: This is duplicate code and so wrong, functions need to be improved + $tag_string = ''; + + $tag = new Tag($song->tags['0']); + $song->genre = $tag->id; + $song->f_genre = $tag->name; + + $tag_string = self::tags_string($song->tags); + + $rating = new Rating($song_id,'song'); + + $art_url = Art::url($song->album, 'album', $_REQUEST['auth']); + + $string .= "id\">\n" . + "\t<![CDATA[$song->title]]>\n" . + "\tartist\">f_artist_full]]>\n" . + "\talbum\">f_album_full]]>\n" . + "\tgenre\">f_genre]]>\n" . + $tag_string . + "\t$song->track\n" . + "\t\n" . + "\t$song->mime\n" . + "\tid) . "]]>\n" . + "\t$song->size\n" . + "\t\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_user_rating() . "\n" . + "\t" . $rating->get_average_rating() . "\n" . + "\t" . $democratic->get_vote($row_id) . "\n" . + "\n"; + + } // end foreach + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // democratic + + /** + * rss_feed + * + * (description here...) + * + * @param array $data (descriptiong here...) + * @param string $title RSS feed title + * @param string $description (not use yet?) + * @param string $date publish date + * @return string RSS feed xml + */ + public static function rss_feed($data,$title,$description,$date) { + + $string = "\t$title\n\t" . Config::get('web_path') . "\n\t" . + "" . date("r",$date) . "\n"; + + // Pass it to the keyed array xml function + foreach ($data as $item) { + // We need to enclose it in an item tag + $string .= self::keyed_array(array('item'=>$item),1); + } + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // rss_feed + + /** + * _header + * + * this returns a standard header, there are a few types + * so we allow them to pass a type if they want to + * + * @return string Header xml tag. + */ + private static function _header() { + + switch (self::$type) { + case 'xspf': + $header = "\n" . + "\n " . + "Ampache XSPF Playlist\n" . + "" . scrub_out(Config::get('site_title')) . "\n" . + "" . scrub_out(Config::get('site_title')) . "\n" . + "". Config::get('web_path') ."\n" . + "\n"; + break; + case 'itunes': + $header = "\n" . + "\n"; + "\n" . + "\n" . + "\n" . + " Major Version1\n" . + " Minor Version1\n" . + " Application Version7.0.2\n" . + " Features1\n" . + " Show Content Ratings\n" . + " Tracks\n" . + " \n"; + break; + case 'rss': + $header = "\n " . + "\n" . + "\n\n"; + break; + default: + $header = "\n\n"; + break; + } // end switch + + return $header; + + } // _header + + /** + * _footer + * + * this returns the footer for this document, these are pretty boring + * + * @return string Footer xml tag. + */ + private static function _footer() { + + switch (self::$type) { + case 'itunes': + $footer = "\t\t\t\n\n\n"; + break; + case 'xspf': + $footer = "\n\n"; + break; + case 'rss': + $footer = "\n\n\n"; + break; + default: + $footer = "\n\n"; + break; + } // end switch on type + + + return $footer; + + } // _footer + +} // XML_Data + +?> diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php deleted file mode 100644 index 96003964..00000000 --- a/lib/class/xmldata.class.php +++ /dev/null @@ -1,659 +0,0 @@ -" . self::_footer(); - return $string; - - } // error - - /** - * single_string - * - * This takes two values, first the key second the string - * - * @param string $key (description here...) - * @param string $string xml data - * @return string return xml - */ - public static function single_string($key,$string) { - - $final = self::_header() . "\t<$key>" . self::_footer(); - - return $final; - - } // single_string - - /** - * header - * - * This returns the header - * - * @see _header() - * @return string return xml - */ - public static function header() { - - return self::_header(); - - } // header - - /** - * footer - * - * This returns the footer - * - * @see _footer() - * @return string return xml - */ - public static function footer() { - - return self::_footer(); - - } // footer - - /** - * tags_string - * - * This returns the formatted 'tags' string for an xml document - * - */ - private static function tags_string($tags) { - - $string = ''; - - if (is_array($tags)) { - - foreach ($tags as $tag_id => $data) { - $tag = new Tag($tag_id); - $string .= "\tid . - '" count="' . count($data['users']) . - '">name . "]]>\n"; - } - } - - return $string; - - } // tags_string - - /** - * keyed_array - * - * This will build an xml document from a key'd array, - * - * @param array $array (description here...) - * @param boolean $callback (description here...) - * @return string return xml - */ - public static function keyed_array($array,$callback='') { - - $string = ''; - - // Foreach it - foreach ($array as $key=>$value) { - $attribute = ''; - // See if the key has attributes - if (is_array($value) AND isset($value[''])) { - $attribute = ' ' . $value['']; - $key = $value['value']; - } - - // If it's an array, run again - if (is_array($value)) { - $value = self::keyed_array($value,1); - $string .= "<$key$attribute>\n$value\n\n"; - } - else { - $string .= "\t<$key$attribute>\n"; - } - - } // end foreach - - if (!$callback) { - $string = self::_header() . $string . self::_footer(); - } - - return $string; - - } // keyed_array - - /** - * tags - * - * This returns tags to the user, in a pretty xml document with the information - * - * @param array $tags (description here...) - * @return string return xml - */ - public static function tags($tags) { - - if (count($tags) > self::$limit OR self::$offset > 0) { - $tags = array_splice($tags,self::$offset,self::$limit); - } - - $string = ''; - - foreach ($tags as $tag_id) { - $tag = new Tag($tag_id); - $counts = $tag->count(); - $string .= "\n" . - "\tname]]>\n" . - "\t" . intval($counts['album']) . "\n" . - "\t" . intval($counts['artist']) . "\n" . - "\t" . intval($counts['song']) . "\n" . - "\t" . intval($counts['video']) . "\n" . - "\t" . intval($count['playlist']) . "\n" . - "\t" . intval($count['live_stream']) . "\n" . - "\n"; - } // end foreach - - $final = self::_header() . $string . self::_footer(); - - return $final; - - } // tags - - /** - * artists - * - * This takes an array of artists and then returns a pretty xml document with the information - * we want - * - * @param array $artists (description here...) - * @return string return xml - */ - public static function artists($artists) { - - if (count($artists) > self::$limit OR self::$offset > 0) { - $artists = array_splice($artists,self::$offset,self::$limit); - } - - $string = ''; - - Rating::build_cache('artist',$artists); - - foreach ($artists as $artist_id) { - $artist = new Artist($artist_id); - $artist->format(); - - $rating = new Rating($artist_id,'artist'); - $tag_string = self::tags_string($artist->tags); - - $string .= "id\">\n" . - "\tf_full_name]]>\n" . - $tag_string . - "\t$artist->albums\n" . - "\t$artist->songs\n" . - "\t" . $rating->get_user_rating() . "\n" . - "\t" . $rating->get_user_rating() . "\n" . - "\t" . $rating->get_average_rating() . "\n" . - "\n"; - } // end foreach artists - - $final = self::_header() . $string . self::_footer(); - - return $final; - - } // artists - - /** - * albums - * - * This echos out a standard albums XML document, it pays attention to the limit - * - * @param array $albums (description here...) - * @return string return xml - */ - public static function albums($albums) { - - if (count($albums) > self::$limit OR self::$offset > 0) { - $albums = array_splice($albums,self::$offset,self::$limit); - } - - Rating::build_cache('album',$albums); - - foreach ($albums as $album_id) { - $album = new Album($album_id); - $album->format(); - - $rating = new Rating($album_id,'album'); - - // Build the Art URL, include session - $art_url = Config::get('web_path') . '/image.php?id=' . $album->id . '&auth=' . scrub_out($_REQUEST['auth']); - - $string .= "id\">\n" . - "\tname]]>\n"; - - // Do a little check for artist stuff - if ($album->artist_count != 1) { - $string .= "\t\n"; - } - else { - $string .= "\tartist_id\">artist_name]]>\n"; - } - - $string .= "\t$album->year\n" . - "\t$album->song_count\n" . - "\t$album->disk\n" . - self::tags_string($album->tags) . - "\t\n" . - "\t" . $rating->get_user_rating() . "\n" . - "\t" . $rating->get_user_rating() . "\n" . - "\t" . $rating->get_average_rating() . "\n" . - "\n"; - } // end foreach - - $final = self::_header() . $string . self::_footer(); - - return $final; - - } // albums - - /** - * playlists - * - * This takes an array of playlist ids and then returns a nice pretty XML document - * - * @param array $playlists (description here...) - * @return string return xml - */ - public static function playlists($playlists) { - - if (count($playlists) > self::$limit OR self::$offset > 0) { - $playlists = array_slice($playlists,self::$offset,self::$limit); - } - - $string = ''; - - // Foreach the playlist ids - foreach ($playlists as $playlist_id) { - $playlist = new Playlist($playlist_id); - $playlist->format(); - $item_total = $playlist->get_song_count(); - - // Build this element - $string .= "id\">\n" . - "\tname]]>\n" . - "\tf_user]]>\n" . - "\t$item_total\n" . - "\t$playlist->type\n" . - "\n"; - - - } // end foreach - - // Build the final and then send her off - $final = self::_header() . $string . self::_footer(); - - return $final; - - } // playlists - - /** - * songs - * - * This returns an xml document from an array of song ids. - * (Spiffy isn't it!) - */ - public static function songs($songs) { - - if (count($songs) > self::$limit OR self::$offset > 0) { - $songs = array_slice($songs, self::$offset, self::$limit); - } - - Song::build_cache($songs); - Stream::set_session($_REQUEST['auth']); - - // Foreach the ids! - foreach ($songs as $song_id) { - $song = new Song($song_id); - - // If the song id is invalid/null - if (!$song->id) { continue; } - - $tag_string = self::tags_string(Tag::get_top_tags('song', $song_id)); - $rating = new Rating($song_id, 'song'); - $art_url = Art::url($song->album, 'album', $_REQUEST['auth']); - - $string .= "id\">\n" . - "\t<![CDATA[$song->title]]>\n" . - "\tartist . - '">get_artist_name() . - "]]>\n" . - "\talbum . - '">get_album_name(). - "]]>\n" . - $tag_string . - "\t$song->track\n" . - "\t\n" . - "\t$song->year\n" . - "\t$song->bitrate\n". - "\t$song->mode\n". - "\t$song->mime\n" . - "\tid) . "]]>\n" . - "\t$song->size\n". - "\t$song->mbid\n". - "\t$song->album_mbid\n". - "\t$song->artist_mbid\n". - "\t\n" . - "\t" . $rating->get_user_rating() . "\n" . - "\t" . $rating->get_user_rating() . "\n" . - "\t" . $rating->get_average_rating() . "\n" . - "\n"; - - } // end foreach - - return self::_header() . $string . self::_footer(); - - } // songs - - /** - * videos - * - * This builds the xml document for displaying video objects - * - * @param array $videos (description here...) - * @return string return xml - */ - public static function videos($videos) { - - if (count($videos) > self::$limit OR self::$offset > 0) { - $videos = array_slice($videos,self::$offset,self::$limit); - } - - $string = ''; - - foreach ($videos as $video_id) { - $video = new Video($video_id); - $video->format(); - - $string .= "\n"; - - } // end foreach - - $final = self::_header() . $string . self::_footer(); - - return $final; - - } // videos - - /** - * democratic - * - * This handles creating an xml document for democratic items, this can be a little complicated - * due to the votes and all of that - * - * @param array $object_ids Object IDs - * @return string return xml - */ - public static function democratic($object_ids=array()) { - - if (!is_array($object_ids)) { $object_ids = array(); } - - $democratic = Democratic::get_current_playlist(); - - $string = ''; - - foreach ($object_ids as $row_id=>$data) { - $song = new $data['object_type']($data['object_id']); - $song->format(); - - //FIXME: This is duplicate code and so wrong, functions need to be improved - $tag_string = ''; - - $tag = new Tag($song->tags['0']); - $song->genre = $tag->id; - $song->f_genre = $tag->name; - - $tag_string = self::tags_string($song->tags); - - $rating = new Rating($song_id,'song'); - - $art_url = Art::url($song->album, 'album', $_REQUEST['auth']); - - $string .= "id\">\n" . - "\t<![CDATA[$song->title]]>\n" . - "\tartist\">f_artist_full]]>\n" . - "\talbum\">f_album_full]]>\n" . - "\tgenre\">f_genre]]>\n" . - $tag_string . - "\t$song->track\n" . - "\t\n" . - "\t$song->mime\n" . - "\tid) . "]]>\n" . - "\t$song->size\n" . - "\t\n" . - "\t" . $rating->get_user_rating() . "\n" . - "\t" . $rating->get_user_rating() . "\n" . - "\t" . $rating->get_average_rating() . "\n" . - "\t" . $democratic->get_vote($row_id) . "\n" . - "\n"; - - } // end foreach - - $final = self::_header() . $string . self::_footer(); - - return $final; - - } // democratic - - /** - * rss_feed - * - * (description here...) - * - * @param array $data (descriptiong here...) - * @param string $title RSS feed title - * @param string $description (not use yet?) - * @param string $date publish date - * @return string RSS feed xml - */ - public static function rss_feed($data,$title,$description,$date) { - - $string = "\t$title\n\t" . Config::get('web_path') . "\n\t" . - "" . date("r",$date) . "\n"; - - // Pass it to the keyed array xml function - foreach ($data as $item) { - // We need to enclose it in an item tag - $string .= self::keyed_array(array('item'=>$item),1); - } - - $final = self::_header() . $string . self::_footer(); - - return $final; - - } // rss_feed - - /** - * _header - * - * this returns a standard header, there are a few types - * so we allow them to pass a type if they want to - * - * @return string Header xml tag. - */ - private static function _header() { - - switch (self::$type) { - case 'xspf': - $header = "\n" . - "\n " . - "Ampache XSPF Playlist\n" . - "" . scrub_out(Config::get('site_title')) . "\n" . - "" . scrub_out(Config::get('site_title')) . "\n" . - "". Config::get('web_path') ."\n" . - "\n"; - break; - case 'itunes': - $header = "\n" . - "\n"; - "\n" . - "\n" . - "\n" . - " Major Version1\n" . - " Minor Version1\n" . - " Application Version7.0.2\n" . - " Features1\n" . - " Show Content Ratings\n" . - " Tracks\n" . - " \n"; - break; - case 'rss': - $header = "\n " . - "\n" . - "\n\n"; - break; - default: - $header = "\n\n"; - break; - } // end switch - - return $header; - - } // _header - - /** - * _footer - * - * this returns the footer for this document, these are pretty boring - * - * @return string Footer xml tag. - */ - private static function _footer() { - - switch (self::$type) { - case 'itunes': - $footer = "\t\t\t\n\n\n"; - break; - case 'xspf': - $footer = "\n\n"; - break; - case 'rss': - $footer = "\n\n\n"; - break; - default: - $footer = "\n\n"; - break; - } // end switch on type - - - return $footer; - - } // _footer - -} // xmlData - -?> diff --git a/lostpassword.php b/lostpassword.php index a7fbd3e5..c5deb98b 100644 --- a/lostpassword.php +++ b/lostpassword.php @@ -54,7 +54,7 @@ function send_newpassword($email,$current_ip){ $newpassword = generate_password(6); $client->update_password($newpassword); - $mailer = new AmpacheMail(); + $mailer = new Ampache_Mail(); $mailer->set_default_sender(); $mailer->subject = T_("Lost Password"); $mailer->recipient_name = $client->fullname; diff --git a/rss.php b/rss.php index 195efda9..d1387e2a 100644 --- a/rss.php +++ b/rss.php @@ -32,7 +32,7 @@ if (!Config::get('use_rss') || Config::get('demo_mode')) { // Add in our base hearder defining the content type header("Content-Type: application/xml; charset=" . Config::get('site_charset')); -$rss = new AmpacheRSS($_REQUEST['type']); +$rss = new Ampache_RSS($_REQUEST['type']); echo $rss->get_xml(); ?> diff --git a/server/xml.server.php b/server/xml.server.php index bd13af57..4dfc124d 100644 --- a/server/xml.server.php +++ b/server/xml.server.php @@ -40,7 +40,7 @@ header("Content-Disposition: attachment; filename=information.xml"); if (!Config::get('access_control')) { ob_end_clean(); debug_event('Access Control','Error Attempted to use XML API with Access Control turned off','3'); - echo xmlData::error('501', T_('Access Control not Enabled')); + echo XML_Data::error('501', T_('Access Control not Enabled')); exit; } @@ -51,7 +51,7 @@ if (!Config::get('access_control')) { if (!vauth::session_exists('api', $_REQUEST['auth']) AND $_REQUEST['action'] != 'handshake' AND $_REQUEST['action'] != 'ping') { debug_event('Access Denied','Invalid Session attempt to API [' . $_REQUEST['action'] . ']','3'); ob_end_clean(); - echo xmlData::error('401', T_('Session Expired')); + echo XML_Data::error('401', T_('Session Expired')); exit(); } @@ -62,7 +62,7 @@ $username = ($_REQUEST['action'] == 'handshake' || $_REQUEST['action'] == 'ping' if (!Access::check_network('init-api',$username,'5')) { debug_event('Access Denied','Unauthorized access attempt to API [' . $_SERVER['REMOTE_ADDR'] . ']', '3'); ob_end_clean(); - echo xmlData::error('403', T_('Unauthorized access attempt to API - ACL Error')); + echo XML_Data::error('403', T_('Unauthorized access attempt to API - ACL Error')); exit(); } @@ -93,4 +93,4 @@ foreach ($methods as $method) { // If we manage to get here, we still need to hand out an XML document ob_end_clean(); -echo xmlData::error('405', T_('Invalid Request')); +echo XML_Data::error('405', T_('Invalid Request')); diff --git a/templates/show_now_playing.inc.php b/templates/show_now_playing.inc.php index dfa55f8d..6b3c985b 100644 --- a/templates/show_now_playing.inc.php +++ b/templates/show_now_playing.inc.php @@ -28,7 +28,7 @@ */ if (count($results)) { -$link = Config::get('use_rss') ? ' ' . AmpacheRSS::get_display('nowplaying') : ''; +$link = Config::get('use_rss') ? ' ' . Ampache_RSS::get_display('nowplaying') : ''; ?> -- cgit