[geeklog-cvs] geeklog: Added support for plugins to show comments in the What'...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Tue Mar 9 19:08:49 EST 2010
changeset 7770:bf42ac6ef2d4
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/bf42ac6ef2d4
user: Tom <websitemaster at cogeco.net>
date: Tue Mar 09 18:47:08 2010 -0500
description:
Added support for plugins to show comments in the What's New Block
diffstat:
public_html/lib-common.php | 98 ++++++++++++++++++++++++++++++-------------------
system/lib-plugins.php | 45 ++++++++++++++++++++++
2 files changed, 105 insertions(+), 38 deletions(-)
diffs (171 lines):
diff -r 25ccc280f368 -r bf42ac6ef2d4 public_html/lib-common.php
--- a/public_html/lib-common.php Thu Feb 25 14:08:52 2010 -0500
+++ b/public_html/lib-common.php Tue Mar 09 18:47:08 2010 -0500
@@ -4290,52 +4290,74 @@
$sql['mysql'] = "SELECT DISTINCT COUNT(*) AS dups, type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid, 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) AND ({$_TABLES['stories']}.commentcode >= 0)" . $topicsql . COM_getLangSQL( 'sid', 'AND', $_TABLES['stories'] ) . ") WHERE ({$_TABLES['comments']}.date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) AND ((({$stwhere}))) GROUP BY {$_TABLES['comments']}.sid,type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid ORDER BY 5 DESC LIMIT 15";
$sql['pgsql'] = "SELECT DISTINCT COUNT(*) AS dups, type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid, 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) AND ({$_TABLES['stories']}.commentcode >= 0)" . $topicsql . COM_getLangSQL( 'sid', 'AND', $_TABLES['stories'] ) . ") WHERE ({$_TABLES['comments']}.date >= (NOW()+ INTERVAL '{$_CONF['newcommentsinterval']} SECOND')) AND ((({$stwhere}))) GROUP BY {$_TABLES['comments']}.sid,type, {$_TABLES['stories']}.title, {$_TABLES['stories']}.title, {$_TABLES['stories']}.sid ORDER BY 5 DESC LIMIT 15";
- $result = DB_query( $sql );
-
- $nrows = DB_numRows( $result );
-
- if( $nrows > 0 )
- {
+ $result = DB_query($sql);
+ $nrows = DB_numRows($result);
+ $new_plugin_comments= array();
+ if ($nrows > 0) {
+ for ($x = 0; $x < $nrows; $x++) {
+ $new_plugin_comments[] = DB_fetchArray($result);
+ }
+ }
+
+ $new_plugin_comments = array_merge(PLG_getWhatsNewComment(), $new_plugin_comments);
+
+ if( !empty($new_plugin_comments) ) {
+ // Sort array by element lastdate newest to oldest
+ foreach($new_plugin_comments as $k=>$v) {
+ $b[$k] = strtolower($v['lastdate']);
+ }
+ arsort($b);
+ foreach($b as $key=>$val) {
+ $temp[] = $new_plugin_comments[$key];
+ }
+ $new_plugin_comments = $temp;
+
$newcomments = array();
-
- for( $x = 0; $x < $nrows; $x++ )
- {
- $A = DB_fetchArray( $result );
-
- if(( $A['type'] == 'article' ) || empty( $A['type'] ))
- {
+ $count = 0;
+ foreach ($new_plugin_comments as $A) {
+ $count .= +1;
+ $url = '';
+ if(( $A['type'] == 'article' ) || empty( $A['type'] )) {
$url = COM_buildUrl( $_CONF['site_url']
. '/article.php?story=' . $A['sid'] ) . '#comments';
- }
-
- $title = COM_undoSpecialChars( stripslashes( $A['title'] ));
- $titletouse = COM_truncate( $title, $_CONF['title_trim_length'],
- '...' );
- if( $title != $titletouse )
- {
- $attr = array('title' => htmlspecialchars($title));
- }
- else
- {
- $attr = array();
- }
- $acomment = str_replace( '$', '$', $titletouse );
- $acomment = str_replace( ' ', ' ', $acomment );
-
- if( $A['dups'] > 1 )
- {
- $acomment .= ' [+' . $A['dups'] . ']';
- }
-
- $newcomments[] = COM_createLink($acomment, $url, $attr);
+ } else {
+ $info = PLG_getItemInfo($A['type'], $A['sid'], 'url');
+ if (!(empty($info))) {
+ //$url = COM_createLink($info[0], $info[1]); //, array('title' => $excerpt));
+ $url = $info . '#comments';
+ }
+ }
+ // Check to see if url (plugin may not support PLG_getItemInfo
+ if (!(empty($url))) {
+ $title = COM_undoSpecialChars( stripslashes( $A['title'] ));
+ $titletouse = COM_truncate( $title, $_CONF['title_trim_length'],
+ '...' );
+ if( $title != $titletouse ) {
+ $attr = array('title' => htmlspecialchars($title));
+ } else {
+ $attr = array();
+ }
+ $acomment = str_replace( '$', '$', $titletouse );
+ $acomment = str_replace( ' ', ' ', $acomment );
+
+ if( $A['dups'] > 1 ) {
+ $acomment .= ' [+' . $A['dups'] . ']';
+ }
+
+ $newcomments[] = COM_createLink($acomment, $url, $attr);
+
+ if ($count == 15) {
+ break;
+ }
+ }
+
}
$retval .= COM_makeList( $newcomments, 'list-new-comments' );
- }
- else
- {
+ } else {
$retval .= $LANG01[86] . '<br' . XHTML . '>' . LB;
}
+
if(( $_CONF['hidenewplugins'] == 0 )
|| ( $_CONF['trackback_enabled']
&& ( $_CONF['hidenewtrackbacks'] == 0 )))
diff -r 25ccc280f368 -r bf42ac6ef2d4 system/lib-plugins.php
--- a/system/lib-plugins.php Thu Feb 25 14:08:52 2010 -0500
+++ b/system/lib-plugins.php Tue Mar 09 18:47:08 2010 -0500
@@ -1936,6 +1936,51 @@
return array($newheadlines, $newbylines, $newcontent);
}
+
+/**
+* Ask plugins if they want to add new comments to Geeklog's What's New block.
+*
+* @return array $whatsnew
+*
+*/
+function PLG_getWhatsNewComment()
+{
+ global $_PLUGINS;
+
+ $whatsnew= array();
+
+ foreach ($_PLUGINS as $pi_name) {
+ $fn_head = 'plugin_whatsnewsupported_' . $pi_name;
+ if (function_exists($fn_head)) {
+ $supported = $fn_head();
+ if (is_array($supported)) {
+ list($headline, $byline) = $supported;
+
+ $fn_new = 'plugin_getwhatsnewcomment_' . $pi_name;
+ if (function_exists($fn_new)) {
+ $whatsnew = array_merge($fn_new (), $whatsnew);
+ }
+ }
+ }
+ }
+
+ $fn_head = 'CUSTOM_whatsnewsupported';
+ if (function_exists($fn_head)) {
+ $supported = $fn_head();
+ if (is_array($supported)) {
+ list($headline, $byline) = $supported;
+
+ $fn_new = 'CUSTOM_getwhatsnewcomment';
+ if (function_exists($fn_new)) {
+ $whatsnew = array_merge($fn_new (), $whatsnew);
+ }
+ }
+ }
+
+ return $whatsnew;
+
+}
+
/**
* Allows plugins and Core Geeklog Components to filter out spam.
*
More information about the geeklog-cvs
mailing list