_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) { $sql = "SELECT * FROM `user_shout` WHERE `id` = ?"; $db_results = Dba::read($sql, array($shout_id)); $data = Dba::fetch_assoc($db_results); foreach ($data as $key=>$value) { $this->$key = $value; } return true; } // _get_info /** * gc * * Cleans out orphaned shoutbox items */ public static function gc() { foreach (array('song', 'album', 'artist') as $object_type) { Dba::write("DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `$object_type` ON `$object_type`.`id` = `user_shout`.`object_id` WHERE `$object_type`.`id` IS NULL AND `user_shout`.`object_type` = '$object_type'"); } } /** * 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($shouts,0,$limit); 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::read($sql); while ($row = Dba::fetch_assoc($db_results)) { $shouts[] = $row['id']; } return $shouts; } // get_top public static function get_shouts_since($time) { $sql = "SELECT * FROM `user_shout` WHERE `date` > ? ORDER BY `date` DESC"; $db_results = Dba::read($sql, array($time)); $shouts = array(); while ($row = Dba::fetch_assoc($db_results)) { $shouts[] = $row['id']; } return $shouts; } /** * 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::read($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 associated with it */ public function get_image() { switch ($this->object_type) { case 'album': $image_string = ""; break; case 'artist': break; case 'song': $song = new Song($this->object_id); $image_string = ""; 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) { $sticky = isset($data['sticky']) ? 1 : 0; $sql = "INSERT INTO `user_shout` (`user`,`date`,`text`,`sticky`,`object_id`,`object_type`, `data`) " . "VALUES (? , ?, ?, ?, ?, ?, ?)"; $db_results = Dba::write($sql, array($GLOBALS['user']->id, time(), strip_tags($data['comment']), $sticky, $data['object_id'], $data['object_type'], $data['data'])); $insert_id = Dba::insert_id(); return $insert_id; } // create /** * update * This takes a key'd array of data as input and updates a shoutbox entry */ public static function update($data) { $id = Dba::escape($data['shout_id']); $text = Dba::escape(strip_tags($data['comment'])); $sticky = make_bool($data['sticky']); $sql = "UPDATE `user_shout` SET `text`='$text', `sticky`='$sticky' WHERE `id`='$id'"; $db_results = Dba::write($sql); return true; } // create /** * format * this function takes the object and reformats some values */ public function format() { $this->sticky = ($this->sticky == "0") ? 'No' : 'Yes'; $this->date = date("m\/d\/Y - H:i", $this->date); return true; } //format /** * delete * this function deletes a specific shoutbox entry */ public function delete($shout_id) { // Delete the shoutbox post $shout_id = Dba::escape($shout_id); $sql = "DELETE FROM `user_shout` WHERE `id`='$shout_id'"; $db_results = Dba::write($sql); } // delete public function get_display($jsbuttons = false) { $object = Shoutbox::get_object($this->object_type, $this->object_id); $object->format(); $user = new User($this->user); $user->format(); $img = $this->get_image(); $html = "
"; $html .= "
"; if ($img) { $html .= "
" . $img . "
"; } $html .= "
"; $html .= "
" . $object->f_link . "
"; $html .= "
".date("Y/m/d H:i:s", $this->date) . "
"; $html .= "
" . preg_replace('/(\r\n|\n|\r)/', '
', $this->text) . "
"; $html .= "
"; $html .= "
"; $html .= ""; $html .= "
"; return $html; } public static function get_shouts($object_type, $object_id) { $sql = "SELECT `id` FROM `user_shout` WHERE `object_type` = ? AND `object_id` = ? ORDER BY `sticky`, `date` DESC"; $db_results = Dba::read($sql, array($object_type, $object_id)); $results = array(); while ($row = Dba::fetch_assoc($db_results)) { $results[] = $row['id']; } return $results; } } // Shoutbox class