diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-12-17 05:26:11 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-12-17 05:26:11 +0000 |
commit | 8448a0fc84ba25e6fd949b8162e3d1c96948d808 (patch) | |
tree | f25ba419b76412d0d072e9e9c9ffa7cbbfb36885 /lib/class/shoutbox.class.php | |
parent | d23122dffafa40415b1496c240ebd0b27619ef0f (diff) | |
download | ampache-8448a0fc84ba25e6fd949b8162e3d1c96948d808.tar.gz ampache-8448a0fc84ba25e6fd949b8162e3d1c96948d808.tar.bz2 ampache-8448a0fc84ba25e6fd949b8162e3d1c96948d808.zip |
added shoutbox functionality, only linked from song and album right now also interface for adding could use some improvement and also needs some management stuff to remove stickies etc
Diffstat (limited to 'lib/class/shoutbox.class.php')
-rw-r--r-- | lib/class/shoutbox.class.php | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/lib/class/shoutbox.class.php b/lib/class/shoutbox.class.php new file mode 100644 index 00000000..3cea772b --- /dev/null +++ b/lib/class/shoutbox.class.php @@ -0,0 +1,177 @@ +<?php +/* + + Copyright (c) 2001 - 2007 Ampache.org + All rights reserved. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License v2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +class shoutBox { + + public $id; + + /** + * Constructor + * This pulls the shoutbox information from the database and returns + * a constructed object, uses user_shout table + */ + public function __construct($shout_id) { + + // Load the data from the database + $this->_get_info($shout_id); + + return true; + + } // Constructor + + /** + * _get_info + * does the db call, reads from the user_shout table + */ + private function _get_info($shout_id) { + + $sticky_id = Dba::escape($shout_id); + + $sql = "SELECT * FROM `user_shout` WHERE `id`='$shout_id'"; + $db_results = Dba::query($sql); + + $data = Dba::fetch_assoc($db_results); + + foreach ($data as $key=>$value) { + $this->$key = $value; + } + + return true; + + } // _get_info + + /** + * get_top + * This returns the top user_shouts, shoutbox objects are always shown regardless and count against the total + * number of objects shown + */ + public static function get_top($limit) { + + $shouts = self::get_sticky(); + + // If we've already got too many stop here + if (count($shouts) > $limit) { + $shouts = array_slice(0,$limit,$shouts); + return $shouts; + } + + // Only get as many as we need + $limit = intval($limit) - count($shouts); + $sql = "SELECT * FROM `user_shout` WHERE `sticky`='0' ORDER BY `date` DESC LIMIT $limit"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $shouts[] = $row['id']; + } + + return $shouts; + + } // get_top + + /** + * get_sticky + * This returns all current sticky shoutbox items + */ + public static function get_sticky() { + + $sql = "SELECT * FROM `user_shout` WHERE `sticky`='1' ORDER BY `date` DESC"; + $db_results = Dba::query($sql); + + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } + + return $results; + + } // get_sticky + + /** + * get_object + * This takes a type and an ID and returns a created object + */ + public static function get_object($type,$object_id) { + + $allowed_objects = array('song','genre','album','artist','radio'); + + if (!in_array($type,$allowed_objects)) { + return false; + } + + $object = new $type($object_id); + + return $object; + + } // get_object + + /** + * get_image + * This returns an image tag if the type of object we're currently rolling with + * has an image assoicated with it + */ + public function get_image() { + + switch ($this->object_type) { + case 'album': + $image_string = "<img height=\"75\" width=\"75\" src=\"" . Config::get('web_path') . "/image.php?id=" . $this->object_id . "&thumb=1\" />"; + break; + case 'artist': + + break; + case 'song': + $song = new Song($this->object_id); + $image_string = "<img height=\"75\" width=\"75\" src=\"" . Config::get('web_path') . "/image.php?id=" . $song->album . "&thumb=1\" />"; + break; + default: + // Rien a faire + break; + } // end switch + + return $image_string; + + } // get_image + + /** + * create + * This takes a key'd array of data as input and inserts a new shoutbox entry, it returns the auto_inc id + */ + public static function create($data) { + + $user = Dba::escape($GLOBALS['user']->id); + $text = Dba::escape(strip_tags($data['comment'])); + $date = time(); + $sticky = make_bool($data['sticky']); + $object_id = Dba::escape($data['object_id']); + $object_type = Dba::escape($data['object_type']); + + $sql = "INSERT INTO `user_shout` (`user`,`date`,`text`,`sticky`,`object_id`,`object_type`) " . + "VALUES ('$user','$date','$text','$sticky','$object_id','$object_type')"; + $db_results = Dba::query($sql); + + $insert_id = Dba::insert_id(); + + return $insert_id; + + } // create + +} // shoutBox class +?> |