diff options
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/album.class.php | 54 | ||||
-rw-r--r-- | lib/class/artist.class.php | 44 | ||||
-rw-r--r-- | lib/class/browse.class.php | 91 | ||||
-rw-r--r-- | lib/class/dba.class.php | 35 | ||||
-rw-r--r-- | lib/class/localplay.abstract.php | 2 | ||||
-rw-r--r-- | lib/class/rating.class.php | 55 | ||||
-rw-r--r-- | lib/class/song.class.php | 143 | ||||
-rw-r--r-- | lib/class/tagcloud.class.php | 193 | ||||
-rw-r--r-- | lib/class/update.class.php | 33 | ||||
-rw-r--r-- | lib/class/user.class.php | 22 |
10 files changed, 380 insertions, 292 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php index eef95831..87964a58 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -24,7 +24,7 @@ * This is the class responsible for handling the Album object * it is related to the album table in the database. */ -class Album { +class Album extends database_object { /* Variables from DB */ public $id; @@ -50,12 +50,13 @@ class Album { * pull the album or thumb art by default or * get any of the counts. */ - public function __construct($album_id='') { + public function __construct($id='') { + + if (!$id) { return false; } - if (!$album_id) { return false; } /* Assign id for use in get_info() */ - $this->id = intval($album_id); + $this->id = intval($id); /* Get the information from the db */ $info = $this->_get_info(); @@ -70,7 +71,7 @@ class Album { return true; - } //constructor + } // constructor /** * construct_from_array @@ -90,31 +91,46 @@ class Album { return $album; } // construct_from_array - public static function build_cache($ids, $fields='*') { - $idlist = '(' . implode(',', $ids) . ')'; - $sql = "SELECT $fields FROM album WHERE id in $idlist"; - $db_results = Dba::query($sql); - global $album_cache; - $album_cache = array(); - while ($results = Dba::fetch_assoc($db_results)) { - $album_cache[intval($results['id'])] = $results; - } - } + + /** + * build_cache + * This takes an array of object ids and caches all of their information + * with a single query + */ + public static function build_cache($ids) { + $idlist = '(' . implode(',', $ids) . ')'; + + $sql = "SELECT * FROM `album` WHERE `id` IN $idlist"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('album',$row['id'],$row); + } + + } // build_cache + /** * _get_info * This is a private function that pulls the album * from the database */ private function _get_info() { - global $album_cache; - if (isset($album_cache[intval($this->id)])) - return $album_cache[intval($this->id)]; + + $id = intval($this->id); + + if (parent::is_cached('album',$id)) { + return parent::get_from_cache('album',$id); + } + // Just get the album information - $sql = "SELECT * FROM `album` WHERE `id`='" . $this->id . "'"; + $sql = "SELECT * FROM `album` WHERE `id`='$id'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); + // Cache the object + parent::add_to_cache('album',$id,$results); + return $results; } // _get_info diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php index 73d5bef7..f5591018 100644 --- a/lib/class/artist.class.php +++ b/lib/class/artist.class.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2008 Ampache.org + Copyright (c) Ampache.org All rights reserved. This program is free software; you can redistribute it and/or @@ -22,7 +22,7 @@ /** * Artist Class */ -class Artist { +class Artist extends database_object { /* Variables from DB */ public $id; @@ -76,30 +76,42 @@ class Artist { return $artist; } // construct_from_array - public static function build_cache($ids, $fields='*') { - $idlist = '(' . implode(',', $ids) . ')'; - $sql = "SELECT $fields FROM artist WHERE id in $idlist"; - $db_results = Dba::query($sql); - global $artist_cache; - $artist_cache = array(); - while ($results = Dba::fetch_assoc($db_results)) { - $artist_cache[intval($results['id'])] = $results; - } - } + + /** + * this attempts to build a cache of the data from the passed albums all in one query + */ + public static function build_cache($ids) { + $idlist = '(' . implode(',', $ids) . ')'; + + $sql = "SELECT * FROM `artist` WHERE `id` IN $idlist"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('artist',$row['id'],$row); + } + + } // build_cache + /** * _get_info * get's the vars for $this out of the database taken from the object */ private function _get_info() { - global $artist_cache; - if (isset($artist_cache[intval($this->id)])) - return $artist_cache[intval($this->id)]; + + $id = intval($this->id); + + if (parent::is_cached('artist',$id)) { + return parent::get_from_cache('artist',$id); + } + /* Grab the basic information from the catalog and return it */ - $sql = "SELECT * FROM artist WHERE id='" . Dba::escape($this->id) . "'"; + $sql = "SELECT * FROM artist WHERE id='$id'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); + parent::add_to_cache('artist',$id,$results); + return $results; } // _get_info diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php index 0afbf8f7..1d0f3db4 100644 --- a/lib/class/browse.class.php +++ b/lib/class/browse.class.php @@ -72,19 +72,20 @@ class Browse { } break; case 'tag': - //var_dump($value); - if (is_array($value)) - $_SESSION['browse']['filter'][$key] = $value; - else if (is_numeric($value)) - $_SESSION['browse']['filter'][$key] = - array($value); - else - $_SESSION['browse']['filter'][$key] = array(); - break; - case 'artist': - case 'album': - $_SESSION['browse']['filter'][$key] = $value; - break; + if (is_array($value)) { + $_SESSION['browse']['filter'][$key] = $value; + } + elseif (is_numeric($value)) { + $_SESSION['browse']['filter'][$key] = array($value); + } + else { + $_SESSION['browse']['filter'][$key] = array(); + } + break; + case 'artist': + case 'album': + $_SESSION['browse']['filter'][$key] = $value; + break; case 'min_count': case 'unplayed': @@ -93,7 +94,6 @@ class Browse { break; case 'alpha_match': if (self::$static_content) { return false; } - //if ($value == _('All')) { $value = ''; } $_SESSION['browse']['filter'][$key] = $value; break; case 'playlist_type': @@ -364,9 +364,10 @@ class Browse { $db_results = Dba::query($sql); $results = array(); - while ($data = Dba::fetch_assoc($db_results)) - $results[] = $data; - var_dump($results); + while ($data = Dba::fetch_assoc($db_results)) { + $results[] = $data; + } + $results = self::post_process($results); $filtered = array(); foreach ($results as $data) { @@ -506,25 +507,40 @@ class Browse { $order_sql = rtrim($order_sql,","); $sql = $sql . $order_sql; - var_dump($sql); return $sql; } // get_sql - private static function post_process($results) - { - $tags = $_SESSION['browse']['filter']['tag']; - if (!is_array($tags) || sizeof($tags) < 2) - return $results; - $cnt = sizeof($tags); - $ar = array(); - foreach($results as $row) - $ar[$row['id']]++; - $res = array(); - foreach($ar as $k=>$v) - if ($v >= $cnt) - $res[] = array('id' => $k); - return $res; - } + + /** + * post_process + * This does some additional work on the results that we've received before returning them + */ + private static function post_process($results) { + + $tags = $_SESSION['browse']['filter']['tag']; + + if (!is_array($tags) || sizeof($tags) < 2) { + return $results; + } + $cnt = sizeof($tags); + $ar = array(); + + foreach($results as $row) { + $ar[$row['id']]++; + } + + $res = array(); + + foreach($ar as $k=>$v) { + if ($v >= $cnt) { + $res[] = array('id' => $k); + } + } // end foreach + + return $res; + + } // post_process + /** * sql_filter * This takes a filter name and value and if it is possible @@ -540,7 +556,6 @@ class Browse { || $_SESSION['browse']['type'] == 'artist' || $_SESSION['browse']['type'] == 'album' )) { - //var_dump($value); if (is_array($value) && sizeof($value)) $vals = '(' . implode(',',$value) . ')'; else if (is_integer($value)) @@ -796,7 +811,6 @@ class Browse { // Load any additional object we need for this $extra_objects = self::get_supplemental_objects(); - var_dump($object_ids); foreach ($extra_objects as $class_name => $id) { ${$class_name} = new $class_name($id); } @@ -805,11 +819,10 @@ class Browse { if (!$ajax && in_array($_SESSION['browse']['type'], array('artist','album','song'))) { $tagcloudHead = "Matching tags"; - $tagcloudList = - TagCloud::get_tags($_SESSION['browse']['type'], $all_ids); + $tagcloudList = TagCloud::get_tags($_SESSION['browse']['type'], $all_ids); require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php'; } - Dba::show_profile(); + Ajax::start_container('browse_content'); // Switch on the type of browsing we're doing switch ($_SESSION['browse']['type']) { @@ -965,11 +978,9 @@ class Browse { public static function set_filter_from_request($r) { - //var_dump($r); foreach ($r as $k=>$v) { //reinterpret v as a list of int $vl = explode(',', $v); - //var_dump($vl); $ok = 1; foreach($vl as $i) { if (!is_numeric($i)) { diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php index 6515b71f..a4685f21 100644 --- a/lib/class/dba.class.php +++ b/lib/class/dba.class.php @@ -32,8 +32,9 @@ if (INIT_LOADED != '1') { exit; } */ class Dba { - private static $_default_db; + public static $stats = array('query'=>0); + private static $_default_db; private static $_sql; private static $config; @@ -53,16 +54,14 @@ class Dba { * The mysql_query function */ public static function query($sql) { - /*if ($_REQUEST['profiling']) { - $sql = rtrim($sql, '; '); - $sql .= ' SQL_NO_CACHE'; - }*/ + // Run the query $resource = mysql_query($sql,self::dbh()); debug_event('Query',$sql,'6'); // Save the query, to make debug easier self::$_sql = $sql; + self::$stats['query']++; return $resource; @@ -200,17 +199,23 @@ class Dba { } // _connect + /** + * show_profile + * This function is used for debug, helps with profiling + */ public static function show_profile() { - if ($_REQUEST['profiling']) { - print '<br/>Profiling data: <br/>'; - $res = Dba::query('show profiles'); - print '<table>'; - while ($r = Dba::fetch_row($res)) { - print '<tr><td>' . implode('</td><td>', $r) . '</td></tr>'; - } - print '</table>'; - } - } + + if (Config::get('sql_profiling')) { + print '<br/>Profiling data: <br/>'; + $res = Dba::query('show profiles'); + print '<table>'; + while ($r = Dba::fetch_row($res)) { + print '<tr><td>' . implode('</td><td>', $r) . '</td></tr>'; + } + print '</table>'; + } + } // show_profile + /** * dbh * This is called by the class to return the database handle diff --git a/lib/class/localplay.abstract.php b/lib/class/localplay.abstract.php index 9eebdbe2..49fc85db 100644 --- a/lib/class/localplay.abstract.php +++ b/lib/class/localplay.abstract.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2007 Ampache.org + Copyright (c) Ampache.org All Rights Reserved This program is free software; you can redistribute it and/or diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 0519672e..086084ea 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -24,7 +24,7 @@ * This is an amalgamation(sp?) of code from SoundOfEmotion * to track ratings for songs, albums and artists. */ -class Rating { +class Rating extends database_object { /* Provided vars */ var $id; // The ID of the object who's ratings we want to pull @@ -56,31 +56,56 @@ class Rating { return true; } // Constructor + + /** + * build_cache + * This attempts to get everything we'll need for this page load in a single query, saving + * the connection overhead + * //FIXME: Improve logic so that misses get cached as average + */ public static function build_cache($type, $ids) { - $idlist = '(' . implode(',', $ids) . ')'; - $sql = "SELECT `rating`, object_id FROM `rating` WHERE `user`='$user_id' AND `object_id` in $idlist AND `object_type`='$type'"; - global $rating_cache; - $rating_cache = array(); - $db_results = Dba::query($sql); - while ($results = Dba::fetch_assoc($db_results)) { - $rating_cache[intval($results['object_id'])] = $results; - } - } + + $user_id = Dba::escape($GLOBALS['user']->id); + + $idlist = '(' . implode(',', $ids) . ')'; + $sql = "SELECT `rating`, `object_id` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . + "AND `object_type`='$type'"; + $db_results = Dba::query($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $rating[$row['id']] = $row['rating']; + } + + $user_cache_name = 'rating_' . $type . '_user'; + + foreach ($ids as $id) { + parent::add_to_cache($user_cache_name,$id,intval($rating[$id])); + } // end foreach + + + } // build_cache + /** * get_user * Get the user's rating this is based off the currently logged * in user. It returns the value */ public function get_user($user_id) { - global $rating_cache; - if (isset($rating_cache[intval($this->id)])); - return $rating_cache[intval($this->id)]['rating']; - $user_id = Dba::escape($user_id); + + $id = intval($this->id); - $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'"; + if (parent::is_cached('rating_' . $this->type . '_user',$id)) { + return parent::get_from_cache('rating_' . $this->type . '_user',$id); + } + + $user_id = Dba::escape($user_id); + + $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$id' AND `object_type`='$this->type'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); + + parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']); return $results['rating']; diff --git a/lib/class/song.class.php b/lib/class/song.class.php index ef2bfd8e..1fa696ef 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -19,7 +19,7 @@ */ -class Song { +class Song extends database_object { /* Variables from DB */ public $id; @@ -52,11 +52,11 @@ class Song { */ public function __construct($id='') { + if (!$id) { return false; } + /* Assign id for use in get_info() */ $this->id = intval($id); - if (!$this->id) { return false; } - /* Get the information from the db */ if ($info = $this->_get_info()) { @@ -70,65 +70,60 @@ class Song { return true; } // constructor - public static function build_cache($ids) - { - $idlist = '(' . implode(',', $ids) . ')'; - - // Song data cache - $sql = "SELECT song.id,file,catalog,album,year,artist,". - "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,". - "addition_time FROM `song` WHERE `song`.`id` in - $idlist"; - $db_results = Dba::query($sql); - global $song_cache; - $song_cache = array(); - while ($results = Dba::fetch_assoc($db_results)) - { - $song_cache[intval($results['id'])] = $results; - } + + /** + * build_cache + * This attempts to reduce # of queries by asking for everything in the browse + * all at once and storing it in the cache, this can help if the db connection + * is the slow point + */ + public static function build_cache($song_ids) { + + $idlist = '(' . implode(',', $song_ids) . ')'; - // Extra sound data cache - global $song_data_cache; - $song_data_cache = array(); - $sql = "SELECT * FROM song_data WHERE song_id in $idlist"; - $db_results = Dba::query($sql); - while ($results = Dba::fetch_assoc($db_results)) - { - $song_data_cache[intval($results['song_id'])] = $results; - } + // Song data cache + $sql = "SELECT song.id,file,catalog,album,year,artist,". + "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,". + "addition_time FROM `song` WHERE `song`.`id` IN + $idlist"; + $db_results = Dba::query($sql); - // Get all artist, album, genre ids. - $artists = array(); - $albums = array(); - $genre = array(); - foreach ($song_cache as $i) - { - $artists[$i['artist']] = 1; - $albums[$i['album']] = 1; - $genre[$i['genre']] = 1; - } - Artist::build_cache(array_keys($artists), 'id,name'); - Album::build_cache(array_keys($albums), 'id,name'); - Genre::build_cache(array_keys($genre), 'id,name'); - } - /*! - @function _get_info - @discussion get's the vars for $this out of the database - @param $this->id Taken from the object - */ + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('song',$row['id'],$row); + $artists[$row['artist']] = $row['artist']; + $albums[$row['album']] = $row['album']; + } + + Artist::build_cache($artists); + Album::build_cache($albums); + + return true; + + } // build_cache + + /** + * _get_info + * get's the vars for $this out of the database + * Taken from the object + */ private function _get_info() { - global $song_cache; - if (isset($song_cache[intval($this->id)])) - return $song_cache[intval($this->id)]; + + $id = intval($this->id); + + if (parent::is_cached('song',$id)) { + return parent::get_from_cache('song',$id); + } + /* Grab the basic information from the catalog and return it */ $sql = "SELECT song.id,file,catalog,album,year,artist,". "title,bitrate,rate,mode,size,time,track,genre,played,song.enabled,update_time,". - "addition_time FROM `song` WHERE `song`.`id` = '$this->id'"; - + "addition_time FROM `song` WHERE `song`.`id` = '$id'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); + parent::add_to_cache('song',$id,$results); + return $results; } // _get_info @@ -225,28 +220,11 @@ class Song { } // format_type - /*! - @function get_album_songs - @discussion gets an array of song objects based on album - */ - function get_album_songs($album_id) { - - $sql = "SELECT id FROM song WHERE album='$album_id'"; - $db_results = mysql_query($sql, dbh()); - - while ($r = mysql_fetch_object($db_results)) { - $results[] = new Song($r->id); - } - - return $results; - - } // get_album_songs - /** * get_album_name * gets the name of $this->album, allows passing of id */ - function get_album_name($album_id=0) { + public function get_album_name($album_id=0) { if (!$album_id) { $album_id = $this->album; } $album = new Album($album_id); if ($album->prefix) @@ -259,7 +237,7 @@ class Song { * get_artist_name * gets the name of $this->artist, allows passing of id */ - function get_artist_name($artist_id=0) { + public function get_artist_name($artist_id=0) { if (!$artist_id) { $artist_id = $this->artist; } $artist = new Artist($artist_id); @@ -275,7 +253,7 @@ class Song { * gets the name of the genre, allow passing of a specified * id */ - function get_genre_name($genre_id=0) { + public function get_genre_name($genre_id=0) { if (!$genre_id) { $genre_id = $this->genre; } $genre = new Genre($genre_id); @@ -284,27 +262,6 @@ class Song { } // get_genre_name /** - * get_flags - * This gets any flag information this song may have, it always - * returns an array as it may be possible to have more then - * one flag - */ - function get_flags() { - - $sql = "SELECT id,flag,comment FROM flagged WHERE object_type='song' AND object_id='$this->id'"; - $db_results = mysql_query($sql, dbh()); - - $results = array(); - - while ($r = mysql_fetch_assoc($db_results)) { - $results[] = $r; - } - - return $results; - - } // get_flag - - /** * has_flag * This just returns true or false depending on if this song is flagged for something * We don't care what so we limit the SELECT to 1 diff --git a/lib/class/tagcloud.class.php b/lib/class/tagcloud.class.php index ef141783..97beee09 100644 --- a/lib/class/tagcloud.class.php +++ b/lib/class/tagcloud.class.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2008 Ampache.org + Copyright (c) Ampache.org All rights reserved. This program is free software; you can redistribute it and/or @@ -19,46 +19,51 @@ */ - /** * TagCloud Class */ - class TagCloud { - public static function add_tag($objType, $id, $tagval) - { - if (!in_array($objType, array('artist','album','song'))) - return; - if (!is_numeric($id)) - return; - if (!preg_match('/^[A-Za-z_]+$/',$tagval)) - return; - $uid = $GLOBALS['user']->id; - // Check if tag object exists - $sql = "SELECT tags.id from tags where name='$tagval'"; - $db_results = Dba::query($sql) ; - $ar = Dba::fetch_assoc($db_results); - if (!sizeof($ar)) { - $sql = "INSERT into tags set name='$tagval'"; - $db_results = Dba::query($sql) ; - $sql = "SELECT tags.id from tags where name='$tagval'"; - $db_results = Dba::query($sql); - $ar = Dba::fetch_assoc($db_results); - } - $tid = $ar['id']; - $sql = "INSERT into tag_map set tag_id=$tid, user=$uid, - object_type = '$objType', object_id=$id;"; - $db_results = Dba::query($sql) ;//or die(Dba::error()); - $results['error'] = '<error>'.Dba::error().'</error>'; - } - /** - * show_tags - * Return all tags maching any object of type $objtype in list $id - */ - public static function get_tags($objType, $id) { - if (!sizeof($id)) - return array(); - global $tag_cache; - $tag_cache = array(); +class TagCloud { + + public static function add_tag($objType, $id, $tagval) { + + if (!in_array($objType, array('artist','album','song'))) + return; + if (!is_numeric($id)) + return; + if (!preg_match('/^[A-Za-z_]+$/',$tagval)) + return; + $uid = $GLOBALS['user']->id; + + // Check if tag object exists + $sql = "SELECT tag.id from tag where name='$tagval'"; + $db_results = Dba::query($sql) ; + $ar = Dba::fetch_assoc($db_results); + + if (!sizeof($ar)) { + $sql = "INSERT into tag set name='$tagval'"; + $db_results = Dba::query($sql) ; + $sql = "SELECT tag.id from tag where name='$tagval'"; + + $db_results = Dba::query($sql); + $ar = Dba::fetch_assoc($db_results); + } + + $tid = $ar['id']; + $sql = "INSERT into tag_map set tag_id=$tid, user=$uid, object_type = '$objType', object_id=$id;"; + $db_results = Dba::query($sql) ;//or die(Dba::error()); + + } // add_tag + + /** + * show_tags + * Return all tags maching any object of type $objtype in list $id + */ + public static function get_tags($objType, $id) { + + if (!sizeof($id)) + return array(); + global $tag_cache; + $tag_cache = array(); $lid = '(' . implode(',',$id) . ')'; $orsql = ''; if ($objType == 'artist' || $objType == 'album') @@ -67,9 +72,9 @@ if ($objType == 'artist') $orsql .= "or (tag_map.object_id = album.id AND tag_map.object_type='album' and $objType.id in $lid )"; - $sql = "SELECT DISTINCT tags.id, tags.name, tag_map.user, $objType.id as oid - FROM tags, tag_map, song, artist, album WHERE - tag_map.tag_id = tags.id AND + $sql = "SELECT DISTINCT tag.id, tag.name, tag_map.user, $objType.id as oid + FROM tag, tag_map, song, artist, album WHERE + tag_map.tag_id = tag.id AND ( (tag_map.object_type='$objType' AND $objType.id in $lid AND tag_map.object_id = $objType.id) $orsql) AND @@ -94,9 +99,9 @@ $restrictObjType == $id */ public static function get_tagso($objType, $restrictObjType, $id) { - $sql = "SELECT DISTINCT tag_map.id, tags.name, tag_map.user - FROM tags, tag_map, song, artist, album WHERE - tag_map.id = tags.map_id AND + $sql = "SELECT DISTINCT tag_map.id, tag.name, tag_map.user + FROM tag, tag_map, song, artist, album WHERE + tag_map.id = tag.map_id AND tag_map.object_type='$objType' AND $restrictObjType.id=$id AND song.album = album.id AND @@ -109,47 +114,65 @@ } return $results; } - //Use perfs to filter and add display properties - public static function filter_with_prefs($l) - { + + /** + * filter_with_prefs + * This filters the tags based on the users preference + */ + public static function filter_with_prefs($l) { + $colors = array('#0000FF', '#00FF00', '#FFFF00', '#00FFFF','#FF00FF','#FF0000'); - $prefs = Config::get('tags_userlist'); - $ulist = explode(' ', $prefs); - $req = ''; - foreach($ulist as $i) { - $req .= "'" . Dba::escape($i) . "',"; - } - rtrim($req, ','); - $sql = 'select id,username from user where '; - if ($prefs=='all') - $sql .= '1'; - else - $sql .= 'username in ('.$req.')'; - var_dump($sql); - $db_results = Dba::query($sql) or die(Dba::error()); - $uids=array(); - $usernames = array(); - $p = 0; - while ($r = Dba::fetch_assoc($db_results)) { - $usernames[$r['id']] = $r['username']; - $uids[$r['id']] = $colors[$p]; - $p++; - if ($p == sizeof($colors)) - $p = 0; - } - var_dump($uids); - $res = array(); - foreach ($l as $i) { - if ($GLOBALS['user']->id == $i['user']) - $res[] = $i; - else if (isset($uids[$i['user']])) { - $i['color'] = $uids[$i['user']]; - $i['username'] = $usernames[$i['user']]; - $res[] = $i; - } - } - return $res; - } - } // end of TagCloud class + $prefs = 'tag company'; +// $prefs = Config::get('tags_userlist'); + + $ulist = explode(' ', $prefs); + $req = ''; + + foreach($ulist as $i) { + $req .= "'" . Dba::escape($i) . "',"; + } + $req = rtrim($req, ','); + + $sql = 'SELECT `id`,`username` FROM `user` WHERE '; + + if ($prefs=='all') { + $sql .= '1'; + } + else { + $sql .= 'username in ('.$req.')'; + } + + $db_results = Dba::query($sql); + + $uids=array(); + $usernames = array(); + $p = 0; + while ($r = Dba::fetch_assoc($db_results)) { + $usernames[$r['id']] = $r['username']; + $uids[$r['id']] = $colors[$p]; + $p++; + if ($p == sizeof($colors)) { + $p = 0; + } + } + + $res = array(); + + foreach ($l as $i) { + if ($GLOBALS['user']->id == $i['user']) { + $res[] = $i; + } + elseif (isset($uids[$i['user']])) { + $i['color'] = $uids[$i['user']]; + $i['username'] = $usernames[$i['user']]; + $res[] = $i; + } + } + + return $res; + + } // filter_with_prefs + +} // end of TagCloud class ?> diff --git a/lib/class/update.class.php b/lib/class/update.class.php index a02d93ca..da6b7da8 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -277,6 +277,11 @@ class Update { $version[] = array('version' => '340018','description'=>$update_string); + $update_string = '- Modify the Tag tables so that they actually work.<br />' . + '- Alter the Prefix fields to allow for more prefixs.<br />'; + + $version[] = array('version' => '350001','description'=>$update_string); + return $version; @@ -1328,5 +1333,33 @@ class Update { } // update_340018 + /** + * update_350001 + * This updates modifies the tag tables per codeunde1load's specs from his tag patch + * it also adjusts the prefix fields so that we can use more prefixes + */ + public static function update_350001() { + + $sql = "ALTER TABLE `tag_map` ADD `tag_id` INT ( 11 ) UNSIGNED NOT NULL AFTER `id`"; + $db_results = Dba::query($sql); + + $sql = "RENAME TABLE `ampache`.`tags` TO `ampache`.`tag`"; + $db_results = Dba::query($sql); + + $sql = "ALTER TABLE `tag` CHANGE `map_id` `id` INT ( 11 ) UNSIGNED NOT NULL auto_increment"; + $db_results = Dba::query($sql); + + $sql = "ALTER TABLE `album` CHANGE `prefix` `prefix` VARCHAR ( 32 ) NULL"; + $db_results = Dba::query($sql); + + $sql = "ALTER TABLE `artist` CHANGE `prefix` `prefix` VARCHAR ( 32 ) NULL"; + $db_results = Dba::query($sql); + + self::set_version('db_version','350001'); + + return true; + + } // update_350001 + } // end update class ?> diff --git a/lib/class/user.class.php b/lib/class/user.class.php index ae53038c..ef40a58f 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -24,7 +24,7 @@ * and deletion of the user objects from the database by defualt you constrcut it * with a user_id from user.id */ -class User { +class User extends database_object { //Basic Componets public $id; @@ -49,8 +49,9 @@ class User { if (!$user_id) { return false; } - $this->id = intval($user_id); - $info = $this->_get_info(); + $this->id = intval($user_id); + + $info = $this->_get_info(); foreach ($info as $key=>$value) { // Let's not save the password in this object :S @@ -69,22 +70,27 @@ class User { */ private function _get_info() { + $id = intval($this->id); + + if (parent::is_cached('user',$id)) { + return parent::get_from_cache('user',$id); + } + // If the ID is -1 then - if ($this->id == '-1') { + if ($id == '-1') { $data['username'] = 'System'; $data['fullname'] = 'Ampache User'; $data['access'] = '25'; return $data; } - // Else... - $id = Dba::escape($this->id); - - $sql = "SELECT * FROM `user` WHERE `id`='" . $id . "'"; + $sql = "SELECT * FROM `user` WHERE `id`='$id'"; $db_results = Dba::query($sql); $data = Dba::fetch_assoc($db_results); + parent::add_to_cache('user',$id,$data); + return $data; } // _get_info |