Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5

Créer un Flux RSS globale pour vos pages CMS Made Simple, la solution
#1

Bonjour à tous,

Mon premier message sur le forum et mon premier tutorial.

CMS Made simple, un CMS sans flux RSS ? Bien sûr que non...

Vous souhaitez avoir un flux RSS pour votre site affichant les 10 dernières pages mises à jours ?

Voici comment procéder.

Créez un fichier nommé /plugins/function.recently_updated_xml.php contenant :

Code :
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

function smarty_cms_function_recently_updated_xml($params, &$smarty)
{
  if(empty($params['number']))
    {
      $number = 10;
    }
  else
    {
      $number = $params['number'];
    }
    
  if(empty($params['leadin']))
    {
      $leadin = "Modified: ";
    }
  else
    {
      $leadin = $params['leadin'];
    }
    
  if(empty($params['showtitle']))
    {
      $showtitle='true';
    }
  else
    {
      $showtitle = $params['showtitle'];
    }    
    
    $dateformat = isset($params['dateformat']) ? $params['dateformat'] : "d.m.y h:m" ;    
    $css_class = isset($params['css_class']) ? $params['css_class'] : "" ;    
    
if (isset($params['css_class'])){
    $output = '<div class="'.$css_class.'"><ul>';
    }
else {
    $output = '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel>';
    $output = '';
}

global $gCms;
$hm =& $gCms->GetHierarchyManager();
$db = &$gCms->db;
// Get list of most recently updated pages excluding the home page
/*
$q = "SELECT * FROM ".cms_db_prefix()."content WHERE (type='content' OR type='link')
AND default_content != 1 AND active = 1 AND show_in_menu = 1
ORDER BY modified_date DESC LIMIT ".((int)$number);
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
    echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
while ($dbresult && $updated_page = $dbresult->FetchRow())
{
    $curnode =& $hm->getNodeById($updated_page['content_id']);
    $curcontent =& $curnode->GetContent();
    $output .= '<li>';
    $output .= '<a href="'.$curcontent->GetURL().'">'.$updated_page['content_name'].'</a>';
    if ((FALSE == empty($updated_page['titleattribute'])) && ($showtitle=='true'))
      {
    $output .= '<br />';
    $output .= $updated_page['titleattribute'];
      }
    $output .= '<br />';
    
    $output .= $leadin;
    $output .= date($dateformat,strtotime($updated_page['modified_date']));
    $output .= '</li>';
}
*/
// Modif http://forum.cmsmadesimple.fr/viewtopic.php?id=64
// Dans notre page on place le tag suivant: {recently_updated_xml dateformat="d/m/y H:i" number='10' showtitle='true' leadin='Modifié le: '}
// Par defaut cette balise ne tient pas compte de la page d'accueil. Pour voir aussi s'afficher la page d'accueil si elle a été modifée, il faut supprimer  "AND default_content != 1" dans la requete SQL
$q = "SELECT c.content_id, c.type, c.last_modified_by, c.default_content, c.content_name, c.titleattribute, c.active, c.show_in_menu, c.modified_date, u.user_id, u.last_name, u.first_name FROM ".cms_db_prefix()."content c LEFT JOIN ".cms_db_prefix()."users u ON u.user_id=c.last_modified_by WHERE (type='content' OR type='link')
AND default_content != 1 AND c.active = 1 AND show_in_menu = 1
ORDER BY c.modified_date DESC LIMIT ".((int)$number);
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
    echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
while ($dbresult && $updated_page = $dbresult->FetchRow())
{
/*
<item>
  <title>Scandinavia design</title>
  <link>http://www.waaaouh.com/annuaire/scandinavia-design-s6497.html</link>
  <description>Scandinavia design, boutique du centre ville d'Angers, propose le meilleur </description>
  <pubDate>Tue, 27 Apr 2010 16:18:02 +0200</pubDate>
  <guid>http://www.waaaouh.com/annuaire/scandinavia-design-s6497.html</guid>
</item>
*/
    $curnode =& $hm->getNodeById($updated_page['content_id']);
    $curcontent =& $curnode->GetContent();
    $output .= '<item>'."\n";
    $output .= '<title>'.$updated_page['content_name'].'</title>'."\n";
    $output .= '<link>'.$curcontent->GetURL().'</link>'."\n";
    $output .= '<description>'.$updated_page['content_name'].' sur NomDeVotreSite.com</description>'."\n";
    $output .= '<pubDate>'.date('r',strtotime($updated_page['modified_date'])).'</pubDate>'."\n";
     $output .= '<guid>'.$curcontent->GetURL().'</guid>'."\n";
    $output .= '</item>'."\n";

    //$output .= '<a href="'.$curcontent->GetURL().'">'.$updated_page['content_name'].'</a>';
    
    /*
    if ((FALSE == empty($updated_page['titleattribute'])) && ($showtitle=='true'))
      {
        $output .= '<br />';
        $output .= $updated_page['titleattribute'];
      }
    */
    //$output .= '<br />';

    //$output .= $leadin;
    //$output .= date($dateformat,strtotime($updated_page['modified_date']))." par ".$updated_page['last_name']." ".$updated_page['first_name'];
}

//$output .= '</channel></rss>';
if (isset($params['css_class'])){
        $output .= '</div>';
        }
        
return $output;
}

