Changeset 949
- Timestamp:
- 03/14/08 21:42:52 (9 months ago)
- Files:
-
- bbpress-polls/trunk/bb-polls.php (modified) (16 diffs)
- bbpress-polls/trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
bbpress-polls/trunk/bb-polls.php
r948 r949 6 6 Author: _ck_ 7 7 Author URI: http://bbShowcase.org 8 Version: 0.5. 28 Version: 0.5.4 9 9 10 10 License: CC-GNU-GPL http://creativecommons.org/licenses/GPL/2.0/ … … 58 58 59 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; }60 "#bb_polls {list-style: none; width:400px; line-height:120%; margin:5px 0; padding:5px; border:1px solid #ADADAD; font-size:90%; color:#000; background:#eee; } 61 61 #bb_polls .submit {cursor: pointer; cursor: hand; text-align:center; padding:2px 5px;} 62 62 #bb_polls .nowrap {white-space:nowrap;} 63 63 #bb_polls p {margin:15px 0;padding:0;} 64 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; }65 #bb_polls .poll_label {font-weight:bold; margin:1em 0 1em 1em;} 66 #bb_polls .poll_option {margin:2px 0 -2px 0; text-align:center;font-weight:bold; font-size:9px; line-height:5px; padding:2px 1px; border:1px solid #303030; color:#fff; } 67 67 #bb_polls .poll_option1 {background:red;} 68 68 #bb_polls .poll_option2 {background:green;} … … 77 77 78 78 $bb_polls['poll_question']=__("Would you like to add a poll to this topic for members to vote on?"); 79 $bb_polls['poll_instructions']=__("You may submit a poll question with several options for other members to vote from.");79 $bb_polls['poll_instructions']=__("You may add a poll question with options for members to vote from."); 80 80 $bb_polls['label_single']=__("you can vote on <u>ONE</u> choice"); 81 81 $bb_polls['label_multiple']=__("you can vote on <u>MULTIPLE</u> choices"); … … 297 297 if ($bb_polls['minimum_view_level']=="read" || bb_current_user_can($bb_polls['minimum_view_level']) ) { 298 298 $topic_id=bb_polls_check_cache($topic_id); 299 $output='< p class="poll_question">'.$bb_polls['label_poll_text'].': '.$poll_options['poll_question'].'</p>';299 $output='<div class="poll_question">'.$bb_polls['label_poll_text'].': '.$poll_options['poll_question'].'</div>'; 300 300 301 301 if (!$poll_options['poll_multiple_choice'] && isset($poll_options['poll_count_0'])) {$real_vote_count=intval($poll_options['poll_count_0']);} … … 304 304 for ($i=1; $i<=$bb_polls['max_options']; $i++) { 305 305 if (isset($poll_options[$i])) { 306 $output.= '< pclass="poll_label">'.$poll_options[$i].' : ';306 $output.= '<div class="poll_label">'.$poll_options[$i].' : '; 307 307 $test=(isset($poll_options['poll_count_'.$i]) ? intval($poll_options['poll_count_'.$i]) : 0); 308 $output.= ' ('.$test.' '.$bb_polls['label_votes_text'].') ';308 $output.= ' ('.$test.' '.$bb_polls['label_votes_text'].') <br />'; 309 309 if ($test) { 310 310 $vote_percent=(round($test/$real_vote_count,2)*100); … … 312 312 $output.= ' <div style="width:'.$vote_width.'%" class="poll_option poll_option'.$i.'"> '.$vote_percent.' % </div> '; 313 313 } 314 $output.= ' </ p>';314 $output.= ' </div>'; 315 315 } 316 316 } … … 318 318 $output.= '<p class="poll_footer">'.intval($test).' '.$bb_polls['label_votes_text'].'</p>'; 319 319 if (isset($_GET['show_poll_results']) || (bb_get_current_user_info( 'id' ) && !bb_polls_has_voted(bb_get_current_user_info( 'id' ),$topic_id) )) { 320 $output.= '<p class="poll_footer">( <a onClick="if (window.bb_polls_insert_ajax) {bb_polls_show_poll_vote_form_ajax();return false;}" href="'.remove_query_arg( 'show_poll_results').'">'.$bb_polls['label_now_text'].'</a> )</p>';320 $output.= '<p class="poll_footer">( <a onClick="if (window.bb_polls_insert_ajax) {bb_polls_show_poll_vote_form_ajax();return false;}" href="'.remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache')).'">'.$bb_polls['label_now_text'].'</a> )</p>'; 321 321 } 322 322 $output.=bb_polls_edit_link(); … … 331 331 $topic_id=bb_polls_check_cache($topic_id); 332 332 if ($poll_options['poll_multiple_choice']==1) {$poll_type="checkbox";} else {$poll_type="radio";} 333 $output='<form action="'.remove_query_arg( 'show_poll_results').'" method="post" name="bb_polls" onSubmit="if (window.bb_polls_insert_ajax) {bb_polls_add_vote_ajax();return false;}">334 < p class="poll_question">'.$bb_polls['label_poll_text'].': '.$poll_options['poll_question'].'</p>';333 $output='<form action="'.remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache')).'" method="post" name="bb_polls" onSubmit="if (window.bb_polls_insert_ajax) {bb_polls_add_vote_ajax();return false;}"> 334 <div class="poll_question">'.$bb_polls['label_poll_text'].': '.$poll_options['poll_question'].'</div>'; 335 335 for ($i=1; $i<=$bb_polls['max_options']; $i++) { 336 336 if (isset($poll_options[$i])) { … … 389 389 $topic_id=bb_polls_check_cache($topic_id); 390 390 391 $output='<form action="'.remove_query_arg(array('start_new_poll','edit_poll' )).'" method="post"><p>'.$bb_polls['poll_instructions'].'</p>';391 $output='<form action="'.remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache')).'" method="post"><p>'.$bb_polls['poll_instructions'].'</p>'; 392 392 393 $output.='< p class="poll_label">'.$bb_polls['label_question_text'].' : <input name="poll_question" type="text" style="width:98%" maxlength="'.$bb_polls['max_length'].'" value="'.$poll_options['poll_question'].'" /></p>';393 $output.='<div class="poll_label">'.$bb_polls['label_question_text'].' : <br /><input name="poll_question" type="text" style="width:98%" maxlength="'.$bb_polls['max_length'].'" value="'.$poll_options['poll_question'].'" /></div>'; 394 394 395 $output.='< pclass="poll_label"><span class="nowrap"><input name="poll_multiple_choice" type="radio" value="0" ';395 $output.='<div class="poll_label"><span class="nowrap"><input name="poll_multiple_choice" type="radio" value="0" '; 396 396 $output.=($poll_options['poll_multiple_choice']) ? ' ' : ' checked="checked" '; 397 397 $output.=' />'.$bb_polls['label_single'].'</span> <span class="nowrap"><input name="poll_multiple_choice" type="radio" value="1" '; 398 398 $output.=($poll_options['poll_multiple_choice']) ? ' checked="checked" ' : ' '; 399 $output.=' /> '.$bb_polls['label_multiple'].'</span></ p>';399 $output.=' /> '.$bb_polls['label_multiple'].'</span></div>'; 400 400 401 401 for ($i=1; $i<=$bb_polls['max_options']; $i++) { … … 403 403 $output.='<a href="javascript:void(0)" onClick="this.style.display='."'none'".'; document.getElementById('."'poll_more_options'".').style.display='."'block'".'">[+] '.$bb_polls['label_option_text'].'</a><div id="poll_more_options" style="display:none;">'; 404 404 } 405 $output.='< p class="poll_label">'.$bb_polls['label_option_text'].' #'.$i.' : <input name="poll_option_'.$i.'" type="text" style="width:98%" maxlength="'.$bb_polls['max_length'].'" value="'.$poll_options[$i].'" /></p>';405 $output.='<div class="poll_label">'.$bb_polls['label_option_text'].' #'.$i.' : <br /><input name="poll_option_'.$i.'" type="text" style="width:98%" maxlength="'.$bb_polls['max_length'].'" value="'.$poll_options[$i].'" /></div>'; 406 406 } // loop 407 407 if ($bb_polls['max_options']>4 && !$poll_options[5]) {$output.='</div>';} 408 408 409 409 $output.='<p class="poll_footer"> 410 <input class="submit" type="button" value="'.$bb_polls['label_cancel_text'].'" onClick="document.location='."'".remove_query_arg( 'start_new_poll')."'".'" />410 <input class="submit" type="button" value="'.$bb_polls['label_cancel_text'].'" onClick="document.location='."'".remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache'))."'".'" /> 411 411 <input class="submit" type="submit" value="'.$bb_polls['label_save_text'].'" /></p></form>'; 412 412 $output=stripslashes($output);if ($display) {echo '<li id="bb_polls" class="extra-caps-row">'.$output.'</li>';} else {return $output;} … … 435 435 if (isset($_GET['delete_poll']) && intval($_GET['delete_poll'])) { 436 436 bb_polls_delete_poll(); 437 wp_redirect(remove_query_arg(array('start_new_poll',' delete_poll'))); // I *really* don't like this technique but it's the only way to clear post data?437 wp_redirect(remove_query_arg(array('start_new_poll','edit_poll','delete_poll','show_poll_vote_form_ajax','show_poll_setup_form_ajax','bb_polls_cache'))); // I *really* don't like this technique but it's the only way to clear post data? 438 438 } 439 439 if (isset($_GET['show_poll_results_ajax'])) { … … 448 448 echo 'bb_polls_insert_ajax("'.mysql_escape_string(bb_polls_show_poll_vote_form($topic_id,0)).'")'; 449 449 exit(); 450 } 451 if (isset($_GET['show_poll_setup_form_ajax'])) { 452 $topic_id=intval($_GET['show_poll_setup_form_ajax']); 453 header("Content-Type: application/x-javascript"); 454 echo 'bb_polls_insert_ajax("'.mysql_escape_string(bb_polls_show_poll_setup_form($topic_id,0,1)).'")'; 455 exit(); 450 456 } 451 457 if (isset($_GET['add_vote_ajax'])) { … … 459 465 460 466 function bb_polls_add_javascript($topic_id=0) { 461 global $bb_polls; 462 if ($bb_polls['use_ajax']) : 467 global $bb_polls, $topic; 468 if ($bb_polls['use_ajax'] && bb_current_user_can($bb_polls['minimum_vote_level']) ) : 469 $topic_id=bb_polls_check_cache($topic_id); 463 470 echo '<scr'.'ipt type="text/javascript" defer="defer"> 464 471 <!-- … … 469 476 function append_dhead(bb_polls_src) { 470 477 if (bb_polls_script) {dhead.removeChild(bb_polls_script);} 471 d = new Date(); bb_polls_src=bb_polls_src+"& "+d.getTime();478 d = new Date(); bb_polls_src=bb_polls_src+"&bb_polls_cache="+d.getTime(); 472 479 bb_polls_script = document.createElement("script"); 473 480 bb_polls_script.src = bb_polls_src; … … 483 490 } 484 491 function bb_polls_insert_ajax_delayed() {document.getElementById("bb_polls").innerHTML=bb_polls_htmldata;} 485 492 '; 493 494 // only add new poll support if they can add and there's no poll already 495 if (bb_current_user_can($bb_polls['minimum_add_level']) && !isset($topic->poll_options)) { 496 echo ' 497 function bb_polls_start_new_poll_ajax() { 498 append_dhead("'.add_query_arg( 'show_poll_setup_form_ajax', $topic_id).'"); 499 } 500 ';} 501 502 // only add edit support if they can edit and saved poll question with options 503 if (bb_current_user_can($bb_polls['minimum_edit_level']) && isset($topic->poll_options)) { 504 echo ' 505 function bb_polls_edit_poll_ajax() { 506 append_dhead("'.add_query_arg( 'show_poll_setup_form_ajax', $topic_id).'"); 507 } 508 ';} 509 510 // only add vote and view toggle support javascript if they have not yet voted 511 if (!bb_polls_has_voted(bb_get_current_user_info( 'id' ),$topic_id) ) { 512 echo ' 486 513 function bb_polls_show_poll_results_ajax() { 487 append_dhead("'.add_query_arg( 'show_poll_results_ajax', get_topic_id( $topic_id )).'"); 488 } 489 514 append_dhead("'.add_query_arg( 'show_poll_results_ajax', $topic_id).'"); 515 } 490 516 function bb_polls_show_poll_vote_form_ajax() { 491 var bb_polls_poll_vote_form = "'.mysql_escape_string(bb_polls_show_poll_vote_form(get_topic_id( $topic_id ),0)).'"; 492 if (bb_polls_poll_vote_form) {bb_polls_insert_ajax(bb_polls_poll_vote_form);} 493 else { 494 append_dhead("'.add_query_arg( 'show_poll_vote_form_ajax', get_topic_id( $topic_id )).'"); 495 } 496 } 497 498 function bb_polls_start_new_poll_ajax() { 499 var bb_polls_poll_setup_form = "'.mysql_escape_string(bb_polls_show_poll_setup_form(get_topic_id( $topic_id ),0,1)).'"; 500 if (bb_polls_poll_setup_form) {bb_polls_insert_ajax(bb_polls_poll_setup_form);} 501 } 502 503 function bb_polls_edit_poll_ajax() { 504 var bb_polls_poll_setup_form = "'.mysql_escape_string(bb_polls_show_poll_setup_form(get_topic_id( $topic_id ),0,1)).'"; 505 if (bb_polls_poll_setup_form) {bb_polls_insert_ajax(bb_polls_poll_setup_form);} 506 } 507 517 append_dhead("'.add_query_arg( 'show_poll_vote_form_ajax', $topic_id).'"); 518 } 508 519 function bb_polls_add_vote_ajax() { 509 520 vote=""; … … 516 527 if (test && test.checked) {vote=vote+"&poll_vote_"+i+"="+i;} 517 528 } 518 if (vote.length) {append_dhead("'.add_query_arg( 'add_vote_ajax', get_topic_id( $topic_id )).'"+vote);}529 if (vote.length) {append_dhead("'.add_query_arg( 'add_vote_ajax', $topic_id).'"+vote);} 519 530 else {alert("'.$bb_polls['label_nocheck_text'].'"); return false;} 520 531 } 532 ';} 533 534 echo ' 521 535 //--> 522 536 </scr'.'ipt>'; bbpress-polls/trunk/readme.txt
r947 r949 54 54 * 0.50 2008-March-1 basic admin menu added 55 55 * 0.5.2 2008-March-14 xhtml and non-ajax-edit bug fixes, props zmaroti 56 * 0.5.3 2008-March-14 javascript payload is now kept as small as possible 57 * 0.5.4 2008-March-14 new poll form (and edit form) remotely loaded when in "ajax" mode 56 58 57 59 == To Do ==
