示例#1
0
 private function getRecords($table, $field = null, $value = null)
 {
     $data = array();
     $sql = $this->assembleQuery($table, $field);
     $statement = \Dba::read($sql, is_array($value) ? $value : array($value));
     while ($object = \Dba::fetch_object($statement, $this->modelClassName)) {
         $data[$object->getId()] = $object;
     }
     return $data;
 }
示例#2
0
 /**
  * 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);
     }
 }
示例#3
0
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;
 }
示例#6
0
/**
 * 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";
}
示例#7
0
 /**
  * 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;
 }
示例#8
0
 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;
 }
示例#9
0
 /**
  * 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;
 }
示例#10
0
 /**
  * update_370028
  *
  * Add width and height in table image
  *
  */
 public static function update_370028()
 {
     $retval = true;
     $sql = "select `width` from `image`";
     $db_results = Dba::read($sql);
     if (!$db_results) {
         $sql = "ALTER TABLE `image` ADD `width` int(4) unsigned DEFAULT 0 AFTER `image`";
         $retval &= Dba::write($sql);
     }
     $sql = "select `height` from `image`";
     $db_results = Dba::read($sql);
     if (!$db_results) {
         $sql = "ALTER TABLE `image` ADD `height` int(4) unsigned DEFAULT 0 AFTER `width`";
         $retval &= Dba::write($sql);
     }
     return $retval;
 }
示例#11
0
 /**
  * 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;
 }
示例#12
0
 /**
  * check_lock_media
  *
  * This checks to see if the media is already being played.
  */
 public static function check_lock_media($media_id, $type)
 {
     $sql = 'SELECT `object_id` FROM `now_playing` WHERE ' . '`object_id` = ? AND `object_type` = ?';
     $db_results = Dba::read($sql, array($media_id, $type));
     if (Dba::num_rows($db_results)) {
         debug_event('Stream', 'Unable to play media currently locked by another user', 3);
         return false;
     }
     return true;
 }
示例#13
0
 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;
 }
示例#14
0
 /**
  * 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;
 }
示例#15
0
 /**
  * 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;
 }
示例#16
0
 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;
 }
示例#17
0
 /**
  * check_local_mp3
  * Checks the song to see if it's there already returns true if found, false if not
  */
 public function check_local_mp3($full_file, $gather_type = '')
 {
     $file_date = filemtime($full_file);
     if ($file_date < $this->last_add) {
         debug_event('Check', 'Skipping ' . $full_file . ' File modify time before last add run', '3');
         return true;
     }
     $sql = "SELECT `id` FROM `song` WHERE `file` = ?";
     $db_results = Dba::read($sql, array($full_file));
     //If it's found then return true
     if (Dba::fetch_row($db_results)) {
         return true;
     }
     return false;
 }
示例#18
0
 public function add_medias($medias, $ordered = false)
 {
     /* We need to pull the current 'end' track and then use that to
      * append, rather then integrate take end track # and add it to
      * $song->track add one to make sure it really is 'next'
      */
     $sql = "SELECT `track` FROM `playlist_data` WHERE `playlist` = ? ORDER BY `track` DESC LIMIT 1";
     $db_results = Dba::read($sql, array($this->id));
     $data = Dba::fetch_assoc($db_results);
     $base_track = $data['track'];
     debug_event('add_medias', 'Track number: ' . $base_track, '5');
     $i = 0;
     foreach ($medias as $data) {
         $media = new $data['object_type']($data['object_id']);
         // Based on the ordered prop we use track + base or just $i++
         if (!$ordered && $data['object_type'] == 'song') {
             $track = $media->track + $base_track;
         } else {
             $i++;
             $track = $base_track + $i;
         }
         /* Don't insert dead media */
         if ($media->id) {
             $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " . " VALUES (?, ?, ?, ?)";
             Dba::write($sql, array($this->id, $data['object_id'], $data['object_type'], $track));
         }
         // if valid id
     }
     // end foreach medias
 }
示例#19
0
 /**
  * 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;
 }
示例#20
0
 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;
 }
示例#21
0
 /**
  * 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'];
 }
示例#22
0
 /**
  * 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;
 }
示例#23
0
 /**
  * optimize_tables
  *
  * This runs an optimize on the tables and updates the stats to improve
  * join speed.
  * This can be slow, but is a good idea to do from time to time. We do
  * it in case the dba isn't doing it... which we're going to assume they
  * aren't.
  */
 public static function optimize_tables()
 {
     $sql = "SHOW TABLES";
     $db_results = Dba::read($sql);
     while ($row = Dba::fetch_row($db_results)) {
         $sql = "OPTIMIZE TABLE `" . $row[0] . "`";
         Dba::write($sql);
         $sql = "ANALYZE TABLE `" . $row[0] . "`";
         Dba::write($sql);
     }
 }
示例#24
0
 /**
  * get_newest
  * This returns an array of the newest artists/albums/whatever
  * in this ampache instance
  */
 public static function get_newest($type, $count = '', $offset = '', $catalog = 0)
 {
     if (!$count) {
         $count = AmpConfig::get('popular_threshold');
     }
     if (!$offset) {
         $limit = $count;
     } else {
         $limit = $offset . ',' . $count;
     }
     $sql = self::get_newest_sql($type, $catalog);
     $sql .= "LIMIT {$limit}";
     $db_results = Dba::read($sql);
     $items = array();
     while ($row = Dba::fetch_row($db_results)) {
         $items[] = $row[0];
     }
     // end while results
     return $items;
 }
示例#25
0
 /**
  * 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));
 }
示例#26
0
 /**
  * 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;
 }
示例#27
0
 /**
  * save
  *
  * Save this search to the database for use as a smart playlist
  */
 public function save()
 {
     // Make sure we have a unique name
     if (!$this->name) {
         $this->name = $GLOBALS['user']->username . ' - ' . date('Y-m-d H:i:s', time());
     }
     $sql = "SELECT `id` FROM `search` WHERE `name` = ?";
     $db_results = Dba::read($sql, array($this->name));
     if (Dba::num_rows($db_results)) {
         $this->name .= uniqid('', true);
     }
     $sql = "INSERT INTO `search` (`name`, `type`, `user`, `rules`, `logic_operator`, `random`, `limit`) VALUES (?, ?, ?, ?, ?, ?, ?)";
     Dba::write($sql, array($this->name, $this->type, $GLOBALS['user']->id, serialize($this->rules), $this->logic_operator, $this->random, $this->limit));
     $insert_id = Dba::insert_id();
     $this->id = $insert_id;
     return $insert_id;
 }
示例#28
0
 /**
  * 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');
 }
示例#29
0
 /**
  * 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;
 }
示例#30
0
 /**
  * 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'];
 }