indicates the start of the VoodooPad entry, so create page object
$thispage = array();
break;
case 'key': // This is the unique identifier of the page
$mykey = serendipity_makeFilename($elements[$key_a]->data);
$mykey = basename($this->data['keyPrefix']) . $mykey;
// Pluck out the existing one if its there
$page = serendipity_db_query("SELECT *
FROM {$serendipity['dbPrefix']}staticpages
WHERE filename = '" . serendipity_db_escape_string($mykey.'.htm') . "'
LIMIT 1", true, 'assoc');
if (is_array($page)) {
$thispage =& $page;
if (empty($thispage['timestamp'])) {
$thispage['timestamp'] = time();
}
}
$thispage['filename'] = $mykey.'.htm';
// Thanks for pointing this out to me and not just fixing it, I'm learning.
$thispage['permalink'] = $serendipity['serendipityHTTPPath'] . 'index.php?serendipity[subpage]=' . $mykey;
break;
case 'alias': // The title and the string used to match links
$thispage['articleformattitle'] = $this->data['wikiName'];
$thispage['pagetitle'] = $mykey;
$thispage['headline'] = $elements[$key_a]->data;
break;
case 'content': // The content of a voodoopad entry
case 'path': // The path of a url string
$thispage['content'] = $elements[$key_a]->data;
// If its a content link list it for referencing with the page permalink
if ( $name == 'content' ){
$aliases[$thispage['headline']] = $thispage['permalink'];
// Either replace or insert depending on previous existence
if (!isset($thispage['id'])) {
echo '
'.IMPORTER_VOODOO_CREATINGPAGE.': '. $mykey;
serendipity_db_insert('staticpages', $thispage);
$serendipity["POST"]["staticpage"] = serendipity_db_insert_id("staticpages", 'id');
} elseif ($this->data['updateExisting'] == 'true') {
echo '
'.IMPORTER_VOODOO_UPDATINGPAGE.': '. $mykey;
serendipity_db_update("staticpages", array("id" => $thispage["id"]), $thispage);
} else {
echo '
'.IMPORTER_VOODOO_NOTUPDATING.': '. $mykey;
}
} else {
// If its a url, the content is the link instead
echo '
'.IMPORTER_VOODOO_RECORDURL.': '.$thispage['headline'];
$aliases[$thispage['headline']] = $thispage['content'];
}
break;
}
}
// Now rewrite the permalinks
echo '
';
if ($this->data['shouldWriteLinks'] == 'true') {
Serendipity_Import_VoodooPad::write_links($aliases);
}
return true;
}
function write_links($aliases) {
// Here we run through the static pages database and put in cross links
// around the keywords in the text
global $serendipity;
// **TODO** Change this to pull out only entries for the current wiki
echo '
'.IMPORTER_VOODOO_WRITEINTRALINKS.'
';
$pages= &serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}staticpages ORDER BY pagetitle DESC");
foreach ($pages as $thispage) {
// Parse the content string
foreach ($aliases as $alias => $permalink) {
$thispage['content'] = Serendipity_Import_VoodooPad::wikify($alias, $permalink, $thispage['content']);
}
for ($counter = 0; $counter <= 12; $counter+=1) {
unset ($thispage[$counter]);
}
// Write back to the database
serendipity_db_update("staticpages", array("id" => $thispage["id"]), $thispage);
}
echo DONE . '
';
}
// Search and replace avoiding content of links
// **TODO** Fix this to avoid short links screwing up longer links
function wikify($alias, $link, $txt) {
$r = preg_split('((>)|(<))', $txt, -1, PREG_SPLIT_DELIM_CAPTURE);
$ns = '';
for ($i = 0; $i < count($r); $i++) {
if ($r[$i] == "<") {
$i+=2;
continue;
}
$r[$i] = eregi_replace(sql_regcase($alias), ''.$alias.'', $r[$i]);
}
return join("", $r);
}
}
// XML Parser callbacks
function start_element_handler($parser, $name, $attribs){
global $elements, $stack, $count, $depth;
$id = $count;
$element = new element;
$elements[$id] = $element;
$elements[$id]->name = $name;
while(list($key, $value) = each($attribs)) {
$elements[$id]->attributes[$key] = $value;
}
$elements[$id]->depth = $depth;
array_push($stack, $id);
$count++;
$depth++;
}
function end_element_handler($parser, $name){
global $stack, $depth;
array_pop($stack);
$depth--;
}
function character_data_handler($parser, $data){
global $elements, $stack;
$elements[$stack[count($stack)-1]]->data .= $data;
}
return 'Serendipity_Import_VoodooPad';
?>