| [ Root ] [ Search ] [ Index ] |
PHP Cross Reference of bbPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 3 define( 'BB_IS_ADMIN', true ); 4 define( 'DOING_AJAX', true ); 5 6 require_once ('../bb-load.php'); 7 8 if ( !class_exists( 'WP_Ajax_Response' ) ) 9 require_once( BACKPRESS_PATH . 'class.wp-ajax-response.php' ); 10 11 require_once ( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' ); 12 13 if ( !$bb_current_id = bb_get_current_user_info( 'id' ) ) 14 die('-1'); 15 16 function bb_grab_results() { 17 global $ajax_results; 18 $ajax_results = @ unserialize(func_get_arg(0)); 19 if ( false === $ajax_results ) 20 $ajax_results = func_get_args(); 21 return; 22 } 23 24 $id = (int) @$_POST['id']; 25 26 switch ( $action = $_POST['action'] ) : 27 case 'add-tag' : // $id is topic_id 28 if ( !bb_current_user_can('edit_tag_by_on', $bb_current_id, $id) ) 29 die('-1'); 30 31 bb_check_ajax_referer( "add-tag_$id" ); 32 33 global $tag, $topic; 34 add_action('bb_tag_added', 'bb_grab_results', 10, 3); 35 add_action('bb_already_tagged', 'bb_grab_results', 10, 3); 36 $tag_name = @$_POST['tag']; 37 $tag_name = stripslashes( $tag_name ); 38 39 $topic = get_topic( $id ); 40 if ( !$topic ) 41 die('0'); 42 43 $tag_name = rawurldecode($tag_name); 44 $x = new WP_Ajax_Response(); 45 foreach ( bb_add_topic_tags( $id, $tag_name ) as $tag_id ) { 46 if ( !is_numeric($tag_id) || !$tag = bb_get_tag( (int) $tag_id, bb_get_current_user_info( 'id' ), $topic->topic_id ) ) { 47 if ( !$tag = bb_get_tag( $tag_id ) ) { 48 continue; 49 } 50 } 51 $tag->user_id = bb_get_current_user_info( 'id' ); 52 $tag_id_val = $tag->tag_id . '_' . $tag->user_id; 53 $tag->raw_tag = esc_attr( $tag->raw_tag ); 54 $x->add( array( 55 'what' => 'tag', 56 'id' => $tag_id_val, 57 'data' => _bb_list_tag_item( $tag, array( 'list_id' => 'tags-list', 'format' => 'list' ) ) 58 ) ); 59 } 60 $x->send(); 61 break; 62 63 case 'delete-tag' : 64 list($tag_id, $user_id) = explode('_', $_POST['id']); 65 $tag_id = (int) $tag_id; 66 $user_id = (int) $user_id; 67 $topic_id = (int) $_POST['topic_id']; 68 69 if ( !bb_current_user_can('edit_tag_by_on', $user_id, $topic_id) ) 70 die('-1'); 71 72 bb_check_ajax_referer( "remove-tag_$tag_id|$topic_id" ); 73 74 add_action('bb_rpe_tag_removed', 'bb_grab_results', 10, 3); 75 76 $tag = bb_get_tag( $tag_id ); 77 $user = bb_get_user( $user_id ); 78 $topic = get_topic ( $topic_id ); 79 if ( !$tag || !$topic ) 80 die('0'); 81 if ( false !== bb_remove_topic_tag( $tag_id, $user_id, $topic_id ) ) 82 die('1'); 83 break; 84 85 case 'dim-favorite' : 86 $user_id = bb_get_current_user_info( 'id' ); 87 88 if ( !$topic = get_topic( $id ) ) 89 die('0'); 90 91 if ( !bb_current_user_can( 'edit_favorites_of', $user_id ) ) 92 die('-1'); 93 94 bb_check_ajax_referer( "toggle-favorite_$topic->topic_id" ); 95 96 $is_fav = is_user_favorite( $user_id, $topic->topic_id ); 97 98 if ( 1 == $is_fav ) { 99 if ( bb_remove_user_favorite( $user_id, $topic->topic_id ) ) 100 die('1'); 101 } elseif ( false === $is_fav ) { 102 if ( bb_add_user_favorite( $user_id, $topic->topic_id ) ) 103 die('1'); 104 } 105 break; 106 107 case 'delete-post' : // $id is post_id 108 if ( !bb_current_user_can( 'delete_post', $id ) ) 109 die('-1'); 110 111 bb_check_ajax_referer( "delete-post_$id" ); 112 113 $status = (int) $_POST['status']; 114 115 if ( !$bb_post = bb_get_post( $id ) ) 116 die('0'); 117 118 if ( $status == $bb_post->post_status ) 119 die('1'); // We're already there 120 121 if ( bb_delete_post( $id, $status ) ) { 122 $topic = get_topic( $bb_post->topic_id ); 123 if ( 0 == $topic->topic_posts ) { 124 // If we deleted the only post, send back a WP_Ajax_Response object with a URL to redirect to 125 if ( $ref = wp_get_referer() ) { 126 $ref_topic = bb_get_topic_from_uri( $ref ); 127 if ( $ref_topic && $ref_topic->topic_id == $topic->topic_id ) 128 $ref = add_query_arg( 'view', 'all', $ref ); 129 if ( false === strpos( $ref, '#' ) ) 130 $ref .= "#post-{$bb_post->post_id}"; 131 } else { 132 $ref = add_query_arg( 'view', 'all', get_post_link( $topic->topic_id ) ); 133 } 134 $x = new WP_Ajax_Response( array( 135 'what' => 'post', 136 'id' => $bb_post->post_id, 137 'data' => $ref, 138 ) ); 139 $x->send(); 140 } 141 die('1'); 142 } 143 break; 144 /* 145 case 'add-post' : // Can put last_modified stuff back in later 146 bb_check_ajax_referer( $action ); 147 $error = false; 148 $post_id = 0; 149 $topic_id = (int) $_POST['topic_id']; 150 $last_mod = (int) $_POST['last_mod']; 151 if ( !$post_content = trim($_POST['post_content']) ) 152 $error = new WP_Error( 'no-content', __('You need to actually submit some content!') ); 153 if ( !bb_current_user_can( 'write_post', $topic_id ) ) 154 die('-1'); 155 if ( !$topic = get_topic( $topic_id ) ) 156 die('0'); 157 if ( !topic_is_open( $topic_id ) ) 158 $error = new WP_Error( 'topic-closed', __('This topic is closed.') ); 159 if ( $throttle_time = bb_get_option( 'throttle_time' ) ) 160 if ( isset($bb_current_user->data->last_posted) && time() < $bb_current_user->data->last_posted + $throttle_time && !bb_current_user_can('throttle') ) 161 $error = new WP_Error( 'throttle-limit', sprintf( __('Slow down! You can only post every %d seconds.'), $throttle_time ); 162 163 if ( !$error ) : 164 if ( !$post_id = bb_new_post( $topic_id, rawurldecode($_POST['post_content']) ) ) 165 die('0'); 166 167 $bb_post = bb_get_post( $post_id ); 168 169 $new_page = bb_get_page_number( $bb_post->post_position ); 170 171 ob_start(); 172 echo "<li id='post-$post_id'>"; 173 bb_post_template(); 174 echo '</li>'; 175 $data = ob_get_contents(); 176 ob_end_clean(); 177 endif; 178 $x = new WP_Ajax_Response( array( 179 'what' => 'post', 180 'id' => $post_id, 181 'data' => is_wp_error($error) ? $error : $data 182 ) ); 183 $x->send(); 184 break; 185 */ 186 case 'add-forum' : 187 if ( !bb_current_user_can( 'manage_forums' ) ) 188 die('-1'); 189 190 bb_check_ajax_referer( $action ); 191 192 if ( !$forum_id = bb_new_forum( $_POST ) ) 193 die('0'); 194 195 global $forums_count; 196 $forums_count = 2; // Hack 197 198 $data = bb_forum_row( $forum_id, false, true ); 199 200 $forum = bb_get_forum( $forum_id ); 201 if ( $forum->forum_parent ) { 202 $siblings = bb_get_forums( $forum->forum_parent ); 203 $last_sibling = array_pop( $siblings ); 204 if ( $last_sibling->forum_id == $forum_id ) 205 $last_sibling = array_pop( $siblings ); 206 if ( $last_sibling ) { 207 $position = "forum-$last_sibling->forum_id"; 208 } else { 209 $position = "+forum-$forum->forum_parent"; 210 $data = "<ul id='forum-root-$forum->forum_parent' class='list-block holder'>$data</ul>"; 211 } 212 } else { 213 $position = 1; 214 } 215 216 $x = new WP_Ajax_Response( array( 217 'what' => 'forum', 218 'id' => $forum_id, 219 'data' => $data, 220 'position' => $position, 221 'supplemental' => array( 'name' => $forum->forum_name ) 222 ) ); 223 $x->send(); 224 break; 225 226 case 'order-forums' : 227 if ( !bb_current_user_can( 'manage_forums' ) ) 228 die('-1'); 229 230 bb_check_ajax_referer( $action ); 231 232 if ( !is_array($_POST['order']) ) 233 die('0'); 234 235 global $bbdb; 236 237 $forums = array(); 238 239 bb_get_forums(); // cache 240 241 foreach ( $_POST['order'] as $pos => $forum_id ) : 242 $forum = $bbdb->escape_deep( get_object_vars( bb_get_forum( $forum_id ) ) ); 243 $forum['forum_order'] = $pos; 244 $forums[(int) $forum_id] = $forum; 245 endforeach; 246 247 foreach ( $_POST['root'] as $root => $ids ) 248 foreach ( $ids as $forum_id ) 249 $forums[(int) $forum_id]['forum_parent'] = (int) $root; 250 251 foreach ( $forums as $forum ) 252 bb_update_forum( $forum ); 253 254 die('1'); 255 break; 256 257 default : 258 do_action( 'bb_ajax_' . $_POST['action'] ); 259 break; 260 endswitch; 261 262 die('0'); 263 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Nov 15 04:45:27 2010 | Cross-referenced by PHPXref 0.7 |