3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2006 The Nucleus Group
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)
14 * This script will convert a GreyMatter blog to a Nucleus blog, using
15 * a easy to use wizard.
17 * Last Modified: August 20, 2002
20 * - templates are not converted
21 * - Nucleus should already be installed
23 * @license http://nucleuscms.org/license.txt GNU General Public License
24 * @copyright Copyright (C) 2002-2006 The Nucleus Group
25 * @version $Id: greymatter.php 1889 2012-06-17 08:46:45Z 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('greymatter.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.");
47 gmc_assignMembers(); break;
49 gmc_showOverview(); break;
51 gmc_doConversion(); break;
52 case "login": // drop through
57 function gmc_askGreyPath() {
58 global $HTTP_SERVER_VARS, $PHP_SELF;
62 // try to guess greymatter path
63 $guess = $HTTP_SERVER_VARS["PATH_TRANSLATED"];
64 $guess = str_replace("/nucleus/convert","",$guess);
65 $guess = str_replace("greymatter.php","",$guess);
66 $guess = str_replace("\\","/",$guess);
67 // add slash at end if necessary
68 if (!endsWithSlash($guess)) $guess .= '/';
70 if (file_exists($guess . 'gm-authors.cgi'))
72 else if (file_exists($guess . 'gm/gm-authors.cgi'))
73 $guess = $guess . 'gm/';
74 else if (file_exists($guess . 'greymatter/gm-authors.cgi'))
75 $guess = $guess . 'greymatter/';
76 else if (file_exists($guess . '../gm-authors.cgi'))
77 $guess = $guess . '../';
78 else if (file_exists($guess . '../gm/gm-authors.cgi'))
79 $guess = $guess . '../gm/';
80 else if (file_exists($guess . '../greymatter/gm-authors.cgi'))
81 $guess = $guess . '../greymatter/';
85 <h1>Before you start</h1>
88 Before you start converting, make sure that you have created Nucleus Member accounts for all your GreyMatter authors. You'll be asked to assign Nucleus member accounts to GreyMatter authors in the next step.
92 If you used {{popup}} tags in GreyMatter to create popup windows with images, make sure you've set the mediadir correctly and that has the correct filepermissions to allow upload. (Nucleus will copy your images to that directory)
95 <h1>Greymatter Path</h1>
97 <form method="post" action="greymatter.php">
100 Please enter the path in which the GreyMatter script is installed below. The current value is a guess by Nucleus. The GreyMatter data path will be extracted from the GM config in the next step.
102 <b>Note:</b> The path should end with a slash!
106 <li>GreyMatter path: <input name="grey_scriptpath" size="60" value="<?php echo Entity::hsc($guess)?>" /></li>
110 <input type="submit" value="Next Step: Assign Members to Authors" />
111 <input type="hidden" name="action" value="assignMembers" />
119 function gmc_assignMembers() {
120 global $HTTP_POST_VARS, $CONF;
122 // get data from form
123 $grey_scriptpath = stripslashes($HTTP_POST_VARS['grey_scriptpath']);
124 $grey_scriptpath = str_replace("\\","/",$grey_scriptpath);
127 if (!is_dir($grey_scriptpath))
128 convert_doError("Given GreyMatter Path does not exist");
129 if (!endsWithSlash($grey_scriptpath))
130 convert_doError("Given GreyMatter Path does not end with a slash");
131 $grey_configfile = $grey_scriptpath . 'gm-config.cgi';
132 if (!is_readable($grey_configfile))
133 convert_doError("GreyMatter configfile ($grey_configfile) is not readable. Make sure the path is correct and the file permissions are set correctly so PHP can access it.");
135 // get datapath out of configfile
136 $filehandle = fopen($grey_configfile,'r');
137 $skip = fgets($filehandle,4096);
138 $grey_datapath = chop(fgets($filehandle,4096)) . '/';
139 $skip = fgets($filehandle,4096);
140 $grey_dataurl = chop(fgets($filehandle,4096)) . '/';
143 if (!is_dir($grey_datapath))
144 convert_doError("GreyMatter Data Path extracted from GreyMatter configuration does not exist. Please check your GreyMatter settings.");
146 $grey_authorfile = $grey_scriptpath . 'gm-authors.cgi';
148 if (!is_readable($grey_authorfile))
149 convert_doError("GreyMatter authorfile ($grey_authorfile) is not readable. Make sure the path is correct and the file permissions are set correctly so PHP can access it.");
154 <form method="post" action="greymatter.php">
157 <h1>Assign Members to Authors</h1>
160 Below is a list of all the GreyMatter authors that Nucleus could discover. Please assign a Nucleus Member to all of these authors.
166 <th>GreyMatter Author</th>
167 <th>Nucleus Member</th>
172 $filehandle = fopen($grey_authorfile,'r');
174 while ($author = fgets($filehandle,4096)) {
175 list ($a_name, $a_pwd, $a_email, $a_url, $a_data, $a_entries, $a_entryaccess, $a_entryeditaccess, $a_configureaccess, $templateaccess, $a_authoraccess, $a_rebuildaccess, $a_cplogaccess, $bookmarkletaccess, $uploadaccess, $loginaccess) = explode ("|", $author);
179 <b><?php echo $a_name?></b>
180 <input name="author[<?php echo $idx?>]" value="<?php echo Entity::hsc($a_name)?>" type="hidden" />
183 <?php // TODO: avoid doing this query multiple times
184 $query = 'SELECT mname as text, mnumber as value FROM '.sql_table('member');
186 $template['name'] = 'memberid[' . $idx . ']';
187 echo showlist($query,'select',$template);
191 <input name="admin[<?php echo $idx?>]" type="checkbox" value="1" id="admin<?php echo $idx?>" <?php if ($a_configureaccess == 'Y') echo "checked='checked'";
193 /><label for="admin<?php echo $idx?>">Blog Admin</label>
204 <i>(users not listed in gm-authors.cgi)</i>
205 <input name="author[0]" value="_other_" type="hidden" />
208 <?php // TODO: avoid doing this query multiple times
209 $query = 'SELECT mname as text, mnumber as value FROM '.sql_table('member');
211 $template['name'] = 'memberid[0]';
212 echo showlist($query,'select',$template);
216 <input name="admin[0]" type="checkbox" value="1" id="admin0" /><label for="admin0">Blog Admin</label>
222 <h1>Choose Destination Weblog</h1>
225 There are two options: you can either choose an existing blog to add the greymatter entries into, or you can choose to create a new weblog.
229 <input name="createnew" value="0" type="radio" checked='checked' label="createnew_no" /><label for="createnew_no">Choose existing weblog to add to</label>:
231 <?php $query = 'SELECT bname as text, bnumber as value FROM '.sql_table('blog');
232 $template['name'] = 'blogid';
233 $template['selected'] = $CONF['DefaultBlog'];
234 echo showlist($query,'select',$template);
238 <input name="createnew" value="1" type="radio" id="createnew_yes" /><label for="createnew_yes">Create new weblog</label>
240 <li>New blog name: <input name="newblogname" /></li>
242 <?php // TODO: avoid doing this query multiple times
243 $query = 'SELECT mname as text, mnumber as value FROM '.sql_table('member');
245 $template['name'] = 'newowner';
246 echo showlist($query,'select',$template);
252 <h1>Do the conversion!</h1>
254 <input type="hidden" name="authorcount" value="<?php echo $idx?>" />
255 <input type="hidden" name="grey_scriptpath" value="<?php echo Entity::hsc($grey_scriptpath)?>" />
256 <input type="hidden" name="grey_datapath" value="<?php echo Entity::hsc($grey_datapath)?>" />
257 <input type="hidden" name="grey_dataurl" value="<?php echo Entity::hsc($grey_dataurl)?>" />
258 <input type="submit" value="Do the conversion!" />
259 <input type="hidden" name="action" value="doConversion" />
268 function gmc_doConversion() {
269 global $HTTP_POST_VARS, $manager;
273 $authorcount = intval($HTTP_POST_VARS['authorcount']);
274 $author = $HTTP_POST_VARS['author'];
276 for ($i=0;$i<$authorcount;$i++) {
278 $memberid[$key] = intval($HTTP_POST_VARS['memberid'][$i]);
279 $isadmin[$key] = intval($HTTP_POST_VARS['admin'][$i]);
282 $grey_scriptpath = stripslashes($HTTP_POST_VARS['grey_scriptpath']);
283 $grey_datapath = stripslashes($HTTP_POST_VARS['grey_datapath']);
284 $grey_dataurl = stripslashes($HTTP_POST_VARS['grey_dataurl']);
286 // needed in gm_popup
287 global $grey_datapath;
289 $createnew = intval($HTTP_POST_VARS['createnew']);
290 $newblogname = stripslashes($HTTP_POST_VARS['newblogname']);
291 $newowner = intval($HTTP_POST_VARS['newowner']);
293 $nucleus_blogid = intval($HTTP_POST_VARS['blogid']);
301 <h1>Converting...</h1>
304 Please be patient. Don't hit reload! The conversion progress should be showing below.
307 // try to extend time limit
308 // surpress error messages when not allowed to do so
309 @set_time_limit(1200);
313 echo "Authors: <br/>";
314 for ($i=0;$i<$authorcount;$i++) {
315 echo "\tAuthor=" . $author[$i];
316 echo " ID=" . $memberid[$author[$i]];
317 echo " ADMIN=" . $isadmin[$author[$i]];
320 echo "Create New Weblog = $createnew (name='$newblogname', owner=$newowner, dest=$nucleus_blogid)<br />";
325 if ($createnew == 1) {
326 // choose unique name
327 $shortname = 'greymatter';
328 if (Blog::exists($shortname)) {
330 while (Blog::exists($shortname . $idx))
332 $shortname = $shortname . $idx;
335 $nucleus_blogid = convert_addToBlog($newblogname, $shortname, $newowner);
336 echo "<pre>New blog created</pre>";
339 // add authors to blog team
340 $blog =& $manager->getBlog($nucleus_blogid);
342 $catid = $blog->getDefaultCategory();
343 for ($i=0;$i<$authorcount;$i++)
344 $blog->addTeamMember($memberid[$author[$i]],$isadmin[$author[$i]]);
346 // go through all files
347 $dirhandle = opendir($grey_datapath);
348 while ($filename = readdir($dirhandle)) {
349 if (ereg("\.cgi$",$filename)) {
350 gmc_convertOneFile($grey_datapath . $filename, $nucleus_blogid, $memberid);
353 closedir($dirhandle);
355 echo "<pre>All done!</pre>";
362 * Converts one GreyMatter entry into a Nucleus Item
364 function gmc_convertOneFile($filename, $nucleus_blogid, $memberid) {
369 $filehandle = fopen($filename,'r');
371 $entry_info = fgets($filehandle,4096); // entry info
372 $entry_karma = fgets($filehandle,4096); // ips of karma voters (ignore)
373 $entry_body = fgets($filehandle,4096); // body
374 $entry_more = fgets($filehandle,4096); // extended
376 // decode information
377 $entry_info = str_replace("|*|","\n",$entry_info);
378 $entry_body = str_replace("|*|","\n",$entry_body);
379 $entry_more = str_replace("|*|","\n",$entry_more);
381 list ($e_number, $e_author, $e_title, $e_wday, $e_mon, $e_mday, $e_year, $e_hour, $e_min, $e_sec, $e_ampm, $e_karmapos, $e_karmaneg, $e_commentcount, $e_allowkarma, $e_allowcomments, $e_openclosed) = explode ("|", $entry_info);
383 if (($e_ampm == "PM") && ($e_hour != 12 ))
384 $e_hour = $e_hour + 12;
386 if ($e_allowcomments == "yes")
391 $e_timestamp = mktime($e_hour, $e_min, $e_sec, $e_mon, $e_mday, $e_year);
392 $e_timestamp = date("Y-m-d H:i:s",$e_timestamp);
396 $nucl_id = $memberid[$e_author];
397 if (intval($nucl_id) == 0)
398 $nucl_id = $memberid['_other_'];
400 // handle {{link, {{linkmo, {{email and {{emailmo
401 $e_title = gm_parsecommands($e_title,$nucl_id);
402 $entry_body = gm_parsecommands($entry_body,$nucl_id);
403 $entry_more = gm_parsecommands(trim($entry_more),$nucl_id);
405 echo "Title: <b>$e_title</b><br />";
406 echo "\tGreyMatter Author = $e_author<br />";
407 echo "\tNucleus Memberid = $nucl_id<br />";
408 echo "\tKarma: $e_karmapos+/$e_karmaneg-<br />";
411 // add to nucleus_item table
412 $nucleus_itemid = convert_addToItem($e_title, $entry_body, $entry_more, $nucleus_blogid, $nucl_id, $e_timestamp, $e_closed, $catid, $e_karmapos, $e_karmaneg);
415 echo "\tComments: <br/>";
417 while ($comment = fgets($filehandle,4096)) {
418 // echo "\t\tConverting comment: $comment<br />";
421 $comment = str_replace("|*|","\n",$comment);
422 list ($c_author, $c_ip, $c_email, $c_url, $c_wday, $c_mon, $c_mday, $c_year, $c_hour, $c_min, $c_sec, $c_ampm, $c_body) = explode("|",$comment);
424 echo "\t\tConverting comment by <i>$c_author</i><br />";
426 // make hrefs out of links
427 $c_body = eregi_replace("(http://([a-zA-Z0-9]|\.|/|~|%|&|\?|\@|\=|_|\+|\:|;|-)*)","<a href='\\0'>http://.../</a>",$c_body);
429 // special markup commands
430 $c_body = gm_parsecommands($c_body,0);
433 $c_hour = $c_hour + 12;
434 $c_timestamp = mktime($c_hour, $c_min, $c_sec, $c_mon, $c_mday, $c_year);
435 $c_timestamp = date("Y-m-d H:i:s",$c_timestamp);
437 // choose url or email to pass as userid
438 if (stristr($c_url,'http://') != false)
441 $c_userid = $c_email;
444 convert_addToComments($c_author, $c_userid, $c_body, $nucleus_blogid, $nucleus_itemid, 0, $c_timestamp, $c_ip);
454 // returns $text with special greymatter markup commands expanded.
455 function gm_parsecommands($text, $authorid ) {
456 // special markup characters
457 // **bold text** -> <b>bold text</b>
458 // __underlined text__ -> <u>underlined text</u>
459 // \\italic text\\ -> <i>italic text</i>
470 $text = preg_replace($to_replace, $replace_by, $text);
474 // {{linkmo url text|mouseover text}}
476 // {{email address text}}
477 // {{emailmo address text|mouseover text}}
479 if (i18n::strpos($text,"{{link") !== FALSE || stristr($text,"{{email") || stristr($text,"{{popup")) {
481 "/({{linkmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/ies",
482 "/({{link) (http|https|ftp)(:\/\/\S+?)(}})/is",
483 "/({{link) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/is",
484 "/({{emailmo) (\S+\@\S+?) (.+?)(\|)(.+?)(}})/ies",
485 "/({{email) (\S+\@\S+?)(}})/is",
486 "/({{email) (\S+\@\S+?) (.+?)(}})/is",
487 "/{{popup (\S+) (.+?) (\d+)x(\d+)}}(.*?)<\/a>/ies"
491 'gm_linkmo("\\2\\3","\\6","\\4")',
493 "<a href='\\2\\3'>\\2\\3</a>",
494 "<a href='\\2\\3'>\\4</a>",
496 'gm_linkmo("mailto:\\2","\\5","\\3")',
498 "<a href='mailto:\\2'>\\2</a>",
499 "<a href='mailto:\\2'>\\3</a>",
501 'gm_popup("\\1",$authorid,"\\5",\\3,\\4)'
503 $text = preg_replace($to_replace, $replace_by, $text);
506 // newlines (greymatter renders newlines as linebreaks)
507 $text = ereg_replace("\n","<br />",$text); // newlines
512 // makes sure quotes are escaped in javascript strings
513 // php seems to quote the arguments as the get passed to this method by preg_replace
515 function gm_linkmo($url, $mouseover, $text) {
516 // remove slashes from text (not needed there)
517 $text = stripslashes($text);
519 // replace " by \' in mouseover (to avoid error)
520 $mouseover = str_replace('"',"\'",$mouseover);
522 return '<a href="' . $url . '" onmouseover="window.status=\'' . $mouseover . '\';return true" onmouseout="window.status=\'\';return true">'.$text.'</a>';
525 // converts GM {{popup command into a link to the image
526 function gm_popup($filename, $authorid, $text, $width, $height) {
527 global $grey_datapath, $manager;
529 $res = Media::addMediaObject($manager->getMember($authorid), "$grey_datapath$filename", $filename);
532 die("error copying media files: $res");
534 // TODO: copy file to media directory
535 // TODO: create %popup(...)% code instead
537 $text = Entity::hsc(stripslashes($text));
539 return "<%popup($filename|$width|$height|$text)%>";