Changeset 948
- Timestamp:
- 09/24/2007 06:07:29 PM (19 years ago)
- Location:
- trunk/bb-includes
- Files:
-
- 3 edited
-
bozo.php (modified) (4 diffs)
-
deprecated.php (modified) (1 diff)
-
functions.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bb-includes/bozo.php
r916 r948 77 77 $old = (array) $bbdb->get_col("SELECT topic_id FROM $bbdb->topicmeta WHERE meta_key = 'bozos'"); 78 78 $old = array_flip($old); 79 if ( $topics = (array) $bbdb->get_results("SELECT topic_id, poster_id, COUNT(post_id) AS count FROM $bbdb->posts WHERE post_status > 1 GROUP BY topic_id, poster_id") ) : 80 list($topic_ids, $poster_ids, $counts) = bb_pull_cols( $topics, 'topic_id', 'poster_id', 'count' ); 79 if ( $topics = (array) $bbdb->get_col("SELECT topic_id, poster_id, COUNT(post_id) FROM $bbdb->posts WHERE post_status > 1 GROUP BY topic_id, poster_id") ) : 81 80 echo "\t\t" . __("Counting bozo posts...") . "<br />\n"; 82 $unique_topics = array_unique($topic_ids); 81 $unique_topics = array_unique($topics); 82 $posters = (array) $bbdb->get_col('', 1); 83 $counts = (array) $bbdb->get_col('', 2); 83 84 foreach ($unique_topics as $i): 84 85 $bozos = array(); 85 $indices = array_keys($topic _ids, $i);86 $indices = array_keys($topics, $i); 86 87 foreach ( $indices as $index ) 87 $bozos[(int) $poster _ids[$index]] = (int) $counts[$index];88 $bozos[(int) $posters[$index]] = (int) $counts[$index]; 88 89 if ( $bozos ) : 89 90 bb_update_topicmeta( $i, 'bozos', $bozos ); … … 91 92 endif; 92 93 endforeach; 93 unset($topics, $t opic_ids, $poster_ids, $counts, $unique_topics, $i, $bozos);94 unset($topics, $t, $i, $counts, $posters, $bozos); 94 95 endif; 95 96 if ( $old ) : … … 112 113 $topics_replied = (int) $bbdb->get_var("SELECT COUNT(DISTINCT topic_id) FROM $bbdb->posts WHERE post_status = 0 AND poster_id = '$user'"); 113 114 bb_update_usermeta( $user, $bb_table_prefix. 'topics_replied', $topics_replied ); 114 $bozo s = (array) $bbdb->get_results("SELECT topic_id, COUNT(post_id) AS countFROM $bbdb->posts WHERE post_status > 1 AND poster_id = '$user' GROUP BY topic_id");115 if ( $c = count($bozos) ) :116 $bozo_topics = array();115 $bozo_keys = (array) $bbdb->get_col("SELECT topic_id, COUNT(post_id) FROM $bbdb->posts WHERE post_status > 1 AND poster_id = '$user' GROUP BY topic_id"); 116 $bozo_values = (array) $bbdb->get_col('', 1); 117 if ( $c = count($bozo_keys) ) : 117 118 for ( $i=0; $i < $c; $i++ ) 118 $bozo_topics[(int) $bozo s[$i]->topic_id] = (int) $bozos[$i]->count;119 $bozo_topics[(int) $bozo_keys[$i]] = (int) $bozo_values[$i]; 119 120 bb_update_usermeta( $user, $bozo_mkey, $bozo_topics ); 120 121 else : … … 126 127 $bbdb->query("DELETE FROM $bbdb->usermeta WHERE user_id IN ($no_bozos) AND meta_key = '$bozo_mkey'"); 127 128 endif; 129 unset($users, $user, $topics_replied, $bozo_keys, $bozo_values, $bozo_topics); 128 130 endif; 129 131 _e("Done counting bozo topics.\n\n"); -
trunk/bb-includes/deprecated.php
r941 r948 492 492 endif; 493 493 494 // With no extra arguments, converts array of objects into object of arrays 495 // With extra arguments corresponding to name of object properties, returns array of arrays: 496 // list($a, $b) = bb_pull_cols( $obj_array, 'a', 'b' ); 497 function bb_pull_cols( $obj_array ) { 498 $r = new stdClass; 499 foreach ( array_keys($obj_array) as $o ) 500 foreach ( get_object_vars( $obj_array[$o] ) as $k => $v ) 501 $r->{$k}[] = $v; 502 503 if ( 1 == func_num_args() ) 504 return $r; 505 506 $args = func_get_args(); 507 $args = array_splice($args, 1); 508 509 $a = array(); 510 foreach ( $args as $arg ) 511 $a[] = $r->$arg; 512 return $a; 513 } 494 514 495 515 ?> -
trunk/bb-includes/functions.php
r940 r948 347 347 if ( !isset( $thread_ids_cache[$topic_id] ) ) { 348 348 $where = apply_filters('get_thread_post_ids_where', 'AND post_status = 0'); 349 $thread_ids = (array) $bbdb->get_results("SELECT post_id, poster_id FROM $bbdb->posts WHERE topic_id = $topic_id $where ORDER BY post_time");350 list($thread_ids_cache[$topic_id]['post'], $thread_ids_cache[$topic_id]['poster']) = bb_pull_cols( $thread_ids, 'post_id', 'poster_id');349 $thread_ids_cache[$topic_id]['post'] = (array) $bbdb->get_col("SELECT post_id, poster_id FROM $bbdb->posts WHERE topic_id = $topic_id $where ORDER BY post_time"); 350 $thread_ids_cache[$topic_id]['poster'] = (array) $bbdb->get_col('', 1); 351 351 } 352 352 return $thread_ids_cache[$topic_id]; … … 793 793 794 794 // We care about the tag in this topic and if it's in other topics, but not which other topics 795 $topics = (array) $bbdb->get_results("SELECT topic_id, COUNT(*) AS count FROM $bbdb->tagged WHERE tag_id = '$tag_id' GROUP BY topic_id = '$topic_id'"); 796 list($topic_ids, $counts) = bb_pull_topics( $topics, 'topic_id', 'count' ); 797 798 if ( !$here = $counts[$topic_ids[$topic_id]] ) // Topic doesn't have this tag 795 $topics = array_flip((array) $bbdb->get_col("SELECT topic_id, COUNT(*) FROM $bbdb->tagged WHERE tag_id = '$tag_id' GROUP BY topic_id = '$topic_id'")); 796 $counts = (array) $bbdb->get_col('', 1); 797 if ( !$here = $counts[$topics[$topic_id]] ) // Topic doesn't have this tag 799 798 return false; 800 799 … … 2250 2249 } 2251 2250 2252 // With no extra arguments, converts array of objects into object of arrays2253 // With extra arguments corresponding to name of object properties, returns array of arrays:2254 // list($a, $b) = bb_pull_cols( $obj_array, 'a', 'b' );2255 function bb_pull_cols( $obj_array ) {2256 $r = new stdClass;2257 foreach ( array_keys($obj_array) as $o )2258 foreach ( get_object_vars( $obj_array[$o] ) as $k => $v )2259 $r->{$k}[] = $v;2260 2261 if ( 1 == func_num_args() )2262 return $r;2263 2264 $args = func_get_args();2265 $args = array_splice($args, 1);2266 2267 $a = array();2268 foreach ( $args as $arg )2269 $a[] = $r->$arg;2270 return $a;2271 }2272 2273 2251 ?>
Note: See TracChangeset
for help on using the changeset viewer.