Welcome to Geeklog, Anonymous Sunday, December 22 2024 @ 01:22 am EST
Geeklog Forums
What's New: Journal Comments
Status: offline
THEMike
Forum User
Moderator
Registered: 07/25/03
Posts: 141
Location:Sheffield, UK
Hi, I've just created the required functions for the journal plugin to display new comments in the what's new block, see it in action on the front page of my site (click the profile link, my domain name gets censored).
The changes are in my (extensive) hacks to the Journal plugin, but should work with the core journal plugins so here they are:
Or you can grab my extended/enhanced/altered version of the journal plugin from CVS here:
http://sourceforge.net/projects/fbglplugins
(no packages released, it's still not 'done', but it is working on my site ;-))
The changes are in my (extensive) hacks to the Journal plugin, but should work with the core journal plugins so here they are:
/**
* This function tells Geeklog that we support the "What's New" api
* @return array with main title and subtitle, populated intellegently
* @author Mike Jervis (mike AT *censored*ingbrit DOT com)
*/
function plugin_whatsnewsupported_journal() {
global $_CONF, $LANG01;
$hours = $_CONF['newcommentsinterval'] / 60 / 60;
return array("JOURNAL $LANG01[83]","last $hours hours");
}
/**
* This function provides the content of our "What's New" feed for the
* new "What's New" API in geeklog 1.3.9 or better
* @return array of items (links to journal entries)
* @author Mike Jervis (mike AT *censored*ingbrit DOT com)
*/
function plugin_getwhatsnew_journal() {
global $_TABLES, $_CONF, $LANG01;
$sql = "SELECT DISTINCT count( * ) AS dups, type, "
."{$_TABLES['journal_entry']}.je_summary, {$_TABLES['comments']}.sid, "
."{$_TABLES['comments']}.title, "
."{$_TABLES['journal_entry']}.je_jrn_id, max( {$_TABLES['comments']}.date )"
." AS lastdate FROM {$_TABLES['comments']} LEFT JOIN "
."{$_TABLES['journal_entry']} ON ( ( {$_TABLES['journal_entry']}.je_id "
."= {$_TABLES['comments']}.sid ) AND ( {$_TABLES['journal_entry']}."
."je_public = 1 ) ) WHERE ( {$_TABLES['comments']}.date >= ( DATE_SUB( "
."NOW( ) , INTERVAL {$_CONF['newcommentsinterval']} SECOND ) ) ) "
."AND {$_TABLES['comments']}.type='journal' GROUP BY "
."{$_TABLES['comments']}.sid ORDER BY lastdate DESC LIMIT 15 ";
$result = DB_query( $sql );
$nrows = DB_numRows( $result );
if( $nrows == 0 )
{
$retval .= $LANG01[86] . '
' . LB;
} else {
$items = array();
for( $i = 0; $i
{
$item = DB_fetchArray( $result );
$str = "
."&type=entry&je_id={$item['sid']}#comments">";
if( $item['je_summary'] != '' )
{
$str .= stripslashes( $item['je_summary'] );
} else {
$str .= stripslashes( $item['title'] );
}
if( $item['dups'] > 1 ) { $str .= "[+{$item['dups']}]"; }
$str .= '';
$items[] = $str;
}
return $items;
}
}
Or you can grab my extended/enhanced/altered version of the journal plugin from CVS here:
http://sourceforge.net/projects/fbglplugins
(no packages released, it's still not 'done', but it is working on my site ;-))
7
5
Quote
Status: offline
Blaine
Forum User
Moderator
Registered: 07/16/02
Posts: 1232
Location:Canada
Quote by THEMike: hmm Well I thought I'd correctly escaped the HTML parts of the string that is built for posting here, but I guess not. CVS is your best bet then. Silly forum software.
Why do you not use the CODE BB Tag the forum supports Silly Member
As in this example:
Text Formatted Code
function COM_whatsNewBlock( $help='', $title='' )
{
global $_TABLES, $_CONF, $LANG01, $_USER, $_GROUPS, $page, $newstories;
$retval = COM_startBlock( $title, $help,
COM_getBlockTemplate( 'whats_new_block', 'header' ));
$topicsql = '';
if(( $_CONF['hidenewstories'] == 0 ) || ( $_CONF['hidenewcomments'] == 0 ))
{
$tresult = DB_query( "SELECT tid FROM {$_TABLES['topics']}"
. COM_getPermSQL() );
$trows = DB_numRows( $tresult );
if( $trows > 0 )
{
$tids = array();
for( $i = 0; $i < $trows; $i++ )
{
$T = DB_fetchArray( $tresult );
$tids[] = $T['tid'];
}
if( sizeof( $tids ) > 0 )
{
$topicsql = " AND (tid IN ('" . implode( "','", $tids ) . "'))";
}
}
}
if( $_CONF['hidenewstories'] == 0 )
{
// Find the newest stories
$sql = "SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) AND (date <= NOW()) AND (draft_flag = 0)" . COM_getPermSQL( 'AND' ) . $topicsql;
$result = DB_query( $sql );
$A = DB_fetchArray( $result );
$nrows = $A['count'];
if( empty( $title ))
{
$title = DB_getItem( $_TABLES['blocks'], 'title', "name='whats_new_block'" );
}
// Any late breaking news stories?
$retval .= '<b>' . $LANG01[99] . '</b><br>';
if( $nrows > 0 )
{
$hours = (( $_CONF['newstoriesinterval'] / 60 ) / 60 );
if( $nrows == 1 )
{
$newmsg = '1 ' . $LANG01[81] . ' ' . $hours . ' ' . $LANG01[82];
if ($newstories && ($page < 2))
{
$retval .= $newmsg . '<br>';
}
else
{
$retval .= '<a href="' . $_CONF['site_url']
. '/index.php?display=new">' . $newmsg . '</a><br>';
}
}
else
{
$newmsg = $nrows . ' ' . $LANG01[80] . ' ' . $hours . ' '
. $LANG01[82];
if ($newstories && ($page < 2))
{
$retval .= $newmsg . '<br>';
}
else
{
$retval .= '<a href="' . $_CONF['site_url']
. '/index.php?display=new">' . $newmsg . '</a><br>';
}
}
}
else
{
$retval .= $LANG01[100] . '<br>';
}
$retval .= '<br>';
}
if( $_CONF['hidenewcomments'] == 0 )
{
// Go get the newest comments
$retval .= '<b>' . $LANG01[83] . '</b> <small>' . $LANG01[85] . '</small><br>';
$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";
$result = DB_query( $sql );
$nrows = DB_numRows( $result );
if( $nrows > 0 )
{
$newcomments = array();
for( $x = 1; $x <= $nrows; $x++ )
{
$A = DB_fetchArray( $result );
if(( $A['type'] == 'article' ) || empty( $A['type'] ))
{
$itemlen = strlen( $A['title'] );
$titletouse = stripslashes( $A['title'] );
$urlstart = '<a href="' . COM_buildUrl( $_CONF['site_url']
. '/article.php?story=' . $A['sid'] . '#comments' ) . '"';
}
else if( $A['type'] == 'poll' )
{
$itemlen = strlen( $A['question'] );
$titletouse = $A['question'];
$urlstart = '<a href="' . $_CONF['site_url'] . '/pollbooth.php?qid=' . $A['qid'] . '&aid=-1#comments"';
}
if( $itemlen > 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'] . ']';
}
}
else
{
$acomment = str_replace( '$', '$', $titletouse );
$acomment = str_replace( ' ', ' ', $acomment );
if( $A['dups'] > 1 )
{
$acomment .= ' [+' . $A['dups'] . ']';
}
}
$newcomments[] = $urlstart . $acomment . '</a>';
}
$retval .= COM_makeList( $newcomments );
}
else
{
$retval .= $LANG01[86] . '<br>' . LB;
}
$retval .= '<br>';
}
if( $_CONF['hidenewlinks'] == 0 )
{
// Get newest links
$retval .= '<b>' . $LANG01[84] . '</b> <small>' . $LANG01[87] . '</small><br>';
$sql = "SELECT lid,title,url FROM {$_TABLES['links']}"
. COM_getPermSQL() . ' ORDER BY lid DESC LIMIT 15';
$foundone = 0;
$now = time();
$desired = $now - $_CONF['newlinksinterval'];
$result = DB_query( $sql );
$nrows = DB_numRows( $result );
if( $nrows > 0 )
{
$newlinks = array();
for( $x = 1; $x <= $nrows; $x++ )
{
$A = DB_fetchArray( $result );
$A['title'] = stripslashes( $A['title'] );
// Need to reparse the date from the link id
$myyear = substr( $A['lid'], 0, 4 );
$mymonth = substr( $A['lid'], 4, 2 );
$myday = substr( $A['lid'], 6, 2 );
$myhour = substr( $A['lid'], 8, 2 );
$mymin = substr( $A['lid'], 10, 2 );
$mysec = substr( $A['lid'], 12, 2 );
$newtime = "{$mymonth}/{$myday}/{$myyear} {$myhour}:{$mymin}:{$mysec}";
$convtime = strtotime( $newtime );
if( $convtime > $desired )
{
$foundone = 1;
// redirect link via portal.php so we can count the clicks
$lcount = $_CONF['site_url']
. '/portal.php?what=link&item=' . $A['lid'];
// Trim the length if over 16 characters
$itemlen = strlen( $A['title'] );
if( $itemlen > 16 )
{
$newlinks [] = '<a href="' . $lcount . '" title="'
. $A['title'] . '">' . substr( $A['title'], 0, 16 )
. '...</a>' . LB;
}
else
{
$newlinks[] = '<a href="' . $lcount . '">'
. substr( $A['title'], 0, $itemlen ) . '</a>' . LB;
}
}
}
}
if( $foundone == 0 )
{
$retval .= $LANG01[88] . '<br>' . LB;
}
else
{
$retval .= COM_makeList( $newlinks );
}
}
if( $_CONF['hidenewplugins'] == 0 )
{
list( $headlines, $bylines, $content ) = PLG_getWhatsNew();
$plugins = sizeof( $headlines );
if( $plugins > 0 )
{
for( $i = 0; $i < $plugins; $i++ )
{
$retval .= '<br>';
$retval .= '<b>' . $headlines[$i] . '</b> <small>'
. $bylines[$i] . '</small><br>';
if( is_array( $content[$i] ))
{
$retval .= COM_makeList( $content[$i] );
}
else
{
$retval .= $content[$i] . '<br>' . LB;
}
}
}
}
$retval .= COM_endBlock( COM_getBlockTemplate( 'whats_new_block', 'footer' ));
return $retval;
}
Geeklog components by PortalParts -- www.portalparts.com
6
9
Quote
Status: offline
THEMike
Forum User
Moderator
Registered: 07/25/03
Posts: 141
Location:Sheffield, UK
Text Formatted Code
/**
* This function tells Geeklog that we support the "What's New" api
* @return array with main title and subtitle, populated intellegently
* @author Mike Jervis (mike AT *censored*ingbrit DOT com)
*/
function plugin_whatsnewsupported_journal() {
global $_CONF, $LANG01;
$hours = $_CONF['newcommentsinterval'] / 60 / 60;
return array("JOURNAL $LANG01[83]","last $hours hours");
}
/**
* This function provides the content of our "What's New" feed for the
* new "What's New" API in geeklog 1.3.9 or better
* @return array of items (links to journal entries)
* @author Mike Jervis (mike AT *censored*ingbrit DOT com)
*/
function plugin_getwhatsnew_journal() {
global $_TABLES, $_CONF, $LANG01;
$sql = "SELECT DISTINCT count( * ) AS dups, type, "
."{$_TABLES['journal_entry']}.je_summary, {$_TABLES['comments']}.sid, "
."{$_TABLES['comments']}.title, "
."{$_TABLES['journal_entry']}.je_jrn_id, max( {$_TABLES['comments']}.date )"
." AS lastdate FROM {$_TABLES['comments']} LEFT JOIN "
."{$_TABLES['journal_entry']} ON ( ( {$_TABLES['journal_entry']}.je_id "
."= {$_TABLES['comments']}.sid ) AND ( {$_TABLES['journal_entry']}."
."je_public = 1 ) ) WHERE ( {$_TABLES['comments']}.date >= ( DATE_SUB( "
."NOW( ) , INTERVAL {$_CONF['newcommentsinterval']} SECOND ) ) ) "
."AND {$_TABLES['comments']}.type='journal' GROUP BY "
."{$_TABLES['comments']}.sid ORDER BY lastdate DESC LIMIT 15 ";
$result = DB_query( $sql );
$nrows = DB_numRows( $result );
if( $nrows == 0 )
{
$retval .= $LANG01[86] . '<br>' . LB;
} else {
$items = array();
for( $i = 0; $i < $nrows; $i++ )
{
$item = DB_fetchArray( $result );
$str = "<a href="{$_CONF['site_url']}/journal/index.php?mode=read"
."&type=entry&je_id={$item['sid']}#comments">";
if( $item['je_summary'] != '' )
{
$str .= stripslashes( $item['je_summary'] );
} else {
$str .= stripslashes( $item['title'] );
}
if( $item['dups'] > 1 ) { $str .= "[+{$item['dups']}]"; }
$str .= '</a>';
$items[] = $str;
}
return $items;
}
}
Last time I tried using BB tags in this forum, funny things happened. Mind, that was a long time ago.
7
13
Quote
All times are EST. The time is now 01:22 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content