ulfben

get-recent-comments patch

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