Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/28/2004 08:54:20 AM (17 years ago)
Author:
matt
Message:

Let's rename everything just in case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/functions.php

    r16 r18  
    1919}
    2020
    21 function get_thread ( $topic, $page = 0 ) {
     21function get_thread( $topic, $page = 0 ) {
    2222    global $bbdb, $bb;
    2323
    24     $limit = get_option('page_topics');
     24    $limit = bb_get_option('page_topics');
    2525    if ( $page )
    2626        $limit = ($limit * $page) . ", $limit";
     
    2828}
    2929
    30 function get_post ( $post_id ) {
     30function get_post( $post_id ) {
    3131    global $bbdb;
    3232    $post_id = (int) $post_id;
     
    3838    if ( $forum )
    3939        $where = "WHERE forum_id = $forum";
    40     $limit = get_option('page_topics');
     40    $limit = bb_get_option('page_topics');
    4141    if ( $page )
    4242        $limit = ($limit * $page) . ", $limit";
     
    4444}
    4545
    46 function apply_filters($tag, $string, $filter = true) {
     46function bb_apply_filters($tag, $string, $filter = true) {
    4747    global $wp_filter;
    4848    if (isset($wp_filter['all'])) {
     
    7373}
    7474
    75 function add_filter($tag, $function_to_add, $priority = 10) {
     75function bb_add_filter($tag, $function_to_add, $priority = 10) {
    7676    global $wp_filter;
    7777    // So the format is wp_filter['tag']['array of priorities']['array of functions']
     
    8282}
    8383
    84 function remove_filter($tag, $function_to_remove, $priority = 10) {
     84function bb_remove_filter($tag, $function_to_remove, $priority = 10) {
    8585    global $wp_filter;
    8686    if (@in_array($function_to_remove, $wp_filter[$tag]["$priority"])) {
     
    9898// The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content
    9999
    100 function do_action($tag, $string) {
    101     apply_filters($tag, $string, false);
     100function bb_do_action($tag, $string) {
     101    bb_apply_filters($tag, $string, false);
    102102    return $string;
    103103}
    104104
    105105function 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);
    107107}
    108108
    109109function 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 like timer_stop(1), will echo $timetotal
     110    bb_remove_filter($tag, $function_to_remove, $priority);
     111}
     112
     113function bb_timer_stop($display = 0, $precision = 3) { //if called like bb_timer_stop(1), will echo $timetotal
    114114    global $bb_timestart, $timeend;
    115115    $mtime = explode(' ', microtime());
     
    121121}
    122122
    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     }
     123function 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    );
    145133   
    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
     158function bb_get_option( $option ) {
    151159    global $bb;
    152160
     
    174182
    175183function option( $option ) {
    176     echo get_option( $option ) ;
    177 }
    178 
    179 function add_query_arg() {
     184    echo bb_get_option( $option ) ;
     185}
     186
     187function bb_add_query_arg() {
    180188    $ret = '';
    181189    if( is_array( func_get_arg(0) ) ) {
     
    220228}
    221229
    222 function remove_query_arg($key, $query) {
    223     add_query_arg($key, '', $query);
     230function bb_remove_query_arg($key, $query) {
     231    bb_add_query_arg($key, '', $query);
    224232}
    225233
     
    239247}
    240248
    241 function current_time($type) {
     249function bb_current_time($type) {
    242250    switch ($type) {
    243251        case 'mysql':
     
    286294function bb_new_topic( $title, $forum ) {
    287295    global $bbdb, $current_user;
    288     $title = apply_filters('pre_topic_title', $title);
     296    $title = bb_apply_filters('pre_topic_title', $title);
    289297    $forum = (int) $forum;
    290     $now   = current_time('mysql');
     298    $now   = bb_current_time('mysql');
    291299
    292300    if ( $forum && $title ) {
     
    297305        $topic_id = $bbdb->insert_id;
    298306        $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);
    300308        return $topic_id;
    301309    } else {
     
    306314function bb_update_topic( $title, $topic_id ) {
    307315    global $bbdb;
    308     $title = apply_filters('pre_topic_title', $title);
     316    $title = bb_apply_filters('pre_topic_title', $title);
    309317    $topic_id = (int) $topic_id;
    310318    $forum_id = (int) $forum_id;
     
    312320    if ( $topic_id && $title ) {
    313321        $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);
    315323        return $topic_id;
    316324    } else {
     
    321329function bb_new_post( $topic_id, $post ) {
    322330    global $bbdb, $current_user;
    323     $post  = apply_filters('pre_post', $post);
     331    $post  = bb_apply_filters('pre_post', $post);
    324332    $tid   = (int) $topic_id;
    325     $now   = current_time('mysql');
     333    $now   = bb_current_time('mysql');
    326334    $uid   = $current_user->user_id;
    327335    $uname = $current_user->username;
     
    339347        $bbdb->query("UPDATE $bbdb->topics SET topic_last_poster = $uid, topic_last_poster_name = '$uname',
    340348        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);
    342350        return $post_id;
    343351    } else {
     
    348356function bb_update_post( $post, $post_id ) {
    349357    global $bbdb, $current_user;
    350     $post  = apply_filters('pre_post', $post);
     358    $post  = bb_apply_filters('pre_post', $post);
    351359    $post_id   = (int) $post_id;
    352360
    353361    if ( $post_id && $post ) {
    354362        $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);
    356364        return $post_id;
    357365    } else {
Note: See TracChangeset for help on using the changeset viewer.