V. Le nouveau module d'administration▲
Nous avons la structure et nos scripts sont prêts à l'utiliser. Il ne nous reste plus qu'à prévoir une interface permettant de transférer une catégorie depuis un site vers un autre : les sujets et messages suivront la catégorie à laquelle ils appartiennent.
V-A. Les variables de langue▲
Dans les scripts suivants :
- language/lang_english/lang_admin.php
//
// That's all Folks!
// -------------------------------------------------
//
// Module to move forums from one site to another
//
$lang
[
'
Migrate
'
]
=
'
Migrating
'
;
$lang
[
'
Category
'
]
=
'
Category
'
;
$lang
[
'
Destination
'
]
=
'
Destination
'
;
$lang
[
'
Forums
'
]
=
'
Forums
'
;
$lang
[
'
Topics
'
]
=
'
Topics
'
;
$lang
[
'
Posts
'
]
=
'
Posts
'
;
//
// That's all Folks!
// -------------------------------------------------
Il faut appliquer cette modification pour chacune des langues du forum !
V-B. Le gabarit du script▲
Créer le fichier :
- templates/subSilver/admin/forum_admin_migrate.tpl
<h1>{L_FORUM_TITLE}</h1>
<p>{L_FORUM_EXPLAIN}</p>
<table width
=
"100%"
cellpadding
=
"4"
cellspacing
=
"1"
border
=
"0"
class
=
"forumline"
align
=
"center"
>
<!-- BEGIN siterow -->
<tr>
<th class
=
"thHead"
colspan
=
"5"
>
{siterow.SITE_URI}</th>
</tr>
<tr>
<td class
=
"catLeft"
><span class
=
"gen"
><b>{L_CATEGORY}</b></span></td>
<td class
=
"catLeft"
align
=
"center"
valign
=
"middle"
><span class
=
"gen"
><b>{L_DESTINATION}</b></span></td>
<td class
=
"catLeft"
align
=
"center"
valign
=
"middle"
><span class
=
"gen"
><b>{L_FORUMS}</b></span></td>
<td class
=
"catLeft"
align
=
"center"
valign
=
"middle"
><span class
=
"gen"
><b>{L_TOPICS}</b></span></td>
<td class
=
"catLeft"
align
=
"center"
valign
=
"middle"
><span class
=
"gen"
><b>{L_POSTS}</b></span></td>
</tr>
<!-- BEGIN catrow -->
<tr>
<td class
=
"row1"
><span class
=
"cattitle"
><b><a href
=
"{siterow.catrow.U_VIEWCAT}"
>
{siterow.catrow.CAT_DESC}</a></b></span></td>
<td class
=
"row2"
align
=
"center"
valign
=
"middle"
>
<form method
=
"post"
action
=
"{S_FORUM_ACTION}"
>
<select name
=
"site_id"
>
<!-- BEGIN site -->
<option value
=
"{siterow.catrow.site.SITE_ID}"
class
=
"liteoption"
>
{siterow.catrow.site.SITE_URI}</option>
<!-- END site -->
</select>
<input type
=
"hidden"
name
=
"cat_id"
value
=
"{siterow.catrow.CAT_ID}"
/>
<input type
=
"submit"
value
=
"Envoyer"
class
=
"mainoption"
/>
</form>
</td>
<td class
=
"row1"
align
=
"center"
valign
=
"middle"
><span class
=
"gen"
>
{siterow.catrow.NUM_FORUMS}</span></td>
<td class
=
"row2"
align
=
"center"
valign
=
"middle"
><span class
=
"gen"
>
{siterow.catrow.NUM_TOPICS}</span></td>
<td class
=
"row1"
align
=
"center"
valign
=
"middle"
><span class
=
"gen"
>
{siterow.catrow.NUM_POSTS}</span></td>
</tr>
<tr>
<td colspan
=
"5"
height
=
"1"
class
=
"spaceRow"
><img src
=
"../templates/lpch_cinema/images/spacer.gif"
alt
=
""
width
=
"1"
height
=
"1"
/></td>
</tr>
<!-- END catrow -->
<!-- END siterow -->
</table>
Il faut créer ce fichier pour chacun des templates du forum !
V-C. Le script▲
Créer le fichier :
- admin/admin_migrate.php
<?php
/***************************************************************************
* admin_migrate.php
* -------------------
* begin : Monday, May
1
,
2007
* copyright : (C) Guillaume Rossolini
* email : g-rossolini@redaction-developpez.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.
*
***************************************************************************/
define('IN_PHPBB'
,
1
);
if
( !
empty($setmodules
) )
{
$file
=
basename(__FILE__
);
$module
[
'Forums'
][
'Migrate'
]
=
$file
;
return
;
}
//
// Load default header
//
$phpbb_root_path
=
"./../"
;
require($phpbb_root_path
.
'extension.inc'
);
require('./pagestart.'
.
$phpEx
);
include($phpbb_root_path
.
'includes/functions_admin.'
.
$phpEx
);
//
// Mode setting
//
if
( isset($HTTP_POST_VARS
[
'mode'
]
) ||
isset($HTTP_GET_VARS
[
'mode'
]
) )
{
$mode
=
( isset($HTTP_POST_VARS
[
'mode'
]
) ) ?
$HTTP_POST_VARS
[
'mode'
]
:
$HTTP_GET_VARS
[
'mode'
];
$mode
=
htmlspecialchars($mode
);
}
else
{
$mode
=
""
;
}
//
// Begin program proper
//
if
(strtolower($_SERVER
[
'REQUEST_METHOD'
]
) ==
'post'
)
{
$sql
=
'UPDATE '
.
ALL_CATEGORIES_TABLE .
'
SET site_id = '
.
intval($_POST
[
'site_id'
]
) .
'
WHERE cat_id = '
.
intval($_POST
[
'cat_id'
]
);
if
( !
$db
->
sql_query($sql
) )
{
message_die(GENERAL_ERROR,
"Couldn't update the Category"
,
""
,
__LINE__
,
__FILE__
,
$sql
);
}
}
$sql
=
"SELECT site_id, site_uri
FROM "
.
ALL_SITES_TABLE .
"
ORDER BY site_uri"
;
if
( !
$q_sites
=
$db
->
sql_query($sql
) )
{
message_die(GENERAL_ERROR,
"Couldn't get list of Sites"
,
""
,
__LINE__
,
__FILE__
,
$sql
);
}
if
($db
->
sql_numrows($q_sites
))
{
$site_rows
=
$db
->
sql_fetchrowset($q_sites
);
foreach
($site_rows
as
$site_row
)
{
$template
->
assign_block_vars('siterow'
,
array
(
'SITE_URI'
=>
$site_row
[
'site_uri'
]
)
);
$sql
=
"SELECT c.cat_id, c.cat_title, c.cat_order, c.site_id,
(
SELECT COUNT(*)
FROM "
.
ALL_FORUMS_TABLE .
" f
WHERE f.cat_id = c.cat_id
) num_forums,
(
SELECT COUNT(*)
FROM "
.
ALL_TOPICS_TABLE .
" t
INNER JOIN "
.
ALL_FORUMS_TABLE .
" f ON t.forum_id = f.forum_id
WHERE f.cat_id = c.cat_id
) num_topics,
(
SELECT COUNT(*)
FROM "
.
ALL_POSTS_TABLE .
" p
INNER JOIN "
.
ALL_TOPICS_TABLE .
" t ON p.topic_id = t.topic_id
INNER JOIN "
.
ALL_FORUMS_TABLE .
" f ON t.forum_id = f.forum_id
WHERE f.cat_id = c.cat_id
) num_posts
FROM "
.
ALL_CATEGORIES_TABLE .
" c
WHERE site_id = "
.
$site_row
[
'site_id'
]
.
"
ORDER BY cat_order"
;
if
( !
$q_categories
=
$db
->
sql_query($sql
) )
{
message_die(GENERAL_ERROR,
"Couldn't get list of Categories"
,
""
,
__LINE__
,
__FILE__
,
$sql
);
}
if
( $db
->
sql_numrows($q_categories
) )
{
$category_rows
=
$db
->
sql_fetchrowset($q_categories
);
foreach
($category_rows
as
$i
=>
$category_row
)
{
$template
->
assign_block_vars('siterow.catrow'
,
array
(
'CAT_ID'
=>
$category_row
[
'cat_id'
],
'CAT_DESC'
=>
$category_row
[
'cat_title'
],
'NUM_FORUMS'
=>
$category_row
[
'num_forums'
],
'NUM_TOPICS'
=>
$category_row
[
'num_topics'
],
'NUM_POSTS'
=>
$category_row
[
'num_posts'
],
'U_VIEWCAT'
=>
append_sid($phpbb_root_path
.
"index.
$phpEx
?"
.
POST_CAT_URL .
"=
$category_row[cat_id]
"
))
);
$sql
=
"SELECT site_id, site_uri
FROM "
.
ALL_SITES_TABLE .
"
WHERE site_id <> "
.
$category_row
[
'site_id'
]
.
"
ORDER BY site_uri"
;
if
( !
$q_catsites
=
$db
->
sql_query($sql
) )
{
message_die(GENERAL_ERROR,
"Couldn't get list of Sites"
,
""
,
__LINE__
,
__FILE__
,
$sql
);
}
if
($db
->
sql_numrows($q_catsites
))
{
$catsites
=
$db
->
sql_fetchrowset($q_catsites
);
foreach
($catsites
as
$catsite
)
{
$template
->
assign_block_vars('siterow.catrow.site'
,
array
(
'SITE_ID'
=>
$catsite
[
'site_id'
],
'SITE_URI'
=>
$catsite
[
'site_uri'
]
)
);
}
}
}
}
}
}
//
// Start page proper
//
$template
->
set_filenames(array
(
"body"
=>
"admin/forum_admin_migrate.tpl"
)
);
$template
->
assign_vars(array
(
'S_FORUM_ACTION'
=>
append_sid("admin_migrate.
$phpEx
"
),
'L_CATEGORY'
=>
$lang
[
'Category'
],
'L_DESTINATION'
=>
$lang
[
'Destination'
],
'L_FORUMS'
=>
$lang
[
'Forums'
],
'L_TOPICS'
=>
$lang
[
'Topics'
],
'L_POSTS'
=>
$lang
[
'Posts'
],
'L_FORUM_TITLE'
=>
$lang
[
'Forum_admin'
],
'L_FORUM_EXPLAIN'
=>
$lang
[
'Forum_admin_explain'
]
)
);
$template
->
pparse("body"
);
include('./page_footer_admin.'
.
$phpEx
);
?>