OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / convert / blogger.php
1 <?php
2 /*
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4  * Copyright (C) 2002-2006 The Nucleus Group
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * (see nucleus/documentation/index.html#license for more info)
11  */
12 /**
13  * This script will import a Blogger blog into a Nucleus blog, using
14  * a easy to use wizard.
15  *
16  * Notes:
17  *   - Templates are not converted
18  *   - Nucleus should already be installed
19  *   - Members should exist for all teammembers
20  *
21  * History
22  *   v1.0 initial version
23  *   v1.1 (04/09/2005) change instruction as suggested by user (lloyd_borrett) 
24  *
25  * @license http://nucleuscms.org/license.txt GNU General Public License
26  * @copyright Copyright (C) 2002-2006 The Nucleus Group
27  * @version $Id: blogger.php 1692 2012-03-10 11:22:09Z sakamocchi $
28  */
29
30 include("../../config.php");
31 include("functions.inc.php");
32 include($DIR_LIBS . "ADMIN.php");
33 include($DIR_LIBS . "MEDIA.php");
34
35 $thisFile = 'blogger.php';
36 $xmlFile = 'blogger.xml';
37
38 if (!$member->isLoggedIn($thisFile)) {
39         convert_showLogin('blogger.php');
40 }
41
42 if (!$member->isAdmin()) {
43         convert_doError('Only Super-Admins are allowed to perform blog conversions');
44 }
45
46 // include PRAX lib (to read XML files easily)
47 include ('PRAX.php');
48
49 switch($action) {
50         case 'selectBlog':
51                 bc_selectBlog(); break;
52         case 'assignMembers':
53                 bc_assignMembers(); break;
54         case 'showOverview':
55                 bc_showOverview(); break;
56         case 'doConvert':
57                 bc_doConversion(); break;
58         case 'login': // drop through
59         default:
60                 bc_BloggerToXml();
61 }
62
63 // step 1: get the Blogger Blog ID
64 function bc_BloggerToXml() {
65         global $xmlFile, $thisFile;
66
67         convert_head();
68
69         ?>
70                 <h1>Step 1: Exporting to a file</h1>
71
72                 <p>
73                 The first step in the conversion is to export all your Blogger entries into one single file. This is done by logging in in Blogger and by temporary changing your settings and templates.
74                 <br />The full procedure is explained below:
75                 </p>
76
77                 <h2>Exporting</h2>
78
79                 <div class="note"><b>Note:</b> If you intend to keep using your weblog afterwards, write down the changes you made, so they can be undone afterwards. For the templates, copy paste the old ones in a textfile.</div>
80
81                 <ol>
82                         <li>
83                                 Log into <a href="http://www.blogger.com/">Blogger</a> and go to the blog you want to export.
84                         </li>
85                         <li>
86                                 Change the template of your blog to the following:
87
88                                 <pre><code>&lt;?xml version="1.0"?&gt;
89
90 &lt;blog xmlns="http://nucleuscms.org/ns/import1.0" version="1.0"&gt;
91
92  &lt;Blogger&gt;
93
94   &lt;item id="&lt;$BlogItemNumber$&gt;"&gt;
95    &lt;title&gt;&lt;BlogItemTitle&gt;&lt;$BlogItemTitle$&gt;&lt;/BlogItemTitle&gt;&lt;/title&gt;
96    &lt;body&gt;&lt;![CDATA[&lt;$BlogItemBody$&gt;]]&gt;&lt;/body&gt;
97    &lt;timestamp type="blogger"&gt;&lt;$BlogItemDateTime$&gt;&lt;/timestamp&gt;
98    &lt;author&gt;&lt;$BlogItemAuthor$&gt;&lt;/author&gt;
99   &lt;/item&gt;
100
101  &lt;/Blogger&gt;
102
103 &lt;/blog&gt;</code></pre>
104                                 Don't forget to save changes!
105                         </li>
106                         <li>
107                                 Go to the settings and change the following options:
108                                 <ul>
109                                         <li>
110                                                 Blog filename: <strong><?php echo $xmlFile?></strong>
111                                         </li>
112                                         <li>
113                                                 Show <b>900</b> <b>day's posts</b> on main page
114                                         </li>
115                                         <li>
116                                                 Under <b>Settings : Formating</b>, change the Timestamp Format to the date/time format <b>MM/DD/YYYY HH:MM:SS AM|PM</b> (that option is not listed as such, instead it has the current date filled in) 
117                                         </li>
118                                         <li>
119                                                 Archive Frequency: <b>No Archive</b>
120                                         </li>
121                                 </ul>
122                         </li>
123                         <li>
124                                 Save the settings and publish your blog. You'll end up with a <?php echo $xmlFile;?> file on your server containing all of your blog items.
125                         </li>
126                         <li>
127                                 If you're running blogspot, you'll need to edit this file and take out the advertising banner code.
128                         </li>
129                 </ol>
130
131                 <h2>Importing</h2>
132
133                 <p>You now have a file called <code><?php echo $xmlFile?></code>. Upload it in the same directory as the convert files (<code>/nucleus/convert</code>) and continue to the next step.</p>
134
135                 <p>
136                 <form method="post" action="<?php echo $thisFile;?>">
137                 <input type="submit" value="Next Step: Select Blog" />
138                 <input type="hidden" name="action" value="selectBlog" />
139                 </form>
140                 </p>
141
142         <?php
143         convert_foot();
144 }
145
146 function bc_selectBlog() {
147         global $CONF, $xmlFile, $thisFile;
148
149         // some checks
150         if (!file_exists($xmlFile))
151                 convert_doError($xmlFile . " not found. Make sure it is in the correct directory");
152         if (!is_readable($xmlFile))
153                 convert_doError($xmlFile ." file is not readable. Make sure the file permissions are set correctly so PHP can access it.");
154
155         convert_head();
156
157         $oImport = new BlogImport();
158
159         ?>
160
161         <h1>Step 2: Select Destination Blog</h1>
162
163                 <form method="post" action="<?php echo $thisFile;?>"><div>
164
165         <?php
166                 echo $oImport->getHtmlCode('ConvertSelectBlog');
167         ?>
168
169                 <p>
170                         <input type="submit" value="Next Step: Assign Members" />
171                         <input type="hidden" name="action" value="assignMembers" />
172                         (Could take quite a while. Press the button only once)
173                 </p>
174
175                 </div></form>
176
177         <?php
178         convert_foot();
179
180
181 }
182
183 function bc_assignMembers() {
184         global $xmlFile, $thisFile;
185         global $CONF;
186
187         // some checks
188         if (!file_exists($xmlFile))
189                 convert_doError($xmlFile . " not found. Make sure it is in the correct directory");
190         if (!is_readable($xmlFile))
191                 convert_doError($xmlFile ." file is not readable. Make sure the file permissions are set correctly so PHP can access it.");
192
193         convert_head();
194
195         ?>
196                 <form method="post" action="<?php echo $thisFile;?>"><div>
197
198                 <h1>Step 3: Assign members and Categories</h1>
199
200         <?php
201
202                 // create blog if requested
203                 $blogid = BlogImport::getBlogIdFromRequest();
204
205                 // read author and category names
206                 $oImport = new BlogImport($blogid, array('ReadNamesOnly' => 1));
207                 $oImport->importXmlFile($xmlFile);
208
209                 echo $oImport->getHtmlCode('ConvertSelectMembers');
210 //              echo $oImport->getHtmlCode('ConvertSelectCategories');
211         ?>
212
213                 <p>
214                         <input type="submit" value="Start Conversion" />
215                         <input type="hidden" name="blogid" value="<?php echo intval($blogid) ?>" />
216                         <input type="hidden" name="action" value="doConvert" /> (Could take quite a while. Press the button only once)
217                 </p>
218
219                 </div></form>
220         <?php
221         convert_foot();
222
223 }
224
225
226 function bc_doConversion() {
227         global $xmlFile, $thisFile;
228
229         // some checks
230         if (!file_exists($xmlFile))
231                 convert_doError($xmlFile . " not found. Make sure it is in the correct directory");
232         if (!is_readable($xmlFile))
233                 convert_doError($xmlFile ." file is not readable. Make sure the file permissions are set correctly so PHP can access it.");
234
235         convert_head();
236
237         echo '<h1>Step 4: Conversion</h1>';
238
239         echo '<h2>Importing...</h2>';
240         echo '<p>Hold on while your blog is imported...</p>';
241
242         // 1. get all data
243         $blogid = BlogImport::getBlogIdFromRequest();
244         $oImport = new BlogImport($blogid);
245
246         $oImport->getFromRequest('authors');
247         $oImport->getFromRequest('categories');
248         $oImport->strCallback = '';     // don't use a callback method
249
250         echo '<div>';
251         $bOk = $oImport->importXmlFile($xmlFile);
252         echo '</div>';
253
254         // 2. import data...
255         if (!$bOk) {
256                 echo '<p class="error">Error on import: ' . $oImport->getLastError() . '</p>';
257                 exit;
258         }
259
260         echo '<p>Successfully imported items</p>';
261
262         echo '<h2>Mappings</h2>';
263
264         echo '<p>The mapping below maps blogger post ids to nucleus ids.</p>';
265
266         echo '<pre>';
267         print_r($oImport->aMapIdToNucleusId);
268         echo '</pre>';
269
270         convert_foot();
271         convert_foot();
272
273 }
274
275
276
277
278
279 ?>