1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Fixes #1449 - Polls failing in PHP7 and Multiple options voting not functioning.

This commit is contained in:
Cameron 2016-03-23 16:43:41 -07:00
parent 1c16094dea
commit 8282802d5e
8 changed files with 399 additions and 233 deletions

View File

@ -2244,7 +2244,7 @@ class e107
if(ADMIN && E107_DBG_INCLUDES)
{
e107::getMessage()->addDebug( "template path=".$path );
e107::getMessage()->addDebug( "Attempting to load Template File: ".$path );
}
$id = str_replace('/', '_', $id);

View File

@ -531,11 +531,25 @@ class e_db_mysql
{
$buglink = is_null($rli) ? $this->mySQLaccess : $rli;
if(is_array($query) && is_object($ex))
if($this->pdo == true && isset($ex) && is_object($ex))
{
$query = "ERROR: ".$ex->errorInfo[2]."<br />PREPARE: ".$query['PREPARE']."<br />BIND:".print_a($query['BIND'],true); // ,true);
if(is_array($query))
{
$query = "ERROR: ".$ex->errorInfo[2]."<br />PREPARE: ".$query['PREPARE']."<br />BIND:".print_a($query['BIND'],true); // ,true);
}
else
{
$query = $ex->getMessage();
$query .= print_a( $ex->getTrace(),true);
}
}
$db_debug->Mark_Query($query, $buglink, $sQryRes, $aTrace, $mytime, $pTable);
}
else
@ -1040,7 +1054,7 @@ class e_db_mysql
foreach ($arg['data'] as $fn => $fv)
{
$new_data .= ($new_data ? ', ' : '');
$ftype = $fieldTypes[$fn];
$ftype = isset($fieldTypes[$fn]) ? $fieldTypes[$fn] : 'str';
$new_data .= ($this->pdo == true && $ftype !='cmd') ? "`{$fn}`= :". $fn : "`{$fn}`=".$this->_getFieldValue($fn, $fv, $fieldTypes);

View File

@ -1290,6 +1290,9 @@ class e_shortcode
*/
protected $scVars = null;
/**
* e_shortcode constructor.
*/
public function __construct()
{
$this->scVars = new e_vars();

View File

@ -179,7 +179,7 @@ if($thread->message)
//{
if(e107::isInstalled('poll'))
{
$_qry = 'SELECT * FROM `#polls` WHERE `poll_datestamp` = ' . $thread->threadId;
$_qry = 'SELECT p.*, u.user_id, u.user_name FROM `#polls` AS p LEFT JOIN `#user` AS u ON p.poll_admin_id = u.user_id WHERE p.poll_datestamp = ' . $thread->threadId;
if($sql->gen($_qry))
{
if (!defined('POLLCLASS'))

View File

@ -60,6 +60,16 @@ $FORUM_POLL_TEMPLATE['results']['end'] = "
";
/* v2.x template for polls when user HAS been denied the ability to vote (userclass) */
$FORUM_POLL_TEMPLATE['denied']['start'] = $FORUM_POLL_TEMPLATE['results']['start'];
$FORUM_POLL_TEMPLATE['denied']['item'] = $FORUM_POLL_TEMPLATE['results']['item'];
$FORUM_POLL_TEMPLATE['denied']['end'] = "<div class='alert text-warning text-center'>{DISALLOWMESSAGE}</div>
<div class='text-center'><small>{VOTE_TOTAL}</small></div>
{COMMENTS} {OLDPOLLS}
</div>
</div>
";

View File

@ -23,52 +23,46 @@ if (!e107::isInstalled('poll'))
require_once(HEADERF);
require_once(e_HANDLER."comment_class.php");
$cobj = new comment;
$gen = new convert;
if(!defined("USER_WIDTH")){ define("USER_WIDTH","width:95%"); }
if(!defined("USER_WIDTH") && !deftrue('BOOTSTRAP'))
{
define("USER_WIDTH","width:95%");
}
include_lan(e_PLUGIN."poll/languages/".e_LANGUAGE.".php");
if(e_QUERY)
{
require_once('poll_class.php');
$query = "SELECT p.*, u.user_id, u.user_name FROM #polls AS p
LEFT JOIN #user AS u ON p.poll_admin_id = u.user_id
WHERE p.poll_type=1 AND p.poll_id=".intval(e_QUERY);
if($sql->db_Select_gen($query))
if($sql->gen($query))
{
$pl = new poll;
$row = $sql ->fetch();
$row = $sql -> db_Fetch();
extract($row);
$start_datestamp = $tp->toDate($row['poll_datestamp'], "long");
$end_datestamp = $tp->toDate($row['poll_end_datestamp'], "long");
$uparams = array('id' => $row['user_id'], 'name' => $row['user_name']);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$row['user_name']."</a>";
$optionArray = explode(chr(1), $poll_options);
$optionArray = array_slice($optionArray, 0, -1);
$voteArray = explode(chr(1), $poll_votes);
$voteArray = array_slice($voteArray, 0, -1);
$voteTotal = array_sum($voteArray);
$percentage = array();
foreach($voteArray as $votes)
{
$percentage[] = round(($votes/$voteTotal) * 100, 2);
}
$text = $pl->render_poll($row, 'forum', 'oldpolls',true);
$start_datestamp = $gen->convert_date($poll_datestamp, "long");
$end_datestamp = $gen->convert_date($poll_end_datestamp, "long");
//<a href='".e_BASE."user.php?id.{$user_id}'>".$user_name."</a>
$uparams = array('id' => $user_id, 'name' => $user_name);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$user_name."</a>";
$text = "<table style='".USER_WIDTH."'>
<tr>
<td colspan='2' class='mediumtext' style='text-align:center'>
<b>".$tp -> toHTML($poll_title,TRUE,'TITLE')."</b>
<div class='smalltext'>".POLLAN_35." ".$userlink."<br /> ".POLLAN_37." ".$start_datestamp." ".POLLAN_38." ".$end_datestamp.".<br />".POLLAN_26.": {$voteTotal}</div>
<br />
</td>
</tr>";
$text .= "
<div class='smalltext text-right'>
<small>".POLLAN_35." ".$userlink."<br /> ".POLLAN_37." ".$start_datestamp." ".POLLAN_38." ".$end_datestamp."</small></div>
";
$count = 0;
/* $count = 0;
$barl = (file_exists(THEME."images/barl.png") ? THEME."images/barl.png" : e_PLUGIN."poll/images/barl.png");
$barr = (file_exists(THEME."images/barr.png") ? THEME."images/barr.png" : e_PLUGIN."poll/images/barr.png");
@ -92,79 +86,90 @@ if(e_QUERY)
$count++;
}
*/
$query = "SELECT c.*, u.* FROM #comments AS c
LEFT JOIN #user AS u ON FLOOR(SUBSTR(c.comment_author,1,INSTR(c.comment_author,'.')-1))=u.user_id
WHERE comment_item_id=".intval($poll_id)." AND comment_type=4 ORDER BY comment_datestamp";
if ($comment_total = $sql->db_Select_gen($query) !== FALSE)
LEFT JOIN #user AS u ON c.comment_author_id = u.user_id
WHERE comment_item_id=".intval($row['poll_id'])." AND comment_type='4' ORDER BY comment_datestamp";
if ($comment_total = $sql->gen($query))
{
$text .= "<tr><td colspan='2'><br /><br />";
while ($row = $sql->db_Fetch()) {
$text .= $cobj->render_comment($row);
$text .= "<hr /><div>";
while ($row2 = $sql->fetch())
{
$text .= e107::getComment()->render_comment($row2, 'poll', 'comment');
}
$text .= "</td></tr>";
$text .= "</div>";
}
$text .= "</table>";
$ns->tablerender(POLL_ADLAN01." #".$poll_id, $text);
// $text .= "</table>";
$ns->tablerender(LAN_PLUGIN_POLL_NAME." #".$row['poll_id'], $text);
echo "<hr />";
}
}
$query = "SELECT p.*, u.user_name FROM #polls AS p
LEFT JOIN #user AS u ON p.poll_admin_id = u.user_id
WHERE p.poll_type=1
ORDER BY p.poll_datestamp DESC";
if(!$sql->db_Select_gen($query))
{
$ns->tablerender(POLLAN_28, "<div style='text-align:center'>".POLLAN_33."</div>");
// Render List of Polls.
$query = "SELECT p.*, u.user_name FROM #polls AS p
LEFT JOIN #user AS u ON p.poll_admin_id = u.user_id
WHERE p.poll_type=1
ORDER BY p.poll_datestamp DESC";
if(!$array = $sql->retrieve($query,true))
{
$ns->tablerender(POLLAN_28, "<div style='text-align:center'>".POLLAN_33."</div>");
require_once(FOOTERF);
exit;
}
$array = array_slice($array, 1);
if(empty($array))
{
$ns->tablerender(POLLAN_28, "<div style='text-align:center'>".POLLAN_33."</div>");
require_once(FOOTERF);
exit;
}
$text = "<table class='table fborder' style='".USER_WIDTH."'>
<colgroup>
<col style='width: 55%;' />
<col style='width: 15%;' />
<col style='width: 30%;' />
<thead>
<tr>
<th class='fcaption'>".LAN_TITLE."</th>
<th class='fcaption'>".POLLAN_35."</th>
<th class='fcaption'>".POLLAN_36."</th>
</tr></thead><tbody>\n";
foreach($array as $row)
{
$from = $tp->toDate($row['poll_datestamp'], "short");
$to = $tp->toDate($row['poll_end_datestamp'], "short");
$poll_title = $tp->toHtml($row['poll_title'], true, 'TITLE');
$uparams = array('id' => $row['poll_admin_id'], 'name' => $row['user_name']);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$row['user_name']."</a>";
$text .= "<tr>
<td class='forumheader3' style='width: 55%;'><a href='".e_SELF."?".$row['poll_id']."'>{$poll_title}</a></td>
<td class='forumheader3' style='width: 15%;'>".$userlink."</td>
<td class='forumheader3' style='width: 30%;'>".$from." ".POLLAN_38." ".$to."</td>
</tr>\n";
}
$text .= "</tbody></table>";
e107::getRender()->tablerender(POLLAN_28, $text);
require_once(FOOTERF);
exit;
}
$array = $sql -> db_getList();
$oldpollArray = array_slice($array, 1);
if(!count($oldpollArray))
{
$ns->tablerender(POLLAN_28, "<div style='text-align:center'>".POLLAN_33."</div>");
require_once(FOOTERF);
exit;
}
$text = "<table class='fborder' style='".USER_WIDTH."'>
<tr>
<td class='fcaption' style='width: 55%;'>".POLLAN_34."</td>
<td class='fcaption' style='width: 15%;'>".POLLAN_35."</td>
<td class='fcaption' style='width: 30%;'>".POLLAN_36."</td>
</tr>\n";
if (!is_object($tp->e_bb))
{
require_once(e_HANDLER.'bbcode_handler.php');
$tp->e_bb = new e_bbcode;
}
foreach($oldpollArray as $oldpoll)
{
extract($oldpoll);
$from = $gen->convert_date($poll_datestamp, "short");
$to = $gen->convert_date($poll_end_datestamp, "short");
$poll_title = $tp->e_bb->parseBBCodes($poll_title, 0,TRUE,TRUE); // Strip bbcodes
//<a href='".e_BASE."user.php?id.{$poll_admin_id}'>{$user_name}</a>
$uparams = array('id' => $poll_admin_id, 'name' => $user_name);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$user_name."</a>";
$text .= "<tr>
<td class='forumheader3' style='width: 55%;'><a href='".e_SELF."?{$poll_id}'>{$poll_title}</a></td>
<td class='forumheader3' style='width: 15%;'>".$userlink."</td>
<td class='forumheader3' style='width: 30%;'>{$from} ".POLLAN_38." {$to}</td>
</tr>\n";
}
$text .= "</table>";
$ns->tablerender(POLLAN_28, $text);
require_once(FOOTERF);
?>

View File

@ -43,7 +43,7 @@ class poll
$arr_polls_cookies = array();
foreach($_COOKIE as $cookie_name => $cookie_val)
{ // Collect poll cookies
list($str, $int) = explode('_', $cookie_name);
list($str, $int) = explode('_', $cookie_name, 2);
if (($str == 'poll') && is_numeric($int))
{ // Yes, its poll's cookie
$arr_polls_cookies[] = $int;
@ -310,6 +310,12 @@ class poll
}
function render_poll($pollArray = "", $type = "menu", $POLLMODE = "", $returnMethod=FALSE)
{
$ns = e107::getRender();
@ -321,6 +327,7 @@ class poll
switch ($POLLMODE)
{
case 'query' : // Show poll, register any vote
if ($this->get_poll($pollArray) === FALSE)
{
return ''; // No display if no poll
@ -328,12 +335,24 @@ class poll
$pollArray = $this->pollRow;
$POLLMODE = $this->pollmode;
break;
case 'results' :
if ($sql->gen($pollArray))
{
$pollArray = $sql->fetch();
}
break;
case 'oldpolls':
$POLLMODE = 'results';
break;
default:
if(ADMIN)
{
return "<div class='alert alert-danger'>No \$POLLMODE set</div>";
}
}
@ -385,189 +404,157 @@ class poll
}
}
}
/* get template */
if (file_exists(THEME.'poll_template.php'))
{
require(THEME.'poll_template.php');
}
else if (!isset($POLL_NOTVOTED_START))
{
require(e_PLUGIN.'poll/templates/poll_template.php');
}
$template = array();
if(deftrue('BOOTSTRAP'))
{
if($type == 'forum')
$template = ($type == 'forum') ? e107::getTemplate('forum','forum_poll') : e107::getTemplate('poll');
}
else
{
/* get template */
if (file_exists(THEME.'poll_template.php'))
{
require_once(e_PLUGIN."forum/templates/forum_poll_template.php");
$POLL_FORUM_NOTVOTED_START = $FORUM_POLL_TEMPLATE['form']['start'];
$POLL_FORUM_NOTVOTED_LOOP = $FORUM_POLL_TEMPLATE['form']['item'];
$POLL_FORUM_NOTVOTED_END = $FORUM_POLL_TEMPLATE['form']['end'];
$POLL_FORUM_VOTED_START = $FORUM_POLL_TEMPLATE['results']['start'];
$POLL_FORUM_VOTED_LOOP = $FORUM_POLL_TEMPLATE['results']['item'];
$POLL_FORUM_VOTED_END = $FORUM_POLL_TEMPLATE['results']['end'];
require(THEME.'poll_template.php');
}
else if (!isset($POLL_NOTVOTED_START))
{
require(e_PLUGIN.'poll/templates/poll_template.php');
}
$POLL_NOTVOTED_START = $POLL_TEMPLATE['form']['start'];
$POLL_NOTVOTED_LOOP = $POLL_TEMPLATE['form']['item'];
$POLL_NOTVOTED_END = $POLL_TEMPLATE['form']['end'];
$POLL_VOTED_START = $POLL_TEMPLATE['results']['start'];
$POLL_VOTED_LOOP = $POLL_TEMPLATE['results']['item'];
$POLL_VOTED_END = $POLL_TEMPLATE['results']['end'];
}
$preview = FALSE;
if ($type == 'preview')
{
$POLLMODE = 'notvoted';
}
elseif ($type == 'forum')
{
$preview = TRUE;
$template['form']['start'] = $POLL_NOTVOTED_START ;
$template['form']['item'] = $POLL_NOTVOTED_LOOP;
$template['form']['end'] = $POLL_NOTVOTED_END;
$template['results']['start'] = $POLL_VOTED_START;
$template['results']['item'] = $POLL_VOTED_LOOP;
$template['results']['end'] = $POLL_VOTED_END;
$template['denied']['start'] = $POLL_DISALLOWED_START;
$template['denied']['item'] = $POLL_DISALLOWED_LOOP ;
$template['denied']['end'] = $POLL_DISALLOWED_END ;
}
$comment_total = 0;
if ($pollArray['poll_comment'])
{ // Only get comments if they're allowed on poll. And we only need the count ATM
$comment_total = $sql->count("comments", "(*)", "WHERE `comment_item_id`='".intval($pollArray['poll_id'])."' AND `comment_type`=4");
}
$sc = e107::getScBatch('poll');
$sc->setVars($pollArray);
$QUESTION = $tp->toHTML($pollArray['poll_title'], TRUE, "emotes_off, defs");
$VOTE_TOTAL = POLLAN_31.": ".$voteTotal;
$COMMENTS = ($pollArray['poll_comment'] ? " <a href='".e_HTTP."comment.php?comment.poll.".$pollArray['poll_id']."'>".LAN_COMMENTS.": ".$comment_total."</a>" : "");
$poll_count = $sql->count("polls", "(*)", "WHERE poll_id <= '".$pollArray['poll_id']."'");
$OLDPOLLS = '';
if ($poll_count > 1)
{
$OLDPOLLS = ($type == 'menu' ? "<a href='".e_PLUGIN_ABS."poll/oldpolls.php'>".POLLAN_28."</a>" : "");
if ($pollArray['poll_comment']) // Only get comments if they're allowed on poll. And we only need the count ATM
{
$sc->pollCommentTotal = $sql->count("comments", "(*)", "WHERE `comment_item_id`='".intval($pollArray['poll_id'])."' AND `comment_type`=4");
}
//"<a href='".e_HTTP."user.php?id.".$pollArray['poll_admin_id']."'>".$pollArray['user_name']."</a>"
$uparams = array('id' => $pollArray['poll_admin_id'], 'name' => $pollArray['user_name']);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$pollArray['user_name']."</a>";
$AUTHOR = POLLAN_35." ".($type == 'preview' || $type == 'forum' ? USERNAME : $userlink);
$sc->pollCount = $sql->count("polls", "(*)", "WHERE poll_id <= '".$pollArray['poll_id']."'");
$sc->pollRenderMode = $type;
$sc->pollVoteTotal = $voteTotal;
$sc->pollRenderType = $type;
if ($type == 'preview')
{
$POLLMODE = 'notvoted';
}
elseif ($type == 'forum')
{
$sc->pollPreview = true;
}
$text = '';
switch ($POLLMODE)
{
case 'notvoted':
$text = "<form method='post' action='".e_SELF.(e_QUERY ? "?".e_QUERY : "")."'>\n".preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_NOTVOTED_START : $POLL_NOTVOTED_START));
$text = "<form method='post' action='".e_SELF.(e_QUERY ? "?".e_QUERY : "")."'>\n";
$text .= $tp->parseTemplate($template['form']['start'],true, $sc);
$count = 1;
$sc->answerCount = 1;
$alt = 0; // alternate style.
$template = ($type == "forum") ? $POLL_FORUM_NOTVOTED_LOOP : $POLL_NOTVOTED_LOOP;
foreach ($optionArray as $option)
foreach ($optionArray as $option)
{
$sc->answerOption = $option;
// $MODE = ($mode) ? $mode : ""; /* debug */
// $OPTIONBUTTON = ($pollArray['poll_allow_multiple'] ? "<input type='checkbox' name='votea[]' value='$count' />" : "<input type='radio' name='votea' value='$count' />");
// $OPTION = $tp->toHTML($option, TRUE);
// $OPTIONBUTTON = $tp->parseTemplate("{OPTIONBUTTON}",true);
// $OPTION = $tp->parseTemplate("{OPTION}",true);
// $OPTION = $tp->parseTemplate("{ANSWER}",true);
$text .= $tp->parseTemplate($template, true, $sc);
$text .= $tp->parseTemplate($template['form']['item'], true, $sc);
$count ++;
$sc->answerCount++;
}
$SUBMITBUTTON = "<input class='button btn btn-primary' type='submit' name='pollvote' value='".POLLAN_30."' />";
// disable submit when previewing the poll or when NOT viewing the poll in the forum
if (('preview' == $type || $preview == TRUE) && strpos(e_REQUEST_SELF, "forum") === FALSE)
{
$SUBMITBUTTON = "<input class='button btn btn-default e-tip' type='button' name='null' title='Disabled' value='".POLLAN_30."' />";
}
$text .= $tp->parseTemplate($template['form']['end'], true, $sc);
$text .= "\n".preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_NOTVOTED_END : $POLL_NOTVOTED_END))."\n</form>";
$text .= "</form>";
break;
case 'voted':
case 'results' :
if ($pollArray['poll_result_type'] && !strstr(e_SELF, "comment.php"))
{
$text = "<div style='text-align: center;'><br /><br />".POLLAN_39."<br /><br /><a href='".e_HTTP."comment.php?comment.poll.".$pollArray['poll_id']."'>".POLLAN_40."</a></div><br /><br />";
}
else
{
$text = preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_VOTED_START : $POLL_VOTED_START));
$text = $tp->parseTemplate( $template['results']['start'], true, $sc);
$count = 0;
$sc->answerCount = 0;
foreach ($optionArray as $option)
{
$OPTION = $tp->toHTML($option, TRUE);
$BAR = $this->generateBar($percentage[$count]);
// $BAR = ($percentage[$count] ? "<div style='width: 100%'><div style='background-image: url($barl); width: 5px; height: 14px; float: left;'></div><div style='background-image: url($bar); width: ".min(intval($percentage[$count]), 90)."%; height: 14px; float: left;'></div><div style='background-image: url($barr); width: 5px; height: 14px; float: left;'></div></div>" : "");
$PERCENTAGE = $percentage[$count]."%";
$VOTES = POLLAN_31.": ".$voteArray[$count];
$text .= preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_VOTED_LOOP : $POLL_VOTED_LOOP));
$sc->pollPercentage = $percentage[$count];
$sc->answerOption = $option;
$sc->pollVotes = $voteArray[$count];
$text .= $tp->parseTemplate($template['results']['item'], true, $sc);
$count ++;
$sc->answerCount++;
}
$text .= preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_VOTED_END : $POLL_VOTED_END));
$text .= $tp->parseTemplate($template['results']['end'], true, $sc);
}
break;
case 'disallowed':
$text = preg_replace("/\{(.*?)\}/e", '$\1', $POLL_DISALLOWED_START);
$text = $tp->parseTemplate($template['denied']['start'], true, $sc);
$count = 0;
foreach ($optionArray as $option)
{
$MODE = $mode; /* debug */
$OPTION = $tp->toHTML($option, TRUE);
$text .= preg_replace("/\{(.*?)\}/e", '$\1', $POLL_DISALLOWED_LOOP);
$sc->pollPercentage = $percentage[$count];
$sc->answerOption = $option;
$sc->pollVotes = $voteArray[$count];
$text .= $tp->parseTemplate($template['denied']['item'], true, $sc);
$count ++;
}
if ($pollArray['poll_vote_userclass'] == 253)
{
$DISALLOWMESSAGE = POLLAN_41;
}
elseif ($pollArray['poll_vote_userclass'] == 254)
{
$DISALLOWMESSAGE = POLLAN_42;
}
else
{
$DISALLOWMESSAGE = POLLAN_43;
}
$text .= preg_replace("/\{(.*?)\}/e", '$\1', $POLL_DISALLOWED_END);
$text .= $tp->parseTemplate($template['denied']['end'], true, $sc);
break;
}
if (!defined("POLLRENDERED")) define("POLLRENDERED", TRUE);
$caption = (file_exists(THEME."images/poll_menu.png") ? "<img src='".THEME_ABS."images/poll_menu.png' alt='' /> ".POLLAN_MENU_CAPTION : POLLAN_MENU_CAPTION);
if ($type == 'preview')
{
$caption = POLLAN_23.SEP."Preview"; // TODO LAN
$caption = POLLAN_23.SEP.LAN_PREVIEW; // "Preview"; // TODO LAN
$text = "<div class='clearfix'>\n<div class='well span3'>".$text."</div></div>";
}
elseif ($type == 'forum')
@ -682,7 +669,7 @@ class poll
$opts = array(1 => LAN_YES, 0=> LAN_NO);
// Set to IP address.. Can add a pref to Poll admin for 'default front-end storage method' if demand is there for it.
$text .= "<br />
<div class='form-horizontal control-group'>
<label class='control-label'>".LAN_FORUM_3033."</label>
@ -898,34 +885,173 @@ class poll
class poll_shortcodes extends e_shortcode
{
var $answerOption = array();
var $answerCount;
public $answerOption = array();
public $answerCount = 0;
public $pollRenderType = null; // type
public $pollPreview = false;
public $pollVoteTotal = 0;
public $pollCommentTotal = 0;
public $pollPercentage = 0;
public $pollVotes = 0;
public $pollCount = 0; // total polls in the system
private $barl = null;
private $barr = null;
private $bar = null;
public function __construct()
{
$this->barl = (file_exists(THEME.'images/barl.png') ? THEME_ABS.'images/barl.png' : e_PLUGIN_ABS.'poll/images/barl.png');
$this->barr = (file_exists(THEME.'images/barr.png') ? THEME_ABS.'images/barr.png' : e_PLUGIN_ABS.'poll/images/barr.png');
$this->bar = (file_exists(THEME.'images/bar.png') ? THEME_ABS.'images/bar.png' : e_PLUGIN_ABS.'poll/images/bar.png');
}
function sc_option($parm='')
{
return $this->answerOption;
if(!empty($this->answerOption))
{
return $this->answerOption;
}
}
function sc_percentage($parm=null)
{
return $this->pollPercentage."%";
}
function sc_author($parm=null)
{
$uparams = array('id' => $this->var['poll_admin_id'], 'name' => $this->var['user_name']);
$link = e107::getUrl()->create('user/profile/view', $uparams);
$userlink = "<a href='".$link."'>".$this->var['user_name']."</a>";
// return print_a($this->var,true);
return POLLAN_35." ".(($this->pollType == 'preview' || $this->pollType == 'forum') ? USERNAME : $userlink);
}
function sc_oldpolls($parm=null)
{
// return 'type: '.$this->pollCount;
if (intval($this->pollCount) > 1 && ($this->pollRenderType == 'menu'))
{
return "<a href='".e_PLUGIN_ABS."poll/oldpolls.php'>".POLLAN_28."</a>" ;
}
}
function sc_disallowmessage($parm=null)
{
if ($this->var['poll_vote_userclass'] == 253)
{
return POLLAN_41;
}
elseif ($this->var['poll_vote_userclass'] == 254)
{
return POLLAN_42;
}
else
{
return POLLAN_43;
}
}
function sc_votes($parm=null)
{
return POLLAN_31.": ".$this->pollVotes;
}
function sc_bar($parm=null)
{
$perc = $this->pollPercentage;
if(deftrue('BOOTSTRAP',false))
{
// return "<span class='label label-danger'>".$perc."</span>";
$val = intval($perc);
return '
<div class="progress">
<div class="bar progress-bar" role="progressbar" aria-valuenow="'.$val.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$val.'%;">
<span class="sr-only">'.$val.'%</span>
</div>
</div>';
}
else
{
$barl = $this->barl;
$barr = $this->barr;
$bar = $this->bar;
return ($perc ? "<div style='width: 100%'><div style='background-image: url($barl); width: 5px; height: 14px; float: left;'></div><div style='background-image: url($bar); width: ".min(intval($perc), 90)."%; height: 14px; float: left;'></div><div style='background-image: url($barr); width: 5px; height: 14px; float: left;'></div></div>" : "");
}
}
function sc_optionbutton($parm='')
{
return ($this->var['poll_allow_multiple'] ? "<input type='checkbox' name='votea[]' value='$count' />" : "<input type='radio' name='votea' value='".$this->answerCount."' />");
return ($this->var['poll_allow_multiple'] ? "<input type='checkbox' name='votea[]' value='$this->answerCount' />" : "<input type='radio' name='votea' value='".$this->answerCount."' />");
}
function sc_question($parm = "")
{
$tp = e107::getParser();
return $tp->toHTML($this->var['poll_title'], TRUE, "emotes_off, defs");
return $tp->toHTML($this->var['poll_title'], true, "TITLE");
}
function sc_answer($parm='')
{
$frm = e107::getForm();
$opt = array('label'=> $this->answerOption);
return $frm->radio('votea', $this->answerCount,false, $opt);
// $this->answerOption
if(empty($this->var['poll_allow_multiple']))
{
return $frm->radio('votea', $this->answerCount,false, $opt);
}
else
{
return $frm->checkbox('votea[]', $this->answerCount,false, $opt);
}
}
function sc_submitbutton($parm=null)
{
if (('preview' == $this->pollType || $this->pollPreview == true) && strpos(e_REQUEST_SELF, "forum") === false)
{
return "<input class='button btn btn-default e-tip' type='button' name='null' title='Disabled' value='".POLLAN_30."' />";
}
return "<input class='button btn btn-primary' type='submit' name='pollvote' value='".POLLAN_30."' />";
// disable submit when previewing the poll or when NOT viewing the poll in the forum
}
function sc_vote_total($parm=null)
{
return POLLAN_31.": ".intval($this->pollVoteTotal);
}
function sc_comments($parm=null)
{
return ($this->var['poll_comment'] ? " <a href='".e_HTTP."comment.php?comment.poll.".$this->var['poll_id']."'>".LAN_COMMENTS.": ".$this->pollCommentTotal."</a>" : "");
}
}

View File

@ -233,8 +233,16 @@ $POLL_TEMPLATE['results']['end'] = "
</div>
";
/* v2.x template for polls when user HAS been denied the ability to vote (userclass) */
$POLL_TEMPLATE['denied']['start'] = $POLL_TEMPLATE['results']['start'];
$POLL_TEMPLATE['denied']['item'] = $POLL_TEMPLATE['results']['item'];
$POLL_TEMPLATE['denied']['end'] = "<div class='alert text-warning text-center'>{DISALLOWMESSAGE}</div>
<div class='text-center'><small>{VOTE_TOTAL}</small></div>
{COMMENTS} {OLDPOLLS}
</div>
</div>
";
?>