function plugin_ls_convert() { global $vars; $with_title = FALSE; if (func_num_args()) { $args = func_get_args(); $with_title = in_array('title', $args); } $prefix = $vars['page'] . '/'; $page = isset($vars['page']) ? $vars['page'] : ''; $pages = array(); foreach (Auth::get_existpages() as $page) { if (strpos($page, $prefix) === 0) { $pages[] = $page; } } natcasesort($pages); $ls = array(); foreach ($pages as $page) { $comment = ''; if ($with_title) { $array = file_head(get_filename($page), 1); if ($array) { $comment = ' - ' . preg_replace(array('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/S', '/^(?:-+|\\*+)/'), array('$1$2', null), current($array)); } } $ls[] = "-[[{$page}]] {$comment}"; } return RendererFactory::factory($ls); }
function plugin_recent_convert() { global $vars, $date_format, $_recent_plugin_frame, $show_passage; static $exec_count = 1; $recent_lines = PLUGIN_RECENT_DEFAULT_LINES; if (func_num_args()) { $args = func_get_args(); if (!is_numeric($args[0]) || isset($args[1])) { return PLUGIN_RECENT_USAGE . '<br />'; } else { $recent_lines = $args[0]; } } // Show only N times if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) { return '#recent(): You called me too much' . '<br />' . "\n"; } else { ++$exec_count; } if (!file_exists(PLUGIN_RECENT_CACHE)) { return '#recent(): Cache file of RecentChanges not found' . '<br />'; } // Get latest N changes $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines); if ($lines == FALSE) { return '#recent(): File can not open' . '<br />' . "\n"; } $script = get_script_uri(); $date = $items = ''; foreach ($lines as $line) { list($time, $page) = explode("\t", rtrim($line)); $_date = get_date($date_format, $time); if ($date != $_date) { // End of the day if ($date != '') { $items .= '</ul>' . "\n"; } // New day $date = $_date; $items .= '<strong>' . $date . '</strong>' . "\n" . '<ul class="recent_list">' . "\n"; } $s_page = htmlsc($page); if ($page == $vars['page']) { // No need to link to the page you just read, or notify where you just read $items .= ' <li>' . $s_page . '</li>' . "\n"; } else { $r_page = rawurlencode($page); $passage = $show_passage ? ' ' . get_passage($time) : ''; $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n"; } } // End of the day if ($date != '') { $items .= '</ul>' . "\n"; } return sprintf($_recent_plugin_frame, count($lines), $items); }
function write() { if (PluginAccesslog::is_admin(NULL, PLUGIN_ACCESSLOG_USE_SESSION, PLUGIN_ACCESSLOG_THROUGH_IF_ADMIN)) { return; } global $vars, $defaultpage; $page = isset($vars['refer']) ? $vars['refer'] : (isset($vars['page']) ? $vars['page'] : $defaultpage); $cmd = isset($vars['cmd']) ? $vars['cmd'] : (isset($vars['plugin']) ? $vars['plugin'] : ''); // logdata format $logdata = array(); $logdata['time'] = strftime('%y/%m/%d %H:%M:%S'); $logdata['ip'] = $_SERVER['REMOTE_ADDR']; $logdata['host'] = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : gethostbyaddr($_SERVER['REMOTE_ADDR']); $logdata['referer'] = $_SERVER['HTTP_REFERER']; $logdata['agent'] = $_SERVER['HTTP_USER_AGENT']; $logdata['page'] = $page; $logdata['cmd'] = $cmd; $line = serialize($logdata) . "\n"; if (ereg(PLUGIN_ACCESSLOG_EXCEPT_AGENT, $logdata['agent'])) { return TRUE; } if (ereg(PLUGIN_ACCESSLOG_EXCEPT_HOST, $logdata['host'])) { return TRUE; } $date = date('Ymd', time()); // use localtime simply because time handling ways in pukiwiki plus! and official are different. if (file_exists(PLUGIN_ACCESSLOG_FILENAME)) { $logdate = rtrim(array_shift(file_head(PLUGIN_ACCESSLOG_FILENAME, 1))); if ($logdate != $date) { slide_rename(PLUGIN_ACCESSLOG_FILENAME, PLUGIN_ACCESSLOG_KEEPLOG_DAYS, '.%d'); @move(PLUGIN_ACCESSLOG_FILENAME, PLUGIN_ACCESSLOG_FILENAME . '.1'); file_put_contents(PLUGIN_ACCESSLOG_FILENAME, $date . "\n"); } } else { file_put_contents(PLUGIN_ACCESSLOG_FILENAME, $date . "\n"); } return file_put_contents(PLUGIN_ACCESSLOG_FILENAME, $line, FILE_APPEND); }
function plugin_rss_action() { global $vars, $rss_max, $rss_description, $page_title, $whatsnew, $trackback; $version = isset($vars['ver']) ? $vars['ver'] : '2.0'; switch ($version) { case '1': $version = '1.0'; break; // Sugar // Sugar case '2': $version = '2.0'; break; // Sugar // Sugar case '0.91': /* FALLTHROUGH */ /* FALLTHROUGH */ case '1.0': /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': default: break; } $lang = LANG; $page_title_utf8 = mb_convert_encoding($page_title, 'UTF-8', SOURCE_ENCODING); $self = get_script_absuri(); $rss_description_utf8 = mb_convert_encoding(htmlspecialchars($rss_description), 'UTF-8', SOURCE_ENCODING); // Creating <item> $items = $rdf_li = ''; $recent = CACHE_DIR . PKWK_MAXSHOW_CACHE; if (!file_exists($recent)) { die('PKWK_MAXSHOW_CACHE is not found'); } foreach (file_head($recent, $rss_max) as $line) { list($time, $page) = explode("\t", rtrim($line)); $items .= plugin_rss_generate_item($version, $time, $page); } // Feeding start pkwk_common_headers($time); // header('Content-type: application/xml'); header('Content-type: text/html'); print '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $url_whatsnew = get_page_absuri($whatsnew); switch ($version) { case '0.91': print '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"' . ' "http://my.netscape.com/publish/formats/rss-0.91.dtd">' . "\n"; /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': print <<<EOD <rss version="{$version}"> \t<channel> \t\t<title><![CDATA[{$page_title_utf8}]]></title> \t\t<link>{$url_whatsnew}</link> \t\t<description><![CDATA[{$rss_description_utf8}]]></description> \t\t<language>{$lang}</language> {$items} \t</channel> </rss> EOD; break; case '1.0': $xmlns_trackback = $trackback ? 'xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"' : ''; print <<<EOD <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" {$xmlns_trackback} xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xml:lang="{$lang}"> \t<channel rdf:about="{$url_whatsnew}"> \t\t<title><![CDATA[{$page_title_utf8}]]></title> \t\t<link>{$url_whatsnew}</link> \t\t<description><![CDATA[{$rss_description_utf8}]]></description> \t\t<items> \t\t\t<rdf:Seq> {$rdf_li} \t\t\t</rdf:Seq> \t\t</items> \t</channel> {$items} </rdf:RDF> EOD; break; } exit; }
} echo file_foot(); } } else { if ($action == 'file') { if (function_exists('ob_filter_path_nicer')) { ob_start('ob_filter_path_nicer'); } $dir_url = urlencode($dir); $dir_html = htmlspecialchars($dir); echo <<<EOS \t<div> \t\t<a href="?">{$l_root}</a> <a href="?path={$dir_url}">{$dir_html}</a>/<strong>{$filename}</strong><br /> \t</div> EOS; echo file_head(); echo file_row($fileinfo, $path); echo file_foot(); if ($tplfile) { $tplfile_html = htmlspecialchars($tplfile); echo <<<EOS \t\t<div> \t\t\t<a href="#tpl">{$tplfile_html}</a><br /> \t\t</div> EOS; } if (function_exists('ob_filter_path_nicer')) { ob_end_flush(); } echo <<<EOS \t<div class="code">
function lastmodified_add($update = '', $remove = '') { global $maxshow, $whatsnew, $autolink, $autobasealias; // AutoLink implimentation needs everything, for now if ($autolink || $autobasealias) { put_lastmodified(); // Try to (re)create ALL return; } if (($update == '' || check_non_list($update)) && $remove == '') { return; } // No need $file = CACHE_DIR . PKWK_MAXSHOW_CACHE; if (!file_exists($file)) { put_lastmodified(); // Try to (re)create ALL return; } // Read (keep the order of the lines) $recent_pages = $matches = array(); foreach (file_head($file, $maxshow + PKWK_MAXSHOW_ALLOWANCE, FALSE) as $line) { if (preg_match('/^([0-9]+)\\t(.+)/', $line, $matches)) { $recent_pages[$matches[2]] = $matches[1]; } } // Remove if it exists inside if (isset($recent_pages[$update])) { unset($recent_pages[$update]); } if (isset($recent_pages[$remove])) { unset($recent_pages[$remove]); } // Add to the top: like array_unshift() if ($update != '' && $update != $whatsnew && !check_non_list($update)) { $recent_pages = array($update => get_filetime($update)) + $recent_pages; } // Check if (count($recent_pages) < $maxshow) { put_lastmodified(); // Try to (re)create ALL return; } // Sort decending order of last-modification date(Pointed Question/119) arsort($recent_pages, SORT_NUMERIC); // Re-create PKWK_MAXSHOW_CACHE pkwk_touch_file($file); $fp = fopen($file, 'r+') or die_message('Cannot open ' . 'CACHE_DIR/' . PKWK_MAXSHOW_CACHE); set_file_buffer($fp, 0); @flock($fp, LOCK_EX); $last = ignore_user_abort(1); ftruncate($fp, 0); rewind($fp); foreach ($recent_pages as $page => $time) { fputs($fp, $time . "\t" . $page . "\n"); } ignore_user_abort($last); @flock($fp, LOCK_UN); @fclose($fp); // Update 'RecentChanges' $recent_pages = array_splice($recent_pages, 0, $maxshow); $file = get_filename($whatsnew); pkwk_touch_file($file); $fp = fopen($file, 'r+') or die_message('Cannot open ' . htmlspecialchars($whatsnew)); set_file_buffer($fp, 0); @flock($fp, LOCK_EX); $last = ignore_user_abort(1); ftruncate($fp, 0); rewind($fp); foreach ($recent_pages as $page => $time) { fputs($fp, '-' . htmlspecialchars(format_date($time)) . ' - ' . '[[' . htmlspecialchars($page) . ']]' . "\n"); } fputs($fp, '#norelated' . "\n"); // :) ignore_user_abort($last); @flock($fp, LOCK_UN); @fclose($fp); }
function plugin_rss_action() { global $vars, $rss_max, $page_title, $whatsnew, $trackback; $version = isset($vars['ver']) ? $vars['ver'] : ''; switch ($version) { case '': $version = '0.91'; break; // Default // Default case '1': $version = '1.0'; break; // Sugar // Sugar case '2': $version = '2.0'; break; // Sugar // Sugar case '0.91': /* FALLTHROUGH */ /* FALLTHROUGH */ case '1.0': /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': break; default: die('Invalid RSS version!!'); } $recent = CACHE_DIR . 'recent.dat'; if (!file_exists($recent)) { die('recent.dat is not found'); } $lang = LANG; $page_title_utf8 = mb_convert_encoding($page_title, 'UTF-8', SOURCE_ENCODING); $self = get_script_uri(); // Creating <item> $items = $rdf_li = ''; foreach (file_head($recent, $rss_max) as $line) { list($time, $page) = explode("\t", rtrim($line)); $r_page = rawurlencode($page); $title = mb_convert_encoding($page, 'UTF-8', SOURCE_ENCODING); switch ($version) { case '0.91': /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': $date = get_date('D, d M Y H:i:s T', $time); $date = $version == '0.91' ? ' <description>' . $date . '</description>' : ' <pubDate>' . $date . '</pubDate>'; $items .= <<<EOD <item> <title>{$title}</title> <link>{$self}?{$r_page}</link> {$date} </item> EOD; break; case '1.0': // Add <item> into <items> $rdf_li .= ' <rdf:li rdf:resource="' . $self . '?' . $r_page . '" />' . "\n"; $date = substr_replace(get_date('Y-m-d\\TH:i:sO', $time), ':', -2, 0); $trackback_ping = ''; if ($trackback) { $tb_id = md5($r_page); $trackback_ping = ' <trackback:ping>' . $self . '?tb_id=' . $tb_id . '</trackback:ping>'; } $items .= <<<EOD <item rdf:about="{$self}?{$r_page}"> <title>{$title}</title> <link>{$self}?{$r_page}</link> <dc:date>{$date}</dc:date> <dc:identifier>{$self}?{$r_page}</dc:identifier> {$trackback_ping} </item> EOD; break; } } // Feeding start pkwk_common_headers(); header('Content-type: application/xml'); print '<?xml version="1.0" encoding="UTF-8"?>' . "\n\n"; $r_whatsnew = rawurlencode($whatsnew); switch ($version) { case '0.91': print '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"' . ' "http://my.netscape.com/publish/formats/rss-0.91.dtd">' . "\n"; /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': print <<<EOD <rss version="{$version}"> <channel> <title>{$page_title_utf8}</title> <link>{$self}?{$r_whatsnew}</link> <description>PukiWiki RecentChanges</description> <language>{$lang}</language> {$items} </channel> </rss> EOD; break; case '1.0': $xmlns_trackback = $trackback ? ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"' : ''; print <<<EOD <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" {$xmlns_trackback} xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xml:lang="{$lang}"> <channel rdf:about="{$self}?{$r_whatsnew}"> <title>{$page_title_utf8}</title> <link>{$self}?{$r_whatsnew}</link> <description>PukiWiki RecentChanges</description> <items> <rdf:Seq> {$rdf_li} </rdf:Seq> </items> </channel> {$items} </rdf:RDF> EOD; break; } exit; }
function plugin_qblog_list_convert() { global $vars, $qblog_date_format, $show_passage; global $qblog_page_prefix, $qblog_defaultpage, $qblog_page_format, $qblog_close; global $style_name; //閉鎖中は何も表示しない if ($qblog_close && !ss_admin_check()) { return ''; } static $exec_count = 1; $qm = get_qm(); $qt = get_qt(); $qt->setv('jquery_include', TRUE); $list_type = PLUGIN_QBLOG_LIST_TYPE; $recent_posts = PLUGIN_QBLOG_LIST_DEFAULT_POSTS; if (func_num_args()) { $args = func_get_args(); if (count($args) > 2) { return '#qblog_list([line or table], [number])'; } foreach ($args as $arg) { if (is_numeric($arg)) { $recent_posts = (int) $arg; } if ($arg == 'line') { $list_type = $arg; } } } //表示モード //recent, archives, category $mode = isset($vars['mode']) ? $vars['mode'] : 'recent'; //表示ページ:ページネーション //表示ページは必ず 1以上の整数 $page_num = isset($vars['p']) ? (int) $vars['p'] : 1; $page_num = $page_num <= 0 ? 1 : $page_num; // !前処理 if (!is_bootstrap_skin()) { $include_bs = ' <link rel="stylesheet" href="skin/bootstrap/css/bootstrap-custom.min.css" /> <script type="text/javascript" src="skin/bootstrap/js/bootstrap.min.js"></script>'; $qt->appendv_once('include_bootstrap_pub', 'beforescript', $include_bs); } //qblog.css を読み込む $head = ' <link rel="stylesheet" href="plugin/qblog/qblog.css" />'; $qt->appendv_once('qblog_beforescript', 'beforescript', $head); //---- キャッシュのための処理を登録 ----- $qt->enable_cache = FALSE; //------------------------------------ if (!file_exists(PLUGIN_QBLOG_LIST_CACHE)) { return $qm->m['plg_recent']['err_file_notfound'] . '<br />'; } $script = get_script_uri(); $date = $items = ''; //h2.title 前に挿入するHTML $pre_title_html = ''; // !新規記事追加リンクを表示 // デフォルトブログページが編集できるユーザー $editable = FALSE; if (check_editable($qblog_defaultpage, FALSE, FALSE) === TRUE) { $editable = TRUE; $search_replace = array('YYYY' => date('Y'), 'MM' => date('m'), 'DD' => date('d')); $newpage = str_replace(array_keys($search_replace), array_values($search_replace), $qblog_page_format); $number_holder_pos = strpos($newpage, '#'); if ($number_holder_pos !== FALSE) { $filename_prefix = encode(substr($newpage, 0, $number_holder_pos)); $files = glob(DATA_DIR . $filename_prefix . '*'); $pattern = '/^(' . str_replace('#', '(\\d+)', preg_quote($newpage)) . ')$/'; $max = 1; foreach ($files as $file) { $pagename = decode(basename($file, '.txt')); if (preg_match($pattern, $pagename, $mts)) { $max = max($mts[2], $max); } } $newpage = str_replace('#', $max + 1, $newpage); } $addpostlink = $script . '?cmd=qblog&mode=addpost'; $pre_title_html .= '<a href="' . h($addpostlink) . '" class="badge badge-info" style="color:#fff"><i class="icon-white icon-edit" style="vertical-align:text-bottom;"></i> 記事の追加</a> '; } // !モードによって、読み込むキャッシュを替える $pages = array(); $start = ($page_num - 1) * $recent_posts; $addquery = ''; switch ($mode) { case 'archives': $date = $vars['date']; $addquery = '&mode=archives&date=' . rawurlencode($date); if (preg_match('/^(\\d{4})(\\d{2})$/', $date, $mts)) { $year = $mts[1]; $month = $mts[2]; } else { $year = date('Y'); $month = date('m'); } $date = $year . $month; $files = glob(DATA_DIR . encode($qblog_page_prefix . $date) . '*'); foreach ($files as $file) { $pages[] = decode(basename($file, '.txt')); } $count_pages = count($pages); natsort($pages); $pages = array_reverse($pages); $pages = array_slice($pages, $start, $recent_posts); $subtitle = "{$year}年{$month}月"; $pre_title_html .= '<span class="badge">' . h($subtitle) . '</span> '; break; case 'category': $cat = isset($vars['catname']) ? $vars['catname'] : $qblog_default_cat; $addquery = '&mode=category&catname=' . rawurlencode($cat); $pages = explode("\n", trim(file_get_contents(CACHEQBLOG_DIR . encode($cat) . '.qbc.dat'))); $count_pages = count($pages); $pages = array_slice($pages, $start, $recent_posts); $pre_title_html .= '<span class="badge">カテゴリ:' . h($cat) . '</span> '; break; default: //recent mode // Get latest N changes $count_pages = (int) array_pop(file_head(PLUGIN_QBLOG_LIST_CACHE, 1)); $lines = file_slice(PLUGIN_QBLOG_LIST_CACHE, $start + 1, $recent_posts); foreach ($lines as $line) { $pages[] = rtrim($line); } } //! 記事毎のデータをまとめる $posts = array(); foreach ($pages as $i => $page) { //キャッシュファイルを読み込む $data = get_qblog_post_data($page); if ($data === FALSE) { continue; } $r_page = rawurlencode($page); if (is_file(SWFU_IMAGE_DIR . $data['image'])) { $data['image'] = SWFU_IMAGE_DIR . $data['image']; } if (trim($data['image']) === '') { $data['image'] = PLUGIN_DIR . 'qblog/qblog_thumbnail.png'; } if (trim($data['image']) === '') { $data['image'] = PLUGIN_DIR . 'qblog/qblog_thumbnail.png'; } $posts[$i] = array('page' => $page, 'title' => $data['title'], 'abstract' => $data['abstract'], 'image' => $data['image'], 'category' => $data['category'], 'url' => $script . '?' . $r_page . $addquery, 'date' => get_qblog_date($qblog_date_format, $page)); } // !ページネーションリンクを足す $paginates = array(); if ($count_pages > $recent_posts) { if ($page_num > 1) { $paginates[PLUGIN_QBLOG_LIST_PAGINATE_LAST_NAV] = $script . '?' . $qblog_defaultpage . '&p=1' . $addquery; } $paginate_length = ceil($count_pages / $recent_posts); if (PLUGIN_QBLOG_LIST_PAGINATE_NUM < $paginate_length) { } $range = (int) floor(PLUGIN_QBLOG_LIST_PAGINATE_NUM / 2); $start = (int) max(1, $page_num - $range); $end = (int) min($paginate_length + 1, $start + PLUGIN_QBLOG_LIST_PAGINATE_NUM); // 最初<<< 1 | 2 | 3 | 4 | 5 >>>最後 // 最初<<< 5 | 6 | 7 | 8 | 9 >>>最後 for ($i = $start; $i < $end; $i++) { $paginates[$i] = $script . '?' . $qblog_defaultpage . '&p=' . $i . $addquery; if ($page_num == $i) { $paginates[$i] = ''; } } if ($page_num < $paginate_length) { $paginates[PLUGIN_QBLOG_LIST_PAGINATE_FIRST_NAV] = $script . '?' . $qblog_defaultpage . '&p=' . $paginate_length . $addquery; } } $template_name = 'qblog_list_template.html'; if (file_exists(SKIN_DIR . $style_name . '/' . $template_name)) { $template_path = SKIN_DIR . $style_name . '/' . $template_name; } else { $template_path = PLUGIN_DIR . 'qblog/list_template.html'; } //! テンプレートを読み込む ob_start(); include $template_path; $items .= ob_get_clean(); //! h2.title にbadge を挿入 if ($list_type === 'table') { $qt->prependv('this_right_title', $pre_title_html); } return '<div id="qblog">' . $items . '</div>'; }
function lastmodified_add($update = '', $remove = '') { global $maxshow, $whatsnew, $autolink; // AutoLink implimentation needs everything, for now if ($autolink) { put_lastmodified(); // Try to (re)create ALL return; } if (($update == '' || check_non_list($update)) && $remove == '') { return; } // No need $file = CACHE_DIR . PKWK_MAXSHOW_CACHE; if (!file_exists($file)) { put_lastmodified(); // Try to (re)create ALL return; } // Open pkwk_touch_file($file); $fp = fopen($file, 'r+') or die_message('Cannot open ' . 'CACHE_DIR/' . PKWK_MAXSHOW_CACHE); set_file_buffer($fp, 0); flock($fp, LOCK_EX); // Read (keep the order of the lines) $recent_pages = $matches = array(); foreach (file_head($file, $maxshow + PKWK_MAXSHOW_ALLOWANCE, FALSE) as $line) { if (preg_match('/^([0-9]+)\\t(.+)/', $line, $matches)) { $recent_pages[$matches[2]] = $matches[1]; } } // Remove if it exists inside if (isset($recent_pages[$update])) { unset($recent_pages[$update]); } if (isset($recent_pages[$remove])) { unset($recent_pages[$remove]); } // Add to the top: like array_unshift() if ($update != '') { $recent_pages = array($update => get_filetime($update)) + $recent_pages; } // Check $abort = count($recent_pages) < $maxshow; if (!$abort) { // Write ftruncate($fp, 0); rewind($fp); foreach ($recent_pages as $_page => $time) { fputs($fp, $time . "\t" . $_page . "\n"); } } flock($fp, LOCK_UN); fclose($fp); if ($abort) { put_lastmodified(); // Try to (re)create ALL return; } // ---- // Update the page 'RecentChanges' $recent_pages = array_splice($recent_pages, 0, $maxshow); $file = get_filename($whatsnew); // Open pkwk_touch_file($file); $fp = fopen($file, 'r+') or die_message('Cannot open ' . htmlspecialchars($whatsnew)); set_file_buffer($fp, 0); flock($fp, LOCK_EX); // Recreate ftruncate($fp, 0); rewind($fp); foreach ($recent_pages as $_page => $time) { fputs($fp, '-' . htmlspecialchars(format_date($time)) . ' - ' . '[[' . htmlspecialchars($_page) . ']]' . "\n"); } fputs($fp, '#norelated' . "\n"); // :) flock($fp, LOCK_UN); fclose($fp); }
function plugin_rss_action() { global $vars, $rss_max, $page_title, $whatsnew, $trackback; global $qblog_defaultpage, $qblog_title, $qblog_close; $qm = get_qm(); $qt = get_qt(); $version = isset($vars['ver']) ? $vars['ver'] : ''; switch ($version) { case '': $version = '2.0'; break; // Default // Default case '1': $version = '1.0'; break; // Sugar // Sugar case '2': $version = '2.0'; break; // Sugar // Sugar case '0.91': /* FALLTHROUGH */ /* FALLTHROUGH */ case '1.0': /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': break; default: die($qm->m['plg_rss']['err_version']); } $lang = LANG; $qblog_mode = 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; } else { if (isset($vars['qblog_rss'])) { //閉鎖中はRSS出力しない if ($qblog_close) { exit; } $qblog_mode = TRUE; $blog_mode = FALSE; $page_title_utf8 = mb_convert_encoding($qblog_title, 'UTF-8', SOURCE_ENCODING); } else { $blog_mode = false; $page_title_utf8 = mb_convert_encoding($page_title, 'UTF-8', SOURCE_ENCODING); } } $self = get_script_uri(); // Creating <item> 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); } 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); $time = strtotime(get_qblog_date('Y-m-d 00:00:00', $page)); } else { list($time, $page) = explode("\t", rtrim($line)); } //blogモードで、$blog_name/Hogehogeでないなら(つまり、ブログページでないなら、何もしない 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)) { // リストから省く $skip_list = TRUE; break; } if (preg_match($strip_plugin, $l)) { // 説明から省く unset($source[$k]); } } if ($skip_list) { 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); $contents = plugin_rss_utf8_for_xml($contents); switch ($version) { case '0.91': /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': $date = get_date('D, d M Y H:i:s T', $time); $date = $version == '0.91' ? ' <description>' . $date . ' -- ' . $contents . '</description>' : ' <pubDate>' . $date . '</pubDate>' . ' <description>' . $contents . '</description>'; $items .= <<<EOD <item> <title>{$title}</title> <link>{$self}?{$r_page}</link> {$date} </item> EOD; break; case '1.0': // Add <item> into <items> $rdf_li .= ' <rdf:li rdf:resource="' . $self . '?' . $r_page . '" />' . "\n"; $date = substr_replace(get_date('Y-m-d\\TH:i:sO', $time), ':', -2, 0); $trackback_ping = ''; if ($trackback) { $tb_id = md5($r_page); $trackback_ping = ' <trackback:ping>' . $self . '?tb_id=' . $tb_id . '</trackback:ping>'; } $items .= <<<EOD <item rdf:about="{$self}?{$r_page}"> <title>{$title}</title> <link>{$self}?{$r_page}</link> <description><![CDATA[{$contents}]]></description> <dc:date>{$date}</dc:date> <dc:identifier>{$self}?{$r_page}</dc:identifier> {$trackback_ping} </item> EOD; break; } } // Feeding start pkwk_common_headers(); header('Content-type: application/xml; charset=utf-8'); print '<?xml version="1.0" encoding="UTF-8"?>' . "\n\n"; $r_whatsnew = rawurlencode($blog_mode ? $blog_mode : $whatsnew); $pagename = $qblog_mode ? $qblog_defaultpage : $r_whatsnew; $description = $qblog_mode ? 'QBlog Recent Changes' : $qm->m['plg_rss']['description']; $page_title_utf8 = h(plugin_rss_utf8_for_xml($page_title_utf8)); $description = h(plugin_rss_utf8_for_xml($description)); switch ($version) { case '0.91': print '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN"' . ' "http://my.netscape.com/publish/formats/rss-0.91.dtd">' . "\n"; /* FALLTHROUGH */ /* FALLTHROUGH */ case '2.0': print <<<EOD <rss version="{$version}"> <channel> <title>{$page_title_utf8}</title> <link>{$self}?{$pagename}</link> <description>{$description}</description> <language>{$lang}</language> {$items} </channel> </rss> EOD; break; case '1.0': $xmlns_trackback = $trackback ? ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"' : ''; print <<<EOD <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" {$xmlns_trackback} xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xml:lang="{$lang}"> <channel rdf:about="{$self}?{$pagename}"> <title>{$page_title_utf8}</title> <link>{$self}?{$pagename}</link> <description>{$description}</description> <items> <rdf:Seq> {$rdf_li} </rdf:Seq> </items> </channel> {$items} </rdf:RDF> EOD; break; } exit; }
function plugin_recent_convert() { global $vars, $date_format, $show_passage; static $exec_count = 1; $qm = get_qm(); $qt = get_qt(); $recent_lines = PLUGIN_RECENT_DEFAULT_LINES; if (func_num_args()) { $args = func_get_args(); if (!is_numeric($args[0]) || isset($args[1])) { return $qm->m['plg_recent']['err_usage'] . '<br />'; } else { $recent_lines = $args[0]; } } //---- キャッシュのための処理を登録 ----- if ($qt->create_cache) { $args = func_get_args(); return $qt->get_dynamic_plugin_mark(__FUNCTION__, $args); } //------------------------------------ // Show only N times if ($exec_count > PLUGIN_RECENT_EXEC_LIMIT) { return $qm->m['plg_recent']['err_limit'] . '<br />' . "\n"; } else { ++$exec_count; } if (!file_exists(PLUGIN_RECENT_CACHE)) { return $qm->m['plg_recent']['err_file_notfound'] . '<br />'; } // Get latest N changes $lines = file_head(PLUGIN_RECENT_CACHE, $recent_lines); if ($lines == FALSE) { return $qm->m['plg_recent']['err_file_cannotopen'] . '<br />' . "\n"; } $script = get_script_uri(); $date = $items = ''; foreach ($lines as $line) { list($time, $page) = explode("\t", rtrim($line)); $_date = get_date($date_format, $time); if ($date != $_date) { // End of the day if ($date != '') { $items .= '</ul>' . "\n"; } // New day $date = $_date; $items .= '<strong>' . $date . '</strong>' . "\n" . '<ul class="recent_list">' . "\n"; } $s_page = htmlspecialchars($page); //customized by hokuken.com $s_page = get_page_title($page); if ($page == $vars['page']) { // No need to link to the page you just read, or notify where you just read $items .= ' <li>' . $s_page . '</li>' . "\n"; } else { $r_page = rawurlencode($page); $passage = $show_passage ? ' ' . get_passage($time) : ''; $items .= ' <li><a href="' . $script . '?' . $r_page . '"' . ' title="' . $s_page . $passage . '">' . $s_page . '</a></li>' . "\n"; } } // End of the day if ($date != '') { $items .= '</ul>' . "\n"; } $html = sprintf($qm->m['plg_recent']['frame'], count($lines), $items); return '<div class="qhm-plugin-recent">' . $html . '</div>'; }
function spamlog_write($vars, $comment = array(), $filename = '') { if ($filename === '') { $filename = PLUGIN_AKISMET_SPAMLOG_FILENAME; } $page = isset($vars['refer']) ? $vars['refer'] : (isset($vars['page']) ? $vars['page'] : $defaultpage); $cmd = isset($vars['cmd']) ? $vars['cmd'] : ''; // logdata format $logdata = array(); $logdata['time'] = strftime('%y/%m/%d %H:%M:%S'); $logdata['ip'] = $_SERVER['REMOTE_ADDR']; $logdata['host'] = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : gethostbyaddr($_SERVER['REMOTE_ADDR']); $logdata['agent'] = $_SERVER['HTTP_USER_AGENT']; $logdata['page'] = $page; $logdata['cmd'] = $cmd; $logdata['body'] = isset($comment['body']) ? str_replace("\n", '<br />', $comment['body']) : ''; $line = serialize($logdata) . "\n"; $date = (int) (time() / 3600 / 24); // use localtime simply because time handling ways in pukiwiki plus! and official are different. if (file_exists($filename)) { $logdate = rtrim(array_shift(file_head($filename, 1))); if ($date - PLUGIN_AKISMET_ONELOG_DAYS >= $logdate) { slide_rename($filename, PLUGIN_AKISMET_KEEPLOG, '.%d'); @move($filename, $filename . '.1'); file_put_contents($filename, $date . "\n"); } } else { file_put_contents($filename, $date . "\n"); } return file_put_contents($filename, $line, FILE_APPEND); }