예제 #1
0
 /**
  * democratic
  * This is for controlling democratic play
  */
 public static function democratic($input)
 {
     // Load up democratic information
     $democratic = Democratic::get_current_playlist();
     $democratic->set_parent();
     switch ($input['method']) {
         case 'vote':
             $type = 'song';
             $media = new $type($input['oid']);
             if (!$media->id) {
                 echo XML_Data::error('400', T_('Media Object Invalid or Not Specified'));
                 break;
             }
             $democratic->add_vote(array(array('object_type' => 'song', 'object_id' => $media->id)));
             // If everything was ok
             $xml_array = array('action' => $input['action'], 'method' => $input['method'], 'result' => true);
             echo XML_Data::keyed_array($xml_array);
             break;
         case 'devote':
             $type = 'song';
             $media = new $type($input['oid']);
             if (!$media->id) {
                 echo XML_Data::error('400', T_('Media Object Invalid or Not Specified'));
             }
             $uid = $democratic->get_uid_from_object_id($media->id, $type);
             $democratic->remove_vote($uid);
             // Everything was ok
             $xml_array = array('action' => $input['action'], 'method' => $input['method'], 'result' => true);
             echo XML_Data::keyed_array($xml_array);
             break;
         case 'playlist':
             $objects = $democratic->get_items();
             Song::build_cache($democratic->object_ids);
             Democratic::build_vote_cache($democratic->vote_ids);
             XML_Data::democratic($objects);
             break;
         case 'play':
             $url = $democratic->play_url();
             $xml_array = array('url' => $url);
             echo XML_Data::keyed_array($xml_array);
             break;
         default:
             echo XML_Data::error('405', T_('Invalid Request'));
             break;
     }
     // switch on method
 }
예제 #2
0
 /**
  * create_xspf
  */
 public function create_xspf()
 {
     $result = "";
     foreach ($this->urls as $url) {
         $xml = array();
         $xml['track'] = array('title' => $url->title, 'creator' => $url->author, 'duration' => $url->time * 1000, 'location' => $url->url, 'identifier' => $url->url);
         if ($url->type == 'video') {
             $xml['track']['meta'] = array('attribute' => 'rel="provider"', 'value' => 'video');
         }
         if ($url->info_url) {
             $xml['track']['info'] = $url->info_url;
         }
         if ($url->image_url) {
             $xml['track']['image'] = $url->image_url;
         }
         if ($url->album) {
             $xml['track']['album'] = $url->album;
         }
         $result .= XML_Data::keyed_array($xml, true);
     }
     // end foreach
     XML_Data::set_type('xspf');
     echo XML_Data::header();
     echo $result;
     echo XML_Data::footer();
 }