~edb/quam-plures/item_show_attachments

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
<?php
/**
 * "item comment form" sub-template

Need help doing something with this file?
http://docs.quamplures.net/li_templates.html - tutorials and autodocs

 * This is meant to be included via a .main.php (or other .inc.php) file
 *
 * Quam Plures - {@link http://quamplures.net/}
 * Released under GNU GPL License - {@link http://quamplures.net/license.html}
 * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
 * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
 * @package templates
 * @subpackage generics
 */
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

global $cookie_name, $cookie_email, $cookie_url;
global $comment_allowed_tags, $comments_use_autobr;
global $comment_cookies, $comment_allow_msgform;
global $PageCache;

// set some default params...
$params = array_merge( array(
	'disp_comment_form' => true,
	'form_title_start' => '<h3>',
	'form_title_end' => '</h3>',
	'policy_text' => '',
	'textarea_lines' => 10,
	'default_text' => '',
	'preview_start' => '<div class="bComment" id="comment_preview">',
	'comment_template' => '_item_comment.inc.php',
	'preview_end' => '</div>',
), $params );

/**
 * Comment form:
 */
if( $params['disp_comment_form'] && $Item->can_comment() )
{ // We want to display the comments form and the item can be commented on:

	// INIT/PREVIEW:
	if( $Comment = $Session->get('core.preview_Comment') )
	{ // 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!!
			$PageCache->abort_collect();

			// --- --- --- --- --- --- --- --- --- --- ---
			// --- A SINGLE COMMENT PREVIEWED HERE ---
			template_include( $params['comment_template'], array(
				'Comment' => & $Comment,
				'comment_start' => $params['preview_start'],
				'comment_end' => $params['preview_end'],
			) );

			// Form fields:
			$comment_content = $Comment->original_content;
			// for visitors:
			$comment_author = $Comment->author;
			$comment_author_email = $Comment->author_email;
			$comment_author_url = $Comment->author_url;
		}

		// delete any preview comment from session data:
		$Session->delete( 'core.preview_Comment' );
	}
	else
	{ // New comment:
		$Comment = new Comment();
		if( $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
		{
			$comment_author = isset($_COOKIE[$cookie_name]) ? trim($_COOKIE[$cookie_name]) : '';
			$comment_author_email = isset($_COOKIE[$cookie_email]) ? trim($_COOKIE[$cookie_email]) : '';
			$comment_author_url = isset($_COOKIE[$cookie_url]) ? trim($_COOKIE[$cookie_url]) : '';
		}
		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'];
	}

	if( $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 T_('Leave a comment');
	echo $params['form_title_end'];


	$Form = new Form( $srvc_url.'comment_post.php', 'bComment_form_id_'.$Item->ID, 'post' );
	$Form->begin_form( 'bComment', '', array( 'target' => '_self' ) );

	/**
	 * @todo (legacy): 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->hidden( 'comment_post_ID', $Item->ID );
	$Form->hidden( 'redirect_to',
		// Make sure we get back to the right page (on the right domain)
		/**
		 * @todo (legacy): fp> 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'), '&' ), $srvc_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( is_logged_in() )
	{ // User is logged in:
		$Form->info_field( T_('User'), '<strong>'.$current_User->get_preferred_name().'</strong>'
			.' '.get_user_profile_link( ' [', ']', T_('Edit profile') ) );
	}
	else
	{ // User is not logged in:
		// Note: we use funky field names to defeat the most basic guestbook spam bots
		$Form->text( 'u', $comment_author, 40, T_('Name'), '', 100, 'bComment' );
		$Form->text( 'i', $comment_author_email, 40, T_('Email'), '<br />'.T_('Your email address will <strong>not</strong> be revealed on this site.'), 100, 'bComment' );
		$Form->text( 'o', $comment_author_url, 40, T_('Website'), '<br />'.T_('Your URL will be displayed.'), 100, 'bComment' );
	}

	if( $Item->can_rate() )
	{ // Comment rating:
		echo $Form->begin_field( NULL, T_('Your vote'), true );
		// display options to rate a comment
		$Comment->rating_input( array() );
		echo $Form->end_field();
	}

	if( !empty($params['policy_text']) )
	{ // We have a policy text to display
		$Form->info_field( '', $params['policy_text'] );
	}

	echo '<div class="comment_toolbars">';
	// CALL PLUGINS NOW:
	$Plugins->trigger_event( 'DisplayCommentToolbar', array() );
	echo '</div>';

	// Message field:
	$note = '';
	// $note = T_('Allowed XHTML tags').': '.htmlspecialchars(str_replace( '><',', ', $comment_allowed_tags));
	$Form->textarea( 'p', $comment_content, $params['textarea_lines'], T_('Comment text'), $note, 40, 'bComment' );

	// set app_Canvas for plugins
	echo '<script type="text/javascript">var app_Canvas = document.getElementById( "p" );</script>';

	$comment_options = array();

	if( substr($comments_use_autobr,0,4) == 'opt-')
	{
		$comment_options[] = '<label><input type="checkbox" class="checkbox" name="comment_autobr" tabindex="6"'
			.( ($comments_use_autobr == 'opt-out') ? ' checked="checked"' : '' )
			.' value="1" /> '.T_('Auto-BR').'</label>'
			.' <span class="note">('.T_('Line breaks become &lt;br /&gt;').')</span>';
	}

	if( ! is_logged_in() )
	{ // 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_('Name, email &amp; website').')</span>';
		/**
		 * @todo (legacy): If we got info from cookies, Add a link called "Forget me now!" (without posting a comment).
		 */

		$comment_options[] = '<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 you through a message form (your email will <strong>not</strong> be revealed.').')</span>';
		/**
		 * @todo (legacy): 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".
		 */
	}

	if( ! empty($comment_options) )
	{
		echo $Form->begin_field( NULL, T_('Options'), true );
		echo implode( '<br />', $comment_options );
		echo $Form->end_field();
	}

	$Plugins->trigger_event( 'DisplayCommentFormFieldset', array( 'Form' => & $Form, 'Item' => & $Item ) );

	$Form->begin_fieldset();
	echo '<div class="input">';
	$Form->button_input( array(
		'name' => 'submit_comment_post_'.$Item->ID.'[save]',
		'class' => 'submit',
		'value' => T_('Send comment'),
		'tabindex' => 10,
	) );
	$Form->button_input( array(
		'name' => 'submit_comment_post_'.$Item->ID.'[preview]',
		'class' => 'preview',
		'value' => T_('Preview'),
		'tabindex' => 9,
	) );
	$Plugins->trigger_event( 'DisplayCommentFormButton', array( 'Form' => & $Form, 'Item' => & $Item ) );
	echo '</div>';
	$Form->end_fieldset();
	?>

	<div class="clear"></div>

	<?php
	$Form->end_form();
}

?>