Dupliquer un module

La théorie


Il est possible de dupliquer un module, soit pour le renommer à son goût, soit pour utiliser simultanément plusieurs fois le même module dans des situations différentes, mais encore pour ne pas être impacté par les mises à jour du module en cas de simples modifications du module originel .

Il suffit de remplacer le nom du module partout où il apparaît 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 entraînera une erreur.

Outil : notepad++

La pratique


Exemple avec le module news transformé en module blog, version PHPBoost 4.0 .

  1. Télécharger le module news officiel
  2. Décompresser l'archive
  3. Modifier le nom du dossier news en blog



Remplacer le nom du module dans le contenu de chaque fichier


Il faut effectuer le remplacement des trois chaînes de caractères contenues dans chaque fichier du module : module, Module et MODULE.

  1. Ouvrir un des fichiers du dossier avec notepad++
  2. Cliquer sur le menu Recherche > Rechercher... ou CTRL+F
  3. Cliquer sur l'onglet replace
  4. Cocher la case Respecter la casse



Effectuer les 3 recherches suivantes :



Grâce au bouton Remplacer tout, la manipulation est très rapide pour chaque recherche.

Une recherche, sans respect de la casse, sur news permet de s'assurer que tout est modifié.

enregistrer le fichier puis ouvrir le suivant et recommencer

Remplacer le nom des fichiers


une fois le contenu des fichiers modifiés, il faut renommer le nom de chaque fichier qui contient le mot news, News ou NEWS, respectivement avec blog, Blog ou BLOG (news_block.tpl devient blog_block.tpl, NewsSetup.class.php devient BlogSetup.class.php, etc.).

__news

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


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


Ajustements


Il y a quelques réajustement à faire dans les fichiers de langues (news est féminin, blog est masculin :wink)

Changer les icônes blog.png et blog_mini.png si besoin.

Installation


Ajouter le dossier à la racine du site.

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

Les mises à jours


Vous devrez refaire la manipulation sur les fichiers modifiés par la mise à jour si le module dupliqué (ici 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 fichiers sans avoir besoin de réinstaller le module (sauf en cas de mise à jour impactant la base de données).

Bonus


version PHPBoost 4.0

Appel des 5 derniers billets du blog dans HomeCustom




Fichier 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;
}
}
?>


Fichier home.tpl :

Code TPL :
# START blog #
<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 blog #