VI. Tutoriels communautaires

Dupliquer un module

Cet article a été mis à jour, vous consultez ici une archive de cet article!
Dernière mise à jour : 23/11/2013 à 23h52

La théorie





Il est possible de dupliquer un module soit pour le renommer à son gout soit pour utiliser simultanément plusieurs fois le même module dans des situations différentes .



Il suffit de remplacer le nom du module partout où il apparait en respectant bien la casse (majuscules/minuscules), dans sa version non-installée.

Vous n'avez besoin d'aucune connaissance particulière en programmation, mais il va falloir être méthodique sachant que chaque oubli ou suppression d'un autre caractère entrainera une erreur



outil: notepad++



La pratique





exemple avec le module news transformé en module blog.



  1. telecharger le module news officiel
  2. décompresser l'archive
  3. modifier le nom du dossier "news" en "blog"
  4. ajouter le dossier à la racine du site, sans l'installer.





Le contenu des fichiers





Ouvrir le premier de TOUS les fichiers du module, pour vérifier s'il contient au moins une des 3 formes du mot news. Si oui, il faut modifier toutes les formes présentes



Avec l'outil recherche de l'éditeur, cocher la case "respecter la casse"

première recherche

Rechercher: news

Remplacer: blog


puis

Rechercher: News

Remplacer: Blog


et enfin

Rechercher: NEWS

Remplacer: BLOG




Grâce au bouton "remplacer tout" la manipulation est assez rapide pour chaque recherche

une recherche, sans respect de la casse, sur "news" permet de s'assurer que tout est fait



enregistrer le fichier



Notez comme j'ai appuyé le "TOUS" dans "tous les fichiers" car il ne s'agit pas d'en oublier en pensant qu'il ne fallait vérifier que les fichiers avec "news" dans leur nom



Le nom des fichiers





Renommer tous les fichiers qui contiennent le mot "news", "News" ou "NEWS", dans leur titre avec le "blog" correspondant (news->blog, News->Blog...)

news_block.tpl devient blog_block.tpl, NewsSetup.class.php devient BlogSetup.class.php, etc...





__blog

Caché :
____lang

______english

________desc.ini

________install.php

________news_config.php

________news_english.php

______french

________desc.ini

________install.php

________news_config.php

________news_french.php

____phpboost

______NewsCats.class.php

______NewsCommentsTopic.class.php

______NewsExtensionPointProvider.class.php

______NewsFeedProvider.class.php

______NewsHomePageExtensionPoint.class.php

______NewsSearchable.class.php

______NewsSetup.class.php

______NewsSitemapExtensionPoint.class.php

____templates

______framework

________content

__________syndication

____________last_news.tpl

______images

______admin_news.tpl

______admin_news_cat.tpl

______admin_news_config.tpl

______admin_news_menu.tpl

______management.tpl

______news.css

______news.tpl

______news_block.tpl

______news_list.tpl

____admin_news.php

____admin_news_cat.php

____admin_news_config.php

____admin_news_menu.php

____config.ini

____index.php

____management.php

____news.php

____news.png

____news_begin.php

____news_constants.php

____news_mini.png

____print.php

____xmlhttprequest.php

____xmlhttprequest_cats.php




ça fait du monde :)

une fois TOUS les fichiers vérifiés et modifiés, le répertoire blog ressemble à ça

__blog

Caché :
____lang

______english

________desc.ini

________install.php

________blog_config.php

________blog_english.php

______french

________desc.ini

________install.php

________blog_config.php

________blog_french.php

____phpboost

______BlogCats.class.php

______BlogCommentsTopic.class.php

______BlogExtensionPointProvider.class.php

______BlogFeedProvider.class.php

______BlogHomePageExtensionPoint.class.php

______BlogSearchable.class.php

______BlogSetup.class.php

______BlogSitemapExtensionPoint.class.php

____templates

______framework

________content

__________syndication

____________last_blog.tpl

______images

______admin_blog.tpl

______admin_blog_cat.tpl

______admin_blog_config.tpl

______admin_blog_menu.tpl

______management.tpl

______blog.css

______blog.tpl

______blog_block.tpl

______blog_list.tpl

____admin_blog.php

____admin_blog_cat.php

____admin_blog_config.php

____admin_blog_menu.php

____config.ini

____index.php

____management.php

____blog.php

____blog.png

____blog_begin.php

____blog_constants.php

____blog_mini.png

____print.php

____xmlhttprequest.php

____xmlhttprequest_cats.php




et chacun des fichiers contient des "blog" à la place des "news".



Il ne reste plus qu'a tester en installant le module via l'administration du site.



Il y a quelques réajustement à faire dans les fichier de langues (news est féminin, blog est masculin :wink ), et pour les icônes du modules.



Les mises à jours





Vous devrez refaire la manipulation sur les fichiers modifiés par la mise à jour si le module dupliqué (news) est impacté.

La configuration et la création de la base de donnée du nouveau module (blog) étant déjà effectuées, il suffit de remplacer les fichier sans avoir besoin de réinstaller le module. (sauf cas de mise à jour majeure)



bonus





**- le module blog

icônes 16 32 64px dans blog/templates/images



**- appel des 5 derniers billets du blog dans HomeCustom

HomeCustomHomePageExtensionPoint.class.php





Code PHP :
<?php
/*##################################################
 *                     HomeCustomHomePageExtensionPoint.class.php
 *                            -------------------
 *   begin                : August 25, 2012
 *   copyright            : (C) 2012 Kevin MASSY
 *   email                : kevin.massy@phpboost.com
 *
 *
 ###################################################
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/
 
class HomeCustomHomePageExtensionPoint implements HomePageExtensionPoint
{
    public function get_home_page()
    {
        return new DefaultHomePage($this->get_title(), $this->get_view());
    }
 
    private function get_title()
    {
        return LangLoader::get_message('title', 'common', 'HomeCustom');
    }
 
    private function get_view()
    {
        $template = new FileTemplate('HomeCustom/home.tpl');
 
        return $this->build_view($template);
    }
 
    private function build_view(View $template)
    {
        $result = PersistenceContext::get_querier()->select('
            SELECT id, title, contents, timestamp, img, user_id
            FROM ' . PREFIX . 'blog
            WHERE visible = 1
            ORDER BY timestamp DESC 
            LIMIT 5
        ');
 
        while ($row = $result->fetch())
        {
            $date = new Date(DATE_TIMESTAMP, TIMEZONE_AUTO, $row['timestamp']);
            $template->assign_block_vars('blog', array(
                'U_LINK' => Url::to_absolute('/blog/blog.php?id=' . $row['id']),
                'TITLE' => $row['title'],
                'CONTENT' => $row['contents'],
                'IMG' => FormatingHelper::second_parse_url($row['img']),
                'DATE' => $date->format(DATE_FORMAT_TEXT_LONG)
            ));
 
        }
 
        return $template;
    }
}
?>




home.tpl



Code TPL :
# START news #
<div>
    <a href="{blog.U_LINK}">{blog.TITLE}</a>
    <p>{blog.DATE}</p>
        <img src="{blog.IMG}" alt="{blog.TITLE}" />
    <p>{blog.CONTENT}</p>
</div>
# END news #