A series of changes to push Elgg's approach to themes in a more CSS driven direction...
[elgg.git] / units / weblogs / weblogs_posts_view.php
blobb17d6c5a950081862c26f53b0204b2d6e360c34d
1 <?php
3 if (isset($parameter)) {
5 $post = $parameter;
7 global $post_authors;
8 global $individual;
10 $url = url;
12 if (!isset($post_authors[$post->owner])) {
14 $author = "";
16 $stuff = db_query("select users.* from users where ident = ".$post->owner);
17 $stuff = $stuff[0];
19 $author->fullname = stripslashes($stuff->name);
21 if ($stuff->icon == -1 || $post->owner == -1) {
22 $author->icon = "default.png";
23 } else {
24 $icon = db_query("select filename from icons where ident = ".$stuff->icon);
25 $author->icon = $icon[0]->filename;
28 $post_authors[$post->owner] = $author;
31 if (!isset($post->authors[$post->weblog])) {
32 $community = "";
34 $stuff2 = db_query("select users.* from users where ident = ".$post->weblog);
35 $stuff2 = $stuff2[0];
37 $community->fullname = stripslashes($stuff2->name);
39 if ($stuff2->icon == -1) {
40 $community->icon = "default.png";
41 } else {
42 $icon = db_query("select filename from icons where ident = ".$stuff2->icon);
43 $community->icon = $icon[0]->filename;
46 $post_authors[$post->weblog] = $community;
49 $date = gmdate("H:i",$post->posted);
50 $username = run("users:id_to_name",$post->owner);
51 $usericon = $post_authors[$post->owner]->icon;
52 if ($usericon == "default.png") {
53 $usericon = $post_authors[$post->weblog]->icon;
55 $fullname = $post_authors[$post->owner]->fullname;
56 $title = stripslashes($post->title);
58 if ($post->owner != $post->weblog) {
60 if ($post_authors[$post->owner]->icon == -1) {
61 $usericon = $post_authors[$post->weblog]->icon;
63 $fullname .= " @ " . $post_authors[$post->weblog]->fullname;
64 $username = run("users:id_to_name",$post->weblog);
67 $body = run("weblogs:text:process",stripslashes($post->body));
68 $More = gettext("More");
69 $Keywords = gettext("Keywords:");
70 $anyComments = gettext("comment(s)");
71 $body = str_replace("{{more}}","<a href=\"" . url . "/".$username."/weblog/{$post->ident}.html\">$More ...</a>",$body);
72 $keywords = run("display:output_field", array("","keywords","weblog","weblog",$post->ident,$post->owner));
73 if ($keywords) {
74 $body .= <<< END
75 <div class="weblog_keywords">
76 <p>
77 $Keywords {$keywords}
78 </p>
79 </div>
80 END;
82 // if ($post->owner == $_SESSION['userid'] && logged_on) {
83 if (run("permissions:check",array("weblog:edit",$post->owner))) {
84 $Edit = gettext("Edit");
85 $returnConfirm = gettext("Are you sure you want to permanently delete this weblog post?");
86 $Delete = gettext("Delete");
87 $body .= <<< END
89 <div class="blog_edit_functions">
90 <p>
91 [<a href="{$url}_weblog/edit.php?action=edit&weblog_post_id={$post->ident}&owner={$post->owner}">$Edit</a>]
92 [<a href="{$url}_weblog/action_redirection.php?action=delete_weblog_post&delete_post_id={$post->ident}" onClick="return confirm('$returnConfirm')">$Delete</a>]
93 </p>
94 </div>
96 END;
99 if (!isset($_SESSION['comment_cache'][$post->ident]) || (time() - $_SESSION['comment_cache'][$post->ident]->created > 120)) {
100 $numcomments = db_query("select count(ident) as numcomments from weblog_comments where post_id = " . $post->ident);
101 $_SESSION['comment_cache'][$post->ident]->created = time();
102 $_SESSION['comment_cache'][$post->ident]->data = $numcomments[0]->numcomments;
104 $numcomments = $_SESSION['comment_cache'][$post->ident]->data;
106 $comments = "<a href=\"".url.$username."/weblog/{$post->ident}.html\">$numcomments $anyComments</a>";
108 if (isset($individual) && ($individual == 1)) {
109 // looking at an individual post and its comments
111 $commentsbody = "";
113 if ($post->ident > 0) {
114 // if post exists and is visible
116 $comments = db_query("select * from weblog_comments where post_id = " . $post->ident . " order by posted asc");
118 if (sizeof($comments) > 0) {
119 foreach($comments as $comment) {
120 $commentmenu = "";
121 if (logged_on && ($comment->owner == $_SESSION['userid'] || $post->owner == $_SESSION['userid'])) {
122 $Edit = gettext("Edit");
123 $returnConfirm = gettext("Are you sure you want to permanently delete this weblog comment?");
124 $Delete = gettext("Delete");
125 $commentmenu = <<< END
127 [<a href="{$url}_weblog/action_redirection.php?action=weblog_comment_delete&amp;weblog_comment_delete={$comment->ident}" onClick="return confirm('$returnConfirm')">$Delete</a>]
128 </p>
129 END;
131 $comment->postedname = stripslashes($comment->postedname);
133 // turn commentor name into a link if they're a registered user
134 if ($comment->owner > 0) {
135 $commentownerusername = run("users:id_to_name",$comment->owner);
136 $comment->postedname = '<a href="' . url . $commentownerusername . '/">' . $comment->postedname . '</a>';
139 $commentsbody .= run("templates:draw", array(
140 'context' => 'weblogcomment',
141 'postedname' => $comment->postedname,
142 'body' => run("weblogs:text:process",stripslashes($comment->body)) . $commentmenu,
143 'posted' => strftime("%A, %e %B %Y, %R %Z",$comment->posted)
148 $commentsbody = run("templates:draw", array(
149 'context' => 'weblogcomments',
150 'comments' => $commentsbody
156 $run_result .= run("templates:draw", array(
157 'context' => 'weblogpost',
158 'date' => $date,
159 'username' => $username,
160 'usericon' => $usericon,
161 'body' => $body,
162 'fullname' => $fullname,
163 'title' => $title,
164 'comments' => $commentsbody
168 if (logged_on || run("users:flags:get",array("publiccomments",$post->owner))) {
169 $run_result .= run("weblogs:comments:add",$post);
170 } else {
171 $run_result .= "<p>" . gettext("You must be logged in to post a comment.") . "</p>";
174 } else {
175 // post is missing or prohibited
177 $run_result .= run("templates:draw", array(
178 'context' => 'weblogpost',
179 'date' => "",
180 'username' => "",
181 'usericon' => "default.png",
182 'body' => $body,
183 'fullname' => "",
184 'title' => $title,
185 'comments' => ""
190 } else {
192 $run_result .= run("templates:draw", array(
193 'context' => 'weblogpost',
194 'date' => $date,
195 'username' => $username,
196 'usericon' => $usericon,
197 'body' => $body,
198 'fullname' => $fullname,
199 'title' => $title,
200 'commentslink' => $comments