Пример #1
0
function do_sitemap($formatter, $options)
{
    global $DBInfo;
    # get page list
    if ($formater->group) {
        $group_pages = $DBInfo->getLikePages($formater->group);
        foreach ($group_pages as $page) {
            $all_pages[] = str_replace($formatter->group, '', $page);
        }
    } else {
        $all_pages = $DBInfo->getPageLists();
    }
    usort($all_pages, 'strcasecmp');
    $items = '';
    // empty string
    # process page list
    $zone = '+00:00';
    foreach ($all_pages as $page) {
        $url = qualifiedUrl($formatter->link_url(_rawurlencode($page)));
        $p = new WikiPage($page);
        $t = $p->mtime();
        $date = gmdate("Y-m-d\\TH:i:s", $t) . $zone;
        // W3C datetime format
        $item = "<url>\n";
        $item .= "  <loc>" . $url . "</loc>\n";
        $item .= "  <lastmod>" . $date . "</lastmod>\n";
        $item .= "</url>\n";
        $items .= $item;
    }
    # process output
    $out = $items;
    if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) {
        $charset = $options['oe'];
        if (function_exists('iconv')) {
            $new = iconv($DBInfo->charset, $charset, $items);
            if (!$new) {
                $charset = $DBInfo->charset;
            }
            if ($new) {
                $out = $new;
            }
        }
    } else {
        $charset = $DBInfo->charset;
    }
    $head = <<<HEAD
<?xml version="1.0" encoding="{$charset}"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9"
         url="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
         xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

HEAD;
    $foot = <<<FOOT