function smarty_cms_help_function_recently_updated_xml() {
    ?>
    <h3>What does this do?</h3>
    <p>Outputs a list of recently updated pages.</p>
    <h3>How do I use it?</h3>
    <p>Just insert the tag into your template/page like: <code>{recently_updated_xml}</code></p>
    <h3>What parameters does it take?</h3>
    <ul>
                                             <li><p><em>(optional)</em> number='10' - Number of updated pages to show.</p><p>Example: <pre>{recently_updated_xml number='15'}</pre></p></li>
                                                 <li><p><em>(optional)</em> leadin='Last changed' - Text to show left of the modified date.</p><p>Example: <pre>{recently_updated_xml leadin='Last Changed'}</pre></p></li>
                                                 <li><p><em>(optional)</em> showtitle='true' - Shows the titleattribute if it exists as well (true|false).</p><p>Example: <pre>{recently_updated_xml showtitle='true'}</pre></p></li>                                                
                                                 <li><p><em>(optional)</em> css_class='some_name' - Warp a div tag with this class around the list.</p><p>Example: <pre>{recently_updated_xml css_class='some_name'}</pre></p></li>                                                
                                                     <li><p><em>(optional)</em> dateformat='d.m.y h:m' - default is d.m.y h:m , use the format you whish (php -date- format)</p><p>Example: <pre>{recently_updated_xml dateformat='D M j G:i:s T Y'}</pre></p></li>                                                
    </ul>
    <p>or combined:</p>
    <pre>Pour Fr {recently_updated_xml dateformat="d/m/y H:i" number='10' showtitle='true' leadin='Modifié  le: '}</pre>
    <pre>{recently_updated_xml number='15' showtitle='false' leadin='Last Change: ' css_class='my_changes' dateformat='D M j G:i:s T Y'}</pre>
    <?php
}

function smarty_cms_about_function_recently_updated_xml() {
    ?>
    <p>Author: Olaf Noehring <http://www.team-noehring.de></p>
    <p>Version: 1.1</p>
    <p>Author: Elijah Lofgren <elijahlofgren@elijahlofgren.com></p>
    <p>Version: 1.0</p>
    <p>
    Change History:<br/>
    1.1: added new parameters: <br /> <leadin>. The contents of leadin will be shown left of the modified date. Default is <Modified:><br />
    $showtitle='true' - if true, the titleattribute of the page will be shown if it exists (true|false)<br />
    css_class<br />
    dateformat - default is d.m.y h:m , use the format you whish (php format)    <br />
    
    </p>
    <?php
}
?>
Créez un gabarit nommé "RSS Feed" contenant uniquement :

Code :
{process_pagedata}<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>News</title>
    <link>{root_url}/feed.xml</link>
    <description>The new pages</description>
    <language>fr-fr</language>
    <lastBuildDate>{php} echo date("r"); {/php}</lastBuildDate>
    <generator>RSS Generator</generator>
{php}
//global $gCms;
//$tpl_vars = $gCms->smarty->get_template_vars();
//print_r( $tpl_vars );
{/php}
{content}
</channel>
</rss>
Dans votre fichier htaccess, ajoutez cette ligne où il faut :

Code :
RewriteRule feed.xml feed.html

# au dessus de :
# Rewrites urls in the form of /parent/child/
Créez une page feed.html contenant ceci

Code :
{recently_updated_xml}
Ajouter ce code dans le <head> de votre gabarit :

Code :
<link rel="alternate" type="application/rss+xml" title="Dernières pages du site" href="{root_url}/feed.xml" />
Complément :
http://forum.cmsmadesimple.org/index.php...74163.html
http://wiki.cmsmadesimple.org/index.php/...ly_updated
http://cmsmadesimple.fr/forum/viewtopic.php?id=496
Exemple :
http://2dweb.be/fr/feed.xml


Edit : ... sur NomDeVotreSite.com
Répondre


Messages dans ce sujet

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)