glFusion Wiki

Site Tools


glfusion:development:pluginapi:whatnew

plugin_whatsnewsupported_<plugin name>

Plugins can add their own section to glFusion's What's New block by implementing this and the following function at private/plugins/filemgmt/functions.inc. The function should return an array of 2 strings. The first string is used as the headline for the plugin's section in What's New and the second string is used to indicate the timespan that the entries in this section cover (i.e. “last 2 weeks”).

Arguments

/**
  * Whats New Block API Support
  * Return the Headline and Byline for the new section in the Whatsnew Block
*/
function plugin_whatsnewsupported_filemgmt() {
    global $_USER, $mydownloads_publicpriv, $_CONF, $LANG_FM00,$mydownloads_whatsnew,$filemgmtWhatsNewPeriodDays;
 
    if ( (!isset($_USER['uid']) || $_USER['uid'] < 2) && $mydownloads_publicpriv != 1 )  {
        return '';
    }
 
    if ($mydownloads_whatsnew == 1) {
        return array(
            $LANG_FM00['WhatsNewLabel'],
            sprintf($LANG_FM00['WhatsNewPeriod'], $filemgmtWhatsNewPeriodDays)
            );
    } else {
        return false;
    }
}

plugin_getwhatsnew_<plugin name>

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.

Arguments

/**
  * API function provides the content of our "What's New" feed
*/
function plugin_getwhatsnew_filemgmt() {
    global $_TABLES, $_FM_TABLES, $_CONF, $LANG_FILEMGMT, $LANG01;
    global $filemgmtWhatsNewTitleLength,$filemgmtWhatsNewPeriodDays,$filemgmt_showWhatsNewComments,$mydownloads_publicpriv;
 
    $retval = '';
 
    $items = array();
    if (SEC_hasRights('filemgmt.user') OR $mydownloads_publicpriv == 1) {
        $sql  = "SELECT a.lid, a.title FROM {$_FM_TABLES['filemgmt_filedetail']} a ";
        $sql .= "LEFT JOIN {$_FM_TABLES['filemgmt_cat']} b ON a.cid=b.cid ";
        $sql .= "WHERE date >= UNIX_TIMESTAMP( DATE_SUB(NOW(), INTERVAL $filemgmtWhatsNewPeriodDays DAY )) ";
        $sql .= filemgmt_buildAccessSql();
        $sql .= "AND STATUS=1 ORDER  BY date DESC LIMIT 15 ";
        $result = DB_query( $sql );
        $nrows1 = DB_numRows( $result );
        if( $nrows1 == 0 ) {
            $retval .= $LANG_FILEMGMT['no_new_files'] . '<br' . XHTML . '>' . LB;
        } else {
            for( $i = 0; $i < $nrows1; $i++ ) {
                list($lid, $ftitle) = DB_fetchArray( $result );
                $str = "<a href=\"{$_CONF['site_url']}/filemgmt/index.php?id={$lid}\" title=\"".htmlspecialchars($ftitle,ENT_COMPAT,COM_getEncodingt())."\">";
				if( strlen( $ftitle ) > $filemgmtWhatsNewTitleLength ) {
					$titleTrimLength = $filemgmtWhatsNewTitleLength - 3;
                    $str .= COM_truncate( $ftitle,$titleTrimLength, '...' );
				} else {
					$str .= $ftitle;
				}
                $str .= '</a>';
                $items[] = $str;
            }
        }
        if ($filemgmt_showWhatsNewComments) {
            // Search for new comments
            $sql  = "SELECT a.lid,a.title,c.title FROM {$_FM_TABLES['filemgmt_filedetail']} a ";
            $sql .= "LEFT JOIN {$_FM_TABLES['filemgmt_cat']} b ON a.cid=b.cid ";
            $sql .= "LEFT JOIN {$_TABLES['comments']} c ON c.sid = concat('fileid_' ,a.lid )";
            $sql .= filemgmt_buildAccessSql('WHERE');
            $sql .= " AND c.date >=  DATE_SUB(NOW(), INTERVAL $filemgmtWhatsNewPeriodDays DAY ) AND c.type='filemgmt' ";
            $sql .= "GROUP BY c.sid ORDER  BY c.date DESC LIMIT 15 ";
 
            $result = DB_query($sql);
            $nrows2 = DB_numRows( $result );
            if( $nrows2 == 0 ) {
                $retval .= $LANG_FILEMGMT['no_comments'] . '<br' . XHTML . '>' . LB;
            } else {
                for( $i = 0; $i < $nrows2; $i++ ) {
                    list($lid, $ftitle, $ctitle) = DB_fetchArray( $result );
                    $commentTitle = $ctitle;
                    $titlePrefix = "<b>C:</b>&nbsp;";
                    $ctitle = $titlePrefix . $ctitle;
                    $titleLength = $filemgmtWhatsNewTitleLength + strlen( $titlePrefix ) - 3;        // Compensate for the added HTML
                    $str = "<a href=\"{$_CONF['site_url']}/filemgmt/index.php?id={$lid}\" title=\"".htmlspecialchars($commentTitle,ENT_COMPAT,COM_getEncodingt())."\" >";
					if( strlen( $ctitle ) > $titleLength ) {
						$titleTrimLength = $titleLength - 3;
	                    $str .= COM_truncate( $ctitle,$titleTrimLength, '...' );
					} else {
						$str .= $ctitle;
					}
                    $str .= '</a>';
                    $items[] = $str;
                }
            }
        }
 
        if ($nrows1 == 0 and $nrows2 == 0) {
            return $retval;
        } else {
            return $items;
        }
    } else {
        $retval .= $LANG_FILEMGMT['no_new_files'] . '<br' . XHTML . '>' . LB;
        return $retval;
    }
}
glfusion/development/pluginapi/whatnew.txt · Last modified: 2017/04/12 21:13 (external edit)

Page Tools