Voting on Polls and Muted Words

This commit is contained in:
Daisuke
2020-04-22 20:25:00 -05:00
parent 64f540dce5
commit f1a4636a5a
16 changed files with 195 additions and 60 deletions

View File

@ -230,6 +230,28 @@ function api_delete($url, $array) {
return json_decode($result, true);
}
/* this function is used to generate the html code of a poll */
function renderPoll($elem) {
$output = "";
$output .= "<br>";
$votes = $elem['poll']['votes_count'];
if ($elem['poll']['voted'] || $elem['poll']['expired']) {
$output.= "<b>Votes: $votes</b><br>";
foreach ($elem['poll']['options'] as $option){
$percentage = ($option['votes_count'] / $votes ) * 100;
$output .= "<div class='polloption fixed' title='".$option['votes_count']." votes'><div class='voteBar' style='font-weight:bold; max-width:".$percentage."%;padding:1px; height:10px;'> </div>".$option['title']."</div>";
}
} else {
foreach ($elem['poll']['options'] as $option){
$output .= "<div class='polloption'>".$option['title']."</div>";
}
$output .= "<input type='submit' class='vote' id='".$elem['poll']['id']."' value='Send Vote' style='padding:2px;' onClick='return false;'>";
}
return $output;
}
/* this function is used to generate the html code of a reply */
function render_reply($item) {
global $user_settings;
@ -389,6 +411,34 @@ function delpost($id) {
}
}
function vote($poll, $choices) {
global $srv;
global $token;
if (!is_null($token)) {
$cSession = curl_init();
curl_setopt($cSession, CURLOPT_URL, "https://$srv/api/v1/polls/$poll/votes");
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_POST, 1);
curl_setopt($cSession, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $token
));
$query = "";
$choicelist = explode(",",$choices);
foreach($choicelist as $choice){
$query .= "choices[]=$choice&";
}
curl_setopt($cSession, CURLOPT_POSTFIELDS, $query);
$result = curl_exec($cSession);
curl_close($cSession);
return $result;
}
else {
return false;
}
}
/* function to send a new post to the logged in instance
it takes the media ids as an array */
function sendpost($text, $media, $reply, $markdown = false, $scope, $sensitive, $spoiler = false) {