Changeset 922

Show
Ignore:
Timestamp:
03/01/08 23:12:55 (9 months ago)
Author:
_ck_
Message:

now with 100% more admin menu

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bbpress-polls/trunk/bb-polls.php

    r914 r922  
    22/* 
    33Plugin Name: bbPress Polls 
    4 Description:  allows users to add polls to topics, with optional ajax-ish update action 
     4Description:  allows users to add polls to topics, with optional ajax-like actions 
    55Plugin URI:  http://bbpress.org/plugins/topic/62 
    66Author: _ck_ 
    77Author URI: http://bbShowcase.org 
    8 Version: 0.33 
     8Version: 0.50 
    99 
    1010License: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/ 
    1111 
    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          
     12Instructions:   install, activate, check admin menu for options. 
     13 
    4014To Do:  
    41         : admin menu (coming soon - edit plugin directly for now, many options)  
    42         : display a poll anywhere within bbpress templates 
    43         : list all polls on a single page 
     15        * polls should be able to close with topic 
     16        * allow results to display by number of votes 
     17        * display a poll anywhere within bbpress templates 
     18        * display all polls on a single page 
     19        * better editing / vote count editing  
     20        * see who voted 
     21        * better poll styles (colors / graphics) 
    4422*/ 
    45 //      edit these lines below (until an Admin menu is made) 
     23 
     24global $bb_polls; 
     25 
     26add_action( 'bb_send_headers', 'bb_polls_initialize');  // bb_init 
     27add_action( 'bb_admin-header.php','bb_polls_process_post'); 
     28add_action( 'bb_admin_menu_generator', 'bb_polls_add_admin_page' ); 
     29 
     30function bb_polls_add_admin_page() {bb_admin_add_submenu(__('bbPress Polls'), 'administrate', 'bb_polls_admin_page');} 
     31 
     32function bb_polls_initialize() { 
     33        global $bb_polls, $bb_polls_type, $bb_polls_label; 
     34        if (!isset($bb_polls)) {$bb_polls = bb_get_option('bb_polls'); 
     35                if (!$bb_polls) { 
    4636 
    4737        $bb_polls['minimum_view_level']="read";   // who can view polls = read / participate / moderate / administrate  (watchout for typos) 
     
    6656        $bb_polls['use_ajax']=true;             // true = enables ajax-ish behaviours, still works without javascript  / false = typical page refreshes 
    6757        $bb_polls['test_mode']=false;   // if set to "true" allows multiple votes per person for testing purposes only 
    68                                  
     58 
     59        $bb_polls['style']= 
     60        "#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; } 
     61        #bb_polls .submit {cursor: pointer; cursor: hand; text-align:center; padding:2px 5px;} 
     62        #bb_polls .nowrap {white-space:nowrap;} 
     63        #bb_polls p {margin:15px 0;padding:0;} 
     64        #bb_polls .poll_question, #bb_polls .poll_footer {font-weight:bold; text-align:center; color:#2E6E15;} 
     65        #bb_polls .poll_label {font-weight:bold;}                                                                
     66        #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; } 
     67        #bb_polls .poll_option1 {background:red;} 
     68        #bb_polls .poll_option2 {background:green;} 
     69        #bb_polls .poll_option3 {background:blue;} 
     70        #bb_polls .poll_option4 {background:orange;} 
     71        #bb_polls .poll_option5 {background:purple;} 
     72        #bb_polls .poll_option6 {background:pink;} 
     73        #bb_polls .poll_option7 {background:yellow;} 
     74        #bb_polls .poll_option8 {background:navy;} 
     75        #bb_polls .poll_option9 {background:grey;} 
     76        ";                       
     77                                         
    6978        $bb_polls['poll_question']=__("Would you like to add a poll to this topic for members to vote on?"); 
    7079        $bb_polls['poll_instructions']=__("You may submit a poll question with several options for other members to vote from."); 
     
    8493        $bb_polls['label_nocheck_text']=__("You haven't selected anything!");    
    8594        $bb_polls['label_warning_text']=__("This cannot be undone. Are you sure to delete?"); 
    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
    106193 
    107194function bb_polls_pre_poll($topic_id,$edit_poll=0) {  
     
    158245endif;   
    159246remove_action('topicmeta','bb_polls_pre_poll',200);  // NullFix ? 
    160 } add_action('topicmeta','bb_polls_pre_poll',200); 
     247}  
    161248 
    162249function bb_polls_check_cache($topic_id) { 
     
    332419        if ($bb_polls['label_poll_text'] && isset($topic->poll_options) && !is_topic())  {return '['.$bb_polls['label_poll_text'].'] '.$title;}          
    333420        return $title; 
    334 } add_filter('topic_title', 'bb_polls_title'); 
     421}  
    335422 
    336423function bb_polls_add_header() {  
     
    370457                exit(); 
    371458        }                        
    372 } add_action('bb_send_headers', 'bb_polls_add_header'); 
     459}  
    373460 
    374461function bb_polls_add_javascript($topic_id) { 
     
    439526global $bb_polls; 
    440527if (is_topic()) {echo '<style type="text/css">'.$bb_polls['style'].'</style>'; } 
    441 } add_action('bb_head', 'bb_polls_add_css'); 
     528}  
     529 
     530function 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                                                                        &nbsp;  
     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 
     598function bb_polls_process_post() { 
     599global $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 
    442622?> 
  • bbpress-polls/trunk/readme.txt

    r852 r922  
    1818 
    1919Add the "bb-polls.php" file to bbPress "my-plugins/" directory and activate.  
    20  
    21 For now you must edit the bb-polls.php directly to change default options. 
    22 Options can be found near the top of the file as `$bb_polls['option']` etc. 
    23 This is a beta release without an admin menu (coming soon). 
     20Check under the admin menu for "bbPress Polls" options. 
    2421 
    2522== License == 
     
    5552* 0.29  enhancement so admin can always delete any poll 
    5653* 0.30  enhancement so admin can edit any poll (don't try to change the order of questions, it's a simple edit for now) 
     54* 0.50  2008-March-1 basic admin menu  added 
    5755         
    5856== To Do == 
    5957 
    60 admin menu (coming soon - edit plugin directly for now, many options) 
    61 display a poll anywhere within bbpress templates 
    62 display all polls on a single page 
    63 better editing / vote count editing  
    64 see who voted 
    65 better colors / graphics 
     58* polls should be able to close with topic 
     59* allow results to display by number of votes 
     60* display a poll anywhere within bbpress templates 
     61* display all polls on a single page 
     62* better editing / vote count editing  
     63* see who voted 
     64* better poll styles (colors / graphics) 
     65