isLoggedIn()) { convert_showLogin('greymatter.php'); } if (!$member->isAdmin()) { convert_doError('Only Super-Admins are allowed to perform blog conversions'); } $ver = convert_getNucleusVersion(); if ($ver > 210) convert_doError("You should check the Nucleus website for updates to this convert tool. This one might not work with your current Nucleus installation."); switch($action) { case "assignMembers": gmc_assignMembers(); break; case "showOverview": gmc_showOverview(); break; case "doConversion": gmc_doConversion(); break; case "login": // drop through default: gmc_askGreyPath(); } function gmc_askGreyPath() { global $HTTP_SERVER_VARS, $PHP_SELF; convert_head(); // try to guess greymatter path $guess = $HTTP_SERVER_VARS["PATH_TRANSLATED"]; $guess = str_replace("/nucleus/convert","",$guess); $guess = str_replace("greymatter.php","",$guess); $guess = str_replace("\\","/",$guess); // add slash at end if necessary if (!endsWithSlash($guess)) $guess .= '/'; if (file_exists($guess . 'gm-authors.cgi')) $guess = $guess; else if (file_exists($guess . 'gm/gm-authors.cgi')) $guess = $guess . 'gm/'; else if (file_exists($guess . 'greymatter/gm-authors.cgi')) $guess = $guess . 'greymatter/'; else if (file_exists($guess . '../gm-authors.cgi')) $guess = $guess . '../'; else if (file_exists($guess . '../gm/gm-authors.cgi')) $guess = $guess . '../gm/'; else if (file_exists($guess . '../greymatter/gm-authors.cgi')) $guess = $guess . '../greymatter/'; ?>

Before you start

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.

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)

Greymatter Path

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.
Note: The path should end with a slash!

Assign Members to Authors

Below is a list of all the GreyMatter authors that Nucleus could discover. Please assign a Nucleus Member to all of these authors.

GreyMatter Author Nucleus Member Blog Admin?
/>
(users not listed in gm-authors.cgi)

Choose Destination Weblog

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.

:

Do the conversion!

Converting...

Please be patient. Don't hit reload! The conversion progress should be showing below.

"; echo "Authors:
"; for ($i=0;$i<$authorcount;$i++) { echo "\tAuthor=" . $author[$i]; echo " ID=" . $memberid[$author[$i]]; echo " ADMIN=" . $isadmin[$author[$i]]; echo "
"; } echo "Create New Weblog = $createnew (name='$newblogname', owner=$newowner, dest=$nucleus_blogid)
"; echo ""; // create blog if ($createnew == 1) { // choose unique name $shortname = 'greymatter'; if (Blog::exists($shortname)) { $idx = 1; while (Blog::exists($shortname . $idx)) $idx++; $shortname = $shortname . $idx; } $nucleus_blogid = convert_addToBlog($newblogname, $shortname, $newowner); echo "
New blog created
"; } // add authors to blog team $blog =& $manager->getBlog($nucleus_blogid); global $catid; $catid = $blog->getDefaultCategory(); for ($i=0;$i<$authorcount;$i++) $blog->addTeamMember($memberid[$author[$i]],$isadmin[$author[$i]]); // go through all files $dirhandle = opendir($grey_datapath); while ($filename = readdir($dirhandle)) { if (ereg("\.cgi$",$filename)) { gmc_convertOneFile($grey_datapath . $filename, $nucleus_blogid, $memberid); } } closedir($dirhandle); echo "
All done!
"; convert_foot(); } /** * Converts one GreyMatter entry into a Nucleus Item */ function gmc_convertOneFile($filename, $nucleus_blogid, $memberid) { global $catid; echo "
";

	$filehandle = fopen($filename,'r');

	$entry_info = fgets($filehandle,4096);	// entry info
	$entry_karma = fgets($filehandle,4096); // ips of karma voters (ignore)
	$entry_body = fgets($filehandle,4096);  // body
	$entry_more = fgets($filehandle,4096);  // extended

	// decode information
	$entry_info = str_replace("|*|","\n",$entry_info);
	$entry_body = str_replace("|*|","\n",$entry_body);
	$entry_more = str_replace("|*|","\n",$entry_more);

	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);

	if (($e_ampm == "PM") && ($e_hour != 12 ))
		$e_hour = $e_hour + 12;

	if ($e_allowcomments == "yes")
		$e_closed = 0;
	else
		$e_closed = 1;

	$e_timestamp = mktime($e_hour, $e_min, $e_sec, $e_mon, $e_mday, $e_year);
	$e_timestamp = date("Y-m-d H:i:s",$e_timestamp);



	$nucl_id = $memberid[$e_author];
	if (intval($nucl_id) == 0)
		$nucl_id = $memberid['_other_'];

	// handle {{link, {{linkmo, {{email and {{emailmo
	$e_title = gm_parsecommands($e_title,$nucl_id);
	$entry_body = gm_parsecommands($entry_body,$nucl_id);
	$entry_more = gm_parsecommands(trim($entry_more),$nucl_id);

	echo "Title: $e_title
