From f1a4636a5af359808ce96f46443c440067a3ae4f Mon Sep 17 00:00:00 2001 From: Daisuke Date: Wed, 22 Apr 2020 20:25:00 -0500 Subject: [PATCH] Voting on Polls and Muted Words --- action.php | 15 ++++++++++ css/color.css | 10 ++++++- include/functions.php | 50 ++++++++++++++++++++++++++++++++ js/scripts.js | 44 ++++++++++------------------ layout/footer.php | 25 ++++++++++++++++ modules/settings.php | 10 +++++++ modules/timeline.php | 21 +++++++------- themes/1994/css/color.css | 7 ++++- themes/amplifier/css/color.css | 6 +++- themes/ancientbird/css/color.css | 10 +++++-- themes/bythebook/css/color.css | 6 +++- themes/chicago/css/color.css | 6 +++- themes/cuatro/css/color.css | 12 +++++--- themes/custom/css/color.php | 6 +++- themes/monad/css/color.css | 13 +++++++-- themes/phubbub/css/color.css | 14 +++++---- 16 files changed, 195 insertions(+), 60 deletions(-) diff --git a/action.php b/action.php index 476fec5..b4354c7 100644 --- a/action.php +++ b/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){ diff --git a/css/color.css b/css/color.css index e1cbb5a..09d945e 100644 --- a/css/color.css +++ b/css/color.css @@ -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; diff --git a/include/functions.php b/include/functions.php index 2ff4501..a7d531b 100644 --- a/include/functions.php +++ b/include/functions.php @@ -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 .= "
"; + $votes = $elem['poll']['votes_count']; + + if ($elem['poll']['voted'] || $elem['poll']['expired']) { + $output.= "Votes: $votes
"; + foreach ($elem['poll']['options'] as $option){ + $percentage = ($option['votes_count'] / $votes ) * 100; + $output .= "
".$option['title']."
"; + } + } else { + foreach ($elem['poll']['options'] as $option){ + $output .= "
".$option['title']."
"; + } + $output .= ""; + } + 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) { diff --git a/js/scripts.js b/js/scripts.js index de59011..853655c 100644 --- a/js/scripts.js +++ b/js/scripts.js @@ -434,36 +434,22 @@ window.setInterval(function() { $('body').on('click', '#settings #send', function() { $('#settings #send').after(''); - 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(); diff --git a/layout/footer.php b/layout/footer.php index bb97871..d888873 100644 --- a/layout/footer.php +++ b/layout/footer.php @@ -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(); }); diff --git a/modules/settings.php b/modules/settings.php index 95ab68c..9bd2cae 100644 --- a/modules/settings.php +++ b/modules/settings.php @@ -31,6 +31,16 @@ > +

+

Muted words

+ One per line +
+ +
diff --git a/modules/timeline.php b/modules/timeline.php index 582dc65..9758ff8 100644 --- a/modules/timeline.php +++ b/modules/timeline.php @@ -149,6 +149,13 @@ if ((!isset($thread[0]['id']) && !empty($thread)) || !is_array($thread)) { $post['replyto'] = "" . ($elem['in_reply_to_id'] ? " " : "") . ""; } + /* 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'] .= "
"; - $votes = $elem['poll']['votes_count']; - $post['text'] .= "
Votes: $votes
"; - - foreach ($elem['poll']['options'] as $option){ - $post['text'] .= "
".$option['title']."
"; - } + $post['text'] .= "
"; + $post['text'] .= renderPoll($elem); $post['text'] .= "
"; } - $post['spoiler'] = (empty($elem['spoiler_text']) ? "" : "" . $elem['spoiler_text'] . "
"); $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'] .= "
"; } diff --git a/themes/1994/css/color.css b/themes/1994/css/color.css index 812fd1e..6867e7d 100644 --- a/themes/1994/css/color.css +++ b/themes/1994/css/color.css @@ -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 { diff --git a/themes/amplifier/css/color.css b/themes/amplifier/css/color.css index acc8fdf..90a95ed 100644 --- a/themes/amplifier/css/color.css +++ b/themes/amplifier/css/color.css @@ -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; } diff --git a/themes/ancientbird/css/color.css b/themes/ancientbird/css/color.css index f7662d6..ca6337b 100644 --- a/themes/ancientbird/css/color.css +++ b/themes/ancientbird/css/color.css @@ -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; } diff --git a/themes/bythebook/css/color.css b/themes/bythebook/css/color.css index f98fc1f..f834e7b 100644 --- a/themes/bythebook/css/color.css +++ b/themes/bythebook/css/color.css @@ -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; } diff --git a/themes/chicago/css/color.css b/themes/chicago/css/color.css index 3c33968..a6db544 100644 --- a/themes/chicago/css/color.css +++ b/themes/chicago/css/color.css @@ -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; diff --git a/themes/cuatro/css/color.css b/themes/cuatro/css/color.css index daddecd..651a5f5 100644 --- a/themes/cuatro/css/color.css +++ b/themes/cuatro/css/color.css @@ -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; diff --git a/themes/custom/css/color.php b/themes/custom/css/color.php index bedcaa2..418f5da 100644 --- a/themes/custom/css/color.php +++ b/themes/custom/css/color.php @@ -123,12 +123,16 @@ input[type="checkbox"]:checked+label { color: ; } -.polloption:hover{ +.polloption:hover:not(.fixed),.voted{ cursor: pointer; background-color: ; color: white; } +.voteBar{ + background-color: ; +} + .tiselected { border-bottom: 2px solid ; } diff --git a/themes/monad/css/color.css b/themes/monad/css/color.css index 40f6e7b..a264d1d 100644 --- a/themes/monad/css/color.css +++ b/themes/monad/css/color.css @@ -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; } diff --git a/themes/phubbub/css/color.css b/themes/phubbub/css/color.css index 04bcece..f60135a 100644 --- a/themes/phubbub/css/color.css +++ b/themes/phubbub/css/color.css @@ -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 {