本文整理汇总了PHP中Song::format方法的典型用法代码示例。如果您正苦于以下问题:PHP Song::format方法的具体用法?PHP Song::format怎么用?PHP Song::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Song
的用法示例。
在下文中一共展示了Song::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_media_files
/**
* get_media_files
*
* Takes an array of media ids and returns an array of the actual filenames
*
* @param array $media_ids Media IDs.
*/
function get_media_files($media_ids)
{
$media_files = array();
$total_size = 0;
foreach ($media_ids as $element) {
if (is_array($element)) {
if (isset($element['object_type'])) {
$type = $element['object_type'];
$id = $element['object_id'];
} else {
$type = array_shift($element);
$id = array_shift($element);
}
$media = new $type($id);
} else {
$media = new Song($element);
}
if ($media->enabled) {
$media->format();
$total_size += sprintf("%.2f", $media->size / 1048576);
$dirname = '';
$parent = $media->get_parent();
if ($parent != null) {
$pobj = new $parent['object_type']($parent['object_id']);
$pobj->format();
$dirname = $pobj->get_fullname();
}
if (!array_key_exists($dirname, $media_files)) {
$media_files[$dirname] = array();
}
array_push($media_files[$dirname], Core::conv_lc_file($media->file));
}
}
return array($media_files, $total_size);
}
示例2: get
/**
* Get a song waveform.
* @param int $song_id
* @return binary|string|null
*/
public static function get($song_id)
{
$song = new Song($song_id);
$waveform = null;
if ($song->id) {
$song->format();
$waveform = $song->waveform;
if (!$waveform) {
$catalog = Catalog::create_from_id($song->catalog);
if ($catalog->get_type() == 'local') {
$transcode_to = 'wav';
$transcode_cfg = AmpConfig::get('transcode');
$valid_types = $song->get_stream_types();
if ($song->type != $transcode_to) {
$basedir = AmpConfig::get('tmp_dir_path');
if ($basedir) {
if ($transcode_cfg != 'never' && in_array('transcode', $valid_types)) {
$tmpfile = tempnam($basedir, $transcode_to);
$tfp = fopen($tmpfile, 'wb');
if (!is_resource($tfp)) {
debug_event('waveform', "Failed to open " . $tmpfile, 3);
return null;
}
$transcoder = Stream::start_transcode($song, $transcode_to);
$fp = $transcoder['handle'];
if (!is_resource($fp)) {
debug_event('waveform', "Failed to open " . $song->file . " for waveform.", 3);
return null;
}
do {
$buf = fread($fp, 2048);
fwrite($tfp, $buf);
} while (!feof($fp));
fclose($fp);
fclose($tfp);
Stream::kill_process($transcoder);
$waveform = self::create_waveform($tmpfile);
//$waveform = self::create_waveform("C:\\tmp\\test.wav");
@unlink($tmpfile);
} else {
debug_event('waveform', 'transcode setting to wav required for waveform.', '3');
}
} else {
debug_event('waveform', 'tmp_dir_path setting required for waveform.', '3');
}
} else {
$waveform = self::create_waveform($song->file);
}
}
if ($waveform) {
self::save_to_db($song_id, $waveform);
}
}
}
return $waveform;
}
示例3: get_current_slideshow
public static function get_current_slideshow()
{
$songs = Song::get_recently_played($GLOBALS['user']->id);
$images = array();
if (count($songs) > 0) {
$last_song = new Song($songs[0]['object_id']);
$last_song->format();
$images = self::get_images($last_song->f_artist);
}
return $images;
}
示例4: get_song_files
/**
* get_song_files
*
* Takes an array of song ids and returns an array of the actual filenames
*
* @param array $media_ids Media IDs.
*/
function get_song_files($media_ids)
{
$media_files = array();
$total_size = 0;
foreach ($media_ids as $element) {
if (is_array($element)) {
$type = array_shift($element);
$media = new $type(array_shift($element));
} else {
$media = new Song($element);
}
if ($media->enabled) {
$total_size += sprintf("%.2f", $media->size / 1048576);
$media->format();
$dirname = $media->f_album_full;
//debug_event('batch.lib.php', 'Songs file {'.$media->file.'}...', '5');
if (!array_key_exists($dirname, $media_files)) {
$media_files[$dirname] = array();
}
array_push($media_files[$dirname], $media->file);
}
}
return array($media_files, $total_size);
}
示例5: get_media_js_param
/**
* Get media javascript parameters.
* @param \playable_item $item
* @param string $force_type
* @return string
*/
public static function get_media_js_param($item, $force_type = '')
{
$js = array();
foreach (array('title', 'author') as $member) {
if ($member == "author") {
$kmember = "artist";
} else {
$kmember = $member;
}
$js[$kmember] = $item->{$member};
}
$url = $item->url;
$types = self::get_types($item, $force_type);
$media = null;
$urlinfo = Stream_URL::parse($url);
$url = $urlinfo['base_url'];
if ($urlinfo['id'] && Core::is_media($urlinfo['type'])) {
$media = new $urlinfo['type']($urlinfo['id']);
} else {
if ($urlinfo['id'] && $urlinfo['type'] == 'song_preview') {
$media = new Song_Preview($urlinfo['id']);
} else {
if (isset($urlinfo['demo_id'])) {
$democratic = new Democratic($urlinfo['demo_id']);
if ($democratic->id) {
$song_id = $democratic->get_next_object();
if ($song_id) {
$media = new Song($song_id);
}
}
}
}
}
if ($media != null) {
$media->format();
if ($urlinfo['type'] == 'song') {
$js['artist_id'] = $media->artist;
$js['album_id'] = $media->album;
$js['replaygain_track_gain'] = $media->replaygain_track_gain;
$js['replaygain_track_peak'] = $media->replaygain_track_peak;
$js['replaygain_album_gain'] = $media->replaygain_album_gain;
$js['replaygain_album_peak'] = $media->replaygain_album_peak;
}
$js['media_id'] = $media->id;
if ($media->type != $types['real']) {
$url .= '&transcode_to=' . $types['real'];
}
//$url .= "&content_length=required";
}
$js['filetype'] = $types['player'];
$js['url'] = $url;
if ($urlinfo['type'] == 'song') {
$js['poster'] = $item->image_url;
}
debug_event("webplayer.class.php", "Return get_media_js_param {" . json_encode($js) . "}", 5);
return json_encode($js);
}
示例6: Song
$rtype = $type;
}
$oid = Random::get_single_song($rtype);
if ($oid) {
// Save this one in case we do a seek
$_SESSION['random']['last'] = $oid;
}
} else {
$oid = $_SESSION['random']['last'];
}
}
// if random
if ($type == 'song') {
/* Base Checks passed create the song object */
$media = new Song($oid);
$media->format();
} else {
if ($type == 'song_preview') {
$media = new Song_Preview($oid);
$media->format();
} else {
$type = 'video';
$media = new Video($oid);
if (isset($_REQUEST['subtitle'])) {
$subtitle = $media->get_subtitle_file($_REQUEST['subtitle']);
}
$media->format();
}
}
if (!User::stream_control(array(array('object_type' => $type, 'object_id' => $media->id)))) {
debug_event('UI::access_denied', 'Stream control failed for user ' . $GLOBALS['user']->username . ' on ' . $media->get_stream_name(), 3);
示例7: addPlaylistsItems
private static function addPlaylistsItems(SimpleXMLElement $xml, $items, $itemIDName = 'playlistItemID')
{
foreach ($items as $item) {
$xitem = null;
if ($item['object_type'] == 'song') {
$media = new Song($item['object_id']);
$media->format();
$xitem = self::addSong($xml, $media);
} elseif ($item['object_type'] == 'video') {
$media = Video::create_from_id($item['object_id']);
$media->format();
$xitem = self::addVideoExt($xml, $media);
}
if ($xitem != null) {
if (isset($item['track_id'])) {
$xitem->addAttribute($itemIDName, $item['track_id']);
}
}
}
}
示例8: format
/**
* format
* this function takes the object and reformats some values
*/
public function format($details = true)
{
parent::format($details);
if ($details) {
if ($this->artist) {
$artist = new Artist($this->artist);
$artist->format();
$this->f_artist = $artist->link;
}
if ($this->song) {
$song = new Song($this->song);
$song->format();
$this->f_song = $song->f_link;
}
}
return true;
}
示例9: _setCustomView
protected static function _setCustomView($xml, $data)
{
foreach ($data as $key => $value) {
foreach ($value as $id) {
if ($key == 'artist') {
$artist = new Artist($id);
$artist->format();
self::addArtist($xml, $artist);
} elseif ($key == 'album') {
$album = new Album($id);
$album->format();
self::addAlbum($xml, $album);
} elseif ($key == 'song') {
$song = new Song($id);
$song->format();
self::addSong($xml, $song);
}
}
}
}
示例10: get_favorites
/**
* get_favorites
* returns an array of your $type favorites
*/
public function get_favorites($type)
{
$results = Stats::get_user(AmpConfig::get('popular_threshold'), $type, $this->id, 1);
$items = array();
foreach ($results as $r) {
/* If its a song */
if ($type == 'song') {
$data = new Song($r['object_id']);
$data->count = $r['count'];
$data->format();
$data->f_link;
$items[] = $data;
} elseif ($type == 'album') {
$data = new Album($r['object_id']);
//$data->count = $r['count'];
$data->format();
$items[] = $data;
} elseif ($type == 'artist') {
$data = new Artist($r['object_id']);
//$data->count = $r['count'];
$data->format();
$data->f_name = $data->f_link;
$items[] = $data;
} elseif ($type == 'genre') {
$data = new Genre($r['object_id']);
//$data->count = $r['count'];
$data->format();
$data->f_name = $data->f_link;
$items[] = $data;
}
}
// end foreach
return $items;
}
示例11: load_recently_played
/**
* load_recently_played
* This loads in the recently played information and formats it up real nice like
* @return array
*/
public static function load_recently_played()
{
//FIXME: The time stuff should be centralized, it's currently in two places, lame
$time_unit = array('', T_('seconds ago'), T_('minutes ago'), T_('hours ago'), T_('days ago'), T_('weeks ago'), T_('months ago'), T_('years ago'));
$data = Song::get_recently_played();
$results = array();
foreach ($data as $item) {
$client = new User($item['user']);
$song = new Song($item['object_id']);
$song->format();
$amount = intval(time() - $item['date'] + 2);
$final = '0';
$time_place = '0';
while ($amount >= 1) {
$final = $amount;
$time_place++;
if ($time_place <= 2) {
$amount = floor($amount / 60);
}
if ($time_place == '3') {
$amount = floor($amount / 24);
}
if ($time_place == '4') {
$amount = floor($amount / 7);
}
if ($time_place == '5') {
$amount = floor($amount / 4);
}
if ($time_place == '6') {
$amount = floor($amount / 12);
}
if ($time_place > '6') {
$final = $amount . '+';
break;
}
}
// end while
$time_string = $final . ' ' . $time_unit[$time_place];
$xml_array = array('title' => $song->f_title . ' - ' . $song->f_artist . ' - ' . $song->f_album, 'link' => str_replace('&', '&', $song->link), 'description' => $song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full . ' - ' . $time_string, 'comments' => $client->username, 'pubDate' => date("r", $item['date']));
$results[] = $xml_array;
}
// end foreach
return $results;
}
示例12: _musicChilds
public static function _musicChilds($prmPath, $prmQuery, $start, $count)
{
$mediaItems = array();
$maxCount = 0;
$queryData = array();
parse_str($prmQuery, $queryData);
$parent = 'amp://music' . $prmPath;
$pathreq = explode('/', $prmPath);
if ($pathreq[0] == '' && count($pathreq) > 0) {
array_shift($pathreq);
}
switch ($pathreq[0]) {
case 'artists':
switch (count($pathreq)) {
case 1:
// Get artists list
//$artists = Catalog::get_artists();
//list($maxCount, $artists) = self::_slice($artists, $start, $count);
$artists = Catalog::get_artists(null, $count, $start);
list($maxCount, $artists) = array(999999, $artists);
foreach ($artists as $artist) {
$artist->format();
$mediaItems[] = self::_itemArtist($artist, $parent);
}
break;
case 2:
// Get artist's albums list
$artist = new Artist($pathreq[1]);
if ($artist->id) {
$album_ids = $artist->get_albums();
list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count);
foreach ($album_ids as $album_id) {
$album = new Album($album_id);
$album->format();
$mediaItems[] = self::_itemAlbum($album, $parent);
}
}
break;
}
break;
case 'albums':
switch (count($pathreq)) {
case 1:
// Get albums list
//!!$album_ids = Catalog::get_albums();
//!!list($maxCount, $album_ids) = self::_slice($album_ids, $start, $count);
$album_ids = Catalog::get_albums($count, $start);
list($maxCount, $album_ids) = array(999999, $album_ids);
foreach ($album_ids as $album_id) {
$album = new Album($album_id);
$album->format();
$mediaItems[] = self::_itemAlbum($album, $parent);
}
break;
case 2:
// Get album's songs list
$album = new Album($pathreq[1]);
if ($album->id) {
$song_ids = $album->get_songs();
list($maxCount, $song_ids) = self::_slice($song_ids, $start, $count);
foreach ($song_ids as $song_id) {
$song = new Song($song_id);
$song->format();
$mediaItems[] = self::_itemSong($song, $parent);
}
}
break;
}
break;
case 'songs':
switch (count($pathreq)) {
case 1:
// Get songs list
$catalogs = Catalog::get_catalogs();
foreach ($catalogs as $catalog_id) {
$catalog = Catalog::create_from_id($catalog_id);
$songs = $catalog->get_songs();
list($maxCount, $songs) = self::_slice($songs, $start, $count);
foreach ($songs as $song) {
$song->format();
$mediaItems[] = self::_itemSong($song, $parent);
}
}
break;
}
break;
case 'playlists':
switch (count($pathreq)) {
case 1:
// Get playlists list
$pl_ids = Playlist::get_playlists();
list($maxCount, $pl_ids) = self::_slice($pl_ids, $start, $count);
foreach ($pl_ids as $pl_id) {
$playlist = new Playlist($pl_id);
$playlist->format();
$mediaItems[] = self::_itemPlaylist($playlist, $parent);
}
break;
case 2:
// Get playlist's songs list
//.........这里部分代码省略.........
示例13: set_flag
/**
* 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;
}
示例14: songs
/**
* songs
*
* This returns an xml document from an array of song ids.
* (Spiffy isn't it!)
*/
public static function songs($songs, $playlist_data = '')
{
if (count($songs) > self::$limit or self::$offset > 0) {
$songs = array_slice($songs, self::$offset, self::$limit);
}
Song::build_cache($songs);
Stream::set_session($_REQUEST['auth']);
$string = "";
// Foreach the ids!
foreach ($songs as $song_id) {
$song = new Song($song_id);
// If the song id is invalid/null or disabled
if (!$song->id || !$song->enabled) {
continue;
}
$song->format();
$playlist_track_string = self::playlist_song_tracks_string($song, $playlist_data);
$tag_string = self::tags_string(Tag::get_top_tags('song', $song_id));
$rating = new Rating($song_id, 'song');
$art_url = Art::url($song->album, 'album', $_REQUEST['auth']);
$string .= "<song id=\"" . $song->id . "\">\n" . "\t<title><![CDATA[" . $song->title . "]]></title>\n" . "\t<artist id=\"" . $song->artist . '"><![CDATA[' . $song->get_artist_name() . "]]></artist>\n" . "\t<album id=\"" . $song->album . '"><![CDATA[' . $song->get_album_name() . "]]></album>\n";
if ($song->albumartist) {
$string .= "\t<albumartist id=\"" . $song->albumartist . "\"><![CDATA[" . $song->get_album_artist_name() . "]]></albumartist>\n";
}
$string .= $tag_string . "\t<filename><![CDATA[" . $song->file . "]]></filename>\n" . "\t<track>" . $song->track . "</track>\n" . $playlist_track_string . "\t<time>" . $song->time . "</time>\n" . "\t<year>" . $song->year . "</year>\n" . "\t<bitrate>" . $song->bitrate . "</bitrate>\n" . "\t<rate>" . $song->rate . "</rate>\n" . "\t<mode>" . $song->mode . "</mode>\n" . "\t<mime>" . $song->mime . "</mime>\n" . "\t<url><![CDATA[" . Song::play_url($song->id, '', 'api') . "]]></url>\n" . "\t<size>" . $song->size . "</size>\n" . "\t<mbid>" . $song->mbid . "</mbid>\n" . "\t<album_mbid>" . $song->album_mbid . "</album_mbid>\n" . "\t<artist_mbid>" . $song->artist_mbid . "</artist_mbid>\n" . "\t<albumartist_mbid>" . $song->albumartist_mbid . "</albumartist_mbid>\n" . "\t<art><![CDATA[" . $art_url . "]]></art>\n" . "\t<preciserating>" . ($rating->get_user_rating() ?: 0) . "</preciserating>\n" . "\t<rating>" . ($rating->get_user_rating() ?: 0) . "</rating>\n" . "\t<averagerating>" . ($rating->get_average_rating() ?: 0) . "</averagerating>\n" . "\t<composer>" . $song->composer . "</composer>\n" . "\t<channels>" . $song->channels . "</channels>\n" . "\t<comment><![CDATA[" . $song->comment . "]]></comment>\n";
$string .= "\t<publisher><![CDATA[" . $song->label . "]]></publisher>\n" . "\t<language>" . $song->language . "</language>\n" . "\t<replaygain_album_gain>" . $song->replaygain_album_gain . "</replaygain_album_gain>\n" . "\t<replaygain_album_peak>" . $song->replaygain_album_peak . "</replaygain_album_peak>\n" . "\t<replaygain_track_gain>" . $song->replaygain_track_gain . "</replaygain_track_gain>\n" . "\t<replaygain_track_peak>" . $song->replaygain_track_peak . "</replaygain_track_peak>\n";
foreach ($song->tags as $tag) {
$string .= "\t<genre><![CDATA[" . $tag['name'] . "]]></genre>\n";
}
$string .= "</song>\n";
}
// end foreach
return self::_header() . $string . self::_footer();
}
示例15: write_id3_for_song
/**
* write_id3_for_song
* Write id3 metadata to the file for the excepted song id
* @param int $song_id
*/
public static function write_id3_for_song($song_id)
{
$song = new Song($song_id);
if ($song->id) {
$song->format();
$song->write_id3();
}
}