mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Fixed merge issues
This commit is contained in:
135
php/change.php
Executable file → Normal file
135
php/change.php
Executable file → Normal file
@@ -11,50 +11,81 @@ if(isset($_REQUEST['test'])){
|
||||
$list = explode("/", htmlspecialchars(strtolower($_SERVER["REQUEST_URI"])));
|
||||
if($list[1]==""||!isset($list[1])||count($list)<=1)$list="videos";
|
||||
else $list=$list[1];
|
||||
$list="../lists/".$list.".json";
|
||||
|
||||
$list="../lists/".$list.".json";
|
||||
$array = array("nowPlaying" => array(), "songs" => array(), "conf" => array("startTime" => time(), "views" => 0, "skips" => array()));
|
||||
$f = @fopen($list,"x");
|
||||
if($f){ fwrite($f,"[[],[".time()."],[],[],[],[]]"); fclose($f); }
|
||||
if($f){ fwrite($f,$array); fclose($f); }
|
||||
$file = file_get_contents($list);
|
||||
$data = json_decode($file);
|
||||
$data = json_decode($file, TRUE);
|
||||
$songs = $data["songs"];
|
||||
$np = $data["nowPlaying"];
|
||||
$np = array_values($np);
|
||||
$firstSong = array_values($songs);
|
||||
$save = false;
|
||||
|
||||
|
||||
if(isset($_REQUEST['thisUrl'])){
|
||||
$string = $_REQUEST['thisUrl'];
|
||||
$action = isset($_REQUEST['act']);
|
||||
|
||||
if($data[0][0] == $string)
|
||||
$firstToAdd = $firstSong[0]["id"];
|
||||
if($np[0]["id"] == $string)
|
||||
{
|
||||
if($action=="save"){ //next song
|
||||
$save = true;
|
||||
nextSong();
|
||||
}
|
||||
else if($action=="delete"){
|
||||
array_shift($data[0]);
|
||||
array_shift($data[3]);
|
||||
array_shift($data[2]);
|
||||
//array_shift($data["songs"]);
|
||||
//array_shift($data["nowPlaying"]);
|
||||
array_shift($data["songs"]);
|
||||
$data["songs"][$np[0]["id"]] = array("id" => $np[0]["id"], "title" => $np[0]["title"], "votes" => $np[0]["votes"], "added" => time(), "guids" => array());
|
||||
array_shift($data["nowPlaying"]);
|
||||
$data["nowPlaying"][$firstSong[0]["id"]] = array("id" => $firstSong[0]["id"], "title" => $firstSong[0]["title"], "votes" => 0, "added" => $firstSong[0]["added"], "guids" => $firstSong[0]["guids"]);
|
||||
//array_push($data["songs"], $add);
|
||||
$data["conf"]["skips"] = array();
|
||||
$data["conf"]["startTime"] = time();
|
||||
$data["conf"]["views"] = 1;
|
||||
foreach($data["songs"] as $k=>$v) {
|
||||
$sort['votes'][$k] = $v['votes'];
|
||||
$sort['added'][$k] = $v['added'];
|
||||
}
|
||||
array_multisort($sort['votes'], SORT_DESC, $sort['added'], SORT_ASC, $data["songs"]);
|
||||
}
|
||||
/* else if($action=="delete"){
|
||||
array_shift($firstSong[0]);
|
||||
}*/
|
||||
file_put_contents($list, json_encode($data));
|
||||
}
|
||||
if($action == "save" && !$save) //count views
|
||||
{
|
||||
$data[4][0] = $data[4][0] + 1;
|
||||
$data["conf"]["views"] = $data["conf"]["views"] + 1;
|
||||
file_put_contents($list, json_encode($data));
|
||||
}
|
||||
echo $data[0][0];
|
||||
$newPlaying = array_values($data["nowPlaying"]);
|
||||
echo $newPlaying[0]["id"];
|
||||
}
|
||||
else if(isset($_GET['v'])){ //add
|
||||
$video = htmlspecialchars($_GET['v']);
|
||||
$name = htmlspecialchars($_GET['n']);
|
||||
if(!in_array($video, $data[0]))
|
||||
if(!in_array($video, $data["songs"]))
|
||||
{
|
||||
//$arrayAdd = array("id" => array("id" => $video, "title" => $name, "votes" => array()));
|
||||
//array_push($data[0], $video);
|
||||
$i = array_search(0, $data[2]);
|
||||
$data["songs"][$video] = array("id" => $video, "title" => $name, "votes" => 0, "added" => time(), "guids" => array());
|
||||
$data["songs"][$video]["votes"] = 1;
|
||||
array_push($data["songs"][$video]["guids"], $guid);
|
||||
$sort = array();
|
||||
foreach($data["songs"] as $k=>$v) {
|
||||
$sort['votes'][$k] = $v['votes'];
|
||||
$sort['added'][$k] = $v['added'];
|
||||
}
|
||||
array_multisort($sort['votes'], SORT_DESC, $sort['added'], SORT_ASC, $data["songs"]);
|
||||
//array_push($data["songs"], $arrayAdd);
|
||||
/*$i = array_search(0, $data[2]);
|
||||
if($i == 0)$i=1;
|
||||
else if($i == false)$i=count($data[2]);
|
||||
array_splice($data[3], $i, 0, array($name));
|
||||
array_splice($data[2], $i, 0, array(1));
|
||||
array_splice($data[0], $i, 0, array($video));
|
||||
file_put_contents($list, json_encode($data));*/
|
||||
file_put_contents($list, json_encode($data));
|
||||
print("added");
|
||||
}
|
||||
@@ -63,46 +94,64 @@ else if(isset($_GET['v'])){ //add
|
||||
else if(isset($_GET['vote'])){ //add vote
|
||||
$vote=$_GET['vote'];
|
||||
$id=$_GET['id'];
|
||||
$i = array_search($id, $data[0]);
|
||||
//$i = array_search($id, $data["songs"]);
|
||||
//$i = array_search($id, array_keys($data["songs"]))
|
||||
if($vote == 'neg'){$voteAdd = -1;}
|
||||
else if($vote == 'pos'){$voteAdd = 1;}
|
||||
$name = $data[3][$i];
|
||||
$votes = $data[2][$i] + $voteAdd;
|
||||
if($i == true && $votes >= 0){
|
||||
|
||||
//print_r($i);
|
||||
// echo "IIII: ",$i;
|
||||
unset($data[3][$i]);
|
||||
unset($data[0][$i]);
|
||||
unset($data[2][$i]);
|
||||
$underVote = array_search($votes-1, $data[2]); #nenennenenen feiiiiiiiiiiiiiiiiil
|
||||
|
||||
if($underVote == 0)$underVote=1;
|
||||
else if($underVote == false)$underVote=count($data[2]);
|
||||
array_splice($data[3], $underVote, 0, array($name));
|
||||
array_splice($data[2], $underVote, 0, array($votes));
|
||||
array_splice($data[0], $underVote, 0, array($id));
|
||||
file_put_contents($list, json_encode($data));
|
||||
echo "Vote registrated. I hope";
|
||||
//$name = $data[3][$i];
|
||||
if(array_key_exists($id, $data["songs"]) && !in_array($guid, $data["songs"][$id]["guids"]))
|
||||
{
|
||||
$data["songs"][$id]["votes"] = $data["songs"][$id]["votes"] + $voteAdd;
|
||||
$data["songs"][$id]["added"] = time();
|
||||
array_push($data["songs"][$id]["guids"], $guid);
|
||||
foreach($data["songs"] as $k=>$v) {
|
||||
$sort['votes'][$k] = $v['votes'];
|
||||
$sort['added'][$k] = $v['added'];
|
||||
}
|
||||
array_multisort($sort['votes'], SORT_DESC, $sort['added'], SORT_ASC, $data["songs"]);
|
||||
print_r($data);
|
||||
file_put_contents($list, json_encode($data));
|
||||
echo "Vote registrated. I hope";
|
||||
}else
|
||||
{
|
||||
echo array_key_exists($id, $data["songs"]);
|
||||
}
|
||||
}
|
||||
else if(isset($_GET['skip'])){ //skip song request
|
||||
$viewers=$data[4][0];
|
||||
$skips=count($data[5]);
|
||||
if(!in_array($guid, $data[5])){
|
||||
array_push($data[5], $guid);
|
||||
$viewers=$data["conf"]["views"];
|
||||
$skips=count($data["conf"]["skips"]);
|
||||
if(!in_array($guid, $data["conf"]["skips"])){
|
||||
array_push($data["conf"]["skips"], $guid);
|
||||
$skips+=1;
|
||||
$data[5][0]=$skips;
|
||||
//$data["conf"]["skips"]=$skips;
|
||||
if($skips>=$viewers/2){
|
||||
nextSong();
|
||||
echo("skipped!");
|
||||
array_shift($data["songs"]);
|
||||
$data["songs"][$np[0]["id"]] = array("id" => $np[0]["id"], "title" => $np[0]["title"], "votes" => $np[0]["votes"], "added" => time(), "guids" => array());
|
||||
array_shift($data["nowPlaying"]);
|
||||
$data["nowPlaying"][$firstSong[0]["id"]] = array("id" => $firstSong[0]["id"], "title" => $firstSong[0]["title"], "votes" => 0, "added" => $firstSong[0]["added"], "guids" => $firstSong[0]["guids"]);
|
||||
//array_push($data["songs"], $add);
|
||||
$data["conf"]["skips"] = array();
|
||||
$data["conf"]["startTime"] = time();
|
||||
$data["conf"]["views"] = 1;
|
||||
foreach($data["songs"] as $k=>$v) {
|
||||
$sort['votes'][$k] = $v['votes'];
|
||||
$sort['added'][$k] = $v['added'];
|
||||
}
|
||||
array_multisort($sort['votes'], SORT_DESC, $sort['added'], SORT_ASC, $data["songs"]);
|
||||
}
|
||||
file_put_contents($list, json_encode($data));
|
||||
}
|
||||
echo($skips."/".$viewers);
|
||||
|
||||
}else if(isset($_GET['timedifference'])){
|
||||
|
||||
$diff = (time() - $data["conf"]["startTime"]);
|
||||
$returnArray = array($diff, $firstSong[0]["id"], time(), $data["conf"]["startTime"], $firstSong[0]["title"], $data["conf"]["views"]);
|
||||
$returnArray = json_encode($returnArray);
|
||||
echo($data);
|
||||
}else{
|
||||
echo json_encode($data);
|
||||
}
|
||||
else{ print($file); }
|
||||
|
||||
function nextSong(){
|
||||
global $data;
|
||||
@@ -121,4 +170,4 @@ function nextSong(){
|
||||
$data[5]=array();
|
||||
$data[1][0] = time();
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user