1
astuni
[help]Modifiyng the xf-section top article query
  • 2005/3/1 1:54

  • astuni

  • Just popping in

  • Posts: 22

  • Since: 2004/6/7 4


$sql "SELECT articleid, title, published, expired, counter, groupid FROM ".$xoopsDB->prefix("xfs_article")." WHERE published < ".time()." AND published > 0 AND (expired = 0 OR expired > ".time().") AND noshowart = 0 AND offline = 0 ORDER BY ".$options[0]." DESC";


This is the query for the top articles block of xf-section, there is any way to modify it to show only the "last month" top articles?

I believe there is something to tweak on "AND published > 0" using some time() feature but i dont know how, anyone can help?

Thanks!

2
astuni
Re: [help]Modifiyng the xf-section top article query
  • 2005/3/2 0:37

  • astuni

  • Just popping in

  • Posts: 22

  • Since: 2004/6/7 4


Ok, done by myself, i wanna share the result because it might be useful.

Found on php.net this function:

/**
 * Examples
 *    return seconds in a year:
 *      echo time_to_seconds (0, 0, 0, 1);
 *
 *    get a time() value from 30 days ago:
 *      echo time() - time_to_seconds (0, 0, 30);
 */

function time_to_seconds ($minutes$hours=NULL$days=NULL$years=NULL) {
   
$seconds 0;

   
$seconds += $minutes 60;
   if (
$hours != NULL$seconds += $hours 3600;
   if (
$days  != NULL$seconds += $days  86400;
   if (
$years != NULL$seconds += $years 31536000;
  
   return 
$seconds;
}


so i applyed it to the /modules/xfsection/blocks/xfs_top.php
making it looks this way:
if ( !function_exists('xfs_checkAccess') )
{
    include_once 
XOOPS_ROOT_PATH."/modules/xfsection/include/xfs_groupaccess.php";
}

function 
time_to_seconds ($minutes$hours=NULL$days=NULL$years=NULL) {
   
$seconds 0;

   
$seconds += $minutes 60;
   if (
$hours != NULL$seconds += $hours 3600;
   if (
$days  != NULL$seconds += $days  86400;
   if (
$years != NULL$seconds += $years 31536000;
  
   return 
$seconds;
}

function 
b_xfs_top_show($options) {    // *** change this ***
    
global $xoopsDB;
    
$myts =& MyTextSanitizer::getInstance();
    
$block = array();

// *** change this ***
//    $sql = "SELECT articleid, title, published, expired, counter, groupid FROM ".$xoopsDB->prefix("wfs_article")." WHERE published < ".time()." AND published > 0 AND (expired = 0 OR expired > ".time().") AND noshowart = 0 AND offline = 0 ORDER BY ".$options[0]." DESC";
    
$sql "SELECT articleid, title, published, expired, counter, groupid FROM ".$xoopsDB->prefix("xfs_article")." WHERE published < ".time()." AND published > ".(time() - time_to_seconds (0030))." AND (expired = 0 OR expired > ".time().") AND noshowart = 0 AND offline = 0 ORDER BY ".$options[0]." DESC";

    
$result $xoopsDB->query($sql,$options[1],0);
    while ( 
$myrow $xoopsDB->fetchArray($result) ) {

// for avoiding to collide with WFsection.
//    if(checkAccess($myrow["groupid"])) {    
    
if(xfs_checkAccess($myrow["groupid"])) {

        
$wfs = array();
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[2]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."...";
            }
        }
        
$wfs['title'] = $title;
        
$wfs['id'] = $myrow['articleid'];
        if ( 
$options[0] == "published" ) {
            
$wfs['top'] = formatTimestamp($myrow['published'],"s");
        } elseif ( 
$options[0] == "counter" ) {
            
$wfs['top'] = $myrow['counter'];
        }
        
$block['top'][] = $wfs;
    }
    }
    return 
$block;
}

function 
b_xfs_top_edit($options) {    // *** change this ***

// rename WFS to XFS
    
$form ""._MB_XFS_ORDER.";

    
$form .= ";
    if ( 
$options[0] == "published" ) {
        
$form .= " selected='selected'";
    }

// rename WFS to XFS
    
$form .= ">"._MB_XFS_DATE."n";

    
$form .= ";
    if(
$options[0] == "counter"){
        
$form .= " selected='selected'";
    }

// rename WFS to XFS
    
$form .= ">"._MB_XFS_HITS."n";

    
$form .= "n";

// rename WFS to XFS
    
$form .= " "._MB_XFS_DISP..$options[1]."' /> "._MB_XFS_ARTCLS."";
    
$form .= 
"
._MB_XFS_CHARS..$options[2]."' /> "._MB_XFS_LENGTH."";


    return 
$form;
}
?>

After including the function the key is:
AND published ".(time() - time_to_seconds (0, 0, 30))."

so the result is that he pulls off db the top articles of the last 30 days.
Cheers

Login

Who's Online

348 user(s) are online (294 user(s) are browsing Support Forums)


Members: 0


Guests: 348


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits