Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PukiWiki 2 Evernote
<?php
// PukiWiki 2 Evernote
//
// @version 1.00
//
// this script is freely distributable under the terms of new BSD license.
// Copyright (c) 2009, makoto_kw All rights reserved.
//
// How to Use
// 1. copy this file to your pukiwiki directory
// 2. set includes and excludes in settings
// 3. execute this script:
// php ./pukiwiki2evernote.php > pukiwiki.enex
//
// History
// 2009-07-17 (1.00) : Initial Release
// ------------------------------------------------------------
// Settings
$p2e_exclude_pages = array();
$p2e_topicpath2tag = false;
$p2e_exclude_tags = array();
$p2e_date_format = 'Ymd\THis';
define('PKWK_PLUGIN_CALL_TIME_LIMIT', 7680);
// ------------------------------------------------------------
error_reporting(E_ERROR | E_PARSE); // Avoid E_WARNING, E_NOTICE, etc
//error_reporting(E_ALL); // Debug purpose
@ini_set("display_errors","No");
@ini_set('memory_limit', '128M');
define('DATA_HOME', '');
define('LIB_DIR', 'lib/');
$script = 'http://pukiwiki2evernote/'; // dummy
require(LIB_DIR . 'func.php');
require(LIB_DIR . 'file.php');
require(LIB_DIR . 'plugin.php');
require(LIB_DIR . 'html.php');
require(LIB_DIR . 'backup.php');
require(LIB_DIR . 'convert_html.php');
require(LIB_DIR . 'make_link.php');
require(LIB_DIR . 'diff.php');
require(LIB_DIR . 'config.php');
require(LIB_DIR . 'link.php');
require(LIB_DIR . 'auth.php');
require(LIB_DIR . 'proxy.php');
if (! extension_loaded('mbstring')) {
require(LIB_DIR . 'mbstring.php');
}
// Defaults
$notify = $trackback = $referer = 0;
require(LIB_DIR . 'init.php');
//
$p2e_default_wikipages = array(
':RenameLog',
':config',
':config/PageReading',
':config/PageReading/dict',
':config/plugin',
':config/plugin/attach/mime-type',
':config/plugin/referer/config',
':config/plugin/tracker',
':config/plugin/tracker/default',
':config/plugin/tracker/default/form',
':config/plugin/tracker/default/list',
':config/plugin/tracker/default/page',
'BracketName',
'FormattingRules',
'FrontPage',
'Help',
'InterWiki',
'InterWikiName',
'InterWikiSandBox',
'InterWikiテクニカル',
'MenuBar',
'PHP',
'PukiWiki',
'PukiWiki/1.4',
'PukiWiki/1.4/Manual',
'PukiWiki/1.4/Manual/Plugin',
'PukiWiki/1.4/Manual/Plugin/A-D',
'PukiWiki/1.4/Manual/Plugin/E-G',
'PukiWiki/1.4/Manual/Plugin/H-K',
'PukiWiki/1.4/Manual/Plugin/L-N',
'PukiWiki/1.4/Manual/Plugin/O-R',
'PukiWiki/1.4/Manual/Plugin/S-U',
'PukiWiki/1.4/Manual/Plugin/V-Z',
'PukiWiki/1.4/マニュアル/プラグイン',
'PukiWiki/1.4/マニュアル/プラグイン/a',
'PukiWiki/1.4/マニュアル/プラグイン/b',
'PukiWiki/1.4/マニュアル/プラグイン/c',
'PukiWiki/1.4/マニュアル/プラグイン/d',
'PukiWiki/1.4/マニュアル/プラグイン/e',
'PukiWiki/1.4/マニュアル/プラグイン/f',
'PukiWiki/1.4/マニュアル/プラグイン/h',
'PukiWiki/1.4/マニュアル/プラグイン/i',
'PukiWiki/1.4/マニュアル/プラグイン/l',
'PukiWiki/1.4/マニュアル/プラグイン/m',
'PukiWiki/1.4/マニュアル/プラグイン/n',
'PukiWiki/1.4/マニュアル/プラグイン/o',
'PukiWiki/1.4/マニュアル/プラグイン/p',
'PukiWiki/1.4/マニュアル/プラグイン/r',
'PukiWiki/1.4/マニュアル/プラグイン/s',
'PukiWiki/1.4/マニュアル/プラグイン/t',
'PukiWiki/1.4/マニュアル/プラグイン/u',
'PukiWiki/1.4/マニュアル/プラグイン/v',
'PukiWiki/1.4/マニュアル/プラグイン/y',
'RecentChanges',
'RecentDeleted',
'SandBox',
'WikiEngines',
'WikiName',
'WikiWikiWeb',
'YukiWiki',
'ヘルプ',
'整形ルール',
'日本語',
);
echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
echo '<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export.dtd">'."\r\n";
echo '<en-export export-date="'.gmdate($p2e_date_format).'" application="Evernote/Windows" version="3.0">'."\r\n";
$pages = get_existpages();
$p2e_exclude_pages = array_merge($p2e_default_wikipages,$p2e_exclude_pages);
foreach ($pages as $file => $page) {
if (!in_array($page,$p2e_exclude_pages)) {
$tags = array();
if ($p2e_topicpath2tag) {
$topics = explode('/',$page);
if (!empty($topics)) foreach ($topics as $topic) if (!in_array($topic,$p2e_exclude_tags)) $tags[] = $topic;
}
$path = DATA_DIR.'/'.$file;
$title = mb_convert_encoding($page, "UTF-8", CONTENT_CHARSET);
$content = mb_convert_encoding(p2e_convert_html(p2e_get_source($file)), "UTF-8", CONTENT_CHARSET);
echo '<note>';
echo '<title>'.$title.'</title>';
echo '<content><![CDATA[<?xml version="1.0" encoding="UTF-8"?><en-note>'.$content.'</en-note>]]></content>';
echo '<created>'.gmdate($p2e_date_format, filectime($path)).'</created>';
echo '<updated>'.gmdate($p2e_date_format, filemtime($path)).'</updated>';
foreach ($tags as $tag) echo '<tag>'.$tag.'</tag>';
echo '</note>';
unset($content);
}
}
echo '</en-export>';
function p2e_convert_html($content) {
global $script;
$html = convert_html($content);
$html = str_replace('<div class="jumpmenu"><a href="#navigator">&uarr;</a></div>','',$html);
$html = preg_replace('/<a\s[^>]*>&dagger;<\/a>/','',$html);
$html = preg_replace('/<a\s[^>]*href="'.str_replace('/','\/',$script).'[^>]*>(.*)<\/a>/','$1',$html);
return $html;
}
function p2e_get_source($file, $lock = TRUE) {
$result = array();
$path = DATA_DIR.'/'.$file;
if ($lock) {
$fp = @fopen($path, 'r');
if ($fp == FALSE) return $result;
flock($fp, LOCK_SH);
}
$result = str_replace("\r", '', file($path));
if ($lock) {
flock($fp, LOCK_UN);
@fclose($fp);
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment