Exemple #1
0
 /**
  * toggle_follow
  * @param integer $user_id
  * @return boolean
  */
 public function toggle_follow($user_id)
 {
     if (!$user_id || $user_id === $this->id) {
         return false;
     }
     $params = array($this->id, $user_id);
     if ($this->is_following($user_id)) {
         $sql = "DELETE FROM `user_follower` WHERE `user` = ? AND `follow_user` = ?";
     } else {
         $sql = "INSERT INTO `user_follower` (`user`, `follow_user`, `follow_date`) VALUES (?, ?, ?)";
         $params[] = time();
         Useractivity::post_activity($this->id, 'follow', 'user', $user_id);
     }
     return Dba::write($sql, $params);
 }
Exemple #2
0
 /**
  * insert
  * This inserts a new record for the specified object
  * with the specified information, amazing!
  */
 public static function insert($type, $oid, $user, $agent = '', $location, $count_type = 'stream')
 {
     if (!self::is_already_inserted($type, $oid, $user)) {
         $type = self::validate_type($type);
         $latitude = null;
         $longitude = null;
         $geoname = null;
         if (isset($location['latitude'])) {
             $latitude = $location['latitude'];
         }
         if (isset($location['longitude'])) {
             $longitude = $location['longitude'];
         }
         if (isset($location['name'])) {
             $geoname = $location['name'];
         }
         $sql = "INSERT INTO `object_count` (`object_type`,`object_id`,`count_type`,`date`,`user`,`agent`, `geo_latitude`, `geo_longitude`, `geo_name`) " . " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
         $db_results = Dba::write($sql, array($type, $oid, $count_type, time(), $user, $agent, $latitude, $longitude, $geoname));
         if (Core::is_media($type)) {
             Useractivity::post_activity($user, 'play', $type, $oid);
         }
         if (!$db_results) {
             debug_event('statistics', 'Unabled to insert statistics:' . $sql, '3');
         }
     } else {
         debug_event('statistics', 'Statistics insertion ignored due to graceful delay.', '3');
     }
 }
Exemple #3
0
 /**
  * insert
  *
  * This inserts the song described by the passed array
  * @param array $results
  * @return int|boolean
  */
 public static function insert(array $results)
 {
     $catalog = $results['catalog'];
     $file = $results['file'];
     $title = trim($results['title']) ?: $file;
     $artist = $results['artist'];
     $album = $results['album'];
     $albumartist = $results['albumartist'] ?: $results['band'];
     $albumartist = $albumartist ?: null;
     $bitrate = $results['bitrate'] ?: 0;
     $rate = $results['rate'] ?: 0;
     $mode = $results['mode'];
     $size = $results['size'] ?: 0;
     $time = $results['time'] ?: 0;
     $track = $results['track'];
     $track_mbid = $results['mb_trackid'] ?: $results['mbid'];
     $track_mbid = $track_mbid ?: null;
     $album_mbid = $results['mb_albumid'];
     $album_mbid_group = $results['mb_albumid_group'];
     $artist_mbid = $results['mb_artistid'];
     $albumartist_mbid = $results['mb_albumartistid'];
     $disk = $results['disk'] ?: 0;
     $year = Catalog::normalize_year($results['year'] ?: 0);
     $comment = $results['comment'];
     $tags = $results['genre'];
     // multiple genre support makes this an array
     $lyrics = $results['lyrics'];
     $user_upload = isset($results['user_upload']) ? $results['user_upload'] : null;
     $license = isset($results['license']) ? $results['license'] : null;
     $composer = isset($results['composer']) ? $results['composer'] : null;
     $label = isset($results['publisher']) ? $results['publisher'] : null;
     $catalog_number = isset($results['catalog_number']) ? $results['catalog_number'] : null;
     $language = isset($results['language']) ? $results['language'] : null;
     $channels = $results['channels'] ?: 0;
     $release_type = isset($results['release_type']) ? $results['release_type'] : null;
     $replaygain_track_gain = isset($results['replaygain_track_gain']) ? $results['replaygain_track_gain'] : null;
     $replaygain_track_peak = isset($results['replaygain_track_peak']) ? $results['replaygain_track_peak'] : null;
     $replaygain_album_gain = isset($results['replaygain_album_gain']) ? $results['replaygain_album_gain'] : null;
     $replaygain_album_peak = isset($results['replaygain_album_peak']) ? $results['replaygain_album_peak'] : null;
     $albumartist_id = null;
     if (!isset($results['albumartist_id'])) {
         if ($albumartist) {
             $albumartist_id = Artist::check($albumartist, $albumartist_mbid);
         }
     } else {
         $albumartist_id = intval($results['albumartist_id']);
     }
     $artist_id = null;
     if (!isset($results['artist_id'])) {
         $artist_id = Artist::check($artist, $artist_mbid);
     } else {
         $artist_id = intval($results['artist_id']);
     }
     $album_id = null;
     if (!isset($results['album_id'])) {
         $album_id = Album::check($album, $year, $disk, $album_mbid, $album_mbid_group, $albumartist_id, $release_type);
     } else {
         $album_id = intval($results['album_id']);
     }
     $sql = 'INSERT INTO `song` (`file`, `catalog`, `album`, `artist`, ' . '`title`, `bitrate`, `rate`, `mode`, `size`, `time`, `track`, ' . '`addition_time`, `year`, `mbid`, `user_upload`, `license`, ' . '`composer`, `channels`) ' . 'VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
     $db_results = Dba::write($sql, array($file, $catalog, $album_id, $artist_id, $title, $bitrate, $rate, $mode, $size, $time, $track, time(), $year, $track_mbid, $user_upload, $license, $composer, $channels));
     if (!$db_results) {
         debug_event('song', 'Unable to insert ' . $file, 2);
         return false;
     }
     $song_id = Dba::insert_id();
     if ($user_upload) {
         Useractivity::post_activity($this->id, 'upload', 'song', $song_id);
     }
     if (is_array($tags)) {
         // Allow scripts to populate new tags when injecting user uploads
         if (!defined('NO_SESSION')) {
             if ($user_upload && !Access::check('interface', 50, $user_upload)) {
                 $tags = Tag::clean_to_existing($tags);
             }
         }
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if (!empty($tag)) {
                 Tag::add('song', $song_id, $tag, false);
                 Tag::add('album', $album_id, $tag, false);
                 Tag::add('artist', $artist_id, $tag, false);
             }
         }
     }
     $sql = 'INSERT INTO `song_data` (`song_id`, `comment`, `lyrics`, `label`, `language`, `catalog_number`, `replaygain_track_gain`, `replaygain_track_peak`, `replaygain_album_gain`, `replaygain_album_peak`) ' . 'VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
     Dba::write($sql, array($song_id, $comment, $lyrics, $label, $language, $catalog_number, $replaygain_track_gain, $replaygain_track_peak, $replaygain_album_gain, $replaygain_album_peak));
     return $song_id;
 }
Exemple #4
0
 /**
  * set_flag
  * This function sets the user flag for the current object.
  * If no userid is passed in, we use the currently logged in user.
  */
 public function set_flag($flagged, $user_id = null)
 {
     if ($user_id === null) {
         $user_id = $GLOBALS['user']->id;
     }
     $user_id = intval($user_id);
     debug_event('Userflag', "Setting userflag for {$this->type} {$this->id} to {$flagged}", 5);
     if (!$flagged) {
         $sql = "DELETE FROM `user_flag` WHERE " . "`object_id` = ? AND " . "`object_type` = ? AND " . "`user` = ?";
         $params = array($this->id, $this->type, $user_id);
     } else {
         $sql = "REPLACE INTO `user_flag` " . "(`object_id`, `object_type`, `user`, `date`) " . "VALUES (?, ?, ?, ?)";
         $params = array($this->id, $this->type, $user_id, time());
         Useractivity::post_activity($user_id, 'userflag', $this->type, $this->id);
     }
     Dba::write($sql, $params);
     parent::add_to_cache('userflag_' . $this->type . '_user' . $user_id, $this->id, $flagged);
     // Forward flag to last.fm and Libre.fm (song only)
     if ($this->type == 'song') {
         $user = new User($user_id);
         $song = new Song($this->id);
         if ($song) {
             $song->format();
             foreach (Plugin::get_plugins('save_mediaplay') as $plugin_name) {
                 try {
                     $plugin = new Plugin($plugin_name);
                     if ($plugin->load($user)) {
                         $plugin->_plugin->set_flag($song, $flagged);
                     }
                 } catch (Exception $e) {
                     debug_event('user.class.php', 'Stats plugin error: ' . $e->getMessage(), '1');
                 }
             }
         }
     }
     return true;
 }
Exemple #5
0
 /**
  * create
  * This takes a key'd array of data as input and inserts a new shoutbox entry, it returns the auto_inc id
  */
 public static function create(array $data)
 {
     if (!Core::is_library_item($data['object_type'])) {
         return false;
     }
     $sticky = isset($data['sticky']) ? 1 : 0;
     $user = intval($data['user'] ?: $GLOBALS['user']->id);
     $date = intval($data['date'] ?: time());
     $comment = strip_tags($data['comment']);
     $sql = "INSERT INTO `user_shout` (`user`,`date`,`text`,`sticky`,`object_id`,`object_type`, `data`) " . "VALUES (? , ?, ?, ?, ?, ?, ?)";
     Dba::write($sql, array($user, $date, $comment, $sticky, $data['object_id'], $data['object_type'], $data['data']));
     Useractivity::post_activity($user, 'shout', $data['object_type'], $data['object_id']);
     $insert_id = Dba::insert_id();
     // Never send email in case of user impersonation
     if (!isset($data['user']) && $insert_id) {
         $libitem = new $data['object_type']($data['object_id']);
         $item_owner_id = $libitem->get_user_owner();
         if ($item_owner_id) {
             if (Preference::get_by_user($item_owner_id, 'notify_email')) {
                 $item_owner = new User($item_owner_id);
                 if (!empty($item_owner->email)) {
                     $libitem->format();
                     $mailer = new Mailer();
                     $mailer->set_default_sender();
                     $mailer->recipient = $item_owner->email;
                     $mailer->recipient_name = $item_owner->fullname;
                     $mailer->subject = T_('New shout on your content');
                     $mailer->message = sprintf(T_("You just received a new shout from %s on your content `%s`.\n\n\n    ----------------------\n    %s\n    ----------------------\n\n    %s\n    "), $GLOBALS['user']->fullname, $libitem->get_fullname(), $comment, AmpConfig::get('web_path') . "/shout.php?action=show_add_shout&type=" . $data['object_type'] . "&id=" . $data['object_id'] . "#shout" . $insert_id);
                     $mailer->send();
                 }
             }
         }
     }
     return $insert_id;
 }