</urlset>
FOOT;
    # output
    header("Content-Type: text/xml");
    print $head . $out . $foot;
}
Пример #2
0
function macro_BBS($formatter, $value, $options = array())
{
    global $DBInfo;
    # set defaults
    $ncount = 20;
    # default
    $bname = $formatter->page->name;
    $nid = '';
    # check options
    $args = preg_split('/\\s*,\\s*/', $value);
    foreach ($args as $arg) {
        $arg = trim($arg);
        if ($arg == '') {
            continue;
        }
        if (($p = strpos($arg, '=')) !== false) {
            $k = substr($arg, 0, $p);
            $v = substr($arg, $p + 1);
            if ($k == 'no') {
                $nid = $v;
            } else {
                if ($k == 'mode') {
                    $options['mode'] = $v;
                }
            }
        } else {
            if ($arg == 'mode') {
            } else {
                if ($arg == (int) $arg . "") {
                    $ncount = $arg;
                } else {
                    $bname = $arg;
                }
            }
        }
    }
    $bpage = _rawurlencode($bname);
    $nid = $nid ? $nid : $_GET['no'];
    $nids = array();
    if ($nid) {
        $nids = preg_split('/\\s+/', $nid);
        rsort($nids);
    }
    $options['p'] = $_GET['p'] > 0 ? $_GET['p'] : 1;
    $options['c'] = $ncount != 20 ? $ncount : '';
    $options['p'] = intval($options['p']);
    # is it exists ?
    if (!$DBInfo->hasPage($bname)) {
        return _("This bbs does not exists yet. Please save this page first");
    }
    # load a config file
    $conf0 = array();
    if (file_exists('config/bbs.' . $bname . '.php')) {
        $confname = 'bbs.' . $bname . '.php';
        $conf0 = _load_php_vars('config/bbs.default.php');
    } else {
        $confname = 'bbs.default.php';
    }
    $conf = _load_php_vars('config/' . $confname);
    $conf = array_merge($conf0, $conf);
    $conf['data_dir'] = $DBInfo->data_dir;
    $conf['dba_type'] = $DBInfo->dba_type;
    if (!$DBInfo->use_bbs) {
        return '[[BBS]]';
    }
    #if ($DBInfo->use_bbs == 1);
    #if ($DBInfo->use_bbs == 2);
    $MyBBS = new BBS_text($bname, $conf);
    // XXX
    if ($options['new'] and $MyBBS) {
        return $MyBBS;
    }
    if (!$MyBBS) {
        return '[[BBS]]';
    }
    $msg = '';
    $btn = array();
    # read messages
    #
    $formatter->baserule[] = "/^((-=)+-?\$)/";
    $formatter->baserule[] = "/ comment #(\\d+)\\b/";
    $formatter->baserule[] = "/\\[reply (\\d+)\\]/";
    $formatter->baserepl[] = "<hr />\n";
    $formatter->baserepl[] = " comment [#c\\1 #\\1]";
    $formatter->baserepl[] = "<script type='text/javascript'><!--\n" . " addReplyLink(\\1); //--></script>";
    $msg = '';
    $narticle = sizeof($nids);
    $js = '';
    if ($nid and $narticle == 1 and $options['mode'] == 'simple') {
        $nid = $nids[0];
        if (!$nid or !$MyBBS->hasPage($nid)) {
            return '[[BBS(error)]]';
        }
        include_once 'lib/metadata.php';
        $body = $MyBBS->getPage($nid);
        list($metas, $body) = _get_metadata($body);
        $img = '';
        if ($MyBBS->use_attach) {
            $cache = new Cache_text('attachments');
            $attachs = $cache->fetch($MyBBS->bbsname . ':' . $nid);
            if (preg_match('/^attachment:([^\\?]+)(\\?.*)?$/', $attachs[0], $m)) {
                $img = $formatter->macro_repl('Attachment', $m[1] . '?thumbwidth=100');
            }
            $subject = $formatter->link_tag($bpage, "?no={$nid}", $metas['Subject']);
        }
        $out = "<div class='simpleView'><table>\n" . "<tr><td class='img'>" . $img . "</td><td class='subject'>" . $subject . '</td></tr>' . "<tr><td colspan='2'></td>\n</tr></table></div>";
        return $out;
    }
    foreach ($nids as $nid) {
        if (!$nid or !$MyBBS->hasPage($nid)) {
            continue;
        }
        $fields = array('Name', 'Subject', 'Date', 'Email', 'HomePage', 'IP', 'Keywords');
        include_once 'lib/metadata.php';
        #Name: wkpark
        #Subject: Oh well
        #Date: 2006-04-29 42:04:39
        #Email: wkpark@gmail.com
        #HomePage:
        #IP: 2xx.xxx.xxx.x
        $body = $MyBBS->getPage($nid);
        if ($body != null) {
            $options['nosisters'] = 1;
            $MyBBS->counter->incCounter($nid, $options);
            list($metas, $body) = _get_metadata($body);
            $boundary = strtoupper(md5("COMMENT"));
            # XXX
            $copy = $body;
            list($comment, $copy) = explode("----" . $boundary . "\n", $copy, 2);
            while (!empty($comment)) {
                list($comment, $copy) = explode("----" . $boundary . "\n", $copy, 2);
                if (preg_match('/^Comment-Id:\\s*(\\d+)/i', $comment, $m)) {
                    list($myhead, $my) = explode("\n\n", $comment, 2);
                    $hidden .= '<pre style="display:none;" id="comment_text_' . $m[1] . '">' . _html_escape($my) . '</pre>';
                }
            }
            ob_start();
            # add some basic rule/repl for bts
            $rule = "/-{4}(?:" . $boundary . ")?\nComment-Id:\\s*(\\d+)\n" . "From:\\s*([^\n]+)\nDate:\\s*([^\n]+)\n\n/im";
            $repl = "----\n'''Comment-Id:''' [#c\\1][#c\\1 #\\1] by \\2 on [[DateTime(\\3)]] [reply \\1]\n\n";
            $body = preg_replace($rule, $repl, $body);
            $formatter->quote_style = 'bbs-comment';
            $options['usemeta'] = 1;
            #
            $q_save = $formatter->self_query;
            $query = '?no=' . $nid . '&amp;p=' . $options['p'];
            $formatter->self_query = $query;
            $save = $formatter->preview;
            $formatter->preview = 1;
            $save_markup = $formatter->format;
            ob_start();
            if ($conf['default_markup']) {
                $formatter->pi['#format'] = $conf['default_markup'];
            }
            $formatter->send_page($body, $options);
            $body = ob_get_contents();
            ob_end_clean();
            $formatter->pi['#format'] = $save_markup;
            $formatter->self_query = $q_save;
            $msg .= "<div class='bbsArticle'>" . '<div class="head"><h2>' . _("No") . ' ' . $nid . ': ' . $metas['Subject'] . '</h2></div>' . '<div class="body">' . '<div class="extra"> @ ' . $metas['Date'] . ' (' . _mask_hostname($metas['IP'], 3) . ')</div>' . '<div class="user"><h3>' . $metas['Name'] . '</h3></div>' . '<div class="article">' . $body . "</div>\n</div>\n" . '<div class="foot"><div></div></div>' . "</div>\n";
            $snid = $nid;
            $btn['edit'] = $formatter->link_tag($bpage, "?action=bbs&amp;mode=edit&amp;no=" . $nid, '<span>' . _("Edit") . '</span>', 'class="button"');
            $btn['delete'] = $formatter->link_tag($bpage, "?action=bbs&amp;mode=delete&amp;no=" . $nid, '<span>' . _("Delete") . '</span>', 'class="button"');
            if ($narticle == 1 and $conf['use_comment']) {
                $opts['action'] = 'bbs';
                $opts['no'] = $nid;
                $opts['p'] = $options['p'];
                $opts['mode'] = 'comment';
                $opts['nopreview'] = 1;
                $p = new WikiPage($bname . ':' . $opts['no'], $options);
                $opts['datestamp'] = $p->mtime();
                $comment = $formatter->macro_repl('Comment', 'usemeta', $opts);
                unset($opts['no']);
                # XXX
            }
            $msg .= '<div class="bbsComment">' . $comment . '</div><div class="bbsArticleBtn">' . implode(" ", $btn) . '</div>';
            unset($btn['delete']);
            unset($btn['edit']);
            $title = str_replace('"', '\\"', $metas['Subject']);
            $js .= <<<JS
<script type="text/javascript">
/*<![CDATA[*/
document.title+=" [" + {$snid} + "] - " + "{$title}";
/*]]>*/
</script>
JS;
        }
    }
    if (!empty($msg) and !$_GET['p']) {
        return $msg;
    }
    if (1) {
        # XXX
        $nochk = _("Please check article numbers.");
        $js .= <<<JS
<script type='text/javascript'>
/*<![CDATA[*/
  function send_list(obj,mode) {
    var tmp="";
    var i, chk=false;

    form=obj.parentNode.parentNode;

    for(i=0;i< form.length;i++) {
       if(form[i].type!="checkbox") continue;
       if(form[i].checked) {
          tmp+=form[i].value+" ";
          chk=true;
       }
    }
    if(chk==true) {
       form.no.value = tmp.substr(0,tmp.length-1);
       if (mode!=undefined) {
         form.elements.action.value = 'bbs';
         form.elements.mode.value = mode;
       } else {
         form.removeChild(form.elements.mode);
         form.removeChild(form.elements.action);
       }
       form.submit();
       return false;
    }
    alert ("{$nochk}");
    return false;
  }
/*]]>*/
</script>

JS;
    }
    # get list
    $options['perpage'] = $ncount;
    $list = $MyBBS->getList($ncount, $options);
    # get total number of articles
    $tot = $MyBBS->getCount();
    $pages = intval($tot / $ncount);
    if ($tot % $ncount) {
        $pages++;
    }
    if ($options['mode'] == 'rss') {
        $rss = '<' . '?xml version="1.0" encoding="utf-8"?>' . "\n" . '<rss version="2.0">' . "\n";
        $rss .= "<channel>\n<title>" . $DBInfo->sitename . ": </title>\n";
        $rss .= "<link>" . qualifiedUrl($formatter->link_url($bpage)) . "</link>\n";
        $rss .= "<description></description>\n";
        $rss .= "<pubDate>" . gmdate('D, j M Y H:i:s', time()) . " +0000</pubDate>\n";
        foreach ($list as $l) {
            $item = "<item>\n";
            $item .= "<title><![CDATA[" . $l[7] . "]]></title>\n";
            $item .= "<link>" . qualifiedUrl($formatter->link_url($bpage, "?no={$l['0']}")) . "</link>\n";
            $item .= "<author><![CDATA[" . $l[3] . "]]></author>\n";
            $item .= "<description><![CDATA[" . $l[3] . "]]></description>\n";
            $item .= "<pubDate>" . gmdate('D, j M Y H:i:s', $l[2]) . " +0000</pubDate>\n</item>\n";
            $rss .= $item;
        }
        $rss .= "</channel>\n</rss>\n";
        return $rss;
    } else {
        if ($options['mode'] == 'simple') {
            $simple = "<div class='bbsSimple'><table class='bbsSimple'>\n";
            foreach ($list as $l) {
                $date = date("Y-m-d", $l[2]);
                $my = $l[7];
                $title = '';
                if (function_exists('mb_strimwidth') and strlen($l[7]) > 60) {
                    $title = 'title="' . $l[7] . '"';
                    $my = mb_strimwidth($l[7], 0, 40, '...', $DBInfo->charset);
                }
                $simple .= "<tr><td class='date'>[" . $date . "]</td><td>" . $formatter->link_tag($bpage, "?no={$l['0']}" . $extra, $my, $title) . '</td></tr>';
            }
            $simple .= "<tr><td colspan='2' class='more'>" . $formatter->link_tag($bpage, "", _("More") . '&#187;') . "</td>\n</tr>\n";
            $simple .= "</table>";
            return $simple;
        }
    }
    if ($pages > 1) {
        $pnut = _get_pagelist($formatter, $pages, '?' . $extra . ($extra ? '&amp;p=' : 'p='), $options['p'], $ncount);
    } else {
        $pnut = "<div class='clear'></div>";
    }
    $extra = $options['p'] ? '&amp;p=' . $options['p'] : '';
    #$head=array(_("no"),'C',_("Title"),_("Name"),_("Date"),_("Hit"));
    #$out.="<col width='3%' class='num' /><col width='1%' class='check' /><col width='63%' class='title' /><col width='14%' /><col width='13%' /><col width='7%' class='hit' />\n";
    #$out.='<thead><tr><th>'.implode("</th><th>",$head)."</th></tr><thead>\n";
    #$out.="<tbody>\n";
    $item = array();
    foreach ($list as $l) {
        $nid =& $l[0];
        $ip =& $l[1];
        $date = date("Y-m-d", $l[2]);
        $user = $l[3];
        $subject = $formatter->link_tag($bpage, "?no={$nid}" . $extra, $l[7]);
        $hit = $MyBBS->counter->pageCounter($nid);
        $chk = '<input type="checkbox" value="' . $nid . '">';
        #$item=array(in_array($nid,$nids) ? '<strong>&raquo;</strong>':$nid,$chk,$subject,$user,$date,$hit);
        $item[] = array('num' => in_array($nid, $nids) ? '<strong>&raquo;</strong>' : $nid, 'check' => $chk, 'subject' => $subject, 'name' => $user, 'date' => $date, 'hit' => $hit);
        ##$tmp='<tr><td>'.implode("</td><td>",$item)."</td></tr>\n";
        #$tmp="<tr><td class='no'>$item[0]</td><td class='check'>$item[1]</td>".
        #    "<td class='title'>$item[2]</td><td class='name'>$item[3]</td>".
        #    "<td class='date'>$item[4]</td><td class='hit'>$item[5]</td>".
        #    "</tr>\n";
        #$out.=$tmp;
    }
    $formatter->_vars['item'] =& $item;
    $out .= $formatter->include_theme('plugin/BBS/default', 'list', array());
    #$out.= $formatter->include_theme('plugin/BBS/default_tpl','list',array());
    #$out.= $formatter->processor_repl('tpl_','',array('path'=>'theme/plugin/BBS/blue_tpl/list.tpl'));
    #$out.="</tbody>\n";
    $btn['new'] = $formatter->link_tag($bpage, "?action=bbs&amp;mode=edit", '<span>' . _("New") . '</span>', 'class="button"');
    unset($btn['edit']);
    $bn['view'] = $formatter->link_tag($bpage, "", '<span>' . _("Read") . '</span>', 'onclick="return send_list(this)" onfocus="blur()" class="button"');
    $bn['delete'] = $formatter->link_tag($bpage, "", '<span>' . _("Delete") . '</span>', 'onclick="return send_list(this,\'delete\')" onfocus="blur()" class="button"');
    $del = "<div class='bbsAdminBtn'>" . implode(" ", $bn) . "</div>\n";
    $btns = "<div class='bbsBtn'>" . implode(" ", $btn) . "</div>\n";
    $lnk = $formatter->link_url($bpage, '?action=bbs');
    $form0 = "<form method='get' action='{$lnk}'>\n";
    $form1 = '<input type="hidden" name="no" />';
    if ($options['p']) {
        $form1 .= '<input type="hidden" name="p" value="' . $options['p'] . "\" />\n";
    }
    $form1 .= '<input type="hidden" name="mode" />' . '<input type="hidden" name="action" />';
    $form1 .= "</form>\n";
    $pnut = "<div class='pnut'>{$pnut}</div>";
    $info = '<div class="bbsRSS">' . sprintf(_("Total %s articles."), '<strong>' . $tot . '</strong>') . ' ' . $formatter->link_tag($bpage, '?action=bbs&amp;mode=rss', $formatter->icon['rss']) . '</div>';
    return $info . $pnut . $msg . $js . $form0 . $out . $del . $form1 . $pnut . $btns;
}
Пример #3
0
function macro_PageList($formatter, $arg = "", $options = array())
{
    global $DBInfo;
    $offset = '';
    if (!is_numeric($options['offset']) or $options['offset'] <= 0) {
        unset($options['offet']);
    } else {
        $offset = $options['offset'];
    }
    preg_match("/([^,]*)(\\s*,\\s*)?(.*)?\$/", $arg, $match);
    if ($match[1] == 'date') {
        $options['date'] = 1;
        $arg = '';
    } else {
        if ($match) {
            $arg = $match[1];
            $opts = array();
            if ($match[3]) {
                $opts = explode(",", $match[3]);
            }
            if (in_array('date', $opts)) {
                $options['date'] = 1;
            }
            if (in_array('dir', $opts)) {
                $options['dir'] = 1;
            }
            if (in_array('subdir', $opts)) {
                $options['subdir'] = 1;
            }
            if (in_array('info', $opts)) {
                $options['info'] = 1;
            } else {
                if ($arg and (in_array('metawiki', $opts) or in_array('m', $opts))) {
                    $options['metawiki'] = 1;
                }
            }
        }
    }
    $upper = '';
    if (!empty($options['subdir'])) {
        if (($p = strrpos($formatter->page->name, '/')) !== false) {
            $upper = substr($formatter->page->name, 0, $p);
        }
        $needle = _preg_search_escape($formatter->page->name);
        $needle = '^' . $needle . '\\/';
    } else {
        if (!empty($options['rawre'])) {
            $needle = $arg;
        } else {
            $needle = _preg_search_escape($arg);
        }
    }
    $test = @preg_match("/{$needle}/", "", $match);
    if ($test === false) {
        # show error message
        return "[[PageList(<font color='red'>Invalid \"{$arg}\"</font>)]]";
    }
    $ret = array();
    $options['ret'] =& $ret;
    $options['offset'] = $offset;
    if (!empty($options['date'])) {
        $tz_offset =& $formatter->tz_offset;
        $all_pages = $DBInfo->getPageLists($options);
    } else {
        if (!empty($options['metawiki'])) {
            $all_pages = $DBInfo->metadb->getLikePages($needle);
        } else {
            $all_pages = $DBInfo->getLikePages($needle);
        }
    }
    $hits = array();
    $out = '';
    if (!empty($options['date']) and !is_numeric($k = key($all_pages)) and is_numeric($all_pages[$k])) {
        if ($needle) {
            while (list($pagename, $mtime) = @each($all_pages)) {
                preg_match("/{$needle}/", $pagename, $matches);
                if ($matches) {
                    $hits[$pagename] = $mtime;
                }
            }
        } else {
            $hits = $all_pages;
        }
        arsort($hits);
        while (list($pagename, $mtime) = @each($hits)) {
            $out .= '<li>' . $formatter->link_tag(_rawurlencode($pagename), "", _html_escape($pagename)) . ". . . . [" . gmdate("Y-m-d", $mtime + $tz_offset) . "]</li>\n";
        }
        $out = "<ol>\n" . $out . "</ol>\n";
    } else {
        foreach ($all_pages as $page) {
            preg_match("/{$needle}/", $page, $matches);
            if ($matches) {
                $hits[] = $page;
            }
        }
        sort($hits);
        if (!empty($options['dir']) or !empty($options['subdir'])) {
            $dirs = array();
            $files = array();
            if ($options['subdir']) {
                $plen = strlen($formatter->page->name) + 1;
            } else {
                $plen = 0;
            }
            foreach ($hits as $pagename) {
                if (($rp = strrpos($pagename, '/')) !== false) {
                    $p = strpos($pagename, '/');
                    $name = substr($pagename, $plen);
                    $dum = explode('/', $name);
                    if (sizeof($dum) > 1) {
                        $dirname = array_shift($dum);
                        $orgname = substr($pagename, 0, $p) . '/' . $dirname;
                        if (empty($dirs[$orgname])) {
                            $dirs[$orgname] = array();
                        }
                        $dirs[$orgname][] = implode('/', $dum);
                        $files[$orgname] = $dirname;
                    } else {
                        $files[$pagename] = $name;
                    }
                    continue;
                }
                $files[$pagename] = $pagename;
            }
            $iconset = 'tango';
            $icon_dir = $DBInfo->imgs_dir . '/plugin/UploadedFiles/' . $iconset;
            $dicon = "<img src='{$icon_dir}/folder-16.png' width='16px'/>";
            $uicon = "<img src='{$icon_dir}/up-16.png' width='16px'/>";
            $ficon = "<img src='{$icon_dir}/text-16.png' width='16px'/>";
            $now = time();
            if ($upper) {
                $out .= '<tr><td>' . $uicon . '</td><td>' . $formatter->link_tag(_rawurlencode($upper), "", '..') . '</td>';
            }
            foreach ($dirs as $pg => $name) {
                $out .= '<tr><td>' . $dicon . '</td><td>' . $formatter->link_tag(_rawurlencode($pg), "", _html_escape($files[$pg])) . '</td>';
                if ($options['info']) {
                    $p = new WikiPage($pg);
                    $mtime = $p->mtime();
                    $time_diff = (int) ($now - $mtime) / 60;
                    if ($time_diff < 1440) {
                        $date = sprintf(_("[%sh %sm ago]"), (int) ($time_diff / 60), $time_diff % 60);
                    } else {
                        $date = date("Y/m/d H:i", $mtime);
                    }
                    $out .= '<td>' . $date . '</td>';
                }
                $out .= "</tr>\n";
                if (isset($files[$pg])) {
                    unset($files[$pg]);
                }
            }
            foreach ($files as $pg => $name) {
                $out .= '<tr><td>' . $ficon . '</td><td>' . $formatter->link_tag(_rawurlencode($pg), "", _html_escape($name)) . '</td>';
                if (!empty($options['info'])) {
                    $p = new WikiPage($pg);
                    $mtime = $p->mtime();
                    $time_diff = (int) ($now - $mtime) / 60;
                    if ($time_diff < 1440) {
                        $date = sprintf(_("[%sh %sm ago]"), (int) ($time_diff / 60), $time_diff % 60);
                    } else {
                        $date = date("Y/m/d H:i", $mtime);
                    }
                    $out .= '<td>' . $date . '</td>';
                }
                $out .= "</tr>\n";
            }
            $out = '<table>' . $out . '</table>';
        } else {
            foreach ($hits as $pagename) {
                $out .= '<li>' . $formatter->link_tag(_rawurlencode($pagename), "", _html_escape($pagename)) . "</li>\n";
            }
            $out = "<ol>\n" . $out . "</ol>\n";
            $count = count($hits);
            $total = $DBInfo->getCounter();
            // hide the link of next page for anonymous user
            if (!empty($options['id']) and $options['id'] == 'Anonymous') {
                return $out;
            }
            if ($total > $count or $offset < $total) {
                if (isset($ret['offset']) and $ret['offset'] < $total and $count < $total) {
                    $extra = '';
                    if ($options['date']) {
                        $extra .= '&amp;date=1';
                    }
                    if ($options['info']) {
                        $extra .= '&amp;info=1';
                    }
                    if (isset($needle[0])) {
                        $extra .= '&amp;value=' . $needle;
                    }
                    $qoff = '&amp;offset=' . ($ret['offset'] + $count);
                    $out .= $formatter->link_to("?action=pagelist{$extra}{$qoff}", _("Show next page"));
                }
            }
        }
    }
    return $out;
}
Пример #4
0
/**
 * get updated info
 *
 */
