root/tags/1.0.2/log.php

Revision 1624, 11.2 KB (checked in by driehle, 2 years ago)

removed svn:executable bit recursively

Line 
1<?php
2 require('.'.DIRECTORY_SEPARATOR.'personal'.DIRECTORY_SEPARATOR.'settings.inc.php');
3 require(JLOG_BASEPATH.'lang'.DIRECTORY_SEPARATOR.'lang-admin.inc.php');
4
5 $get = strip($_GET);
6 $c['form_content'] = "";
7 $date = strftime(JLOG_DATE);
8
9 $sql_get = escape_for_mysql($get);
10
11        if(!empty($sql_get['y']) AND !empty($sql_get['m']) AND !empty($sql_get['url'])) {
12                $sql = "SELECT
13                                 *,
14                                 UNIX_TIMESTAMP(date) AS date,
15                                 DATE_FORMAT(date, '%Y-%m-%dT%T".substr(date("O"), 0, 3) . ":" . substr(date("O"), 3)."') AS metadate
16                                 FROM ".JLOG_DB_CONTENT."
17                                 WHERE
18                                                YEAR(date)      = ".$sql_get['y']." AND
19                                                MONTH(date)     = ".$sql_get['m']." AND
20                                                url                     = '".$sql_get['url']."' AND
21                                                section         = 'weblog'
22                                  LIMIT 1";
23
24        $blog = new Query($sql);
25        if($blog->error()) {
26                echo "<pre>\n";
27                echo $blog->getError();
28                echo "</pre>\n";
29                die();
30        }
31
32                if($blog->numRows() == 0) {
33                        header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
34                        include_once(JLOG_BASEPATH."error404.php");
35                        exit;
36                }
37        }
38        else {
39                header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
40                include_once(JLOG_BASEPATH."error404.php");
41                exit;
42        }
43
44 $blogentry = $blog->fetch();
45
46// get comments from Database
47
48        $sql_comments = "SELECT
49                                                                *,
50                                                                UNIX_TIMESTAMP(date) AS date
51                                                        FROM ".JLOG_DB_COMMENTS."
52                                                        WHERE reference = '".$blogentry['id']."'
53                                                        ORDER BY date;";
54
55 $c['meta']['date']        = $blogentry['metadate'];
56 $c['meta']['description'] = strip_tags($bbcode->parse($blogentry['teaser']));
57 $c['meta']['keywords']    = $blogentry['keywords'];
58 $c['meta']['title']       = $blogentry['topic'];
59 $c['meta']['pingback']    = true;
60
61 $c['main'] = do_entry($blogentry);
62
63// Form entry
64
65 $com_form = strip($_POST);
66 if(!isset($com_form['type'])) $com_form['type'] = "";
67 $error = com_check_errors($com_form);
68
69// Preview
70 if(isset($com_form['form_submitted']) AND $com_form['form_submitted'] === $l['comments_preview']) {
71
72    $comments = new Query($sql_comments);
73     if($comments->error()) {
74        echo "<pre>\n";
75        echo $comments->getError();
76        echo "</pre>\n";
77        die();
78     }
79
80    $commentsArray = array();
81    $countComments = 0;
82    while($commentsArray[] = $comments->fetch());
83    foreach($commentsArray as $tmp_comment) if($tmp_comment['type'] != 'pingback') ++$countComments;
84
85  $preview = "";
86  if(isset($error)) $preview .= error_output($error);
87  $clear_form = com_clean_data($com_form);
88  $clear_form['id'] = "";
89
90  $preview .= "
91   <ul class='comments' id='preview'>
92    ".do_comment($clear_form, $countComments)."
93   </ul>";
94
95  $c['form_content'] .= $preview;
96  $c['form_content'] .= com_form_output($com_form).com_javascript_variables();
97 }
98
99
100// Send data to DB
101 elseif(isset($com_form['form_submitted']) AND $com_form['form_submitted'] == $l['comments_send'] AND $blogentry['comments'] == 1) {
102  if(isset($error)) {
103
104   $c['form_content'] .= error_output($error);
105   $c['form_content'] .= com_form_output($com_form).com_javascript_variables();
106  }
107  else {
108 // Send comment
109
110   $com_form = com_clean_data($com_form);
111
112   ### Plugin Hook
113   $com_form = $plugins->callHook('newComment', $com_form, $blogentry);
114
115   $com = escape_for_mysql($com_form);
116   if(!isset($com['mail_by_comment'])) $com['mail_by_comment'] = "";
117   
118   $sql = "INSERT INTO ".JLOG_DB_COMMENTS." (
119                        sid,
120                        name,
121                        city,
122                        email,
123                        homepage,
124                        content,
125                        reference,
126                        mail_by_comment,
127                        date,
128                                                                                                type
129                  )
130           VALUES (
131            '".$com['sid']."',
132            '".$com['name']."',
133            '".$com['city']."',
134            '".$com['email']."',
135            '".$com['homepage']."',
136            '".$com['content']."',
137            '".$blogentry['id']."',
138            '".$com['mail_by_comment']."',
139            NOW(),
140                                                '".$com['type']."'
141           )"; 
142
143   $newcomment = new Query($sql);
144   $cid = mysql_insert_id();
145   if($newcomment->error()) {
146    if($newcomment->getErrno() == 1062) {
147          $errors[] = $l['comments_duplicate'];
148     $c['form_content'] .= error_output($errors, 'entryform').com_javascript_variables();
149    }
150    else {
151     echo "<pre>\n";
152     echo $newcomment->getError();
153     echo "</pre>\n";
154     die();
155    }
156   }
157   else {
158    if(isset($com_form['cookie']) AND $com_form['cookie'] == 1) set_cookie($com_form);
159    else trash_cookie();
160   
161    include_once(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'update.php');
162   
163     $sql = "SELECT DISTINCT email
164                            FROM ".JLOG_DB_COMMENTS." WHERE reference = '".$blogentry['id']."' AND mail_by_comment = 1";
165          $comment_mail = new Query($sql);
166   
167     if($comment_mail->error()) {
168      echo "<pre>\n";
169      echo $comment_mail->getError();
170      echo "</pre>\n";
171      die();
172     }
173     else {
174
175             $mail['topic'] = $l['admin']['comments_mailsubject']." - ".$blogentry['topic'];
176       $mail['headers'] = "From: ";
177       if(!empty($com_form['name'])) $mail['headers'] .= str_replace(array("\n", "\r"), "", $com_form['name']);
178       else $mail['headers'] .= $l['admin']['comments_anonym'];
179       if(!empty($com_form['email'])) $mail['headers'] .= " <".str_replace(array("\n", "\r"), "", $com_form['email']).">";
180       $mail['headers'] .= "\r\nX-Mailer: PHP/".phpversion();
181
182       $mail['text'] = $l['admin']['comments_mail_txt']." »".$blogentry['topic'].\n- -\n";
183       if(!empty($com_form['name'])) $mail['text'] .= $com_form['name'];
184       else $mail['text'] .= $l['admin']['comments_anonym'];
185       if(!empty($com_form['city'])) $mail['text'] .= " ".$l['comments_from']." ".$com_form['city'];
186       $mail['text'] .= " ".$l['admin']['comments_posted']." ".$date.":\n\n";
187       $mail['text'] .= html_entity_decode(strip_tags($bbcomments->parse($com_form['content'])));
188       $mail['text'] .= "\n\n".str_replace ( '&amp;', '&', blog($blogentry['date'], $blogentry['url']))."#c".$cid;
189       $mail['text'] .= "\n\n".$l['admin']['kill_c_email']."\n".JLOG_PATH."/admin/comments.php?action=trash&id=".$cid;
190
191                   ### Plugin Hook
192                   $mail = $plugins->callHook('adminMail', $mail, $blogentry);
193                         
194       if(empty($mail['nomail']) and JLOG_INFO_BY_COMMENT) @mail(JLOG_EMAIL, $mail['topic'], $mail['text'], $mail['headers']);
195      }
196
197                        $mail['topic'] = $l['comments_mailsubject']." - ".$blogentry['topic'];
198      $mail['headers'] = "From: ".JLOG_WEBSITE." <".JLOG_EMAIL.">\r\n"
199                        ."X-Mailer: PHP/".phpversion();
200
201      $mail['all_text'] = $l['comments_mail_txt']." »".$blogentry['topic'].\n- -\n";
202      if(!empty($com_form['name'])) $mail['all_text'] .= $com_form['name'];
203      else $mail['all_text'] .= $l['comments_anonym'];
204      if(!empty($com_form['city'])) $mail['all_text'] .= " ".$l['comments_from']." ".$com_form['city'];
205      $mail['all_text'] .= " ".$l['comments_posted']." ".$date.":\n\n";
206      $mail['all_text'] .= html_entity_decode(strip_tags($bbcomments->parse($com_form['content'])));
207      $mail['all_text'] .= "\n\n".str_replace ( '&amp;', '&', blog($blogentry['date'], $blogentry['url']))."#c".$cid."";
208      $mail['all_text'] .= "\n-- \n".$l['comments_stop_receiving']."\n";
209      $mail['all_text'] .= JLOG_PATH."/stop.php?id=".$blogentry['id']."&email=";
210
211      while ($data = $comment_mail->fetch()) {
212       if($data['email'] != $com_form['email']) {
213
214                                 $mail['mail_to'] = $data['email'];
215                                         $mail['text'] = $mail['all_text'].$data['email'];
216                                 
217                                         ### Plugin Hook
218                                 $mail = $plugins->callHook('commentorMail', $mail, $blogentry);
219
220           if(empty($mail['nomail'])) @mail($mail['mail_to'], $mail['topic'], $mail['text'], $mail['headers']);
221                                }
222        }
223         }
224   $c['form_content'] .= "<p id='entryform'>".$l['comments_thx']."</p>".com_javascript_variables();
225  }
226 }
227
228// If nothing happens
229 elseif($blogentry['comments'] == 1) {
230  $com_form['name']             = $l['comments_name'];
231  $com_form['city']             = $l['comments_city'];
232  $com_form['email']            = $l['comments_email'];
233  $com_form['homepage']         = $l['comments_homepage'];
234  $com_form['sid']              = new_sid();
235  if(isset($_COOKIE["jlog_userdata"])) {
236        $cookie = unserialize(urldecode($_COOKIE["jlog_userdata"]));
237         if($cookie != "")       $com_form['cookie']    = 1;
238         if($cookie[0] != "") $com_form['name']                 = $cookie[0];
239         if($cookie[1] != "") $com_form['city']                 = $cookie[1];
240         if($cookie[2] != "") $com_form['email']                = $cookie[2];
241         if($cookie[3] != "") $com_form['homepage']     = $cookie[3];
242  }
243  $c['form_content'] .= com_form_output($com_form).com_javascript_variables();
244 }
245 else $c['form_content'] .= "  <p id='entryform'>".$l['comments_closed']."</p>\n".com_javascript_variables();
246
247// get comments and pingbacks
248
249    $comments = new Query($sql_comments);
250     if($comments->error()) {
251        echo "<pre>\n";
252        echo $comments->getError();
253        echo "</pre>\n";
254        die();
255     }
256    $countPingbacks = 0;
257    $countComments = 0;
258    $commentsArray = array();
259    $no_comments = "";
260
261    while($tmp_commentsArray = $comments->fetch()) $commentsArray[] = $tmp_commentsArray;
262    foreach($commentsArray as $tmp_comment) {
263        if($tmp_comment['type'] == 'pingback') ++$countPingbacks;
264        else ++$countComments;
265    }
266
267    if($countPingbacks > 0)  {
268        if($countComments < 1) $no_comments = " class='entryform'";
269        $c['main'] .= "\n <h3 id='pingbacks'".$no_comments.">".$l['pingback_topic']."</h3>\n  <ol id='pingbackslist'>";
270        foreach($commentsArray as $pingback) {
271            if($pingback['type'] == 'pingback') $c['main'] .= "\n   <li><a href='".$pingback['homepage']."'>".$pingback['name']."</a></li>";
272        }
273        $c['main'] .= "\n  </ol>\n";
274    }
275
276 if($countComments < 1) $no_comments = " class='entryform'";
277 $c['main'] .= "\n <h3 id='comments'".$no_comments.">".$l['comments_comment_topic']."</h3>\n";
278
279 if($countComments > 0) {
280    $c['main'] .= "  <ul class='comments' id='commentslist'>";
281
282    $i = 0;
283    foreach($commentsArray as $data) {
284        if($data['type'] !== 'pingback') {
285            ++$i;
286            $data = com_clean_data($data);
287            $c['main'] .= do_comment($data, $i);
288        }
289    }
290
291    $c['main'] .= "\n  </ul>\n";
292  }
293
294 $c['main'] .= $c['form_content'];
295
296require(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'do_template.php');
297echo $body;
298?>
Note: See TracBrowser for help on using the browser.