/** * build_cache * Build a cache based on the array of ids passed, saves lots of little queries */ public static function build_cache($ids = array()) { if (!is_array($ids) or !count($ids)) { return false; } $idlist = '(' . implode(',', $ids) . ')'; $sql = "SELECT * FROM `video` WHERE `video`.`id` IN {$idlist}"; $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { parent::add_to_cache('video', $row['id'], $row); } }
function update_preferences($pref_id = 0) { /* Get current keys */ $sql = "SELECT `id`,`name`,`type` FROM `preference`"; /* If it isn't the System Account's preferences */ if ($pref_id != '-1') { $sql .= " WHERE `catagory` != 'system'"; } $db_results = Dba::read($sql); $results = array(); // Collect the current possible keys while ($r = Dba::fetch_assoc($db_results)) { $results[] = array('id' => $r['id'], 'name' => $r['name'], 'type' => $r['type']); } // end collecting keys /* Foreach through possible keys and assign them */ foreach ($results as $data) { /* Get the Value from POST/GET var called $data */ $name = $data['name']; $apply_to_all = 'check_' . $data['name']; $new_level = 'level_' . $data['name']; $id = $data['id']; $value = scrub_in($_REQUEST[$name]); /* Some preferences require some extra checks to be performed */ switch ($name) { case 'transcode_bitrate': $value = Stream::validate_bitrate($value); break; default: break; } if (preg_match('/_pass$/', $name)) { if ($value == '******') { unset($_REQUEST[$name]); } else { if (preg_match('/md5_pass$/', $name)) { $value = md5($value); } } } /* Run the update for this preference only if it's set */ if (isset($_REQUEST[$name])) { Preference::update($id, $pref_id, $value, $_REQUEST[$apply_to_all]); } if (Access::check('interface', '100') && $_REQUEST[$new_level]) { Preference::update_level($id, $_REQUEST[$new_level]); } } // end foreach preferences // Now that we've done that we need to invalidate the cached preverences Preference::clear_from_session(); }
/** * 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; }
/** * Stream_Playlist constructor * If an ID is passed, it should be a stream session ID. */ public function __construct($id = null) { if ($id != -1) { if ($id) { Stream::set_session($id); } $this->id = Stream::$session; if (!Session::exists('stream', $this->id)) { debug_event('stream_playlist', 'Session::exists failed', 2); return false; } $this->user = intval($GLOBALS['user']->id); $sql = 'SELECT * FROM `stream_playlist` WHERE `sid` = ? ORDER BY `id`'; $db_results = Dba::read($sql, array($this->id)); while ($row = Dba::fetch_assoc($db_results)) { $this->urls[] = new Stream_URL($row); } } return true; }
/** * 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; }
/** * update_360020 * * Catalog types are plugins now */ public static function update_360020() { $retval = true; $sql = "SELECT `id`, `catalog_type`, `path`, `remote_username`, `remote_password` FROM `catalog`"; $db_results = Dba::read($sql); $c = Catalog::create_catalog_type('local'); $c->install(); $c = Catalog::create_catalog_type('remote'); $c->install(); while ($results = Dba::fetch_assoc($db_results)) { if ($results['catalog_type'] == 'local') { $sql = "INSERT INTO `catalog_local` (`path`, `catalog_id`) VALUES (?, ?)"; $retval &= Dba::write($sql, array($results['path'], $results['id'])); } elseif ($results['catalog_type'] == 'remote') { $sql = "INSERT INTO `catalog_remote` (`uri`, `username`, `password`, `catalog_id`) VALUES (?, ?, ?, ?)"; $retval &= Dba::write($sql, array($results['path'], $results['remote_username'], $results['remote_password'], $results['id'])); } } $sql = "ALTER TABLE `catalog` DROP `path`, DROP `remote_username`, DROP `remote_password`"; $retval &= Dba::write($sql); $sql = "ALTER TABLE `catalog` MODIFY COLUMN `catalog_type` varchar(128)"; $retval &= Dba::write($sql); $sql = "UPDATE `artist` SET `mbid` = null WHERE `mbid` = ''"; $retval &= Dba::write($sql); $sql = "UPDATE `album` SET `mbid` = null WHERE `mbid` = ''"; $retval &= Dba::write($sql); $sql = "UPDATE `song` SET `mbid` = null WHERE `mbid` = ''"; $retval &= Dba::write($sql); return $retval; }
/** * check * * Checks for an existing tv show; if none exists, insert one. */ public static function check($name, $year, $tvshow_summary, $readonly = false) { // null because we don't have any unique id like mbid for now if (isset(self::$_mapcache[$name]['null'])) { return self::$_mapcache[$name]['null']; } $id = 0; $exists = false; $trimmed = Catalog::trim_prefix(trim($name)); $name = $trimmed['string']; $prefix = $trimmed['prefix']; if (!$exists) { $sql = 'SELECT `id` FROM `tvshow` WHERE `name` LIKE ? AND `year` = ?'; $db_results = Dba::read($sql, array($name, $year)); $id_array = array(); while ($row = Dba::fetch_assoc($db_results)) { $key = 'null'; $id_array[$key] = $row['id']; } if (count($id_array)) { $id = array_shift($id_array); $exists = true; } } if ($exists) { self::$_mapcache[$name]['null'] = $id; return $id; } if ($readonly) { return null; } $sql = 'INSERT INTO `tvshow` (`name`, `prefix`, `year`, `summary`) VALUES(?, ?, ?, ?)'; $db_results = Dba::write($sql, array($name, $prefix, $year, $tvshow_summary)); if (!$db_results) { return null; } $id = Dba::insert_id(); self::$_mapcache[$name]['null'] = $id; return $id; }
/** * show_playlist_select * This one is for playlists! */ function show_playlist_select($name, $selected = '', $style = '') { echo "<select name=\"{$name}\" style=\"{$style}\">\n"; echo "\t<option value=\"\">" . T_('None') . "</option>\n"; $sql = "SELECT `id`,`name` FROM `playlist` ORDER BY `name`"; $db_results = Dba::read($sql); $nb_items = Dba::num_rows($db_results); $index = 1; $already_selected = false; while ($row = Dba::fetch_assoc($db_results)) { $select_txt = ''; if (!$already_selected && ($row['id'] == $selected || $index == $nb_items)) { $select_txt = 'selected="selected"'; $already_selected = true; } echo "\t<option value=\"" . $row['id'] . "\" {$select_txt}>" . scrub_out($row['name']) . "</option>\n"; ++$index; } // end while users echo "</select>\n"; }
/** * _clean_chunk * This is the clean function, its broken into * said chunks to try to save a little memory */ private function _clean_chunk($media_type, $chunk, $chunk_size) { debug_event('clean', "Starting chunk {$chunk}", 5); $dead = array(); $count = $chunk * $chunk_size; $sql = "SELECT `id`, `file` FROM `{$media_type}` " . "WHERE `catalog`='{$this->id}' LIMIT {$count},{$chunk_size}"; $db_results = Dba::read($sql); while ($results = Dba::fetch_assoc($db_results)) { debug_event('clean', 'Starting work on ' . $results['file'] . '(' . $results['id'] . ')', 5); $count++; if (UI::check_ticker()) { $file = str_replace(array('(', ')', '\''), '', $results['file']); UI::update_text('clean_count_' . $this->id, $count); UI::update_text('clean_dir_' . $this->id, scrub_out($file)); } $file_info = Core::get_filesize(Core::conv_lc_file($results['file'])); if (!file_exists(Core::conv_lc_file($results['file'])) || $file_info < 1) { debug_event('clean', 'File not found or empty: ' . $results['file'], 5); AmpError::add('general', sprintf(T_('Error File Not Found or 0 Bytes: %s'), $results['file'])); // Store it in an array we'll delete it later... $dead[] = $results['id']; } else { if (!Core::is_readable(Core::conv_lc_file($results['file']))) { debug_event('clean', $results['file'] . ' is not readable, but does exist', 1); } } } return $dead; }
/** * Sort the tracks and save the new position */ public function sort_tracks() { /* First get all of the songs in order of their tracks */ $sql = "SELECT A.`id`\n FROM `playlist_data` AS A\n LEFT JOIN `song` AS B ON A.object_id = B.id\n LEFT JOIN `artist` AS C ON B.artist = C.id\n LEFT JOIN `album` AS D ON B.album = D.id\n WHERE A.`playlist` = ?\n ORDER BY C.`name` ASC,\n B.`title` ASC,\n D.`year` ASC,\n D.`name` ASC,\n B.`track` ASC"; $db_results = Dba::query($sql, array($this->id)); $i = 1; $results = array(); while ($r = Dba::fetch_assoc($db_results)) { $new_data = array(); $new_data['id'] = $r['id']; $new_data['track'] = $i; $results[] = $new_data; $i++; } // end while results foreach ($results as $data) { $sql = "UPDATE `playlist_data` SET `track` = ? WHERE `id` = ?"; Dba::write($sql, array($data['track'], $data['id'])); } // foreach re-ordered results return true; }
public static function get_song_previews($album_mbid) { $songs = array(); $sql = "SELECT `id` FROM `song_preview` " . "WHERE `session` = ? AND `album_mbid` = ?"; $db_results = Dba::read($sql, array(session_id(), $album_mbid)); while ($results = Dba::fetch_assoc($db_results)) { $songs[] = new Song_Preview($results['id']); } return $songs; }
/** * mysql_auth * * This is the core function of our built-in authentication. */ private static function mysql_auth($username, $password) { if (strlen($password) && strlen($username)) { $sql = 'SELECT `password` FROM `user` WHERE `username` = ?'; $db_results = Dba::read($sql, array($username)); if ($row = Dba::fetch_assoc($db_results)) { // Use SHA2 now... cooking with fire. // For backwards compatibility we hash a couple of different // variations of the password. Increases collision chances, but // doesn't break things. // FIXME: Break things in the future. $hashed_password = array(); $hashed_password[] = hash('sha256', $password); $hashed_password[] = hash('sha256', Dba::escape(stripslashes(htmlspecialchars(strip_tags($password))))); // Automagically update the password if it's old and busted. if ($row['password'] == $hashed_password[1] && $hashed_password[0] != $hashed_password[1]) { $user = User::get_from_username($username); $user->update_password($password); } if (in_array($row['password'], $hashed_password)) { return array('success' => true, 'type' => 'mysql', 'username' => $username); } } } return array('success' => false, 'error' => 'MySQL login attempt failed'); }
/** * rebuild_all_preferences * This rebuilds the user preferences for all installed users, called by the plugin functions */ public static function rebuild_all_preferences() { // Clean out any preferences garbage left over $sql = "DELETE `user_preference`.* FROM `user_preference` " . "LEFT JOIN `user` ON `user_preference`.`user` = `user`.`id` " . "WHERE `user_preference`.`user` != -1 AND `user`.`id` IS NULL"; Dba::write($sql); // Get only users who has less preferences than excepted // otherwise it would have significant performance issue with large user database $sql = "SELECT `user` FROM `user_preference` " . "GROUP BY `user` HAVING COUNT(*) < (" . "SELECT COUNT(`id`) FROM `preference` WHERE `catagory` != 'system')"; $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { User::fix_preferences($row['user']); } return true; }
/** * get_user * This gets all stats for atype based on user with thresholds and all * If full is passed, doesn't limit based on date */ public static function get_user($count, $type, $user, $full = '') { $count = intval($count); $type = self::validate_type($type); /* If full then don't limit on date */ if ($full) { $date = '0'; } else { $date = time() - 86400 * AmpConfig::get('stats_threshold'); } /* Select Objects based on user */ //FIXME:: Requires table scan, look at improving $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . " WHERE object_type = ? AND date >= ? AND user = ?" . " GROUP BY object_id ORDER BY `count` DESC LIMIT {$count}"; $db_results = Dba::read($sql, array($type, $date, $user)); $results = array(); while ($r = Dba::fetch_assoc($db_results)) { $results[] = $r; } return $results; }
public static function get_shares($object_type, $object_id) { $sql = "SELECT `id` FROM `share` WHERE `object_type` = ? AND `object_id` = ?"; $db_results = Dba::read($sql, array($object_type, $object_id)); $results = array(); while ($row = Dba::fetch_assoc($db_results)) { $results[] = $row['id']; } return $results; }
/** * get_instance * This returns a single instance and all it's variables */ public function get_instance($instance = '') { $instance = $instance ? $instance : AmpConfig::get('xbmc_active'); $sql = "SELECT * FROM `localplay_xbmc` WHERE `id` = ?"; $db_results = Dba::query($sql, array($instance)); $row = Dba::fetch_assoc($db_results); return $row; }
/** * get_highest * Get objects with the highest average rating. */ public static function get_highest($type, $count = '', $offset = '') { if (!$count) { $count = AmpConfig::get('popular_threshold'); } $count = intval($count); if (!$offset) { $limit = $count; } else { $limit = intval($offset) . "," . $count; } /* Select Top objects counting by # of rows */ $sql = self::get_highest_sql($type); $sql .= "LIMIT {$limit}"; $db_results = Dba::read($sql, array($type)); $results = array(); while ($row = Dba::fetch_assoc($db_results)) { $results[] = $row['id']; } return $results; }
public static function get_all_radios($catalog = null) { $sql = "SELECT `live_stream`.`id` FROM `live_stream` JOIN `catalog` ON `catalog`.`id` = `live_stream`.`catalog` "; if (AmpConfig::get('catalog_disable')) { $sql .= "WHERE `catalog`.`enabled` = '1' "; } $params = array(); if ($catalog) { if (AmpConfig::get('catalog_disable')) { $sql .= "AND "; } $sql .= "`catalog`.`id` = ?"; $params[] = $catalog; } $db_results = Dba::read($sql, $params); $radios = array(); while ($results = Dba::fetch_assoc($db_results)) { $radios[] = $results['id']; } return $radios; }
/** * get_songs * This functions returns an array containing information about * the songs that MPD currently has in its playlist. This must be * done in a standardized fashion */ public function get() { // If we don't have the playlist yet, pull it if (!isset($this->_mpd->playlist)) { $this->_mpd->RefreshInfo(); } /* Get the Current Playlist */ $playlist = $this->_mpd->playlist; foreach ($playlist as $entry) { $data = array(); /* Required Elements */ $data['id'] = $entry['Pos']; $data['raw'] = $entry['file']; $url_data = $this->parse_url($entry['file']); 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['file']); $sql = "SELECT `id`,'song' AS `type` FROM `song` WHERE `file` LIKE '%{$filename}' " . "UNION ALL " . "SELECT `id`,'live_stream' AS `type` FROM `live_stream` WHERE `url`='{$filename}' "; $db_results = Dba::read($sql); if ($row = Dba::fetch_assoc($db_results)) { $media = new $row['type']($row['id']); $media->format(); switch ($row['type']) { case 'song': $data['name'] = $media->f_title . ' - ' . $media->f_album . ' - ' . $media->f_artist; $data['link'] = $media->f_link; break; case 'live_stream': $frequency = $media->frequency ? '[' . $media->frequency . ']' : ''; $site_url = $media->site_url ? '(' . $media->site_url . ')' : ''; $data['name'] = "{$media->name} {$frequency} {$site_url}"; $data['link'] = $media->site_url; break; } // end switch on type } else { $data['name'] = T_('Unknown'); $data['link'] = ''; } break; } // end switch on primary key type /* Optional Elements */ $data['track'] = $entry['Pos'] + 1; $results[] = $data; } // foreach playlist items return $results; }
/** * 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; }
/** * get_ampache_db_version * This function returns the Ampache database version */ public function get_ampache_db_version() { $sql = "SELECT * FROM `update_info` WHERE `key`='db_version'"; $db_results = Dba::read($sql); $results = Dba::fetch_assoc($db_results); return $results['value']; }
/** * get_access_lists * returns a full listing of all access rules on this server */ public static function get_access_lists() { $sql = 'SELECT `id` FROM `access_list`'; $db_results = Dba::read($sql); $results = array(); while ($row = Dba::fetch_assoc($db_results)) { $results[] = $row['id']; } return $results; }
/** * reset_db_charset * * This cruises through the database and trys to set the charset to the * current site charset. This is an admin function that can be run by an * administrator only. This can mess up data if you switch between charsets * that are not overlapping. */ public static function reset_db_charset() { $translated_charset = self::translate_to_mysqlcharset(AmpConfig::get('site_charset')); $target_charset = $translated_charset['charset']; $target_collation = $translated_charset['collation']; // Alter the charset for the entire database $sql = "ALTER DATABASE `" . AmpConfig::get('database_name') . "` DEFAULT CHARACTER SET {$target_charset} COLLATE {$target_collation}"; Dba::write($sql); $sql = "SHOW TABLES"; $db_results = Dba::read($sql); // Go through the tables! while ($row = Dba::fetch_row($db_results)) { $sql = "DESCRIBE `" . $row['0'] . "`"; $describe_results = Dba::read($sql); // Change the tables default charset and colliation $sql = "ALTER TABLE `" . $row['0'] . "` DEFAULT CHARACTER SET {$target_charset} COLLATE {$target_collation}"; Dba::write($sql); // Iterate through the columns of the table while ($table = Dba::fetch_assoc($describe_results)) { if (strpos($table['Type'], 'varchar') !== false || strpos($table['Type'], 'enum') !== false || strpos($table['Table'], 'text') !== false) { $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; $charset_results = Dba::write($sql); if (!$charset_results) { debug_event('CHARSET', 'Unable to update the charset of ' . $table['Field'] . '.' . $table['Type'] . ' to ' . $target_charset, '3'); } // if it fails } } } }
/** * get_now_playing * * This returns the now playing information */ public static function get_now_playing() { $sql = 'SELECT `session`.`agent`, `np`.* FROM `now_playing` AS `np` '; $sql .= 'LEFT JOIN `session` ON `session`.`id` = `np`.`id` '; if (AmpConfig::get('now_playing_per_user')) { $sql .= 'INNER JOIN ( ' . 'SELECT MAX(`insertion`) AS `max_insertion`, `user`, `id` ' . 'FROM `now_playing` ' . 'GROUP BY `user`' . ') `np2` ' . 'ON `np`.`user` = `np2`.`user` ' . 'AND `np`.`insertion` = `np2`.`max_insertion` '; } if (!Access::check('interface', '100')) { // We need to check only for users which have allowed view of personnal info $personal_info_id = Preference::id_from_name('allow_personal_info_now'); if ($personal_info_id) { $current_user = $GLOBALS['user']->id; $sql .= "WHERE (`np`.`user` IN (SELECT `user` FROM `user_preference` WHERE ((`preference`='{$personal_info_id}' AND `value`='1') OR `user`='{$current_user}'))) "; } } $sql .= 'ORDER BY `np`.`expire` DESC'; $db_results = Dba::read($sql); $results = array(); while ($row = Dba::fetch_assoc($db_results)) { $type = $row['object_type']; $media = new $type($row['object_id']); $media->format(); $client = new User($row['user']); $results[] = array('media' => $media, 'client' => $client, 'agent' => $row['agent'], 'expire' => $row['expire']); } // end while return $results; }
/** * Duplicate an object associate images to a new object * @param string $object_type * @param int $old_object_id * @param int $new_object_id * @return boolean */ public static function duplicate($object_type, $old_object_id, $new_object_id) { if (AmpConfig::get('album_art_store_disk')) { $sql = "SELECT `size`, `kind` FROM `image` WHERE `object_type` = ? AND `object_id` = ?"; $db_results = Dba::read($sql, array($object_type, $old_object_id)); while ($row = Dba::fetch_assoc($db_results)) { $image = self::read_from_dir($row['size'], $object_type, $old_object_id, $row['kind']); if ($image != null) { self::write_to_dir($image, $row['size'], $object_type, $new_object_id, $row['kind']); } } } $sql = "INSERT INTO `image` (`image`, `mime`, `size`, `object_type`, `object_id`, `kind`) SELECT `image`, `mime`, `size`, `object_type`, ? as `object_id`, `kind` FROM `image` WHERE `object_type` = ? AND `object_id` = ?"; return Dba::write($sql, array($new_object_id, $object_type, $old_object_id)); }
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; }
/** * get_random_items * * Returns a randomly sorted array (with an optional limit) of the items * output by our search (part of the playlist interface) */ public function get_random_items($limit = null) { $results = array(); $sqltbl = $this->to_sql(); $sql = $sqltbl['base'] . ' ' . $sqltbl['table_sql']; if (!empty($sqltbl['where_sql'])) { $sql .= ' WHERE ' . $sqltbl['where_sql']; } if (!empty($sqltbl['group_sql'])) { $sql .= ' GROUP BY ' . $sqltbl['group_sql']; } if (!empty($sqltbl['having_sql'])) { $sql .= ' HAVING ' . $sqltbl['having_sql']; } $sql .= ' ORDER BY RAND()'; $sql .= $limit ? ' LIMIT ' . intval($limit) : ''; $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { $results[] = array('object_id' => $row['id'], 'object_type' => $this->searchtype); } return $results; }
/** * 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']; }
/** * count * This returns the count for the all objects associated with this tag * If a type is specific only counts for said type are returned */ public function count($type = '') { $filter_sql = ""; if ($type) { $filter_sql = " AND `object_type`='" . Dba::escape($type) . "'"; } $results = array(); $sql = "SELECT COUNT(`id`) AS `count`,`object_type` FROM `tag_map` WHERE `tag_id`='" . Dba::escape($this->id) . "'" . $filter_sql . " GROUP BY `object_type`"; $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { $results[$row['object_type']] = $row['count']; } return $results; }
/** * Get broadcasts from an user. * @param int $user_id * @return int[] */ public static function get_broadcasts($user_id) { $sql = "SELECT `id` FROM `broadcast` WHERE `user` = ?"; $db_results = Dba::read($sql, array($user_id)); $broadcasts = array(); while ($results = Dba::fetch_assoc($db_results)) { $broadcasts[] = $results['id']; } return $broadcasts; }