Migration SimplePhpBlog to Joomla

1 – installer votre site Joomla, et copier les répertoires CONFIG et CONTENT de votre ancien site dans un dossier migration du nouveau.

2 – Allez dans l’administration de votre site Joomla, créer une section, recréer toutes vos catégories, puis un menu par catégorie. Vos menus doivent être de type ‘CATEGORY BLOG LAYOUT’ 2 – Pour les commentaires, installer le plugin MCX_COMMENT

3 – Copier le script ci-dessous dans un fichier migration/import.php

4 – Dans le fichier import.php, paramétrer votre connexion à la base.

5 – Lancer la page import.php Fichier import.php

 

 

<?php
//REQUIRES
//CREATE ONE SECTION AND YOURS CATEGORIES IN JOOMLA
//CREATE A MENU BY CATEGORY
//MENU CATEGORY MUST HAVE A TYPE = CATEGORY BLOG LAYOUT
//COPY THE CONTENT AND CONFIG DIRECTORY HERE
//INSTALL MXC COMMENT IN JOOMLA
//LAUNCH THIS PAGE

//Parametres de connexion
define (« DB_SERVER », »localhost »);
define (« DB_NAME », »ynizon3″);
define (« DB_USER », »root »);
define (« DB_PASSWORD », » »);

session_start();
$connexion=ouvrirConnexion();//Indique si la connexion à la base est ouverte

$sSQL= »delete from jos_content »;
if (!mysql_query($sSQL)){
echo « erreur delete »;
}
$sSQL= »delete from jos_mxc_comments »;
if (!mysql_query($sSQL)){
echo « erreur delete »;
}

//IMPORT DES DONNEES
recursive_import(« . », »entry »);
recursive_import(« . », »comment »);

fermerConnexion();

