Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
function do_rdf_blog($formatter, $options)
{
    global $DBInfo;
    #  if (!$options['date'] or !preg_match('/^\d+$/',$date)) $date=date('Ym');
    #  else $date=$options['date'];
    $date = $options['date'];
    if ($options['all']) {
        # 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);
        $logs = Blog_cache::get_summary($blogs, $date);
        $rss_name = $DBInfo->sitename . ': ' . _("Blog Changes");
    } else {
        $blogs = array($DBInfo->pageToKeyname($formatter->page->name));
        $logs = Blog_cache::get_summary($blogs, $date);
        $rss_name = $formatter->page->name;
    }
    usort($logs, 'BlogCompare');
    $time_current = time();
    $URL = qualifiedURL($formatter->prefix);
    $img_url = qualifiedURL($DBInfo->logo_img);
    $url = qualifiedUrl($formatter->link_url("BlogChanges"));
    $desc = sprintf(_("BlogChanges at %s"), $DBInfo->sitename);
    $channel = <<<CHANNEL
<channel rdf:about="{$URL}">
  <title>{$rss_name}</title>
  <link>{$url}</link>
  <description>{$desc}</description>
  <image rdf:resource="{$img_url}"/>
  <items>
  <rdf:Seq>
CHANNEL;
    $items = "";
    #          print('<description>'."[$data] :".$chg["action"]." ".$chg["pageName"].$comment.'</description>'."\n");
    #          print('</rdf:li>'."\n");
    #        }
    $ratchet_day = FALSE;
    if (!$logs) {
        $logs = array();
    }
    foreach ($logs as $log) {
        #print_r($log);
        list($page, $user, $date, $title, $summary) = $log;
        $url = qualifiedUrl($formatter->link_url(_urlencode($page)));
        if (!$title) {
            continue;
        }
        #$tag=md5("#!blog ".$line);
        $tag = md5($user . " " . $date . " " . $title);
        #$tag=_rawurlencode(normalize($title));
        $channel .= "    <rdf:li rdf:resource=\"{$url}#{$tag}\"/>\n";
        $items .= "     <item rdf:about=\"{$url}#{$tag}\">\n";
        $items .= "     <title>{$title}</title>\n";
        $items .= "     <link>{$url}#{$tag}</link>\n";
        if ($summary) {
            $p = new WikiPage($page);
            $f = new Formatter($p);
            ob_start();
            #$f->send_page($summary);
            $f->send_page($summary, array('fixpath' => 1));
            #$summary=_html_escape(ob_get_contents());
            $summary = '<![CDATA[' . ob_get_contents() . ']]>';
            ob_end_clean();
            $items .= "     <description>{$summary}</description>\n";
        }
        $items .= "     <dc:date>{$date}+00:00</dc:date>\n";
        $items .= "     <dc:contributor>\n<rdf:Description>\n" . "<rdf:value>{$user}</rdf:value>\n" . "</rdf:Description>\n</dc:contributor>\n";
        $items .= "     </item>\n";
    }
    $url = qualifiedUrl($formatter->link_url($DBInfo->frontpage));
    $channel .= <<<FOOT
    </rdf:Seq>
  </items>
</channel>
<image rdf:about="{$img_url}">
<title>{$DBInfo->sitename}</title>
<link>{$url}</link>
<url>{$img_url}</url>
</image>
FOOT;
    $url = qualifiedUrl($formatter->link_url("FindPage"));
    $form = <<<FORM
<textinput>
<title>Search</title>
<link>{$url}</link>
<name>goto</name>
</textinput>
FORM;
    $new = "";
    if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) {
        $charset = $options['oe'];
        if (function_exists('iconv')) {
            $out = $head . $channel . $items . $form;
            $new = iconv($DBInfo->charset, $charset, $out);
            if (!$new) {
                $charset = $DBInfo->charset;
            }
        }
    } else {
        $charset = $DBInfo->charset;
    }
    $head = <<<HEAD
<?xml version="1.0" encoding="{$charset}"?>
<rdf:RDF xmlns:wiki="http://purl.org/rss/1.0/modules/wiki/"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns="http://purl.org/rss/1.0/">

<!--
    Add "oe=utf-8" to convert the charset of this rss to UTF-8.
-->
HEAD;
    header("Content-Type: text/xml");
    if ($new) {
        print $head . $new;
    } else {
        print $head . $channel . $items . $form;
    }
    #print $head;
    #print $channel;
    #print $items;
    #print $form;
    print "</rdf:RDF>";
}
Exemplo n.º 3
0
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&amp;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&amp;value={$tag}", _("track back") . $counter);
                }
                $btn = "<div class='blog-action'><span class='bullet'>&raquo;</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&amp;';
    }
    if (!empty($options['category'])) {
        $action .= 'category=' . $options['category'] . '&amp;';
    }
    if (!empty($options['mode'])) {
        $action .= 'mode=' . $options['mode'] . '&amp;';
    }
    $prev = $formatter->link_to('?' . $action . 'date=' . $prev_date, "<span class='bullet'>&laquo;</span> " . _("Previous"));
    $next = '';
    if (!empty($next_date)) {
        $next = " | " . $formatter->link_to('?' . $action . 'date=' . $next_date, _("Next") . " <span class='bullet'>&raquo;</span>");
    }
    return $bra . $items . $cat . '<div class="blog-action">' . $prev . $next . '</div>';
}