function ajax_RecentChanges($formatter, $options = array())
{
    global $DBInfo;
    // list style
    if (!empty($options['type']) and $options['type'] == 'list') {
        $options['call'] = 1;
        $options['ajax'] = 1;
        $opt = '';
        if (isset($options['datefmt'])) {
            $opt .= $options['datefmt'] . ',';
        }
        $opt .= 'list';
        if (!empty($options['item'])) {
            $opt .= ',item=' . $options['item'];
        }
        $out = macro_RecentChanges($formatter, $opt, $options);
        echo $out;
        return;
    }
    if (empty($options['value'])) {
        echo '[]';
        return;
    }
    $checknew = 0;
    $checkchange = 0;
    if (!empty($options['new'])) {
        $checknew = 1;
    }
    if (!empty($options['change'])) {
        $checkchange = 1;
    }
    require_once 'lib/JSON.php';
    $json = new Services_JSON();
    $rclist = $json->decode($options['value']);
    if (!is_array($rclist)) {
        echo '[]';
        return;
    }
    // get bookmark parameter and call bookmark macro
    if (!empty($options['time'])) {
        if (is_numeric($options['time']) and $options['time'] > 0) {
            $formatter->macro_repl('Bookmark', '', $options);
            //$bookmark = $options['time'];
        }
    }
    $u = $DBInfo->user;
    # retrive user info
    if ($u->id != 'Anonymous') {
        $bookmark = !empty($u->info['bookmark']) ? $u->info['bookmark'] : '';
    } else {
        $bookmark = $u->bookmark;
    }
    if (!$bookmark) {
        $bookmark = time();
    }
    $tz_offset = $formatter->tz_offset;
    $info = array();
    foreach ($rclist as $page_name) {
        $p = new WikiPage($page_name);
        if (!$p->exists()) {
            $info[$page_name]['state'] = 'deleted';
            continue;
            // XXX
        }
        $ed_time = $p->mtime();
        if ($ed_time <= $bookmark) {
            break;
        }
        $info[$page_name]['state'] = 'updated';
        $add = 0;
        $del = 0;
        if ($checknew or $checkchange) {
            $v = $p->get_rev($bookmark);
            if (empty($v)) {
                $info[$page_name]['state'] = 'new';
                $add += $p->lines();
            }
        }
        if ($checkchange) {
            if (empty($v)) {
                // new
                $infos = array();
            } else {
                $infos = $p->get_info('>' . $bookmark);
            }
            foreach ($infos as $inf) {
                $tmp = explode(' ', trim($inf[1]));
                if (isset($tmp[1])) {
                    $add += $tmp[0];
                    $del += $tmp[1];
                }
            }
            $info[$page_name]['add'] = $add;
            $info[$page_name]['del'] = $del;
        }
    }
    $info['__-_-bookmark-_-__'] = $bookmark;
    echo $json->encode($info);
    return;
}
Пример #5
0
function do_sitemap($formatter, $options)
{
    global $DBInfo, $Config;
    $tc = new Cache_text('persist', array('depth' => 0));
    $extra = '';
    if (!empty($formater->group)) {
        $extra = '.' . $formatter->group;
    }
    if (!empty($formatter->prefix)) {
        $extra .= qualifiedUrl($formatter->prefix);
    }
    // all pages
    $mtime = $DBInfo->mtime();
    $lastmod = gmdate('D, d M Y H:i:s \\G\\M\\T', $mtime);
    $etag = md5($mtime . $DBInfo->etag_seed . $extra);
    $options['etag'] = $etag;
    $options['mtime'] = $mtime;
    // set the s-maxage for proxy
    $date = gmdate('Y-m-d-H-i-s', $mtime);
    $proxy_maxage = !empty($Config['proxy_maxage']) ? ', s-maxage=' . $Config['proxy_maxage'] : '';
    // only xml format supported
    $format = 'text/xml';
    if (isset($options['format']) and in_array($options['format'], array('text/xml'))) {
        $format = $options['format'];
    }
    $header[] = 'Content-Type: ' . $format;
    $header[] = 'Cache-Control: public' . $proxy_maxage . ', max-age=0, must-revalidate';
    $need = http_need_cond_request($mtime, $lastmod, $etag);
    if (!$need) {
        $header[] = 'HTTP/1.0 304 Not Modified';
    } else {
        $header[] = 'Content-Disposition: attachment; filename="sitemap-' . $date . '.xml"';
    }
    $formatter->send_header($header, $options);
    if (!$need) {
        @ob_end_clean();
        return;
    }
    if (!$formatter->refresh && ($ret = $tc->fetch('sitemap' . $extra . '.mtime')) !== false) {
        if (($ret = $tc->fetch('sitemap' . $extra, 0, array('print' => 1))) !== false) {
            return;
        }
    }
    // set sitemap public cache
    $ext = $format == 'text/xml' ? 'xml' : 'txt';
    $sc = new Cache_text('sitemap', array('dir' => $DBInfo->cache_public_dir, 'ext' => $ext, 'depth' => 0));
    # get page list
    set_time_limit(0);
    if ($formater->group) {
        $group_pages = $DBInfo->getLikePages($formater->group);
        foreach ($group_pages as $page) {
            $all_pages[] = str_replace($formatter->group, '', $page);
        }
        usort($all_pages, 'strcasecmp');
    } else {
        if (!empty($Config['sitemap_sortby'])) {
            // call PageSort macro.
            $opts = array();
            $opts['sortby'] = $Config['sitemap_sortby'];
            // date or size
            $opts['.call'] = 1;
            $ret = $formatter->macro_repl('PageSort', '', $opts);
            $all_pages = array();
            if (!empty($ret['count'])) {
                $tc->fetch('pagedate.raw');
                $rawfile = $tc->cache_path . '/' . $tc->getKey('pagedate.raw');
                $fp = fopen($rawfile, 'r');
                if (is_resource($fp)) {
                    while (($line = fgets($fp, 1024)) != false) {
                        $tmp = explode("\t", $line);
                        $all_pages[] = $tmp[0];
                    }
                    fclose($fp);
                }
            }
        } else {
            $args = array('all' => 1);
            $all_pages = $DBInfo->getPageLists($args);
            usort($all_pages, 'strcasecmp');
        }
    }
    $count = sizeof($all_pages);
    $map = '';
    $zone = '+00:00';
    $ttl = !empty($DBInfo->sitemap_ttl) ? $DBInfo->sitemap_ttl : 60 * 60 * 24 * 7;
    if ($count > 50000) {
        $map = <<<HEAD
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

HEAD;
        $date = gmdate("Y-m-d\\TH:i:s", time()) . $zone;
        // W3C datetime format
        $total = intval($count / 50000) + ($count % 50000 > 0 ? 1 : 0);
        for ($i = 0; $i < $total; $i++) {
            $mapname = $sc->getKey(sprintf('sitemap' . $extra . '%03d', $i));
            $map .= "<sitemap>\n<loc>\n" . qualifiedUrl($DBInfo->cache_public_url . '/' . $mapname) . '</loc>' . "\n";
            $map .= '<lastmod>' . $date . "</lastmod>\n</sitemap>\n";
        }
        $map .= "</sitemapindex>\n";
        $tc->update('sitemap' . $extra, $map);
        $tc->update('sitemap' . $extra . '.mtime', array('dummy' => 1), $ttl);
    }
    # charset
    if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) {
        $charset = $options['oe'];
    } else {
        $charset = $DBInfo->charset;
    }
    $head = <<<HEAD
