示例#1
0
文件: Action.php 项目: sni/webmp3
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#################################################################
#
# $Id:$
#
#################################################################
#########################################################################################
##
## ACTION
##
if (isset($_SERVER["argv"][1]) and substr($_SERVER["argv"][1], 0, 6) == "action") {
    $action = substr($_SERVER["argv"][1], 7);
} elseif (isset($_GET["action"])) {
    $action = $_GET["action"];
} elseif (isset($_POST["action"])) {
    $action = $_POST["action"];
}
if (isset($action)) {
    if (function_exists("action_" . $action)) {
        $ret = call_user_func("action_" . $action);
    } else {
        user_error("function action_" . $action . " not found");
        $ret = action_default("");
    }
} else {
    $action = "default";
    $ret = action_default("");
}
#########################################################################################
示例#2
0
文件: play.php 项目: sni/webmp3
function action_default()
{
    global $config;
    $data = getData();
    if (isset($data["ppid"])) {
        $data = killChild($data);
    }
    if (isset($data["curTrack"]) and isset($data["playlist"][$data["curTrack"]])) {
        $track = $data["playlist"][$data["curTrack"]];
    } else {
        $tmp = $data["playlist"];
        $track = array_shift($tmp);
        $data["curTrack"] = $track["token"];
    }
    doPrint("playing: " . $track["filename"]);
    # clean up playlist
    if ($data['partymode'] == 1) {
        # clean everything up to 3 songs after the current one
        $x = 0;
        $num = 0;
        foreach ($data['playlist'] as $token => $tr) {
            if ($tr['token'] == $track["token"]) {
                $num = $x;
                continue;
            }
            $x++;
        }
        $num = $num - 3;
        $num = max(0, $num);
        for ($x = 0; $x < $num; $x++) {
            array_shift($data["playlist"]);
        }
    } elseif ($data['partymode'] == 2) {
        # clean everything up to the first song of the cur album
        $newPlaylist = array();
        $found = 0;
        foreach ($data['playlist'] as $token => $tr) {
            if ($tr['token'] == $track["token"] or $tr['album'] == $track['album']) {
                $found = 1;
            }
            if ($found == 1) {
                $newPlaylist[$token] = $tr;
            }
        }
        $data['playlist'] = $newPlaylist;
    }
    $data["start"] = time();
    $data["length"] = $track["lengths"];
    $data["title"] = $track["title"];
    $data["artist"] = $track["artist"];
    $data["album"] = $track["album"];
    $data["track"] = $track["tracknum"];
    $data["token"] = $track["token"];
    $data["filename"] = $track["filename"];
    if (!isset($track["bitrate"])) {
        $track["bitrate"] = "";
    }
    $data["bitrate"] = $track["bitrate"];
    $data["play"] = 1;
    $data["gmtimestart"] = gmdate("U");
    $data["playingPic"] = getPictureForPath(dirname($track["filename"]));
    if (isset($config["notifyCommand"])) {
        $tmp = $config["notifyCommand"];
        $tmpTrack = $track["tracknum"];
        $tmpArtist = $track["artist"];
        $tmpTitle = $track["title"];
        $tmpArtist = str_replace('\'', '', $tmpArtist);
        $tmpArtist = str_replace('\\"', '', $tmpArtist);
        $tmpArtist = str_replace(';', '', $tmpArtist);
        $tmpTitle = str_replace('\'', '', $tmpTitle);
        $tmpTitle = str_replace('\\"', '', $tmpTitle);
        $tmpTitle = str_replace(';', '', $tmpTitle);
        $tmpTrack = str_replace('\'', '', $tmpTrack);
        $tmpTrack = str_replace('\\"', '', $tmpTrack);
        $tmpTrack = str_replace(';', '', $tmpTrack);
        $tmp = str_replace("%#", $tmpTrack, $tmp);
        $tmp = str_replace("%T", $tmpTitle, $tmp);
        $tmp = str_replace("%A", $tmpArtist, $tmp);
        doPrint("notify: " . $tmp);
        $output = "";
        $rc = 0;
        exec($tmp, $output, $rc);
        if ($rc != 0) {
            doPrint("notify failed: " . join("\n", $output));
        }
    }
    $data["ppid"] = getmypid();
    # most played
    addFileToHitlist($track["filename"]);
    if (strpos($track["filename"], "http://") === 0) {
        doPrint("playing stream");
        $options = $config["playStrOpt"];
        $playBin = $config["streamBin"];
        if (!isset($config["streamUrlPre"])) {
            $config["streamUrlPre"] = "";
        }
        $track["filename"] = $config["streamUrlPre"] . $track["filename"];
        $data["playingStream"] = 1;
    } else {
        doPrint("playing normal file");
        $tmp = explode(".", $track["filename"]);
        $ext = "." . array_pop($tmp);
        if (isset($config["ext"][$ext])) {
            $playBin = $config["ext"][$ext]["binary"];
            $options = $config["ext"][$ext]["option"];
        } else {
            doPrint("Extension {$ext} not supported");
        }
        $data["playingStream"] = 0;
    }
    $options[] = $track["filename"];
    $data["aktBin"] = $playBin;
    storeData($data);
    #$options = array_map("myescapeshellarg", $options);
    setlocale(LC_CTYPE, "en_US.UTF-8");
    $options = array_map("escapeshellarg", $options);
    $data = brokerPlugin("pre_playing_song", $data);
    doPrint("executing: " . $playBin . " " . join(" ", $options));
    system($playBin . " " . join(" ", $options) . ' >> ' . $config["logfile"] . ' 2>&1');
    doPrint("finished playing");
    $data = getData();
    $data = brokerPlugin("post_playing_song", $data);
    unset($data["ppid"]);
    unset($data["start"]);
    unset($data["length"]);
    unset($data["title"]);
    unset($data["track"]);
    unset($data["artist"]);
    unset($data["album"]);
    unset($data["aktBin"]);
    unset($data["playingPic"]);
    $lastToken = $track["token"];
    $track = "";
    storeData($data);
    if ($data["play"]) {
        $data["play"] = 0;
        $track = getNextTrack($data["playlist"], $lastToken);
        if ($track) {
            $data["curTrack"] = $track;
            storeData($data);
            action_default();
        }
    }
}
示例#3
0
<?php

/**
 * This is the main entry point for the application, inclusion of all code and routing occurs
 */
require "inc/settings.php";
require "inc/utils.php";
require "inc/db.php";
require "inc/tpl.php";
require "inc/datatypes.php";
require "inc/actions.php";
// Router implementation. Requets to ?action=some_handler is handled by the function "action_some_handler"
// If no action is supplied, call action_default(). See actions.php.
if (!empty($_GET['action'])) {
    $action = 'action_' . $_GET['action'];
    if (function_exists($action)) {
        $action();
    } else {
        display_error('Ugyldig handling');
    }
} else {
    action_default();
}