"; echo "\tGreyMatter Author = $e_author
"; echo "\tNucleus Memberid = $nucl_id
"; echo "\tKarma: $e_karmapos+/$e_karmaneg-
"; // add to nucleus_item table $nucleus_itemid = convert_addToItem($e_title, $entry_body, $entry_more, $nucleus_blogid, $nucl_id, $e_timestamp, $e_closed, $catid, $e_karmapos, $e_karmaneg); echo "\tComments:
"; while ($comment = fgets($filehandle,4096)) { // echo "\t\tConverting comment: $comment
"; // decode $comment = str_replace("|*|","\n",$comment); 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); echo "\t\tConverting comment by $c_author
"; // make hrefs out of links $c_body = eregi_replace("(http://([a-zA-Z0-9]|\.|/|~|%|&|\?|\@|\=|_|\+|\:|;|-)*)","http://.../",$c_body); // special markup commands $c_body = gm_parsecommands($c_body,0); if ($c_ampm == "PM") $c_hour = $c_hour + 12; $c_timestamp = mktime($c_hour, $c_min, $c_sec, $c_mon, $c_mday, $c_year); $c_timestamp = date("Y-m-d H:i:s",$c_timestamp); // choose url or email to pass as userid if (stristr($c_url,'http://') != false) $c_userid = $c_url; else $c_userid = $c_email; // add to comments convert_addToComments($c_author, $c_userid, $c_body, $nucleus_blogid, $nucleus_itemid, 0, $c_timestamp, $c_ip); } fclose($filehandle); echo "
"; } // returns $text with special greymatter markup commands expanded. function gm_parsecommands($text, $authorid ) { // special markup characters // **bold text** -> bold text // __underlined text__ -> underlined text // \\italic text\\ -> italic text $to_replace = array( "/\*\*(.*?)\*\*/is", "/\\\\(.*?)\\\\/is", "/__(.*?)__/is" ); $replace_by = array( "\\1", "\\1", "\\1" ); $text = preg_replace($to_replace, $replace_by, $text); // {{link url}} // {{link url text}} // {{linkmo url text|mouseover text}} // {{email address}} // {{email address text}} // {{emailmo address text|mouseover text}} // {{popup if (i18n::strpos($text,"{{link") !== FALSE || stristr($text,"{{email") || stristr($text,"{{popup")) { $to_replace = array( "/({{linkmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/ies", "/({{link) (http|https|ftp)(:\/\/\S+?)(}})/is", "/({{link) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/is", "/({{emailmo) (\S+\@\S+?) (.+?)(\|)(.+?)(}})/ies", "/({{email) (\S+\@\S+?)(}})/is", "/({{email) (\S+\@\S+?) (.+?)(}})/is", "/{{popup (\S+) (.+?) (\d+)x(\d+)}}(.*?)<\/a>/ies" ); $replace_by = array( // linkmo 'gm_linkmo("\\2\\3","\\6","\\4")', // link "\\2\\3", "\\4", // emailmo 'gm_linkmo("mailto:\\2","\\5","\\3")', // email "\\2", "\\3", // popup 'gm_popup("\\1",$authorid,"\\5",\\3,\\4)' ); $text = preg_replace($to_replace, $replace_by, $text); } // newlines (greymatter renders newlines as linebreaks) $text = ereg_replace("\n","
",$text); // newlines return $text; } // makes sure quotes are escaped in javascript strings // php seems to quote the arguments as the get passed to this method by preg_replace // with /e modifier function gm_linkmo($url, $mouseover, $text) { // remove slashes from text (not needed there) $text = stripslashes($text); // replace " by \' in mouseover (to avoid error) $mouseover = str_replace('"',"\'",$mouseover); return ''.$text.''; } // converts GM {{popup command into a link to the image function gm_popup($filename, $authorid, $text, $width, $height) { global $grey_datapath, $manager; $res = Media::addMediaObject($manager->getMember($authorid), "$grey_datapath$filename", $filename); if ($res != "") die("error copying media files: $res"); // TODO: copy file to media directory // TODO: create %popup(...)% code instead $text = Entity::hsc(stripslashes($text)); return "<%popup($filename|$width|$height|$text)%>"; } ?>