<?xml version="1.0" encoding="{$charset}"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9"
         url="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
         xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

HEAD;
    $foot = <<<FOOT
</urlset>
FOOT;
    # process page list
    $i = 0;
    $ii = 0;
    $items = array();
    foreach ($all_pages as $page) {
        $ii++;
        $url = qualifiedUrl($formatter->link_url(_rawurlencode($page)));
        $p = new WikiPage($page);
        $t = $p->mtime();
        $date = gmdate("Y-m-d\\TH:i:s", $t) . $zone;
        // W3C datetime format
        $item = "<url>\n";
        $item .= "  <loc>" . $url . "</loc>\n";
        $item .= "  <lastmod>" . $date . "</lastmod>\n";
        $item .= "</url>";
        $items[] = $item;
        if ($ii >= 50000) {
            $ii = 0;
            // process output
            $out = implode("\n", $items);
            if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) {
                $charset = $options['oe'];
                if (function_exists('iconv')) {
                    $new = iconv($DBInfo->charset, $charset, $items);
                    if (!$new) {
                        $charset = $DBInfo->charset;
                    }
                    if ($new) {
                        $out = $new;
                    }
                }
            }
            $sc->update(sprintf('sitemap' . $extra . '%03d', $i), $head . $out . $foot);
            $i++;
            $items = array();
        }
    }
    $sc->update('sitemap' . $extra . '.mtime', array('dummy' => 1), $ttl);
    // process output
    if ($count > 50000) {
        if (count($items)) {
            $out = implode("\n", $items);
            if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) {
                $charset = $options['oe'];
                if (function_exists('iconv')) {
                    $new = iconv($DBInfo->charset, $charset, $items);
                    if (!$new) {
                        $charset = $DBInfo->charset;
                    }
                    if ($new) {
                        $out = $new;
                    }
                }
            }
            $sc->update(sprintf('sitemap' . $extra . '%03d', $i), $head . $out . $foot);
        }
    } else {
        $out = implode("\n", $items);
        if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) {
            $charset = $options['oe'];
            if (function_exists('iconv')) {
                $new = iconv($DBInfo->charset, $charset, $items);
                if (!$new) {
                    $charset = $DBInfo->charset;
                }
                if ($new) {
                    $out = $new;
                }
            }
        }
        $map = $head . $out . $foot;
        $tc->update('sitemap' . $extra, $map);
        $tc->update('sitemap' . $extra, array('dummy' => 1), $ttl);
    }
    echo $map;
}