diff --git a/plugin/rss.inc.php b/plugin/rss.inc.php index 79bf50b..6820a7f 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,14 @@ function plugin_rss_action() $lang = LANG; $qblog_mode = FALSE; + $qblog_export = FALSE; + $page_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 +54,16 @@ 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 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 { @@ -64,28 +76,42 @@ 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 { - $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) { $skip_list = FALSE; - + if ($qblog_mode) { $page = trim($line); @@ -100,11 +126,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 +138,7 @@ function plugin_rss_action() $skip_list = TRUE; break; } - + if (preg_match($strip_plugin, $l)) { // 説明から省く unset($source[$k]); @@ -122,30 +148,69 @@ 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 || $page_export) { + $contents = convert_html($source); + $contents = preg_replace( + '/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.'' : ''; + + $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); - $date = ($version == '0.91') ? - ' ' . $date .' -- '. $contents. '' : - ' ' . $date . '' . - ' ' . $contents . ''; + if ($version == '0.91') { + $date = ''; + $desc = ' ' . $date .' -- '. $contents. ''; + } else { + $date = ' ' . $date . ''; + if ($qblog_export || $page_export) { + $desc = ''; + } else { + $desc = ' ' . $contents . ''; + } + } $items .= << $title - $self?$r_page + $permalink $date +$desc +$wp_post_type +$wp_post_date +$wp_category +$wp_comments +$wp_qhm_permalink EOD; @@ -190,6 +255,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 || $qblog_export ? ' + 1.2 +' : ''; + switch ($version) { case '0.91': print ' + {$page_title_utf8} {$self}?{$pagename} {$description} {$lang} + {$wxr_definitions} {$items} @@ -253,4 +326,101 @@ 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; +} + +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; +} + +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 = h($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); + $comment_body = '' . h($comment['title']) . "
\n
\n" .$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('Y-m-d H:i:s', $time); + $gmdate = gmdate('Y-m-d H:i:s', $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; +}