| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 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 |
|
|---|
| 16 |
$weblog = optional_param('weblog'); |
|---|
| 17 |
|
|---|
| 18 |
if (!empty($weblog)) { |
|---|
| 19 |
$profile_id = get_field('users', 'ident', 'username', $weblog); |
|---|
| 20 |
} |
|---|
| 21 |
} else { |
|---|
| 22 |
|
|---|
| 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 |
|
|---|
| 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 Topic") . "</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 |
|
|---|
| 61 |
$weblog_offset = optional_param('weblog_offset',0,PARAM_INT); |
|---|
| 62 |
$filter = optional_param('filter'); |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 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 |
|
|---|
| 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 class=\"cent\">" . __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 |
$row_class = 'odd'; |
|---|
| 104 |
foreach($posts as $post) { |
|---|
| 105 |
if ($row_class == 'odd') { |
|---|
| 106 |
$row_class = 'even'; |
|---|
| 107 |
} else { |
|---|
| 108 |
$row_class = 'odd'; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
$time = strftime("%B %d, %Y",$post->posted); |
|---|
| 112 |
|
|---|
| 113 |
$select='select * from ' . $CFG->prefix . 'weblog_comments Where post_id='. $post->ident . ' ORDER by posted DESC Limit 1'; |
|---|
| 114 |
|
|---|
| 115 |
$lastcomment = get_records_sql($select); |
|---|
| 116 |
|
|---|
| 117 |
$lastcommenter=""; |
|---|
| 118 |
$lastcommenttime=""; |
|---|
| 119 |
|
|---|
| 120 |
if ($lastcomment){ |
|---|
| 121 |
foreach($lastcomment as $comment) { |
|---|
| 122 |
$lastcommenter=$comment->postedname; |
|---|
| 123 |
$lastcommenttime=textify_age($comment->posted); |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
$numberofcomments = get_record_sql("select count(*) as numberofcomments from ".$CFG->prefix."weblog_comments WHERE post_id =" . $post->ident); |
|---|
| 129 |
$numberofcomments = $numberofcomments->numberofcomments; |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
//<td><a href=\"" . $CFG->wwwroot . user_info("username",$page_owner) . "/weblog/" . $post->ident . ".html\" title=\"View full discussion...\">" . $post->title . "</a></td> |
|---|
| 133 |
|
|---|
| 134 |
// handle empty titles |
|---|
| 135 |
if(empty($post->title)){ |
|---|
| 136 |
$words = 6; |
|---|
| 137 |
$cut_body = preg_replace("/<[^<>]>/","",$post->body); |
|---|
| 138 |
$cut_body = explode(" ",$cut_body,$words); |
|---|
| 139 |
array_pop($cut_body); |
|---|
| 140 |
$post->title = "<em>".implode(" ",$cut_body)." ...</em>"; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
$body .= " |
|---|
| 147 |
<tr scope=\"row\" class=\"$row_class\"> |
|---|
| 148 |
<td><a href=\"" . $CFG->wwwroot . "mod/forum/" . $post->ident . ".html\" title=\"" . __gettext("View full discussion...") . "\">" . $post->title . "</a></td> |
|---|
| 149 |
<td class=\"cent\"><a href=\"" . $CFG->wwwroot . user_info("username",$post->owner) . "/" . "\" title=\"" . __gettext("View profile...") . "\">" . user_info("name",$post->owner) . "</a></td> |
|---|
| 150 |
<td class=\"cent\"><a href=\"forum_view_thread.php?post=" . $post->ident . "\" title=\"" . __gettext("View comments...") . "\">" . $numberofcomments . "</a></td> |
|---|
| 151 |
<td class=\"smallprint\">" . $lastcommenter . "<br>" . $lastcommenttime . "</td> |
|---|
| 152 |
</tr>"; |
|---|
| 153 |
|
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
$body .= '</table><br>'; |
|---|
| 161 |
|
|---|
| 162 |
if (run("permissions:check", "weblog")) { |
|---|
| 163 |
$body .= '<form action="'. $CFG->wwwroot . $weblog . '/weblog/edit">'; |
|---|
| 164 |
$body .= '<input type="submit" value="'.__gettext("Add New Topic").'"/></form>'; |
|---|
| 165 |
} |
|---|
| 166 |
|
|---|
| 167 |
if (!empty($posts)) { |
|---|
| 168 |
|
|---|
| 169 |
if ($numberofposts - ($weblog_offset + 25) > 0) { |
|---|
| 170 |
$display_weblog_offset = $weblog_offset + 25; |
|---|
| 171 |
$back = __gettext("Back"); |
|---|
| 172 |
$body .= <<< END |
|---|
| 173 |
|
|---|
| 174 |
<a href="{$CFG->wwwroot}mod/forum/forum.php?weblog={$weblog}&weblog_offset={$display_weblog_offset}"><< $back</a> |
|---|
| 175 |
|
|---|
| 176 |
END; |
|---|
| 177 |
} |
|---|
| 178 |
if ($weblog_offset > 0) { |
|---|
| 179 |
$display_weblog_offset = $weblog_offset - 25; |
|---|
| 180 |
if ($display_weblog_offset < 0) { |
|---|
| 181 |
$display_weblog_offset = 0; |
|---|
| 182 |
} |
|---|
| 183 |
$next = __gettext("Next"); |
|---|
| 184 |
$body .= <<< END |
|---|
| 185 |
|
|---|
| 186 |
<a href="{$CFG->wwwroot}mod/forum/forum.php?weblog={$weblog}&weblog_offset={$display_weblog_offset}">$next >></a> |
|---|
| 187 |
|
|---|
| 188 |
END; |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
$title = run("profile:display:name") . " :: " . __gettext("Forum"); |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
else { |
|---|
| 197 |
global $messages; |
|---|
| 198 |
$messages[] = __gettext("This forum doesn't exists."); |
|---|
| 199 |
|
|---|
| 200 |
$title = __gettext("Forum"); |
|---|
| 201 |
$body = ""; |
|---|
| 202 |
|
|---|
| 203 |
$profile_id = -1; |
|---|
| 204 |
$page_owner = -1; |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
$body = templates_draw(array( |
|---|
| 210 |
'context' => 'contentholder', |
|---|
| 211 |
'title' => $title, |
|---|
| 212 |
'body' => $body |
|---|
| 213 |
) |
|---|
| 214 |
); |
|---|
| 215 |
|
|---|
| 216 |
echo templates_page_draw( array( |
|---|
| 217 |
$title, $body |
|---|
| 218 |
) |
|---|
| 219 |
); |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
function textify_age($input) |
|---|
| 224 |
{ |
|---|
| 225 |
$age=time()-$input; |
|---|
| 226 |
if($age<60) |
|---|
| 227 |
return "about a minute ago"; |
|---|
| 228 |
elseif($age<300) |
|---|
| 229 |
return "about five minutes ago"; |
|---|
| 230 |
elseif($age<600) |
|---|
| 231 |
return "about ten minutes ago"; |
|---|
| 232 |
elseif($age<1800) |
|---|
| 233 |
return "about thirty minutes ago"; |
|---|
| 234 |
elseif($age<7200) |
|---|
| 235 |
return "about an hour ago"; |
|---|
| 236 |
elseif($age>=7200&&$age<86400) |
|---|
| 237 |
return "about ".round(floor($age/3600))." hours ago"; |
|---|
| 238 |
elseif($age>=86400&&$age<129600) |
|---|
| 239 |
return "yesterday"; |
|---|
| 240 |
elseif($age>=129600&&$age<249600) |
|---|
| 241 |
return round(ceil($age/86400))." days ago"; |
|---|
| 242 |
else |
|---|
| 243 |
return "on " . gmstrftime("%b %d, %y",$input); |
|---|
| 244 |
} |
|---|
| 245 |
|
|---|
| 246 |
?> |
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|