Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 677 lines (616 sloc) 26.712 kb
5372c9c @matzko initial setup
authored
1 <?php
2 /*
3 Plugin Name: Filosofo Comments Preview
2cbd83a @matzko update files to be more current
authored
4 Plugin URI: http://austinmatzko.com/wordpress-plugins/comments-preview/
abc47aa @matzko v.1.0 - beta or final?
authored
5 Description: Filosofo Comments Preview lets you preview WordPress comments before you submit them.
630da6e @matzko let url submit work for https urls
authored
6 Version: 1.6
5372c9c @matzko initial setup
authored
7 Author: Austin Matzko
2cbd83a @matzko update files to be more current
authored
8 Author URI: http://austinmatzko.com/
5372c9c @matzko initial setup
authored
9 */
10
2cbd83a @matzko update files to be more current
authored
11 /* Copyright 2011 Austin Matzko ( email : austin -at- pressedcode -dot- com )
5372c9c @matzko initial setup
authored
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27
7a2db0e @matzko version .6 with popup support
authored
28 class filosofo_cp {
abc47aa @matzko v.1.0 - beta or final?
authored
29 function filosofo_cp() {
30 global $wpdb;
31
32 $this->version = 1.0;
33 $this->preview_comment_id = round($wpdb->get_var("SELECT MAX(comment_ID) FROM $wpdb->comments") + 1000, -3);
34 $this->options_page_id = 'filosofo-comments-preview-page';
35 $this->counter = 0;
36
37 add_action('init', array(&$this,'init'));
38 add_action('activate_' . basename(__FILE__), array(&$this,'activate_plugin'));
39 add_action('admin_menu', array(&$this,'menu'));
309f1cd @matzko v.1.0.1: flush output buffer for comments closed posts
authored
40 add_action('comment_form', create_function('$a','global $filosofo_cp_class; ob_end_flush(); $filosofo_cp_class->flush = false;'));
41 // flush if not already done
42 add_action('wp_footer', create_function('$a','global $filosofo_cp_class; if ( true == $filosofo_cp_class->flush ) { ob_end_flush(); $filosofo_cp_class->flush = false; }'));
05ac4e2 @matzko support threaded comments
authored
43 add_action('wp_head', array(&$this,'header_script'));
abc47aa @matzko v.1.0 - beta or final?
authored
44 if ( ! $this->older_system() )
45 add_filter('comments_array', array(&$this,'add_previewed_comment'));
46 if( isset( $_POST['comment_post_ID'] ) && isset( $_POST['author'] ) ) {
47 $_POST['filosofo_cp_author'] = $_POST['author'];
48 unset( $_POST['author'] );
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
49 }
abc47aa @matzko v.1.0 - beta or final?
authored
50 if( 'ACTIVE' == get_option('filosofo_cp_styling') )
51 add_action('wp_head', array(&$this,'header_style'));
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
52
abc47aa @matzko v.1.0 - beta or final?
authored
53 // add the preview button
309f1cd @matzko v.1.0.1: flush output buffer for comments closed posts
authored
54 add_filter('comments_template', create_function('$a','global $filosofo_cp_class; $filosofo_cp_class->pagekind = "standard"; ob_start(array(&$filosofo_cp_class,"replace_button")); $filosofo_cp_class->flush = true; return $a;'));
55 add_filter('comments_popup_template', create_function('$a','global $filosofo_cp_class; $filosofo_cp_class->pagekind = "popup"; ob_start(array(&$filosofo_cp_class,"replace_button")); $filosofo_cp_class->flush = true; return $a;'));
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
56
57 add_filter('preprocess_comment', array(&$this, 'kill_wp_comments_use'));
cd0a582 @matzko v.76a: cleanup before a bigger change
authored
58 }
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
59
abc47aa @matzko v.1.0 - beta or final?
authored
60 function activate_plugin() {
61 if ( '' == get_option('filosofo_cp_styling') ) {
62 update_option('filosofo_cp_styling','ACTIVE');
63 update_option('filosofo_cp_bgcolor','#FFFF33');
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
64 }
abc47aa @matzko v.1.0 - beta or final?
authored
65 update_option('filosofo_cp_version',$this->version);
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
66 }
05ac4e2 @matzko support threaded comments
authored
67
68 function get_comment_parent_id() {
69 if ( isset( $_REQUEST['comment_parent'] ) ) {
70 return intval($_REQUEST['comment_parent']);
71 } else {
72 return 0;
73 }
74 }
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
75
abc47aa @matzko v.1.0 - beta or final?
authored
76 function is_popup_template() {
77 if ( isset( $_REQUEST['comments_popup'] ) ) return true;
78 else return false;
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
79 }
80
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
81 /*
82 * Prevent direct calls to wp-comments-post.php
83 * (should help reduce spam)
84 */
85 function kill_wp_comments_use($data = null) {
86 if ( false !== stristr($_SERVER['REQUEST_URI'], 'wp-comments-post.php') )
87 wp_die( __('You must submit a comment using the comment form.','filosofo-comments-preview') );
88 return $data;
89 }
90
abc47aa @matzko v.1.0 - beta or final?
authored
91 function using_kubrick() { // a hack to make kubrick preview buttons look good
92 if ( function_exists('kubrick_head') ) return true;
93 else return false;
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
94 }
95
abc47aa @matzko v.1.0 - beta or final?
authored
96 function menu() {
aa051be @matzko v1.0.5--fix admin rights
authored
97 add_options_page(__('Filosofo Comments Preview','filosofo-comments-preview'), __('Comments Preview','filosofo-comments-preview'), 'manage_options', $this->options_page_id, array(&$this,'options_page'));
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
98 }
99
abc47aa @matzko v.1.0 - beta or final?
authored
100 function options_page() {
aa051be @matzko v1.0.5--fix admin rights
authored
101 if ( ! current_user_can('manage_options') ) {
102 return false;
103 }
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
104 if ( isset( $_POST['comments-preview-updated'] ) ) :
aa051be @matzko v1.0.5--fix admin rights
authored
105 $msg = '';
106 // check nonce
107 if ( ! $this->check_nonce($_REQUEST['comments-preview-nonce'], 'filosofo-comments-preview_save_options') ) :
108 $msg = __('Options not saved. Please try again.');
abc47aa @matzko v.1.0 - beta or final?
authored
109 else :
aa051be @matzko v1.0.5--fix admin rights
authored
110 if ( '' == $_POST['bgcolor'] ) :
111 update_option('filosofo_cp_styling','NONE');
112 else :
113 update_option('filosofo_cp_styling','ACTIVE');
114 endif;
115 update_option('filosofo_cp_bgcolor',$_POST['bgcolor']);
116 update_option('filosofo_cp_req_prev', (int) $_POST['force-preview']);
117 $msg = __('Comments Preview options saved.','filosofo-comments-preview');
118 endif;
119 if ( ! empty( $msg ) ) :
120 ?><div id="message" class="updated fade"><p><?php echo $msg ?></p></div><?php
abc47aa @matzko v.1.0 - beta or final?
authored
121 endif;
122 endif;
123 ?>
124 <div class="wrap"><h2><?php _e('Comments Preview','filosofo-comments-preview') ?></h2>
125 <form name="preview_styling" method="post" action="?page=<?php
aa051be @matzko v1.0.5--fix admin rights
authored
126 echo $this->options_page_id ?>">
127 <input type="hidden" name="comments-preview-nonce" id="comments-preview-nonce" value="<?php echo $this->create_nonce('filosofo-comments-preview_save_options') ?>" />
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
128 <input type="hidden" name="comments-preview-updated" id="comments-preview-updated" value="true" />
abc47aa @matzko v.1.0 - beta or final?
authored
129 <fieldset class="options">
130 <legend><?php _e('Automatic Styling','filosofo-comments-preview') ?></legend>
131 <div><div style="background-color: <?php echo get_option('filosofo_cp_bgcolor') ?>; border: 1px solid gray; width: 20px; height: 20px; margin-right: 3px; float: left;" title="<?php _e('This box displays the color for the preview&rsquo;s background.','filosofo-comments-preview') ?>">&nbsp;</div>
132 <p><label <?php
133 if ( 'NONE' === get_option('filosofo_cp_styling') ) echo 'style="color: gray"';
134 ?>>
135 <input type="text" value="<?php echo get_option('filosofo_cp_bgcolor') ?>" size="20" class="code<?php
136 if ( 'NONE' === get_option('filosofo_cp_styling') ) echo ' disabled';
137 ?>" id="bgcolor" name="bgcolor" /> <?php
138 if ( 'ACTIVE' === get_option('filosofo_cp_styling') ) :
139 _e('Set the automatic preview&rsquo;s background color with a <acronym title="Cascading Style Sheets">CSS</acronym> color value. Clear the input field to disable automatic styling.','filosofo-comments-preview');
140 else :
141 _e('Automatic styling is disabled. Enter a <acronym title="Cascading Style Sheets">CSS</acronym> color value to style the preview&rsquo;s background color.','filosofo-comments-preview');
142 endif;
143 ?></label></p></div>
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
144 </fieldset>
145 <fieldset class="options">
146 <legend><?php _e('Preview Options','filosofo-comments-preview') ?></legend>
147 <div><p><label for="force-preview"><?php _e('Require commenters to preview before posting?','filosofo-comments-preview') ?>
148 <input type="checkbox" name="force-preview" id="force-preview" value="1" <?php
149 if ( true == get_option('filosofo_cp_req_prev') ) {
150 echo 'checked="checked"';
151 }
152 ?> />
153 </label></p>
154 </div>
abc47aa @matzko v.1.0 - beta or final?
authored
155 </fieldset>
156 <?php do_action('filosofo-comments-preview_options_form'); ?>
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
157 <p class="submit"><input type="submit" name="Update" value="<?php _e('Update Options &raquo;') ?>" /></p>
abc47aa @matzko v.1.0 - beta or final?
authored
158 </form>
159 </div>
160 <?php
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
161 }
162
abc47aa @matzko v.1.0 - beta or final?
authored
163 function check_query($query) {
164 global $post, $wpdb;
165 $commenter = (array) wp_get_current_commenter();
166 extract($commenter);
167 if ( empty($comment_author) ) :
168 $the_query = "SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date";
169 else :
170 $author_db = $wpdb->escape($comment_author);
171 $email_db = $wpdb->escape($comment_author_email);
172 $the_query = "SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date";
173 endif;
174 $the_query_two = '';
175 if ( $this->is_popup_template() ) :
176 $the_query = "SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date";
177 // messed up query in older version of get_approved_comments()
178 $the_query_two = "SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND comment_approved = '1' ORDER BY comment_date";
179 endif;
180 if ( $query == $the_query ) : return true;
181 elseif ( '' != $the_query_two && $query == $the_query_two ) : return true;
182 else : return false;
183 endif;
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
184 }
185
abc47aa @matzko v.1.0 - beta or final?
authored
186 function add_previewed_comment( $comments = array() , $comment_post_ID = 0 ) {
187 return array_merge( $comments , $this->previewed_comment( $comment_post_ID ) );
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
188 }
7a2db0e @matzko version .6 with popup support
authored
189
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
190 /*
191 * Nonce functions with backwards-compat for old versions of WP
192 */
193
194 function check_nonce($nonce = '', $action = -1) {
195 if ( function_exists('wp_verify_nonce') ) {
196 return wp_verify_nonce($nonce, $action);
197 } else {
198 $user = wp_get_current_user();
199 $uid = (int) $user->id;
200 $i = ceil(time() / 43200);
201
202 //Allow for expanding range, but only do one check if we can
203 $salt = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH;
204 if ( function_exists('hash_hmac') ) {
205 $hash = hash_hmac('md5', $i . $action . $uid, $salt);
206 } else {
207 $hash = md5($i . $action . $uid . $salt);
208 }
209 if( substr($hash, -12, 10) == $nonce || substr($hash, -12, 10) == $nonce )
210 return true;
211 return false;
212 }
213 }
214
215 function create_nonce($action = null) {
216 if ( function_exists('wp_create_nonce') ) {
217 return wp_create_nonce($action);
218 } else {
219 $user = wp_get_current_user();
220 $uid = (int) $user->id;
221 $i = ceil(time() / 43200);
222 $salt = DB_PASSWORD . DB_USER . DB_NAME . DB_HOST . ABSPATH;
223 if ( function_exists('hash_hmac') ) {
224 $hash = hash_hmac('md5', $i . $action . $uid, $salt);
225 } else {
226 $hash = md5($i . $action . $uid . $salt);
227 }
228 return substr($hash, -12, 10);
229 }
230 }
231
05ac4e2 @matzko support threaded comments
authored
232 function header_script() {
233 // scoot the form up underneath the previewed threaded comment, if applicable
234 $parent_id = $this->get_comment_parent_id();
235 if ( $this->preview_submitted() && ! empty( $parent_id ) ) : ?>
236 <script type="text/javascript">
237 // <![CDATA[
238 (function() {
239 var init = function() {
240 try {
241 addComment._premoveForm = function() {
242 var t = this;
243 var respondId = 'respond';
244 var prevID = 'comment-<?php echo $this->preview_comment_id; ?>';
245 var prevComm = t.I(prevID);
5d79c69 @matzko remove reply link bug props steveegg
authored
246 // remove reply link from previewed comment
247 try {
248 var divs = prevComm.getElementsByTagName('div');
249 if ( divs )
250 for( var i = 0; i < divs.length; i++ )
251 if ( 'reply' == divs[i].className )
252 divs[i].parentNode.removeChild(divs[i]);
253 } catch(e) {}
05ac4e2 @matzko support threaded comments
authored
254 var respond = t.I(respondId);
255 t.I('comment_parent').value = <?php echo $parent_id; ?>;
256 prevComm.appendChild(respond);
257 }
258
259 addComment._premoveForm();
260
5d79c69 @matzko remove reply link bug props steveegg
authored
261 } catch(e) {console.log(e)}
05ac4e2 @matzko support threaded comments
authored
262 }
263
264 if (window.addEventListener)
265 window.addEventListener('load', init, false);
266 else if (window.attachEvent)
267 window.attachEvent('onload', function() { return init.apply(window, new Array(window.event));});
268 })();
269 //]]>
270 </script>
271 <?php
272 endif;
273 }
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
274
abc47aa @matzko v.1.0 - beta or final?
authored
275 function header_style() {
276 $template = get_template_directory();
277 if ( $this->preview_submitted() || $this->using_kubrick() ) :
278 ?>
279 <style type="text/css">
280 <?php if ( $this->using_kubrick() ) : ?>
281 #commentform #preview {
282 float:left;
283 margin:0pt;
284 }
285 <?php endif; ?>
286 <?php if ( $this->preview_submitted() ) : ?>
287 #comment-<?php echo $this->preview_comment_id ?> {
288 background-color: <?php echo get_option('filosofo_cp_bgcolor') ?>;
289 }
290 <?php endif; ?>
291 </style>
5372c9c @matzko initial setup
authored
292 <?php
abc47aa @matzko v.1.0 - beta or final?
authored
293 endif;
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
294 }
7a2db0e @matzko version .6 with popup support
authored
295
abc47aa @matzko v.1.0 - beta or final?
authored
296 function previewed_comment( $comment_post_ID = 0 ) {
297 global $fcp_comment_author, $fcp_comment_author_email, $fcp_comment_author_url, $fcp_comment_content, $fcp_comment_post_ID, $fcp_comment_type, $fcp_user_ID;
298 if ( $this->preview_submitted() ) :
299 $preview_header = '<strong id="previewed-comment-header">' . apply_filters('filosofo-comments-preview_previewed_comment_header',__('Previewed comment:','filosofo-comments-preview')) . "</strong>\n\n";
300 $c['comment_ID'] = $this->preview_comment_id;
301 $c['comment_post_ID'] = $fcp_comment_post_ID;
302 $c['comment_author'] = $fcp_comment_author;
303 $c['comment_author_email'] = $fcp_comment_author_email;
304 $c['comment_author_url'] = $fcp_comment_author_url;
305 $c['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
306 $c['comment_date'] = current_time('mysql');
29cffd6 @matzko 1.0.2: fix date
authored
307 $c['comment_date_gmt'] = current_time('mysql',1);
abc47aa @matzko v.1.0 - beta or final?
authored
308 $c['comment_content'] = $fcp_comment_content;
309 $c['comment_karma'] = 0;
310 $c['comment_approved'] = 1;
5d79c69 @matzko remove reply link bug props steveegg
authored
311 $c['comment_agent'] = $_SERVER['HTTP_USER_AGENT'];
abc47aa @matzko v.1.0 - beta or final?
authored
312 $c['comment_type'] = '';
05ac4e2 @matzko support threaded comments
authored
313 $c['comment_parent'] = $this->get_comment_parent_id();
abc47aa @matzko v.1.0 - beta or final?
authored
314 $c['user_id'] = $fcp_user_ID;
5d79c69 @matzko remove reply link bug props steveegg
authored
315 $c['user_ID'] = $fcp_user_ID;
abc47aa @matzko v.1.0 - beta or final?
authored
316 $c['comment_is_preview'] = true;
317 $ca = wp_filter_comment($c); // apply WP pre-save filters
318 foreach ( (array) $ca as $k => $v )
319 $comment->{$k} = stripslashes($v);
320 $comment->comment_content = $preview_header . $comment->comment_content;
321 $comment = apply_filters('filosofo-comments-preview_comment', $comment);
322 return array(0 => $comment);
323 else :
324 return array();
325 endif;
326 }
7a2db0e @matzko version .6 with popup support
authored
327
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
328 function post_submitted() {
329 if (isset($_POST['comment']) && isset($_POST['comment_post_ID'])) {
330 return true;
331 }
332 else return false;
333 }
334
abc47aa @matzko v.1.0 - beta or final?
authored
335 function preview_submitted() {
336 if (isset($_POST['comment']) && isset($_POST['comment_post_ID']) && isset($_POST['preview']))
337 return true;
338 else return false;
cd0a582 @matzko v.76a: cleanup before a bigger change
authored
339 }
5372c9c @matzko initial setup
authored
340
abc47aa @matzko v.1.0 - beta or final?
authored
341 function replace_button($content) {
342 global $id, $raw_comment;
343 if ( 0 < (int) $this->counter ) return $content; // popup calls this twice in older versions of WP
344 $this->counter++;
345 $link = add_query_arg(
346 (( 'popup' == $this->pagekind ) ? array('comments_popup' => $id ) : array()),
347 get_permalink($id)) . '#comment-' . $this->preview_comment_id;
630da6e @matzko let url submit work for https urls
authored
348 $content = str_replace(array( get_bloginfo('wpurl') . '/wp-comments-post.php', get_option('siteurl') . '/wp-comments-post.php', '/wp-comments-post.php'), $link, $content);
ce5a3e2 @matzko enhanced regex accuracy
authored
349 if ( !strpos($content,'id="preview"') && strpos($content,'comment_post_ID')) {
350 // search reversed strings to get last input first
351 $p1 = array('#>/[^>]*("|\')timbus("|\')=eman[^>]*tupni<#i');
352 $p2 = array('#>nottub/<.*>[^>]*("|\')timbus("|\')=epyt[^>]*nottub<#i');
abc47aa @matzko v.1.0 - beta or final?
authored
353 if ( false !== strpos( $content, '<button' )) {
354 add_filter('filosofo-comments-preview_input_array', array(&$this,'use_buttons'));
ce5a3e2 @matzko enhanced regex accuracy
authored
355 $p1 = array_merge( $p1, $p2 );
abc47aa @matzko v.1.0 - beta or final?
authored
356 }
ce5a3e2 @matzko enhanced regex accuracy
authored
357 $content = strrev(preg_replace($p1,strrev($this->submitbuttons()),strrev($content),1));
abc47aa @matzko v.1.0 - beta or final?
authored
358 }
359 if ( $this->preview_submitted() )
360 $content = str_replace('</textarea>',stripslashes($raw_comment) . '</textarea>',$content);
361 return apply_filters('filosofo-comments-preview_form', $content);
cd0a582 @matzko v.76a: cleanup before a bigger change
authored
362 }
363
abc47aa @matzko v.1.0 - beta or final?
authored
364 function use_buttons( $inputs = array() ) { // use buttons instead of inputs for the submit tags
365 foreach ( array( 'preview','submit' ) as $tag ) {
366 $t = $inputs[$tag];
367 $t['element'] = 'button';
368 $t['childnode'] = array( 'text' => $t['attribs']['value'] );
369 unset( $t['attribs']['value'] );
370 $inputs[$tag] = $t;
371 }
372 return $inputs;
cd0a582 @matzko v.76a: cleanup before a bigger change
authored
373 }
5372c9c @matzko initial setup
authored
374
abc47aa @matzko v.1.0 - beta or final?
authored
375 function generate_markup( $nodes = array() ) {
376 $str = '';
377 foreach( $nodes as $id => $dom ) {
378 if ( 'text' == $id ) return (string) $dom;
379 $str .= "<{$dom['element']} id=\"{$id}\" ";
380 foreach ( (array) $dom['attribs'] as $attrib => $value )
381 $str .= "{$attrib}=\"{$value}\" ";
382 if (isset($dom['childnode']))
383 $str .= '>' . $this->generate_markup( $dom['childnode'] ) . "</{$dom['element']}>";
384 else $str .= '/>';
385 }
386 return $str;
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
387 }
7a2db0e @matzko version .6 with popup support
authored
388
abc47aa @matzko v.1.0 - beta or final?
authored
389 function submitbuttons() {
390 global $id;
391 $input_array = array(
392 'preview' => array(
393 'element' => 'input',
394 'attribs' => array(
395 'type' => 'submit',
396 'name' => 'preview',
397 'tabindex' => '5',
398 'value' => apply_filters('filosofo-comments-preview_preview_text',__('Preview','filosofo-comments-preview')),
399 ),
400 ),
401 'submit' => array(
402 'element' => 'input',
403 'attribs' => array(
404 'type' => 'submit',
405 'name' => 'submit',
406 'tabindex' => '6',
407 'style' => 'font-weight: bold',
408 'value' => apply_filters('filosofo-comments-preview_submit_text',__('Post','filosofo-comments-preview')),
409 ),
410 ),
411 );
412 $input_array = apply_filters('filosofo-comments-preview_input_array', $input_array);
413 return $this->generate_markup( $input_array );
414 } //end submitbuttons
415
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
416 /*
417 * Remove the preview button
418 */
419 function lone_prev_button($markup = array()) {
420 if ( isset( $markup['submit'] ) ) {
421 unset($markup['submit']);
422 }
423 return $markup;
424 }
425
426 /*
427 * Add preview nonce
428 */
429 function preview_check($markup = array()) {
430 $markup['preview-check'] = array(
431 'element' => 'input',
432 'attribs' => array(
433 'type' => 'hidden',
434 'name' => 'preview-check',
77e73be @matzko better spam fighting with forced preview
authored
435 'value' => $this->create_nonce('filosofo-comments-preview-check' . $_SERVER['REMOTE_ADDR']),
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
436 ),
437 );
438 return $markup;
439 }
440
abc47aa @matzko v.1.0 - beta or final?
authored
441 function older_system() {
442 if ( ! function_exists('wp_schedule_event') ) return true;
443 else return false;
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
444 }
7a2db0e @matzko version .6 with popup support
authored
445
abc47aa @matzko v.1.0 - beta or final?
authored
446 function init() {
447 global $fcp_comment_author, $fcp_comment_author_email, $fcp_comment_author_url, $fcp_comment_content, $fcp_comment_post_ID, $fcp_comment_type, $fcp_user_ID, $raw_comment, $wpdb;
448 load_plugin_textdomain('filosofo-comments-preview');
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
449
450 $req_prev = (int) get_option('filosofo_cp_req_prev');
451 // if previews are required
452 if ( $req_prev ) {
453 if ( $this->preview_submitted() ) {
454 add_filter('filosofo-comments-preview_input_array', array(&$this, 'preview_check'), 999);
455 } else {
456 add_filter('filosofo-comments-preview_input_array', array(&$this, 'lone_prev_button'), 999);
457 }
458
77e73be @matzko better spam fighting with forced preview
authored
459 if ( ! $this->preview_submitted() && $this->post_submitted() && ! $this->check_nonce($_POST['preview-check'],'filosofo-comments-preview-check' . $_SERVER['REMOTE_ADDR']) ) {
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
460 wp_die( __('You must preview the comment before submitting.','filosofo-comments-preview') );
461 }
462 }
463
abc47aa @matzko v.1.0 - beta or final?
authored
464 //if someone's submitting a comment (both for previewing and direct submit)
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
465 if ($this->post_submitted()) {
466 nocache_headers();
abc47aa @matzko v.1.0 - beta or final?
authored
467 $comment_post_ID = (int) trim($_POST['comment_post_ID']);
468 $status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");
469
470 if ( empty($status->comment_status) ) {
471 do_action('comment_id_not_found', $comment_post_ID);
472 exit;
473 }
474 elseif ( 'closed' == $status->comment_status ) {
475 do_action('comment_closed', $comment_post_ID);
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
476 wp_die( __('Sorry, comments are closed for this item.','filosofo-comments-preview') );
abc47aa @matzko v.1.0 - beta or final?
authored
477 }
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
478 elseif ( in_array($status->post_status, array('draft', 'pending') ) ) {
abc47aa @matzko v.1.0 - beta or final?
authored
479 do_action('comment_on_draft', $comment_post_ID);
480 exit;
481 }
482
5d79c69 @matzko remove reply link bug props steveegg
authored
483 $comment_author = ( ! empty( $_POST['filosofo_cp_author'] ) ) ? trim($_POST['filosofo_cp_author']) : '';
484 $comment_author_email = ( ! empty( $_POST['email'] ) ) ? trim($_POST['email']) : '';
485 $comment_author_url = ( ! empty( $_POST['url'] ) ) ? trim($_POST['url']) : '';
486 $comment_content = ( ! empty( $_POST['comment'] ) ) ? trim($_POST['comment']) : '';
abc47aa @matzko v.1.0 - beta or final?
authored
487
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
488 if ( current_user_can('unfiltered_html') ) {
489 if ( $this->create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {
490 kses_remove_filters(); // start with a clean slate
491 kses_init_filters(); // set up the filters
492 }
493 }
494
abc47aa @matzko v.1.0 - beta or final?
authored
495 // If the user is logged in
496 $user = wp_get_current_user();
497 $user_ID = $user->ID;
498 if ( $user_ID ) :
499 $comment_author = $wpdb->escape($user->display_name);
500 $comment_author_email = $wpdb->escape($user->user_email);
501 $comment_author_url = $wpdb->escape($user->user_url);
502 else :
503 if ( get_option('comment_registration') )
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
504 wp_die( __('Sorry, you must be logged in to post a comment.','filosofo-comments-preview') );
abc47aa @matzko v.1.0 - beta or final?
authored
505 endif;
506 $comment_type = '';
507 if ( get_option('require_name_email') && !$user_ID ) {
508 if ( 6 > strlen($comment_author_email) || '' == $comment_author )
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
509 wp_die( __('Error: please fill the required fields (name, email).','filosofo-comments-preview') );
abc47aa @matzko v.1.0 - beta or final?
authored
510 elseif ( !is_email($comment_author_email))
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
511 wp_die( __('Error: please enter a valid email address.','filosofo-comments-preview') );
abc47aa @matzko v.1.0 - beta or final?
authored
512 }
513 if ( '' == $comment_content )
faa912d @matzko v1.0.3: add forced previews, update comment submitting
authored
514 wp_die( __('Error: please type a comment.','filosofo-comments-preview') );
abc47aa @matzko v.1.0 - beta or final?
authored
515
05ac4e2 @matzko support threaded comments
authored
516 $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
517 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
abc47aa @matzko v.1.0 - beta or final?
authored
518 $fcp_comment_post_ID = $comment_post_ID;
519 $fcp_comment_author = $comment_author;
520 $fcp_comment_author_email = $comment_author_email;
521 $fcp_comment_author_url = $comment_author_url;
522 $fcp_comment_content = $comment_content;
523 $fcp_comment_type = $comment_type;
524 $fcp_user_ID = $user_ID;
525 if ( !$user_ID ) {
526 setcookie('comment_author_' . COOKIEHASH, $fcp_comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
527 setcookie('comment_author_email_' . COOKIEHASH, $fcp_comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
3eedf67 @matzko do not use deprecated clean_url
authored
528 setcookie('comment_author_url_' . COOKIEHASH, $this->clean_url($fcp_comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
abc47aa @matzko v.1.0 - beta or final?
authored
529 }
530 //if someone submits a preview
531 if( $this->preview_submitted() ) :
532 // set cookie server variables for preview
533 $_COOKIE['comment_author_' . COOKIEHASH] = $fcp_comment_author;
534 $_COOKIE['comment_author_email_' . COOKIEHASH] = $fcp_comment_author_email;
535 $_COOKIE['comment_author_url_' . COOKIEHASH] = $fcp_comment_author_url;
536
537 $raw_comment = htmlspecialchars($comment_content);
538 //make logged in users show up in the preview
539 if ( $user_ID ) {
540 $author = $comment_author;
5d79c69 @matzko remove reply link bug props steveegg
authored
541 $email = ( ! empty( $user_email ) ) ? addslashes($user_email) : '';
542 $url = ( ! empty( $user_url ) ) ? addslashes($user_url) : '';
abc47aa @matzko v.1.0 - beta or final?
authored
543 }
544 else {
5d79c69 @matzko remove reply link bug props steveegg
authored
545 $author = ( ! empty( $comment_author ) ) ? $comment_author : '';
546 $email = ( ! empty( $comment_author_email ) ) ? addslashes($comment_author_email) : '';
547 $url = ( ! empty( $comment_author_url ) ) ? addslashes($comment_author_url) : '';
abc47aa @matzko v.1.0 - beta or final?
authored
548 }
549 else :
550 $comment_id = wp_new_comment( $commentdata );
551 $comment = get_comment($comment_id);
552 //send the viewer back to the post with the comment now added
553 $location = ( empty($_POST['redirect_to']) ? get_permalink($comment_post_ID) : $_POST['redirect_to'] ) . '#comment-' . $comment_id;
554 $location = apply_filters('comment_post_redirect', $location, $comment);
555 wp_redirect($location);
556 exit;
557 endif; //end if someone submits a preview
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
558 }
559 }
3eedf67 @matzko do not use deprecated clean_url
authored
560
561 function clean_url( $t = '' )
562 {
563 if ( function_exists('esc_url') )
564 return esc_url( $t );
565 else
566 return clean_url( $t );
567 }
7a2db0e @matzko version .6 with popup support
authored
568 } //end filosofo_cp class
569
570 $filosofo_cp_class = new filosofo_cp();
571
572 //for backwards compatibility
abc47aa @matzko v.1.0 - beta or final?
authored
573 if ( $filosofo_cp_class->older_system() || $filosofo_cp_class->is_popup_template() ) :
574 class filosofo_cp_wpdb extends wpdb {
575 function get_results($query = null, $output = OBJECT) {
576 global $filosofo_cp_class, $id;
577 $this->func_call = "\$db->get_results(\"$query\", $output)";
578 if ( $query )
579 $this->query($query);
580
581 // where the magic hack happens
582 if ( $filosofo_cp_class->check_query( $query ) ) :
583 $this->last_result = $filosofo_cp_class->add_previewed_comment( $this->last_result );
584 endif;
585 // end the magic hack
586
587 // Send back array of objects. Each row is an object
588 if ( $output == OBJECT ) {
589 return $this->last_result;
590 } elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
591 if ( $this->last_result ) {
592 $i = 0;
593 foreach( $this->last_result as $row ) {
594 $new_array[$i] = (array) $row;
595 if ( $output == ARRAY_N ) {
596 $new_array[$i] = array_values($new_array[$i]);
597 }
598 $i++;
599 }
600 return $new_array;
601 } else {
602 return null;
603 }
604 }
605 }
606 }
607 $wpdb =& new filosofo_cp_wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
608
609 // Table names
610 $wpdb->posts = $table_prefix . 'posts';
611 $wpdb->users = $table_prefix . 'users';
612 $wpdb->categories = $table_prefix . 'categories';
613 $wpdb->post2cat = $table_prefix . 'post2cat';
614 $wpdb->comments = $table_prefix . 'comments';
615 $wpdb->links = $table_prefix . 'links';
616 $wpdb->link2cat = $table_prefix . 'link2cat';
617 $wpdb->linkcategories = $table_prefix . 'linkcategories';
618 $wpdb->options = $table_prefix . 'options';
619 $wpdb->postmeta = $table_prefix . 'postmeta';
620 $wpdb->usermeta = $table_prefix . 'usermeta';
621 $wpdb->prefix = $table_prefix;
622
623 endif;
624
625 if(!function_exists('wp_die')) {
626 function wp_die($msg = '') {
627 die($msg);
e604fb6 @matzko version 7.0--improved filtering and guessed templates
authored
628 }
7a2db0e @matzko version .6 with popup support
authored
629 }
630
abc47aa @matzko v.1.0 - beta or final?
authored
631 if(!function_exists('wp_get_current_commenter')) :
632 function wp_get_current_commenter() {
633 $comment_author = '';
634 if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) )
635 $comment_author = $_COOKIE['comment_author_'.COOKIEHASH];
636 $comment_author_email = '';
637 if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) )
638 $comment_author_email = $_COOKIE['comment_author_email_'.COOKIEHASH];
639 $comment_author_url = '';
640 if ( isset($_COOKIE['comment_author_url_'.COOKIEHASH]) )
641 $comment_author_url = $_COOKIE['comment_author_url_'.COOKIEHASH];
642 return compact('comment_author', 'comment_author_email', 'comment_author_url');
5372c9c @matzko initial setup
authored
643 }
644
e318838 @matzko update tested versions
authored
645 // define it here to keep from re-defining this pluggable function for versions after 2.0.4
646 if ( !function_exists('wp_get_current_user') ) {
647 function wp_get_current_user() {
648 global $current_user;
649 get_currentuserinfo();
650 return $current_user;
651 }
5372c9c @matzko initial setup
authored
652 }
e318838 @matzko update tested versions
authored
653
654 endif;
5372c9c @matzko initial setup
authored
655
abc47aa @matzko v.1.0 - beta or final?
authored
656 if(!function_exists('filosofo_cp_submitbuttons')) {
657 function filosofo_cp_submitbuttons($variable) {
658 global $filosofo_cp_class;
659 $filosofo_cp_class->pagekind = $variable;
660 echo $filosofo_cp_class->submitbuttons();
6168ddb @matzko v.76: now a more robust, trimmer button-replacement technique
authored
661 }
5372c9c @matzko initial setup
authored
662 }
abc47aa @matzko v.1.0 - beta or final?
authored
663 //end backwards compatibility
664
665 if(!function_exists('comment_is_preview')) {
666 function comment_is_preview( $id = 0 ) {
667 global $comment, $filosofo_cp_class;
668 $id = (int) $id;
669 if ( ( 0 == $id && isset( $comment->comment_is_preview ) && true == $comment->comment_is_preview ) ||
670 $filosofo_cp_class->preview_comment_id == $id )
671 return true;
672 else return false;
673 }
5372c9c @matzko initial setup
authored
674 }
abc47aa @matzko v.1.0 - beta or final?
authored
675 add_filter('comment_is_preview', 'comment_is_preview');
88f66bf @matzko v0.6.5: fixed template bug; styled to look better in 2.0
authored
676 ?>
Something went wrong with that request. Please try again.