A couple of tweaks to get the comment owner to display properly
[elgg.git] / units / weblogs / weblogs_posts_view.php
blob647d6114ed940a7db509771a546856dd1e205837
1 <?php
3 if (isset($parameter)) {
5 $post = $parameter;
7 global $post_authors;
8 global $individual;
9 global $CFG;
11 $url = url;
13 //if (!isset($post_authors[$post->owner])) {
15 $author = "";
17 $stuff = get_record('users','ident',$post->owner);
19 $author->fullname = stripslashes($stuff->name);
21 if ($stuff->icon == -1 || $post->owner == -1) {
22 $author->icon = 0;
23 } else {
24 $icon = get_record('icons','ident',$stuff->icon);
25 $author->icon = $icon->ident;
28 $post_authors[$post->owner] = $author;
30 //}
31 //if (!isset($post->authors[$post->weblog])) {
32 $community = "";
34 $stuff2 = get_record('users','ident',$post->weblog);
36 $community->fullname = stripslashes($stuff2->name);
38 if (empty($stuff2->icon) || $stuff2->icon == -1) {
39 $community->icon = 0;
40 } else {
41 $icon = get_record('icons','ident',$stuff2->icon);
42 $community->icon = $icon->ident;
45 $post_authors[$post->weblog] = $community;
46 //}
48 $date = gmdate("H:i",$post->posted);
50 $username = run("users:id_to_name",$post->owner);
53 // Allow plugins to set special icons
54 $specialicon = run("weblogs:posts:geticon",$post);
56 // If there is no special icon for this post, set to the default
57 if ($specialicon == NULL) {
58 $usericon = $post_authors[$post->owner]->icon;
59 if ($usericon == "default.png") {
60 $usericon = $post_authors[$post->weblog]->icon;
62 } else {
63 $usericon = $specialicon;
66 // Allow plugins to set the name on the post
67 $specialname = run("weblogs:posts:getname",$post);
68 if (empty($specialname)) {
69 $fullname = $post_authors[$post->owner]->fullname;
70 } else {
71 $fullname = $specialname;
73 if ($post->access != "PUBLIC") {
74 if ($post->access == "LOGGED_IN") {
75 $title = "[" . gettext("Logged in users") . "]";
76 } else if (substr_count($post->access, "user") > 0) {
77 $title = "[" . gettext("Private") . "]";
78 } else {
79 $title = "[" . gettext("Restricted") . "]";
81 } else {
82 $title = "";
85 $title .= " " . stripslashes($post->title);
87 if ($post->owner != $post->weblog) {
89 if ($post_authors[$post->owner]->icon == -1) {
90 $usericon = $post_authors[$post->weblog]->icon;
93 $fullname .= " @ " . $post_authors[$post->weblog]->fullname;
94 $username = run("users:id_to_name",$post->weblog);
97 $body = run("weblogs:text:process",stripslashes($post->body));
98 $More = gettext("More");
99 $Keywords = gettext("Keywords:");
100 $anyComments = gettext("comment(s)");
101 $body = str_replace("{{more}}","<a href=\"" . url .$username."/weblog/{$post->ident}.html\">$More ...</a>",$body);
102 $keywords = display_output_field(array("","keywords","weblog","weblog",$post->ident,$post->owner));
104 if ($keywords) {
105 $body .= <<< END
106 <div class="weblog_keywords">
108 $Keywords {$keywords}
109 </p>
110 </div>
111 END;
113 // if ($post->owner == $_SESSION['userid'] && logged_on) {
114 if (run("permissions:check",array("weblog:edit",$post->owner))) {
115 $Edit = gettext("Edit");
116 $returnConfirm = gettext("Are you sure you want to permanently delete this weblog post?");
117 $Delete = gettext("Delete");
118 $body .= <<< END
120 <div class="blog_edit_functions">
122 [<a href="{$url}_weblog/edit.php?action=edit&amp;weblog_post_id={$post->ident}&amp;owner={$post->owner}">$Edit</a>]
123 [<a href="{$url}_weblog/action_redirection.php?action=delete_weblog_post&amp;delete_post_id={$post->ident}" onclick="return confirm('$returnConfirm')">$Delete</a>]
124 </p>
125 </div>
127 END;
130 if (!isset($_SESSION['comment_cache'][$post->ident]) || (time() - $_SESSION['comment_cache'][$post->ident]->created > 120)) {
131 $numcomments = count_records('weblog_comments','post_id',$post->ident);
132 $_SESSION['comment_cache'][$post->ident]->created = time();
133 $_SESSION['comment_cache'][$post->ident]->data = $numcomments;
135 $numcomments = $_SESSION['comment_cache'][$post->ident]->data;
137 $comments = "<a href=\"".url.$username."/weblog/{$post->ident}.html\">$numcomments $anyComments</a>";
139 if (isset($individual) && ($individual == 1)) {
140 // looking at an individual post and its comments
142 $commentsbody = "";
144 if ($post->ident > 0) {
145 // if post exists and is visible
147 if ($comments = get_records('weblog_comments','post_id',$post->ident,'posted ASC')) {
148 foreach($comments as $comment) {
149 $commentmenu = "";
150 if (logged_on && ($comment->owner == $_SESSION['userid'] || run("permissions:check", "weblog"))) {
151 $Edit = gettext("Edit");
152 $returnConfirm = gettext("Are you sure you want to permanently delete this weblog comment?");
153 $Delete = gettext("Delete");
154 $commentmenu = <<< END
157 [<a href="{$url}_weblog/action_redirection.php?action=weblog_comment_delete&amp;weblog_comment_delete={$comment->ident}" onclick="return confirm('$returnConfirm')">$Delete</a>]
158 </p>
159 END;
161 $comment->postedname = stripslashes($comment->postedname);
163 // turn commentor name into a link if they're a registered user
164 if ($comment->owner > 0) {
165 $commentownerusername = run("users:id_to_name",$comment->owner);
166 $comment->postedname = '<a href="' . url . $commentownerusername . '/">' . $comment->postedname . '</a>';
167 $comment->icon = '<a href="' . url . $commentownerusername . '/">' . "<img src=\"" . $CFG->wwwroot . $commentownerusername . "/icons/" . run("icons:get",$comment->owner) . "/w/50/h/50/\" border=\"0\" align=\"left\"/></a>";
168 } else {
169 $comment->icon = "<img src=\"" . $CFG->wwwroot . "_icons/data/default.png\" width=\"50\" height=\"50\" align=\"left\"/>";
172 $commentsbody .= templates_draw(array(
173 'context' => 'weblogcomment',
174 'postedname' => $comment->postedname,
175 'body' => run("weblogs:text:process",stripslashes($comment->body)) . $commentmenu,
176 'posted' => strftime("%A, %e %B %Y, %R %Z",$comment->posted),
177 'usericon' => $comment->icon
182 $commentsbody = templates_draw(array(
183 'context' => 'weblogcomments',
184 'comments' => $commentsbody
190 $run_result .= templates_draw(array(
191 'context' => 'weblogpost',
192 'date' => $date,
193 'username' => $username,
194 'usericon' => $usericon,
195 'body' => $body,
196 'fullname' => $fullname,
197 'title' => "<a href=\"".url.$username."/weblog/{$post->ident}.html\">$title</a>",
198 'comments' => $commentsbody
202 if (logged_on || run("users:flags:get",array("publiccomments",$post->owner))) {
203 $run_result .= run("weblogs:comments:add",$post);
204 } else {
205 $run_result .= "<p>" . gettext("You must be logged in to post a comment.") . "</p>";
208 $run_result .= run("weblogs:interesting:form",$post->ident);
210 } else {
211 // post is missing or prohibited
213 $run_result .= templates_draw(array(
214 'context' => 'weblogpost',
215 'date' => "",
216 'username' => "",
217 'usericon' => "default.png",
218 'body' => $body,
219 'fullname' => "",
220 'title' => "<a href=\"".url.$username."/weblog/{$post->ident}.html\">$title</a>",
221 'comments' => ""
225 } else {
227 $run_result .= templates_draw(array(
228 'context' => 'weblogpost',
229 'date' => $date,
230 'username' => $username,
231 'usericon' => $usericon,
232 'body' => $body,
233 'fullname' => $fullname,
234 'title' => "<a href=\"".url.$username."/weblog/{$post->ident}.html\">$title</a>",
235 'commentslink' => $comments