Skip to:
Content

BuddyPress.org

Ticket #137: bp-activity-templatetags.php

File bp-activity-templatetags.php, 5.4 KB (added by iprashant, 17 years ago)

patch for activity to work with local languages

Line 
1<?php
2
3class BP_Activity_Template {
4        var $current_activity = -1;
5        var $activity_count;
6        var $activities;
7        var $activity;
8       
9        var $in_the_loop;
10       
11        var $pag_page;
12        var $pag_num;
13        var $pag_links;
14        var $total_activity_count;
15       
16        var $full_name;
17       
18        var $table_name;
19        var $filter_content;
20        var $is_home;
21       
22        function bp_activity_template( $user_id = false, $limit = false, $filter_content = true ) {
23                global $bp;
24               
25                if ( !$user_id )
26                        $user_id = $bp['current_userid'];
27                       
28                if ( $bp['current_component'] != $bp['activity']['slug'] || ( $bp['current_component'] == $bp['activity']['slug'] && $bp['current_action'] == 'just-me' ) ) {
29                        $this->activities = BP_Activity_Activity::get_activity_for_user( $user_id, $limit );
30                } else {
31                        $this->activities = BP_Activity_Activity::get_activity_for_friends( $user_id, $limit );
32                }
33
34                $this->activity_count = count($this->activities);
35       
36                $this->full_name = $bp['current_fullname'];
37
38                $this->is_home = bp_is_home();
39                $this->filter_content = $filter_content;
40        }
41       
42        function has_activities() {
43                if ( $this->activity_count )
44                        return true;
45               
46                return false;
47        }
48       
49        function next_activity() {
50                $this->current_activity++;
51                $this->activity = $this->activities[$this->current_activity];
52               
53                return $this->activity;
54        }
55       
56        function rewind_activities() {
57                $this->current_activity = -1;
58                if ( $this->activity_count > 0 ) {
59                        $this->activity = $this->activities[0];
60                }
61        }
62       
63        function user_activities() { 
64                if ( $this->current_activity + 1 < $this->activity_count ) {
65                        return true;
66                } elseif ( $this->current_activity + 1 == $this->activity_count ) {
67                        do_action('loop_end');
68                        // Do some cleaning up after the loop
69                        $this->rewind_activities();
70                }
71
72                $this->in_the_loop = false;
73                return false;
74        }
75       
76        function the_activity() {
77                global $activity;
78
79                $this->in_the_loop = true;
80                $this->activity = $this->next_activity();
81
82                if ( $this->current_activity == 0 ) // loop has just started
83                        do_action('loop_start');
84        }
85}
86
87function bp_activity_get_list( $user_id, $title, $no_activity, $limit = false ) {
88        global $bp_activity_user_id, $bp_activity_limit, $bp_activity_title, $bp_activity_no_activity;
89       
90        $bp_activity_user_id = $user_id;
91        $bp_activity_limit = $limit;
92        $bp_activity_title = $title;
93        $bp_activity_no_activity = $no_activity;
94       
95        load_template( TEMPLATEPATH . '/activity/activity-list.php' );
96}
97
98function bp_has_activities() {
99        global $bp, $activities_template, $bp_activity_user_id, $bp_activity_limit;
100       
101        if ( $bp['current_action'] == 'my-friends' )
102                $filter_content = false;
103        else
104                $filter_content = true;
105       
106        $activities_template = new BP_Activity_Template( $bp_activity_user_id, $bp_activity_limit, $filter_content );           
107        return $activities_template->has_activities();
108}
109
110function bp_activities() {
111        global $activities_template;
112        return $activities_template->user_activities();
113}
114
115function bp_the_activity() {
116        global $activities_template;
117        return $activities_template->the_activity();
118}
119
120function bp_activities_title() {
121        global $bp_activity_title;
122        echo $bp_activity_title;
123}
124
125function bp_activities_no_activity() {
126        global $bp_activity_no_activity;
127        echo $bp_activity_no_activity;
128}
129
130function bp_activity_content() {
131        global $activities_template;
132       
133        if ( $activities_template->filter_content ) {
134                if ( $activities_template->is_home ) {
135                        echo bp_activity_content_filter( $activities_template->activity['content'], $activities_template->activity['date_recorded'], $activities_template->full_name );                                         
136                } else {
137                        echo bp_activity_content_filter( $activities_template->activity['content'], $activities_template->activity['date_recorded'], $activities_template->full_name, true, false, false );                                                                     
138                }
139        } else {
140                $activities_template->activity['content'] = bp_activity_insert_time_since( $activities_template->activity['content'], $activities_template->activity['date_recorded'] );
141                echo $activities_template->activity['content'];
142        }
143}
144
145function bp_activity_content_filter( $content, $date_recorded, $full_name, $insert_time = true, $filter_words = true, $filter_you = true ) {
146        if ( !$content )
147                return false;
148               
149        /* Split the content so we don't evaluate and replace text on content we don't want to */
150        $content = explode( '%s', $content );
151
152        /** Commented to work for local langugaes made changes to "content" column in wp_bp_activity_sitewide table
153        *** Re-add the exploded %s *
154        ** $content[0] .= '%s';
155        **/
156        /* Insert the time since */
157        if ( $insert_time )
158                $content[0] = bp_activity_insert_time_since( $content[0], $date_recorded );
159
160        /* Switch 'their/your' depending on whether the user is logged in or not and viewing their profile */
161        if ( $filter_words ) {
162                $content[0] = str_replace( __('their', 'buddypress'), __('your', 'buddypress'), $content[0] );
163        }
164       
165        /* Remove the 'You' and replace if with the persons name */
166        if ( $filter_you ) {
167                $content[0] = str_replace( $full_name, __('You', 'buddypress'), $content[0] );                         
168        }
169       
170        for ( $i = 0; $i < count($content); $i++ )
171                $content_new .= $content[$i];
172       
173        return $content_new;
174}
175
176function bp_activity_insert_time_since( $content, $date ) {
177        /** Commented & replaced to work for local langugaes. Reason of commenting - long url getting interrupted
178        ** return sprintf( $content, '&nbsp; ' . bp_core_time_since( strtotime( $date ) ) . ' ' . __('ago', 'buddypress') );
179        **/
180        return $content . sprintf( "%s", '&nbsp; ' . bp_core_time_since( strtotime( $date ) ) . ' ' . __('ago', 'buddypress') );
181}
182
183function bp_activity_css_class() {
184        global $activities_template;
185        echo $activities_template->activity['component_name'];
186}
187
188
189
190?>