4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2006 The Nucleus Group
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * (see nucleus/documentation/index.html#license for more info)
15 * This script will import a Live Journal blog into a Nucleus blog, using
16 * a easy to use wizard.
19 * - Templates are not converted
20 * - Nucleus should already be installed
21 * - Members should exist for all teammembers
23 * @license http://nucleuscms.org/license.txt GNU General Public License
24 * @copyright Copyright (C) 2002-2006 The Nucleus Group
25 * @version $Id: livejournal.php 1624 2012-01-09 11:36:20Z sakamocchi $
28 include("../../config.php");
29 include("functions.inc.php");
30 include($DIR_LIBS . "ADMIN.php");
31 include($DIR_LIBS . "MEDIA.php");
33 if (!$member->isLoggedIn()) {
34 convert_showLogin('livejournal.php');
37 if (!$member->isAdmin()) {
38 convert_doError('Only Super-Admins are allowed to perform blog conversions');
41 $ver = convert_getNucleusVersion();
43 convert_doError("You should check the Nucleus website for updates to this convert tool. This one might not work with your current Nucleus installation.");
45 // include PRAX lib (to read XML files easily)
50 bc_assignMembers(); break;
52 bc_showOverview(); break;
54 bc_doConversion(); break;
55 case "login": // drop through
57 bc_getlivejournalID();
60 // step 1: get the Blogger Blog ID
61 function bc_getlivejournalID() {
62 global $HTTP_SERVER_VARS, $PHP_SELF;
68 <b>Note:</b> This conversion tool was written for LiveJournal blogs. </div>
70 <h1>Step 1: Exporting to a file</h1>
73 The first step in the conversion is to export one month's Live Journal entries into one single file. This can be done with an export tool you can read about in the LiveJournal.com F.A.Q. <a href="http://www.livejournal.com/support/faqbrowse.bml?faqid=8" target="_blank">here</a>. The export tool itself can be found <a href="http://www.livejournal.com/export.bml" target="_blank">here</a>. The settings you will need are as follows:
76 <p><li><b>Format</b>: XML</li>
77 <p><li><b>Encoding</b>: Unicode</li>
78 <p><li><b>Fields</b>:<br></li>
81 <li>Event Time</li></ul>
82 <p></b>(all others should be unselected)<br>
85 Save the resulting file as <b>ljent.xml</b>.
91 Now you have a file called <b>ljent.xml</b>. Upload it in the same directory as the convert files (/nucleus/convert) and continue to the next step.
95 <form method="post" action="livejournal.php">
96 <input type="submit" value="Next Step: Assign Member" />
97 <input type="hidden" name="action" value="assignMembers" />
107 function bc_assignMembers() {
108 global $HTTP_POST_VARS, $CONF;
111 if (!file_exists('ljent.xml'))
112 convert_doError("ljent.xml not found. Make sure it is in the correct directory");
113 if (!is_readable('ljent.xml'))
114 convert_doError("The ljent.xml file is not readable. Make sure the file permissions are set correctly so PHP can access it.");
119 <form method="post" action="livejournal.php">
122 <h1>Step 2: Assign Members to Authors</h1>
125 Please assign a Nucleus Member to these entries.
131 <th>Blogger Author</th>
132 <th>Nucleus Member</th>
139 $blog->openfile('ljent.xml');
140 $blog->record_delim = 'entry';
144 $blog->close(); // close the file
152 <input name="default" value="default" type="hidden" />
156 $query = "SELECT mname as text, mnumber as value"
157 . " FROM ".sql_table('member');
159 $template['name'] = 'memberid[' . $idx . ']';
160 showlist($query,'select',$template);
164 <input name="admin[<?php echo $idx?>]" type="checkbox" value="1" id="admin<?php echo $idx?>" /><label for="admin<?php echo $idx?>">Blog Admin</label>
176 <h1>Choose Destination Weblog</h1>
179 There are two options: you can either choose an existing blog to add the Live Journal entries into, or you can choose to create a new weblog.
183 <input name="createnew" value="0" type="radio" checked='checked' id="createnew_no" /><label for="createnew_no">Choose existing weblog to add to:</label>
186 $query = "SELECT bname as text, bnumber as value"
187 . " FROM ".sql_table('blog');
188 $template['name'] = 'blogid';
189 $template['selected'] = $CONF['DefaultBlog'];
190 showlist($query,'select',$template);
194 <input name="createnew" value="1" type="radio" id="createnew_yes" /><label for="createnew_yes">Create new weblog</label>
196 <li>New blog name: <input name="newblogname" /></li>
199 $query = "SELECT mname as text, mnumber as value"
200 . " FROM ".sql_table('member');
202 $template['name'] = 'newowner';
203 showlist($query,'select',$template);
209 <h1>Do the conversion!</h1>
211 <input type="hidden" name="authorcount" value="<?php echo $idx?>" />
212 <input type="submit" value="Step 3: Do the conversion!" />
213 <input type="hidden" name="action" value="doConversion" />
217 <b>Note:</b> Clicking the button once is enough, even if it takes a while to complete.
228 function bc_doConversion() {
229 global $HTTP_POST_VARS, $manager;
232 $authorcount = intval($HTTP_POST_VARS['authorcount']);
233 $author = $HTTP_POST_VARS['author'];
235 for ($i=0;$i<$authorcount;$i++) {
237 $memberid[$key] = intval($HTTP_POST_VARS['memberid'][$i]);
238 $isadmin[$key] = intval($HTTP_POST_VARS['admin'][$i]);
241 $createnew = intval($HTTP_POST_VARS['createnew']);
242 $newblogname = stripslashes($HTTP_POST_VARS['newblogname']);
243 $newowner = intval($HTTP_POST_VARS['newowner']);
245 $nucleus_blogid = intval($HTTP_POST_VARS['blogid']);
253 <h1>Step 3: Converting...</h1>
256 Please be patient. Don't hit reload! The conversion progress should be showing below.
260 // try to extend time limit
261 // surpress error messages when not allowed to do so
262 @set_time_limit(1200);
266 echo "Authors: <br/>";
267 for ($i=0;$i<$authorcount;$i++) {
268 echo "\tAuthor=" . $author[$i];
269 echo " ID=" . $memberid[$author[$i]];
270 echo " ADMIN=" . $isadmin[$author[$i]];
273 echo "Create New Weblog = $createnew (name='$newblogname', owner=$newowner, dest=$nucleus_blogid)<br />";
278 if ($createnew == 1) {
279 // choose unique name
280 $shortname = 'blogger';
281 if (Blog::exists($shortname)) {
283 while (Blog::exists($shortname . $idx))
285 $shortname = $shortname . $idx;
288 $nucleus_blogid = convert_addToBlog($newblogname, $shortname, $newowner);
289 echo "<pre>New blog created</pre>";
292 // add authors to blog team
293 $b =& $manager->getBlog($nucleus_blogid);
295 $catid = $b->getDefaultCategory();
297 for ($i=0;$i<$authorcount;$i++)
298 $b->addTeamMember($memberid[$author[$i]],$isadmin[$author[$i]]);
301 // 3. go through ljent.xml file
304 $blog->openfile('ljent.xml');
305 $blog->record_delim = 'entry';
308 while ( $entry = $blog->readRecord() ) {
309 $row = $entry->getRow();
311 bc_convertOneItem($row, $memberid, $nucleus_blogid);
314 $blog->close(); // close the file
316 echo "<pre>All done!</pre>";
322 function bc_convertOneItem($row, $memberid, $nucleus_blogid) {
325 $nucl_id = $memberid[$row['author']];
327 $timestamp = date("Y-m-d H:i:s",bc_transformDate($row['eventtime']));
330 echo "<b>entry</b>:" . Entity::hsc(substr($row['event'],0,20)) . "...(time: " . $timestamp . ") \n";
331 echo "<b>author</b>: " . $row['author'] ;
332 echo " (nucleus-id: " . $nucl_id . ")";
335 $title = $row['subject']; // use the title when it is in the XML file
336 convert_addToItem($title, $row['event'], '', $nucleus_blogid, $nucl_id, $timestamp, 0, $catid, 0, 0);
340 function bc_transformDate($eventtime) {
341 // 2003-07-03 23:59:00
342 if (eregi("(.*)-(.*)-(.*) (.*):(.*):(.*)",$eventtime,$regs) != false) {
343 return mktime($regs[4],$regs[5],$regs[6],$regs[2],$regs[3],$regs[1]);