source: branches/1.1/log.php @ 1802

Revision 1802, 11.1 KB checked in by driehle, 3 years ago (diff)

Solved #223

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