コード例 #1
0
ファイル: auth.class.php プロジェクト: axelsimon/ampache
 /**
  * logout
  *
  * This is called when you want to log out and nuke your session.
  * This is the function used for the Ajax logouts, if no id is passed
  * it tries to find one from the session,
  */
 public static function logout($key = '', $relogin = true)
 {
     // If no key is passed try to find the session id
     $key = $key ? $key : session_id();
     // Nuke the cookie before all else
     Session::destroy($key);
     if (!$relogin && AmpConfig::get('logout_redirect')) {
         $target = AmpConfig::get('logout_redirect');
     } else {
         $target = AmpConfig::get('web_path') . '/login.php';
     }
     // Do a quick check to see if this is an AJAXed logout request
     // if so use the iframe to redirect
     if (defined('AJAX_INCLUDE')) {
         ob_end_clean();
         ob_start();
         xoutput_headers();
         $results = array();
         $results['rfc3514'] = '<script type="text/javascript">reloadRedirect("' . $target . '")</script>';
         echo xoutput_from_array($results);
     } else {
         /* Redirect them to the login page */
         header('Location: ' . $target);
     }
     exit;
 }
コード例 #2
0
ファイル: random.ajax.php プロジェクト: cheese1/ampache
        foreach ($items as $item) {
            $GLOBALS['user']->playlist->add_object($item['object_id'], $item['object_type']);
        }
        $results['rightbar'] = UI::ajax_include('rightbar.inc.php');
        break;
    case 'advanced_random':
        $object_ids = Random::advanced('song', $_POST);
        // First add them to the active playlist
        if (is_array($object_ids)) {
            foreach ($object_ids as $object_id) {
                $GLOBALS['user']->playlist->add_object($object_id, 'song');
            }
        }
        $results['rightbar'] = UI::ajax_include('rightbar.inc.php');
        // Now setup the browse and show them below!
        $browse = new Browse();
        $browse->set_type('song');
        $browse->save_objects($object_ids);
        ob_start();
        $browse->show_objects();
        $results['browse'] = ob_get_contents();
        ob_end_clean();
        break;
    default:
        $results['rfc3514'] = '0x1';
        break;
}
// switch on action;
// We always do this
echo xoutput_from_array($results);
コード例 #3
0
ファイル: ui.lib.php プロジェクト: cheese1/ampache
/**
 * xml_from_array
 * This takes a one dimensional array and creates a XML document from it. For
 * use primarily by the ajax mojo.
 */
function xml_from_array($array, $callback = false, $type = '')
{
    $string = '';
    // If we weren't passed an array then return
    if (!is_array($array)) {
        return $string;
    }
    // The type is used for the different XML docs we pass
    switch ($type) {
        case 'itunes':
            foreach ($array as $key => $value) {
                if (is_array($value)) {
                    $value = xoutput_from_array($value, true, $type);
                    $string .= "\t\t<{$key}>\n{$value}\t\t</{$key}>\n";
                } else {
                    if ($key == "key") {
                        $string .= "\t\t<{$key}>{$value}</{$key}>\n";
                    } elseif (is_int($value)) {
                        $string .= "\t\t\t<key>{$key}</key><integer>{$value}</integer>\n";
                    } elseif ($key == "Date Added") {
                        $string .= "\t\t\t<key>{$key}</key><date>{$value}</date>\n";
                    } elseif (is_string($value)) {
                        /* We need to escape the value */
                        $string .= "\t\t\t<key>{$key}</key><string><![CDATA[{$value}]]></string>\n";
                    }
                }
            }
            // end foreach
            return $string;
        case 'xspf':
            foreach ($array as $key => $value) {
                if (is_array($value)) {
                    $value = xoutput_from_array($value, true, $type);
                    $string .= "\t\t<{$key}>\n{$value}\t\t</{$key}>\n";
                } else {
                    if ($key == "key") {
                        $string .= "\t\t<{$key}>{$value}</{$key}>\n";
                    } elseif (is_numeric($value)) {
                        $string .= "\t\t\t<{$key}>{$value}</{$key}>\n";
                    } elseif (is_string($value)) {
                        /* We need to escape the value */
                        $string .= "\t\t\t<{$key}><![CDATA[{$value}]]></{$key}>\n";
                    }
                }
            }
            // end foreach
            return $string;
        default:
            foreach ($array as $key => $value) {
                // No numeric keys
                if (is_numeric($key)) {
                    $key = 'item';
                }
                if (is_array($value)) {
                    // Call ourself
                    $value = xoutput_from_array($value, true);
                    $string .= "\t<content div=\"{$key}\">{$value}</content>\n";
                } else {
                    /* We need to escape the value */
                    $string .= "\t<content div=\"{$key}\"><![CDATA[{$value}]]></content>\n";
                }
                // end foreach elements
            }
            if (!$callback) {
                $string = '<?xml version="1.0" encoding="utf-8" ?>' . "\n<root>\n" . $string . "</root>\n";
            }
            return UI::clean_utf8($string);
    }
}
コード例 #4
0
ファイル: catalog.class.php プロジェクト: axelsimon/ampache
 /**
  * exports the catalog
  * it exports all songs in the database to the given export type.
  */
 public static function export($type, $catalog_id = '')
 {
     // Select all songs in catalog
     $params = array();
     if ($catalog_id) {
         $sql = 'SELECT `id` FROM `song` ' . "WHERE `catalog`= ? " . 'ORDER BY `album`, `track`';
         $params[] = $catalog_id;
     } else {
         $sql = 'SELECT `id` FROM `song` ORDER BY `album`, `track`';
     }
     $db_results = Dba::read($sql, $params);
     switch ($type) {
         case 'itunes':
             echo xml_get_header('itunes');
             while ($results = Dba::fetch_assoc($db_results)) {
                 $song = new Song($results['id']);
                 $song->format();
                 $xml = array();
                 $xml['key'] = $results['id'];
                 $xml['dict']['Track ID'] = intval($results['id']);
                 $xml['dict']['Name'] = $song->title;
                 $xml['dict']['Artist'] = $song->f_artist_full;
                 $xml['dict']['Album'] = $song->f_album_full;
                 $xml['dict']['Total Time'] = intval($song->time) * 1000;
                 // iTunes uses milliseconds
                 $xml['dict']['Track Number'] = intval($song->track);
                 $xml['dict']['Year'] = intval($song->year);
                 $xml['dict']['Date Added'] = date("Y-m-d\\TH:i:s\\Z", $song->addition_time);
                 $xml['dict']['Bit Rate'] = intval($song->bitrate / 1000);
                 $xml['dict']['Sample Rate'] = intval($song->rate);
                 $xml['dict']['Play Count'] = intval($song->played);
                 $xml['dict']['Track Type'] = "URL";
                 $xml['dict']['Location'] = Song::play_url($song->id);
                 echo xoutput_from_array($xml, 1, 'itunes');
                 // flush output buffer
             }
             // while result
             echo xml_get_footer('itunes');
             break;
         case 'csv':
             echo "ID,Title,Artist,Album,Length,Track,Year,Date Added,Bitrate,Played,File\n";
             while ($results = Dba::fetch_assoc($db_results)) {
                 $song = new Song($results['id']);
                 $song->format();
                 echo '"' . $song->id . '","' . $song->title . '","' . $song->f_artist_full . '","' . $song->f_album_full . '","' . $song->f_time . '","' . $song->f_track . '","' . $song->year . '","' . date("Y-m-d\\TH:i:s\\Z", $song->addition_time) . '","' . $song->f_bitrate . '","' . $song->played . '","' . $song->file . "\n";
             }
             break;
     }
     // end switch
 }