function explode_key( $str, $delim=’|’ ) {
// Hex value of pipe is | and html-munged version is |
$hex_arr = array(‘&#’.ord($delim).’;’, ‘&#’.ord($delim).’;’);

if ( is_array( $str ) ) {
$arr = $str;
} else {
$arr = explode($delim, $str);
}

$arr_out = array();
for ($i = 0; $i < count($arr); $i = $i + 2) {
$k = str_replace($hex_arr, $delim, $arr[$i]);
$v = str_replace($hex_arr, $delim, $arr[$i+1]);
$arr_out[ $k ] = $v;
}

return $arr_out;
}
function explode_with_keys( $str, $delim=’|’ ) {
return explode_key($str, $delim);
}

function rechercheCategorie($idCategorie){
//Recherche la categorie dans simplepbpblog, et renvoie l’id de la meme dans Joomla

$fp = fopen(« config/categories.txt », »r »); //lecture du fichier
while (!feof($fp)) { //on parcourt toutes les lignes
$sINFO .= fgets($fp, 4096); // lecture du contenu de la ligne
}

$sTitre=keep_string_part($sINFO, $idCategorie. »| », « |0 ») ;
$sTitre=str_replace($idCategorie. »| », » »,$sTitre);
$sTitre=str_replace(« – « , » »,$sTitre);

$sSQL= »select * from jos_categories where title=' ».$sTitre. »‘ »;
$result = mysql_query($sSQL);
$iCatid= »0″;
while ($row = mysql_fetch_array($result)) {
$iCatid=$row[« id »];
}

return $iCatid;

}

function rechercheSection($idCategorie){
//Recherche la section id de la categorie dans Joomla

$sSQL= »select * from jos_categories where id=' ».$idCategorie. »‘ »;
$result = mysql_query($sSQL);
$iSectionid= »0″;
while ($row = mysql_fetch_array($result)) {
$iSectionid=$row[« section »];
}

return $iSectionid;

}

function importEntry($sFichier){
$fp = fopen($sFichier, »r »); //lecture du fichier
while (!feof($fp)) { //on parcourt toutes les lignes
$sINFO .= fgets($fp, 4096); // lecture du contenu de la ligne
}

$blog_entry_data = array();
$exploded_array = explode( ‘|’, $sINFO );
$blog_entry_data = explode_with_keys( $exploded_array );

$sTitle=$blog_entry_data[ ‘SUBJECT’ ] ;
$sTitle=html_entity_decode($sTitle);
$sTitle=str_replace(« ‘ », » » »,$sTitle);
$sAlias=removeSpecialChar($sTitle);
$sTitleAlias=basename($sFichier);
$sTexte=$blog_entry_data[ ‘CONTENT’ ] ;
$iSectionID= »0″;
$iCategorieId=$blog_entry_data[ ‘CATEGORIES’ ];

//On prend la 1er categorie
$iPosD=strpos($iCategorieId, », »);
if ($iPosD!==false){
$iCategorieId=keep_string_part( $iCategorieId, «  », », » );
}

$iCategorieId=rechercheCategorie($iCategorieId);

$iSectionID =rechercheSection($iCategorieId);
$sDate=$blog_entry_data[ ‘DATE’ ];
$sKeyword=$blog_entry_data[ ‘relatedlink’ ];
$sTexte=html_entity_decode(replace_Link($sTexte));
$sTexte=str_replace(« n », »<br/> »,$sTexte);
//echo $iSectionID2. »<br/> »;

$sDate=date(‘Y-m-d’,$sDate). » 22:01:34″;

$sSQL= »INSERT INTO `jos_content` (`title`, `alias`, `title_alias`, `introtext`, `fulltext`, `state`, `sectionid`, `mask`, `catid`, `created`, `created_by`, `created_by_alias`, `modified`, `modified_by`, `checked_out`, `checked_out_time`, `publish_up`, `publish_down`, `images`, `urls`, `attribs`, `version`, `parentid`, `ordering`, `metakey`, `metadesc`, `access`, `hits`, `metadata`) VALUES
(‘ ».$sTitle. »‘, ‘ ».$sAlias. »‘, ‘ ».$sTitleAlias. »‘, ‘ ».$sTexte. »‘,  », 1, « .$iSectionID. », 0, « .$iCategorieId. », ‘ ».$sDate. » 22:01:34’, 62,  », ‘0000-00-00 00:00:00’, 0, 0, ‘0000-00-00 00:00:00’, ‘ ».$sDate. » 22:01:34’, ‘0000-00-00 00:00:00’,  »,  », ‘show_title=nlink_titles=nshow_intro=nshow_section=nlink_section=nshow_category=nlink_category=nshow_vote=nshow_author=nshow_create_date=nshow_modify_date=nshow_pdf_icon=nshow_print_icon=nshow_email_icon=nlanguage=nkeyref=nreadmore=’, 1, 0, 1, ‘ ».$sKeyword. »‘,  », 0, 0, ‘robots=nauthor=’); »;

//echo « import: « .$sFichier. »–> » . $sSQL. « <br/> »;

if (!mysql_query($sSQL)){ echo « Erreur « .$sSQL;
}

}

function importComment($sFichier){
$fp = fopen($sFichier, »r »); //lecture du fichier
while (!feof($fp)) { //on parcourt toutes les lignes
$sINFO .= fgets($fp, 4096); // lecture du contenu de la ligne
}

$blog_entry_data = array();
$exploded_array = explode( ‘|’, $sINFO );
$blog_entry_data = explode_with_keys( $exploded_array );

$sAuteur=$blog_entry_data[ ‘NAME’ ] ;
$sTexte=$blog_entry_data[ ‘CONTENT’ ] ;
$sTexte=html_entity_decode(replace_Link($sTexte));
$sAdresseIp=$blog_entry_data[ ‘IP-ADDRESS’ ];
$sDate=$blog_entry_data[ ‘DATE’ ];

$sSQL= »select * from jos_content where title_alias=' ».keep_string_part($sFichier, »entry », »/ »). ».txt' »;

$result = mysql_query($sSQL);
$iContentid=0;
while ($row = mysql_fetch_array($result)) {
$iContentid=$row[« id »];
}
$sDate=date(‘Y-m-d’,$sDate). » 22:01:34″;

$sSQL= »INSERT INTO `jos_mxc_comments` ( `parentid`, `status`, `contentid`, `ip`, `name`, `web`, `email`, `title`, `comment`, `date`, `published`, `ordering`, `iduser`, `subscribe`, `rating`, `currentlevelrating`, `lang`, `component`) VALUES
( 0, 0, « .$iContentid. », ‘ ».$sAdresseIp. »‘, ‘ ».$sAuteur. »‘,  »,  », ‘Commentaire’, ‘ ».$sTexte. »‘, ‘ ».$sDate. »‘, 1, 0, 0, 0, 0, 5,  », ‘com_content’);
« ;

// echo « import: « .$sFichier. »–> » . $sSQL. « <br/> »;

if (!mysql_query($sSQL)){ echo « Erreur « .$sSQL;
}

}

function ouvrirConnexion(){
$connexion = @mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(« connexion à la base impossible. »);
if ($connexion>0){
mysql_select_db(DB_NAME);
}else{
echo « CONNEXION IMPOSSIBLE »;
exit(0);
}
return $connexion;
}

function fermerConnexion(){
if ($connexion>0){
mysql_close();
$connexion=0;
}
return $connexion;
}

function recursive_import($sRep,$sComment) {
$O = dir($sRep);
if(!is_object($O)) {
return false;
}
while($file = $O -> read())
{
if($file != ‘.’ && $file != ‘..’)
{
if(is_file($sRep.’/’.$file))
{
$fichier_decoupe = explode(« . », strtoupper($sRep .’/’ . $file));
$sExt= array_pop($fichier_decoupe);
//Affichage des images
if ($sExt== »TXT » and substr($file,0,4)== »entr » and $sComment== »entry ») {
importEntry($sRep .’/’ . $file);
}

if ($sExt== »TXT » and substr($file,0,4)== »comm » and $sComment== »comment »){
importComment($sRep .’/’ . $file);
}
}
else {
if(is_dir($sRep.’/’.$file)) {
recursive_import($sRep.’/’.$file,$sComment);
}
}
}
}

$O -> close();
}
function replace_Link($sTexte){

$iPosD=strpos($sTexte, »[url= »);
while ($iPosD!==false){
@$iPosF=strpos($sTexte, »] »,$iPosD+1);
if ($iPosF!==false){
$iPosF=$iPosF-5;
$sLien=substr($sTexte,$iPosD+5,$iPosF-$iPosD);
@$iPosF2=strpos($sTexte, »[/url] »,$iPosF+1);
if ($iPosF2!==false){
$sTitreLien=substr($sTexte,$iPosF+6,$iPosF2-$iPosF-6);
}

}
$sTexte=str_replace(« [url= ».$sLien. »] ».$sTitreLien. »[/url] », »<a href= » ».$sLien. » »> ».$sTitreLien. »</a> »,$sTexte);
$iPosD=strpos($sTexte, »[url= »);
}
//echo « [url= ».$sLien. »] ».$sTitreLien. »[/url] ». »<br/> »;

$sTexte=str_replace(« ‘ », »‘ »,$sTexte);

$sTexte=str_replace(« 

","",$sTexte);    <br />    $sTexte=str_replace("

« , » »,$sTexte);

$iPosD=strpos($sTexte, »[img= »);
while ($iPosD!==false){
@$iPosF=strpos($sTexte, »] »,$iPosD+1);
if ($iPosF!==false){
$iPosF=$iPosF-5;
$sLien=substr($sTexte,$iPosD+5,$iPosF-$iPosD);
}
$sTexte=str_replace(« [img= ».$sLien. »] », »<img src= » ».$sLien. » » /> »,$sTexte);
$iPosD=strpos($sTexte, »[img= »);
}

return $sTexte;
}

function removeSpecialChar($sString){
// Remove special chars (to create directory)
$sString= strtr($sString,
« ÀÁÂÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ?&=*% ‘’,;:/!§{}ABCDEFGHIJKLMNOPQRSTUVWXYZ »,
« aaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn_________________abcdefghijklmnopqrstuvwxyz »);

return $sString;
} ;

function keep_string_part($sTexte, $sStringDebut, $sStringFin)
{
//$sStringDebut mot clé debut
//$sStringFin mot clé fin

$sFichierOrigine=($sTexte);
if ($sStringDebut!= » »){
$iPosD=strpos($sFichierOrigine,$sStringDebut);
}else{
$iPosD=0;
}
if ($iPosD!==false){
$iPosF=strpos($sFichierOrigine,$sStringFin,$iPosD+1);
if ($iPosF!==false){
$sNode=substr($sFichierOrigine,$iPosD,$iPosF-$iPosD);
}
}

return $sNode;
}

?>

Laisser un commentaire

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.