Changeset 1396
- Timestamp:
- 04/01/2008 08:24:36 AM (18 years ago)
- Location:
- branches/0.8
- Files:
-
- 7 edited
-
bb-admin/admin-ajax.php (modified) (12 diffs)
-
bb-admin/admin-functions.php (modified) (1 diff)
-
bb-admin/js/content-forums.js (modified) (1 diff)
-
bb-includes/js/topic-js.php (modified) (3 diffs)
-
bb-includes/pluggable.php (modified) (3 diffs)
-
bb-includes/script-loader.php (modified) (2 diffs)
-
bb-includes/template-functions.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.8/bb-admin/admin-ajax.php
r1221 r1396 2 2 require_once('../bb-load.php'); 3 3 require_once(BB_PATH . 'bb-admin/admin-functions.php'); 4 bb_check_ajax_referer();5 4 6 5 if ( !$bb_current_id = bb_get_current_user_info( 'id' ) ) … … 17 16 } 18 17 19 switch ( $_POST['action'] ) : 20 case 'add-tag' : 18 $id = (int) @$_POST['id']; 19 20 switch ( $action = $_POST['action'] ) : 21 case 'add-tag' : // $id is topic_id 22 if ( !bb_current_user_can('edit_tag_by_on', $bb_current_id, $id) ) 23 die('-1'); 24 25 bb_check_ajax_referer( "add-tag_$id" ); 26 21 27 global $tag, $topic; 22 28 add_action('bb_tag_added', 'bb_grab_results', 10, 3); 23 29 add_action('bb_already_tagged', 'bb_grab_results', 10, 3); 24 $topic_id = (int) @$_POST['id']; 25 $tag_name = @$_POST['tag']; 30 $tag_name = @$_POST['tag']; 26 31 $tag_name = stripslashes( $tag_name ); 27 if ( !bb_current_user_can('edit_tag_by_on', $bb_current_id, $topic_id) ) 28 die('-1'); 29 30 $topic = get_topic( $topic_id ); 32 33 $topic = get_topic( $id ); 31 34 if ( !$topic ) 32 35 die('0'); … … 34 37 $tag_name = rawurldecode($tag_name); 35 38 $x = new WP_Ajax_Response(); 36 foreach ( bb_add_topic_tags( $ topic_id, $tag_name ) as $tag_id ) {39 foreach ( bb_add_topic_tags( $id, $tag_name ) as $tag_id ) { 37 40 if ( !is_numeric($tag_id) || !$tag = bb_get_tag( $tag_id, bb_get_current_user_info( 'id' ), $topic->topic_id ) ) 38 41 if ( !$tag = bb_get_tag( $tag_id ) ) … … 50 53 51 54 case 'delete-tag' : 52 add_action('bb_rpe_tag_removed', 'bb_grab_results', 10, 3);53 55 list($tag_id, $user_id) = explode('_', $_POST['id']); 54 56 $tag_id = (int) $tag_id; … … 59 61 die('-1'); 60 62 63 bb_check_ajax_referer( "remove-tag_$tag_id|$topic_id" ); 64 65 add_action('bb_rpe_tag_removed', 'bb_grab_results', 10, 3); 66 61 67 $tag = bb_get_tag( $tag_id ); 62 68 $user = bb_get_user( $user_id ); … … 80 86 die('-1'); 81 87 88 bb_check_ajax_referer( "toggle-favorite_$topic_id" ); 89 82 90 $is_fav = is_user_favorite( $user_id, $topic_id ); 83 91 … … 85 93 if ( bb_remove_user_favorite( $user_id, $topic_id ) ) 86 94 die('1'); 87 } elseif ( 0=== $is_fav ) {95 } elseif ( false === $is_fav ) { 88 96 if ( bb_add_user_favorite( $user_id, $topic_id ) ) 89 97 die('1'); … … 91 99 break; 92 100 93 case 'delete-post' : 94 $post_id = (int) $_POST['id']; 101 case 'delete-post' : // $id is post_id 102 if ( !bb_current_user_can( 'delete_post', $id ) ) 103 die('-1'); 104 105 bb_check_ajax_referer( "delete-post_$id" ); 106 95 107 $page = (int) $_POST['page']; 96 108 $last_mod = (int) $_POST['last_mod']; 97 109 98 if ( !bb_current_user_can( 'delete_post', $post_id ) ) 99 die('-1'); 100 101 $bb_post = bb_get_post ( $post_id ); 110 $bb_post = bb_get_post( $id ); 102 111 103 112 if ( !$bb_post ) … … 106 115 $topic = get_topic( $bb_post->topic_id ); 107 116 108 if ( bb_delete_post( $ post_id, 1 ) )117 if ( bb_delete_post( $id, 1 ) ) 109 118 die('1'); 110 119 break; 111 120 /* 112 121 case 'add-post' : // Can put last_modified stuff back in later 122 bb_check_ajax_referer( $action ); 113 123 $error = false; 114 124 $post_id = 0; … … 153 163 die('-1'); 154 164 165 bb_check_ajax_referer( $action ); 166 155 167 if ( !$forum_id = bb_new_forum( $_POST ) ) 156 168 die('0'); … … 171 183 die('-1'); 172 184 185 bb_check_ajax_referer( $action ); 186 173 187 if ( !is_array($_POST['order']) ) 174 188 die('0'); … … 198 212 default : 199 213 do_action( 'bb_ajax_' . $_POST['action'] ); 200 die('0');201 214 break; 202 215 endswitch; 216 217 die('0'); 203 218 ?> -
branches/0.8/bb-admin/admin-functions.php
r1386 r1396 581 581 <input type="hidden" name="forum_id" value="<?php echo $forum_id; ?>" /> 582 582 <?php endif; ?> 583 <?php bb_nonce_field( 'order-forums', 'order-nonce' ); ?> 583 584 <?php bb_nonce_field( "$action-forum" ); ?> 584 585 585 <input type="hidden" name="action" value="<?php echo $action; ?>" /> 586 586 <input name="Submit" type="submit" value="<?php if ( $forum_id ) _e('Update Forum »'); else _e('Add Forum »'); ?>" tabindex="13" /> -
branches/0.8/bb-admin/js/content-forums.js
r1348 r1396 95 95 $.post( 96 96 'admin-ajax.php', 97 'action=order-forums& cookie=' + encodeURIComponent(document.cookie) + '&' + hash97 'action=order-forums&_ajax_nonce=' + $('#add-forum input[name=order-nonce]').val() + '&' + hash 98 98 ); 99 99 } ); -
branches/0.8/bb-includes/js/topic-js.php
r1216 r1396 6 6 } ); 7 7 8 function ajaxPostDelete(postId, postAuthor ) {8 function ajaxPostDelete(postId, postAuthor, a) { 9 9 if (!confirm('<?php printf(__("Are you sure you wanna delete this post by \"' + %s + '\"?"), 'postAuthor'); //postAuthor should be left untranslated ?>')) return false; 10 thePostList.inputData = '&_ajax_nonce=' + a.href.toQueryParams()['_wpnonce']; 10 11 return thePostList.ajaxDelete( 'post', postId ); 11 12 } … … 37 38 } ); 38 39 39 function ajaxDelTag(tag, user, tagName) { 40 function ajaxDelTag(tag, user, tagName, a) { 41 yourTagList.inputData = '&topic_id=' + topicId + '&_ajax_nonce=' + a.href.toQueryParams()['_wpnonce']; 42 othersTagList.inputData = '&topic_id=' + topicId + '&_ajax_nonce=' + a.href.toQueryParams()['_wpnonce']; 40 43 if ( !confirm('<?php printf(__("Are you sure you want to remove the \"' + %s + '\" tag?"), 'tagName'); ?>') ) 41 44 return false; … … 47 50 48 51 addLoadEvent( function() { // TopicMeta 52 var favoritesToggle = $('favorite-toggle'); 53 favoritesToggle[ 1 === isFav ? 'removeClass' : 'addClass' ]( 'is-not-favorite' ); 49 54 theTopicMeta = new listMan('topicmeta'); 50 55 theTopicMeta.showLink = false; 51 theTopicMeta.inputData = '&user_id=' + currentUserId + '&topic_id=' + topicId; 56 var nonce = jQuery( '#favorite-toggle a[href*="_wpnonce="]' ).click( FavIt ).attr( 'href' ).toQueryParams()['_wpnonce']; 57 theTopicMeta.inputData = '&user_id=' + currentUserId + '&topic_id=' + topicId + '&_ajax_nonce=' + nonce; 52 58 theTopicMeta.dimComplete = function(what, id, dimClass) { 53 59 if ( 'is-not-favorite' == dimClass ) { 54 var favoritesToggle = $('favorite-toggle');55 60 isFav = favoritesToggle.hasClassName(dimClass) ? 0 : 1; 56 61 favLinkSetup(); 57 62 } 58 63 } 59 favLinkSetup();60 61 64 } ); 62 65 63 66 function favLinkSetup() { 64 67 var favoritesToggle = $('favorite-toggle'); 65 if ('no' == isFav)66 return;67 68 if ( 1 == isFav ) 68 69 favoritesToggle.update('<?php printf(__("This topic is one of your <a href=' + %s + '>favorites</a>"), 'favoritesLink'); ?> [<a href="#" onclick="return FavIt();">x</a>]'); -
branches/0.8/bb-includes/pluggable.php
r1394 r1396 285 285 $i = ceil(time() / 43200); 286 286 287 //Allow for expanding range, but only do one check if we can 288 if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce ) 289 return true; 287 // Nonce generated 0-12 hours ago 288 if ( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce ) 289 return 1; 290 // Nonce generated 12-24 hours ago 291 if ( substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce ) 292 return 2; 293 // Invalid nonce 290 294 return false; 291 295 } … … 402 406 403 407 if ( !function_exists('bb_check_admin_referer') ) : 404 function bb_check_admin_referer( $action = -1 ) {405 if ( !bb_verify_nonce($_REQUEST[ '_wpnonce'], $action) ) {408 function bb_check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) { 409 if ( !bb_verify_nonce($_REQUEST[$query_arg], $action) ) { 406 410 bb_nonce_ays($action); 407 411 die(); … … 412 416 413 417 if ( !function_exists('bb_check_ajax_referer') ) : 414 function bb_check_ajax_referer() { 415 if ( !$current_id = bb_get_current_user_info( 'ID' ) ) 418 function bb_check_ajax_referer( $action = -1, $query_arg = false, $die = true ) { 419 if ( $query_arg ) 420 $nonce = $_REQUEST[$query_arg]; 421 else 422 $nonce = $_REQUEST['_ajax_nonce'] ? $_REQUEST['_ajax_nonce'] : $_REQUEST['_wpnonce']; 423 424 $result = bb_verify_nonce( $nonce, $action ); 425 426 if ( $die && false == $result ) 416 427 die('-1'); 417 418 $cookie = explode('; ', urldecode(empty($_POST['cookie']) ? $_GET['cookie'] : $_POST['cookie'])); // AJAX scripts must pass cookie=document.cookie 419 foreach ( $cookie as $tasty ) { 420 if ( false !== strpos($tasty, bb_get_option( 'authcookie' )) ) 421 $auth_cookie = substr(strstr($tasty, '='), 1); 422 } 423 424 if ( empty($auth_cookie) ) 425 die('-1'); 426 427 if ( ! $user_id = wp_validate_auth_cookie( $auth_cookie ) ) 428 die('-1'); 429 430 if ( $current_id != $user_id ) 431 die('-1'); 432 433 do_action('bb_check_ajax_referer'); 428 429 do_action('bb_check_ajax_referer', $action, $result); 430 return $result; 434 431 } 435 432 endif; -
branches/0.8/bb-includes/script-loader.php
r1348 r1396 15 15 $this->add( 'wp-ajax', '/' . BB_INC . 'js/wp-ajax-js.php', array('prototype'), '2.1-beta2' ); 16 16 $this->add( 'listman', '/' . BB_INC . 'js/list-manipulation-js.php', array('add-load-event', 'wp-ajax', 'fat'), '440' ); 17 $this->add( 'topic', '/' . BB_INC . 'js/topic-js.php', array('add-load-event', 'listman'), ' 433' );17 $this->add( 'topic', '/' . BB_INC . 'js/topic-js.php', array('add-load-event', 'listman'), '20080401' ); 18 18 $this->add( 'jquery', '/' . BB_INC . 'js/jquery/jquery.js', false, '1.1.3.1'); 19 19 $this->add( 'interface', '/' . BB_INC . 'js/jquery/interface.js', array('jquery'), '1.2.3'); … … 194 194 return false; 195 195 } 196 197 196 } 198 197 -
branches/0.8/bb-includes/template-functions.php
r1386 r1396 1269 1269 $r = "<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/delete-post.php?id=' . $bb_post->post_id . '&status=0&view=all', 'delete-post_' . $bb_post->post_id ) ) . "' onclick='return confirm(\" ". js_escape( __('Are you sure you wanna undelete that?') ) ." \");'>". __('Undelete') ."</a>"; 1270 1270 else 1271 $r = "<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/delete-post.php?id=' . $bb_post->post_id . '&status=1', 'delete-post_' . $bb_post->post_id ) ) . "' onclick='return ajaxPostDelete(" . $bb_post->post_id . ", \"" . get_post_author( $post_id ) . "\" );'>". __('Delete') ."</a>";1271 $r = "<a href='" . attribute_escape( bb_nonce_url( bb_get_option('uri') . 'bb-admin/delete-post.php?id=' . $bb_post->post_id . '&status=1', 'delete-post_' . $bb_post->post_id ) ) . "' onclick='return ajaxPostDelete(" . $bb_post->post_id . ", \"" . get_post_author( $post_id ) . "\", this);'>". __('Delete') ."</a>"; 1272 1272 $r = apply_filters( 'post_delete_link', $r, $bb_post->post_status, $bb_post->post_id ); 1273 1273 echo $r; … … 1828 1828 return false; 1829 1829 $url = add_query_arg( array('tag' => $tag->tag_id, 'user' => $tag->user_id, 'topic' => $tag->topic_id), bb_get_option('uri') . 'tag-remove.php' ); 1830 $r = '[<a href="' . attribute_escape( bb_nonce_url( $url, 'remove-tag_' . $tag->tag_id . '|' . $tag->topic_id) ) . '" onclick="return ajaxDelTag(' . $tag->tag_id . ', ' . $tag->user_id . ', \'' . js_escape($tag->raw_tag) . '\' );" title="' . attribute_escape( __('Remove this tag') ) . '">×</a>]';1830 $r = '[<a href="' . attribute_escape( bb_nonce_url( $url, 'remove-tag_' . $tag->tag_id . '|' . $tag->topic_id) ) . '" onclick="return ajaxDelTag(' . $tag->tag_id . ', ' . $tag->user_id . ', \'' . js_escape($tag->raw_tag) . '\', this);" title="' . attribute_escape( __('Remove this tag') ) . '">×</a>]'; 1831 1831 return $r; 1832 1832 }
Note: See TracChangeset
for help on using the changeset viewer.