root/trunk/scripts/comments.php

Revision 1731, 5.9 KB (checked in by jeena, 6 months ago)

Jlog does not need cookies to work in the admincenter anymore

Line 
1<?php
2
3 function com_form_output($com_form) {
4 $com_form = array_htmlspecialchars($com_form);
5 global $l, $plugins;
6 if(!isset($com_form['content'])) $com_form['content'] = "";
7
8  $output = "
9   <form method='post' action='#entryform' id='entryform'>
10    <fieldset><legend>".$l['comments_entryform']."</legend>
11    <p class='xmp'>
12     <span>".$l['comments_bbcode']."
13      <a onclick=\"jlog_learnbb('".JLOG_PATH."'); return false;\" href='".JLOG_PATH."/learn_bb.php'>BBcode</a>?
14     </span>
15     <br id='bbcode' />
16     <textarea rows='8' cols='30' name='content'>".$com_form['content']."</textarea>
17    </p>
18    <p>
19     <input class='userdata' type='text' name='name' value='".$com_form['name']."'
20      onfocus=\"if(this.value &amp;&amp; this.value=='".$l['comments_name']."')this.value=''\"
21      onblur=\"if(this.value=='') this.value='".$l['comments_name']."'\" />
22     <input class='userdata' type='text' name='city' value='".$com_form['city']."'
23      onfocus=\"if(this.value &amp;&amp; this.value=='".$l['comments_city']."')this.value=''\"
24      onblur=\"if(this.value=='') this.value='".$l['comments_city']."'\" /><br />
25     <input class='userdata' type='text' name='email' value='".$com_form['email']."'
26      onfocus=\"if(this.value &amp;&amp; this.value=='".$l['comments_email']."')this.value=''\"
27      onblur=\"if(this.value=='') this.value='".$l['comments_email']."'\" />
28     <input class='userdata' type='text' name='homepage' value='".$com_form['homepage']."' />
29    </p>
30    <p class='checkbox'>
31     <input type='checkbox' id='mail_by_comment' name='mail_by_comment' ";
32    if(isset($com_form['mail_by_comment']) AND $com_form['mail_by_comment'] == 1) $output .= "checked='checked'";
33  $output .= " value='1' /> <label for='mail_by_comment'>".$l['comments_mail_by_comment']."</label>&nbsp;";
34    if(defined('JLOG_ADMIN')) $output .= "\n     <input type='hidden' value='".$com_form['id']."' name='id' />\n";
35    else {
36        $output .= "   <input type='checkbox' id='cookie' name='cookie' ";
37        if(isset($com_form['cookie']) AND $com_form['cookie'] == 1) $output .= "checked='checked'";
38        $output .= " value='1' /> <label for='cookie'>".$l['comments_save_data']."</label>\n";
39    }
40  $output .= "     <input type='hidden' value='".$com_form['sid']."' name='sid' />
41    </p>
42    <p>
43     <input class='send' type='submit' name='form_submitted' value='".$l['comments_preview']."' onclick=\"this.form.action = '#preview'\" />
44     <input class='send' type='submit' name='form_submitted' value='".$l['comments_send']."' />";
45
46  if(defined("JLOG_ADMIN")) $output .= add_session_id_input_tag();
47
48  $output .= "
49    </p>
50    </fieldset>
51   </form>\n
52   ";
53
54   ### Plugin Hook
55   $output = $plugins->callHook('commentForm', $output, $com_form);
56
57  return $output;
58 }
59
60 function com_javascript_variables() {
61 global $l;
62    return "
63   <script type='text/javascript'>
64    jlog_l_comments_show = '".$l['comments_show']."';
65    jlog_l_comments_hide = '".$l['comments_hide']."';
66    jlog_l_comments_bold = '".$l['comments_bold']."';
67    jlog_l_comments_italic = '".$l['comments_italic']."';
68    jlog_l_comments_quote = '".$l['comments_quote']."';
69    jlog_l_comments_url = '".$l['comments_url']."';
70    jlog_l_comments_plz_format_txt = '".$l['comments_plz_format_txt']."';
71    jlog_l_comments_url_href = '".$l['comments_url_href']."';
72    jlog_l_comments_url_node = '".$l['comments_url_node']."';
73   </script>
74   "; 
75 }
76 
77 function com_check_errors($com_form) {
78  global $l;
79   if(empty($com_form['sid'])) $errors[] = $l['comments_no_sid'];
80   if(isset($com_form['email']) AND $com_form['email'] != "" AND !preg_match("/^[^@]+@.+\.\D{2,6}$/", $com_form['email']) AND $com_form['email'] != $l['comments_email']) $errors[] = $l['comments_false_mail'];
81   if(empty($com_form['content'])) $errors[] = $l['comments_notext'];
82  if(isset($errors)) return $errors;
83 }
84
85 function com_clean_data($data) {
86  global $l;
87   if(empty($data['name']) OR $data['name'] == $l['comments_name']) $data['name'] = "";
88   if(empty($data['city']) OR $data['city'] == $l['comments_city']) $data['city'] = "";
89   if(empty($data['email']) OR $data['email'] == $l['comments_email']) $data['email'] = "";
90   if(empty($data['homepage']) OR $data['homepage'] == $l['comments_homepage']) $data['homepage'] = "";
91
92   if(empty($data['date'])) $data['date'] = time();
93
94  return $data;
95 }
96
97 function set_cookie($data) {
98  $userdaten = array( $data['name'],
99                             $data['city'],
100                             $data['email'],
101                             $data['homepage'] );
102  $cookielife = time() + 42 * 24 * 60 * 60;
103  $path = parse_url(JLOG_PATH);
104  if(!isset($path['path'])) $path['path'] = "";
105  setcookie("jlog_userdata", urlencode(serialize($userdaten)), $cookielife, $path['path']."/");
106 }
107
108 function trash_cookie() {
109  $cookielife = time() - 3600;
110  setcookie("jlog_userdata", '', $cookielife, "/");
111 }
112
113 function new_sid() {
114     list($usec, $sec) = explode(' ', microtime());
115     mt_srand((float) $sec + ((float) $usec * 100000));
116     return $_SERVER["REMOTE_ADDR"]."-".time()."-".mt_rand(1000,9999);
117 }
118 
119 // Funcitons
120 
121 function do_comment($data, $nr) {
122 global $l, $bbcomments, $plugins;
123
124    $meta = array_htmlspecialchars($data);
125    $comment = "
126  <li id='c".$data['id']."'>
127   <p class='meta'><a class='permalink' title='".$l['comments_permalink']."' href='#c".$data['id']."'>".$nr."</a> <cite>";
128   if(!empty($meta['homepage'])) $comment .= "<a title='".$meta['homepage']."' href='".$meta['homepage']."'>";
129   if(!empty($meta['name'])) $comment .= $meta['name'];
130   else $comment .= $l['comments_anonym'];
131   if(!empty($meta['homepage'])) $comment .= "</a>";
132   $comment .= "</cite>";
133   if(!empty($meta['city'])) $comment .= " ".$l['comments_from']." ".$meta['city'];
134   $comment .= " ".$l['comments_posted']." ".strftime(JLOG_DATE_COMMENT, $data['date']).":</p>\n".$bbcomments->parse($data['content'])."</li>";
135
136   ### Plugin Hook
137         $comment = $plugins->callHook('showComment', $comment, $data, $nr);
138
139 return $comment;
140 }
141?>
Note: See TracBrowser for help on using the browser.