root/afridex/plugins/get-recent-comments 2/get-recent-comments.php @ 23

Revision 21, 72.0 kB (checked in by admin, 18 years ago)
Line 
1<?php
2/*
3Plugin Name: Get Recent Comments
4Version: 2.0.2
5Plugin URI: http://blog.jodies.de/archiv/2004/11/13/recent-comments/
6Author: Krischan Jodies
7Author URI: http://blog.jodies.de
8Description: Display the most recent comments or trackbacks with your own formatting in the sidebar. Visit <a href="options-general.php?page=get-recent-comments.php">Options/Recent Comments</a> after activation of the plugin.
9
10
11
12*/
13
14if ( function_exists("is_plugin_page") && is_plugin_page() ) {
15        kjgrc_options_page(); 
16        return;
17}
18
19function kjgrc_subpage_misc()
20{
21?>
22<h2><?php _e('Miscellaneous Options') ?></h2>
23<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=6&amp;updated=true">
24<input type="hidden" name="function" value="misc">
25<?php wp_nonce_field('update-options') ?>
26
27<p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;') ?>" /></p>
28
29<fieldset class="options"> 
30<legend><?php _e('Smileys') ?></legend>
31<?php
32$converter = "WordPress";
33if (function_exists("csm_convert") ) {
34?>
35The Custom Smileys plugin is active.
36<?php $converter = "Custom Smileys";
37} else { ?>
38WordPress offers conversion of emoticons like :-) and :-P to graphics on display. At the moment WordPress is set to: <a href="options-writing.php"><?php if (get_settings('use_smilies')) echo 'convert to graphics'; else echo 'don\'t convert to graphics'; ?></a>.
39<?php
40}
41?>
42
43<table class="optiontable"> 
44
45<th scope="row"><?php _e('The plugin should:') ?> </th>
46<td>
47<label><input type="radio" name="convert_smileys" value="1" <?php if (kjgrc_get_option("misc","convert_smileys") == 1) echo 'checked="checked"' ?>> do it like <?php echo $converter ?>.</label>
48<br>
49<label><input type="radio" name="convert_smileys" value="0" <?php if (kjgrc_get_option("misc","convert_smileys") == 0) echo 'checked="checked"' ?>> never convert emoticons to graphics (even if <?php echo $converter ?> does it elsewhere).</label>
50</td>
51
52</tr>
53</table>
54</fieldset>
55
56<fieldset class="options"> 
57<legend><?php _e('Cache') ?></legend>
58If there are no new comments, the plugin fetches the output from the cache,
59instead of querying the database. If you want the plugin to ask the database
60every time, a web page is generated, you can disable this feature.
61
62<table class="optiontable"> 
63
64<th scope="row"><?php _e('The plugin should:') ?> </th>
65<td>
66<label><input type="checkbox" name="use_cache_checkbox" <?php if (kjgrc_use_cache()) echo 'checked="checked"'?>> cache the output (recommended).</label>
67</td>
68
69</tr>
70</table>
71</fieldset>
72
73<p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options &raquo;') ?>" />
74<input type="hidden" name="action" value="update" /> 
75<input type="hidden" name="page_options" value="blogname,blogdescription,siteurl,admin_email,users_can_register,gmt_offset,date_format,time_format,home,start_of_week,comment_registration,default_role" /> 
76</p>
77</form>
78
79</div>
80<?php
81}
82
83function kjgrc_subpage_gravatar() 
84{
85        $gravatar_checked[0] = '';
86        $gravatar_checked[1] = '';
87        $gravatar_checked[2] = '';
88        $gravatar_checked[3] = '';
89        $gravatar_checked[kjgrc_get_option('gravatar','rating')] = "checked=\"checked\" ";
90       
91?>
92<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=5&amp;updated=true">
93<input type="hidden" name="function" value="gravatar">
94
95<h2>Settings for %gravatar</h2>
96<fieldset class="options">
97<table width="100%" cellspacing="2" cellpadding="5" class="editform">
98<tr valign="top">
99<th width="33%" scope="row"><?php _e('Size of Gravatars:') ?></th>
100<td nowrap><input name="gravatar_size" type="text" value="<?php echo kjgrc_get_option("gravatar","size"); ?>" size="3" /> <?php _e('Pixel') ?><br />
101Valid values are between 1 and 80 pixels.
102</td>
103</tr>
104<tr valign="top"> 
105        <th scope="row">Alternative URL:</th>
106        <td><input name="gravatar_alt_url" type="text" style="width: 95%" value="<?php echo kjgrc_get_option("gravatar","alt_url"); ?>" size="45" />
107        <br />
108This is an <strong>optional</strong> image that will be displayed if no gravatar is found. Enter the full URL (with http://). If left empty, gravatar.com returns a transparent pixel.</td>
109</tr>
110<tr>
111        <th scope="row">Display gravatars up to this rating:</th>
112        <td> <label for="gravatar_rating0"><input name="gravatar_rating" id="gravatar_rating0" type="radio" value="0" <?php echo $gravatar_checked[0]; ?>/> G (All audiences)</label><br />
113<label for="gravatar_rating1"><input name="gravatar_rating" id="gravatar_rating1" type="radio" value="1" <?php echo $gravatar_checked[1]; ?>/> PG</label><br />
114<label for="gravatar_rating2"><input name="gravatar_rating" id="gravatar_rating2" type="radio" value="2" <?php echo $gravatar_checked[2]; ?>/> R</label><br />
115<label for="gravatar_rating3"><input name="gravatar_rating" id="gravatar_rating3" type="radio" value="3" <?php echo $gravatar_checked[3]; ?>/> X</label></td>
116</tr>
117
118</table>
119
120<p class="submit">
121<input type="submit" name="Submit" value="<?php _e('Update Options') ?> &raquo;" />
122</p>
123</form>
124<?php
125} // kjgrc_subpage_gravatar
126
127function kjgrc_subpage_exclude_cat() 
128{
129        global $wpdb;
130        if (function_exists("get_categories")) {
131                $categories = get_categories('&hide_empty=0');
132        } else {
133                // be still compatible to 2.0.11
134                $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");
135        }
136        $exclude_cat = kjgrc_get_exclude_cat();
137?>
138<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=4&amp;updated=true">
139
140<input type="hidden" name="function" value="exclude_cat">
141<h2>Categories</h2>
142<label><input type="radio" name="exclude_categories_reverse" value="1" <?php if (kjgrc_get_option("misc","exclude_cat_reverse") == 1) echo 'checked="checked"' ?>>Show only comments to articles of the following categories:</label>
143<br>
144<label><input type="radio" name="exclude_categories_reverse" value="0" <?php if (kjgrc_get_option("misc","exclude_cat_reverse") == 0) echo 'checked="checked"' ?>>Show no comments to articles of the following categories:</label>
145<p>
146
147<?php
148
149        if ($categories) {
150                foreach ($categories as $category) {
151                        $checked = '';
152                        if ($exclude_cat && in_array($category->cat_ID,$exclude_cat)) {
153                                $checked = 'checked="checked" ';
154                        }
155                        echo "<label for=\"\">\n";
156                        echo "<input name=\"exclude_category[]\" type=\"checkbox\" value=\"$category->cat_ID\" $checked/>";
157                        echo " $category->cat_name</label><br />\n";
158                }
159        }
160?>
161<p class="submit">
162<input type="submit" name="Submit" value="<?php _e('Update Options') ?> &raquo;" />
163</p>
164</form>
165<?php
166} // kjgrc_subpage_exclude_cat
167
168function kjgrc_subpage_grc() 
169{
170?>
171<script type="text/javascript">
172<!--
173function toggle_grouped_titles()
174{
175        if (document.get_recent_comments_form.grouped_by_post_checkbox.checked == false) {
176                document.getElementById('grouped_by_post_cell_a').style.display = "none";
177                document.getElementById('grouped_by_post_cell_b').style.display = "none";
178        } else {
179                document.getElementById('grouped_by_post_cell_a').style.display = "";
180                document.getElementById('grouped_by_post_cell_b').style.display = "";
181        }
182}
183function toggle_exclude_blog_owner2()
184{
185        if (document.get_recent_comments_form.grc_exclude_blog_owner_checkbox.checked == false) {
186                document.getElementById('grc_exclude_blog_owner_checkbox2').style.display = "none";
187        } else {
188                document.getElementById('grc_exclude_blog_owner_checkbox2').style.display = "";
189        }
190}
191-->
192</script>
193
194<form name="get_recent_comments_form" method=post action="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;updated=true">
195<input type="hidden" name="function" value="grc">
196<h2><?php _e('Recent Comments') ?></h2>
197<fieldset class="options"> 
198<table width="100%" cellspacing="2" cellpadding="5" class="editform">
199<tr valign="top">
200<th width="33%" scope="row"><?php _e('Show the most recent:') ?></th>
201<td><input name="max_comments" type="text" id="max_comments" value="<?php echo kjgrc_get_option("grc","max_comments"); ?>" size="3" /> <?php _e('comments') ?></td>
202<td rowspan="6"><pre><div style='font-size: 10px; border-left: 1px solid; margin: 0px;'> %comment_excerpt - Shortened comment.
203 %comment_link    - Link to the comment.
204 %comment_author  - Name left by the commenter
205 %comment_date    - Date of comment
206 %comment_time    - Time of comment
207 %comment_type    - Comment, Trackback or Pingback
208 %time_since      - Time since comment was posted
209 %userid          - UserID of the commenter
210 %gravatar        - Gravatar of the commenter, full img tag
211 %gravatar_url    - Gravatar of the commenter, only url
212 %profile_picture - URL of profile picture
213 %author_url      - URL of author or trackback
214 %author_url_href - href="%author_url" or empty
215 %post_title      - Title of the posting
216 %post_link       - Link to the posting
217 %post_date       - Date of the posting
218 %post_counter    - Number of comments to this post</pre></div></td>
219</tr>
220<tr valign="top">
221<th width="33%" scope="row"><?php _e('Long comments are chopped off at:') ?></th>
222<td nowrap><input name="chars_per_comment" type="text" id="chars_per_comment" value="<?php echo kjgrc_get_option("grc","chars_per_comment"); ?>" size="3" /> <?php _e('characters') ?></td>
223</tr>
224<tr valign="top">
225<th width="33%" scope="row"><?php _e('Wrap long words at:') ?></th>
226<td nowrap><input name="chars_per_word" type="text" id="chars_per_word" value="<?php echo kjgrc_get_option("grc","chars_per_word"); ?>" size="3" /> <?php _e('characters') ?></td>
227</tr>
228<tr valign="top">
229<th width="33%" scope="row">Template:
230<td>&nbsp;</td>
231</tr>
232
233<tr>
234<td colspan=2>
235<label for="grc_exclude_blog_owner_checkbox">
236<input type="checkbox" name="grc_exclude_blog_owner_checkbox" id="grc_exclude_blog_owner_checkbox" onclick="toggle_exclude_blog_owner2();" <?php if (kjgrc_get_option("grc","exclude_blog_owner") == 1) echo "checked=\"checked\""; ?>> Exclude comments by blog authors (your own comments)</label>
237</td>
238</tr>
239
240<tr id="grc_exclude_blog_owner_checkbox2" style="display: <?php echo ((kjgrc_get_option("grc","exclude_blog_owner") == 0) ? "none" : "table-row") ?>;">
241<td colspan=2>
242<label for="grc_exclude_blog_owner2_checkbox">&nbsp;&nbsp;&nbsp;
243<input type="checkbox" name="grc_exclude_blog_owner2_checkbox" id="grc_exclude_blog_owner2_checkbox" <?php if (kjgrc_get_option("grc","exclude_blog_owner2") == 1) echo "checked=\"checked\""; ?>> Also consider usernames and e-mail addresses, to recognize blog authors</label>
244</td>
245</tr>
246
247
248<tr>
249<td colspan=2>
250<label for="grc_show_trackbacks_checkbox">
251<input type="checkbox" name="grc_show_trackbacks_checkbox" id="grc_show_trackbacks_checkbox" <?php if (kjgrc_get_option("grc","show_trackbacks") == 1) echo "checked=\"checked\""; ?>> Show Comments and Trackbacks/Pingbacks together</label>
252</td>
253</tr>
254</tr>
255<tr>
256<td colspan=2>
257<label for="grouped_by_post_checkbox">
258<input type="checkbox" name="grouped_by_post_checkbox" id="grouped_by_post_checkbox" onclick="toggle_grouped_titles();" <?php if (kjgrc_get_option("grc","grouped_by_post") == 1) echo "checked=\"checked\""; ?>> Group comments by Posting</label>
259</td>
260</tr>
261<tr id="grouped_by_post_cell_a" style="display: <?php echo ((kjgrc_get_option("grc","grouped_by_post") == 0) ? "none" : "table-row") ?>;">
262<td colspan=3>
263<label for="grc_limit_comments_per_post_checkbox">
264<input type="checkbox" name="grc_limit_comments_per_post_checkbox" id="grc_limit_comments_per_post_checkbox" onclick="toggle_grouped_titles();" <?php if (kjgrc_get_option("grc","limit_comments_per_post") == 1) echo "checked=\"checked\""; ?>> Limit number of comments per post: <!-- aka de klein limit --></label> <input type="text" name="grc_comments_per_post" size=3 value="<?php echo kjgrc_get_option("grc","comments_per_post");?>"><br /><br />
265
266<textarea name="grouped_by_post_a" cols="60" rows="2" id="grouped_by_post_a" style="width: 98%; font-size: 12px;" class="code"><?php echo stripslashes(htmlspecialchars(kjgrc_get_option("grc","grouped_by_post_a"))); ?></textarea><br /><span style="font-size: 10px;"><strong>Template for the post</strong>. It should start with &lt;li&gt; and end with &lt;ul&gt;<span>
267</td>
268</tr>
269
270<tr>
271<td colspan=3 style="padding-left: 30px;"><textarea name="format" cols="60" rows="2" id="format" style="width: 98%; font-size: 12px;" class="code"><?php echo stripslashes(htmlspecialchars(kjgrc_get_option("grc","format"))); ?></textarea><br /><span style="font-size: 10px;"><strong>Template for the comments</strong>. If you want them as a list, It should start with &lt;li&gt; and end with &lt;/li&gt;<span></td>
272</tr>
273<tr>
274
275<tr id="grouped_by_post_cell_b" style="display: <?php echo ((kjgrc_get_option("grc","grouped_by_post") == 0) ? "none" : "table-row") ?>;">
276<td colspan=3>
277
278<textarea name="grouped_by_post_b" cols="60" rows="2" id="grouped_by_post_b" style="width: 98%; font-size: 12px;" class="code"><?php echo stripslashes(htmlspecialchars(kjgrc_get_option("grc","grouped_by_post_b"))); ?></textarea><br /><span style="font-size: 10px;"><strong>Template for the closing tags of the post template</strong>. Usally &lt;/ul&gt;&lt;/li&gt;</span></td>
279
280</tr>
281
282<tr>
283<td colspan=3>
284<strong>Result</strong>
285<?php $result=kjgrc_create_recent_comments('grc_sample');  substr_count($result, "\n");?>
286<textarea cols="60" rows="<?php $result=kjgrc_create_recent_comments('grc_sample');  substr_count($result, "\n"); echo substr_count($result, "\n")+1;?>" style="width: 98%; font-size: 12px; left-margin: 30;" class="code" wrap="off" readonly><?php echo trim($result); ?></textarea>
287</td>         
288</tr>
289
290</table>
291<p class="submit">
292<input type="submit" id="deletepost" name="reset_template" value="<?php _e('Reset template to default') ?> &raquo;" onclick="return confirm('You are about to reset your template for \'Recent Comments\'.\n  \'Cancel\' to stop, \'OK\' to delete.')" />
293<input type="submit" name="Submit" value="<?php _e('Update Recent Comments Options') ?> &raquo;" />
294</p>
295</fieldset>
296</form>
297
298<?php
299} // kjgrc_subpage_grc
300
301function kjgrc_subpage_grt () 
302{
303?>
304
305<form name="trackback_form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;updated=true&amp;subpage=2">
306<input type="hidden" name="function" value="grt">
307<h2><?php _e('Recent Trackbacks') ?></h2>
308<fieldset class="options"> 
309<table width="100%" cellspacing="2" cellpadding="5" class="editform">
310<tr valign="top">
311<th width="33%" scope="row"><?php _e('Show the most recent:') ?></th>
312<td nowrap><input name="max_comments" type="text" id="max_comments" value="<?php echo kjgrc_get_option("grt","max_comments"); ?>" size="3" /> <?php _e('Trackbacks') ?></td>
313<td rowspan="3"><pre><div style='font-size: 10px; border-left: 1px solid; margin: 0px;'> %comment_excerpt - Shortened comment.
314 %comment_link    - Link to the comment.
315 %comment_author  - Name left by the commenter
316 %comment_date    - Date of comment
317 %comment_time    - Time of comment
318 %comment_type    - Pingback or Trackback
319 %time_since      - Time since trackback was posted
320 %author_url      - URL of author or trackback
321 %author_url_href - href="%author_url" or empty
322 %trackback_title - Title of trackback
323 %post_title      - Title of the posting
324 %post_link       - Link to the posting
325 %post_date       - Date of the posting</pre></div></td>
326</tr>
327<tr valign="top">
328<th width="33%" scope="row"><?php _e('Long trackbacks are chopped off at:') ?></th>
329<td nowrap><input name="chars_per_comment" type="text" id="chars_per_comment" value="<?php echo kjgrc_get_option("grt","chars_per_comment"); ?>" size="3" /> <?php _e('characters') ?></td>
330</tr>
331<tr valign="top">
332<th width="33%" scope="row"><?php _e('Wrap long words at:') ?></th>
333<td><input name="chars_per_word" type="text" id="chars_per_word" value="<?php echo kjgrc_get_option("grt","chars_per_word"); ?>" size="3" /> <?php _e('characters') ?></td>
334</tr>
335<tr valign="top">
336<th width="33%" scope="row"><?php _e('Ignore trackbacks originating from this ip address:') ?></th>
337<td><input name="ignore_ip" type="text" id="ignore_ip" value="<?php echo kjgrc_get_option("grt","ignore_ip"); ?>" size="16" /><br><span style='font-size: 10px;'>Insert the <a href="javascript:;" onmousedown="document.trackback_form.ignore_ip.value='<?php global $_SERVER; echo $_SERVER['SERVER_ADDR']; ?>';">address of your webserver</a> to filter pingbacks from your own posts</span></td>
338</tr>
339<tr valign="top">
340<th width="33%" scope="row">Template:
341<td>&nbsp;</td>
342</tr>
343<tr valign="top">
344<td colspan="3">
345       <textarea name="format" cols="60" rows="2" id="format" style="width: 98%; font-size: 12px;" class="code"><?php echo stripslashes(htmlspecialchars(kjgrc_get_option("grt","format"))); ?></textarea><br /><span style="font-size: 10px;"><strong>Template for the trackbacks and pingbacks.</strong> Usually starts with &lt;li&gt; and ends with &lt;/li&gt;.</span>
346</td>
347</tr>
348
349<tr>
350<td colspan=3>
351<strong>Result</strong>
352<?php $result=kjgrc_create_recent_comments('grc_sample');  substr_count($result, "\n");?>
353<textarea cols="60" rows="<?php $result=kjgrc_create_recent_trackbacks('grt_sample');  substr_count($result, "\n"); echo substr_count($result, "\n")+1;?>" style="width: 98%; font-size: 12px; left-margin: 30;" class="code" wrap="off" readonly><?php echo trim($result); ?></textarea>
354</td>         
355</tr>
356
357</table>
358
359
360<p class="submit">
361<input type="submit" id="deletepost" name="reset_template" value="<?php _e('Reset template to default') ?> &raquo;" onclick="return confirm('You are about to reset your template for \'Recent Trackbacks\'.\n  \'Cancel\' to stop, \'OK\' to delete.')" />
362<input type="submit" name="Submit" value="<?php _e('Update Recent Trackbacks Options') ?> &raquo;" />
363</p>
364</form>   
365</fieldset>
366
367<?php 
368} //kjgrc_subpage_grt
369
370function kjgrc_subpage_instructions () 
371{
372?>   
373<h2><?php _e('Instructions') ?></h2>
374<p><strong>1. What this plugin does</strong></p>
375It shows excerpts of the latest comments and/or trackbacks in your sidebar. You
376have comprehensive control about their appearance. This ranges from the number
377of comments, the length of the excerpts up to the html layout. You can let the
378plugin order the comments by the corresponding post, or simply order them by
379date. The plugin can (optionally) separate the trackbacks/pingbacks from the
380comments. It can ignore comments to certain categories, and it offers support
381for gravatars. It only gives extra work to the database, when actually a new
382comment arrived. And you can filter out unwanted pingbacks, which originate
383from your own blog. And it is a widget.
384
385<p><strong>2. Installation</strong></p>
386Since you are reading this text, you already uploaded and activated the plugin.
387Now you want to add the plugin to your theme. There are two options to do this:
388
389<p><strong>2.1 Modern Theme with widget support</strong></p>
390The plugin is a <a href="http://automattic.com/code/widgets/">widget</a>. If
391your theme supports widgets, and you have installed the widget plugin, adding
392the plugin to the sidebar is easy: Go to the <a href="themes.php">presentation menu</a> and drag
393and drop the widget into the sidebar. Don't forget the Get Recent Trackbacks
394box. And you might want to change the title. All done.
395
396<p><strong>2.2 Old school theme without widget support</strong></p>
397
398<p>
399You need to insert the following code snippet into the <a href="theme-editor.php">sidebar template</a>.
400</p>
401
402<span class="code">wp-content/themes/default/sidebar.php</span>
403<div style="border: 1px solid; border-color: #ccc; margin: 15px; background: #eee;">
404
405<pre class="code" style='color:#000000;'><span style='color:#7f0055; background:#ffffe8; '>&lt;?php</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; font-weight:bold; '>if</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#000000; background:#ffffe8; '>(</span><span style='color:#7f0055; background:#ffffe8; font-weight:bold; '>function_exists</span><span style='color:#000000; background:#ffffe8; '>(</span><span style='color:#2a00ff; background:#ffffe8; '>'get_recent_comments'</span><span style='color:#000000; background:#ffffe8; '>)</span><span style='color:#000000; background:#ffffe8; '>)</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#000000; background:#ffffe8; '>{</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; '>?></span><span style='color:#000000;  '></span>
406<span style='color:#000000; '>   </span><span style='color:#7f0055;  '>&lt;</span><span style='color:#7f0055;  font-weight:bold; '>li</span><span style='color:#7f0055;  '>></span><span style='color:#7f0055;  '>&lt;</span><span style='color:#7f0055;  font-weight:bold; '>h2</span><span style='color:#7f0055;  '>></span><span style='color:#7f0055; background:#ffffe8; '>&lt;?php</span><span style='color:#000000; background:#ffffe8; '> _e</span><span style='color:#000000; background:#ffffe8; '>(</span><span style='color:#2a00ff; background:#ffffe8; '>'Recent Comments:'</span><span style='color:#000000; background:#ffffe8; '>)</span><span style='color:#000000; background:#ffffe8; '>;</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; '>?></span><span style='color:#7f0055;'>&lt;/</span><span style='color:#7f0055;  font-weight:bold; '>h2</span><span style='color:#7f0055;  '>></span><span style='color:#000000;  '></span>
407<span style='color:#000000; '>   </span><span style='color:#7f0055;  '>&lt;</span><span style='color:#7f0055;  font-weight:bold; '>ul</span><span style='color:#7f0055;  '>></span><span style='color:#7f0055; background:#ffffe8; '>&lt;?php</span><span style='color:#000000; background:#ffffe8; '> get_recent_comments</span><span style='color:#000000; background:#ffffe8; '>(</span><span style='color:#000000; background:#ffffe8; '>)</span><span style='color:#000000; background:#ffffe8; '>;</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; '>?></span><span style='color:#7f0055;  '>&lt;/</span><span style='color:#7f0055;  font-weight:bold; '>ul</span><span style='color:#7f0055;  '>></span><span style='color:#000000;  '></span>
408<span style='color:#000000; '>   </span><span style='color:#7f0055;  '>&lt;/</span><span style='color:#7f0055;  font-weight:bold; '>li</span><span style='color:#7f0055;  '>></span><span style='color:#000000;  '></span>
409<span style='color:#7f0055; background:#ffffe8; '>&lt;?php</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#000000; background:#ffffe8; '>}</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; '>?></span>   
410
411<span style='color:#7f0055; background:#ffffe8; '>&lt;?php</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; font-weight:bold; '>if</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#000000; background:#ffffe8; '>(</span><span style='color:#7f0055; background:#ffffe8; font-weight:bold; '>function_exists</span><span style='color:#000000; background:#ffffe8; '>(</span><span style='color:#2a00ff; background:#ffffe8; '>'get_recent_trackbacks'</span><span style='color:#000000; background:#ffffe8; '>)</span><span style='color:#000000; background:#ffffe8; '>)</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#000000; background:#ffffe8; '>{</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; '>?></span><span style='color:#000000;  '></span>
412<span style='color:#000000; '>   </span><span style='color:#7f0055;  '>&lt;</span><span style='color:#7f0055;  font-weight:bold; '>li</span><span style='color:#7f0055;  '>></span><span style='color:#7f0055;  '>&lt;</span><span style='color:#7f0055;  font-weight:bold; '>h2</span><span style='color:#7f0055;  '>></span><span style='color:#7f0055; background:#ffffe8; '>&lt;?php</span><span style='color:#000000; background:#ffffe8; '> _e</span><span style='color:#000000; background:#ffffe8; '>(</span><span style='color:#2a00ff; background:#ffffe8; '>'Recent Trackbacks:'</span><span style='color:#000000; background:#ffffe8; '>)</span><span style='color:#000000; background:#ffffe8; '>;</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; '>?></span><span style='color:#7f0055;  '>&lt;/</span><span style='color:#7f0055;  font-weight:bold; '>h2</span><span style='color:#7f0055;  '>></span><span style='color:#000000;  '></span>
413<span style='color:#000000; '>   </span><span style='color:#7f0055;  '>&lt;</span><span style='color:#7f0055;  font-weight:bold; '>ul</span><span style='color:#7f0055;  '>></span><span style='color:#7f0055; background:#ffffe8; '>&lt;?php</span><span style='color:#000000; background:#ffffe8; '> get_recent_trackbacks</span><span style='color:#000000; background:#ffffe8; '>(</span><span style='color:#000000; background:#ffffe8; '>)</span><span style='color:#000000; background:#ffffe8; '>;</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; '>?></span><span style='color:#7f0055;  '>&lt;/</span><span style='color:#7f0055;  font-weight:bold; '>ul</span><span style='color:#7f0055;  '>></span><span style='color:#000000;  '></span>
414<span style='color:#000000; '>   </span><span style='color:#7f0055;  '>&lt;/</span><span style='color:#7f0055;  font-weight:bold; '>li</span><span style='color:#7f0055;  '>></span><span style='color:#000000;  '></span>
415<span style='color:#7f0055; background:#ffffe8; '>&lt;?php</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#000000; background:#ffffe8; '>}</span><span style='color:#000000; background:#ffffe8; '> </span><span style='color:#7f0055; background:#ffffe8; '>?></span>
416</pre>
417
418</div>
419
420<p><strong>3. Customizing</strong></p>
421The strongest feature of the plugin is that you can change the html layout in the admin interface, by filling in templates. In the templates you make use of macros, that are later replaced by the actual data.
422
423<p><strong>3.1 Using the Macros</strong></p>
424<table>
425<tr><td valign="top" nowrap>%comment_excerpt</td><td>The text of the comment. It might get shorted to the number of characters you entered in <em>"Long comments are chopped off at..."</em></td></tr>
426<tr><td valign="top" nowrap>%comment_link</td><td>The URL to the cited comment.</td></tr> 
427<tr><td valign="top" nowrap>%comment_author</td><td>The name, the commenter entered in the comment form. If she left the field empty, the name is "Anonymous".</td></tr>
428<tr><td valign="top" nowrap>%comment_date</td><td>The date, when the comment was posted in the style you configured as <a href="options-general.php">default date format</a>.</td></tr>
429<tr><td valign="top" nowrap>%comment_time</td><td>The time, when the comment was posted</td></tr>
430<tr><td valign="top" nowrap>%time_since</td><td>Time since the comment was posted. For example: &quot;9 hours 16 minutes&quot;.</td></tr>
431<tr><td valign="top" nowrap>%comment_type</td><td>&quot;Comment&quot;, &quot;Trackback&quot; or &quot;Pingback&quot;.</td></tr>
432<tr><td valign="top" nowrap>%gravatar</td><td>This macro becomes a complete image tag. If the comment author registered a gravatar with <a href="http://www.gravatar.com">gravatar.com</a>. Example:<br />&lt;img src=&quot;http://www.gravatar.com/avatar.php?gravatar_id=1ebbd34d4e45cac&amp;size=25&amp;rating=X&quot;/&gt;  </td></tr>
433<tr><td valign="top" nowrap>%gravatar_url</td><td>This macro becomes only the URL to the gravatar. Example:<br />http://www.gravatar.com/avatar.php?gravatar_id=1ebbd34d4e45cac&amp;size=25&amp;rating=X</td></tr>
434<tr><td valign="top" nowrap>%profile_picture</td><td>Becomes to URL of a profile picture. Use it like this: &lt;img src="%profile_picture" width=16 height=16&gt;. This only works after activation of <a href="http://geekgrl.net">Hannah Gray's</a> <a href="http://geekgrl.net/2007/01/02/profile-pics-plugin-release/">Profile Pics Plugin</a>.</td></tr>
435<tr><td valign="top" nowrap>%userid</td><td>If the comment author is registered with your wordpress, and was logged in, when she wrote the comment this is replaced with the user id, she has in WordPress. The user id's are listed here: <a href="users.php">users.php</a>. You can do fancyful things with this macro. For example you may construct an image url, that points to pictures of all the authors of your blog: &lt;img src=&quot;/images/user%userid.jpg&quot;&gt;</td></tr>
436<tr><td valign="top" nowrap>%author_url</td><td>The URL, the comment author left in the comment form, or if the comment is a trackback, the URL of the site that issued the trackback.</td></tr>
437<tr><td valign="top" nowrap>%author_url_href</td><td>The same like %author_url but inside a href statement. If there is no URL, the whole macro is empty. Without a href="" statement the link looks like a link, but is inactive. Use it like this: &lt;a %author_url_href title="%comment_date"&gt;comment_author&lt;/a&gt;</td></tr>
438<tr><td valign="top" nowrap>%post_title</td><td>The title of the posting that was commented.</td></tr>
439<tr><td valign="top" nowrap>%post_link</td><td>The URL of the posting that was commented.</td></tr> 
440<tr><td valign="top" nowrap>%post_date</td><td>The date when the commented posting was published.</td></tr>
441<tr><td valign="top" nowrap>%post_counter</td><td>The number of comments this post has..</td></tr>
442<tr><td valign="top" nowrap>%trackback_title</td><td>Only applicable in trackbacks: The title of the trackback. It  might get shorted to the number of characters you entered in <em>"Long trackbacks are chopped off at..."</em></td></tr>
443</table>
444
445<p><strong>3.2 Group by comments</strong></p>
446
447If you want to order the comments by their posting, you will have not one but
448three templates. The middle one is just the same as in the normal order. The
449first and the last template are used to generate headers for the grouped
450comments. Usually you will show the %post_title in this header. This is the
451html markup that is generated by the templates:
452
453<style type="text/css">
454<!--
455.top-example { vertical-align:top; }
456.top-ital { vertical-align:top; font-style:italic; padding-left: 10px; }
457#example { font-family:monospace;
458           font-weight:bold;
459           border: 1px solid;
460           border-color: #ccc;
461           margin: 15px;
462           background: #eee;
463}       
464#example pre {
465        margin: 0;
466}
467#example td {
468       
469}
470-->
471</style>
472<div id="example">
473<table style="border-spacing:0px; ">
474<tr>
475<td class="top-example"><pre><span style="color:green">&lt;li&gt;&lt;h2&gt;Recent Comments:&lt;/h2&gt;
476   &lt;ul&gt;</pre></span></td>
477<td class="top-ital"><span style="color:green">Start sequence.</span> Automatically provided when the plugin is used as widget. Otherwise you have to enter this by manually into the <a href="theme-editor.php">sidebar.php template</a>.</td>
478</tr>
479<tr>
480<td class="top-example"><pre>
481      <span style="color:blue">&lt;li&gt;Post 1&lt;/li&gt;
482         &lt;ul&gt;
483</pre></span></td>
484<td class="top-ital"><span style="color:blue">Template for the post. This is the header for a list of comments, that all belong to the same posting.</span></td>
485</tr>
486<tr>
487<td class="top-example"><pre>
488            <span style="color:olive">&lt;li&gt;Comment1 to Post1&lt;/li&gt;
489            &lt;li&gt;Comment2 to Post1&lt;/li&gt;
490</pre></span></td>
491<td class="top-ital"><span style="color:olive">Template for the comments<br />It is repeated for every single comment</span></td>
492</tr>
493<tr class="top-example">
494<td class="top-example"><pre>
495         <span style="color:red">&lt;/ul&gt;
496      &lt;/li&gt;
497</pre></span></td>
498<td class="top-ital"><span style="color:red">Template for the closing tags of the post template</span></td>
499</tr>
500<tr class="top-example">
501<td class="top-example"><pre>
502      <span style="color:blue">&lt;li&gt;Post 2&lt;/li&gt;
503         &lt;ul&gt;
504</pre></span></td>
505<td class="top-ital"><span style="color:blue">The next posting.</span></td>
506</tr>
507<tr class="top-example">
508<td class="top-example"><pre>
509            <span style="color:olive">&lt;li&gt;Comment1 to Post2&lt;/li&gt;
510            &lt;li&gt;Comment2 to Post2&lt;/li&gt;
511</pre></span></td>
512<td class="top-ital"><span style="color:olive">The comments to the next posting</span></td>
513</tr>
514<tr class="top-example">
515<td class="top-example"><pre>
516         <span style="color:red">&lt;/ul&gt;
517      &lt;/li&gt;
518</pre></span></td>
519<td class="top-ital"><span style="color:red">Again close the tags</span></td>
520</tr>
521<tr class="top-example">
522<td class="top-example"><pre>
523   <span style="color:green">&lt;/ul&gt;
524&lt;/li&gt;
525</pre></span></td>
526<td class="top-ital"><span style="color:green">End sequence.</span> Automatically provided when the plugin is used as widget. Otherwise you have to enter this by manually into the <a href="theme-editor.php">sidebar.php template</a>.</td>
527</tr>
528</table>
529</div>
530
531
532<p><strong>4. Miscellaneous</strong></p>
533<ul>
534<li>Don't worry if you screwed up the template, reset the template to default and try again.</li>
535<li><em>"Wrap long words at..."</em> means: words, that exceed this length are split into fragments to prevent damage to the layout of your blog.</li>
536<li>"<em>Ignore trackbacks originating from this ip address</em>" on the
537configuration page for recent trackbacks is useful for filtering out pingbacks
538that occur when you have a link to your own site in a post.</li>
539<li>If you select to exclude comments made by blog authors (your own comments) from  the list, then the comments which you made, when you were logged in, are ignored. If you also want to exclude comments you made, when you were not logged in, you can select to also consider the username and e-mail address.</li>
540</ul>
541<p><strong>5. Interoperation with other plugins</strong></p>
542<ul>
543<li>If <a href="http://geekgrl.net">Hannah Gray's</a> <a href="http://geekgrl.net/2007/01/02/profile-pics-plugin-release/
544">Profile Pics Plugin</a> is present, you may use to macro <em>%profile_picture</em> to obtain an URL to the profile picture of the commentator (read in the macro section for a working example).</li>
545<li>If <a href="http://fredfred.net/skriker/index.php/polyglot">malyfred's</a> <a href="http://fredfred.net/skriker/index.php/polyglot">Polyglot</a> Plugin is present, additional filters are applied to comments, titles, dates and times, which select the right language for the user.</li>
546</ul>
547</div> 
548
549<?php 
550}
551
552function kjgrc_subpage_header ($kjgrc_selected_tab) {
553        $current_tab[$kjgrc_selected_tab] = "class=\"current\"";
554?>
555<style>
556<!--
557#adminmenu3 li {
558        display: inline;
559        line-height: 200%;
560        list-style: none;
561        text-align: center;
562}
563
564#adminmenu3 {
565        background: #0d324f;
566        border-bottom: none;
567        margin: 0;
568        height: 25px;
569        padding: 3px 2em 0 1em;
570        paddi/ng: 0 0 0 0;
571}
572                                                                                     
573#adminmenu3 .current {
574        background: #f9fcfe;
575        border-top: 1px solid #045290;
576        border-right: 2px solid #045290;
577        color: #000;
578}
579                                                                                     
580#adminmenu3 a {
581        border: none;
582        color: #fff;
583        font-size: 12px;
584        padding: .3em .4em .33em;
585}
586                                                                                     
587#adminmenu3 a:hover {
588        background: #ddeaf4;
589        color: #393939;
590}
591                                                                                     
592-->
593</style>
594<ul id="submenu">
595   <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=1" <?php echo $current_tab[1] ?>>Comments</a></li>
596   <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=2" <?php echo $current_tab[2] ?>>Trackbacks</a></li>
597   <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=4" <?php echo $current_tab[4] ?>>Categories</a></li>
598   <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=5" <?php echo $current_tab[5] ?>>Gravatars</a></li>
599   <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=6" <?php echo $current_tab[6] ?>>Misc</a></li>
600   <li><a href="<?php echo $_SERVER['PHP_SELF']; ?>?page=get-recent-comments.php&amp;subpage=3" <?php echo $current_tab[3] ?>>Instructions</a></li>
601</ul>
602<div class="wrap">
603<?php
604}
605
606// function kjgrc_log ($msg="")
607// {
608//      $handle = @fopen ("/home/krischan/debug.log", "a");
609//      if (is_writable("/home/krischan/debug.log")) {
610//              fwrite($handle,date("r").": $msg\n");
611//              fclose($handle);
612//      }
613// }   
614
615function kjgrc_set_option($key,$value) 
616{
617        global $kjgrc_options_loaded;
618        // Fetch dummy value just to enforce migration if needed
619        kjgrc_get_option("grc","max_comments");
620        $options = get_option("kjgrc_options");
621        $options[$key] = $value;
622        update_option("kjgrc_options",$options);
623        kjgrc_invalidate_cache();
624}
625
626function kjgrc_get_option($section,$option_name)
627{
628        global $wpdb,$kjgrc_options_loaded;
629        $version = 11; // If version differs from saved value -> insert new defaults
630        $kjgrc_options = get_option("kjgrc_options");
631        if ($kjgrc_options == NULL || $kjgrc_options['version'] != $version) 
632        {
633                $default_options = array (
634                        "grc_max_comments" => 5,
635                        "grc_chars_per_comment" => 120,
636                        "grc_chars_per_word" => 30,
637                        "grc_format" => "<li><a href=\"%comment_link\" title=\"%post_title, %post_date\">%comment_author</a>: %comment_excerpt</li>",
638                        "grc_grouped_by_post" => 0,
639                        "grc_grouped_by_post_a" => '<li><strong><a href="%post_link" title="%post_title was posted on %post_date">%post_title</a>&nbsp;(<a href="#" title="There are %post_counter comments to this posting">%post_counter</a>)</strong><ul>',
640                        "grc_grouped_by_post_b" => '</ul></li>',
641                        "grc_show_trackbacks" => 0,
642                        "grc_comments_per_post" => 5,
643                        "grc_limit_comments_per_post" => 0,
644                        "grc_exclude_blog_owner" => 0,
645                        "grc_exclude_blog_owner2" => 0,
646                        "grt_max_comments" => 5,
647                        "grt_chars_per_comment" => 120,
648                        "grt_chars_per_word" => 30,
649                        "grt_format" => "<li><a href=\"%comment_link\" title=\"Trackback to &quot;%post_title&quot;: %comment_excerpt\">%comment_author</a>: %trackback_title</li>",
650                        "misc_exclude_cat" => "",
651                        "misc_exclude_cat_reverse" => 0,
652                        "misc_convert_smileys" => 1,
653                        "gravatar_size" => 20,
654                        "gravatar_alt_url" => "",
655                        "grt_ignore_ip" => "",
656                        "gravatar_rating" => 0,
657                        "grc_sidebar_title" => "Recent Comments",
658                        "grt_sidebar_title" => "Recent Trackbacks"
659                );
660                $old_keys = array("grc_max_comments","grc_chars_per_comment","grc_chars_per_word","grc_format","grt_max_comments","grt_chars_per_comment","grt_chars_per_word","grt_format","misc_exclude_cat","gravatar_size","gravatar_alt_url","gravatar_rating","grt_ignore_ip"); 
661                // This might be an upgrade from < 1.4 to 1.4 or newer version. If there are old keys, migrate them to the new array:
662                add_option('gravatar_alt_url','');
663                if ($kjgrc_options == NULL) {
664                        foreach ($old_keys as $key) {
665                                $sql = "SELECT option_value,option_id FROM $wpdb->options WHERE option_name = 'kjgrc_$key'";
666                                $old_value = $wpdb->get_row($sql,ARRAY_N); // $old_value[0] = old value, $old_value[1] = option id
667                                if ($old_value[1] != NULL) { 
668                                        $kjgrc_options[$key] = $old_value[0];
669                                        delete_option("kjgrc_$key");
670                                } 
671                        }
672                }
673                // Whether it's a new installation or an introduction of new options: Fill in default values
674                foreach (array_keys($default_options) as $key) {
675                        if (($kjgrc_options == NULL) || ! array_key_exists($key,$kjgrc_options) ) {
676                                $kjgrc_options[$key] = $default_options[$key];
677                        }
678                }
679                // Delete keys that are not in use any more
680                foreach (array_keys($default_options) as $key) {
681                        $tmp[$key] = $kjgrc_options[$key];
682                }
683                $kjgrc_options = $tmp;
684                $kjgrc_options["version"] = $version;
685                add_option("kjgrc_options",$options,$description = '', $autoload = 'no');
686                update_option('kjgrc_options',$kjgrc_options);
687        }
688        return $kjgrc_options[$section . "_" . "$option_name"];
689}
690
691function kjgrc_use_cache()
692{
693        add_option('kjgrc_use_cache',1);
694        return get_option("kjgrc_use_cache");
695}
696
697function kjgrc_options_page ()
698{
699?>
700<?php
701        $function = $_POST['function'];
702        if (isset($_GET['updated']) && ($_GET['updated'] == 'true') && 
703                (!empty($_POST['max_comments'])) && 
704                (!empty($_POST['chars_per_comment'])) &&         
705                (!empty($_POST['chars_per_word'])) && 
706                (!empty($_POST['function'])) )
707                // todo: check new params
708        {
709                if (($function == 'grc') ||
710                    ($function == 'grt'))
711                {
712                        if (!empty($_POST['reset_template'])) {
713                                if ($function == 'grc') {
714                                        kjgrc_set_option('grc_format','<li><a href="%comment_link" title="%post_title, %post_date">%comment_author</a>: %comment_excerpt</li>');
715                                        kjgrc_set_option('grc_grouped_by_post_a','<li><strong><a href="%post_link" title="%post_title was posted on %post_date">%post_title</a> (<a href="#" title="There are %post_counter comments to this posting">%post_counter</a>)</strong><ul>');
716                                        kjgrc_set_option('grc_grouped_by_post_b','</ul></li>');
717                                }
718                                if ($function == 'grt') {
719                                        kjgrc_set_option('grt_format','<li><a href="%comment_link" title="Trackback to &quot;%post_title&quot;: %comment_excerpt">%comment_author</a>: %trackback_title</li>');
720                                }
721                                //delete_option('kjgrc_'.$function.'_format');
722                        } else {
723                                kjgrc_set_option($function.'_max_comments', (int)$_POST['max_comments']);
724                                kjgrc_set_option($function.'_chars_per_comment', (int)$_POST['chars_per_comment']);
725                                kjgrc_set_option($function.'_chars_per_word', (int)$_POST['chars_per_word']);
726                                kjgrc_set_option($function.'_format', $_POST['format']);
727                                kjgrc_set_option($function.'_grouped_by_post_a', $_POST['grouped_by_post_a']);
728                                kjgrc_set_option($function.'_grouped_by_post_b', $_POST['grouped_by_post_b']);
729                        }
730                }
731                if ($function == 'grc') {
732
733                        if ($_POST['grc_exclude_blog_owner_checkbox'] == 'on') 
734                                kjgrc_set_option('grc_exclude_blog_owner',1);
735                        else 
736                                kjgrc_set_option('grc_exclude_blog_owner',0);
737                        if ($_POST['grc_exclude_blog_owner2_checkbox'] == 'on') 
738                                kjgrc_set_option('grc_exclude_blog_owner2',1);
739                        else
740                                kjgrc_set_option('grc_exclude_blog_owner2',0);
741                        if ($_POST['grouped_by_post_checkbox'] == 'on') {
742                                kjgrc_set_option('grc_grouped_by_post',1);
743                        } else {
744                                kjgrc_set_option('grc_grouped_by_post',0);
745                        }
746                        if ($_POST['grc_show_trackbacks_checkbox'] == 'on') {
747                                kjgrc_set_option('grc_show_trackbacks',1);
748                        } else {
749                                kjgrc_set_option('grc_show_trackbacks',0);
750                        }
751                        if (! empty($_POST['grc_comments_per_post'])) {
752                                kjgrc_set_option('grc_comments_per_post',(int)$_POST['grc_comments_per_post']);
753                                if (kjgrc_get_option("grc","comments_per_post") == 0)
754                                        kjgrc_set_option("grc_comments_per_post",1);
755                        }
756                        if ($_POST['grc_limit_comments_per_post_checkbox'] == 'on') {
757                                kjgrc_set_option('grc_limit_comments_per_post',1);
758                        } else {
759                                kjgrc_set_option('grc_limit_comments_per_post',0);
760                        }
761                }
762        }
763        if (isset($_GET['updated']) && ($_GET['updated'] == 'true'))
764        {
765                if ($function == 'exclude_cat') 
766                {
767                        if (count($_POST['exclude_category']) == 0) {
768                                kjgrc_set_option('misc_exclude_cat','');
769                        } else {
770                                kjgrc_set_option('misc_exclude_cat',implode(" ",$_POST['exclude_category']));
771                        }
772                        if (isset($_POST['exclude_categories_reverse'])) {
773                                if ($_POST['exclude_categories_reverse'] == 0 || $_POST['exclude_categories_reverse'] == 1) {
774                                        kjgrc_set_option("misc_exclude_cat_reverse",$_POST['exclude_categories_reverse']);
775                                }
776                        }
777                }
778                if ($function == 'gravatar') {
779                        if ($_POST['gravatar_size'] > 0 && $_POST['gravatar_size'] < 81) {
780                                kjgrc_set_option('gravatar_size',$_POST['gravatar_size']);
781                        }
782                        kjgrc_set_option('gravatar_alt_url',$_POST['gravatar_alt_url']);
783                        kjgrc_set_option('gravatar_rating',$_POST['gravatar_rating']);
784                }
785                if ($function == 'grt' && isset($_POST['ignore_ip']))
786                {
787                        kjgrc_set_option('grt_ignore_ip',trim($_POST['ignore_ip']));
788                }
789                if ($function == 'misc' && isset($_POST['convert_smileys'])) {
790                        if ($_POST['convert_smileys'] == 0 || $_POST['convert_smileys'] == 1) {
791                                kjgrc_set_option("misc_convert_smileys",$_POST['convert_smileys']);
792                        }
793                }
794                if ($function == 'misc') {
795                        if ($_POST['use_cache_checkbox'] == 'on') {
796                                update_option("kjgrc_use_cache",1);
797                        } else {
798                                update_option("kjgrc_use_cache",0);
799                        }
800                }
801        }
802        $kjgrc_subpage = 1;
803        if (isset($_GET['subpage'])) {
804                $kjgrc_subpage = $_GET['subpage'];
805        }
806        kjgrc_subpage_header($kjgrc_subpage);
807        if ($kjgrc_subpage == 1) {
808                kjgrc_subpage_grc(); 
809        } elseif ($kjgrc_subpage == 2) {
810                kjgrc_subpage_grt();
811        } elseif ($kjgrc_subpage == 3) {
812                kjgrc_subpage_instructions();
813        } elseif ($kjgrc_subpage == 4) {
814                kjgrc_subpage_exclude_cat();
815        } elseif ($kjgrc_subpage == 5) {
816                kjgrc_subpage_gravatar();
817        } elseif ($kjgrc_subpage == 6) {
818                kjgrc_subpage_misc();
819        }
820}
821
822function kjgrc_add_options_page() 
823{
824        add_options_page('Get Recent Comments Plugin', 'Recent Comments', 8, 'get-recent-comments.php','kjgrc_options_page');
825}
826
827function kjgrc_get_exclude_cat ()
828{
829        $exclude_cat = kjgrc_get_option('misc','exclude_cat');
830        if ($exclude_cat == '') {
831                return FALSE;
832        }
833        #echo "cats: '". kjgrc_get_option('misc','exclude_cat') ."' ";
834        return explode(" ",kjgrc_get_option('misc','exclude_cat'));
835}
836
837#function kjgrc_suicide ()
838#{
839#       $plugins = get_settings('active_plugins');
840#       if (in_array('get-recent-comments.php',$plugins)) {
841#               unset($plugins['get-recent-comments.php']);
842#               update_option('active_plugins',$plugins);
843#       }
844#       delete_option('kjgrc_options');
845#       kjgrc_get_option('grc','max_comments');
846#       delete_option('kjgrc_options');
847#       delete_option('kjgrc_cache');
848#       echo 'you are now dead';
849#}
850
851function get_recent_comments()
852{
853        echo kjgrc_cache("comments");
854}
855
856function get_recent_trackbacks()
857{
858        echo kjgrc_cache("trackbacks");
859}
860
861function kjgrc_invalidate_cache() {
862        delete_option('kjgrc_cache');
863}
864function kjgrc_handle_new_comment($args) {
865        if (wp_get_comment_status($args) == 'approved') {
866                kjgrc_invalidate_cache();
867        }
868}
869
870function kjgrc_prepare_cache($cache)
871{
872        // return $cache;
873        $last = 0;
874        $start = strpos($cache,'<%time_since:');
875        if ($start === false) {
876                return $cache;
877        }
878        while ($start !== false)
879        {
880                //kjgrc_log("start: $start");
881                $end = strpos($cache,'>',$start);
882                //kjgrc_log("end $end");
883                //kjgrc_log("cut $last - $start");
884                $newcache = $newcache . substr($cache,$last,$start-$last);
885                $tmp = substr($cache,$start+13,$end-$start-13);
886                $ago = gmdate('U')-$tmp;
887                //kjgrc_log("--> $tmp <--");
888                $newcache = $newcache . kjgrc_format_seconds($ago);
889                #kjgrc_log("$newcache");
890                $last = $end + 1;
891                $start = strpos($cache,'<%time_since:',$last);
892        }
893        $newcache = $newcache . substr($cache,$last);
894        return $newcache;       
895}
896
897function kjgrc_cache($type)
898{
899        global $wpdb,$kjgrc_cache;
900        $use_cache = FALSE;
901        if (kjgrc_use_cache()) {
902                $use_cache = TRUE;
903        }
904        if ($use_cache == FALSE) {
905                // kjgrc_log("return cache without caching");
906                $kjgrc_cache[comments] = kjgrc_prepare_cache(kjgrc_create_recent_comments());
907                $kjgrc_cache[trackbacks] = kjgrc_prepare_cache(kjgrc_create_recent_trackbacks());
908                return $kjgrc_cache[$type];
909        }
910        if ($kjgrc_cache == NULL) {
911                // kjgrc_log("return cache WITH caching");
912                $kjgrc_cache = get_option('kjgrc_cache');
913                if ($kjgrc_cache == NULL) {
914                        // kjgrc_log("write new cache");
915                        $kjgrc_cache[comments] =  base64_encode(kjgrc_create_recent_comments());
916                        $kjgrc_cache[trackbacks] = base64_encode(kjgrc_create_recent_trackbacks());
917                        update_option('kjgrc_cache',$kjgrc_cache);
918                }
919                $kjgrc_cache[comments] = kjgrc_prepare_cache(base64_decode($kjgrc_cache[comments]));
920                $kjgrc_cache[trackbacks] = kjgrc_prepare_cache(base64_decode($kjgrc_cache[trackbacks]));
921        }
922        // search and replace up to date information
923        return $kjgrc_cache[$type];
924}
925
926
927function kjgrc_create_recent_trackbacks( $caller = '')
928{
929        global $kjgrc_we_are_a_widget,$kjgrc_widget_args;;
930
931        // $entries = kjgrc_get_entries($max_comments,$chars_per_comment,$chars_per_word,$format,$query,0,$caller);
932        $entries = kjgrc_get_comments2('grt',$caller);
933        // If we are a widget: Also care for the title
934        if ($kjgrc_we_are_a_widget == TRUE) {
935                extract($kjgrc_widget_args);
936                return $before_widget . $before_title . kjgrc_get_option("grt","sidebar_title") . $after_title .
937                '<div id="get_recent_comments_wrap"><ul>' .
938                $entries .
939                '</ul></div>' .
940                $after_widget;
941        }
942        return $entries;
943}
944
945function kjgrc_create_recent_comments ($caller='')
946{
947        global $kjgrc_we_are_a_widget,$kjgrc_widget_args;
948
949        // $entries = kjgrc_get_entries($max_comments,$chars_per_comment,$chars_per_word,$format,$query,kjgrc_get_option("grc","grouped_by_post"),$caller);
950        // If we are a widget: Also care for the title
951        // $entries = kjgrc_get_comments2($max_comments,$chars_per_comment,$chars_per_word,$format,kjgrc_get_option("grc","grouped_by_post"),$caller);
952        $entries = kjgrc_get_comments2('grc',$caller);
953        if ($kjgrc_we_are_a_widget == TRUE) {
954                extract($kjgrc_widget_args);
955                return $before_widget . $before_title . kjgrc_get_option("grc","sidebar_title") . $after_title .
956                '<div id="get_recent_comments_wrap"><ul>' .
957                $entries .
958                '</ul></div>' .
959                $after_widget;
960        } 
961        return $entries;
962}
963
964function kjgrc_parse_pingback($pingback_author)
965{
966        $workstring = trim($pingback_author);
967        /* most common syntax
968        1. author &raquo; title
969        2. author &raquo; category &raquo; title
970        3. title at author
971        4. title - author (too insignificant)
972        5. [&raquo;] title &laquo; author
973        */
974        $first_delimiter = strpos($workstring,'&raquo;');
975        while ($first_delimiter !== false && $first_delimiter == 0) {
976                $workstring = trim(substr($workstring,7));
977                $first_delimiter = strpos($workstring,'&raquo;');
978        }
979        if ($first_delimiter !== false) {
980                $comment_author = substr($workstring,0,$first_delimiter-1);
981                $workstring = trim(substr($workstring,$first_delimiter+7));
982                $first_delimiter = strpos($workstring,'&raquo;');
983                if ($first_delimiter !== false) {
984                        $workstring = trim(substr($workstring,$first_delimiter+7));
985                }
986                return array($comment_author,$workstring);
987        }
988        foreach (array(' at ','&laquo;',' - ',' auf ',' by ',' // ',' | ',' : ',' @ ',' / ') as $delimiter)
989        {
990                $first_delimiter = strpos($workstring,$delimiter);
991                if ($first_delimiter !== false) {
992                        $trackback_title = trim(substr($workstring,0,$first_delimiter));
993                        $comment_author = trim(substr($workstring,$first_delimiter+strlen($delimiter)));
994                        // kjgrc_log("delimiter match [$delimiter]: $workstring -> a: '$comment_author' t: '$trackback_title' ");
995                        return array($comment_author,$trackback_title);
996                }
997        }
998        // $comment_author = 'Unknown';
999        $comment_author = $pingback_author;
1000        $trackback_title = '';
1001        return array($comment_author,$trackback_title);
1002}
1003
1004// original function from wordpress 2.3 for backwards compatibility to wordpress 2.0.11
1005function kjgrc_get_users_of_blog( $id = '' ) {
1006        global $wpdb, $blog_id;
1007        if ( empty($id) )
1008                $id = (int) $blog_id;
1009        $users = $wpdb->get_results( "SELECT user_id, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE " . $wpdb->users . 
1010".ID = " . $wpdb->usermeta . ".user_id AND meta_key = '" . $wpdb->prefix . "capabilities' ORDER BY {$wpdb->usermeta}.user_id" );
1011        return $users;
1012}
1013
1014
1015/* This function is dedicated to Mike */
1016function kjgrc_is_wordpress_user($comment)
1017{
1018        global $kjgrc_wordpress_users;
1019        if ($kjgrc_wordpress_users == NULL) {
1020                // be still compatible to wordpress 2.0.11
1021                if (function_exists("get_users_of_blog")) {
1022                        $kjgrc_wordpress_users = get_users_of_blog();
1023                } else {
1024                        $kjgrc_wordpress_users = kjgrc_get_users_of_blog();
1025                }
1026        }
1027        foreach ($kjgrc_wordpress_users as $user) {
1028                if (strcasecmp($comment->comment_author_email,$user->user_email) == 0 ) {
1029                        if ( (strcasecmp($comment->comment_author,$user->user_login) == 0) ||
1030                             (strcasecmp($comment->comment_author,$user->display_name) == 0) ) 
1031                        {
1032                                return TRUE;
1033                        }
1034                }
1035        }
1036        return FALSE;
1037}
1038
1039// function kjgrc_get_comments2 ($max_comments,$chars_per_comment,$chars_per_word,$format,$grouped_by_post,$caller)
1040function kjgrc_get_comments2 ($requested_comment_type,$caller)
1041{
1042        // kjgrc_log("kjgrc_get_comments2 $caller");
1043        // echo "kjgrc_get_comments2 $requested_comment_type $caller<br>";
1044        global $wpdb;
1045        $batch_number = 0;
1046        $number_of_comments = 0;
1047
1048        $requested_number_of_comments = kjgrc_get_option($requested_comment_type,"max_comments");
1049        $chars_per_comment = kjgrc_get_option($requested_comment_type,"chars_per_comment");
1050        $chars_per_word = kjgrc_get_option($requested_comment_type,"chars_per_word");
1051        $format = stripslashes(kjgrc_get_option($requested_comment_type,"format"));
1052        $batch_size = $requested_number_of_comments * 3;
1053        // grc
1054        //x// $max_comments = kjgrc_get_option("grc","max_comments");
1055        //x// $chars_per_comment = kjgrc_get_option("grc","chars_per_comment");
1056        //x// $chars_per_word = kjgrc_get_option("grc","chars_per_word");
1057        //x// $format = stripslashes(kjgrc_get_option("grc","format"));
1058        //x// $sql_comment_type = "AND comment_type = '' ";
1059        //x// if (kjgrc_get_option("grc","show_trackbacks") == 1) {
1060        //x//   $sql_comment_type = '';
1061        //x// }
1062       
1063        // grt
1064        //// $max_comments = kjgrc_get_option("grt","max_comments");
1065        //// $chars_per_comment = kjgrc_get_option("grt","chars_per_comment");
1066        //// $chars_per_word = kjgrc_get_option("grt","chars_per_word");
1067        //// $format = stripslashes(kjgrc_get_option("grt","format"));
1068
1069        //// $query = "SELECT DISTINCT $wpdb->comments.* FROM $wpdb->comments ".
1070        ////    "LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID ".
1071        ////    $sql_join_post2cat .
1072        ////    "WHERE (post_status = 'publish' OR post_status = 'static') AND comment_approved= '1' AND  post_password = '' ".
1073        ////    $sql_exlude_cat .
1074        ////    "AND ( comment_type = 'trackback' OR comment_type = 'pingback' ) ".
1075        ////         $sql_ignore_ip .
1076        ////    "ORDER BY comment_date DESC LIMIT $max_comments";
1077       
1078        $sql_ignore_ip = '';
1079        $sql_exclude_owner = '';
1080        $grouped_by_post = 0;
1081        if ($requested_comment_type == 'grt')
1082        {       
1083                if (kjgrc_get_option("grt","ignore_ip") != '') {
1084                        $sql_ignore_ip = "AND comment_author_IP != '". kjgrc_get_option("grt","ignore_ip") ."' ";
1085                }
1086                $sql_comment_type = "( comment_type = 'trackback' OR comment_type = 'pingback' ) ";
1087        }
1088        if ($requested_comment_type == 'grc')
1089        {
1090                $sql_comment_type = "comment_type = '' ";
1091                if (kjgrc_get_option("grc","show_trackbacks") == 1) {
1092                        $sql_comment_type = '1 ';
1093                }
1094                if (kjgrc_get_option("grc","exclude_blog_owner") == 1) {
1095                        $sql_exclude_owner = "AND user_id = '0' ";
1096                }
1097                if (kjgrc_get_option("grc","grouped_by_post")) {
1098                        $grouped_by_post = 1;
1099                }
1100        }
1101
1102        while ($comments_number < $requested_number_of_comments) 
1103        {
1104                $query = "SELECT * from $wpdb->comments WHERE comment_approved= '1' AND " . 
1105                         $sql_comment_type .
1106                         $sql_exclude_owner .
1107                         $sql_ignore_ip .
1108                         "ORDER BY comment_date DESC LIMIT " . ($batch_number*$batch_size) . ",$batch_size"; 
1109                // echo "$query<br><br>";
1110                $comments = $wpdb->get_results($query);
1111                if (!$comments) {
1112                        $result .= "none";
1113                        break;
1114                }
1115                unset($missing_post);
1116                foreach ($comments as $comment) {
1117                        if ($post_cache == NULL || ! array_key_exists($comment->comment_post_ID,$post_cache)) {
1118                                $missing_post[$comment->comment_post_ID] = 1;
1119                        }
1120                }
1121                if ($missing_post != NULL)
1122                {
1123                        unset($comma_separated);
1124                        $comma_separated = implode(",", array_keys($missing_post));
1125                        if (empty($wpdb->term_relationships)) {
1126                                $query = "SELECT * from $wpdb->posts JOIN $wpdb->post2cat ON ID = post_id WHERE ID IN ($comma_separated);";
1127                        } else { 
1128                                $query = "SELECT * from $wpdb->posts JOIN $wpdb->term_relationships ON ($wpdb->term_relationships.object_id=ID)  WHERE ID IN ($comma_separated);"; 
1129                        }
1130                        // echo "$query<br>";
1131                        $posts = $wpdb->get_results($query);
1132                        foreach ($posts as $post) {
1133                                // echo "p: $post->ID ";
1134                                $post_cache[$post->ID] = $post;
1135                                if (empty($wpdb->term_relationships)) {
1136                                        $cat_cache[$post->ID][$post->category_id] = 1;
1137                                } else {
1138                                        $cat_cache[$post->ID][$post->term_taxonomy_id] = 1;
1139                                }       
1140                        }
1141                }
1142                // echo "-------<br>";
1143                // drop comments:
1144                // 1. comment_approved = 1 -> in select
1145                // 2. post_status = 'publish' OR post_status = 'static'
1146                // 3. post_password = ''
1147                // 4. AND user_id = '0' -> in select
1148                // 5. AND comment_author_IP != '1.2.3.4' -> in select   
1149                // 6. "AND category_id  != '$cat'
1150                // 7. limit_comments_per_post
1151
1152                foreach ($comments as $comment) 
1153                {
1154                        if ($post_cache[$comment->comment_post_ID]->post_status != 'publish' &&
1155                            $post_cache[$comment->comment_post_ID]->post_status != 'static' ) 
1156                        {       
1157                                // echo "drop $comment->comment_ID (". $post_cache[$comment->comment_post_ID]->post_status .")<br>";
1158                                continue;
1159                        }       
1160                        if ($post_cache[$comment->comment_post_ID]->post_password != '') {
1161                                // echo "drop $comment->comment_ID (protected)<br>";
1162                                continue;
1163                        }
1164                        /* Optional additional check for wordpress users who are not logged in */
1165                        if ((kjgrc_get_option("grc","exclude_blog_owner") == 1) && 
1166                            (kjgrc_get_option("grc","exclude_blog_owner2") == 1)       
1167                           ) 
1168                        {
1169                                if (kjgrc_is_wordpress_user($comment)) {
1170                                        // echo "drop $comment->comment_ID (is_wordpress_user)<br>";
1171                                        continue;
1172                                }
1173                        }
1174                        $exclude_cat = kjgrc_get_exclude_cat();
1175                        $is_in_excluded_cat = 0;
1176                        if (kjgrc_get_option("misc","exclude_cat_reverse") == 1) {
1177                                $is_in_excluded_cat = 1;
1178                        }
1179                        if ($exclude_cat) {
1180                                foreach ($exclude_cat as $cat) {
1181                                        if ($cat_cache[$comment->comment_post_ID][$cat] == 1) {
1182                                                $is_in_excluded_cat = 1;
1183                                                if (kjgrc_get_option("misc","exclude_cat_reverse") == 1) {
1184                                                        $is_in_excluded_cat = 0;
1185                                                }
1186                                                // echo "drop $comment->comment_ID (is in excluded cat $cat)<br>";
1187                                               
1188                                        }
1189                                }
1190                                if ($is_in_excluded_cat) {
1191                                        continue;
1192                                }
1193                        }
1194                        // nur !trackbacks?
1195                        if ($grouped_by_post && kjgrc_get_option("grc","limit_comments_per_post") == 1) {
1196                                if ($comments_per_post_counter[$comment->comment_post_ID] >= kjgrc_get_option("grc","comments_per_post")) {
1197                                        // echo "drop $comment->comment_ID (max nr cmt/post reached)<br>";
1198                                        continue;
1199                                }
1200                        }
1201                        $comments_per_post_counter[$comment->comment_post_ID]++;
1202                        $comments_number++;
1203                        // $result .= "$comments_number [$batch_number] $comment->comment_ID ($comment->comment_content)<br>";
1204                        $fetched_comments[] = $comment;
1205                        if ($comments_number >= $requested_number_of_comments) {
1206                                break;
1207                        }
1208                }
1209                $batch_number++;
1210               
1211        } 
1212        // comments are selected. now format them
1213
1214        if (!(strpos($format,"%gravatar") !== false))
1215                $has_gravatar = 0;
1216        else {
1217                $has_gravatar = 1;
1218                $gravatar_alt_url = kjgrc_get_option('gravatar','alt_url');
1219                $gravatar_size    = kjgrc_get_option('gravatar','size');
1220                $gravatar_rating  = kjgrc_get_option('gravatar','rating');
1221                $gravatar_mpaa[0] = 'G';
1222                $gravatar_mpaa[1] = 'PG';
1223                $gravatar_mpaa[2] = 'R';
1224                $gravatar_mpaa[3] = 'X';
1225                $gravatar_options .= "&amp;size=$gravatar_size";
1226                $gravatar_options .= "&amp;rating=" . $gravatar_mpaa[$gravatar_rating];
1227                if (kjgrc_get_option('gravatar','alt_url') != '') {
1228                        $gravatar_options .= "&amp;default=" . urlencode($gravatar_alt_url);
1229                }
1230        }
1231
1232        if (! $fetched_comments) {
1233                return "<li><!-- no comments yet --></li>";
1234        }
1235        foreach ($fetched_comments as $comment)
1236        {
1237                $trackback_title = '';
1238                if (function_exists("polyglot_init")) {
1239                        // This looks like the wrong filter, but the_content deletes smileys when called from here
1240                        $comment_excerpt = apply_filters('single_post_title',$comment->comment_content);
1241                } else {
1242                        $comment_excerpt = $comment->comment_content;
1243                }
1244                // comment_author,
1245                $comment_type = "Comment";
1246                if ($comment->comment_type == 'pingback') 
1247                {
1248                       
1249                        $comment_type = "Pingback";
1250                        list($comment_author,$trackback_title) = kjgrc_parse_pingback($comment->comment_author);
1251                        if(strpos($comment_excerpt,'[...]') == 0) 
1252                                $comment_excerpt = trim(substr($comment_excerpt,5));
1253                        if(strpos($comment_excerpt,'[...]') == strlen($comment_excerpt)-5)
1254                                $comment_excerpt = trim(substr($comment_excerpt,0,strlen($comment_excerpt)-5));
1255                }
1256                elseif ($comment->comment_type == 'trackback') 
1257                {
1258                        $comment_type = "Trackback";
1259                        $trackback_title = preg_replace("/^<strong>(.+?)<\/strong>.*/s","$1",$comment->comment_content);
1260                        $trackback_title = strip_tags($trackback_title);
1261                        $trackback_title = preg_replace("/[\n\t\r]/"," ",$trackback_title);
1262                        $trackback_title = preg_replace("/\s{2,}/"," ",$trackback_title);
1263                        $trackback_title = wordwrap($trackback_title,$chars_per_word,' ',1);
1264                                                                               
1265                        $comment_excerpt = preg_replace("/^<strong>.+?<\/strong>/","",$comment->comment_content,1);
1266                        $comment_author = $comment->comment_author;
1267                }
1268                else 
1269                {
1270                        $comment_author = $comment->comment_author;
1271                        if (!$comment_author)
1272                                $comment_author = "Anonymous";
1273                }       
1274                $comment_excerpt = strip_tags(wptexturize($comment_excerpt));
1275
1276                $comment_excerpt = preg_replace("/[\n\t\r]/"," ",$comment_excerpt); // whitespace into 1 blank
1277                $comment_excerpt = preg_replace("/\s{2,}/"," ",$comment_excerpt); // whitespace into 1 blank
1278                $comment_excerpt = wordwrap($comment_excerpt,$chars_per_word,' ',1);
1279
1280                if ($trackback_title == '')
1281                        $trackback_title = $comment_excerpt;
1282
1283                $post_link    = get_permalink($comment->comment_post_ID);
1284                $comment_link = $post_link .
1285                                "#comment-$comment->comment_ID";
1286                /* Does not work - polyglot uses global variables to access the comment/post data
1287                if (function_exists("polyglot_init")) {
1288                        $comment_date = apply_filters('the_date',$comment->comment_date);
1289                } else {
1290                        $comment_date = mysql2date(get_settings('date_format'),$comment->comment_date);
1291                }
1292                if (function_exists("polyglot_init")) {
1293                        $comment_time = apply_filters('the_time',$comment->comment_date);
1294                } else {
1295                        //$comment_time = substr($comment->comment_date,11,5); // 2005-03-09 22:23:53
1296                        $comment_time = mysql2date(get_settings('time_format'),$comment->comment_date); // Thanks to Keith
1297                }
1298                */
1299                $comment_date = mysql2date(get_settings('date_format'),$comment->comment_date);
1300                $comment_time = mysql2date(get_settings('time_format'),$comment->comment_date); // Thanks to Keith
1301
1302                if ($has_gravatar && $comment_author != '') 
1303                {
1304                        if ($md5_cache && array_key_exists($comment->comment_author,$md5_cache)) {
1305                                $gravatar_md5 = $md5_cache[$comment->comment_author];
1306                        } else {
1307                                $gravatar_md5 = md5($comment->comment_author_email);
1308                                $md5_cache[$comment->comment_author_email] = $gravatar_md5; 
1309                        }
1310                        $comment_gravatar_url = "http://www.gravatar.com/avatar.php?" .
1311                                "gravatar_id=$gravatar_md5" .
1312                                $gravatar_options;
1313                               
1314                        $comment_gravatar = "<img src=\"" . $comment_gravatar_url .
1315                                "\" alt=\"\" width=\"$gravatar_size\" height=\"$gravatar_size\" class=\"kjgrcGravatar\" />";
1316                }
1317                #$post = get_postdata($comment->comment_post_ID);
1318                #$post_date = mysql2date(get_settings('date_format'),$post['Date']);
1319                #$post_title = trim(htmlspecialchars(stripslashes($post['Title'])));
1320                #$post = get_postdata($comment->comment_post_ID);
1321                // *** insert cache for post data here
1322                // $post = $wpdb->get_row("SELECT * from $wpdb->posts WHERE ID = $comment->comment_post_ID");
1323                $post = $post_cache[$comment->comment_post_ID];
1324                if (function_exists("polyglot_init")) {
1325                        $post_date = apply_filters('the_date',$post->post_date);
1326                } else {
1327                        $post_date = mysql2date(get_settings('date_format'),$post->post_date);
1328                }
1329                // $post_title = trim(htmlspecialchars(stripslashes($post->post_title)));
1330                $post_title = strip_tags(wptexturize($post->post_title));
1331                if (function_exists("polyglot_init")) {
1332                        $post_title = apply_filters('single_post_title',$post_title);
1333                }
1334                $post_counter = $post->comment_count;
1335
1336                $author_url = $comment->comment_author_url;
1337                if ($author_url == "http://")
1338                        $author_url = "";
1339                if (empty($author_url) || $author_url == "http://")
1340                        $author_url_href = "";
1341
1342                $output = $format;
1343                // Replace tags by values
1344                $output = str_replace("%comment_link",    $comment_link,     $output);
1345                $output = str_replace("%author_url_href", $author_url_href,  $output);
1346                $output = str_replace("%author_url",      $author_url,       $output);
1347                $output = str_replace("%userid",          $comment->user_id, $output);
1348               
1349                $output = str_replace("%gravatar_url",    $comment_gravatar_url, $output);
1350                $output = str_replace("%gravatar",        $comment_gravatar, $output);
1351
1352                // function author_image_path($authorID, $display = true, $type = 'url')
1353                if (function_exists("author_image_path")) {
1354                        $profile_pict = author_image_path($comment->user_id,false,'url');
1355                        $output = str_replace("%profile_picture",  $profile_pict,   $output);
1356                } else {
1357                        $output = str_replace("%profile_picture",  '',   $output);
1358                }
1359
1360                $output = str_replace("%comment_author",  $comment_author,   $output);
1361                $output = str_replace("%comment_date",    $comment_date,     $output);
1362                $output = str_replace("%comment_time",    $comment_time,     $output);
1363
1364               
1365                //$output = str_replace("%time_since",    'time_since_' . $comment->unixdate . ' - ' . gmdate('U') .' = '. ($comment->unixdate-gmdate('U')),    $output);
1366                $utc_time = kjgrc_utc2unixtime($comment->comment_date_gmt); //2006-12-30 17:05:59
1367                $output = str_replace("%time_since",    "<%time_since:$utc_time>",    $output);
1368               
1369                $output = str_replace("%comment_type",    $comment_type,     $output);
1370                $output = str_replace("%post_title",      $post_title,       $output);
1371                $output = str_replace("%post_link",       $post_link,        $output);
1372                $output = str_replace("%post_date",       $post_date,        $output);
1373                $output = str_replace("%post_counter",    $post_counter,     $output);
1374
1375                /*
1376                // Nice idea, but confuses users
1377                //strip title or content?
1378                $visible = strip_tags($output);
1379                if (strpos($visible,'%comment_excerpt') !== false) {
1380                        $comment_excerpt = kjgrc_excerpt($comment_excerpt,$chars_per_comment,$chars_per_word,'%comment_excerpt',$output);
1381                }
1382                elseif (strpos($visible,'%trackback_title') !== false) {
1383                        $trackback_title = kjgrc_excerpt($trackback_title,$chars_per_comment,$chars_per_word,'%trackback_title',$output);
1384                }
1385                */
1386                $comment_excerpt = kjgrc_excerpt($comment_excerpt,$chars_per_comment,$chars_per_word,'%comment_excerpt',$output);
1387                if (kjgrc_get_option("misc","convert_smileys")) {
1388                        if (function_exists("csm_convert") ) {
1389                                $comment_excerpt = csm_convert($comment_excerpt);
1390                        } 
1391                        else {
1392                                if (get_settings('use_smilies')) {
1393                                        $comment_excerpt = convert_smilies($comment_excerpt);
1394                                }
1395                        }
1396                }
1397
1398                $trackback_title = kjgrc_excerpt($trackback_title,$chars_per_comment,$chars_per_word,'%trackback_title',$output);
1399               
1400                $output = str_replace("%comment_excerpt", $comment_excerpt, $output);
1401                $output = str_replace("%trackback_title", $trackback_title, $output);
1402                // Replacement done
1403
1404                //$len = strlen(strip_tags($output));
1405                //$output .= " [$comment_time]";
1406                // . " (" . time_since(strtotime($comment->comment_date_gmt." GMT")) ." ago)";
1407                // *** Das aber nur bei recent comments, nicht bei trackbacks!
1408                // if (kjgrc_get_option("grc","limit_comments_per_post") == 1) {
1409                //      if (count($comment_list[$comment->comment_post_ID]) < kjgrc_get_option("grc","comments_per_post")) {
1410                //              $comment_list[$comment->comment_post_ID][] = $output;
1411                //      }
1412                // } else {
1413                //              $comment_list[$comment->comment_post_ID][] = $output;
1414                // }
1415                $comment_list[$comment->comment_post_ID][] = $output;
1416
1417                if (($post_list == NULL) || ! array_key_exists($comment->comment_post_ID,$post_list)) {
1418                        $post_output = stripslashes(kjgrc_get_option("grc","grouped_by_post_a"));
1419                        $post_output = str_replace("%post_title",         $post_title,         $post_output);
1420                        $post_output = str_replace("%post_link",          $post_link,          $post_output);
1421                        $post_output = str_replace("%post_date",          $post_date,          $post_output);
1422                        $post_output = str_replace("%post_counter",       $post_counter, $post_output);
1423                        $post_list[$comment->comment_post_ID] = $post_output;
1424                }
1425
1426                $all_entries .= "\t$output\n";
1427                if ($caller == 'grc_sample' || $caller ==  'grt_sample') 
1428                        break;
1429        } // foreach comments
1430
1431        if ($grouped_by_post == 1)
1432        {       
1433                $all_entries = '';
1434                foreach (array_keys($post_list) as $post_id) {
1435                        $all_entries .= $post_list[$post_id] . "\n";
1436                        foreach ($comment_list[$post_id] as $tmp) {
1437                                $all_entries .= $tmp ."\n";
1438                        } 
1439                        $all_entries .= kjgrc_get_option("grc","grouped_by_post_b") ."\n";
1440                }
1441        }
1442               
1443        return $all_entries;
1444}
1445
1446function kjgrc_utc2unixtime($utc_time)
1447{
1448        $y = substr($utc_time,0,4);
1449        $m = substr($utc_time,5,2);
1450        $d = substr($utc_time,8,2);
1451        $h = substr($utc_time,11,2);
1452        $min = substr($utc_time,14,2);
1453        $s   = substr($utc_time,17,2);
1454        //mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]])
1455        //$ago = gmdate('U')-$utc_time;
1456        return gmmktime($h,$min,$s,$m,$d,$y);
1457}
1458
1459function kjgrc_format_seconds($seconds)
1460{
1461        $d_str = "days";
1462        $h_str = "hours";
1463        $m_str = "minutes";
1464        $s_str = "seconds";
1465
1466        $d = floor($seconds / (24 * 3600));
1467        if ($d == 1) $d_str = "day";
1468        $seconds = $seconds - ($d * 24 * 3600);
1469       
1470        $h = floor($seconds / 3600);
1471        if ($h == 1) $h_str = "hour";
1472        $seconds = $seconds - ($h * 3600);
1473
1474        $m = floor($seconds / 60);
1475        if ($m == 1) $m_str = "minute";
1476        $seconds = $seconds - ($m * 60);
1477       
1478        $s = $seconds;
1479        if ($s == 1) $s_str = "second";
1480       
1481        if ($d > 0) return "$d $d_str $h $h_str";
1482        if ($h > 0) return "$h $h_str $m $m_str";
1483        if ($m > 0) return "$m $m_str $s $s_str";
1484        return "$s $s_str";
1485}
1486
1487function kjgrc_excerpt ($text,$chars_per_comment,$chars_per_word,$tag,$output)
1488{
1489        $length = strlen(str_replace($tag,"",strip_tags($output)));
1490        $length = $chars_per_comment - $length;
1491        $length = $length -2; // we will add three dots at the end
1492        if ($length < 0) $length = 0;
1493        if (strlen($text) > $length) {
1494                $text = substr($text,0,$length);
1495                $text = substr($text,0,strrpos($text,' '));
1496                // last word exceeds max word length:
1497                if ((strlen($text) - strrpos($text,' ')) > $chars_per_word) {
1498                        $text = substr($text,0,strlen($text)-3);
1499                } 
1500                $text = $text . "...";
1501        }
1502        #$text = "[EXCERPT]: '$text'";
1503        return "$text";
1504}
1505
1506function widget_kj_get_recent_comments_init() {
1507        if (! function_exists("register_sidebar_widget")) {
1508                return;
1509        }
1510        function widget_get_recent_comments($args) {
1511                global $kjgrc_we_are_a_widget,$kjgrc_widget_args;
1512                $kjgrc_we_are_a_widget = TRUE;
1513                $kjgrc_widget_args = $args;
1514                get_recent_comments();
1515        }
1516        function widget_get_recent_comments_control() {
1517                global $kjgrc_we_are_a_widget;
1518                $kjgrc_we_are_a_widget = TRUE;
1519                if ( $_POST['get_recent_comments-submit'] ) {
1520                        kjgrc_set_option("grc_sidebar_title",stripslashes($_POST['get_recent_comments-title']));
1521                        kjgrc_invalidate_cache();
1522                }
1523                echo '<p style="text-align:right;"><label for="get_recent_comments-title">Title: <input style="width: 200px;" id="get_recent_comments-title" name="get_recent_comments-title" type="text" value="'.kjgrc_get_option("grc","sidebar_title").'" /></label></p>';
1524                echo '<input type="hidden" id="get_recent_comments-submit" name="get_recent_comments-submit" value="1" />';
1525                echo 'More options are on the <a href="options-general.php?page=get-recent-comments.php&amp;subpage=1">plugin page</a>.';
1526        }
1527        register_sidebar_widget('Get Recent Comments', 'widget_get_recent_comments');
1528        register_widget_control('Get Recent Comments', 'widget_get_recent_comments_control', 300, 100);
1529}
1530
1531function widget_kj_get_recent_trackbacks_init() {
1532        if (! function_exists("register_sidebar_widget")) {
1533                return;
1534        }
1535        function widget_get_recent_trackbacks($args) {
1536                global $kjgrc_we_are_a_widget,$kjgrc_widget_args;;
1537                $kjgrc_we_are_a_widget = TRUE;
1538                $kjgrc_widget_args = $args;
1539                get_recent_trackbacks();
1540        }
1541        function widget_get_recent_trackbacks_control() {
1542                global $kjgrc_we_are_a_widget;
1543                $kjgrc_we_are_a_widget = TRUE;
1544                if ( $_POST['get_recent_trackbacks-submit'] ) {
1545                        kjgrc_set_option("grt_sidebar_title",stripslashes($_POST['get_recent_trackbacks-title']));
1546                        kjgrc_invalidate_cache();
1547                }
1548                echo '<p style="text-align:right;"><label for="get_recent_trackbacks-title">Title: <input style="width: 200px;" id="get_recent_trackbacks-title" name="get_recent_trackbacks-title" type="text" value="'.kjgrc_get_option("grt","sidebar_title").'" /></label></p>';
1549                echo '<input type="hidden" id="get_recent_trackbacks-submit" name="get_recent_trackbacks-submit" value="1" />';
1550                echo 'More options are on the <a href="options-general.php?page=get-recent-comments.php&amp;subpage=2">plugin page</a>.';
1551        }
1552       
1553        register_sidebar_widget('Get Recent Trackbacks', 'widget_get_recent_trackbacks');
1554        register_widget_control('Get Recent Trackbacks', 'widget_get_recent_trackbacks_control', 300, 100);
1555}
1556
1557add_action('admin_menu', 'kjgrc_add_options_page');
1558add_action('edit_comment','kjgrc_invalidate_cache');
1559add_action('delete_comment','kjgrc_invalidate_cache');
1560add_action('edit_post','kjgrc_invalidate_cache');
1561add_action('delete_post','kjgrc_invalidate_cache');
1562add_action('publish_post','kjgrc_invalidate_cache');
1563add_action('switch_theme', 'kjgrc_invalidate_cache');
1564add_action('wp_set_comment_status','kjgrc_invalidate_cache');
1565add_action('comment_post','kjgrc_handle_new_comment');
1566add_action('trackback_post','kjgrc_handle_new_comment');
1567add_action('pingback_post','kjgrc_handle_new_comment');
1568add_action('plugins_loaded', 'widget_kj_get_recent_comments_init');
1569add_action('plugins_loaded', 'widget_kj_get_recent_trackbacks_init');
1570
1571?>
Note: See TracBrowser for help on using the browser.