diff -r -u geeklog-1.3.11/public_html/docs/plugin.html geeklog-patched/public_html/docs/plugin.html
--- geeklog-1.3.11/public_html/docs/plugin.html Fri Dec 31 10:03:28 2004
+++ geeklog-patched/public_html/docs/plugin.html Sat Jan 15 01:47:55 2005
@@ -384,6 +384,10 @@
This function should return the actual new entries to be listed in the What's New block (as an array) or a string to be displayed in case there are no new entries. |
+
+
+ If a plugin supports comments and defines this function then its new comments can be reported in the What’s New block. Each comment is associated with some item defined by the plugin; those items are identified by a unique value stored in the sid column of the comments table. sid values from the comments table are passed to this function, which should return a two-element array consisting of the plugin item’s title and the URL for the page showing the item’s comments; the function should return false if the item should not be displayed (e.g., the user does not have permission to see it). |
+
diff -r -u geeklog-1.3.11/public_html/lib-common.php geeklog-patched/public_html/lib-common.php
--- geeklog-1.3.11/public_html/lib-common.php Fri Dec 31 10:03:30 2004
+++ geeklog-patched/public_html/lib-common.php Sat Jan 15 01:47:55 2005
@@ -4636,100 +4636,105 @@
}
}
+ $whatsnew_comment_plugs = array();
+ if( $_CONF['hidenewplugins'] == 0 )
+ {
+ $whatsnew_comment_plugs = PLG_supportingWhatsNewComments();
+ }
+
+ // Always show article and poll comments
+ $whatsnew_comment_plugs[] = 'article';
+ $whatsnew_comment_plugs[] = 'poll';
+
if( $_CONF['hidenewcomments'] == 0 )
{
// Go get the newest comments
$retval .= '' . $LANG01[83] . ' ' . $LANG01[85] . '
';
- $stwhere = '';
-
- if( !empty( $_USER['uid'] ))
- {
- $stwhere .= "({$_TABLES['stories']}.owner_id IS NOT NULL AND {$_TABLES['stories']}.perm_owner IS NOT NULL) OR ";
- $stwhere .= "({$_TABLES['stories']}.group_id IS NOT NULL AND {$_TABLES['stories']}.perm_group IS NOT NULL) OR ";
- $stwhere .= "({$_TABLES['stories']}.perm_members IS NOT NULL)";
- }
- else
- {
- $stwhere .= "({$_TABLES['stories']}.perm_anon IS NOT NULL)";
- }
-
- $powhere = '';
-
- if( !empty( $_USER['uid'] ))
- {
- $powhere .= "({$_TABLES['pollquestions']}.owner_id IS NOT NULL AND {$_TABLES['pollquestions']}.perm_owner IS NOT NULL) OR ";
- $powhere .= "({$_TABLES['pollquestions']}.group_id IS NOT NULL AND {$_TABLES['pollquestions']}.perm_group IS NOT NULL) OR ";
- $powhere .= "({$_TABLES['pollquestions']}.perm_members IS NOT NULL)";
- }
- else
- {
- $powhere .= "({$_TABLES['pollquestions']}.perm_anon IS NOT NULL)";
- }
-
- $sql = "SELECT DISTINCT count(*) AS dups, type, question, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid, qid, max({$_TABLES['comments']}.date) as lastdate FROM {$_TABLES['comments']} LEFT JOIN {$_TABLES['stories']} ON (({$_TABLES['stories']}.sid = {$_TABLES['comments']}.sid)" . COM_getPermSQL( 'AND', 0, 2, $_TABLES['stories'] ) . " AND ({$_TABLES['stories']}.draft_flag = 0)" . $topicsql . ") LEFT JOIN {$_TABLES['pollquestions']} ON ((qid = {$_TABLES['comments']}.sid)" . COM_getPermSQL( 'AND', 0, 2, $_TABLES['pollquestions'] ) . ") WHERE ({$_TABLES['comments']}.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) AND ((({$stwhere})) OR (({$powhere}))) GROUP BY {$_TABLES['comments']}.sid ORDER BY 7 DESC LIMIT 15";
+ $sql = "SELECT DISTINCT COUNT(*) AS dups, sid, type, MAX(date) as lastdate " .
+ "FROM {$_TABLES['comments']} " .
+ "WHERE date >= DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND) " .
+ "AND type in ( '" . implode("','", $whatsnew_comment_plugs) . "' ) " .
+ "GROUP BY sid " .
+ "ORDER BY lastdate DESC";
$result = DB_query( $sql );
$nrows = DB_numRows( $result );
- if( $nrows > 0 )
+ $newcomments = array();
+
+ for( $x = 1; $x <= $nrows && count($newcomments) < 15; $x++ )
{
- $newcomments = array();
+ $A = DB_fetchArray( $result );
- for( $x = 1; $x <= $nrows; $x++ )
+ switch( $A['type'] )
{
- $A = DB_fetchArray( $result );
-
- if(( $A['type'] == 'article' ) || empty( $A['type'] ))
- {
- $itemlen = strlen( $A['title'] );
- $titletouse = stripslashes( $A['title'] );
- $urlstart = ' 20 )
- {
- $urlstart .= ' title="' . htmlspecialchars( $titletouse ) . '">';
- }
- else
- {
- $urlstart .= '>';
- }
-
- // Trim the length if over 20 characters
- if( $itemlen > 20 )
- {
- $titletouse = substr( $titletouse, 0, 17 );
- $acomment = str_replace( '$', '$', $titletouse ) . '...';
- $acomment = str_replace( ' ', ' ', $acomment );
-
- if( $A['dups'] > 1 )
- {
- $acomment .= ' [+' . $A['dups'] . ']';
+ case 'article':
+ $titletouse = DB_getItem($_TABLES['stories'], 'title', "sid = '" . $A['sid'] . "' AND draft_flag = 0 " .
+ $topicsql . COM_getPermSQL('AND', 0, 2));
+ if ( ! empty($titletouse)) {
+ $titletouse = stripslashes($titletouse);
+ $rawurl = $_CONF['site_url'] . '/article.php?story=' . $A['sid'];
+ $show_item = true;
+ } else {
+ $show_item=false;
+ }
+ break;
+ case 'poll':
+ $titletouse = DB_getItem($_TABLES['pollquestions'], 'question', "qid = '" . $A['sid'] . "'" .
+ COM_getPermSQL('AND', 0, 2));
+ if ( ! empty($titletouse)) {
+ $rawurl = $_CONF['site_url'] . '/pollbooth.php?qid=' . $A['sid'] . '&aid=-1';
+ $show_item = true;
+ } else {
+ $show_item=false;
}
- }
- else
- {
- $acomment = str_replace( '$', '$', $titletouse );
- $acomment = str_replace( ' ', ' ', $acomment );
-
- if( $A['dups'] > 1 )
- {
- $acomment .= ' [+' . $A['dups'] . ']';
+ break;
+ default:
+ $title_url = PLG_getWhatsNewCommentsInfo($A['type'], $A['sid']);
+ if (is_array($title_url)) {
+ list ($titletouse, $rawurl) = $title_url;
+ $show_item = true;
+ } else {
+ $show_item = false;
}
- }
+ break;
+ }
+
+ // If the item should not be shown (user doesn't have permission, etc.)
+ // then skip to the next one.
+ if ( ! $show_item) { continue; }
+
+ $urlstart = ' 20 )
+ {
+ $urlstart .= ' title="' . htmlspecialchars( $titletouse ) . '">';
+ }
+ else
+ {
+ $urlstart .= '>';
+ }
+
+ // Trim the length if over 20 characters
+ if( strlen($titletouse) > 20 )
+ {
+ $titletouse = htmlspecialchars( substr( $titletouse, 0, 17 ) );
+ $titletouse .= '…';
+ }
+ $acomment = str_replace( '$', '$', $titletouse );
+ $acomment = str_replace( ' ', ' ', $acomment );
- $newcomments[] = $urlstart . $acomment . '';
+ if( $A['dups'] > 1 )
+ {
+ $acomment .= ' [+' . $A['dups'] . ']';
}
+ $newcomments[] = $urlstart . $acomment . '';
+ }
+
+ if( count($newcomments) > 0 )
+ {
$retval .= COM_makeList( $newcomments, 'list-new-comments' );
}
else
diff -r -u geeklog-1.3.11/system/lib-plugins.php geeklog-patched/system/lib-plugins.php
--- geeklog-1.3.11/system/lib-plugins.php Fri Dec 31 10:02:22 2004
+++ geeklog-patched/system/lib-plugins.php Sat Jan 15 01:47:55 2005
@@ -1213,6 +1213,52 @@
}
/**
+* Prepare a list of all plugins that support the What's New block's comment section.
+* A plugin supports What's New comments if it supports comments, What's New and has
+* a 'getnewcommentsinfo' function.
+*
+* @return array array of plugin names (can be empty)
+*
+*/
+function PLG_supportingWhatsNewComments ()
+{
+ global $_TABLES;
+
+ $plugins = array ();
+
+ $result = DB_query ("SELECT pi_name FROM {$_TABLES['plugins']} WHERE pi_enabled = 1");
+ $nrows = DB_numRows ($result);
+ for ($i = 0; $i < $nrows; $i++) {
+ $A = DB_fetchArray ($result);
+ $fn_head = 'plugin_whatsnewsupported_' . $A['pi_name'];
+ if (function_exists ($fn_head)) {
+ if (is_array ( $fn_head() )) {
+ $fn_getnewcommentsinfo = 'plugin_getnewcommentsinfo_' . $A['pi_name'];
+ if (PLG_supportsComments($A['pi_name']) && function_exists($fn_getnewcommentsinfo)) {
+ $plugins[] = $A['pi_name'];
+ }
+ }
+ }
+ }
+
+ return $plugins;
+}
+
+/**
+ * Get the title and URL of an object which can have comments associated with it.
+ *
+ * @param $type the plugin that owns the object
+ * @param $id the object's unique identifier
+ *
+ * @return array A two-item string array containing the title of the item and its raw URL.
+ */
+function PLG_getWhatsNewCommentsInfo($type, $id)
+{
+ $args[1] = $id;
+ return PLG_callFunctionForOnePlugin('plugin_getnewcommentsinfo_' . $type, $args);
+}
+
+/**
* Allows plugins and Core GL Components to filter out spam.
* The SPAMX Plugin is now part of the Geeklog Distribution
* This plugin API will call the main function in the SPAMX plugin