| 12 | | Instructions: install, activate, tinker with settings located several lines below |
|---|
| 13 | | |
|---|
| 14 | | Version History: |
|---|
| 15 | | 0.01 : bb-polls is born - no voting yet, just create a poll for testing |
|---|
| 16 | | 0.10 : first public beta |
|---|
| 17 | | 0.11 : bug fix for polls on page 1 setting |
|---|
| 18 | | 0.12 : poll can now be on first/last/both/all pages & add text to topic titles like [poll] |
|---|
| 19 | | 0.13 : more control over who can add/vote/view/edit polls |
|---|
| 20 | | 0.14 : colour fixes for default theme |
|---|
| 21 | | 0.15 : cache performance fixes, extra custom label ability, more css classes, colour tweaks |
|---|
| 22 | | 0.16 : added __() for automatic translations when possible, all text is now in array near top |
|---|
| 23 | | 0.17 : trick bbpress to keep data unserialized until needed for performance (backward compatible) |
|---|
| 24 | | 0.18 : post data fix for refreshed pages (via redirect, nasty but no other way?) |
|---|
| 25 | | 0.19 : first ajax-ish behaviours added for view current voting results and then back to the form - pre-caching forms, but no submit saving ajax yet |
|---|
| 26 | | 0.20 : more text found & moved to array for translations, float removed from default css for Right-to-Left setups, graph bars limited to min & max |
|---|
| 27 | | 0.21 : many little fixes for IE to work properly, css changes to make IE vs Firefox almost identical |
|---|
| 28 | | 0.22 : voting is now ajax-ish - only non-ajax-ish form is the one to create a poll, might be awhile - cancel button also added to create poll form |
|---|
| 29 | | 0.23 : javascript fix for internet explorer (has to delay append action a few milliseconds or update won't appear to happen) |
|---|
| 30 | | 0.24 : bug fix for opera trying to cache javascript requests - added alert if they try to vote without selection (todo: need to alert on non-ajax) |
|---|
| 31 | | 0.25 : experimental double-execute fix for Null |
|---|
| 32 | | 0.26 : warnings cleanup for better code |
|---|
| 33 | | 0.27 : bugfix: poll not showing for non-logged in guest and view setting set to "read" |
|---|
| 34 | | 0.28 : enhancement so admin are always offered to start a poll on any topic regardless |
|---|
| 35 | | 0.29 : enhancement so admin can always delete any poll |
|---|
| 36 | | 0.30 : enhancement so admin can edit any poll (don't change the order of questions, it's a simple edit for now). Vote count edits, etc. coming later. |
|---|
| 37 | | 0.31 : bug fix to also track/re-save change of poll type (multiple/single) on edit |
|---|
| 38 | | 0.33 : bug fix on null topic_id saving poll setup |
|---|
| 39 | | |
|---|
| | 12 | Instructions: install, activate, check admin menu for options. |
|---|
| | 13 | |
|---|
| 86 | | |
|---|
| 87 | | $bb_polls['style']="#bb_polls {list-style: none; width:350px; line-height:120%; margin:5px 0; padding:5px; border:1px solid #ADADAD; font-size:85%; color:#000; background:#eee; } |
|---|
| 88 | | #bb_polls .submit {cursor: pointer; cursor: hand; text-align:center; padding:2px 5px;} |
|---|
| 89 | | #bb_polls .nowrap {white-space:nowrap;} |
|---|
| 90 | | #bb_polls p {margin:15px 0;padding:0;} |
|---|
| 91 | | #bb_polls .poll_question, #bb_polls .poll_footer {font-weight:bold; text-align:center; color:#2E6E15;} |
|---|
| 92 | | #bb_polls .poll_label {font-weight:bold;} |
|---|
| 93 | | #bb_polls .poll_option {margin:-12px 0 -5px 0; text-align:center;font-weight:bold; font-size:9px; line-height:5px; padding:2px 1px; border:1px solid #303030; color:#fff; } |
|---|
| 94 | | #bb_polls .poll_option1 {background:red;} |
|---|
| 95 | | #bb_polls .poll_option2 {background:green;} |
|---|
| 96 | | #bb_polls .poll_option3 {background:blue;} |
|---|
| 97 | | #bb_polls .poll_option4 {background:orange;} |
|---|
| 98 | | #bb_polls .poll_option5 {background:purple;} |
|---|
| 99 | | #bb_polls .poll_option6 {background:pink;} |
|---|
| 100 | | #bb_polls .poll_option7 {background:yellow;} |
|---|
| 101 | | #bb_polls .poll_option8 {background:navy;} |
|---|
| 102 | | #bb_polls .poll_option9 {background:grey;} |
|---|
| 103 | | "; |
|---|
| 104 | | |
|---|
| 105 | | // - stop editing here - |
|---|
| | 95 | |
|---|
| | 96 | }} |
|---|
| | 97 | // if (BB_IS_ADMIN) { // doesn't exist until 1040 :-( |
|---|
| | 98 | |
|---|
| | 99 | $bb_polls_type['minimum_view_level']="read,participate,moderate,administrate"; |
|---|
| | 100 | $bb_polls_type['minimum_vote_level']="participate,moderate,administrate"; |
|---|
| | 101 | $bb_polls_type['minimum_add_level']="participate,moderate,administrate"; |
|---|
| | 102 | $bb_polls_type['minimum_edit_level']="participate,moderate,administrate"; |
|---|
| | 103 | $bb_polls_type['minimum_delete_level']="participate,moderate,administrate"; |
|---|
| | 104 | |
|---|
| | 105 | $bb_polls_type['only_topic_author_can_add']="binary"; |
|---|
| | 106 | $bb_polls_type['show_poll_on_which_pages']="first,last,both,all"; |
|---|
| | 107 | |
|---|
| | 108 | $bb_polls_type['add_within_hours']="1,2,6,12,24,48,72,999999"; |
|---|
| | 109 | $bb_polls_type['edit_within_hours']="1,2,6,12,24,48,72,999999"; |
|---|
| | 110 | |
|---|
| | 111 | $bb_polls_type['close_with_topic']="binary"; |
|---|
| | 112 | $bb_polls_type['close_after_days']="1,2,7,30,365"; |
|---|
| | 113 | |
|---|
| | 114 | $bb_polls_type['max_options']="3,5,9,15,20"; |
|---|
| | 115 | $bb_polls_type['max_length']="50,100,200"; |
|---|
| | 116 | $bb_polls_type['options_sort']="binary"; |
|---|
| | 117 | |
|---|
| | 118 | $bb_polls_type['use_ajax']="binary"; |
|---|
| | 119 | $bb_polls_type['test_mode']="binary"; |
|---|
| | 120 | |
|---|
| | 121 | $bb_polls_type['style']="textarea"; |
|---|
| | 122 | /* |
|---|
| | 123 | $bb_polls_type['poll_question']="text"; |
|---|
| | 124 | $bb_polls_type['poll_instructions']="text"; |
|---|
| | 125 | $bb_polls_type['label_single']="text"; |
|---|
| | 126 | $bb_polls_type['label_multiple']="text"; |
|---|
| | 127 | $bb_polls_type['label_poll_text']="text"; |
|---|
| | 128 | $bb_polls_type['label_votes_text']="text"; |
|---|
| | 129 | $bb_polls_type['label_vote_text']="text"; |
|---|
| | 130 | $bb_polls_type['label_save_text']="text"; |
|---|
| | 131 | $bb_polls_type['label_cancel_text']="text"; |
|---|
| | 132 | $bb_polls_type['label_edit_text']="text"; |
|---|
| | 133 | $bb_polls_type['label_delete_text']="text"; |
|---|
| | 134 | $bb_polls_type['label_option_text']="text"; |
|---|
| | 135 | $bb_polls_type['label_question_text']="text"; |
|---|
| | 136 | $bb_polls_type['label_results_text']="text"; |
|---|
| | 137 | $bb_polls_type['label_now_text']="text"; |
|---|
| | 138 | $bb_polls_type['label_nocheck_text']="text"; |
|---|
| | 139 | $bb_polls_type['label_warning_text']="text"; |
|---|
| | 140 | */ |
|---|
| | 141 | |
|---|
| | 142 | $bb_polls_label['minimum_view_level']=__("At what level can users SEE polls?"); |
|---|
| | 143 | $bb_polls_label['minimum_vote_level']=__("At what level can users VOTE on polls?"); |
|---|
| | 144 | $bb_polls_label['minimum_add_level']=__("At what level can users ADD a poll?"); |
|---|
| | 145 | $bb_polls_label['minimum_edit_level']=__("At what level can users EDIT a poll?"); |
|---|
| | 146 | $bb_polls_label['minimum_delete_level']=__("At what level can users DELETE a poll?"); |
|---|
| | 147 | |
|---|
| | 148 | $bb_polls_label['only_topic_author_can_add']=__("Only the topic starter can add a poll?"); |
|---|
| | 149 | $bb_polls_label['show_poll_on_which_pages']=__("Show poll only on which topic pages?"); |
|---|
| | 150 | |
|---|
| | 151 | $bb_polls_label['add_within_hours']=__("How many hours later can a poll be ADDED?"); |
|---|
| | 152 | $bb_polls_label['edit_within_hours']=__("How many hours later can a poll be EDITED?"); |
|---|
| | 153 | |
|---|
| | 154 | $bb_polls_label['close_with_topic']=__("Should polls close when a topic is closed?"); |
|---|
| | 155 | $bb_polls_label['close_after_days']=__("If not closed with topic, after how many days?"); |
|---|
| | 156 | |
|---|
| | 157 | $bb_polls_label['max_options']=__("How many poll question slots should be offered?"); |
|---|
| | 158 | $bb_polls_label['max_length']=__("How many characters can the poll questions be?"); |
|---|
| | 159 | $bb_polls_label['options_sort']=__("Sort results by number of votes?"); |
|---|
| | 160 | |
|---|
| | 161 | $bb_polls_label['use_ajax']=__("Use AJAX-like actions if javascript enabled?"); |
|---|
| | 162 | $bb_polls_label['test_mode']=__("Enable TEST MODE (multiple votes per person)?"); |
|---|
| | 163 | |
|---|
| | 164 | $bb_polls_label['style']=__("Custom CSS style for polls:"); |
|---|
| | 165 | |
|---|
| | 166 | /* |
|---|
| | 167 | $bb_polls_label['poll_question']=__("Question to ask to start poll:"); |
|---|
| | 168 | $bb_polls_label['poll_instructions']=__("Instructions to add poll:"); |
|---|
| | 169 | $bb_polls_label['label_single']=__("Label for single vote selections:"); |
|---|
| | 170 | $bb_polls_label['label_multiple']=__("Label for multiple vote selections:"); |
|---|
| | 171 | $bb_polls_label['label_poll_text']=__("Text to show if a topic title has a poll:"); |
|---|
| | 172 | $bb_polls_label['label_votes_text']=__("Text to show for votes:"); |
|---|
| | 173 | $bb_polls_label['label_vote_text']=__("Text to show for VOTE button:"); |
|---|
| | 174 | $bb_polls_label['label_save_text']=__("Text to show for SAVE button:"); |
|---|
| | 175 | $bb_polls_label['label_cancel_text']=__("Text to show for CANCEL button:"); |
|---|
| | 176 | $bb_polls_label['label_edit_text']=__("Text to show for EDIT button:"); |
|---|
| | 177 | $bb_polls_label['label_delete_text']=__("Text to show for DELETE button:"); |
|---|
| | 178 | $bb_polls_label['label_option_text']=__("Text to show for each option:"); |
|---|
| | 179 | $bb_polls_label['label_question_text']=__("Text to show for question label:"); |
|---|
| | 180 | $bb_polls_label['label_results_text']=__("Text to show for results label:"); |
|---|
| | 181 | $bb_polls_label['label_now_text']=__("Text to show for VOTE NOW label:"); |
|---|
| | 182 | $bb_polls_label['label_nocheck_text']=__("No selection warning:"); |
|---|
| | 183 | $bb_polls_label['label_warning_text']=__("Delete warning:"); |
|---|
| | 184 | */ |
|---|
| | 185 | |
|---|
| | 186 | // } |
|---|
| | 187 | |
|---|
| | 188 | bb_polls_add_header(); // add_action('bb_send_headers', 'bb_polls_add_header'); |
|---|
| | 189 | add_action('bb_head', 'bb_polls_add_css'); |
|---|
| | 190 | add_filter('topic_title', 'bb_polls_title'); |
|---|
| | 191 | add_action('topicmeta','bb_polls_pre_poll',200); |
|---|
| | 192 | } |
|---|
| 441 | | } add_action('bb_head', 'bb_polls_add_css'); |
|---|
| | 528 | } |
|---|
| | 529 | |
|---|
| | 530 | function bb_polls_admin_page() { |
|---|
| | 531 | global $bb_polls, $bb_polls_type, $bb_polls_label; |
|---|
| | 532 | ?> |
|---|
| | 533 | <div style="text-align:right;margin-bottom:-1.5em;"> |
|---|
| | 534 | [ <a href="<?php echo add_query_arg('bb_polls_reset','1',remove_query_arg('bb_polls_recount')); ?>">Reset All Settings To Defaults</a> ] |
|---|
| | 535 | </div> |
|---|
| | 536 | |
|---|
| | 537 | <h2>bbPress Polls</h2> |
|---|
| | 538 | |
|---|
| | 539 | <form method="post" name="bb_polls_form" id="bb_polls_form" action="<?php echo remove_query_arg(array('bb_polls_reset','bb_polls_recount')); ?>"> |
|---|
| | 540 | <input type=hidden name="bb_polls" value="1"> |
|---|
| | 541 | <table class="widefat"> |
|---|
| | 542 | <thead> |
|---|
| | 543 | <tr> <th width="33%">Option</th> <th>Setting</th> </tr> |
|---|
| | 544 | </thead> |
|---|
| | 545 | <tbody> |
|---|
| | 546 | <?php |
|---|
| | 547 | |
|---|
| | 548 | foreach(array_keys( $bb_polls_type) as $key) { |
|---|
| | 549 | |
|---|
| | 550 | // if ($key=="style") {echo "<div id='bb_polls_rollup' style='display:none;'>";} |
|---|
| | 551 | |
|---|
| | 552 | $bb_polls[$key]=stripslashes_deep($bb_polls[$key]); |
|---|
| | 553 | $colspan= (substr($bb_polls_type[$key],0,strpos($bb_polls_type[$key].",",","))=="array") ? "2" : "1"; |
|---|
| | 554 | ?> |
|---|
| | 555 | <tr <?php alt_class('recount'); ?> |
|---|
| | 556 | <td nowrap colspan=<?php echo $colspan; ?>> |
|---|
| | 557 | <label for="bb_polls_<?php echo $key; ?>"> |
|---|
| | 558 | <b><?php if ($bb_polls_label[$key]) {echo $bb_polls_label[$key];} else {echo ucwords(str_replace("_"," ",$key));} ?></b> |
|---|
| | 559 | </label> |
|---|
| | 560 | <?php |
|---|
| | 561 | if ($colspan<2) {echo "</td><td>";} else {echo "<br />";} |
|---|
| | 562 | switch (substr($bb_polls_type[$key],0,strpos($bb_polls_type[$key].",",","))) : |
|---|
| | 563 | case 'binary' : |
|---|
| | 564 | ?><input type=radio name="<?php echo $key; ?>" value="1" <?php echo ($bb_polls[$key]==true ? 'checked="checked"' : ''); ?> >Yes |
|---|
| | 565 | <input type=radio name="<?php echo $key; ?>" value="0" <?php echo ($bb_polls[$key]==false ? 'checked="checked"' : ''); ?> >No <?php |
|---|
| | 566 | break; |
|---|
| | 567 | case 'numeric' : |
|---|
| | 568 | ?><input type=text maxlength=3 name="<?php echo $key; ?>" value="<?php echo $bb_polls[$key]; ?>"> <?php |
|---|
| | 569 | break; |
|---|
| | 570 | case 'textarea' : |
|---|
| | 571 | ?><textarea rows="9" style="width:98%" name="<?php echo $key; ?>"><?php echo $bb_polls[$key]; ?></textarea><?php |
|---|
| | 572 | break; |
|---|
| | 573 | default : // type "input" and everything else we forgot |
|---|
| | 574 | $values=explode(",",$bb_polls_type[$key]); |
|---|
| | 575 | if (count($values)>2) { |
|---|
| | 576 | echo '<select name="'.$key.'">'; |
|---|
| | 577 | foreach ($values as $value) {echo '<option '; echo ($bb_polls[$key]== $value ? 'selected' : ''); echo '>'.$value.'</option>'; } |
|---|
| | 578 | echo '</select>'; |
|---|
| | 579 | } else { |
|---|
| | 580 | ?><input type=text style="width:98%" name="<?php echo $key; ?>" value="<?php echo $bb_polls[$key]; ?>"> <?php |
|---|
| | 581 | } |
|---|
| | 582 | endswitch; |
|---|
| | 583 | ?> |
|---|
| | 584 | </td> |
|---|
| | 585 | </tr> |
|---|
| | 586 | <?php |
|---|
| | 587 | } |
|---|
| | 588 | // echo "</div>"; |
|---|
| | 589 | ?> |
|---|
| | 590 | </tbody> |
|---|
| | 591 | </table> |
|---|
| | 592 | <p class="submit"><input type="submit" name="submit" value="Save bbPress Polls Settings"></p> |
|---|
| | 593 | |
|---|
| | 594 | </form> |
|---|
| | 595 | <?php |
|---|
| | 596 | } |
|---|
| | 597 | |
|---|
| | 598 | function bb_polls_process_post() { |
|---|
| | 599 | global $bb_polls; |
|---|
| | 600 | if (bb_current_user_can('administrate')) { |
|---|
| | 601 | if (isset($_REQUEST['bb_polls_reset'])) { |
|---|
| | 602 | unset($bb_polls); |
|---|
| | 603 | bb_delete_option('bb_polls'); |
|---|
| | 604 | bb_polls_initialize(); |
|---|
| | 605 | bb_update_option('bb_polls',$bb_polls); |
|---|
| | 606 | bb_admin_notice('<b>bbPress Polls: '.__('All Settings Reset To Defaults.').'</b>'); // , 'error' |
|---|
| | 607 | wp_redirect(remove_query_arg(array('bb_polls_reset'))); // bug workaround, page doesn't show reset settings |
|---|
| | 608 | } |
|---|
| | 609 | elseif (isset($_POST['submit']) && isset($_POST['bb_polls'])) { |
|---|
| | 610 | |
|---|
| | 611 | foreach(array_keys( $bb_polls) as $key) { |
|---|
| | 612 | if (isset($_POST[$key])) {$bb_polls[$key]=$_POST[$key];} |
|---|
| | 613 | } |
|---|
| | 614 | |
|---|
| | 615 | bb_update_option('bb_polls',$bb_polls); |
|---|
| | 616 | bb_admin_notice('<b>bbPress Polls: '.__('All Settings Saved.').'</b>'); |
|---|
| | 617 | // unset($GLOBALS['bb_polls']); $bb_polls = bb_get_option('bb_polls'); |
|---|
| | 618 | } |
|---|
| | 619 | } |
|---|
| | 620 | } |
|---|
| | 621 | |
|---|