From 7e0d35064699d955e25ffdd2497a94605b750e82 Mon Sep 17 00:00:00 2001 From: Shun Hotta Date: Sun, 15 Nov 2015 06:49:31 +0900 Subject: [PATCH 1/7] Add export mode to rss plugin --- plugin/rss.inc.php | 90 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/plugin/rss.inc.php b/plugin/rss.inc.php index 79bf50b..0ae2a89 100644 --- a/plugin/rss.inc.php +++ b/plugin/rss.inc.php @@ -15,8 +15,8 @@ function plugin_rss_action() { - global $vars, $rss_max, $page_title, $whatsnew, $trackback; - global $qblog_defaultpage, $qblog_title, $qblog_close; + global $vars, $rss_max, $page_title, $whatsnew, $trackback, $username; + global $qblog_defaultpage, $qblog_title, $qblog_close, $script; $qm = get_qm(); $qt = get_qt(); @@ -33,12 +33,13 @@ function plugin_rss_action() $lang = LANG; $qblog_mode = FALSE; + $qblog_export = FALSE; //blogモード if( isset($vars['blog_rss']) && $vars['blog_rss']!='' ){ $blog_mode = $vars['blog_rss']; //ブログページ名 $qt->setv('blog_rss_mode', true); - + $page_title_utf8 = $page_title.' - '.$blog_mode; } // qblogモード @@ -52,6 +53,11 @@ function plugin_rss_action() $qblog_mode = TRUE; $blog_mode = FALSE; $page_title_utf8 = mb_convert_encoding($qblog_title, 'UTF-8', SOURCE_ENCODING); + + //全ページ表示 + if (isset($vars['qblog_export']) && $vars['qblog_export'] === $username) { + $qblog_export = TRUE; + } } else { @@ -64,16 +70,20 @@ function plugin_rss_action() // Creating global $ignore_plugin, $strip_plugin, $strip_plugin_inline; $items = $rdf_li = ''; - if ($qblog_mode) { $qblog_recent = CACHEQBLOG_DIR . 'qblog_recent.dat'; if (! file_exists($qblog_recent)) die($qm->m['plg_rss']['err_nodata']); - // ページネーション用のヘッダー行を飛ばす - $lines = file_head($qblog_recent, $rss_max+1); - array_shift($lines); + if ($qblog_export) { + $lines = plugin_rss_qblog_posts(); + } + else { + // ページネーション用のヘッダー行を飛ばす + $lines = file_head($qblog_recent, $rss_max+1); + array_shift($lines); + } } else { @@ -85,7 +95,7 @@ function plugin_rss_action() foreach ($lines as $line) { $skip_list = FALSE; - + if ($qblog_mode) { $page = trim($line); @@ -100,11 +110,11 @@ function plugin_rss_action() if( $blog_mode && !preg_match('/^'.$blog_mode.'\/.*/', $page) ){ continue; } - + $r_page = rawurlencode($page); $title = get_page_title($page); $source = get_source($page); - + foreach($source as $k => $l) { if (preg_match($ignore_plugin, $l)) @@ -112,7 +122,7 @@ function plugin_rss_action() $skip_list = TRUE; break; } - + if (preg_match($strip_plugin, $l)) { // 説明から省く unset($source[$k]); @@ -122,30 +132,50 @@ function plugin_rss_action() { continue; } - + //html(noskinを避ける) if( count($source) > 0){ $source = str_replace('#html(noskin)', '#html()', $source); $source = preg_replace($strip_plugin_inline, '', $source); // 行内のプラグインを説明から省く } - $contents = mb_strimwidth( strip_htmltag( convert_html( $source ) ), 0, RSS_DESP_LENGTH , '...' ); - $contents = preg_replace_callback('/(&[^;]+;)/', 'plugin_rss_html_entity_decode', $contents); + + // 全文出力 + if ($qblog_export) { + $contents = convert_html($source); + $contents = preg_replace( + '/' . $date .' -- '. $contents. '' : - ' ' . $date . '' . - ' ' . $contents . ''; + if ($version == '0.91') { + $date = ''; + $desc = ' ' . $date .' -- '. $contents. ''; + } else { + $date = ' ' . $date . ''; + if ($qblog_export) { + $desc = ''; + } else { + $desc = ' ' . $contents . ''; + } + } $items .= << $title $self?$r_page $date +$desc EOD; @@ -198,7 +228,7 @@ function plugin_rss_action() case '2.0': print << + {$page_title_utf8} {$self}?{$pagename} @@ -253,4 +283,20 @@ function plugin_rss_utf8_for_xml($string) return preg_replace ('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string); } -?> \ No newline at end of file +function plugin_rss_qblog_posts() +{ + global $qblog_page_prefix, $qblog_page_re; + + $files = glob(DATA_DIR . encode($qblog_page_prefix) . '*'); + + $pages = array(); + foreach ($files as $file) + { + $pagename = decode(basename($file, '.txt')); + if (preg_match($qblog_page_re, $pagename, $mts)) + { + $pages[] = $pagename; + } + } + return $pages; +} From 523cd9fa5c58c9429c1e2369b8f5816f0f2ff559 Mon Sep 17 00:00:00 2001 From: Shun Hotta Date: Tue, 12 Jul 2016 15:10:22 +0900 Subject: [PATCH 2/7] Add page export mode for WP to rss plugin --- plugin/rss.inc.php | 55 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/plugin/rss.inc.php b/plugin/rss.inc.php index 0ae2a89..09de8f0 100644 --- a/plugin/rss.inc.php +++ b/plugin/rss.inc.php @@ -34,6 +34,7 @@ function plugin_rss_action() $lang = LANG; $qblog_mode = FALSE; $qblog_export = FALSE; + $page_export = FALSE; // 全ページエクスポート //blogモード if( isset($vars['blog_rss']) && $vars['blog_rss']!='' ){ @@ -59,6 +60,11 @@ function plugin_rss_action() $qblog_export = TRUE; } } + else if (isset($vars['page_export']) && $vars['page_export'] === $username) { + $blog_mode = FALSE; + $page_export = TRUE; + $page_title_utf8 = mb_convert_encoding($page_title, 'UTF-8', SOURCE_ENCODING); + } else { $blog_mode = false; @@ -87,9 +93,19 @@ function plugin_rss_action() } else { - $recent = CACHE_DIR . 'recent.dat'; - if (! file_exists($recent)) die($qm->m['plg_rss']['err_nodata']); - $lines = file_head($recent, $rss_max); + if ($page_export) { + $pages = plugin_rss_get_all_page(); + $lines = array(); + foreach ($pages as $_page) { + if ( ! preg_match('/\A(:config(\z|\/)|InterWiki|MenuAdmin|QBlog|QHMAdmin|RecentChanges|RecentDeleted)/', $_page)) { + $lines[] = "\t$_page"; + } + } + } else { + $recent = CACHE_DIR . 'recent.dat'; + if (! file_exists($recent)) die($qm->m['plg_rss']['err_nodata']); + $lines = file_head($recent, $rss_max); + } } foreach ($lines as $line) @@ -140,7 +156,7 @@ function plugin_rss_action() } // 全文出力 - if ($qblog_export) { + if ($qblog_export || $page_export) { $contents = convert_html($source); $contents = preg_replace( '/page' : ''; $date = get_date('D, d M Y H:i:s T', $time); if ($version == '0.91') { $date = ''; $desc = ' ' . $date .' -- '. $contents. ''; } else { $date = ' ' . $date . ''; - if ($qblog_export) { + if ($qblog_export || $page_export) { $desc = ''; } else { $desc = ' ' . $contents . ''; @@ -176,6 +193,7 @@ function plugin_rss_action() $self?$r_page $date $desc +$wp_post_type EOD; @@ -220,6 +238,10 @@ function plugin_rss_action() $page_title_utf8 = h(plugin_rss_utf8_for_xml($page_title_utf8)); $description = h(plugin_rss_utf8_for_xml($description)); + $wxr_definitions = $page_export ? ' + 1.2 +' : ''; + switch ($version) { case '0.91': print ' + {$page_title_utf8} {$self}?{$pagename} {$description} {$lang} + {$wxr_definitions} {$items} @@ -300,3 +326,20 @@ function plugin_rss_qblog_posts() } return $pages; } + +function plugin_rss_get_all_page($dir = DATA_DIR, $ext = '.txt') +{ + $pages = get_existpages($dir, $ext); + $qm = get_qm(); + + $symbol = ' '; + $list = array(); + + //並び替える + foreach ($pages as $file => $page) + { + $list[] = $page; + } + + return $list; +} From fab89189b75aa5aa038e759f68bbdc196de0901e Mon Sep 17 00:00:00 2001 From: Shun Hotta Date: Thu, 14 Jul 2016 10:46:08 +0900 Subject: [PATCH 3/7] Add wp:postmeta for set qhm_permalink custom field --- plugin/rss.inc.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugin/rss.inc.php b/plugin/rss.inc.php index 09de8f0..bc4476d 100644 --- a/plugin/rss.inc.php +++ b/plugin/rss.inc.php @@ -175,6 +175,10 @@ function plugin_rss_action() case '0.91': /* FALLTHROUGH */ case '2.0': $wp_post_type = $page_export ? 'page' : ''; + $wp_post_type = $qblog_export ? 'post' : $wp_post_type; + + $permalink = "{$self}?{$r_page}"; + $wp_qhm_permalink = $qblog_export || $page_export ? 'qhm_permalink'.$permalink.'' : ''; $date = get_date('D, d M Y H:i:s T', $time); if ($version == '0.91') { $date = ''; @@ -190,10 +194,11 @@ function plugin_rss_action() $items .= << $title - $self?$r_page + $permalink $date $desc $wp_post_type +$wp_qhm_permalink EOD; @@ -238,7 +243,7 @@ function plugin_rss_action() $page_title_utf8 = h(plugin_rss_utf8_for_xml($page_title_utf8)); $description = h(plugin_rss_utf8_for_xml($description)); - $wxr_definitions = $page_export ? ' + $wxr_definitions = $page_export || $qblog_export ? ' 1.2 ' : ''; From 026e986075900b0c60f3174a7538fbd0fe205957 Mon Sep 17 00:00:00 2001 From: Shun Hotta Date: Thu, 14 Jul 2016 13:29:52 +0900 Subject: [PATCH 4/7] Add wp:post_date and wp:post_date_gmt in WXR --- plugin/rss.inc.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/rss.inc.php b/plugin/rss.inc.php index bc4476d..64b0a97 100644 --- a/plugin/rss.inc.php +++ b/plugin/rss.inc.php @@ -177,6 +177,10 @@ function plugin_rss_action() $wp_post_type = $page_export ? 'page' : ''; $wp_post_type = $qblog_export ? 'post' : $wp_post_type; + $post_date = date('Y-m-d H:i:s', $time); + $post_date_gmt = gmdate('Y-m-d H:i:s', $time); + $wp_post_date = $page_export || $qblog_export ? ''.$post_date.''.$post_date_gmt.'' : ''; + $permalink = "{$self}?{$r_page}"; $wp_qhm_permalink = $qblog_export || $page_export ? 'qhm_permalink'.$permalink.'' : ''; $date = get_date('D, d M Y H:i:s T', $time); @@ -198,6 +202,7 @@ function plugin_rss_action() $date $desc $wp_post_type +$wp_post_date $wp_qhm_permalink From 875b3c758c8b6f147afedf348485bdeaa4318a5f Mon Sep 17 00:00:00 2001 From: Shun Hotta Date: Thu, 15 Sep 2016 13:48:40 +0900 Subject: [PATCH 5/7] [rss]Add wp category and comments to qblog export mode --- plugin/rss.inc.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/plugin/rss.inc.php b/plugin/rss.inc.php index 64b0a97..551d9cc 100644 --- a/plugin/rss.inc.php +++ b/plugin/rss.inc.php @@ -177,6 +177,11 @@ function plugin_rss_action() $wp_post_type = $page_export ? 'page' : ''; $wp_post_type = $qblog_export ? 'post' : $wp_post_type; + $cat = get_qblog_category($page); + $cat_nicename = strtolower(rawurlencode($cat)); + $wp_category = $qblog_export ? '': ''; + $wp_comments = $qblog_export ? plugin_rss_get_wp_comments($page) : ''; + $post_date = date('Y-m-d H:i:s', $time); $post_date_gmt = gmdate('Y-m-d H:i:s', $time); $wp_post_date = $page_export || $qblog_export ? ''.$post_date.''.$post_date_gmt.'' : ''; @@ -203,6 +208,8 @@ function plugin_rss_action() $desc $wp_post_type $wp_post_date +$wp_category +$wp_comments $wp_qhm_permalink @@ -353,3 +360,66 @@ function plugin_rss_get_all_page($dir = DATA_DIR, $ext = '.txt') return $list; } + +function plugin_rss_get_wp_comments($page) +{ + $comments = array(); + if (file_exists(CACHEQBLOG_DIR . encode($page) . '.qbcm.dat')) { + $comments = unserialize(file_get_contents(CACHEQBLOG_DIR . encode($page) . '.qbcm.dat')); + } + else { + return ''; + } + + $xml = ''; + foreach ($comments as $i => $comment) + { + if ( ! $comment['show']) { + unset($comments[$i]); + continue; + } + + $comment_body = $comment['msg']; + $comment_body = nl2br($comment_body); + $ptns = array( + '/(?:https?|ftp)(?::\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/', + ); + $rpls = array( + '$0' + ); + $comment_body = preg_replace($ptns, $rpls, $comment_body); + + // datetime: 2016.09.15 13:22:43 + //var_dump($comment); + $time = mktime( + (int)substr($comment['datetime'], 11, 2), + (int)substr($comment['datetime'], 14, 2), + (int)substr($comment['datetime'], 17, 2), + (int)substr($comment['datetime'], 5, 2), + (int)substr($comment['datetime'], 8, 2), + (int)substr($comment['datetime'], 0, 4) + ); + $date = date('D, d M Y H:i:s T', $time); + $gmdate = gmdate('D, d M Y H:i:s T', $time); + + $xml .= "\n"; + + $xml .= "\n"; + $xml .= "\n"; + $xml .= "\n"; + $xml .= "" . $date . "\n"; + $xml .= "" . $gmdate . "\n"; + $xml .= "\n"; + if ($comment['accepted']) + $xml .= "1\n"; + else + $xml .= "0\n"; + $xml .= "\n"; + $xml .= "0\n"; + $xml .= "0\n"; + + $xml .= "\n"; + } + + return $xml; +} From 5ad98a4ee472c3a2f3548cd903b6a473d86e7503 Mon Sep 17 00:00:00 2001 From: Shun Hotta Date: Thu, 15 Sep 2016 13:52:16 +0900 Subject: [PATCH 6/7] Add comment title to wp:comment body --- plugin/rss.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/rss.inc.php b/plugin/rss.inc.php index 551d9cc..2bacad8 100644 --- a/plugin/rss.inc.php +++ b/plugin/rss.inc.php @@ -379,7 +379,7 @@ function plugin_rss_get_wp_comments($page) continue; } - $comment_body = $comment['msg']; + $comment_body = h($comment['msg']); $comment_body = nl2br($comment_body); $ptns = array( '/(?:https?|ftp)(?::\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/', @@ -388,6 +388,7 @@ function plugin_rss_get_wp_comments($page) '$0' ); $comment_body = preg_replace($ptns, $rpls, $comment_body); + $comment_body = '' . h($comment['title']) . "
\n
\n" .$comment_body; // datetime: 2016.09.15 13:22:43 //var_dump($comment); From e11314782d1ab291f577eca5d078325fef407909 Mon Sep 17 00:00:00 2001 From: Shun Hotta Date: Thu, 15 Sep 2016 14:04:27 +0900 Subject: [PATCH 7/7] Fix wp:comment date format --- plugin/rss.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/rss.inc.php b/plugin/rss.inc.php index 2bacad8..6820a7f 100644 --- a/plugin/rss.inc.php +++ b/plugin/rss.inc.php @@ -400,8 +400,8 @@ function plugin_rss_get_wp_comments($page) (int)substr($comment['datetime'], 8, 2), (int)substr($comment['datetime'], 0, 4) ); - $date = date('D, d M Y H:i:s T', $time); - $gmdate = gmdate('D, d M Y H:i:s T', $time); + $date = date('Y-m-d H:i:s', $time); + $gmdate = gmdate('Y-m-d H:i:s', $time); $xml .= "\n";