Changeset 18 for trunk/bb-includes/functions.php
- Timestamp:
- 12/28/2004 08:54:20 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/bb-includes/functions.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bb-includes/functions.php
r16 r18 19 19 } 20 20 21 function get_thread ( $topic, $page = 0 ) {21 function get_thread( $topic, $page = 0 ) { 22 22 global $bbdb, $bb; 23 23 24 $limit = get_option('page_topics');24 $limit = bb_get_option('page_topics'); 25 25 if ( $page ) 26 26 $limit = ($limit * $page) . ", $limit"; … … 28 28 } 29 29 30 function get_post ( $post_id ) {30 function get_post( $post_id ) { 31 31 global $bbdb; 32 32 $post_id = (int) $post_id; … … 38 38 if ( $forum ) 39 39 $where = "WHERE forum_id = $forum"; 40 $limit = get_option('page_topics');40 $limit = bb_get_option('page_topics'); 41 41 if ( $page ) 42 42 $limit = ($limit * $page) . ", $limit"; … … 44 44 } 45 45 46 function apply_filters($tag, $string, $filter = true) {46 function bb_apply_filters($tag, $string, $filter = true) { 47 47 global $wp_filter; 48 48 if (isset($wp_filter['all'])) { … … 73 73 } 74 74 75 function add_filter($tag, $function_to_add, $priority = 10) {75 function bb_add_filter($tag, $function_to_add, $priority = 10) { 76 76 global $wp_filter; 77 77 // So the format is wp_filter['tag']['array of priorities']['array of functions'] … … 82 82 } 83 83 84 function remove_filter($tag, $function_to_remove, $priority = 10) {84 function bb_remove_filter($tag, $function_to_remove, $priority = 10) { 85 85 global $wp_filter; 86 86 if (@in_array($function_to_remove, $wp_filter[$tag]["$priority"])) { … … 98 98 // The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content 99 99 100 function do_action($tag, $string) {101 apply_filters($tag, $string, false);100 function bb_do_action($tag, $string) { 101 bb_apply_filters($tag, $string, false); 102 102 return $string; 103 103 } 104 104 105 105 function add_action($tag, $function_to_add, $priority = 10) { 106 add_filter($tag, $function_to_add, $priority);106 bb_add_filter($tag, $function_to_add, $priority); 107 107 } 108 108 109 109 function remove_action($tag, $function_to_remove, $priority = 10) { 110 remove_filter($tag, $function_to_remove, $priority);111 } 112 113 function timer_stop($display = 0, $precision = 3) { //if called liketimer_stop(1), will echo $timetotal110 bb_remove_filter($tag, $function_to_remove, $priority); 111 } 112 113 function bb_timer_stop($display = 0, $precision = 3) { //if called like bb_timer_stop(1), will echo $timetotal 114 114 global $bb_timestart, $timeend; 115 115 $mtime = explode(' ', microtime()); … … 121 121 } 122 122 123 function since($stamp) { 124 $post = $stamp; /* get a timestamp */ 125 $now = time(); /* get the current timestamp */ 126 $diff = ($now - $post); 127 if ($diff <= 3600) { /* is it less than an hour? */ 128 $mins = round($diff / 60); 129 $since = "$mins mins"; 130 } else if (($diff <= 86400) && ($diff > 3600)) { /* is it less than a day? */ 131 $hours = round($diff / 3600); 132 if ($hours <= 1) { /* is it under two hours? */ 133 $since = "1 hour"; 134 } else { 135 $since = "$hours hours"; 136 } 137 } else if ($diff >= 86400) { /* is it more than a day? */ 138 $days = round($diff / 86400); 139 if ($days <= 1) { 140 $since = "1 day"; 141 } else { 142 $since = "$days days"; 143 } 144 } 123 function bb_since( $original, $do_more = 0 ) { 124 // array of time period chunks 125 $chunks = array( 126 array(60 * 60 * 24 * 365 , 'year'), 127 array(60 * 60 * 24 * 30 , 'month'), 128 array(60 * 60 * 24 * 7, 'week'), 129 array(60 * 60 * 24 , 'day'), 130 array(60 * 60 , 'hour'), 131 array(60 , 'minute'), 132 ); 145 133 146 // $since = "Posted ".$since." ago"; 147 return $since; 148 } 149 150 function get_option( $option ) { 134 $today = time(); 135 $since = $today - $original; 136 137 for ($i = 0, $j = count($chunks); $i < $j; $i++) { 138 $seconds = $chunks[$i][0]; 139 $name = $chunks[$i][1]; 140 141 if (($count = floor($since / $seconds)) != 0) 142 break; 143 } 144 145 $print = ($count == 1) ? '1 '.$name : "$count {$name}s"; 146 147 if ($i + 1 < $j) { 148 $seconds2 = $chunks[$i + 1][0]; 149 $name2 = $chunks[$i + 1][1]; 150 151 // add second item if it's greater than 0 152 if ( (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) && $do_more ) 153 $print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s"; 154 } 155 return $print; 156 } 157 158 function bb_get_option( $option ) { 151 159 global $bb; 152 160 … … 174 182 175 183 function option( $option ) { 176 echo get_option( $option ) ;177 } 178 179 function add_query_arg() {184 echo bb_get_option( $option ) ; 185 } 186 187 function bb_add_query_arg() { 180 188 $ret = ''; 181 189 if( is_array( func_get_arg(0) ) ) { … … 220 228 } 221 229 222 function remove_query_arg($key, $query) {223 add_query_arg($key, '', $query);230 function bb_remove_query_arg($key, $query) { 231 bb_add_query_arg($key, '', $query); 224 232 } 225 233 … … 239 247 } 240 248 241 function current_time($type) {249 function bb_current_time($type) { 242 250 switch ($type) { 243 251 case 'mysql': … … 286 294 function bb_new_topic( $title, $forum ) { 287 295 global $bbdb, $current_user; 288 $title = apply_filters('pre_topic_title', $title);296 $title = bb_apply_filters('pre_topic_title', $title); 289 297 $forum = (int) $forum; 290 $now = current_time('mysql');298 $now = bb_current_time('mysql'); 291 299 292 300 if ( $forum && $title ) { … … 297 305 $topic_id = $bbdb->insert_id; 298 306 $bbdb->query("UPDATE $bbdb->forums SET topics = topics + 1 WHERE forum_id = $forum"); 299 do_action('bb_new_topic', $topic_id);307 bb_do_action('bb_new_topic', $topic_id); 300 308 return $topic_id; 301 309 } else { … … 306 314 function bb_update_topic( $title, $topic_id ) { 307 315 global $bbdb; 308 $title = apply_filters('pre_topic_title', $title);316 $title = bb_apply_filters('pre_topic_title', $title); 309 317 $topic_id = (int) $topic_id; 310 318 $forum_id = (int) $forum_id; … … 312 320 if ( $topic_id && $title ) { 313 321 $bbdb->query("UPDATE $bbdb->topics SET topic_title = '$title' WHERE topic_id = $topic_id"); 314 do_action('bb_update_topic', $topic_id);322 bb_do_action('bb_update_topic', $topic_id); 315 323 return $topic_id; 316 324 } else { … … 321 329 function bb_new_post( $topic_id, $post ) { 322 330 global $bbdb, $current_user; 323 $post = apply_filters('pre_post', $post);331 $post = bb_apply_filters('pre_post', $post); 324 332 $tid = (int) $topic_id; 325 $now = current_time('mysql');333 $now = bb_current_time('mysql'); 326 334 $uid = $current_user->user_id; 327 335 $uname = $current_user->username; … … 339 347 $bbdb->query("UPDATE $bbdb->topics SET topic_last_poster = $uid, topic_last_poster_name = '$uname', 340 348 topic_last_post_id = $post_id, topic_posts = topic_posts + 1 WHERE topic_id = $tid"); 341 do_action('bb_new_post', $post_id);349 bb_do_action('bb_new_post', $post_id); 342 350 return $post_id; 343 351 } else { … … 348 356 function bb_update_post( $post, $post_id ) { 349 357 global $bbdb, $current_user; 350 $post = apply_filters('pre_post', $post);358 $post = bb_apply_filters('pre_post', $post); 351 359 $post_id = (int) $post_id; 352 360 353 361 if ( $post_id && $post ) { 354 362 $bbdb->query("UPDATE $bbdb->posts SET post_text = '$post' WHERE post_id = $post_id"); 355 do_action('bb_update_post', $post_id);363 bb_do_action('bb_update_post', $post_id); 356 364 return $post_id; 357 365 } else {
Note: See TracChangeset
for help on using the changeset viewer.