diff -ru geeklog-1.3.9/public_html/lib-common.php geeklog-1.3.9-patched/public_html/lib-common.php
--- geeklog-1.3.9/public_html/lib-common.php Sun Mar 14 14:42:41 2004
+++ geeklog-1.3.9-patched/public_html/lib-common.php Fri Apr 9 21:36:23 2004
@@ -4230,100 +4230,104 @@
$retval .= '
';
}
+ $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', "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', COM_getPermSQL('', 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 doens'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 );
}
else
diff -ru geeklog-1.3.9/system/lib-plugins.php geeklog-1.3.9-patched/system/lib-plugins.php
--- geeklog-1.3.9/system/lib-plugins.php Sun Mar 14 14:42:35 2004
+++ geeklog-1.3.9-patched/system/lib-plugins.php Fri Apr 9 21:36:45 2004
@@ -215,6 +215,34 @@
}
/**
+* Returns a list of plugins whose comments should appear in the What's New
+* block's Comments section.
+*
+* @return array string array of plugins that support the What's New
+* block's comment section
+*
+*/
+function PLG_getWhatsNewCommentPlugs($type)
+{
+ global $_TABLES;
+
+ $plugins = array();
+
+ $result = DB_query("SELECT pi_name FROM {$_TABLES['plugins']} WHERE pi_enabled = 1");
+ $nrows = DB_numRows($result);
+ for ($i = 1; $i <= $nrows; $i++) {
+ $A = DB_fetchArray($result);
+ $function = 'plugin_searchtypes_' . $A['pi_name'];
+ if (PLG_supportsComments($A['pi_name']) && function_exists($function)) {
+ //great, stats function is there, call it
+ $cur_types = $function();
+ $types = array_merge($types, $cur_types);
+ } // no else because this is not a required API function
+ }
+ return PLG_callFunctionForOnePlugin('plugin_commentsupport_' . $type);
+}
+
+/**
* Plugin should perform an operation on one of its comments.
*
* @param string $type Plugin to have handle the comment
@@ -976,6 +1004,52 @@
}
return array ($newheadlines, $newbylines, $newcontent);
+}
+
+/**
+* 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);
}
?>