/
_item_comment_form.inc.php
374 lines (325 loc) · 14.9 KB
/
_item_comment_form.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
/**
* This is the template that displays the comment form for a post
*
* This file is not meant to be called directly.
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/gnu-gpl-license}
* @copyright (c)2003-2016 by Francois Planque - {@link http://fplanque.com/}
*
* @package evoskins
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
global $cookie_name, $cookie_email, $cookie_url;
global $comment_allowed_tags;
global $comment_cookies, $comment_allow_msgform;
global $checked_attachments; // Set this var as global to use it in the method $Item->can_attach()
global $PageCache;
global $Blog, $dummy_fields;
// Default params:
$params = array_merge( array(
'disp_comment_form' => true,
'form_title_start' => '<h3>',
'form_title_end' => '</h3>',
'form_title_text' => T_('Leave a comment'),
'form_comment_text' => T_('Comment text'),
'form_submit_text' => T_('Send comment'),
'form_params' => array(), // Use to change a structre of form, i.e. fieldstart, fieldend and etc.
'policy_text' => '',
'author_link_text' => 'auto',
'textarea_lines' => 10,
'default_text' => '',
'preview_block_start' => '',
'preview_start' => '<div class="bComment" id="comment_preview">',
'comment_template' => '_item_comment.inc.php', // The template used for displaying individual comments (including preview)
'preview_end' => '</div>',
'preview_block_end' => '',
'before_comment_error' => '<p><em>',
'after_comment_error' => '</em></p>',
'before_comment_form' => '',
'after_comment_form' => '',
), $params );
echo '<div id="textinputwrap">';
$comment_reply_ID = param( 'reply_ID', 'integer', 0 );
$email_is_detected = false; // Used when comment contains an email strings
// Consider comment attachments list empty
$comment_attachments = '';
// Default renderers:
$comment_renderers = array( 'default' );
/*
* Comment form:
*/
$section_title = $params['form_title_start'].$params['form_title_text'].$params['form_title_end'];
if( $params['disp_comment_form'] && $Item->can_comment( $params['before_comment_error'], $params['after_comment_error'], '#', '#', $section_title, $params ) )
{ // We want to display the comments form and the item can be commented on:
echo $params['before_comment_form'];
// INIT/PREVIEW:
if( $Comment = get_comment_from_session( 'preview' ) )
{ // We have a comment to preview
if( $Comment->item_ID == $Item->ID )
{ // display PREVIEW:
// We do not want the current rendered page to be cached!!
if( !empty( $PageCache ) )
{
$PageCache->abort_collect();
}
if( $Comment->email_is_detected )
{ // We set it to define a some styles below
$email_is_detected = true;
}
if( empty( $Comment->in_reply_to_cmt_ID ) )
{ // Display the comment preview here only if this comment is not a reply, otherwise it was already displayed
// ------------------ PREVIEW COMMENT INCLUDED HERE ------------------
skin_include( $params['comment_template'], array(
'Comment' => & $Comment,
'comment_block_start' => $Comment->email_is_detected ? '' : $params['preview_block_start'],
'comment_start' => $Comment->email_is_detected ? $params['comment_error_start'] : $params['preview_start'],
'comment_end' => $Comment->email_is_detected ? $params['comment_error_end'] : $params['preview_end'],
'comment_block_end' => $Comment->email_is_detected ? '' : $params['preview_block_end'],
'author_link_text' => $params['author_link_text'],
) );
// Note: You can customize the default item comment by copying the generic
// /skins/_item_comment.inc.php file into the current skin folder.
// ---------------------- END OF PREVIEW COMMENT ---------------------
}
// Form fields:
$comment_content = $Comment->original_content;
// comment_attachments contains all file IDs that have been attached
$comment_attachments = $Comment->preview_attachments;
// checked_attachments contains all attachment file IDs which checkbox was checked in
$checked_attachments = $Comment->checked_attachments;
// for visitors:
$comment_author = $Comment->author;
$comment_author_email = $Comment->author_email;
$comment_author_url = $Comment->author_url;
// Get what renderer checkboxes were selected on form:
$comment_renderers = explode( '.', $Comment->get( 'renderers' ) );
// Display error messages again after preview of comment
global $Messages;
$Messages->display();
}
}
else
{ // New comment:
if( ( $Comment = get_comment_from_session() ) == NULL )
{ // there is no saved Comment in Session
$Comment = new Comment();
if( ( !empty( $PageCache ) ) && ( $PageCache->is_collecting ) )
{ // This page is going into the cache, we don't want personal data cached!!!
// fp> These fields should be filled out locally with Javascript tapping directly into the cookies. Anyone JS savvy enough to do that?
$comment_author = '';
$comment_author_email = '';
$comment_author_url = '';
}
else
{ // Get params from $_COOKIE
$comment_author = param_cookie( $cookie_name, 'string', '' );
$comment_author_email = utf8_strtolower( param_cookie( $cookie_email, 'string', '' ) );
$comment_author_url = param_cookie( $cookie_url, 'string', '' );
}
if( empty($comment_author_url) )
{ // Even if we have a blank cookie, let's reset this to remind the bozos what it's for
$comment_author_url = 'http://';
}
$comment_content = $params['default_text'];
}
else
{ // set saved Comment attributes from Session
$comment_content = $Comment->content;
$comment_author = $Comment->author;
$comment_author_email = $Comment->author_email;
$comment_author_url = $Comment->author_url;
// comment_attachments contains all file IDs that have been attached
$comment_attachments = $Comment->preview_attachments;
// checked_attachments contains all attachment file IDs which checkbox was checked in
$checked_attachments = $Comment->checked_attachments;
}
}
if( ( !empty( $PageCache ) ) && ( $PageCache->is_collecting ) )
{ // This page is going into the cache, we don't want personal data cached!!!
// fp> These fields should be filled out locally with Javascript tapping directly into the cookies. Anyone JS savvy enough to do that?
}
else
{
// Get values that may have been passed through after a preview
param( 'comment_cookies', 'integer', NULL );
param( 'comment_allow_msgform', 'integer', NULL ); // checkbox
if( is_null($comment_cookies) )
{ // "Remember me" checked, if remembered before:
$comment_cookies = isset($_COOKIE[$cookie_name]) || isset($_COOKIE[$cookie_email]) || isset($_COOKIE[$cookie_url]);
}
}
echo $params['form_title_start'];
echo $params['form_title_text'];
echo $params['form_title_end'];
/*
echo '<script type="text/javascript">
/* <![CDATA[ *
function validateCommentForm(form)
{
if( form.p.value.replace(/^\s+|\s+$/g,"").length == 0 )
{
alert("'.TS_('Please do not send empty comments.').'");
return false;
}
}/* ]]> *
</script>';*/
$Form = new Form( get_htsrv_url().'comment_post.php', 'bComment_form_id_'.$Item->ID, 'post', NULL, 'multipart/form-data' );
$Form->switch_template_parts( $params['form_params'] );
$Form->begin_form( 'bComment', '', array( 'target' => '_self', /*'onsubmit' => 'return validateCommentForm(this);'*/ ) );
// TODO: dh> a plugin hook would be useful here to add something to the top of the Form.
// Actually, the best would be, if the $Form object could be changed by a plugin
// before display!
$Form->add_crumb( 'comment' );
$Form->hidden( 'comment_item_ID', $Item->ID );
if( !empty( $comment_reply_ID ) )
{
$Form->hidden( 'reply_ID', $comment_reply_ID );
// Link to scroll back up to replying comment
echo '<a href="'.url_add_param( $Item->get_permanent_url(), 'reply_ID='.$comment_reply_ID.'&redir=no' ).'#c'.$comment_reply_ID.'" class="comment_reply_current" rel="'.$comment_reply_ID.'">'.T_('You are currently replying to a specific comment').'</a>';
}
$Form->hidden( 'redirect_to',
// Make sure we get back to the right page (on the right domain)
// fp> TODO: check if we can use the permalink instead but we must check that application wide,
// that is to say: check with the comments in a pop-up etc...
// url_rel_to_same_host(regenerate_url( '', '', $Blog->get('blogurl'), '&' ), get_htsrv_url())
// fp> what we need is a regenerate_url that will work in permalinks
// fp> below is a simpler approach:
$Item->get_feedback_url( $disp == 'feedback-popup', '&' )
);
if( check_user_status( 'is_validated' ) )
{ // User is logged in and activated:
$Form->info_field( T_('User'), '<strong>'.$current_User->get_identity_link( array(
'link_text' => $params['author_link_text'] ) ).'</strong> '
.get_user_profile_link( ' [', ']', T_('Edit profile') ) );
}
else
{ // User is not logged in or not activated:
if( is_logged_in() && empty( $comment_author ) && empty( $comment_author_email ) )
{
$comment_author = $current_User->login;
$comment_author_email = $current_User->email;
}
// Note: we use funky field names to defeat the most basic guestbook spam bots
$Form->text( $dummy_fields[ 'name' ], $comment_author, 40, T_('Name'), '', 100, 'bComment' );
$Form->text( $dummy_fields[ 'email' ], $comment_author_email, 40, T_('Email'), '<br />'.T_('Your email address will <strong>not</strong> be revealed on this site.'), 255, 'bComment' );
$Item->load_Blog();
if( $Item->Blog->get_setting( 'allow_anon_url' ) )
{
$Form->text( $dummy_fields[ 'url' ], $comment_author_url, 40, T_('Website'), '<br />'.T_('Your URL will be displayed.'), 255, 'bComment' );
}
}
if( $Item->can_rate() )
{ // Comment rating:
echo $Form->begin_field( NULL, T_('Your vote'), true );
$Comment->rating_input( array( 'item_ID' => $Item->ID ) );
echo $Form->end_field();
}
if( !empty($params['policy_text']) )
{ // We have a policy text to display
$Form->info_field( '', $params['policy_text'] );
}
ob_start();
echo '<div class="comment_toolbars">';
// CALL PLUGINS NOW:
$Plugins->trigger_event( 'DisplayCommentToolbar', array( 'Comment' => & $Comment, 'Item' => & $Item ) );
echo '</div>';
$comment_toolbar = ob_get_clean();
// Message field:
$form_inputstart = $Form->inputstart;
$Form->inputstart .= $comment_toolbar;
$note = '';
// $note = T_('Allowed XHTML tags').': '.htmlspecialchars(str_replace( '><',', ', $comment_allowed_tags));
$textarea_params = array(
'note' => $note,
'cols' => 38,
'class' => 'bComment autocomplete_usernames',
'display_fix_pixel' => false,
);
if( !empty( $comment_toolbar ) )
{
$textarea_params['style'] = 'border-radius: 0 0 8px 8px;';
}
$Form->textarea_input( $dummy_fields[ 'content' ], $comment_content, $params['textarea_lines'], $params['form_comment_text'], $textarea_params );
$Form->inputstart = $form_inputstart;
// set b2evoCanvas for plugins
echo '<script type="text/javascript">var b2evoCanvas = document.getElementById( "'.$dummy_fields[ 'content' ].'" );</script>';
// Attach files:
if( !empty( $comment_attachments ) )
{ // display already attached files checkboxes
$FileCache = & get_FileCache();
$attachments = explode( ',', $comment_attachments );
$final_attachments = explode( ',', $checked_attachments );
// create attachments checklist
$list_options = array();
foreach( $attachments as $attachment_ID )
{
$attachment_File = $FileCache->get_by_ID( $attachment_ID, false );
if( $attachment_File )
{
// checkbox should be checked only if the corresponding file id is in the final attachments array
$checked = in_array( $attachment_ID, $final_attachments );
$list_options[] = array( 'preview_attachment'.$attachment_ID, 1, '', $checked, false, $attachment_File->get( 'name' ) );
}
}
if( !empty( $list_options ) )
{ // display list
$Form->checklist( $list_options, 'comment_attachments', T_( 'Attached files' ) );
}
// memorize all attachments ids
$Form->hidden( 'preview_attachments', $comment_attachments );
}
if( $Item->can_attach() )
{ // Display attach file input field
$Form->input_field( array( 'label' => T_('Attach files'), 'note' => '<br />'.get_upload_restriction(), 'name' => 'uploadfile[]', 'type' => 'file', 'size' => '30' ) );
}
$comment_options = array();
if( ! is_logged_in( false ) )
{ // User is not logged in:
$comment_options[] = '<label><input type="checkbox" class="checkbox" name="comment_cookies" tabindex="7"'
.( $comment_cookies ? ' checked="checked"' : '' ).' value="1" /> '.T_('Remember me').'</label>'
.' <span class="note">('.T_('For my next comment on this site').')</span>';
// TODO: If we got info from cookies, Add a link called "Forget me now!" (without posting a comment).
$msgform_class_start = '';
$msgform_class_end = '';
if( $email_is_detected )
{ // Set a class when comment contains a email
$msgform_class_start = '<div class="comment_recommended_option">';
$msgform_class_end = '</div>';
}
$comment_options[] = $msgform_class_start.
'<label><input type="checkbox" class="checkbox" name="comment_allow_msgform" tabindex="8"'
.( $comment_allow_msgform ? ' checked="checked"' : '' ).' value="1" /> '.T_('Allow message form').'</label>'
.' <span class="note">('.T_('Allow users to contact me through a message form -- Your email will <strong>not</strong> be revealed!').')</span>'.
$msgform_class_end;
// TODO: If we have an email in a cookie, Add links called "Add a contact icon to all my previous comments" and "Remove contact icon from all my previous comments".
}
// Display renderers
$comment_renderer_checkboxes = $Plugins->get_renderer_checkboxes( $comment_renderers, array( 'Blog' => & $Blog, 'setting_name' => 'coll_apply_comment_rendering' ) );
if( !empty( $comment_renderer_checkboxes ) )
{
$Form->begin_fieldset();
echo '<div class="label">'.T_('Text Renderers').':</div>';
echo '<div class="input">';
echo $comment_renderer_checkboxes;
echo '</div>';
$Form->end_fieldset();
}
$Plugins->trigger_event( 'DisplayCommentFormFieldset', array( 'Form' => & $Form, 'Item' => & $Item ) );
$Form->begin_fieldset();
echo '<div class="input">';
$preview_text = ( $Item->can_attach() ) ? T_('Preview/Add file') : T_('Preview');
$Form->button_input( array( 'name' => 'submit_comment_post_'.$Item->ID.'[preview]', 'class' => 'preview btn-info', 'value' => $preview_text, 'tabindex' => 9 ) );
$Form->button_input( array( 'name' => 'submit_comment_post_'.$Item->ID.'[save]', 'class' => 'submit SaveButton', 'value' => $params['form_submit_text'], 'tabindex' => 10 ) );
$Plugins->trigger_event( 'DisplayCommentFormButton', array( 'Form' => & $Form, 'Item' => & $Item ) );
echo '</div>';
$Form->end_fieldset();
?>
<div class="clear"></div>
<?php
$Form->end_form();
echo $params['after_comment_form'];
echo_comment_reply_js( $Item );
}
?>