本文整理汇总了PHP中Dba::escape方法的典型用法代码示例。如果您正苦于以下问题:PHP Dba::escape方法的具体用法?PHP Dba::escape怎么用?PHP Dba::escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dba
的用法示例。
在下文中一共展示了Dba::escape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_info
/**
* get_info
* retrieves the info from the database and puts it in the cache
*/
public function get_info($id, $table_name = '')
{
$table_name = $table_name ? Dba::escape($table_name) : Dba::escape(strtolower(get_class($this)));
// Make sure we've got a real id
if (!is_numeric($id)) {
return array();
}
if (self::is_cached($table_name, $id)) {
return self::get_from_cache($table_name, $id);
}
$sql = "SELECT * FROM `{$table_name}` WHERE `id`='{$id}'";
$db_results = Dba::read($sql);
if (!$db_results) {
return array();
}
$row = Dba::fetch_assoc($db_results);
self::add_to_cache($table_name, $id, $row);
return $row;
}
示例2: get_episodes
/**
* get_songs
* gets all episodes for this tv show season
*/
public function get_episodes()
{
$sql = "SELECT `tvshow_episode`.`id` FROM `tvshow_episode` ";
if (AmpConfig::get('catalog_disable')) {
$sql .= "LEFT JOIN `video` ON `video`.`id` = `tvshow_episode`.`id` ";
$sql .= "LEFT JOIN `catalog` ON `catalog`.`id` = `video`.`catalog` ";
}
$sql .= "WHERE `tvshow_episode`.`season`='" . Dba::escape($this->id) . "' ";
if (AmpConfig::get('catalog_disable')) {
$sql .= "AND `catalog`.`enabled` = '1' ";
}
$sql .= "ORDER BY `tvshow_episode`.`episode_number`";
$db_results = Dba::read($sql);
$results = array();
while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
return $results;
}
示例3: get_recently_played
/**
* get_recently_played
* This function returns the last X songs that have been played
* it uses the popular threshold to figure out how many to pull
* it will only return unique object
*/
public static function get_recently_played($user_id = '')
{
$user_id = Dba::escape($user_id);
$sql = "SELECT `object_id`, `user`, `object_type`, `date`, `agent` " . "FROM `object_count` WHERE `object_type`='song' ";
if (AmpConfig::get('catalog_disable')) {
$sql .= "AND " . Catalog::get_enable_filter('song', '`object_id`') . " ";
}
if ($user_id) {
// If user is not empty, we're looking directly to user personal info (admin view)
$sql .= "AND `user`='{$user_id}' ";
} else {
if (!Access::check('interface', '100')) {
// If user identifier is empty, we need to retrieve only users which have allowed view of personnal info
$personal_info_id = Preference::id_from_name('allow_personal_info_recent');
if ($personal_info_id) {
$current_user = $GLOBALS['user']->id;
$sql .= "AND `user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='{$personal_info_id}' AND `value`='1') OR `user`='{$current_user}') ";
}
}
}
$sql .= "ORDER BY `date` DESC ";
$db_results = Dba::read($sql);
$results = array();
while ($row = Dba::fetch_assoc($db_results)) {
$results[] = $row;
if (count($results) >= AmpConfig::get('popular_threshold')) {
break;
}
}
return $results;
}
示例4: get
/**
* get
* This functions returns an array containing information about
* The songs that vlc currently has in it's playlist. This must be
* done in a standardized fashion
* Warning ! if you got files in vlc medialibary those files will be sent to the php xml parser
* to, not to your browser but still this can take a lot of work for your server.
* The xml files of vlc need work, not much documentation on them....
*/
public function get()
{
/* Get the Current Playlist */
$list = $this->_vlc->get_tracks();
if (!$list) {
return array();
}
$counterforarray = 0;
// here we look if there are song in the playlist when media libary is used
if ($list['node']['node'][0]['leaf'][$counterforarray]['attr']['uri']) {
while ($list['node']['node'][0]['leaf'][$counterforarray]) {
$songs[] = htmlspecialchars_decode($list['node']['node'][0]['leaf'][$counterforarray]['attr']['uri'], ENT_NOQUOTES);
$songid[] = $list['node']['node'][0]['leaf'][$counterforarray]['attr']['id'];
$counterforarray++;
}
// if there is only one song look here,and media libary is used
} elseif ($list['node']['node'][0]['leaf']['attr']['uri']) {
$songs[] = htmlspecialchars_decode($list['node']['node'][0]['leaf']['attr']['uri'], ENT_NOQUOTES);
$songid[] = $list['node']['node'][0]['leaf']['attr']['id'];
} elseif ($list['node']['node']['leaf'][$counterforarray]['attr']['uri']) {
while ($list['node']['node']['leaf'][$counterforarray]) {
$songs[] = htmlspecialchars_decode($list['node']['node']['leaf'][$counterforarray]['attr']['uri'], ENT_NOQUOTES);
$songid[] = $list['node']['node']['leaf'][$counterforarray]['attr']['id'];
$counterforarray++;
}
} elseif ($list['node']['node']['leaf']['attr']['uri']) {
$songs[] = htmlspecialchars_decode($list['node']['node']['leaf']['attr']['uri'], ENT_NOQUOTES);
$songid[] = $list['node']['node']['leaf']['attr']['id'];
} else {
return array();
}
$counterforarray = 0;
foreach ($songs as $key => $entry) {
$data = array();
/* Required Elements */
$data['id'] = $songid[$counterforarray];
// id number of the files in the vlc playlist, needed for other operations
$data['raw'] = $entry;
$url_data = $this->parse_url($entry);
switch ($url_data['primary_key']) {
case 'oid':
$data['oid'] = $url_data['oid'];
$song = new Song($data['oid']);
$song->format();
$data['name'] = $song->f_title . ' - ' . $song->f_album . ' - ' . $song->f_artist;
$data['link'] = $song->f_link;
break;
case 'demo_id':
$democratic = new Democratic($url_data['demo_id']);
$data['name'] = T_('Democratic') . ' - ' . $democratic->name;
$data['link'] = '';
break;
case 'random':
$data['name'] = T_('Random') . ' - ' . scrub_out(ucfirst($url_data['type']));
$data['link'] = '';
break;
default:
/* If we don't know it, look up by filename */
$filename = Dba::escape($entry);
$sql = "SELECT `name` FROM `live_stream` WHERE `url`='{$filename}' ";
$db_results = Dba::read($sql);
if ($row = Dba::fetch_assoc($db_results)) {
//if stream is known just send name
$data['name'] = htmlspecialchars(substr($row['name'], 0, 50));
} elseif (strncmp($entry, 'http', 4) == 0) {
$data['name'] = htmlspecialchars("(VLC stream) " . substr($entry, 0, 50));
} else {
$getlast = explode("/", $entry);
$lastis = count($getlast) - 1;
$data['name'] = htmlspecialchars("(VLC local) " . substr($getlast[$lastis], 0, 50));
}
// end if loop
break;
}
// end switch on primary key type
$data['track'] = $key + 1;
$counterforarray++;
$results[] = $data;
}
// foreach playlist items
return $results;
}
示例5: remove_plugin_version
/**
* remove_plugin_version
* This removes the version row from the db done on uninstall
*/
public function remove_plugin_version()
{
$name = Dba::escape('Plugin_' . $this->_plugin->name);
$sql = "DELETE FROM `update_info` WHERE `key`='{$name}'";
Dba::write($sql);
return true;
}
示例6: count_items
/**
* 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'];
}
示例7: resort_objects
/**
* resort_objects
* This takes the existing objects, looks at the current
* sort method and then re-sorts them This is internally
* called by the set_sort() function
*/
private function resort_objects()
{
// There are two ways to do this.. the easy way...
// and the vollmer way, hopefully we don't have to
// do it the vollmer way
if ($this->is_simple()) {
$sql = $this->get_sql(true);
} else {
// FIXME: this is fragile for large browses
// First pull the objects
$objects = $this->get_saved();
// If there's nothing there don't do anything
if (!count($objects) or !is_array($objects)) {
return false;
}
$type = $this->get_type();
$where_sql = "WHERE `{$type}`.`id` IN (";
foreach ($objects as $object_id) {
$object_id = Dba::escape($object_id);
$where_sql .= "'{$object_id}',";
}
$where_sql = rtrim($where_sql, ',');
$where_sql .= ")";
$sql = $this->get_base_sql();
$order_sql = " ORDER BY ";
foreach ($this->_state['sort'] as $key => $value) {
$order_sql .= $this->sql_sort($key, $value);
}
// Clean her up
$order_sql = rtrim($order_sql, "ORDER BY ");
$order_sql = rtrim($order_sql, ",");
$sql = $sql . $this->get_join_sql() . $where_sql . $order_sql;
}
// if not simple
$db_results = Dba::read($sql);
$results = array();
while ($row = Dba::fetch_assoc($db_results)) {
$results[] = $row['id'];
}
$this->save_objects($results);
return true;
}
示例8: check_username
/**
* check_username
* This checks to make sure the username passed doesn't already
* exist in this instance of ampache
*/
public static function check_username($username)
{
$username = Dba::escape($username);
$sql = "SELECT `id` FROM `user` WHERE `username`='{$username}'";
$db_results = Dba::read($sql);
if (Dba::num_rows($db_results)) {
return false;
}
return true;
}
示例9: advanced
/**
* advanced
* This processes the results of a post from a form and returns an
* array of song items that were returned from said randomness
*/
public static function advanced($type, $data)
{
/* Figure out our object limit */
$limit = intval($data['random']);
// Generate our matchlist
/* If they've passed -1 as limit then get everything */
$limit_sql = "";
if ($data['random'] == "-1") {
unset($data['random']);
} else {
$limit_sql = "LIMIT " . Dba::escape($limit);
}
$search_data = Search::clean_request($data);
$search_info = false;
if (count($search_data) > 1) {
$search = new Search(null, $type);
$search->parse_rules($search_data);
$search_info = $search->to_sql();
}
$sql = "";
switch ($type) {
case 'song':
$sql = "SELECT `song`.`id`, `size`, `time` " . "FROM `song` ";
if ($search_info) {
$sql .= $search_info['table_sql'];
}
if (AmpConfig::get('catalog_disable')) {
$sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
$sql .= " WHERE `catalog`.`enabled` = '1'";
}
if ($search_info) {
if (AmpConfig::get('catalog_disable')) {
$sql .= ' AND ' . $search_info['where_sql'];
} else {
$sql .= ' WHERE ' . $search_info['where_sql'];
}
}
break;
case 'album':
$sql = "SELECT `album`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `album` ";
if (!$search_info || !$search_info['join']['song']) {
$sql .= "LEFT JOIN `song` ON `song`.`album`=`album`.`id` ";
}
if ($search_info) {
$sql .= $search_info['table_sql'];
}
if (AmpConfig::get('catalog_disable')) {
$sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
$sql .= " WHERE `catalog`.`enabled` = '1'";
}
if ($search_info) {
if (AmpConfig::get('catalog_disable')) {
$sql .= ' AND ' . $search_info['where_sql'];
} else {
$sql .= ' WHERE ' . $search_info['where_sql'];
}
}
$sql .= ' GROUP BY `album`.`id`';
break;
case 'artist':
$sql = "SELECT `artist`.`id`, SUM(`song`.`size`) AS `size`, SUM(`song`.`time`) AS `time` FROM `artist` ";
if (!$search_info || !$search_info['join']['song']) {
$sql .= "LEFT JOIN `song` ON `song`.`artist`=`artist`.`id` ";
}
if ($search_info) {
$sql .= $search_info['table_sql'];
}
if (AmpConfig::get('catalog_disable')) {
$sql .= " LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
$sql .= " WHERE `catalog`.`enabled` = '1'";
}
if ($search_info) {
if (AmpConfig::get('catalog_disable')) {
$sql .= ' AND ' . $search_info['where_sql'];
} else {
$sql .= ' WHERE ' . $search_info['where_sql'];
}
}
$sql .= ' GROUP BY `artist`.`id`';
break;
}
$sql .= " ORDER BY RAND() {$limit_sql}";
// Run the query generated above so we can while it
$db_results = Dba::read($sql);
$results = array();
$size_total = 0;
$fuzzy_size = 0;
$time_total = 0;
$fuzzy_time = 0;
while ($row = Dba::fetch_assoc($db_results)) {
// If size limit is specified
if ($data['size_limit']) {
// Convert
$new_size = $row['size'] / 1024 / 1024;
// Only fuzzy 100 times
//.........这里部分代码省略.........
示例10: get_episodes
/**
* get_episodes
* gets all episodes for this tv show
*/
public function get_episodes($state_filter = '')
{
$params = array();
$sql = "SELECT `podcast_episode`.`id` FROM `podcast_episode` ";
if (AmpConfig::get('catalog_disable')) {
$sql .= "LEFT JOIN `podcast` ON `podcast`.`id` = `podcast_episode`.`podcast` ";
$sql .= "LEFT JOIN `catalog` ON `catalog`.`id` = `podcast`.`catalog` ";
}
$sql .= "WHERE `podcast_episode`.`podcast`='" . Dba::escape($this->id) . "' ";
if (!empty($state_filter)) {
$sql .= "AND `podcast_episode`.`state` = ? ";
$params[] = $state_filter;
}
if (AmpConfig::get('catalog_disable')) {
$sql .= "AND `catalog`.`enabled` = '1' ";
}
$sql .= "ORDER BY `podcast_episode`.`pubdate` DESC";
$db_results = Dba::read($sql, $params);
$results = array();
while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
return $results;
}
示例11: get_artists_like
/**
* get_artists_like
* Returns a list of similar artists
*/
public static function get_artists_like($artist_id, $limit = 10, $local_only = true)
{
$artist = new Artist($artist_id);
$cache = self::get_recommendation_cache('artist', $artist_id, true);
if (!$cache['id']) {
$similars = array();
$query = 'artist=' . rawurlencode($artist->name);
$xml = self::get_lastfm_results('artist.getsimilar', $query);
foreach ($xml->similarartists->children() as $child) {
$name = $child->name;
$mbid = (string) $child->mbid;
$local_id = null;
// First we check by MBID
if ($mbid) {
$sql = "SELECT `artist`.`id` FROM `artist` WHERE `mbid` = ?";
if (AmpConfig::get('catalog_disable')) {
$sql .= " AND " . Catalog::get_enable_filter('artist', '`artist`.`id`');
}
$db_result = Dba::read($sql, array($mbid));
if ($result = Dba::fetch_assoc($db_result)) {
$local_id = $result['id'];
}
}
// Then we fall back to the less likely to work exact
// name match
if (is_null($local_id)) {
$searchname = Catalog::trim_prefix($name);
$searchname = Dba::escape($searchname['string']);
$sql = "SELECT `artist`.`id` FROM `artist` WHERE `name` = ?";
if (AmpConfig::get('catalog_disable')) {
$sql .= " AND " . Catalog::get_enable_filter('artist', '`artist`.`id`');
}
$db_result = Dba::read($sql, array($searchname));
if ($result = Dba::fetch_assoc($db_result)) {
$local_id = $result['id'];
}
}
// Then we give up
if (is_null($local_id)) {
debug_event('Recommendation', "{$name} did not match any local artist", 5);
$similars[] = array('id' => null, 'name' => $name, 'mbid' => $mbid);
} else {
debug_event('Recommendation', "{$name} matched local artist " . $local_id, 5);
$similars[] = array('id' => $local_id, 'name' => $name);
}
}
if (count($similars) > 0) {
self::update_recommendation_cache('artist', $artist_id, $similars);
}
}
if (!isset($similars) || count($similars) == 0) {
$similars = $cache['items'];
}
if ($similars) {
$results = array();
foreach ($similars as $similar) {
if (!$local_only || !is_null($similar['id'])) {
$results[] = $similar;
}
if ($limit && count($results) >= $limit) {
break;
}
}
}
if (isset($results)) {
return $results;
}
return false;
}
示例12: init
/**
* init
* This grabs the preferences and then loads them into conf it should be run on page load
* to initialize the needed variables
*/
public static function init()
{
$user_id = $GLOBALS['user']->id ? Dba::escape($GLOBALS['user']->id) : '-1';
// First go ahead and try to load it from the preferences
if (self::load_from_session($user_id)) {
return true;
}
/* Get Global Preferences */
$sql = "SELECT `preference`.`name`,`user_preference`.`value`,`syspref`.`value` AS `system_value` FROM `preference` " . "LEFT JOIN `user_preference` `syspref` ON `syspref`.`preference`=`preference`.`id` AND `syspref`.`user`='-1' AND `preference`.`catagory`='system' " . "LEFT JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` AND `user_preference`.`user`='{$user_id}' AND `preference`.`catagory`!='system'";
$db_results = Dba::read($sql);
$results = array();
while ($row = Dba::fetch_assoc($db_results)) {
$value = $row['system_value'] ? $row['system_value'] : $row['value'];
$name = $row['name'];
$results[$name] = $value;
}
// end while sys prefs
/* Set the Theme mojo */
if (strlen($results['theme_name']) > 0) {
$results['theme_path'] = '/themes/' . $results['theme_name'];
} else {
$results['theme_path'] = '/themes/reborn';
}
AmpConfig::set_by_array($results, true);
$_SESSION['userdata']['preferences'] = $results;
$_SESSION['userdata']['uid'] = $user_id;
}
示例13: get_vote
/**
* get_vote
* This returns the current count for a specific song
*/
public function get_vote($id)
{
if (parent::is_cached('democratic_vote', $id)) {
return parent::get_from_cache('democratic_vote', $id);
}
$sql = 'SELECT COUNT(`user`) AS `count` FROM `user_vote` ' . "WHERE `object_id`='" . Dba::escape($id) . "'";
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
parent::add_to_cache('democratic_vote', $id, $results['count']);
return $results['count'];
}
示例14: get_from_path
/**
* get_from_path
* This returns all of the songs that exist under the specified path
* @param string $path
* @return int[]
*/
public static function get_from_path($path)
{
$path = Dba::escape($path);
$sql = "SELECT * FROM `song` WHERE `file` LIKE '{$path}%'";
$db_results = Dba::read($sql);
$songs = array();
while ($row = Dba::fetch_assoc($db_results)) {
$songs[] = $row['id'];
}
return $songs;
}
示例15: get_from_source
/**
* get_from_source
* This gets an image for the album art from a source as
* defined in the passed array. Because we don't know where
* it's coming from we are a passed an array that can look like
* ['url'] = URL *** OPTIONAL ***
* ['file'] = FILENAME *** OPTIONAL ***
* ['raw'] = Actual Image data, already captured
*/
public static function get_from_source($data, $type = 'album')
{
// Already have the data, this often comes from id3tags
if (isset($data['raw'])) {
return $data['raw'];
}
// If it came from the database
if (isset($data['db'])) {
// Repull it
$uid = Dba::escape($data['db']);
$type = Dba::escape($type);
$sql = "SELECT * FROM `image` WHERE `object_type`='{$type}' AND `object_id`='{$uid}' AND `size`='original'";
$db_results = Dba::read($sql);
$row = Dba::fetch_assoc($db_results);
return $row['art'];
}
// came from the db
// Check to see if it's a URL
if (isset($data['url'])) {
$options = array();
if (AmpConfig::get('proxy_host') and AmpConfig::get('proxy_port')) {
$proxy = array();
$proxy[] = AmpConfig::get('proxy_host') . ':' . AmpConfig::get('proxy_port');
if (AmpConfig::get('proxy_user')) {
$proxy[] = AmpConfig::get('proxy_user');
$proxy[] = AmpConfig::get('proxy_pass');
}
$options['proxy'] = $proxy;
}
$request = Requests::get($data['url'], array(), $options);
return $request->body;
}
// Check to see if it's a FILE
if (isset($data['file'])) {
$handle = fopen($data['file'], 'rb');
$image_data = fread($handle, filesize($data['file']));
fclose($handle);
return $image_data;
}
// Check to see if it is embedded in id3 of a song
if (isset($data['song'])) {
// If we find a good one, stop looking
$getID3 = new getID3();
$id3 = $getID3->analyze($data['song']);
if ($id3['format_name'] == "WMA") {
return $id3['asf']['extended_content_description_object']['content_descriptors']['13']['data'];
} elseif (isset($id3['id3v2']['APIC'])) {
// Foreach in case they have more then one
foreach ($id3['id3v2']['APIC'] as $image) {
return $image['data'];
}
}
}
// if data song
return false;
}