Voting on Polls and Muted Words
This commit is contained in:
parent
64f540dce5
commit
f1a4636a5a
15
action.php
15
action.php
@ -59,6 +59,14 @@ if (isset($_GET['action']) && $_GET['action'] == "settings"){
|
||||
}
|
||||
break;
|
||||
|
||||
case "mtwords":
|
||||
$user_settings['mtwords'] = array();
|
||||
$mtwords = explode("\n",$value);
|
||||
foreach ($mtwords as $word){
|
||||
$user_settings['mtwords'][] = $word;
|
||||
}
|
||||
break;
|
||||
|
||||
case "fg":
|
||||
$theme['fg'] = sanitize($value);
|
||||
break;
|
||||
@ -100,6 +108,13 @@ $ajax = (isset($_GET['a']) ? true : false);
|
||||
|
||||
foreach($_GET as $key => $value){
|
||||
switch($key){
|
||||
case "vote":
|
||||
$elem = array();
|
||||
$elem['poll'] = json_decode(vote($value,$_GET['choices']),true);
|
||||
//var_dump($_GET['choices']);
|
||||
echo renderPoll($elem);
|
||||
break;
|
||||
|
||||
case "fav":
|
||||
$result = favourite($value,($mode === 'on' ? true : false));
|
||||
if ($ajax){
|
||||
|
@ -238,13 +238,17 @@ input[type="submit"] {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
background-color: #305792;
|
||||
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color: #305792;
|
||||
}
|
||||
|
||||
.post_footer {
|
||||
background-color: #eee;
|
||||
}
|
||||
@ -253,6 +257,10 @@ input[type="submit"] {
|
||||
color: #404040;
|
||||
}
|
||||
|
||||
.notif .post_buttons {
|
||||
background-color:white;
|
||||
}
|
||||
|
||||
.reply {
|
||||
background-color: #ddd;
|
||||
border-bottom: 1px solid #666;
|
||||
|
@ -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) {
|
||||
|
@ -434,36 +434,22 @@ window.setInterval(function() {
|
||||
|
||||
$('body').on('click', '#settings #send', function() {
|
||||
$('#settings #send').after('<img id="loading" src="img/loading.gif">');
|
||||
var attach = $('#settings input[name=attach]:checked').val();
|
||||
var explicit = $('#settings input[name=explicit]:checked').val();
|
||||
var replies = $('#settings select[name=replies]').val();
|
||||
var reblog = $('#settings input[name=reblog]:checked').val();
|
||||
var text = $('#settings input[name=text]:checked').val();
|
||||
var videoloop = $('#settings input[name=videoloop]:checked').val();
|
||||
var theme = $('#settings').find('select[name=theme]').val();
|
||||
var fg = $('#settings').find('input[name=fg]').val();
|
||||
var bg = $('#settings').find('input[name=bg]').val();
|
||||
var tx = $('#settings').find('input[name=tx]').val();
|
||||
var lc = $('#settings').find('input[name=lc]').val();
|
||||
var bc = $('#settings').find('input[name=bc]').val();
|
||||
var br = $('#settings').find('input[name=br]').val();
|
||||
var bw = $('#settings').find('input[name=bw]').val();
|
||||
|
||||
var params = {
|
||||
attach: attach,
|
||||
explicit: explicit,
|
||||
replies: replies,
|
||||
reblog: reblog,
|
||||
videoloop: videoloop,
|
||||
text: text,
|
||||
theme: theme,
|
||||
fg: fg,
|
||||
bg: bg,
|
||||
tx: tx,
|
||||
lc: lc,
|
||||
bc: bc,
|
||||
bw: bw,
|
||||
br: br
|
||||
attach: $('#settings input[name=attach]:checked').val(),
|
||||
explicit: $('#settings input[name=explicit]:checked').val(),
|
||||
replies: $('#settings select[name=replies]').val(),
|
||||
reblog: $('#settings input[name=reblog]:checked').val(),
|
||||
mtwords: $('#settings textarea[name=mtwords]').val(),
|
||||
videoloop: $('#settings input[name=videoloop]:checked').val(),
|
||||
text: $('#settings input[name=text]:checked').val(),
|
||||
theme: $('#settings').find('select[name=theme]').val(),
|
||||
fg: $('#settings').find('input[name=fg]').val(),
|
||||
bg: $('#settings').find('input[name=bg]').val(),
|
||||
tx: $('#settings').find('input[name=tx]').val(),
|
||||
lc: $('#settings').find('input[name=lc]').val(),
|
||||
bc: $('#settings').find('input[name=bc]').val(),
|
||||
bw: $('#settings').find('input[name=bw]').val(),
|
||||
br: $('#settings').find('input[name=br]').val()
|
||||
};
|
||||
$.get("?action=settings&ajax=1&" + $.param(params), function(data) {
|
||||
$('#settings #loading').remove();
|
||||
|
@ -65,6 +65,31 @@ $query = http_build_query(array_filter(array(
|
||||
$('#postform').toggle();
|
||||
});
|
||||
|
||||
$('body').on('click', '.polloption:not(.fixed)', function(e) {
|
||||
if (typeof $(this).parent().attr('multiple') == 'undefined'){
|
||||
$('.polloption').removeClass('voted');
|
||||
}
|
||||
$(this).toggleClass('voted');
|
||||
});
|
||||
|
||||
$('body').on('click', '.vote', function(e) {
|
||||
var id = $(this).attr('id');
|
||||
var c = 0;
|
||||
var choice = [];
|
||||
$('#'+id+'.poll .polloption').each(function(a){
|
||||
if ($(this).hasClass('voted')){
|
||||
console.log(c);
|
||||
choice.push(c);
|
||||
}
|
||||
c++;
|
||||
});
|
||||
var choices = choice.join(',');
|
||||
console.log(choices);
|
||||
$.get("action.php?a=true&vote="+id+"&choices="+choices, function(result) {
|
||||
$('#'+id+'.poll').html(result);
|
||||
});
|
||||
});
|
||||
|
||||
$('body').on('click', '.searchform', function(e) {
|
||||
$(this).prev().toggle();
|
||||
});
|
||||
|
@ -31,6 +31,16 @@
|
||||
<input type='radio' name='reblog' id='reblogOff' value='off' style='display:none;' <?php echo ($user_settings['reblog'] == 'off' ? "checked" : ""); ?>>
|
||||
<label for='reblogOff'>No</label>
|
||||
</div>
|
||||
<br><br>
|
||||
<h2>Muted words</h2>
|
||||
<span>One per line</span>
|
||||
<div class='setting'>
|
||||
<textarea name='mtwords' style='width:300px'><?php
|
||||
foreach($user_settings['mtwords'] as $word){
|
||||
echo (empty($word) ? "" : trim($word)."\n");
|
||||
}
|
||||
?></textarea>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset style='width:100%'>
|
||||
|
@ -149,6 +149,13 @@ if ((!isset($thread[0]['id']) && !empty($thread)) || !is_array($thread)) {
|
||||
$post['replyto'] = "<span>" . ($elem['in_reply_to_id'] ? " <a class='fontello link preview ldr' target='_blank' id='" . $elem['in_reply_to_id'] . "' href='?thread=" . $elem['in_reply_to_id'] . "'></a>" : "") . "</span>";
|
||||
}
|
||||
|
||||
/* We skip the post if it contains any of the muted words */
|
||||
foreach($user_settings['mtwords'] as $word){
|
||||
if(contains($elem['content'],$word)){
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* if the poster ID was flagged as NSFW by the user, the post is flagged
|
||||
as sensitive by default */
|
||||
if (in_array($elem["account"]['id'], $user_settings['nsfw'])) {
|
||||
@ -208,17 +215,11 @@ if ((!isset($thread[0]['id']) && !empty($thread)) || !is_array($thread)) {
|
||||
$post['text'] = processText($elem);
|
||||
|
||||
if (!empty($elem['poll'])){
|
||||
$post['text'] .= "<br>";
|
||||
$votes = $elem['poll']['votes_count'];
|
||||
$post['text'] .= "<div class='poll'><b>Votes: $votes</b><br>";
|
||||
|
||||
foreach ($elem['poll']['options'] as $option){
|
||||
$post['text'] .= "<div class='polloption'>".$option['title']."</div>";
|
||||
}
|
||||
$post['text'] .= "<div class='poll' id='".$elem['poll']['id']."' ".($elem['poll']['multiple'] ? "multiple" : "").">";
|
||||
$post['text'] .= renderPoll($elem);
|
||||
$post['text'] .= "</div>";
|
||||
}
|
||||
|
||||
|
||||
$post['spoiler'] = (empty($elem['spoiler_text']) ? "" : "<span style='font-weight:bold;font-size:20px;'>" . $elem['spoiler_text'] . "</span><br>");
|
||||
$post['media'] = "";
|
||||
|
||||
@ -244,9 +245,9 @@ if ((!isset($thread[0]['id']) && !empty($thread)) || !is_array($thread)) {
|
||||
$ext = explode(".", $file['url']);
|
||||
$ext = end($ext);
|
||||
$ext = explode("?", $ext) [0];
|
||||
if (in_array($ext,array('webm','mp4'))) {
|
||||
if (in_array($ext,array('webm','mp4','ogv'))) {
|
||||
$post['media'] .= "<div style='overflow:hidden; float:left; margin:2px;' $class><video preload='metadata' style='text-align:center; max-width:100%; max-height:100%;' controls ".($user_settings['videoloop'] == "on" ? "loop" : "").">
|
||||
<source src='" . $file['url'] . "' type='video/$ext'>
|
||||
<source src='" . $file['url'] . "' type='video/".($ext == "ogv" ? "ogg" : $ext)."'>
|
||||
</video></div>
|
||||
";
|
||||
}
|
||||
|
@ -338,12 +338,17 @@ input[type="checkbox"]:checked+label {
|
||||
padding:5px;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
border-bottom:2px solid #ffffff;
|
||||
border-right:2px solid #ffffff;
|
||||
border-top:2px solid #828282;
|
||||
border-left:2px solid #828282;
|
||||
cursor: pointer;
|
||||
background-color:#c8f7f5;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color: #734eec;
|
||||
}
|
||||
|
||||
.post_footer {
|
||||
|
@ -311,12 +311,16 @@ input[type="submit"] {
|
||||
color:#04e703 !important;
|
||||
}
|
||||
|
||||
.polloption:hover {
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
background-color: #04e703;
|
||||
color:black !important;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color: #04e703;
|
||||
}
|
||||
|
||||
.post_footer .post_buttons a, .post_footer span{
|
||||
color: #04e703;
|
||||
}
|
||||
|
@ -86,18 +86,22 @@ input[type="text"] {
|
||||
padding:5px;
|
||||
background-color: white;
|
||||
border:2px solid #7dbcda;
|
||||
border-radius:15px;
|
||||
color:#7dbcda;
|
||||
border-radius:7px;
|
||||
color:#04a0c6;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
cursor: pointer;
|
||||
border:2px solid #7dbcda;
|
||||
background-color: #7dbcda;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color: #04a0c6;
|
||||
}
|
||||
|
||||
.new {
|
||||
background-color:white;
|
||||
}
|
||||
|
@ -236,13 +236,17 @@ input[type="submit"] {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
background-color: #3b5998;
|
||||
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color: #3b5998;
|
||||
}
|
||||
|
||||
.icon {
|
||||
background-color: black;
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ input[type="submit"] {
|
||||
color:black;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
cursor: pointer;
|
||||
border-bottom:2px solid #ffffff ;
|
||||
border-right:2px solid #ffffff;
|
||||
@ -305,6 +305,10 @@ input[type="submit"] {
|
||||
border-left:2px solid #828282;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color:#000082;
|
||||
}
|
||||
|
||||
.post_footer {
|
||||
border-bottom:2px solid #ffffff;
|
||||
border-right:2px solid #ffffff;
|
||||
|
@ -219,19 +219,23 @@ input[type="submit"] {
|
||||
margin:5px;
|
||||
padding:5px;
|
||||
background-color: white;
|
||||
border:2px solid #800;
|
||||
border-radius:15px;
|
||||
border:1px solid #800;
|
||||
border-radius:3px;
|
||||
color:#800;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
cursor: pointer;
|
||||
border:2px solid #800;
|
||||
border:1px solid #800;
|
||||
background-color: #800;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color: #467757;
|
||||
}
|
||||
|
||||
.post_footer {
|
||||
background-color: #FFF;
|
||||
border-top:2px solid #eeaa88;
|
||||
|
@ -123,12 +123,16 @@ input[type="checkbox"]:checked+label {
|
||||
color: <?php echo $link; ?>;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
cursor: pointer;
|
||||
background-color: <?php echo $foregroundDarker; ?>;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color: <?php echo $link; ?>;
|
||||
}
|
||||
|
||||
.tiselected {
|
||||
border-bottom: 2px solid <?php echo $foreground; ?>;
|
||||
}
|
||||
|
@ -216,16 +216,23 @@ input[type="submit"] {
|
||||
display:block;
|
||||
margin:5px;
|
||||
padding:5px;
|
||||
background-color: #d8a070;
|
||||
color:black;
|
||||
color: #d8a070;
|
||||
background-color: rgba(255,255,255,0.1);
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
cursor: pointer;
|
||||
background-color:white;
|
||||
color:black;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.voteBar{
|
||||
background-color: #d8a070;
|
||||
}
|
||||
|
||||
|
||||
.post {
|
||||
border-top: 2px solid #1c2737;
|
||||
}
|
||||
|
@ -222,14 +222,18 @@ textarea,input[type="text"]{
|
||||
display:block;
|
||||
margin:5px;
|
||||
padding:5px;
|
||||
background-color: white;
|
||||
background-color: #3f3f3f;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.polloption:hover:not(.fixed),.voted{
|
||||
cursor: pointer;
|
||||
background-color: #ff8706;
|
||||
color:black;
|
||||
}
|
||||
|
||||
.polloption:hover{
|
||||
cursor: pointer;
|
||||
background-color: #ff8706;;
|
||||
color:black;
|
||||
.voteBar{
|
||||
background-color: #ff8706;
|
||||
}
|
||||
|
||||
.post_buttons {
|
||||
|
Loading…
Reference in New Issue
Block a user