source: trunk/log.php @ 1798

Revision 1798, 12.5 KB checked in by driehle, 3 years ago (diff)

Moved Jlog 1.5 branch into trunk/ as we will focus on Jlog 1.5 development in the future

  • Property svn:keywords set to Date Rev Author HeadURL
Line 
1<?php
2
3/**
4 * Jlog
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 *
20 * $HeadURL$
21 * $Rev$
22 * $Author$
23 * $Date$
24 **/
25
26require_once('./config.inc.php');
27require_once(JLOG_LIBPATH . '/bootstrap.php');
28
29
30 $get = strip($_GET);
31 $c['form_content'] = "";
32 $date = strftime(JLOG_DATE);
33
34 $sql_get = escape_for_mysql($get);
35
36        if(!empty($sql_get['y']) AND !empty($sql_get['m']) AND !empty($sql_get['url'])) {
37                $sql = "SELECT
38                                 *,
39                                 UNIX_TIMESTAMP(date) AS date,
40                                 DATE_FORMAT(date, '%Y-%m-%dT%T".substr(date("O"), 0, 3) . ":" . substr(date("O"), 3)."') AS metadate
41                                 FROM ".JLOG_DB_CONTENT."
42                                 WHERE
43                                                YEAR(date)      = ".$sql_get['y']." AND
44                                                MONTH(date)     = ".$sql_get['m']." AND
45                                                url                     = '".$sql_get['url']."' AND
46                                                section         = 'weblog'
47                                  LIMIT 1";
48
49        $blog = new Query($sql);
50        if($blog->error()) {
51                echo "<pre>\n";
52                echo $blog->getError();
53                echo "</pre>\n";
54                die();
55        }
56
57                if($blog->numRows() == 0) {
58                        header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
59                        include_once(JLOG_BASEPATH."error404.php");
60                        exit;
61                }
62        }
63        else {
64                header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
65                include_once(JLOG_BASEPATH."error404.php");
66                exit;
67        }
68
69 $blogentry = $blog->fetch();
70
71// get comments from Database
72
73        $sql_comments = "SELECT
74                                                                *,
75                                                                UNIX_TIMESTAMP(date) AS date
76                                                        FROM ".JLOG_DB_COMMENTS."
77                                                        WHERE reference = '".$blogentry['id']."'
78                                                        ORDER BY date;";
79
80 $c['meta']['date']        = $blogentry['metadate'];
81 $c['meta']['description'] = strip_tags($bbcode->parse($blogentry['teaser']));
82 $c['meta']['keywords']    = $blogentry['keywords'];
83 $c['meta']['title']       = $blogentry['topic'];
84 $c['meta']['pingback']    = true;
85
86 $c['main'] = do_entry($blogentry);
87
88// Form entry
89
90 $com_form = strip($_POST);
91 if(!isset($com_form['type'])) $com_form['type'] = "";
92 $error = com_check_errors($com_form);
93
94// Preview
95 if(isset($com_form['form_submitted']) AND $com_form['form_submitted'] === $l['comments_preview']) {
96
97    $comments = new Query($sql_comments);
98     if($comments->error()) {
99        echo "<pre>\n";
100        echo $comments->getError();
101        echo "</pre>\n";
102        die();
103     }
104
105    $commentsArray = array();
106    $countComments = 0;
107    while($commentsArray[] = $comments->fetch());
108    foreach($commentsArray as $tmp_comment) if($tmp_comment['type'] != 'pingback') ++$countComments;
109
110  $preview = "";
111  if(isset($error)) $preview .= error_output($error);
112  $clear_form = com_clean_data($com_form);
113  $clear_form['id'] = "";
114 
115  ### Plugin Hook
116  $clear_form = $plugins->callHook('previewComment', $clear_form, $blogentry);
117
118  $preview .= "
119   <ul class='comments' id='preview'>
120    ".do_comment($clear_form, $countComments)."
121   </ul>";
122
123  $c['form_content'] .= $preview;
124  $c['form_content'] .= com_form_output($com_form).com_javascript_variables();
125 }
126
127
128// Send data to DB
129 elseif(isset($com_form['form_submitted']) AND $com_form['form_submitted'] == $l['comments_send'] AND $blogentry['comments'] == 1) {
130  if(isset($error)) {
131
132   $c['form_content'] .= error_output($error);
133   $c['form_content'] .= com_form_output($com_form).com_javascript_variables();
134  }
135  else {
136 // Send comment
137
138   $com_form = com_clean_data($com_form);
139
140   ### Plugin Hook
141   $com_form = $plugins->callHook('newComment', $com_form, $blogentry);
142
143   $com = escape_for_mysql($com_form);
144   if(!isset($com['mail_by_comment'])) $com['mail_by_comment'] = "";
145   
146   $sql = "INSERT INTO ".JLOG_DB_COMMENTS." (
147                        sid,
148                        name,
149                        city,
150                        email,
151                        homepage,
152                        content,
153                        reference,
154                        mail_by_comment,
155                        date,
156                                                                                                type
157                  )
158           VALUES (
159            '".$com['sid']."',
160            '".$com['name']."',
161            '".$com['city']."',
162            '".$com['email']."',
163            '".$com['homepage']."',
164            '".$com['content']."',
165            '".$blogentry['id']."',
166            '".$com['mail_by_comment']."',
167            NOW(),
168                                                '".$com['type']."'
169           )"; 
170
171   $newcomment = new Query($sql);
172   $cid = mysql_insert_id();
173   if($newcomment->error()) {
174    if($newcomment->getErrno() == 1062) {
175          $errors[] = $l['comments_duplicate'];
176     $c['form_content'] .= error_output($errors, 'entryform').com_javascript_variables();
177    }
178    else {
179     echo "<pre>\n";
180     echo $newcomment->getError();
181     echo "</pre>\n";
182     die();
183    }
184   }
185   else {
186    if(isset($com_form['cookie']) AND $com_form['cookie'] == 1) set_cookie($com_form);
187    else trash_cookie();
188   
189    include_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'update.php');
190   
191     $sql = "SELECT DISTINCT email
192                            FROM ".JLOG_DB_COMMENTS." WHERE reference = '".$blogentry['id']."' AND mail_by_comment = 1";
193          $comment_mail = new Query($sql);
194   
195     if($comment_mail->error()) {
196      echo "<pre>\n";
197      echo $comment_mail->getError();
198      echo "</pre>\n";
199      die();
200     }
201     elseif( JLOG_INFO_BY_COMMENT ) {
202        // we need this for some mail texts
203        require(JLOG_BASEPATH.'lang'.DIRECTORY_SEPARATOR.'lang-admin.'.JLOG_LANGUAGE.'.inc.php');
204
205        $urlarray = parse_url(JLOG_PATH);
206        $com_form['email'] = empty($com_form['email']) ? "no-reply@".$urlarray['host'] : $com_form['email'];
207        $mail['topic'] = $l['admin']['comments_mailsubject']." - ".$blogentry['topic'];
208        $mail['headers'] = "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n";
209        $mail['headers'] .= "From: ";
210        if(!empty($com_form['name'])) $mail['headers'] .= str_replace(array("\n", "\r"), "", $com_form['name']);
211        else $mail['headers'] .= $l['admin']['comments_anonym'];
212        if(!empty($com_form['email'])) $mail['headers'] .= " <".str_replace(array("\n", "\r"), "", $com_form['email']).">";
213        $mail['headers'] .= "\r\nX-Mailer: PHP/".phpversion();
214
215        $mail['text'] = $l['admin']['comments_mail_txt']." »".$blogentry['topic']."«\n- -\n";
216        if(!empty($com_form['name'])) $mail['text'] .= $com_form['name'];
217        else $mail['text'] .= $l['admin']['comments_anonym'];
218        if(!empty($com_form['city'])) $mail['text'] .= " ".$l['comments_from']." ".$com_form['city'];
219        $mail['text'] .= " ".$l['admin']['comments_posted']." ".$date.":\n\n";
220        $mail['text'] .= html_entity_decode(strip_tags($bbcomments->parse($com_form['content'])));
221        $mail['text'] .= "\n\n".str_replace ( '&amp;', '&', blog($blogentry['date'], $blogentry['url']))."#c".$cid;
222        $mail['text'] .= "\n\n".$l['admin']['kill_c_email']."\n".JLOG_PATH."/admin/comments.php?action=trash&id=".$cid;
223
224        ### Plugin Hook
225        $mail = $plugins->callHook('adminMail', $mail, $blogentry);
226 
227        if(empty($mail['nomail'])) @mail(JLOG_EMAIL, $mail['topic'], $mail['text'], $mail['headers'], "-f".JLOG_EMAIL);
228    }
229
230    $mail['topic'] = $l['comments_mailsubject']." - ".$blogentry['topic'];
231    $mail['headers'] = "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n";
232    $mail['headers'] .= "From: ".JLOG_WEBSITE." <".JLOG_EMAIL.">\r\n"
233                    ."X-Mailer: PHP/".phpversion();
234
235    $mail['all_text'] = $l['comments_mail_txt']." »".$blogentry['topic']."«\n- -\n";
236    if(!empty($com_form['name'])) $mail['all_text'] .= $com_form['name'];
237    else $mail['all_text'] .= $l['comments_anonym'];
238    if(!empty($com_form['city'])) $mail['all_text'] .= " ".$l['comments_from']." ".$com_form['city'];
239    $mail['all_text'] .= " ".$l['comments_posted']." ".$date.":\n\n";
240    $mail['all_text'] .= html_entity_decode(strip_tags($bbcomments->parse($com_form['content'])));
241    $mail['all_text'] .= "\n\n".str_replace ( '&amp;', '&', blog($blogentry['date'], $blogentry['url']))."#c".$cid."";
242    $mail['all_text'] .= "\n-- \n".$l['comments_stop_receiving']."\n";
243    $mail['all_text'] .= JLOG_PATH."/stop.php?id=".$blogentry['id']."&email=";
244
245      while ($data = $comment_mail->fetch()) {
246       if($data['email'] != $com_form['email']) {
247
248                                 $mail['mail_to'] = $data['email'];
249                                         $mail['text'] = $mail['all_text'].$data['email'];
250                                 
251                                         ### Plugin Hook
252                                 $mail = $plugins->callHook('commentorMail', $mail, $blogentry);
253
254           if(empty($mail['nomail'])) @mail($mail['mail_to'], $mail['topic'], $mail['text'], $mail['headers'], "-f".JLOG_EMAIL);
255                                }
256        }
257         }
258   $c['form_content'] .= "<p id='entryform'>".$l['comments_thx']."</p>".com_javascript_variables();
259  }
260 }
261
262// If nothing happens
263 elseif($blogentry['comments'] == 1) {
264  $com_form['name']             = $l['comments_name'];
265  $com_form['city']             = $l['comments_city'];
266  $com_form['email']            = $l['comments_email'];
267  $com_form['homepage']         = $l['comments_homepage'];
268  $com_form['sid']              = new_sid();
269  if(isset($_COOKIE["jlog_userdata"])) {
270        $cookie = unserialize(urldecode($_COOKIE["jlog_userdata"]));
271         if($cookie != "")       $com_form['cookie']    = 1;
272         if($cookie[0] != "") $com_form['name']                 = $cookie[0];
273         if($cookie[1] != "") $com_form['city']                 = $cookie[1];
274         if($cookie[2] != "") $com_form['email']                = $cookie[2];
275         if($cookie[3] != "") $com_form['homepage']     = $cookie[3];
276  }
277  $c['form_content'] .= com_form_output($com_form).com_javascript_variables();
278 }
279 else $c['form_content'] .= "  <p id='entryform'>".$l['comments_closed']."</p>\n".com_javascript_variables();
280
281// get comments and pingbacks
282
283    $comments = new Query($sql_comments);
284     if($comments->error()) {
285        echo "<pre>\n";
286        echo $comments->getError();
287        echo "</pre>\n";
288        die();
289     }
290    $countPingbacks = 0;
291    $countComments = 0;
292    $commentsArray = array();
293    $no_comments = "";
294
295    while($tmp_commentsArray = $comments->fetch()) $commentsArray[] = $tmp_commentsArray;
296    foreach($commentsArray as $tmp_comment) {
297        if($tmp_comment['type'] == 'pingback') ++$countPingbacks;
298        else ++$countComments;
299    }
300
301    if($countPingbacks > 0)  {
302        if($countComments < 1) $no_comments = " class='entryform'";
303        $c['main'] .= "\n <h3 id='pingbacks'".$no_comments.">".$l['pingback_topic']."</h3>\n  <ol id='pingbackslist'>";
304        foreach($commentsArray as $pingback) {
305            if($pingback['type'] == 'pingback') $c['main'] .= "\n   <li><a href='".$pingback['homepage']."'>".$pingback['name']."</a></li>";
306        }
307        $c['main'] .= "\n  </ol>\n";
308    }
309
310 if($countComments < 1) $no_comments = " class='entryform'";
311 $c['main'] .= "\n <h3 id='comments'".$no_comments.">".$l['comments_comment_topic']."</h3>\n";
312
313 if($countComments > 0) {
314    $c['main'] .= "  <ul class='comments' id='commentslist'>";
315
316    $i = 0;
317    foreach($commentsArray as $data) {
318        if($data['type'] !== 'pingback') {
319            ++$i;
320            $data = com_clean_data($data);
321            $c['main'] .= do_comment($data, $i);
322        }
323    }
324
325    $c['main'] .= "\n  </ul>\n";
326  }
327
328 $c['main'] .= $c['form_content'];
329
330require(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'do_template.php');
331echo $body;
332
333// eof
Note: See TracBrowser for help on using the repository browser.