root/tags/1.1.0/log.php

Revision 1707, 11.7 KB (checked in by jeena, 10 months ago)

changed require prepend.inc.php instead setting.inc.php

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