1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
pre { line-height: 125%; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding-left: 5px; padding-right: 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding-left: 5px; padding-right: 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */<?php
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
/**
*
* LICENSE: GNU General Public License, version 2 (GPLv2)
* Copyright 2001 - 2013 Ampache.org
*
* 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.
*
*/
if(php_sapi_name() != 'cli') {
exit(1);
}
define('NO_SESSION', 1);
define('OUTDATED_DATABASE_OK', 1);
define('CLI', 1);
$path = dirname(__FILE__);
$prefix = realpath($path . '/../../');
require_once $prefix . '/lib/init.php';
$options = getopt('u', array('update'));
$run_update = (isset($options['u']) || isset($options['update']));
if (Update::need_update() && $run_update) {
Update::run_update();
}
if (Update::need_update()) {
echo T_('The following updates need to be performed:'), "\n";
}
Update::display_update();
?>
#n345'>345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
<?php
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
/**
*
* LICENSE: GNU General Public License, version 2 (GPLv2)
* Copyright 2001 - 2013 Ampache.org
*
* 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.
*
*/
/**
* TempPlaylist Class
*
* This class handles the temporary playlists in Ampache. It handles the
* tmp_playlist and tmp_playlist_data tables, and sneaks out at night to
* visit user_vote from time to time.
*
*/
class tmpPlaylist extends database_object {
/* Variables from the Datbase */
public $id;
public $session;
public $type;
public $object_type;
public $base_playlist;
/* Generated Elements */
public $items = array();
/**
* Constructor
* This takes a playlist_id as an optional argument and gathers the
* information. If no playlist_id is passed or the requested one isn't
* found, return false.
*/
public function __construct($playlist_id='') {
if (!$playlist_id) { return false; }
$this->id = intval($playlist_id);
$info = $this->_get_info();
foreach ($info as $key=>$value) {
$this->$key = $value;
}
return true;
} // __construct
/**
* _get_info
* This is an internal (private) function that gathers the information
* for this object from the playlist_id that was passed in.
*/
private function _get_info() {
$sql = "SELECT * FROM `tmp_playlist` WHERE `id`='" . Dba::escape($this->id) . "'";
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
return $results;
} // _get_info
/**
* get_from_session
* This returns a playlist object based on the session that is passed to
* us. This is used by the load_playlist on user for the most part.
*/
public static function get_from_session($session_id) {
$session_id = Dba::escape($session_id);
$sql = "SELECT `id` FROM `tmp_playlist` WHERE `session`='$session_id'";
$db_results = Dba::read($sql);
$results = Dba::fetch_row($db_results);
if (!$results['0']) {
$results['0'] = tmpPlaylist::create(array(
'session_id' => $session_id,
'type' => 'user',
'object_type' => 'song'
));
}
$playlist = new tmpPlaylist($results['0']);
return $playlist;
} // get_from_session
/**
* get_from_userid
* This returns a tmp playlist object based on a userid passed
* this is used for the user profiles page
*/
public static function get_from_userid($user_id) {
// This is a little stupid, but because we don't have the
// user_id in the session or in the tmp_playlist table we have
// to do it this way.
$client = new User($user_id);
$username = Dba::escape($client->username);
$sql = "SELECT `tmp_playlist`.`id` FROM `tmp_playlist` " .
"LEFT JOIN `session` ON " .
"`session`.`id`=`tmp_playlist`.`session` " .
"WHERE `session`.`username`='$username' " .
"ORDER BY `session`.`expire` DESC";
$db_results = Dba::read($sql);
$data = Dba::fetch_assoc($db_results);
return $data['id'];
} // get_from_userid
/**
* get_items
* Returns an array of all object_ids currently in this tmpPlaylist.
*/
public function get_items() {
$id = Dba::escape($this->id);
/* Select all objects from this playlist */
$sql = "SELECT `object_type`, `id`, `object_id` " .
"FROM `tmp_playlist_data` " .
"WHERE `tmp_playlist`='$id' ORDER BY `id` ASC";
$db_results = Dba::read($sql);
/* Define the array */
$items = array();
while ($results = Dba::fetch_assoc($db_results)) {
$key = $results['id'];
$items[$key] = array(
'object_type' => $results['object_type'],
'object_id' => $results['object_id']
);
}
return $items;
} // get_items
/**
* get_next_object
* This returns the next object in the tmp_playlist.
*/
public function get_next_object() {
$id = Dba::escape($this->id);
$sql = "SELECT `object_id` FROM `tmp_playlist_data` " .
"WHERE `tmp_playlist`='$id' ORDER BY `id` LIMIT 1";
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
return $results['object_id'];
} // get_next_object
/**
* count_items
* This returns a count of the total number of tracks that are in this
* tmp playlist
*/
public function count_items() {
$id = Dba::escape($this->id);
$sql = "SELECT COUNT(`id`) FROM `tmp_playlist_data` WHERE " .
"`tmp_playlist`='$id'";
$db_results = Dba::read($sql);
$results = Dba::fetch_row($db_results);
return $results['0'];
} // count_items
/**
* clear
* This clears all the objects out of a single playlist
*/
public function clear() {
$id = Dba::escape($this->id);
$sql = "DELETE FROM `tmp_playlist_data` WHERE " .
"`tmp_playlist`='$id'";
$db_results = Dba::write($sql);
return true;
} // clear
/**
* create
* This function initializes a new tmpPlaylist. It is associated with
* the current session rather than a user, as you could have the same
* user logged in from multiple locations.
*/
public static function create($data) {
$sessid = Dba::escape($data['session_id']);
$type = Dba::escape($data['type']);
$object_type = Dba::escape($data['object_type']);
$sql = "INSERT INTO `tmp_playlist` " .
"(`session`,`type`,`object_type`) " .
" VALUES ('$sessid','$type','$object_type')";
$db_results = Dba::write($sql);
$id = Dba::insert_id();
/* Clean any other playlists associated with this session */
self::session_clean($sessid, $id);
return $id;
} // create
/**
* update_playlist
* This updates the base_playlist on this tmp_playlist
*/
public function update_playlist($playlist_id) {
$playlist_id = Dba::escape($playlist_id);
$id = Dba::escape($this->id);
$sql = "UPDATE `tmp_playlist` SET " .
"`base_playlist`='$playlist_id' WHERE `id`='$id'";
$db_results = Dba::write($sql);
return true;
} // update_playlist
/**
* session_clean
* This deletes any other tmp_playlists associated with this
* session
*/
public static function session_clean($sessid, $id) {
$sessid = Dba::escape($sessid);
$id = Dba::escape($id);
$sql = "DELETE FROM `tmp_playlist` WHERE `session`='$sessid' " .
"AND `id` != '$id'";
$db_results = Dba::write($sql);
/* Remove associated tracks */
self::prune_tracks();
return true;
} // session_clean
/**
* clean
* This cleans up old data
*/
public static function clean() {
self::prune_playlists();
self::prune_tracks();
}
/**
* prune_playlists
* This deletes any playlists that don't have an associated session
*/
public static function prune_playlists() {
/* Just delete if no matching session row */
$sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " .
"LEFT JOIN `session` " .
"ON `session`.`id`=`tmp_playlist`.`session` " .
"WHERE `session`.`id` IS NULL " .
"AND `tmp_playlist`.`type` != 'vote'";
$db_results = Dba::write($sql);
return true;
} // prune_playlists
/**
* prune_tracks
* This prunes tracks that don't have playlists or don't have votes
*/
public static function prune_tracks() {
// This prune is always run and clears data for playlists that
// don't exist anymore
$sql = "DELETE FROM `tmp_playlist_data` USING " .
"`tmp_playlist_data` LEFT JOIN `tmp_playlist` ON " .
"`tmp_playlist_data`.`tmp_playlist`=`tmp_playlist`.`id` " .
"WHERE `tmp_playlist`.`id` IS NULL";
$db_results = Dba::write($sql);
} // prune_tracks
/**
* add_object
* This adds the object of $this->object_type to this tmp playlist
* it takes an optional type, default is song
*/
public function add_object($object_id,$object_type) {
$object_id = Dba::escape($object_id);
$playlist_id = Dba::escape($this->id);
$object_type = $object_type ? Dba::escape($object_type) : 'song';
$sql = "INSERT INTO `tmp_playlist_data` " .
"(`object_id`,`tmp_playlist`,`object_type`) " .
" VALUES ('$object_id','$playlist_id','$object_type')";
$db_results = Dba::write($sql);
return true;
} // add_object
/**
* vote_active
* This checks to see if this playlist is a voting playlist
* and if it is active
*/
public function vote_active() {
/* Going to do a little more here later */
if ($this->type == 'vote') { return true; }
return false;
} // vote_active
/**
* delete_track
* This deletes a track from the tmpplaylist
*/
public function delete_track($id) {
$id = Dba::escape($id);
/* delete the track its self */
$sql = "DELETE FROM `tmp_playlist_data` WHERE `id`='$id'";
$db_results = Dba::write($sql);
return true;
} // delete_track
} // class tmpPlaylist
|