Wiki Plume Community : ArchiveByMonth

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Archive the resources by month


You will need to edit several files, so it could be a good idea to save your sources first.

You could also use the Plugin if you don't have modified the functions below.

Archiver les ressources par mois


Vous allez devoir éditer plusieurs fichiers, aussi je vous conseille de faire une sauvegarde de vos sources avant de commencer.

Vous pouvez aussi utiliser le Plugin si vous n'avez pas fait de modifications dans les fonctions ci-dessous.


/manager/frontinc/class.template.php

Add this 2 lines in the function render(), when initializing variables (line 132).

Ajouter ces 2 lignes dans la fonction render(), au niveau de l'initialisation des variables (ligne 132).

$GLOBALS['_PX_render']['datestart'] = (!empty($this->parsed_query['date'])) ? timestamp(0,0,0,maketime($this->parsed_query['date'])) : '';
$GLOBALS['_PX_render']['dateend'] =   (!empty($this->parsed_query['date'])) ? timestamp(0,1,0,maketime($this->parsed_query['date'])) : '';


Change the function getCacheId for this one. (Not very sure it's necessary to work ...)

Changer la fonction getCacheId pour celle ci. (Pas sur que ce soit nécessaire pour que ça marche ...)

function getCacheId($res, $website=array())
{
    $websiteid = (!empty($website['website_id'])) ? $website['website_id'] : $GLOBALS['_PX_website_config']['website_id'];
    return md5($websiteid.'%cat='.$res['category'].'%res='.$res['resource'].'%p='.$res['page'].'%mode='.$res['mode'].'%date='.$res['date']);
}


Change the function parseQuery for this one.

Changer la fonction parseQuery pour celle ci.

function parseQuery($query)
{
    $query = preg_replace( '#^(/)+#', '/', $query);
    $category = $resource = $page = $mode = '';
   
    if (preg_match('#^(.*/)(index)([0-9]*)$#i', $query, $match)) {
        $category = $match[1];
        $page     = ($match[3]) ? (int) $match[3] : 1;
        $mode     = 'cat';
    } elseif (preg_match('#^(/([A-Za-z][A-Za-z0-9_-]*/)*)(([0-9]{4}/[0-9]{2})(/|\z))?$#i', $query, $match)) {
        $category = $match[1];
        $page     = 1;
        $mode     = 'cat';
        if (preg_match('#^(/([A-Za-z][A-Za-z0-9_-]*/)*)(([0-9]{4}/[0-9]{2})(/|\z))$#i', $query, $match)) {
            $date_ = (int)(substr($match[4],0,4).substr($match[4],5,2));
        }
    } elseif (preg_match('#^(.*/)([a-z]|[a-z][a-z0-9\_\-]*[a-z])(\d*)$#i', $query, $match)) {
        $category = $match[1];
        $resource = $match[2];
        $page     = ($match[3]) ? (int)$match[3] : 1;
        $mode     = 'art';
    } elseif (preg_match('#^(.*/)(\d+)\-([^\.]*)$#i', $query, $match)) {
        $category = $match[1];
        $resource = $match[2];
        $mode     = 'news';
    } else {
        $category = '/';
        $mode     = 'cat';
        $page     = 1;
    }
    return array('category' => $category, 'resource' => $resource, 'page' => $page, 'mode' => $mode, 'date' => $date_);
}


In the function pxTemplateInit, change this line

Dans la fonction pxTemplateInit, changer cette ligne

px_getResources($GLOBALS['_PX_render']['resource']['category_id'], '', ''$order );


for this one

pour celle ci

px_getResources($GLOBALS['_PX_render']['resource']['category_id'], '', ''$order , $GLOBALS['_PX_render']['datestart'], $GLOBALS['_PX_render']['dateend'] );


/manager/frontinc/functions.php

Change the function pxGetLastResources for this one.

Changer la fonction pxGetLastResources pour celle ci.

function pxGetLastResources($limit = 5, $type = '', $category = '') {
    if (!empty($GLOBALS['_PX_render']['datestart'])) {
        $GLOBALS['_PX_render']['m']->lres = $GLOBALS['_PX_render']['m']->getResources($category, '', $type, 'DESC', $GLOBALS['_PX_render']['datestart'], $GLOBALS['_PX_render']['dateend'] );
    }else{
        $GLOBALS['_PX_render']['m']->lres = $GLOBALS['_PX_render']['m']->getResources($category, $limit, $type);
    }
}


Change the function px_getResources for this one.

Changer la fonction px_getResources pour celle ci.

function px_getResources($category='', $limit = 10, $type = ''$order = 'DESC', $datestart='', $dateend='')
{
    global $_PX_website_config, $_PX_config;
    if (empty($GLOBALS['_PX_render']['m']->res)) {
        $GLOBALS['_PX_render']['m']->res = $GLOBALS['_PX_render']['m']->getResources($category, $limit, $type, $order, $datestart, $dateend);
    }
    $GLOBALS['_PX_render']['m']->res->move(($GLOBALS['_PX_render']['resource']['page'] - 1) * $GLOBALS['_PX_render']['m']->NbResPerPage);
    if (!empty($GLOBALS['_PX_render']['datestart'])) {
        $GLOBALS['_PX_render']['m']->res->int_row_count = $GLOBALS['_PX_render']['m']->res->int_row_count_total;
    } elseif ($GLOBALS['_PX_render']['m']->res->int_row_count > ($GLOBALS['_PX_render']['resource']['page'] * $GLOBALS['_PX_render']['m']->NbResPerPage)) {
        $GLOBALS['_PX_render']['m']->res->int_row_count = $GLOBALS['_PX_render']['resource']['page'] * $GLOBALS['_PX_render']['m']->NbResPerPage;
    }
}


Add this fonction.

Ajouter cette fonction.

/**
@function pxMonthsList

Cette fonction affiche la liste des mois contenant les archives.
Si on se trouve dans une catégorie, seuls les mois de cette catégorie
seront affichés.

@param string  block Chaine de substitution pour pour la liste ('<ul>%s</ul>')
@param string  item  Chaine de substitution pour un élément ('<li>%s</li>')
*/

function pxMonthsList($homepage=false,$block='<ul>%s</ul>',$item='<li>%s</li>')
{
    global $_PX_website_config, $_PX_config, $_PX_render, $month, $year, $cat_id, $blog;
   
    $s = ($_PX_website_config['secure']) ? 's' : '';   
    $arry_months = $GLOBALS['_PX_render']['m']->getArrayMonths(''/* All the types */, $GLOBALS['_PX_render']['resource']['category_id'], $homepage);
    foreach($arry_months as $ts => $d)
    {
        $titre = dt::str('%B %Y',$ts);
       
        $url = sprintf('http'.$s.'://'.$_PX_website_config['domain'].$_PX_website_config['rel_url'].$GLOBALS['_PX_render']['parsed_query']['category'].'%s/%s',
                       date('Y',$ts),date('m',$ts));
        $lien = '<a href="'.$url.'">%s</a>';
       
        $liClass = '';
       
        if($year == date('Y',$ts) && $month == date('m',$ts)) {
            $lien = '<strong>'.$lien.'</strong>';
        }
       
        $res .= sprintf($item,sprintf($lien,$titre));
    }
   
    if (count($arry_months) > 0) {
        printf($block,$res);
    }
}


/manager/frontinc/class.rendermanager.php

Add this fonction in the renderManager class.

Ajouter cette fonction dans la classe renderManager.

/**
@param string type of resource
@param int category id
@param bool (true) add the all dates choice (true by default!!!)
@return array($first, $last, array of months + year)
*/

function getArrayMonths($type='', $cat_id='', $homepage=false)
{
    $arry_months = array();
    if ($homepage)
        $cat_id = '';
    //getAllDates returns the values in time DESC order
    foreach ($this->getAllDates('m', $type, $cat_id) as $k => $v) {
        $arry_months[makeTime($k)] = date("Y-m-01",makeTime($k));
    }
    return $arry_months;
}


Change the function getResources for this one.

Changer la fonction getResources pour celle ci.

function getResources($category='', $limit = 10, $type = ''$order = 'DESC', $datestart='', $dateend='')
{
    include_once dirname(__FILE__).'/../inc/class.resource.php';
    $this->getDB();
    return parent::getResources('', PX_RESOURCE_STATUS_VALIDE, $category, $type, $datestart, $dateend, $limit, $order, true);
}


/manager/inc/lib.date.php

Add this file in /manager/inc/

Rajouter ce fichier dans le répertoire /manager/inc/

<?php
class dt
{
    function str($p,$ts=NULL)
    {
        if ($ts == NULL) { $ts = time(); }
       
        $hash = '799b4e471dc78154865706469d23d512';
        $p = preg_replace('/(?<!%)%(a|A)/','{{'.$hash.'__$1%w__}}',$p);
        $p = preg_replace('/(?<!%)%(b|B)/','{{'.$hash.'__$1%m__}}',$p);
       
        $res = strftime($p,$ts);
       
        $res = preg_replace_callback('/{{'.$hash.'__(a|A|b|B)([0-9]{1,2})__}}/',array('dt','_callback'),$res);
       
        return $res;
    }
   
    function dt2str($p,$dt)
    {
        return dt::str($p,strtotime($dt));
    }
   
    function iso8601($ts)
    {
        $tz = date('O',$ts);
        $tz = substr($tz,0,-2).':'.substr($tz,-2);
        return date('Y-m-d\\TH:i:s',$ts).$tz;
    }
   
    function _callback($args)
    {
        $b = array(1=>'Jan',2=>'Feb',3=>'Mar',4=>'Apr',5=>'May',6=>'Jun',
        7=>'Jul',8=>'Aug',9=>'Sep',10=>'Oct',11=>'Nov',12=>'Dec');
       
        $B = array(1=>'January',2=>'February',3=>'March',4=>'April',
        5=>'May',6=>'June',7=>'July',8=>'August',9=>'September',
        10=>'October',11=>'November',12=>'December');
       
        $a = array(1=>'Mon',2=>'Tue',3=>'Wed',4=>'Thu',5=>'Fri',
        6=>'Sat',0=>'Sun');
       
        $A = array(1=>'Monday',2=>'Tuesday',3=>'Wednesday',4=>'Thursday',
        5=>'Friday',6=>'Saturday',0=>'Sunday');
       
        return __(${$args[1]}[(integer) $args[2]]);
    }
}

?>


/manager/frontinc/prepend.php

Add this line in order to load the previous file.

Ajouter cette ligne afin de charger le fichier précédent.

include_once $_PX_config['manager_path'].'/inc/lib.date.php';


Template/Gabarits

You just have to put this line in your template to make this work.

Vous n'avez qu'a insérer cette ligne dans vos gabarits pour voir tous les mois où des ressources ont été publiées pour cette catégorie.

<?php pxMonthsList() ?>


If you want to display the months where resources have been publicated without take in order the category (for the homepage by example), use this.

Si vous voulez afficher les mois où des ressources ont été publiées sans tenir compte de la catégorie courante (pour la page d'accueil par exemple), utilisez ceci.

<?php pxMonthsList(true) ?>



Localisation

Now you just have to complete your traduction file with the month's name.
I've noticed a bug in the initialization of the renderUser. In the file /manager/class.rendermanager.php you have to change, in the function renderUser(), this line.

Maintenant, il ne vous reste plus qu'a compléter votre fichier de localisation avec le nom des mois.
Cependant, j'ai pu constater un petit problème lors de l'initialisation du renderUser. Dans le fichier /manager/class.rendermanager.php vous devez donc changer dans la fonction renderUser() cette ligne.

$this->lang = '';


For this one.

Par celle ci.

$this->lang = $GLOBALS['_PX_config']['lang'];
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.1
Page was generated in 0.4659 seconds