function do_rss_blog($formatter, $options) { global $DBInfo; # if (!$options['date'] or !preg_match('/^\d+$/',$date)) $date=date('Ym'); # else $date=$options['date']; $date = $options['date']; $category_pages = array(); if ($options['category'] and $DBInfo->blog_category) { $categories = Blog_cache::get_categories(); if ($categories[$options['category']]) { $category_pages = $categories[$options['category']]; } $title = $options['category']; } else { $title = _("Blog Changes"); } if ($options['all'] or $options['category']) { # check error and set default value $blog_rss = new Cache_text('blogrss'); # $blog_mtime=filemtime($DBInfo->cache_dir."/blog"); # if ($blog_rss->exists($date'.xml') and ($blog_rss->mtime($date.'.xml') > $blog_mtime)) { # print $blog_rss->fetch($date.'.xml'); # return; # } $blogs = Blog_cache::get_rc_blogs($date, $category_pages); $logs = Blog_cache::get_summary($blogs, $date); $rss_name = $DBInfo->sitename . ': ' . $title; } else { $blogs = array($DBInfo->pageToKeyname($formatter->page->name)); $logs = Blog_cache::get_summary($blogs, $date); $rss_name = $formatter->page->name; } usort($logs, 'BlogCompare'); /* generate <rss> ... </rss> */ $rss = generate_rss($formatter, $rss_name, $logs); /* output encoding */ if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) { $charset = $options['oe']; if (function_exists('iconv')) { $out = iconv($DBInfo->charset, $charset, $rss); if (!$out) { $out =& $rss; $charset = $DBInfo->charset; } } } else { $charset = $DBInfo->charset; } /* emit output rss as text/xml */ header("Content-Type: text/xml"); print <<<XML <?xml version="1.0" encoding="{$charset}"?> <!-- Add "oe=utf-8" to convert the charset of this rss to UTF-8. --> {$rss} XML; }
function macro_BlogChanges($formatter, $value, $options = array()) { global $DBInfo; $tz_off =& $formatter->tz_offset; if (empty($options)) { $options = array(); } if (!empty($_GET['date'])) { $options['date'] = $date = $_GET['date']; } else { $date = !empty($options['date']) ? $options['date'] : ''; } // parse args preg_match("/^(('|\")([^\\2]+)\\2)?,?(\\s*,?\\s*.*)?\$/", $value, $match); $opts = explode(',', $match[4]); $opts = array_merge($opts, array_keys($options)); #print_r($match);print_r($opts); if (in_array('noaction', $opts)) { $options['noaction'] = 1; } $category_pages = array(); $options['category'] = !empty($options['category']) ? $options['category'] : $match[3]; if (!empty($options['category'])) { $options['category'] = preg_replace('/(?<!\\.|\\)|\\])\\*/', '.*', $options['category']); $test = @preg_match("/" . str_replace('/', '\\/', $options['category']) . "/", ''); if ($test === false) { return '[[BlogChanges(' . sprintf(_("Invalid category expr \"%s\""), $options['category']) . ')]]'; } if ($DBInfo->blog_category) { $categories = Blog_cache::get_categories(); if (isset($categories[$options['category']])) { $category_pages = $categories[$options['category']]; } } if (!$category_pages) { if ($DBInfo->hasPage($options['category'])) { // category is not found // regard it as a single blog page $blog_page = $options['category']; } else { // or category pattern like as 'Blog/Misc/.*' $category_pages = array($options['category']); } } } else { $opts['all'] = 1; } foreach ($opts as $opt) { if (($temp = intval($opt)) > 1) { break; } } $limit = $temp > 1 ? $temp : 0; if (!$limit) { if ($date) { $limit = 30; } else { $limit = 10; } } #print_r($category_pages); if (in_array('all', $opts) or $category_pages) { $blogs = Blog_cache::get_rc_blogs($date, $category_pages); } else { if ($blog_page) { //$blogs=array($DBInfo->pageToKeyname($blog_page)); $blogs = array($blog_page); } } # if (empty($blogs)) { # // no blog entries found # return _("No entries found"); # } # print_r($blogs); if (in_array('summary', $opts)) { $logs = Blog_cache::get_summary($blogs, $options); } else { $logs = Blog_cache::get_simple($blogs, $options); } usort($logs, 'BlogCompare'); // get the number of trackbacks $trackback_list = array(); if ($DBInfo->use_trackback) { #read trackbacks and set entry counter $cache = new Cache_text('trackback'); foreach ($blogs as $blog) { if ($cache->exists($blog)) { $trackback_raw = $cache->fetch($blog); $trackbacks = explode("\n", $trackback_raw); foreach ($trackbacks as $trackback) { if (($p = strpos($trackback, "\t")) !== false) { list($dummy, $entry, $extra) = explode("\t", $trackback); if ($entry) { if (isset($trackback_list[$blog][$entry])) { $trackback_list[$blog][$entry]++; } else { $trackback_list[$blog] = array($entry => 1); } } } } } } } if (empty($options['date']) or !preg_match('/^\\d{4}-?\\d{2}$/', $options['date'])) { $date = date('Ym'); } $year = substr($date, 0, 4); $month = substr($date, 4, 2); $day = substr($date, 6, 2); if (strlen($date) == 8) { $prev_date = gmdate('Ymd', mktime(0, 0, 0, $month, intval($day) - 1, $year) + $tz_off); $next_date = gmdate('Ymd', mktime(0, 0, 0, $month, intval($day) + 1, $year) + $tz_off); } else { if (strlen($date) == 6) { $cdate = date('Ym'); $prev_date = date('Ym', mktime(0, 0, 0, intval($month) - 1, 1, $year) + $tz_off); if ($cdate > $date) { $next_date = gmdate('Ym', mktime(0, 0, 0, intval($month) + 1, 1, $year) + $tz_off); } } } // set output style if (in_array('simple', $opts) or in_array('summary', $opts)) { $bra = ""; $sep = "<br />"; $bullet = ""; $cat = ""; } else { $bra = "<ul class='blog-list'>"; $bullet = "<li class='blog-list'>"; $sep = "</li>\n"; $cat = "</ul>"; } $template = '$out="$bullet<a href=\\"$url#$tag\\">$title</a> ' . '<span class=\\"blog-user\\">'; if (in_array('summary', $opts)) { $template = '$out="$bullet<div class=\\"blog-summary\\"><div class=\\"blog-title\\"><a name=\\"$tag\\"></a>' . '<a href=\\"$url#$tag\\">$title</a> <a class=\\"perma\\" href=\\"#$tag\\">' . addslashes($formatter->perma_icon) . '</a></div><span class=\\"blog-user\\">'; } if (!in_array('nouser', $opts)) { $template .= 'by $user '; } if (!in_array('nodate', $opts)) { $template .= '@ $date '; } if (in_array('summary', $opts)) { $template .= '</span><div class=\\"blog-content\\">$summary</div>$btn</div>\\n";'; } else { $template .= '</span>$sep\\n";'; } $time_current = time(); $items = ''; $date_anchor = ''; $sendopt['nosisters'] = 1; $save_page = $formatter->page; foreach ($logs as $log) { #list($page, $user,$date,$title,$summary,$commentcount)= $log; $page = $log[0]; $user = $log[1]; $date = $log[2]; $title = $log[3]; $summary = !empty($log[4]) ? $log[4] : ''; $commentcount = !empty($log[5]) ? $log[5] : ''; $tag = md5($user . ' ' . $date . ' ' . $title); $datetag = ''; $url = qualifiedUrl($formatter->link_url(_urlencode($page))); if (empty($opts['nouser'])) { if (preg_match('/^[\\d\\.]+$/', $user)) { if (!$DBInfo->mask_hostname and $DBInfo->interwiki['Whois']) { $user = '******' . $DBInfo->interwiki['Whois'] . $user . '">' . _("Anonymous") . '</a>'; } else { $user = _("Anonymous"); } #"[$user]"; } else { if ($DBInfo->hasPage($user)) { $user = $formatter->link_tag(_rawurlencode($user), '', $user); } } } if (!$title) { continue; } $date[10] = ' '; $time = strtotime($date . ' GMT'); $date = gmdate('m-d [h:i a]', $time + $tz_off); if (!empty($summary)) { $anchor = date('Ymd', $time); if ($date_anchor != $anchor) { $date_anchor_fmt = $DBInfo->date_fmt_blog; $datetag = '<div class="blog-date">' . date($date_anchor_fmt, $time) . ' <a name="' . $anchor . '"></a><a class="perma" href="#' . $anchor . '">' . $formatter->perma_icon . '</a></div>'; $date_anchor = $anchor; } $p = new WikiPage($page); $formatter->page = $p; $summary = str_replace('\\}}}', '}}}', $summary); # XXX ob_start(); $formatter->send_page($summary, $sendopt); $summary = ob_get_contents(); ob_end_clean(); if (empty($options['noaction'])) { if ($commentcount) { $add_button = $commentcount == 1 ? _("%s comment") : _("%s comments"); } else { $add_button = _("Add comment"); } $count_tag = '<span class="count">' . $commentcount . '</span>'; $add_button = sprintf($add_button, $count_tag); $btn = $formatter->link_tag(_urlencode($page), "?action=blog&value={$tag}#BlogComment", $add_button); if ($DBInfo->use_trackback) { if (isset($trackback_list[$page][$tag])) { $counter = ' (' . $trackback_list[$page][$tag] . ')'; } else { $counter = ''; } $btn .= ' | ' . $formatter->link_tag(_urlencode($page), "?action=trackback&value={$tag}", _("track back") . $counter); } $btn = "<div class='blog-action'><span class='bullet'>»</span> " . $btn . "</div>\n"; } else { $btn = ''; } } eval($template); $items .= $datetag . $out; if (--$limit <= 0) { break; } } $formatter->page = $save_page; $url = qualifiedUrl($formatter->link_url($DBInfo->frontpage)); # make pnut $action = ''; if (!empty($options['action'])) { $action = 'action=blogchanges&'; } if (!empty($options['category'])) { $action .= 'category=' . $options['category'] . '&'; } if (!empty($options['mode'])) { $action .= 'mode=' . $options['mode'] . '&'; } $prev = $formatter->link_to('?' . $action . 'date=' . $prev_date, "<span class='bullet'>«</span> " . _("Previous")); $next = ''; if (!empty($next_date)) { $next = " | " . $formatter->link_to('?' . $action . 'date=' . $next_date, _("Next") . " <span class='bullet'>»</span>"); } return $bra . $items . $cat . '<div class="blog-action">' . $prev . $next . '</div>'; }