From e9d3ae3841075fb533b3be429df514dccb9ef47b Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 25 Mar 2013 23:00:32 -0700 Subject: [PATCH] Forum/Poll template work. --- e107_plugins/forum/forum_viewtopic.php | 23 +- .../shortcodes/batch/post_shortcodes.php | 117 +++++++-- .../forum/templates/forum_poll_template.php | 71 ++++++ .../forum/templates/forum_post_template.php | 23 +- .../templates/forum_viewforum_template.php | 2 +- .../templates/forum_viewtopic_template.php | 9 +- e107_plugins/poll/poll_class.php | 234 +++++++++++++++--- 7 files changed, 404 insertions(+), 75 deletions(-) create mode 100644 e107_plugins/forum/templates/forum_poll_template.php diff --git a/e107_plugins/forum/forum_viewtopic.php b/e107_plugins/forum/forum_viewtopic.php index 7a5804fa3..412a80b7d 100644 --- a/e107_plugins/forum/forum_viewtopic.php +++ b/e107_plugins/forum/forum_viewtopic.php @@ -131,16 +131,21 @@ if ($thread->message) e107::getMessage()->add($thread->message); } -if (isset($thread->threadInfo['thread_options']['poll'])) -{ - if (!defined('POLLCLASS')) - { - include (e_PLUGIN . 'poll/poll_class.php'); - } + + +//if (isset($thread->threadInfo['thread_options']['poll'])) //XXX Currently Failing - misconfigured thread-options. +//{ $_qry = 'SELECT * FROM `#polls` WHERE `poll_datestamp` = ' . $thread->threadId; - $poll = new poll; - $pollstr = "
" . $poll->render_poll($_qry, 'forum', 'query', true) . '
'; -} + if($sql->gen($_qry)) + { + if (!defined('POLLCLASS')) + { + include_once(e_PLUGIN . 'poll/poll_class.php'); + } + $poll = new poll; + $pollstr = "
" . $poll->render_poll($_qry, 'forum', 'query', true) . '
'; + } +//} //Load forum templates // FIXME - new template paths! if (file_exists(THEME . 'forum_design.php')) diff --git a/e107_plugins/forum/shortcodes/batch/post_shortcodes.php b/e107_plugins/forum/shortcodes/batch/post_shortcodes.php index a6fd69af1..8465231c6 100644 --- a/e107_plugins/forum/shortcodes/batch/post_shortcodes.php +++ b/e107_plugins/forum/shortcodes/batch/post_shortcodes.php @@ -129,23 +129,113 @@ class plugin_forum_post_shortcodes extends e_shortcode } } + + function sc_forumattachment() + { + $pref = e107::getPref(); + global $forum; + + //.
".($pref['image_post'] ? "Attach file / image" : "Attach file")."
+ + $tooltip = "Allowed file types | ".vartrue($allowed_filetypes).". Any other file type will be deleted instantly. + Maximum file size: ".(vartrue($max_upload_size) ? $max_upload_size."bytes" : ini_get('upload_max_filesize')); + + $fileattach = " + + +
+
+ + + +
+ +
+ + "; + + if ($forum->prefs->get('attach') && (check_class($pref['upload_class']) || getperms('0'))) + { + return $fileattach; + } + + } + + function sc_postoptions($parm='') + { + $type = $this->sc_postthreadas(); + $poll = $this->sc_poll('front'); + $attach = $this->sc_forumattachment(); + + $text = " + +
+
+
+ +
+ ".$type." +
+
+
+ "; + + if($poll) + { + $text .= "
+ ".$poll." +
"; + + } + + if($attach) + { + $text .= " +
+ ".$attach." +
"; + } + + $text .= " +
"; + + + return $text; + + + + } + function sc_poll($parm='') { - global $forum, $poll_form, $action; - - if(!$poll_form) + global $forum, $action; + + if(is_readable(e_PLUGIN."poll/poll_class.php")) { - if(is_readable(e_PLUGIN."poll/poll_class.php")) - { - require_once(e_PLUGIN."poll/poll_class.php"); - $pollo = new poll; - $poll_form = $pollo -> renderPollForm("forum"); - } + require_once(e_PLUGIN."poll/poll_class.php"); + $pollo = new poll; + $type = ($parm == 'front') ? 'front' : 'forum'; + + $poll_form = $pollo -> renderPollForm($type); } + if ($action == 'nt' && check_class($forum->prefs->get('poll')) && strpos(e_QUERY, 'edit') === false) { + if($parm == 'front') + { + return $poll_form; + } + + return "Add Poll "; @@ -153,22 +243,21 @@ class plugin_forum_post_shortcodes extends e_shortcode return ''; } + function sc_postthreadas() { global $action, $threadInfo; if (MODERATOR && $action == "nt") { - $thread_sticky = (isset($_POST['threadtype']) ? $_POST['threadtype'] : vartrue($threadInfo['thread_sticky'])); // no reference of 'head' $threadInfo['head']['thread_sticky'] + $thread_sticky = (isset($_POST['threadtype']) ? $_POST['threadtype'] : vartrue($threadInfo['thread_sticky'],0)); // no reference of 'head' $threadInfo['head']['thread_sticky'] $opts = array(0 => "Normal", 1 => "Sticky", 2 => "Announcement"); return e107::getForm()->radio('threadtype',$opts, $thread_sticky); - - - return "
post thread as - ".LAN_1." ".LAN_2." ".LAN_3.""; + // return "
post thread as + // ".LAN_1." ".LAN_2." ".LAN_3.""; } return ''; } diff --git a/e107_plugins/forum/templates/forum_poll_template.php b/e107_plugins/forum/templates/forum_poll_template.php new file mode 100644 index 000000000..8e4222c82 --- /dev/null +++ b/e107_plugins/forum/templates/forum_poll_template.php @@ -0,0 +1,71 @@ + +
+
+ +
+
+
+ {SUBMITBUTTON} +
+
+
+ +"; + + + +/* v2.x template for forum polls when user HAS voted */ + +$FORUM_POLL_TEMPLATE['results']['start'] = " +
+
+
Poll: {QUESTION}
+"; + +$FORUM_POLL_TEMPLATE['results']['item'] = " + {OPTION}{PERCENTAGE} + {BAR} +"; + +$FORUM_POLL_TEMPLATE['results']['end'] = " +
{VOTE_TOTAL}
+
+
+"; + + + + + + +?> \ No newline at end of file diff --git a/e107_plugins/forum/templates/forum_post_template.php b/e107_plugins/forum/templates/forum_post_template.php index dfcb50d4c..c15d963ae 100644 --- a/e107_plugins/forum/templates/forum_post_template.php +++ b/e107_plugins/forum/templates/forum_post_template.php @@ -243,23 +243,14 @@ $FORUMPOST_TEMPLATE['form'] = " {POSTBOX} {EMAILNOTIFY} - - - - - Post thread as - - {POSTTHREADAS} - {POLL} - {FILEATTACH} - - - - {BUTTONS} - - - + Post Options + + {POSTOPTIONS} + +
+ {BUTTONS} +
{FORMEND} diff --git a/e107_plugins/forum/templates/forum_viewforum_template.php b/e107_plugins/forum/templates/forum_viewforum_template.php index c99ae7025..2975d556a 100644 --- a/e107_plugins/forum/templates/forum_viewforum_template.php +++ b/e107_plugins/forum/templates/forum_viewforum_template.php @@ -283,7 +283,7 @@ $FORUM_CRUMB['forum']['value'] = "{FORUM_TITLE}"; // {BREADCRUMB} //FIXME Breadcrumb looks crummy $FORUM_VIEWFORUM_TEMPLATE['start'] = ""; -$FORUM_VIEWFORUM_TEMPLATE['header'] = "

{FORUMTITLE}

{NEWTHREADBUTTONX}
+$FORUM_VIEWFORUM_TEMPLATE['header'] = "

{FORUMTITLE}

{NEWTHREADBUTTONX}
diff --git a/e107_plugins/forum/templates/forum_viewtopic_template.php b/e107_plugins/forum/templates/forum_viewtopic_template.php index 2c9821dd8..3bc5f1b04 100644 --- a/e107_plugins/forum/templates/forum_viewtopic_template.php +++ b/e107_plugins/forum/templates/forum_viewtopic_template.php @@ -2,13 +2,10 @@ /* * e107 website system * - * Copyright (C) 2008-2011 e107 Inc (e107.org) + * Copyright (C) 2008-2013 e107 Inc (e107.org) * Released under the terms and conditions of the * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * - * - * $URL$ - * $Id$ */ if (!defined('e107_INIT')) { exit; } @@ -310,11 +307,11 @@ $FORUM_CRUMB['forum']['value'] = "{FORU $FORUM_VIEWTOPIC_TEMPLATE['start'] = " -
+
{BACKLINK}
-
+

{THREADNAME}

{BUTTONSX}
diff --git a/e107_plugins/poll/poll_class.php b/e107_plugins/poll/poll_class.php index c799f5047..815d5d619 100644 --- a/e107_plugins/poll/poll_class.php +++ b/e107_plugins/poll/poll_class.php @@ -377,6 +377,23 @@ class poll { require(e_PLUGIN.'poll/templates/poll_template.php'); } + + if($type == 'forum' && e_BOOTSTRAP === true) + { + + 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']; + + } + + $preview = FALSE; if ($type == 'preview') @@ -394,39 +411,61 @@ class poll $comment_total = $sql->db_Count("comments", "(*)", "WHERE `comment_item_id`='".intval($pollArray['poll_id'])."' AND `comment_type`=4"); } - $QUESTION = $tp -> toHTML($pollArray['poll_title'], TRUE, "emotes_off, defs"); - $VOTE_TOTAL = POLLAN_31.": ".$voteTotal; - $COMMENTS = ($pollArray['poll_comment'] ? "
".POLLAN_27.": ".$comment_total."" : ""); - $poll_count = $sql->db_Count("polls", "(*)", "WHERE poll_id <= '".$pollArray['poll_id']."'"); + $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'] ? " ".POLLAN_27.": ".$comment_total."" : ""); + + + $poll_count = $sql->db_Count("polls", "(*)", "WHERE poll_id <= '".$pollArray['poll_id']."'"); $OLDPOLLS = ''; + if ($poll_count > 1) { $OLDPOLLS = ($type == 'menu' ? "".POLLAN_28."" : ""); } - $AUTHOR = POLLAN_35." ".($type == 'preview' || $type == 'forum' ? USERNAME : "".$pollArray['user_name'].""); + + $AUTHOR = POLLAN_35." ".($type == 'preview' || $type == 'forum' ? USERNAME : "".$pollArray['user_name'].""); + + + switch ($POLLMODE) { case 'notvoted': $text = "
\n".preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_NOTVOTED_START : $POLL_NOTVOTED_START)); $count = 1; + $sc->answerCount = 1; $alt = 0; // alternate style. + + $template = ($type == "forum") ? $POLL_FORUM_NOTVOTED_LOOP : $POLL_NOTVOTED_LOOP; + foreach ($optionArray as $option) { + $sc->answerOption = $option; // $MODE = ($mode) ? $mode : ""; /* debug */ - $OPTIONBUTTON = ($pollArray['poll_allow_multiple'] ? "" : ""); - $OPTION = $tp->toHTML($option, TRUE); - if (isset($POLL_NOTVOTED_LOOP_ALT) && $POLL_NOTVOTED_LOOP_ALT && $type != "forum") - { // alternating style - $text .= preg_replace("/\{(.*?)\}/e", '$\1', ($alt == 0 ? $POLL_NOTVOTED_LOOP : $POLL_NOTVOTED_LOOP_ALT)); - $alt = ($alt ==0) ? 1 : 0; - } - else - { - $text .= preg_replace("/\{(.*?)\}/e", '$\1', ($type == "forum" ? $POLL_FORUM_NOTVOTED_LOOP : $POLL_NOTVOTED_LOOP)); - } + // $OPTIONBUTTON = ($pollArray['poll_allow_multiple'] ? "" : ""); + // $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); + $count ++; + $sc->answerCount++; } + + $SUBMITBUTTON = ""; if (('preview' == $type || $preview == TRUE) && strpos(e_SELF, "viewtopic") === FALSE) { @@ -486,13 +525,15 @@ class poll } if (!defined("POLLRENDERED")) define("POLLRENDERED", TRUE); + $caption = (file_exists(THEME."images/poll_menu.png") ? " ".POLLAN_MENU_CAPTION : POLLAN_MENU_CAPTION); + if ($type == 'preview') { $caption = POLLAN_23; $text = "
\n
\n\n
\n$text\n
"; } - else if ($type == 'forum') + elseif ($type == 'forum') { $caption = LAN_4; } @@ -535,11 +576,100 @@ class poll $mode = "admin" :: called from admin_config.php $mode = "forum" :: called from forum_post.php */ + /** + * Render a Poll creation Form + * @param $mode string - admin | forum | front + */ function renderPollForm($mode='admin') { $tp = e107::getParser(); $frm = e107::getForm(); + + //XXX New v2.x default for front-end. Currently used by forum-post in bootstrap mode. + if ($mode == 'front') + { + + + $text = " + +
+ ".LAN_386." +
+ +
+
+ +
"; + + $option_count = vartrue($_POST['poll_option']) ? count($_POST['poll_option']) : 2; + $text .= " +
"; + + for($count = 1; $count <= $option_count; $count++) + { + if ($count != 1 && $_POST['poll_option'][($count-1)] =="") + { + // break; + } + $opt = ($count==1) ? "id='pollopt' class='btn-group input-append' " : ""; + $text .=""; + $text .= "
"; + } + + $text .="
+
+
+
+
"; + + //FIXME - get this looking good with Bootstrap CSS only. + + $opts = array(1=> "yes", 0=> "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 .= " +
+ +
+ ". $frm->radio('multipleChoice',$opts, vartrue($_POST['multipleChoice'], 0) ).$frm->hidden('storageMethod',1)." +
+
+ + "; + + return $text; + + + /* + $text .= " +
".POLL_506." + + ".POLL_507."   + ".POLL_508." + +
"; + */ + + //XXX Should NOT be decided by USER + /* + $text .= " + +
+ ".POLLAN_16." + + ".POLLAN_17."
+ ".POLLAN_18."
+ ".POLLAN_19." +
+ "; + */ + + + } + + //TODO Hardcoded FORUM code needs to be moved somewhere. if ($mode == 'forum') { @@ -706,17 +836,63 @@ class poll } } -echo ' -'; + + + + + + + + + + + + +e107::js('inline', ' + + function setcook(pollid){ + var name = "poll_"+pollid; + var date = new Date(); + var value = pollid; + date.setTime(date.getTime()+(365*24*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + document.cookie = name+"="+value+expires+"; path=/"; + } + '); + + ?> \ No newline at end of file