root/elgg/trunk/mod/forum/trunk/forum.php

Revision 176, 8.5 kB (checked in by cedenoj, 10 months ago)

refs #2827 Adding forum plugin for elgg

Line 
1 <?php
2     
3     // Run includes
4         require_once("../../includes.php");
5         include(dirname(__FILE__) . '/config.php');
6
7         global $CFG, $page_owner, $metatags, $PAGE;
8         $metatags .= "<style type=\"text/css\">";
9         $metatags .= str_replace('{{url}}', $CFG->wwwroot, file_get_contents($CFG->dirroot . "mod/forum/css"));
10         $metatags .= "</style>";
11
12         $profile_id = optional_param('owner', 0, PARAM_INT);
13
14         if (empty($profile_id)) {
15             // try to get weblog name and then id
16             $weblog = optional_param('weblog');
17
18             if (!empty($weblog)) {
19                 $profile_id = get_field('users', 'ident', 'username', $weblog);
20             }
21         } else {
22             // get weblog from id
23             $weblog = user_info('username', $profile_id);
24         }
25
26         $page_owner = $profile_id;
27
28         define("context", "forum");
29         
30         if ((context == "forum")   && run("users:type:get", $page_owner) == "community")
31         {
32             // Add to the submenu
33             $num = count($PAGE->menu_sub) + 1;
34             $PAGE->menu_sub[$num]['name'] = "forum:rssfeed";
35             $PAGE->menu_sub[$num]['html'] = '<a href="'.$CFG->wwwroot . user_info("username",$page_owner) . '/weblog/rss/"><img src="' . $CFG->wwwroot . 'mod/template/icons/rss.png" border="0" alt="rss" /></a>';
36
37             if(run("permissions:check", "weblog")){
38                 $num = $num + 1;
39                 $PAGE->menu_sub[$num]['name'] = "forum:add_discussion";
40                 $PAGE->menu_sub[$num]['html'] = "<a href=\"{$CFG->wwwroot}{$weblog}/weblog/edit\">" . __gettext("Add New Item") . "</a>";
41             }
42             
43             $num = $num + 1;
44             $PAGE->menu_sub[$num]['name'] = "forum:blogview";
45             $PAGE->menu_sub[$num]['html'] = '<a href="'.$CFG->wwwroot . user_info("username",$page_owner) . '/weblog/">' . __gettext("View as Blog") . '</a>';
46             
47
48         }
49         
50         
51         templates_page_setup();
52         
53         
54
55
56         
57
58         if (!empty($profile_id) && $profile_id > 0 && user_info('user_type', $profile_id) == 'community') {
59
60                     // If the weblog offset hasn't been set, it's 0
61                     $weblog_offset = optional_param('weblog_offset',0,PARAM_INT);
62                     $filter = optional_param('filter');
63                     
64                     // Get all posts in the system that we can see
65                     
66                     $where = run("users:access_level_sql_where",$_SESSION['userid']);
67                     
68                     if ($forum_sort == 1){
69                         $forum_sort_string="last_updated DESC, posted DESC";
70                     }
71                     else
72                     {
73                         $forum_sort_string="posted DESC";                   
74                     }
75                     
76                     
77                     if (empty($filter)) {
78                         $posts = get_records_select('weblog_posts','('.$where.') AND weblog = '.$profile_id,null,$forum_sort_string,'*',$weblog_offset,'25');
79                         $numberofposts = count_records_select('weblog_posts','('.$where.') AND weblog = '.$profile_id);
80                         //echo $numberofposts;
81                     } else {
82                         $where = str_replace("access","wp.access",$where);
83                         $where = str_replace("owner","wp.owner",$where);
84                         $posts = get_records_sql("select * from ".$CFG->prefix."tags t join ".$CFG->prefix."weblog_posts wp on wp.ident = t.ref where ($where) AND t.tagtype = 'weblog' AND wp.weblog = $profile_id AND t.tag = " . $db->qstr($filter) . " order by " . $forum_sort_string . " limit $weblog_offset,25");
85                         $numberofposts = get_record_sql("select count(wp.ident) as numberofposts from ".$CFG->prefix."tags t join ".$CFG->prefix."weblog_posts wp on wp.ident = t.ref where ($where) AND t.tagtype = 'weblog' AND wp.weblog = $profile_id AND t.tag = " . $db->qstr($filter));
86                         $numberofposts = $numberofposts->numberofposts;
87                     }
88                     
89                     
90                     $body="
91                     <table id=\"forum_table\" cellspacing=\"0\" summary=\"Forum Table\">
92                     <tr>
93                         <th scope=\"col\" class=\"nobg\">" . __gettext("Discussion Topic") . "</th>
94                         <th class=\"cent\">" . __gettext("Started by") . "</th>
95                         <th class=\"cent\">" . __gettext("Comments") . "</th>
96                         <th class=\"cent\">" . __gettext("Latest Comment") . "</th>
97                     </tr>";
98
99                     
100                     if (!empty($posts)) {
101                         
102                         
103                         foreach($posts as $post) {
104                             
105                             $time = strftime("%B %d, %Y",$post->posted);
106                             
107                             $select='select * from ' . $CFG->prefix . 'weblog_comments Where post_id='. $post->ident . ' ORDER by posted DESC Limit 1';
108                             //echo $select;
109                             $lastcomment = get_records_sql($select);
110                             
111                             $lastcommenter="";
112                             $lastcommenttime="";
113                             
114                             if ($lastcomment){
115                                 foreach($lastcomment as $comment) {
116                                     $lastcommenter=$comment->postedname;
117                                     $lastcommenttime=textify_age($comment->posted);
118                                 }
119                             }
120                             
121                             
122                             $numberofcomments = get_record_sql("select count(*) as numberofcomments from ".$CFG->prefix."weblog_comments WHERE post_id =" . $post->ident);
123                             $numberofcomments = $numberofcomments->numberofcomments;
124                             
125                             //$body .= run("weblogs:posts:view",$post);
126                             //<td><a href=\"" . $CFG->wwwroot . user_info("username",$page_owner) . "/weblog/" . $post->ident . ".html\" title=\"View full discussion...\">" . $post->title . "</a></td>
127                             
128                             // handle empty titles 
129                             if(empty($post->title)){
130                                 $words = 6; // 5 words, really
131                                 $cut_body = preg_replace("/<[^<>]>/","",$post->body);
132                                 $cut_body = explode(" ",$cut_body,$words);
133                                 array_pop($cut_body);
134                                 $post->title = "<em>".implode(" ",$cut_body)." ...</em>";
135                             }
136                             
137
138                             
139                             
140                             $body .= "
141
142                                 <tr scope=\"row\">
143                                 <td><a href=\"" . $CFG->wwwroot . "mod/forum/" . $post->ident . ".html\" title=\"" . __gettext("View full discussion...") . "\">" . $post->title . "</a></td>
144                                 <td class=\"cent\"><a href=\"" . $CFG->wwwroot . user_info("username",$post->owner) . "/" . "\" title=\"" . __gettext("View profile...") . "\">" . user_info("name",$post->owner) . "</a></td>
145                                 <td class=\"cent\"><a href=\"forum_view_thread.php?post=" . $post->ident . "\" title=\"" . __gettext("View comments...") . "\">" . $numberofcomments . "</a></td>
146                                 <td class=\"smallprint\">" . $lastcommenter . "<br>" . $lastcommenttime . "</td>
147                                 </tr>";
148                             
149                         }
150                         
151                         
152                         
153                     }
154                     
155             $body .= '</table><br>';
156
157             if (run("permissions:check", "weblog")) {
158                 $body .= '<a href="' . $CFG->wwwroot . $weblog . '/weblog/edit" title="' . __gettext("Add New Item") . '">' . __gettext("Add New Item") . '...</a><br><br>';
159     
160             }
161                 
162 if (!empty($posts)) {
163         
164     if ($numberofposts - ($weblog_offset + 25) > 0) {
165         $display_weblog_offset = $weblog_offset + 25;
166         $back = __gettext("Back");
167         $body .= <<< END
168                 
169                 <a href="{$CFG->wwwroot}mod/forum/forum.php?weblog={$weblog}&weblog_offset={$display_weblog_offset}">&lt;&lt; $back</a>
170                 
171 END;
172     }
173     if ($weblog_offset > 0) {
174         $display_weblog_offset = $weblog_offset - 25;
175         if ($display_weblog_offset < 0) {
176             $display_weblog_offset = 0;
177         }
178         $next = __gettext("Next");
179         $body .= <<< END
180                 
181                 <a href="{$CFG->wwwroot}mod/forum/forum.php?weblog={$weblog}&weblog_offset={$display_weblog_offset}">$next &gt;&gt;</a>
182                 
183 END;
184     }
185     
186 }
187
188         $title = run("profile:display:name") . " :: " . __gettext("Forum");
189     } // end !empty($profile_id)
190
191     else {
192         global $messages;
193         $messages[] = __gettext("This forum doesn't exists.");
194
195         $title = __gettext("Forum");
196         $body = "";
197
198         $profile_id = -1;
199         $page_owner = -1;
200     }
201
202     // Draw page
203
204         $body = templates_draw(array(
205                         'context' => 'contentholder',
206                         'title' => $title,
207                         'body' => $body
208                     )
209                     );
210
211         echo templates_page_draw( array(
212                         $title, $body
213                     )
214                     );
215
216
217
218 function textify_age($input)
219 {
220     $age=time()-$input;
221     if($age<60)
222         return "about a minute ago";
223     elseif($age<300)
224         return "about five minutes ago";
225     elseif($age<600)
226         return "about ten minutes ago";
227     elseif($age<1800)
228         return "about thirty minutes ago";
229     elseif($age<7200)
230         return "about an hour ago";
231     elseif($age>=7200&&$age<86400)
232         return "about ".round(floor($age/3600))." hours ago";
233     elseif($age>=86400&&$age<129600)
234         return "yesterday";
235     elseif($age>=129600&&$age<249600)
236         return round(ceil($age/86400))." days ago";
237     else
238         return "on " gmstrftime("%b %d, %y",$input);
239 }
240
241 ?>
242
243
244
Note: See TracBrowser for help on using the browser.