function macro_PageHits($formatter = "", $value) { global $DBInfo; if (!$DBInfo->use_counter) { return "[[PageHits is not activated. set \$use_counter=1; in the config.php]]"; } $pages = $DBInfo->getPageLists(); sort($pages); $hits = array(); foreach ($pages as $page) { $hits[$page] = $DBInfo->counter->pageCounter($page); } if (!empty($value) and ($value == 'reverse' or $value[0] == 'r')) { asort($hits); } else { arsort($hits); } $out = ''; while (list($name, $hit) = each($hits)) { if (!$hit) { $hit = 0; } $name = $formatter->link_tag(_rawurlencode($name), "", htmlspecialchars($name)); $out .= "<li>{$name} . . . . [{$hit}]</li>\n"; } return "<ol>\n" . $out . "</ol>\n"; }
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; }
function do_Clip($formatter, $options) { global $DBInfo; $enable_replace = 1; $keyname = $DBInfo->_getPageKey($options['page']); $_dir = str_replace("./", '', $DBInfo->upload_dir . '/' . $keyname); // support hashed upload dir if (!is_dir($_dir) and !empty($DBInfo->use_hashed_upload_dir)) { $prefix = get_hashed_prefix($keyname); $_dir = str_replace('./', '', $DBInfo->upload_dir . '/' . $prefix . $keyname); } $pagename = _urlencode($options['page']); $name = $options['value']; if (!$name) { $title = _("Fatal error !"); $formatter->send_header("Status: 406 Not Acceptable", $options); $formatter->send_title($title, "", $options); print "<h2>" . _("No filename given") . "</h2>"; $formatter->send_footer("", $options); return; } $pngname = _rawurlencode($name); //$imgpath="$_dir/$pngname"; $imgpath = "{$pngname}"; $imgparam = ''; if (file_exists($_dir . '/' . $imgpath . '.png')) { $url = qualifiedUrl($DBInfo->url_prefix . '/' . $_dir . '/' . $imgpath . '.png'); $imgparam = "<param name='image' value='{$url}' />"; } $png_url = "{$imgpath}.png"; $formatter->send_header("", $options); $formatter->send_title(_("Clipboard"), "", $options); $prefix = $formatter->prefix; $now = time(); $url_exit = $formatter->link_url($pagename, "?ts={$now}"); $url_save = $formatter->link_url($pagename, "?action=draw"); $url_help = $formatter->link_url("ClipMacro"); $pubpath = $DBInfo->url_prefix . "/applets/ClipPlugin"; print "<h2>" . _("Cut & Paste a Clipboard Image") . "</h2>\n"; print <<<APPLET <applet code="clip" archive="clip.jar" codebase="{$pubpath}" width='200' height='200' align="center"> <param name="pngpath" value="{$png_url}" /> <param name="savepath" value="{$url_save}" /> <param name="viewpath" value="{$url_exit}" /> <param name="compress" value="5" /> {$imgparam} <b>NOTE:</b> You need a Java enabled browser to edit the drawing example. </applet><br /> APPLET; $formatter->send_footer("", $options); return; }
function macro_PageHits($formatter, $value = '', $params = array()) { global $DBInfo, $Config; if (empty($Config['use_counter'])) { return "[[PageHits is not activated. set \$use_counter=1; in the config.php]]"; } $perpage = !empty($Config['counter_per_page']) ? intval($Config['counter_per_page']) : 200; if (!empty($params['p'])) { $p = intval($params['p']); } else { $p = 0; } if ($p < 0) { $p = 0; } $hits = $DBInfo->counter->getPageHits($perpage, $p); if (!empty($value) and ($value == 'reverse' or $value[0] == 'r')) { asort($hits); } else { arsort($hits); } $out = ''; while (list($name, $hit) = each($hits)) { if (!$hit) { $hit = 0; } $name = $formatter->link_tag(_rawurlencode($name), "", _html_escape($name)); $out .= "<li>{$name} . . . . [{$hit}]</li>\n"; } $start = $perpage * $p; if ($start > 0) { $start = ' start="' . $start . '"'; } else { $start = ''; } $out = "<ol{$start}>\n" . $out . "</ol>\n"; $prev = ''; $next = ''; if ($p > 0) { $prev = $formatter->link_tag($formatter->page->urlname, '?action=pagehits&p=' . ($p - 1), _("« Prev")); } $p++; if (count($hits) >= 0) { $next = $formatter->link_tag($formatter->page->urlname, '?action=pagehits&p=' . $p, _("Next »")); } return $out . $prev . ' ' . $next; }
function macro_JME($formatter, $value) { global $DBInfo; $jar = 'JME.zip'; // XXX $jar = 'JME.jar'; $draw_dir = str_replace('./', '', $DBInfo->upload_dir . '/JME'); if (!file_exists($draw_dir)) { umask(00); mkdir($draw_dir, 0777); } $name = $value; $urlname = _rawurlencode($value); $molname = $name . ".mol"; $now = time(); $url = $formatter->link_url($formatter->page->name, "?action=jme&value={$urlname}&now={$now}"); if (!file_exists($draw_dir . "/{$molname}")) { if ($name) { return "<a href='{$url}'>" . sprintf(_("Draw a new molecule '%s'"), $name) . "</a>"; } else { return "<a href='{$url}'>" . _("Draw a new molecule") . "</a>"; } } $fp = fopen($draw_dir . '/' . $molname, 'r'); if ($fp) { $mol = ''; while (!feof($fp)) { $mol .= fgets($fp, 2048); } fclose($fp); $mol = str_replace("\r\n", "|\n", $mol); } $pubpath = $DBInfo->url_prefix . "/applets/JMEPlugin"; $mol = _html_escape($mol); return <<<APPLET <applet code="JME.class" name="JME" codebase="{$pubpath}" archive="{$jar}"> <param name="options" value="depict" /> <param name="mol" value="{$mol}" /> You have to enable Java and JavaScript on your machine ! </applet> APPLET; }
function macro_Referer($formatter, $value, &$options) { global $DBInfo; if (empty($DBInfo->use_referer)) { return "[[Referer macro: {$use_referer} is off.]]"; } $referer_log_filename = $DBInfo->cache_dir . "/referer/referer.log"; if ($value !== true) { // [[referer]] or ?action=referer $needle = $formatter->page->urlname; } else { // [[referer()]] unset($needle); } if ($needle and false) { // so slow XXX $handle = fopen($referer_log_filename, 'r'); if (!is_resource($handle)) { return ''; } $logs = array(); while (!feof($handle)) { $line = fgets($handle); list(, $pagename, ) = explode("\t", $line); if ($pagename == $needle) { $logs[] = $line; } if ($count > 100) { break; } $count++; } fclose($handle); $logs = array_reverse($logs); } else { $number_of_lines = 200; // XXX $logs = tail_file($referer_log_filename, $number_of_lines); } $log = array(); $counter = 10; // XXX $count = 0; foreach ($logs as $line) { list(, $pagename, ) = explode("\t", $line); if (strcmp($pagename, $needle) == 0) { $log[] = $line; } if ($count > $counter) { break; } $count++; } $logs = $log; $tz_offset = $formatter->tz_offset; $length = sizeof($logs); for ($c = 0; $c < $length; $c++) { $fields = explode("\t", $logs[$c]); $fields[0] = date("Y-m-d H:i:s", strtotime($fields[0]) + $tz_offset); $fields[1] = $formatter->link_tag(_rawurlencode($fields[1]), "", urldecode($fields[1])); $found = ''; if (ereg("[?&][pqQ](uery)?=([^&]+)&?", $fields[2], $regs)) { $check = strpos($regs[2], '%'); # is it urlecnoded ? if ($check !== false) { $found = urldecode($regs[2]); if (function_exists('iconv')) { $test = false; if (strcasecmp('utf-8', $DBInfo->charset) != 0) { $test = iconv('utf-8', $DBInfo->charset, $found); if ($test !== false) { $found = $test; } } if ($test === false and !empty($DBInfo->url_encodings)) { $cs = explode(',', $DBInfo->url_encodings); foreach ($cs as $c) { $test = @iconv($c, $DBInfo->charset, $found); if ($test !== false) { $found = $test; break; } } } } } else { $found = $regs[2]; } } $fields[2] = (!empty($found) ? "[ {$found} ] " : '') . "<a href='{$fields['2']}'>" . urldecode($fields[2]) . "</a>"; if (isset($needle)) { unset($fields[1]); } $logs[$c] = "<td class='date' style='width:20%'>" . implode("</td><td>", $fields) . "<td>"; } $ret = ''; if ($length > 0) { $ret = "\n<table>"; $ret .= "<caption>" . _("Referer history") . "</caption>"; $ret .= "<tr>"; $ret .= implode("</tr>\n<tr>", $logs); $ret .= "</tr></table>\n"; } return '<div class="Referer">' . $ret . '</div>'; }
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 .= '&date=1'; } if ($options['info']) { $extra .= '&info=1'; } if (isset($needle[0])) { $extra .= '&value=' . $needle; } $qoff = '&offset=' . ($ret['offset'] + $count); $out .= $formatter->link_to("?action=pagelist{$extra}{$qoff}", _("Show next page")); } } } } return $out; }
function macro_Rss($formatter, $value) { global $DBInfo; $xml_parser = xml_parser_create(); $rss_parser = new WikiRSSParser(); xml_set_object($xml_parser, $rss_parser); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); $key = _rawurlencode($value); $cache = new Cache_text("rss"); # reflash rss each 7200 second (60*60*2) if (!$cache->exists($key) or time() > $cache->mtime($key) + 7200) { $fp = @fopen("{$value}", "r"); if (!$fp) { return "[[RSS(ERR: not a valid URL! {$value})]]"; } while ($data = fread($fp, 4096)) { $xml_data .= $data; } fclose($fp); $cache->update($key, $xml_data); } else { $xml_data = $cache->fetch($key); } list($line, $dummy) = explode("\n", $xml_data, 2); preg_match("/\\sencoding=?(\"|')([^'\"]+)/", $line, $match); if ($match) { $charset = strtoupper($match[2]); } else { $charset = 'UTF-8'; } # override $charset for php5 if ((int) phpversion() >= 5) { $charset = 'UTF-8'; } ob_start(); $ret = xml_parse($xml_parser, $xml_data); if (!$ret) { return sprintf("[[RSS(XML error: %s at line %d)]]", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)); } $out = ob_get_contents(); ob_end_clean(); xml_parser_free($xml_parser); # if (strtolower(str_replace("-","",$options['oe'])) == 'euckr') if (function_exists('iconv') and strtoupper($DBInfo->charset) != $charset) { $new = iconv($charset, $DBInfo->charset, $out); if ($new !== false) { return $new; } } return $out; }
function do_atom($formatter, $options) { global $DBInfo; global $_release; define('ATOM_DEFAULT_DAYS', 7); $days = $DBInfo->rc_days ? $DBInfo->rc_days : ATOM_DEFAULT_DAYS; $options['quick'] = 1; if ($options['c']) { $options['items'] = $options['c']; } $lines = $DBInfo->editlog_raw_lines($days, $options); $time_current = time(); # $secs_per_day= 60*60*24; # $days_to_show= 30; # $time_cutoff= $time_current - ($days_to_show * $secs_per_day); $URL = qualifiedURL($formatter->prefix); $img_url = qualifiedURL($DBInfo->logo_img); $url = qualifiedUrl($formatter->link_url($DBInfo->frontpage)); $surl = qualifiedUrl($formatter->link_url($options['page'] . '?action=atom')); $channel = <<<CHANNEL <title>{$DBInfo->sitename}</title> <link href="{$url}"></link> <link rel="self" type="application/atom+xml" href="{$surl}" /> <subtitle>RecentChanges at {$DBInfo->sitename}</subtitle> <generator version="{$_release}">MoniWiki Atom feeder</generator> CHANNEL; $items = ""; $ratchet_day = FALSE; if (!$lines) { $lines = array(); } foreach ($lines as $line) { $parts = explode("\t", $line); $page_name = $DBInfo->keyToPagename($parts[0]); $addr = $parts[1]; $ed_time = $parts[2]; $user = $parts[4]; $user_uri = ''; if ($DBInfo->hasPage($user)) { $user_uri = $formatter->link_url(_rawurlencode($user), "", $user); $user_uri = '<uri>' . $user_uri . '</uri>'; } $log = _stripslashes($parts[5]); $act = rtrim($parts[6]); $url = qualifiedUrl($formatter->link_url(_rawurlencode($page_name))); $diff_url = qualifiedUrl($formatter->link_url(_rawurlencode($page_name), '?action=diff')); $extra = "<br /><a href='{$diff_url}'>" . _("show changes") . "</a>\n"; $content = ''; if (!$DBInfo->hasPage($page_name)) { $status = 'deleted'; $content = "<content type='html'><a href='{$url}'>{$page_name}</a> is deleted</content>\n"; } else { $status = 'updated'; if ($options['diffs']) { $p = new WikiPage($page_name); $f = new Formatter($p); $options['raw'] = 1; $options['nomsg'] = 1; $html = $f->macro_repl('Diff', '', $options); if (!$html) { ob_start(); $f->send_page('', array('fixpath' => 1)); #$f->send_page(''); $html = ob_get_contents(); ob_end_clean(); $extra = ''; } $content = " <content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>{$html}</content>\n"; } else { if ($log) { $html = str_replace('&', '&', $log); $content = "<content type='text'>" . $html . "</content>\n"; } else { $content = "<content type='text'>updated</content>\n"; } } } $zone = '+00:00'; $date = gmdate("Y-m-d\\TH:i:s", $ed_time) . $zone; if (!isset($updated)) { $updated = $date; } #$datetag = gmdate("YmdHis",$ed_time); $valid_page_name = str_replace('&', '&', $page_name); $items .= "<entry>\n"; $items .= " <title>{$valid_page_name}</title>\n"; $items .= " <link href='{$url}'></link>\n"; $items .= ' ' . $content; $items .= " <author><name>{$user}</name>{$user_uri}</author>\n"; $items .= " <updated>{$date}</updated>\n"; $items .= " <contributor><name>{$user}</name>{$user_uri}</contributor>\n"; $items .= "</entry>\n"; } $updated = " <updated>{$updated}</updated>\n"; $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}"?> <!--<?xml-stylesheet href="{$DBInfo->url_prefix}/css/_feed.css" type="text/css"?>--> <feed xmlns="http://www.w3.org/2005/Atom"> <!-- Add "diffs=1" to add change diffs to the description of each items. Add "oe=utf-8" to convert the charset of this rss to UTF-8. --> HEAD; header("Content-Type: application/xml"); if ($new) { print $head . $new; } else { print $head . $channel . $updated . $items . $form; } print "</feed>\n"; }
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 . '&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&mode=edit&no=" . $nid, '<span>' . _("Edit") . '</span>', 'class="button"'); $btn['delete'] = $formatter->link_tag($bpage, "?action=bbs&mode=delete&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") . '»') . "</td>\n</tr>\n"; $simple .= "</table>"; return $simple; } } if ($pages > 1) { $pnut = _get_pagelist($formatter, $pages, '?' . $extra . ($extra ? '&p=' : 'p='), $options['p'], $ncount); } else { $pnut = "<div class='clear'></div>"; } $extra = $options['p'] ? '&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>»</strong>':$nid,$chk,$subject,$user,$date,$hit); $item[] = array('num' => in_array($nid, $nids) ? '<strong>»</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&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&mode=rss', $formatter->icon['rss']) . '</div>'; return $info . $pnut . $msg . $js . $form0 . $out . $del . $form1 . $pnut . $btns; }
function macro_UploadedFiles($formatter, $value = "", $options = "") { global $DBInfo; $use_preview = $DBInfo->use_preview_uploads ? $DBInfo->use_preview_uploads : 0; $preview_width = 64; #$use_preview=0; $use_admin = 1; $use_fileinfo = 1; $js_tag = 0; $js_script = ''; $uploader = ''; // get user id if (empty($formatter->preview) && empty($options)) { $options = array(); $options['id'] = $DBInfo->user->id; } if (isset($DBInfo->members) and !in_array($options['id'], $DBInfo->members)) { $use_admin = 0; } $iconset = 'gnome'; $icon_dir = $DBInfo->imgs_dir . '/plugin/UploadedFiles/' . $iconset; $args = !empty($DBInfo->uploadedfiles_options) ? explode(',', $DBInfo->uploadedfiles_options) : array(); $nargs = explode(',', $value); if (!empty($nargs)) { $args = array_merge($args, $nargs); } $value = ''; $default_column = 8; $col = (!empty($options['col']) and $options['col'] > 0) ? (int) $options['col'] : $default_column; if (!empty($formatter->preview)) { $js_tag = 1; $use_preview = 1; $uploader = 'UploadForm'; $use_admin = 0; $use_fileinfo = 0; $col = 10000; } else { if (!empty($options['preview'])) { $use_preview = 1; $use_admin = 0; $use_fileinfo = 0; } } if (!empty($options['tag'])) { # javascript tag mode $js_tag = 1; $use_preview = 1; $use_admin = 0; $use_fileinfo = 0; $col = 10000; } if ($use_fileinfo) { $col = 1; } $href_attr = ''; $attr = ''; if (!empty($DBInfo->use_lightbox) and !$js_tag) { $href_attr = ' rel="lightbox[upload]" '; } $nodir = 0; foreach ($args as $arg) { $arg = trim($arg); if (($p = strpos($arg, '=')) !== false) { $k = substr($arg, 0, $p); $v = substr($arg, $p + 1); if ($k == 'preview') { $use_preview = $v; } else { if ($k == 'nodir') { $nodir = $v; } else { if ($k == 'tag') { $js_tag = 1; $use_preview = 1; } } } } else { $value = $arg; } } if (!isset($options['nodir'])) { $options['nodir'] = $nodir; } if (!empty($options['page'])) { $value = $options['page']; } // avoid to set the pagename of the "page,name" as "name" if ($js_tag) { $form = 'editform'; $js_script = <<<EOS <script language="javascript" type="text/javascript"> /*<![CDATA[*/ // based on wikibits.js in the MediaWiki // small fix to use opener in the dokuwiki. function insertTags(tagOpen,tagClose,myText,replaced) { var is_ie = document.selection && document.all; if (document.{$form}) { var txtarea = document.{$form}.savetext; } else { // some alternate form? take the first one we can find var areas = document.getElementsByTagName('textarea'); if (areas.length > 0) { var txtarea = areas[0]; } else if (opener) { // WikiWyg support if (opener.document.{$form} && opener.document.{$form}.savetext) { txtarea = opener.document.{$form}.savetext; } else { txtarea = opener.document.getElementsByTagName('textarea')[0]; } var my=opener.document.getElementById('editor_area'); while (my == null || my.style.display == 'none') { // wikiwyg hack txtarea = opener.document.getElementById('wikiwyg_wikitext_textarea'); // get iframe and check visibility. var myframe = opener.document.getElementsByTagName('iframe')[0]; if (myframe.style.display == 'none' || myframe.parentNode.style.display == 'none') break; var postdata = 'action=markup/ajax&value=' + encodeURIComponent(tagOpen + myText + tagClose); var myhtml=''; myhtml= HTTPPost(self.location, postdata); var mnew = myhtml.replace(/^<div>/i,''); // strip div tag mnew = mnew.replace(/<\\/div>\\s*\$/i,''); // strip div tag if (is_ie) { var range = myframe.contentWindow.document.selection.createRange(); if (range.boundingTop == 2 && range.boundingLeft == 2) return; range.pasteHTML(html); range.collapse(false); range.select(); } else { myframe.contentWindow.document.execCommand('inserthtml', false, mnew + ' '); } return; } } else { return; // XXX } } if(is_ie) { var theSelection = document.selection.createRange().text; txtarea.focus(); if(theSelection.charAt(theSelection.length - 1) == " "){ // exclude ending space char, if any theSelection = theSelection.substring(0, theSelection.length - 1); document.selection.createRange().text = theSelection + tagOpen + myText + tagClose + " "; } else { document.selection.createRange().text = theSelection + tagOpen + myText + tagClose + " "; } } // Mozilla else if(txtarea.selectionStart || txtarea.selectionStart == '0') { \t\t//var replaced = false; \t\tvar startPos = txtarea.selectionStart; \t\tvar endPos = txtarea.selectionEnd; \t\tif (!replaced && endPos-startPos) \t\t\treplaced = true; \t\tvar scrollTop = txtarea.scrollTop; \t\tif (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any \t\t\tsubst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " "; \t\t} else { \t\t\tsubst = tagOpen + myText + tagClose; \t\t} \t\ttxtarea.value = txtarea.value.substring(0, startPos) + subst + \t\t\ttxtarea.value.substring(endPos, txtarea.value.length); \t\ttxtarea.focus(); \t\t//set new selection \t\tif (replaced) { \t\t\tvar cPos = startPos+(tagOpen.length+myText.length+tagClose.length); \t\t\ttxtarea.selectionStart = cPos; \t\t\ttxtarea.selectionEnd = cPos; \t\t} else { \t\t\ttxtarea.selectionStart = startPos+tagOpen.length; \t\t\ttxtarea.selectionEnd = startPos+tagOpen.length+myText.length; \t\t}\t \t\ttxtarea.scrollTop = scrollTop; } else { // All others txtarea.value += tagOpen + myText + tagClose + " "; txtarea.focus(); } } /*]]>*/ </script> EOS; } if (!empty($DBInfo->download_action)) { $mydownload = $DBInfo->download_action; } else { $mydownload = 'download'; } $checkbox = 'checkbox'; $needle = "//"; if (!empty($options['download']) || !empty($DBInfo->force_download)) { $force_download = 1; if (!empty($options['download'])) { $mydownload = $options['download']; } } if (!empty($options['needle'])) { $needle = '@' . $options['needle'] . '@i'; } if (!empty($options['checkbox'])) { $checkbox = $options['checkbox']; } if (!in_array('UploadFile', $formatter->actions)) { $formatter->actions[] = 'UploadFile'; } if ($value and $value != 'UploadFile') { $key = $DBInfo->pageToKeyname($value); //if ($force_download or $key != $value) $down_prefix = $formatter->link_url(_rawurlencode($value), "?action={$mydownload}&value="); $dir = $DBInfo->upload_dir . "/{$key}"; } else { $value = $formatter->page->urlname; $key = $DBInfo->pageToKeyname($formatter->page->name); //if ($force_download or $key != $formatter->page->name) $down_prefix = $formatter->link_url($formatter->page->urlname, "?action={$mydownload}&value="); $dir = $DBInfo->upload_dir . "/{$key}"; } // support hashed upload_dir if (!is_dir($dir) and !empty($DBInfo->use_hashed_upload_dir)) { $dir = $DBInfo->upload_dir . '/' . get_hashed_prefix($key) . $key; } if (!empty($force_download) or $key != $value) { $prefix = $down_prefix; } if (!empty($formatter->preview) and $formatter->page->name == $value) { $opener = ''; } else { $opener = $value . ':'; } if ($value != 'UploadFile' and file_exists($dir)) { $handle = opendir($dir); } else { $key = ''; $value = 'UploadFile'; if (!$force_download) { $prefix .= $prefix ? '/' : ''; } $dir = $DBInfo->upload_dir; $handle = opendir($dir); $opener = '/'; } $upfiles = array(); $dirs = array(); $per = !empty($DBInfo->uploadedfiles_per_page) ? $DBInfo->uploadedfiles_per_page : 100; // set nodir option to show only files if (!empty($options['needle']) && !isset($options['nodir'])) { $options['nodir'] = true; } else { if (!isset($options['nodir'])) { $options['nodir'] = false; } } // count files/dirs $count_files = 0; $count_dirs = 0; $uf = new Cache_text('settings'); if (($info = $uf->fetch('uploadedfiles')) !== false) { $count_files = $info['files']; $count_dirs = $info['dirs']; } else { while (($file = readdir($handle)) !== false) { if ($file[0] == '.') { continue; } if (is_dir($dir . "/" . $file)) { $count_dirs++; } else { $count_files++; } } rewinddir($handle); // TTL = 1 day $uf->update('uploadedfiles', array('files' => $count_files, 'dirs' => $count_dirs), 60 * 60 * 24); } // XXX $plink = ''; if (!empty($options['p'])) { $p = $options['p'] ? (int) $options['p'] : 1; } else { $p = 1; } $pfrom = ($p - 1) * $per; $pto = $pfrom + $per; $count = 0; while (($file = readdir($handle)) !== false) { if ($file[0] == '.') { continue; } if ($count >= $pfrom) { if (is_dir($dir . "/" . $file)) { if ($options['nodir']) { continue; } if ($value == 'UploadFile') { $dirs[] = $DBInfo->keyToPagename($file); } } else { if (preg_match($needle, $file) and $count >= $pfrom) { if ($count < $pto) { $upfiles[] = _p_filename($file); } } } } $count++; if ($count >= $pto) { $plink = 1; break; } } closedir($handle); if (!$upfiles and !$dirs) { return "<h3>" . _("No files found") . "</h3>"; } sort($upfiles); sort($dirs); $link = $formatter->link_url($formatter->page->urlname); $out = "<form method='post' action='{$link}'>"; $out .= "<p><input type='hidden' name='action' value='DeleteFile' />\n"; if ($key) { $out .= "<input type='hidden' name='value' value=\"{$value}\" />\n"; } $out .= "</p><table style='border:0px' cellpadding='2' class='info'>\n"; // set colspan to show file informations $c = 1; if ($use_admin) { $c = 2; } if ($c) { $colspan = ' colspan="' . $c . '"'; } if ($use_fileinfo) { $mname = _("File name"); $msize = _("Size"); $mdate = _("Date"); $out .= "<tr><th{$colspan}>{$mname}</th><th>{$msize}</th><th>{$mdate}</th></tr>\n"; $c += 2; } // set colspan again if ($c > 1) { $colspan = ' colspan="' . $c . '"'; } $idx = 1; if ($js_tag) { #$attr=' target="_blank"'; $extra = '&popup=1&tag=1'; } else { $attr = ''; $extra = ''; } // support hashed upload_dir if (!empty($DBInfo->use_hashed_upload_dir)) { $ndirs = array(); foreach ($dirs as $d0) { if (strlen($d0) != 1) { $ndirs[] = $d0; continue; } $handle = opendir($DBInfo->upload_dir . '/' . $d0); if (!is_resource($handle)) { continue; } $pre = $DBInfo->upload_dir . '/' . $d0; while (($d = readdir($handle)) !== false) { if (!is_dir($pre . '/' . $d)) { $ndirs[] = $d0; break; } if ($d[0] == $d0[0]) { $hd = opendir($pre . '/' . $d); if (!is_resource($hd)) { continue; } $pre1 = $pre . '/' . $d; while (($d1 = readdir($hd)) !== false) { if ($d1[0] == '.') { continue; } if (is_dir($pre1 . '/' . $d1)) { $ndirs[] = $d1; } } closedir($hd); } } closedir($handle); } $dirs = $ndirs; sort($dirs); } // count dirs $didx = 0; if (count($dirs)) { $out .= "<tr>"; $didx++; } foreach ($dirs as $file) { $link = $formatter->link_url($file, "?action=uploadedfiles{$extra}", $file, $attr); $key = $DBInfo->pageToKeyname($file); // support hashed upload_dir $pre = ''; if (!empty($DBInfo->use_hashed_upload_dir)) { $pre = get_hashed_prefix($key); if (!is_dir($dir . '/' . $pre . $key)) { $pre = ''; } } $dirname = $dir . '/' . $pre . $key; $date = date("Y-m-d", filemtime($dirname)); $file = _html_escape($file); if ($use_admin) { $out .= "<td class='wiki'><input type='{$checkbox}' name='files[{$idx}]' value=\"{$file}\" /></td>"; } $out .= "<td class='wiki'><a href='{$link}'>{$file}/</a></td>"; if ($use_fileinfo) { $out .= "<td align='right' class='wiki'> </td><td class='wiki'>{$date}</td>"; } if ($didx % $col == 0) { $out .= "</tr>\n<tr>\n"; } $idx++; $didx++; } if (isset($value[0]) and $value != 'UploadFile') { if ($js_tag) { #$attr=' target="_blank"'; $extra = '&popup=1&tag=1'; } if (!empty($options['needle'])) { $extra .= '&q=' . $options['needle']; } $link = $formatter->link_tag('UploadFile', "?action=uploadedfiles&value=top{$extra}", "<img src='" . $icon_dir . "/32/up.png' style='border:0' class='upper' alt='..' />", $attr); $out .= "<tr>"; if ($use_admin) { $out .= "<td class='wiki'> </td>"; } $out .= "<td class='wiki'>{$link}</td>"; if ($use_fileinfo) { $date = date("Y-m-d", filemtime($dir . "/..")); $out .= "<td align='right' class='wiki'> </td><td class='wiki'>{$date}</td>"; } if ($didx % $col == 0) { $out .= "</tr>\n<tr>\n"; } $didx++; } if (!empty($options['needle'])) { $extra .= '&q=' . $options['needle']; } if (isset($options['nodir'])) { $extra .= '&nodir=' . $options['nodir']; } if ($plink) { $plink = $formatter->link_tag('', "?action=uploadedfiles{$extra}&p=" . ($p + 1), _("Next page »"), $attr); } else { if ($p > 1) { $plink = $formatter->link_tag('', "?action=uploadedfiles{$extra}", _("« First page"), $attr); } } if (empty($prefix)) { $prefix = str_replace($DBInfo->upload_dir, $DBInfo->upload_dir_url, $dir) . '/'; } $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB'); $down_mode = strpos($prefix, ';value=') !== false; $mywidth = $preview_width; if (empty($didx)) { // no dirs found. $out .= '<tr>'; } $iidx = $didx; // file index foreach ($upfiles as $file) { $_l_file = _l_filename($file); // force download with some extensions. XXX if ($down_mode or preg_match('/\\.(pl|cgi|py|php.?)$/', $file)) { $link = str_replace(";value=", ";value=" . rawurlencode($file), $down_prefix); } else { $link = $prefix . rawurlencode($file); } // XXX $previewlink = $link; $size = filesize($dir . '/' . $_l_file); if (!empty($use_preview)) { preg_match("/\\.(.{1,4})\$/", $file, $m); $ext = isset($m[1]) ? strtolower($m[1]) : ''; if ($use_preview > 1 and $ext and stristr('gif,png,jpeg,jpg', $ext)) { list($w, $h) = getimagesize($dir . '/' . $file); if ($w <= $preview_width) { $mywidth = $w; } else { $mywidth = $preview_width; } if (file_exists($dir . "/thumbnails/" . $_l_file)) { if ($down_mode) { $previewlink = str_replace('value=', 'value=thumbnails/', $previewlink); } else { $previewlink = $prefix . 'thumbnails/' . rawurlencode($file); } } } } if (!empty($use_fileinfo)) { $i = 0; for (; $i < 4; $i++) { if ($size <= 1024) { #$size= round($size,2).' '.$unit[$i]; break; } $size = $size / 1024; } $size = round($size, 2) . ' ' . $unit[$i]; } $date = date('Y-m-d', filemtime($dir . '/' . $_l_file)); $fname = $file; if ($use_preview or $js_tag) { $tag_open = 'attachment:'; $tag_close = ''; if ($opener != $value) { $tag_open .= $opener; } $alt = "alt='{$tag_open}{$file}{$tag_close}' title='{$file}'"; if ($ext and stristr('gif,png,jpeg,jpg', $ext)) { $fname = "<img src='{$previewlink}' class='icon' width='{$mywidth}' {$alt} />"; $attr .= $href_attr; } else { if (preg_match('/^(wmv|avi|mpeg|mpg|swf|wav|mp3|ogg|midi|mid|mov)$/', $ext)) { $tag_open = '[[Media('; $tag_close = ')]]'; $alt = "{$tag_open}{$file}{$tag_close}"; } else { if (!preg_match('/^(bmp|c|h|java|py|bak|diff|doc|css|php|xml|html|mod|' . 'rpm|deb|pdf|ppt|xls|tgz|gz|bz2|zip)$/', $ext)) { $ext = 'unknown'; } } $fname = "<img src='{$icon_dir}/{$ext}.png' class='icon' {$alt} /><span>{$file}</span>"; } if ($js_tag) { //if (strpos($file,' ')) $tag = "insertTags('{$tag_open}','{$tag_close}','{$file}',true)"; $link = "javascript:{$tag}"; } } $file = _html_escape($file); if ($use_admin) { $out .= "<td class='wiki'><input type='{$checkbox}' name='files[{$idx}]' value=\"{$file}\" /></td>"; } $out .= "<td class='wiki'><a href=\"{$link}\"{$attr}>{$fname}</a></td>"; if ($use_fileinfo) { $out .= "<td align='right' class='wiki'>{$size}</td><td class='wiki'>{$date}</td>"; } if ($iidx % $col == 0) { $out .= "</tr>\n<tr>\n"; } if ($use_admin && $use_fileinfo) { $out .= "<td> </td><td{$colspan}>"; if ($use_admin) { $out .= $dir . '/'; } $out .= "{$file}</td>\n"; $out .= "</tr>\n<tr>"; } $idx++; $iidx++; } $kidx = $iidx - 1; $k = 0; // setup colspan to fill up <tr> with colspaned <td> while ($kidx % $col != 0) { $k += $c; $kidx++; } if ($k > 0) { // fill tr $out .= '<td colspan="' . $k . '"> </td>'; } if (substr($out, -4) == '<tr>') { $out = substr($out, 0, -4); } else { $out .= "</tr>\n"; } $idx--; $msg = sprintf(_("%d files"), $idx); if (count($dirs)) { $msg .= ' / ' . sprintf(_("Total %d files"), $count_files); $msg .= ' / ' . sprintf(_("%d dirs"), $count_dirs); } // colspan for multi column case. if ($col > 1) { $colspan = ' colspan="' . $col * $c . '"'; } $out .= "<tr>"; if ($use_admin && $c > 1) { $out .= "<td> </td>"; } // fill checkbox column $out .= "<th {$colspan}>{$msg}</th></tr>\n"; if ($plink) { $out .= "<tr><th {$colspan}>{$plink}</th></tr>\n"; } $out .= "</table>\n"; if ($use_admin) { if ($DBInfo->security->is_protected("deletefile", $options)) { $out .= '<p>' . _("Password") . ": <input type='password' name='passwd' size='10' /></p>\n"; } $out .= "<p><input type='submit' value='" . _("Delete selected files") . "' /></p>"; } $out .= "</form>\n"; if (!$value and !in_array('UploadFile', $formatter->actions)) { $formatter->actions[] = 'UploadFile'; } if ($uploader and !in_array('UploadedFiles', $formatter->actions)) { $out .= $formatter->macro_repl($uploader); } if ($use_preview) { $class = ' class="fileList preview"'; return $js_script . "<div{$class}>" . $out . "</div>\n"; } return $js_script . $out; }
function macro_RecentChanges($formatter, $value = '', $options = '') { global $DBInfo, $Config; // get members to hide log $members = $DBInfo->members; $checknew = 1; $checkchange = 0; $template_bra = ""; $template = '"$icon $title$updated $date . . . . $user $count$diff $extra<br />\\n"'; $template_cat = ""; $use_day = 1; $users = array(); $target = ''; if (!empty($options['target'])) { $target = "target='{$options['target']}'"; } $bookmark_action = empty($options['bookmark_action']) ? '?action=bookmark' : '?action=' . $options['bookmark_action']; // $date_fmt='D d M Y'; $date_fmt = $DBInfo->date_fmt_rc; $days = !empty($DBInfo->rc_days) ? $DBInfo->rc_days : RC_DEFAULT_DAYS; $perma_icon = $formatter->perma_icon; $changed_time_fmt = $DBInfo->changed_time_fmt; $args = explode(',', $value); // first arg assumed to be a date fmt arg if (preg_match("/^[\\s\\/\\-:aABdDFgGhHiIjmMOrSTY\\[\\]]+\$/", $args[0])) { $my_date_fmt = $args[0]; } $strimwidth = isset($DBInfo->rc_strimwidth) ? $DBInfo->rc_strimwidth : 20; // use javascript $use_js = 0; // show last edit entry only $last_entry_only = 1; $last_entry_check = 60 * 60 * 24; // show last editor only $last_editor_only = 1; // show editrange like as MoinMoin $use_editrange = 0; // avatar $use_avatar = 0; $avatar_type = 'identicon'; if (!empty($DBInfo->use_avatar)) { $use_avatar = 1; if (is_string($DBInfo->use_avatar)) { $avatar_type = $DBInfo->use_avatar; } } // RC cache delay // $rc_cache_delay <= $rc_delay $cache_delay = isset($DBInfo->rc_cache_delay) ? $DBInfo->rc_cache_delay : 0; $avatarlink = $formatter->link_url('', '?action=' . $avatar_type . '&seed='); $ipicon = '<img src="' . $DBInfo->imgs_dir . '/misc/ip.png" />'; $trash = 0; $rctype = ''; $opts = array(); $bra = ''; $cat = ''; $cat0 = ''; $rctitle = "<h2>" . _("Recent Changes") . "</h2>"; foreach ($args as $arg) { $arg = trim($arg); if (($p = strpos($arg, '=')) !== false) { $k = trim(substr($arg, 0, $p)); $v = trim(substr($arg, $p + 1)); if ($k == 'item' or $k == 'items') { $opts['items'] = min((int) $v, RC_MAX_ITEMS); } else { if ($k == 'days') { $days = min(abs($v), RC_MAX_DAYS); } else { if ($k == "datefmt") { $my_date_fmt = $v; } else { if ($k == 'ago') { if (is_numeric($v) and $v == abs($v)) { $opts['ago'] = abs($v); } else { $opts['from'] = $v; } } else { if ($k == "new") { $checknew = $v; } else { if ($k == "delay") { $cache_delay = intval($v); } else { if ($k == 'strimwidth' and is_numeric($v) and (abs($v) > 15 or $v == 0)) { $strimwidth = abs($v); } } } } } } } } else { if ($arg == "quick") { $opts['quick'] = 1; } else { if ($arg == "nonew") { $checknew = 0; } else { if ($arg == "change") { $checkchange = 1; } else { if ($arg == "showhost") { $showhost = 1; } else { if ($arg == "comment") { $comment = 1; } else { if ($arg == "comments") { $comment = 1; } else { if ($arg == "nobookmark") { $nobookmark = 1; } else { if ($arg == "noperma") { $perma_icon = ''; } else { if ($arg == "button") { $button = 1; } else { if ($arg == "timesago") { $timesago = 1; } else { if ($arg == "notitle") { $rctitle = ''; } else { if ($arg == "hits") { $use_hits = 1; } else { if ($arg == "daysago") { $use_daysago = 1; } else { if ($arg == "trash") { $trash = 1; } else { if ($arg == "editrange") { $use_editrange = 1; } else { if ($arg == "allauthors") { $last_editor_only = 0; } else { if ($arg == "allusers") { $last_editor_only = 0; } else { if ($arg == "allentries") { $last_entry_only = 0; } else { if ($arg == "avatar") { $use_avatar = 1; } else { if ($arg == "noavatar") { $use_avatar = 0; } else { if ($arg == "js") { $use_js = 1; } else { if ($arg == "diffwidth") { $use_diffwidth = 1; } else { if (in_array($arg, array('simple', 'moztab', 'board', 'table', 'list'))) { $rctype = $arg; } } } } } } } } } } } } } } } } } } } } } } } } } ksort($opts); if (!empty($nobookmark)) { $use_js = 0; } // set as dynamic macro or not. if ($formatter->_macrocache and empty($options['call']) and empty($use_js) || $rctype != 'list') { return $formatter->macro_cache_repl('RecentChanges', $value); } if (empty($options['call'])) { $formatter->_dynamic_macros['@RecentChanges'] = 1; } if (empty($DBInfo->interwiki)) { $formatter->macro_repl('InterWiki', '', array('init' => 1)); } // reset some conflict params if (empty($DBInfo->use_counter)) { $use_hits = 0; } if (empty($DBInfo->show_hosts)) { $showhost = 0; } if (!empty($rctype)) { if ($rctype == "simple") { $checkchange = 0; $use_day = 0; if ($showhost) { $template = '"$icon $title @ $day $date by $user $count $extra<br />\\n"'; } else { $template = '"$icon $title @ $day $date $count $extra<br />\\n"'; } } else { if ($rctype == "list") { $rctitle = ''; $changed_time_fmt = !empty($my_date_fmt) ? $my_date_fmt : '[H:i]'; $checkchange = 0; $use_day = 0; $template = '"<li>$date $title</li>\\n"'; $template_bra = "<ul>\n"; $template_cat = "</ul>\n"; } else { if ($rctype == "moztab") { $use_day = 1; $template = '"<li>$title $date</li>\\n"'; } else { if ($rctype == "table") { $bra = "<table border='0' cellpadding='0' cellspacing='0' width='100%'>"; $template = '"<tr><td style=\'white-space:nowrap;width:2%\'>$icon</td><td style=\'width:40%\'>$title$updated</td><td class=\'date\' style=\'width:15%\'>$date</td><td>$user $count$diff $extra</td></tr>\\n"'; $cat = "</table>"; $cat0 = ""; } else { if ($rctype == "board") { $changed_time_fmt = !empty($my_date_fmt) ? $my_date_fmt : 'm-d [H:i]'; $use_day = 0; $template_bra = "<table border='0' cellpadding='0' cellspacing='0' width='100%'>"; if (empty($nobookmark)) { $cols = 3; } else { $cols = 2; } $template_bra .= "<thead><tr><th colspan='{$cols}' class='title'>" . _("Title") . "</th>"; if (!empty($showhost)) { $template_bra .= "<th class='author'>" . _("Editor") . '</th>'; } $template_bra .= "<th class='editinfo'>" . _("Changes") . '</th>'; if (!empty($use_hits)) { $template_bra .= "<th class='hits'>" . _("Hits") . "</th>"; } $template_bra .= "<th class='date'>" . _("Change Date") . '</th>'; $template_bra .= "</tr></thead>\n<tbody>\n"; $template = '"<tr$alt><td style=\'white-space:nowrap;width:2%\'>$icon</td><td class=\'title\' style=\'width:40%\'>$title$updated</td>'; if (empty($nobookmark)) { $template .= '<td>$bmark</td>'; } if (!empty($showhost)) { $template .= '<td class=\'author\'>$user</td>'; } $template .= '<td class=\'editinfo\'>$count'; if (!empty($checkchange) or !empty($checknew)) { $template .= ' $diff'; } $template .= '</td>'; if (!empty($use_hits)) { $template .= '<td class=\'hits\'>$hits</td>'; } $template .= '<td class=\'date\'>$date</td>'; $template_extra = $template . '</tr>\\n<tr class=\'log\'$style><td colspan=\'6\'><div>$extra</div></td></tr>\\n"'; $template .= '</tr>\\n"'; $template_cat = "</tbody></table>"; $cat0 = ""; } } } } } } // override days $days = !empty($_GET['days']) ? min(abs($_GET['days']), RC_MAX_DAYS) : $days; // override ago empty($opts['ago']) ? $opts['ago'] = 0 : null; if (!empty($_GET['ago']) and is_numeric($_GET['ago'])) { $opts['ago'] = abs($_GET['ago']); } else { $opts['from'] = $_GET['ago']; } // override times // accept both 'item' or 'items' $tmp = isset($_GET['item']) ? $_GET['item'] : (isset($_GET['items']) ? $_GET['items'] : null); !empty($tmp) ? $opts['items'] = min(abs($tmp), RC_MAX_ITEMS) : null; unset($tmp); // daysago $daysago = '&days=' . $days; $daysago = $opts['ago'] ? $daysago . '&ago=' . $opts['ago'] : $daysago; $u = $DBInfo->user; # retrive user info // check member $ismember = $u->is_member; // use uniq avatar ? $uniq_avatar = 0; if (!empty($DBInfo->use_uniq_avatar)) { $uniq_avatar = $DBInfo->use_uniq_avatar; } if ($ismember) { $uniq_avatar = 'Y'; } // change avatar after year :> if ($u->id != 'Anonymous') { $bookmark = !empty($u->info['bookmark']) ? $u->info['bookmark'] : ''; } else { $bookmark = $u->bookmark; } $tz_offset = $formatter->tz_offset; if (!$bookmark or !empty($nobookmark)) { if (!empty($checknew) and preg_match('/^\\d+(\\s*\\*\\s*\\d+)*$/', $checknew)) { $checknew = eval('return ' . $checknew . ';'); } if ($checknew > 1) { $bookmark = strtotime(date('Y-m-d', time() - $checknew) . ' 00:00:00'); } } if (!$bookmark) { $bookmark = time(); } // set search query if (isset($_GET['q'][0])) { $query = _preg_search_escape(trim($_GET['q'])); if (@preg_match('/' . $query . '/', '') === false) { unset($query); } } // make rclog uniq key $locals = get_defined_vars(); unset($locals['bookmark']); unset($locals['formatter']); unset($locals['options']); unset($locals['DBInfo']); unset($locals['Config']); unset($locals['args']); unset($locals['arg']); unset($locals['u']); unset($locals['k']); unset($locals['v']); unset($locals['p']); unset($locals['value']); unset($locals['tz_offset']); unset($locals['members']); $rckey = md5(serialize($locals)); $rckey2 = $rckey; $rclog = '<!-- rckey = ' . $rckey . ', cache delay = ' . $cache_delay . ' -->'; if ($use_js) { unset($locals['use_js']); $rckey2 = md5(serialize($locals)); // rckey without js option } unset($locals); // check RC cache $lc = new Cache_text('rccache'); $mtime = $lc->mtime($rckey); if (empty($formatter->refresh)) { if (($val = $lc->fetch($rckey)) !== false and $DBInfo->checkUpdated($mtime, $cache_delay)) { return $val . '<!-- cached at ' . date('Y-m-d H:i:s', $mtime) . ' -->'; } else { if (!empty($options['ajax']) && $rctype == 'list' && $rckey != $rckey2) { // rctype == list with ajax option does not depend on "use_js" option. $mtime = $lc->mtime($rckey2); if (($val = $lc->fetch($rckey2)) !== false and $DBInfo->checkUpdated($mtime, $cache_delay)) { return $val . '<!-- cached at ' . date('Y-m-d H:i:s', $mtime) . ' -->'; } } } // need to update cache if ($val !== false and $lc->exists($rckey . '.lock')) { return $val . '<!-- cached at ' . date('Y-m-d H:i:s', $mtime) . ' -->'; } $lc->update($rckey . '.lock', array('lock'), 5); // 5s lock } else { $lc->update($rckey . '.lock', array('lock'), 5); // 5s lock } // $uniq_avatar is numeric case: change avatar icon after 24 hours if (is_numeric($uniq_avatar)) { $uniq_avatar = $rckey . date('mdH', time()); } else { if (is_string($uniq_avatar) and preg_match('/^[YmdHi]+$/', $uniq_avatar)) { // date format string case: change avatar icon after 'Ymd' etc period $uniq_avatar = $rckey . date($uniq_avatar, time()); } } $time_current = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(); $secs_per_day = 60 * 60 * 24; //$time_cutoff= $time_current - ($days * $secs_per_day); $lines = $DBInfo->editlog_raw_lines($days, $opts); // make a daysago button $btnlist = ''; if (!empty($use_daysago) or !empty($_GET['ago'])) { $msg[0] = _("Show changes for "); $agolist = array(-$days, $days, 2 * $days, 3 * $days); $btn = array(); $arg = 'days=' . $days . '&ago'; $msg[1] = _("days ago"); foreach ($agolist as $d) { $d += $opts['ago']; if ($d <= 0) { continue; } $link = $formatter->link_tag($formatter->page_urlname, "?{$arg}=" . $d, $d); $btn[] = $link; } #if (sizeof($lines)==0) $btn=array_slice($btn,0,1); $btn[] = $formatter->link_tag($formatter->page_urlname, "?{$arg}=...", '...', 'onClick="return daysago(this)"'); $script = "<script type='text/javascript' src='{$DBInfo->url_prefix}/local/rc.js' ></script>"; $btnlist = $msg[0] . ' <ul><li>' . implode("</li>\n<li>", $btn) . '</li></ul> ' . $msg[1]; $btnlist = $script . "<div class='rc-button'>\n" . $btnlist . "</div>\n"; } $rc = new Cache_text('rclogs'); $ratchet_day = FALSE; $editors = array(); $editcount = array(); $rc_delay = isset($DBInfo->rc_delay) ? $DBInfo->rc_delay : $rc_cache_delay; $rctimestamp = 0; $needupdate = false; $use_val = false; while (($val = $rc->fetch($rckey)) !== false) { $use_val = true; if (!empty($formatter->refresh) or !$DBInfo->checkUpdated($rc->mtime($rckey), $rc_delay)) { $use_val = $rc->exists($rckey . '.lock'); } if (!$use_val) { break; } $editors = $val['editors']; $editcount = $val['editcount']; $lastmod = $val['lastmod']; $rclastline = $val['lastline']; $rctimestamp = $val['timestamp']; $users = $val['users']; break; } // no cache available if (!$use_val) { $rc->update($rckey . '.lock', array('lock'), 5); } // 5s lock $lastline = $lines[0]; $tmp = explode("\t", $lastline, 6); $timestamp = $tmp[2]; unset($tmp); $updatemod = array(); $needupdate = $rctimestamp < $timestamp or $lastline != $rclastline; if ($needupdate) { foreach ($lines as $line) { $parts = explode("\t", $line, 6); if ($lastline == $rclastline) { break; } $page_key = $parts[0]; $ed_time = $parts[2]; $user = $parts[4]; $addr = $parts[1]; if ($user == 'Anonymous') { $user = '******' . $addr; } else { $user = $user . "\t" . $addr; } $day = gmdate('Ymd', $ed_time + $tz_offset); //if ($day != $ratchet_day) { // $ratchet_day = $day; //} if ($last_entry_only and !empty($last_entry_check)) { if (!empty($lastmod[$page_key]) and $lastmod[$page_key] < $ed_time + $last_entry_check) { $edit_day = gmdate('Ymd', $lastmod[$page_key] + $tz_offset); $editors[$page_key][$edit_day][] = $user; $editcount[$page_key][$edit_day]++; if ($needupdate and empty($updatemod[$page_key])) { $updatemod[$page_key] = $ed_time; } continue; } } else { if (!empty($editcount[$page_key][$day])) { $editors[$page_key][$day][] = $user; $editcount[$page_key][$day]++; if ($needupdate and empty($updatemod[$page_key])) { $updatemod[$page_key] = $ed_time; } continue; } } if (empty($editcount[$page_key])) { $editcount[$page_key] = array(); $editors[$page_key] = array(); } $editcount[$page_key][$day] = 1; $editors[$page_key][$day] = array(); $editors[$page_key][$day][] = $user; $lastmod[$page_key] = $ed_time; if ($needupdate) { $updatemod[$page_key] = $ed_time; } } } if (!empty($lastmod)) { $lastmod = array_merge($lastmod, $updatemod); } // search query if (isset($query[0])) { $lines = preg_grep("/{$query}/i", $lines); } // setup hidelog rule $hiderule = null; if (!$ismember && !empty($Config['ruleset']['hiderule'])) { $rule = implode('|', $Config['ruleset']['hiderule']); if (preg_match('@' . $rule . '@', null) !== false) { $hiderule = '@' . $rule . '@'; } } $out = ""; $ratchet_day = FALSE; $br = ""; $ii = 0; $rc_list = array(); $list = array(); foreach ($lines as $line) { $parts = explode("\t", $line); $page_key = $parts[0]; $ed_time = $parts[2]; $day = gmdate('Ymd', $ed_time + $tz_offset); // show last edit only if (!empty($last_entry_only) and !empty($logs[$page_key])) { continue; } else { if (!empty($logs[$page_key][$day])) { continue; } } $page_name = $DBInfo->keyToPagename($parts[0]); if (!empty($hiderule)) { if (preg_match($hiderule, $page_name)) { continue; } } // show trashed pages only if ($trash and $DBInfo->hasPage($page_name)) { continue; } $addr = $parts[1]; $user = $parts[4]; $log = _stripslashes($parts[5]); $act = rtrim($parts[6]); $via_proxy = false; if (($p = strpos($addr, ',')) !== false) { // user via Proxy $via_proxy = true; $real_ip = substr($addr, 0, $p); $log_proxy = '<span class="via-proxy">' . $real_ip . '</span>'; $log = isset($log[0]) ? $log_proxy . ' ' . $log : $log_proxy; $dum = explode(',', $addr); $addr = array_pop($dum); } // if ($ed_time < $time_cutoff) // break; $group = ''; if ($formatter->group) { if (!preg_match("/^({$formatter->group})(.*)\$/", $page_name, $match)) { continue; } $title = $match[2]; } else { if (!empty($formatter->use_group) and ($p = strpos($page_name, '~')) !== false) { $title = substr($page_name, $p + 1); $group = ' (' . substr($page_name, 0, $p) . ')'; } else { $title = $page_name; } } if (!empty($changed_time_fmt)) { if (empty($timesago)) { $date = gmdate($changed_time_fmt, $ed_time + $tz_offset); } else { $date = _timesago($ed_time, 'Y-m-d', $tz_offset); } } $pageurl = _rawurlencode($page_name); // get title $title0 = get_title($title) . $group; $title0 = _html_escape($title0); if ($rctype == 'list') { $attr = ''; } else { $attr = " id='title-{$ii}'"; } if (!empty($strimwidth) and strlen(get_title($title)) > $strimwidth and function_exists('mb_strimwidth')) { $title0 = mb_strimwidth($title0, 0, $strimwidth, '...', $DBInfo->charset); } $attr .= ' title="' . $title0 . '"'; $title = $formatter->link_tag($pageurl, "", $title0, $target . $attr); // simple list format if ($rctype == 'list') { if (empty($logs[$page_key])) { $logs[$page_key] = array(); } $logs[$page_key][$day] = 1; if (!$DBInfo->hasPage($page_name)) { $act = 'DELETE'; $title = '<strike>' . $title . '</strike>'; } $list[$page_name] = array($title, $date, $ed_time, $act); continue; } // print $ed_time."/".$bookmark."//"; $diff = ''; $updated = ''; if ($act == 'UPLOAD') { $icon = $formatter->link_tag($pageurl, "?action=uploadedfiles", $formatter->icon['attach']); } else { if (!$DBInfo->hasPage($page_name)) { $icon = $formatter->link_tag($pageurl, "?action=info", $formatter->icon['del']); if (!empty($use_js)) { $rc_list[] = $page_name; } } else { $icon = $formatter->link_tag($pageurl, "?action=diff", $formatter->icon['diff'], " id='icon-{$ii}'"); if (empty($use_js) and $ed_time > $bookmark) { $icon = $formatter->link_tag($pageurl, "?action=diff&date={$bookmark}", $formatter->icon['diff']); $updated = ' ' . $formatter->link_tag($pageurl, "?action=diff&date={$bookmark}", $formatter->icon['updated'], 'class="updated"'); $add = 0; $del = 0; if ($checknew or $checkchange) { $p = new WikiPage($page_name); $v = $p->get_rev($bookmark); if (empty($v)) { $icon = $formatter->link_tag($pageurl, "?action=info", $formatter->icon['show']); $updated = ' ' . $formatter->link_tag($pageurl, "?action=info", $formatter->icon['new'], 'class="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]; } } } if (!empty($add)) { $diff .= '<span class="diff-added"><span>+' . $add . '</span></span>'; } if (!empty($del)) { $diff .= '<span class="diff-removed"><span>' . $del . '</span></span>'; } } else { if (!empty($use_js)) { $diff = '<span id="diff-' . $ii . '"></span>'; $rc_list[] = $page_name; } } } } if (!empty($use_hits)) { $hits = $DBInfo->counter->pageCounter($page_name); } if (!empty($showhost)) { if ($last_editor_only) { // show last editor only $editor = $editors[$page_key][$day]; if (is_array($editor)) { $editor = $editor[0]; } } else { // all show all authors // count edit number // make range list if ($use_editrange) { // MoinMoin like edit range $editor_list = array(); if ($editors[$page_key][$day]) { foreach ($editors[$page_key][$day] as $idx => $name) { if (empty($editor_list[$name])) { $editor_list[$name] = array(); } $editor_list[$name][] = $idx + 1; } } $editor_counts = array(); foreach ($editor_list as $name => $edits) { $range = ','; if (isset($edits[1])) { $edits[] = 999999; // MoinMoin method for ($i = 0, $sz = count($edits) - 1; $i < $sz; $i++) { if (substr($range, -1) == ',') { $range .= $edits[$i]; if ($edits[$i] + 1 == $edits[$i + 1]) { $range .= '-'; } else { $range .= ','; } } else { if ($edits[$i] + 1 != $edits[$i + 1]) { $range .= $edits[$i] . ','; } } } $range = trim($range, ',-'); $editor_counts[$name] = $range; } else { $editor_counts[$name] = $edits[0]; } } } else { $editor_counts = array_count_values($editors[$page_key][$day]); } $editor = array_keys($editor_counts); } $all_user = array(); foreach ((array) $editor as $user) { if (!$last_editor_only and isset($editor[1]) and isset($editor_counts[$user])) { $count = " <span class='range'>[" . $editor_counts[$user] . "]</span>"; } else { $count = ''; } if (!empty($showhost) && substr($user, 0, 9) == 'Anonymous') { $ouser = $user; if (isset($users[$ouser])) { $user = $users[$ouser]; } else { $checkaddr = null; $addr = null; $tmp = $user; if (strpos($user, "\t") !== false) { list($tmp, $addr) = explode("\t", $user); } $checkaddr = substr($tmp, 10); // Anonymous-127.0.0.1 or Anonymous-email@foo.bar if (($p = strpos($checkaddr, ',')) !== false) { $dum = explode(',', $checkaddr); $checkaddr = array_pop($dum); // last address is the REMOTE_ADDR } $user = $addr = $addr ? $addr : $checkaddr; if (!is_numeric($checkaddr[0]) and preg_match('/^[a-z][a-z0-9_\\-\\.]+@[a-z][a-z0-9_\\-]+(\\.[a-z0-9_]+)+$/i', $user)) { $user = $checkaddr; if (!empty($DBInfo->hide_emails)) { $user = substr(md5($user), 0, 8); } else { $user = email_guard($user); } } else { if (isset($DBInfo->interwiki['Whois'])) { $wip = "<a href='" . $DBInfo->interwiki['Whois'] . "{$addr}' target='_blank'>{$ipicon}</a>"; } else { $wip = "<a href='?action=whois&q=" . $addr . "' target='_blank'>{$ipicon}</a>"; } if ($ismember) { if (in_array($user, $members)) { $wip = ''; } if (!empty($DBInfo->use_admin_user_url)) { $user = '******' . $DBInfo->use_admin_user_url . $user . '">' . $user . '</a>' . $wip; } else { $user = $user . $wip; } } else { if (!empty($DBInfo->mask_hostname)) { $user = _mask_hostname($addr, intval($DBInfo->mask_hostname)); } } } $avatar = ''; if (!empty($use_avatar)) { if (!empty($uniq_avatar)) { $key = $addr . $uniq_avatar; } else { $key = $addr . $rckey; } $crypted = md5($key); $mylnk = preg_replace('/seed=/', 'seed=' . $crypted, $avatarlink); $avatar = '<img src="' . $mylnk . '" class="avatar" alt="avatar" />'; } $user = $avatar . $user; $users[$ouser] = $user; } } else { list($user, $addr) = explode("\t", $user); $ouser = $user; if (!isset($users[$ouser])) { if (isset($DBInfo->interwiki['Whois'])) { $wip = "<a href='" . $DBInfo->interwiki['Whois'] . "{$addr}' target='_blank'>{$ipicon}</a>"; } else { $wip = "<a href='?action=whois&q=" . $addr . "' target='_blank'>{$ipicon}</a>"; } $avatar = ''; if (!empty($use_avatar)) { if (!empty($uniq_avatar)) { $key = $addr . $uniq_avatar; } else { $key = $addr . $rckey; } if (!$ismember) { $key .= $user; } // not a member: show different avatar for login user $crypted = md5($key); $mylnk = preg_replace('/seed=/', 'seed=' . $crypted, $avatarlink); if ($ouser != 'Anonymous') { $mylnk .= '&user='******'<img src="' . $mylnk . '" class="avatar" alt="avatar" />'; } } if (isset($users[$ouser])) { $user = $users[$ouser]; } else { if ($ismember) { if (in_array($user, $members)) { $wip = ''; } if (!empty($DBInfo->use_admin_user_url)) { $user = $avatar . '<a href="' . $DBInfo->use_admin_user_url . $user . '">' . $user . '</a>' . $wip; } else { $user = $avatar . $user . $wip; } $users[$ouser] = $user; } else { if (!empty($DBInfo->use_nick)) { $uid = $user; if (($p = strpos($uid, ' ')) !== false) { $uid = substr($uid, 0, $p); } $u = $DBInfo->udb->getUser($uid); if (!empty($u->info)) { if (!empty($DBInfo->interwiki['User'])) { $user = $formatter->link_repl('[wiki:User:'******' ' . $u->info['nick'] . ']'); } else { if (!empty($u->info['home'])) { $user = $formatter->link_repl('[' . $u->info['home'] . ' ' . $u->info['nick'] . ']'); } else { if (!empty($u->info['nick'])) { $user = $formatter->link_repl('[wiki:' . $uid . ' ' . $u->info['nick'] . ']'); } } } } $user = $avatar . $user; $users[$ouser] = $user; } else { if (strpos($user, ' ') !== false) { $user = $avatar . $formatter->link_repl($user); $users[$ouser] = $user; } else { if (empty($DBInfo->no_wikihomepage) and $DBInfo->hasPage($user)) { $user = $formatter->link_tag(_rawurlencode($user), "", $user); $user = $avatar . $user; $users[$ouser] = $user; } else { if (substr($user, 0, 9) == 'Anonymous') { $addr = substr($user, 10); $user = _('Anonymous'); } $uid = $user; if (preg_match('/^[a-z][a-z0-9_\\-\\.]+@[a-z][a-z0-9_\\-]+(\\.[a-z0-9_]+)+$/i', $user)) { if (!empty($DBInfo->hide_emails)) { $user = substr(md5($user), 0, 8); } else { $user = email_guard($user); } } $user = $avatar . $user; $users[$ouser] = $user; } } } } } } $all_user[] = $user . $count; } if (isset($editor[1])) { $user = '******' . implode("</span> <span class='editor'>", $all_user) . "</span></span>\n"; } else { $user = '******' . $all_user[0] . "</span>\n"; } } else { $user = '******'; } $jsattr = ''; if (!empty($use_js)) { $jsattr = ' onclick="update_bookmark(' . $ed_time . ');return false;"'; } $bmark = ''; if ($day != $ratchet_day) { $ratchet_day = $day; if (!empty($use_day)) { $tag = str_replace('-', '', $day); $perma = "<a name='{$tag}'></a><a class='perma' href='#{$tag}'>{$perma_icon}</a>"; $out .= $cat0; $rcdate = gmdate($date_fmt, $ed_time + $tz_offset); $out .= sprintf("%s<span class='rc-date' style='font-size:large'>%s ", $br, $rcdate); if (empty($nobookmark)) { $out .= "<span class='rc-bookmark' style='font-size:small'>[" . $formatter->link_tag($formatter->page->urlname, $bookmark_action . "&time={$ed_time}" . $daysago, _("set bookmark"), $jsattr) . "]</span>\n"; } $br = "<br />"; $out .= '</span>' . $perma . '<br />' . $bra; $cat0 = $cat; } else { $bmark = $formatter->link_to($bookmark_action . "&time={$ed_time}" . $daysago, _("Bookmark"), $jsattr . ' class="button-small"'); } } //if (empty($use_day) and empty($nobookmark)) { if (empty($nobookmark)) { $date = $formatter->link_to($bookmark_action . "&time={$ed_time}" . $daysago, $date, ' id="time-' . $ii . '" ' . $jsattr); } $count = ""; $extra = ""; if ($editcount[$page_key][$day] > 1) { $count = '<span id="change-' . $ii . '">' . sprintf(_("%s changes"), " <span class='num'>" . $editcount[$page_key][$day] . "</span>") . '</span>'; } else { $count = '<span id="change-' . $ii . '"></span>'; } if (!empty($comment) && !empty($log)) { $extra = " <small name='word-break'>{$log}</small>"; } $alt = $ii % 2 == 0 ? ' class="alt"' : ''; if ($extra and isset($template_extra)) { if ($rctype == 'board' and !empty($use_js)) { $style = ' style="display:none"'; } else { $style = ''; } if (!empty($use_js)) { $title = '<button onclick="toggle_log(this);return false;"><span>+</span></button>' . $title; } $out .= eval('return ' . $template_extra . ';'); } else { $out .= eval('return ' . $template . ';'); } if (empty($logs[$page_key])) { $logs[$page_key] = array(); } $logs[$page_key][$day] = 1; ++$ii; } if ($needupdate) { $rc->update($rckey, array('editors' => $editors, 'editcount' => $editcount, 'lastmod' => $lastmod, 'lastline' => $lastline, 'timestamp' => $timestamp, 'users' => $users)); } $js = ''; if (!empty($rc_list)) { require_once 'lib/JSON.php'; $json = new Services_JSON(); $icon_new = $formatter->icon['new']; $icon_updated = $formatter->icon['updated']; $icon_show = $formatter->icon['show']; $icon_diff = $formatter->icon['diff']; $js = "<script type='text/javascript'>\n/*<![CDATA[*/\nvar rclist ="; $ext = array(); if (!empty($checknew)) { $ext[] = 'new=1'; } if (!empty($checkchange)) { $ext[] = 'change=1'; } $arg = implode('&', $ext); //$url = qualifiedURL($formatter->link_url('RecentChanges')); // FIXME //$url = preg_replace('/^https?:/', '', $url); $url = $formatter->link_url('RecentChanges'); $postdata = "action=recentchanges/ajax" . ($arg ? '&' . $arg : ''); $js .= $json->encode($rc_list) . ";\n"; if ($use_diffwidth) { $js .= "var use_diffwidth = true;\n"; } else { $js .= "var use_diffwidth = false;\n"; } $js .= <<<EOF function diff_width(size) { if (size < 0) size = -size; if (size < 5) return ''; else if (size < 10) return 'display:inline-block;width:25px'; else return 'display:inline-block;width:' + ~~(25 + 2*Math.sqrt(size)) + 'px'; } function update_bookmark(time) { var url = "{$url}"; if (rclist.length) { var timetag; if (typeof time == 'undefined') timetag = ''; else timetag = '&time=' + time; var data = "{$postdata}"; data += timetag + '&value=' + encodeURIComponent(json_encode(rclist)); var txt = HTTPPost(url, data); var ret; if (txt == null) return; var icon_new = "{$icon_new}"; var icon_updated = "{$icon_updated}"; var icon_show = "{$icon_show}"; var icon_diff = "{$icon_diff}"; ret = window["eval"]("(" + txt + ")"); var bookmark = ret['__-_-bookmark-_-__']; var jj = 0; for (var ii = 0; ii < rclist.length; ii++) { // update time var time = document.getElementById('time-' + ii); var tstr = time.firstChild.innerText; var d0 = Date.parse(tstr); // test if (isNaN(d0)) { // recalc time string var timestamp = time.href.match(/time=(\\d+)/); tstr = timesago(timestamp[1], "{$date_fmt}", {$tz_offset}); if (tstr != null) time.firstChild.innerText = tstr; } var item = document.getElementById('title-' + ii); var title = item.getAttribute('title'); if (rclist[jj] != title) { var re = new RegExp("^.*" + url_prefix + '/'); title = decodeURIComponent(item.href.replace(re, '')); } if (ret[title] && ret[title]['state'] == 'deleted') { jj++; continue; } if (rclist[jj] == title && ret[title]) { var icon = document.getElementById('icon-' + ii); var state = document.createElement('SPAN'); if (ret[title]['state'] == 'new') { state.innerHTML = icon_new; state.setAttribute('class', 'new'); icon.href = icon.href.replace(/action=(diff|info)((?:&|&)date=\\d+)?/, 'action=info'); icon.innerHTML = icon_show; } else { state.innerHTML = icon_updated; state.setAttribute('class', 'updated'); icon.href = icon.href.replace(/action=(diff|info)((?:&|&)date=\\d+)?/, 'action=diff&date=' + bookmark); icon.innerHTML = icon_diff; } // remove previous icon if (item.firstChild.nextSibling) item.removeChild(item.firstChild.nextSibling); item.appendChild(state); // add updated / new icon var change = document.getElementById('change-' + ii); if (!change) continue; var diff = document.getElementById('diff-' + ii); var nodiff = !diff; // remove previous diff info if (change.lastChild && change.lastChild.tagName == 'SPAN') change.removeChild(change.lastChild); else if (diff && diff.lastChild) diff.removeChild(diff.lastChild); // add diff info var diff0 = document.createElement('SPAN'); if (ret[title]['add']) { var add = document.createElement('SPAN'); var add2 = document.createElement('SPAN'); add.setAttribute('class', 'diff-added'); var txt = document.createTextNode('+' + ret[title]['add']); add2.appendChild(txt); add.appendChild(add2); diff0.appendChild(add); if (use_diffwidth) add.style.cssText = diff_width(ret[title]['add']); } if (ret[title]['del']) { var del = document.createElement('SPAN'); var del2 = document.createElement('SPAN'); del.setAttribute('class', 'diff-removed'); var txt = document.createTextNode(ret[title]['del']); del2.appendChild(txt); del.appendChild(del2); diff0.appendChild(del); if (use_diffwidth) del.style.cssText = diff_width(ret[title]['del']); } if (nodiff) change.appendChild(diff0); else diff.appendChild(diff0); jj++; } else { if (item.firstChild.nextSibling) item.removeChild(item.firstChild.nextSibling); var change = document.getElementById('change-' + ii); if (!change) continue; var diff = document.getElementById('diff-' + ii); // remove diff info if (change.lastChild && change.lastChild.tagName == 'SPAN') change.removeChild(change.lastChild); else if (diff && diff.lastChild) diff.removeChild(diff.lastChild); // recover diff icon and link var icon = document.getElementById('icon-' + ii); if (icon && icon.firstChild) { var alt = icon.firstChild.getAttribute('alt'); if (alt != 'D' && alt != '@') { icon.innerHTML = icon_diff; } // recover link icon.href = icon.href.replace(/action=(diff|info)(&date=\\d+)?/, 'action=diff'); } } } } } if(window.addEventListener)window.addEventListener("load",update_bookmark,false); else if(window.attachEvent)window.attachEvent("onload",update_bookmark); /*]]>*/ </script> EOF; } else { if (!empty($list)) { $out = ''; foreach ($list as $k => $v) { $out .= '<li><span data-timestamp="' . $v[2] . '" class="date">' . $v[1] . '</span> ' . $v[0] . '</li>' . "\n"; } //if (!empty($options['ajax'])) { // return '<ul>'.$out.'</ul>'; //} } } if (in_array($rctype, array('list', 'simple')) and $use_js) { static $rc_id = 1; $rcid = ' id="rc' . $rc_id . '"'; $extra = ''; if (!empty($opts['items'])) { $extra .= '&item=' . $opts['items']; } if (!empty($my_date_fmt)) { $extra .= '&datefmt=' . $my_date_fmt; } $url = $formatter->link_url('RecentChanges', "?action=recentchanges/ajax&type={$rctype}" . $extra); $js = <<<JS <script type='text/javascript'> /*<![CDATA[*/ (function() { var url = "{$url}"; var txt = HTTPGet(url); var rc = document.getElementById("rc{$rc_id}"); if (txt.substring(0,5) != 'false') { var m = null; if (m = txt.match(/<ul>[\\s\\S]*<\\/ul>/)) { rc.innerHTML = m[0]; } } })(); /*]]>*/ </script> JS; $rc_id++; } else { if ($use_js and $rctype == 'board') { $js .= <<<JS <script type='text/javascript'> /*<![CDATA[*/ function toggle_log(el) { var item = el.parentNode.parentNode; // container var log = item.nextSibling; if (log.tagName == undefined) log = log.nextSibling; // for IE6 if (log.style.display == "none") { el.className = "close"; log.style.display = ""; } else { el.className = "open"; log.style.display = "none"; } } /*]]>*/ </script> JS; } } $out = $btnlist . '<div class="recentChanges"' . $rcid . '>' . $rctitle . $template_bra . $out . $template_cat . $cat0 . '</div>' . $js . $rclog; $lc->update($rckey, $out); $lc->remove($rckey . '.lock'); // unlock $rc->remove($rckey . '.lock'); // unlock return $out; }
function macro_Rss($formatter, $value) { global $DBInfo; $rsscache = new Cache_text('rsscache'); $key = _rawurlencode($value); // rss TTL = 7200 sec (60*60*2) if (!$formatter->refresh && $rsscache->exists($key) && time() < $rsscache->mtime($key) + 7200) { return $rsscache->fetch($key); } if ($rsscache->exists($key . '.lock')) { return ''; } $args = explode(',', $value); // first arg assumed to be a date fmt arg $date_fmt = ''; $title_width = 0; if (count($args) > 1) { if (preg_match("/^[\\s\\/\\-:aABdDFgGhHiIjmMOrSTY\\[\\]]+\$/", $args[0])) { $date_fmt = array_shift($args); } if (is_numeric($args[0])) { $title_width = array_shift($args); // too small or too big if ($title_width < 10 || $title_width > 40) { $title_width = 0; } } $value = implode(',', $args); } $cache = new Cache_text("rssxml"); # reflash rss each 7200 second (60*60*2) if (!$cache->exists($key) or time() > $cache->mtime($key) + 7200) { $fp = @fopen("{$value}", "r"); if (!$fp) { return "[[RSS(ERR: not a valid URL! {$value})]]"; } while ($data = fread($fp, 4096)) { $xml_data .= $data; } fclose($fp); $cache->update($key, $xml_data); } else { $xml_data = $cache->fetch($key); } // detect charset $charset = 'UTF-8'; list($line, $dummy) = explode("\n", $xml_data, 2); preg_match("/\\sencoding=?(\"|')([^'\"]+)/", $line, $match); if ($match) { $charset = strtoupper($match[2]); } // override $charset for php5 if ((int) phpversion() >= 5) { $charset = 'UTF-8'; } $xml_parser = xml_parser_create(); $rss_parser = new WikiRSSParser($charset); if (!empty($date_fmt)) { $rss_parser->setDateFormat($date_fmt); } if (!empty($title_width)) { $rss_parser->setTitleWidth($title_width); } xml_set_object($xml_parser, $rss_parser); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); ob_start(); $ret = xml_parse($xml_parser, $xml_data); if (!$ret) { return sprintf("[[RSS(XML error: %s at line %d)]]", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)); } $out = ob_get_contents(); ob_end_clean(); xml_parser_free($xml_parser); $out = '<ul class="rss">' . $out . '</ul>'; # if (strtolower(str_replace("-","",$options['oe'])) == 'euckr') if (function_exists('iconv') and strtoupper($DBInfo->charset) != $charset) { $new = iconv($charset, $DBInfo->charset, $out); if ($new !== false) { return $new; } } $rsscache->remove($key . '.lock'); $rsscache->update($key, $out); return $out; }
function macro_FastSearch($formatter, $value = "", &$opts) { global $DBInfo; $default_limit = isset($DBInfo->fastsearch_limit) ? $DBInfo->fastsearch_limit : 30; if ($value === true) { $needle = $value = $formatter->page->name; } else { # for MoinMoin compatibility with [[FullSearch("blah blah")]] $needle = $value = preg_replace("/^('|\")([^\\1]*)\\1/", "\\2", $value); } $needle = _preg_search_escape($needle); $pattern = '/' . $needle . '/i'; $fneedle = str_replace('"', """, $needle); # XXX $url = $formatter->link_url($formatter->page->urlname); $arena = 'fullsearch'; $check1 = 'checked="checked"'; $check2 = $check3 = ''; if (in_array($opts['arena'], array('titlesearch', 'fullsearch', 'pagelinks'))) { $check1 = ''; $arena = $opts['arena']; if ($arena == 'fullsearch') { $check1 = 'checked="checked"'; } else { if ($arena == 'titlesearch') { $check2 = 'checked="checked"'; } else { $check3 = 'checked="checked"'; } } } if (!empty($opts['backlinks'])) { $arena = 'pagelinks'; $check1 = ''; $check3 = 'checked="checked"'; } $msg = _("Fast search"); $msg2 = _("Display context of search results"); $msg3 = _("Full text search"); $msg4 = _("Title search"); $msg5 = _("Link search"); $form = <<<EOF <form method='get' action='{$url}'> <input type='hidden' name='action' value='fastsearch' /> <input name='value' size='30' value='{$fneedle}' /> <span class='button'><input type='submit' class='button' value='{$msg}' /></span><br /> <input type='checkbox' name='context' value='20' />{$msg2}<br /> <input type='radio' name='arena' value='fullsearch' {$check1} />{$msg3} <input type='radio' name='arena' value='titlesearch' {$check2} />{$msg4} <input type='radio' name='arena' value='pagelinks' {$check3} />{$msg5}<br /> </form> EOF; if (!isset($needle[0]) or !empty($opts['form'])) { # or blah blah $opts['msg'] = _("No search text"); return $form; } else { if (validate_needle($needle) === false) { $opts['msg'] = sprintf(_("Invalid search expression \"%s\""), $needle); return $form; } } $DB = new Indexer_dba($arena, "r", $DBInfo->dba_type); if ($DB->db == null) { $opts['msg'] = _("Couldn't open search database, sorry."); $opts['hits'] = array(); $opts['hit'] = 0; $opts['all'] = 0; return ''; } $opts['form'] = $form; $sc = new Cache_text("searchkey"); if ($arena == "pagelinks") { $words = array($value); } else { $words = getTokens($value); } // $words=explode(' ', strtolower($value)); $idx = array(); $new_words = array(); foreach ($words as $word) { if ($sc->exists($word)) { $searchkeys = $sc->fetch($word); } else { $searchkeys = $DB->_search($word); $sc->update($word, $searchkeys); } $new_words = array_merge($new_words, $searchkeys); $new_words = array_merge($idx, $DB->_search($word)); } $words = array_merge($words, $new_words); // $word = array_shift($words); $idx = $DB->_fetchValues($word); foreach ($words as $word) { $ids = $DB->_fetchValues($word); // FIXME foreach ($ids as $id) { $idx[] = $id; } } $init_hits = array_count_values($idx); // initial hits $idx = array_keys($init_hits); //arsort($idx); $all_count = $DBInfo->getCounter(); $pages = array(); $hits = array(); foreach ($idx as $id) { $key = $DB->_fetch($id); $pages[$id] = $key; $hits['_' . $key] = $init_hits[$id]; // HACK. prefix '_' to numerical named pages } $DB->close(); if (!empty($_GET['q']) and isset($_GET['q'][0])) { return $pages; } $context = !empty($opts['context']) ? $opts['context'] : 0; $limit = isset($opts['limit'][0]) ? $opts['limit'] : $default_limit; $contexts = array(); if ($arena == 'fullsearch' || $arena == 'pagelinks') { $idx = 1; foreach ($pages as $page_name) { if (!empty($limit) and $idx > $limit) { break; } $p = new WikiPage($page_name); if (!$p->exists()) { continue; } $body = $p->_get_raw_body(); $count = preg_match_all($pattern, $body, $matches); // more precisely count matches if ($context) { # search matching contexts $contexts[$page_name] = find_needle($body, $needle, '', $context); } $hits['_' . $page_name] = $count; // XXX hack for numerical named pages $idx++; } } //uasort($hits, 'strcasecmp'); //$order = 0; //uasort($hits, create_function('$a, $b', 'return ' . ($order ? '' : '-') . '(strcasecmp($a, $b));')); $name = array_keys($hits); array_multisort($hits, SORT_DESC, $name, SORT_ASC); $opts['hits'] = $hits; $opts['hit'] = count($hits); $opts['all'] = $all_count; if (!empty($opts['call'])) { return $hits; } $out = "<!-- RESULT LIST START -->"; // for search plugin $out .= "<ul>"; $idx = 1; while (list($page_name, $count) = each($hits)) { $page_name = substr($page_name, 1); $out .= '<!-- RESULT ITEM START -->'; // for search plugin $out .= '<li>' . $formatter->link_tag(_rawurlencode($page_name), "?action=highlight&value=" . _urlencode($needle), $page_name, "tabindex='{$idx}'"); if ($count > 1) { $out .= ' . . . . ' . sprintf($count == 1 ? _("%d match") : _("%d matches"), $count); if (!empty($contexts[$page_name])) { $out .= $contexts[$page_name]; } } $out .= "</li>\n"; $out .= '<!-- RESULT ITEM END -->'; // for search plugin $idx++; if (!empty($limit) and $idx > $limit) { break; } } $out .= "</ul>\n"; $out .= "<!-- RESULT LIST END -->"; // for search plugin return $out; }
function macro_LikePages($formatter = "", $value, &$opts) { global $DBInfo; $pname = _preg_escape($value); $metawiki = !empty($opts['metawiki']) ? $opts['metawiki'] : ''; if (strlen($pname) < 3) { $opts['msg'] = _("Use more specific text"); return ''; } $opts['extra'] = ''; $s_re = "^[A-Z][A-Za-z0-9]+"; $e_re = "[A-Z][A-Za-z0-9]+\$"; $count = preg_match("/(" . $s_re . ")/", $pname, $match); $s_len = 0; if ($count) { $start = trim($match[1]); $s_len = strlen($start); } $count = preg_match("/(" . $e_re . ")/", $pname, $match); if ($count) { $end = $match[1]; $e_len = strlen($end); } // for non ASCII codeset if (empty($start) or empty($end)) { if (preg_match('/[^A-Za-z0-9-_]/', $pname)) { $myname = preg_replace('/[\\x00-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7F]/', ' ', $pname); $words = preg_split('/\\s+/', $myname); if (empty($start)) { $start = $words[0]; } if (isset($words[1])) { if (empty($end)) { $end = $words[count($words) - 1]; } } } // try to remove suffix // "위키에서 글쓰기" => start=위키에서|위키에|위키 if (!empty($start) and preg_match('/[\\x{AC00}-\\x{D7AF}]/u', $start)) { $ws = preg_split('//u', $start, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $nw = array(); $nw[] = $start; for ($i = 2; count($ws) > 2 and $i > 0; $i--) { array_pop($ws); $nw[] = implode('', $ws); } $start = implode('|', $nw); } if (!empty($end) and preg_match('/[\\x{AC00}-\\x{D7AF}]/u', $end)) { $ws = preg_split('//u', $end, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $nw = array(); $last = array_splice($ws, -2); $last = implode('', $last); $nw[] = $last; $ws = array_reverse($ws); foreach ($ws as $w) { $last = $w . $last; $nw[] = $last; } $end = implode('|', $nw); } } if (empty($start)) { preg_match("/^(.{2,4})/u", $value, $match); $s_len = strlen($match[1]); $start = trim(_preg_escape($match[1])); } if (empty($end)) { $end = substr($value, $s_len); preg_match("/(.{2,6})\$/u", $end, $match); $end = isset($match[1]) ? $match[1] : ''; $e_len = strlen($end); if ($e_len < 2) { $end = ""; } else { $end = _preg_escape($end); } } $starts = array(); $ends = array(); $likes = array(); if (empty($metawiki)) { if (!$end) { $needle = $start; } else { $needle = "{$start}|{$end}"; } $indexer = $DBInfo->lazyLoad('titleindexer'); $pages = $indexer->getLikePages($needle); // get aliases if (empty($DBInfo->alias)) { $DBInfo->initAlias(); } $alias = $DBInfo->alias->getAllPages(); $pages = array_merge($pages, $alias); } else { if (empty($DBInfo->metadb)) { $DBInfo->initMetaDB(); } if (empty($DBInfo->metadb)) { $opts['msg'] = _("No metadb found"); return ''; } if (!$end) { $needle = $start; } else { $needle = "{$start}|{$end}"; } $pages = $DBInfo->metadb->getLikePages($needle); } if ($start) { foreach ($pages as $page) { preg_match("/^{$start}/", $page, $matches); if ($matches) { $starts[$page] = 1; } } } if ($end) { foreach ($pages as $page) { preg_match("/{$end}\$/", $page, $matches); if ($matches) { $ends[$page] = 1; } } } if (!empty($DBInfo->use_similar_text)) { $len = strlen($value); $ii = 0; foreach ($pages as $page) { $ii++; $match = similar_text($value, $page) / min($len, strlen($page)); if ($match > 0.9 && empty($starts[$page]) && empty($ends[$page])) { $likes[$page] = $match; } } } else { if ($start || $end) { if ($start and $end) { $similar_re = "{$start}|{$end}"; } else { if ($start) { $similar_re = $start; } else { $similar_re = $end; } } if (!empty($words)) { $similar_re .= '|' . implode('|', $words); } foreach ($pages as $page) { preg_match("/({$similar_re})/i", $page, $matches); if ($matches && empty($starts[$page]) && empty($ends[$page])) { $likes[$page] = 1; } } } } $idx = 1; $hits = 0; $out = ""; if ($likes) { ksort($likes); $out .= "<h3>" . _("These pages share a similar word...") . "</h3>"; $out .= "<ol>\n"; foreach ($likes as $pagename => $i) { $pageurl = _rawurlencode($pagename); $pagetext = htmlspecialchars(urldecode($pagename)); $out .= '<li>' . $formatter->link_tag($pageurl, "", $pagetext, "tabindex='{$idx}'") . "</li>\n"; $idx++; } $out .= "</ol>\n"; $hits = count($likes); } if ($starts || $ends) { ksort($starts); $out .= "<h3>" . _("These pages share an initial or final title word...") . "</h3>"; $out .= "<table border='0' width='100%'><tr><td width='50%' valign='top'>\n<ol>\n"; while (list($pagename, $i) = each($starts)) { $pageurl = _rawurlencode($pagename); $pagetext = htmlspecialchars(urldecode($pagename)); $out .= '<li>' . $formatter->link_tag($pageurl, "", $pagetext, "tabindex='{$idx}'") . "</li>\n"; $idx++; } $out .= "</ol></td>\n"; ksort($ends); $out .= "<td width='50%' valign='top'><ol>\n"; while (list($pagename, $i) = each($ends)) { $pageurl = _rawurlencode($pagename); $pagetext = htmlspecialchars(urldecode($pagename)); $out .= '<li>' . $formatter->link_tag($pageurl, "", $pagetext, "tabindex='{$idx}'") . "</li>\n"; $idx++; } $out .= "</ol>\n</td></tr></table>\n"; $hits += count($starts) + count($ends); } if (empty($hits)) { $out .= "<h3>" . _("No similar pages found") . "</h3>"; } $opts['msg'] = sprintf(_("Like \"%s\""), $value); while (empty($metawiki)) { if (empty($DBInfo->metadb)) { $DBInfo->initMetaDB(); } if (empty($DBInfo->metadb) or empty($DBInfo->shared_metadb)) { break; } $opts['extra'] = _("If you can't find this page, "); if (empty($hits) and empty($metawiki) and !empty($DBInfo->metadb)) { $opts['extra'] = _("You are strongly recommened to find it in MetaWikis. "); } $tag = $formatter->link_to("?action=LikePages&metawiki=1", _("Search all MetaWikis")); $opts['extra'] .= "{$tag} (" . _("Slow Slow") . ")<br />"; break; } return $out; }
function do_post_Draw($formatter, $options = array()) { global $DBInfo; $enable_replace = 1; $keyname = $DBInfo->_getPageKey($options['page']); $_dir = str_replace("./", '', $DBInfo->upload_dir . '/' . $keyname); $pagename = $options['page']; // support hashed upload dir if (!is_dir($_dir) and !empty($DBInfo->use_hashed_upload_dir)) { $prefix = get_hashed_prefix($keyname); $_dir = str_replace('./', '', $DBInfo->upload_dir . '/' . $prefix . $keyname); } umask(00); if (!file_exists($_dir)) { _mkdir_p($_dir, 0777); } $name = $options['value']; if (!empty($_FILES['filepath'])) { $upfile = $_FILES['filepath']['tmp_name']; $temp = explode("/", $_FILES['filepath']['name']); $upfilename = $temp[count($temp) - 1]; preg_match("/(.*)\\.([a-z0-9]{1,4})\$/i", $upfilename, $fname); # do not change the extention of the file. $file_path = $newfile_path = $_dir . "/" . $upfilename; # is file already exists ? $dummy = 0; while (file_exists($newfile_path)) { $dummy = $dummy + 1; $ufname = $fname[1] . "_" . $dummy; // rename file $upfilename = $ufname . ".{$fname['2']}"; $newfile_path = $_dir . "/" . $upfilename; } if ($enable_replace) { if ($file_path != $newfile_path) { $test = @copy($file_path, $newfile_path); } $test = @copy($upfile, $file_path); } else { $test = @copy($upfile, $newfile_path); } if (!$test) { $title = sprintf(_("Fail to copy \"%s\" to \"%s\""), $upfilename, $file_path); $formatter->send_header("Status: 406 Not Acceptable", $options); $formatter->send_title($title, "", $options); return; } if ($fname[2] == 'map') { # fix map file. $map = file($newfile_path); $map = implode('', $map); # remove useless areas $map = preg_replace('/HREF="%TWIKIDRAW%"/', 'nohref', $map); $fp = fopen($newfile_path, 'w'); if ($fp) { fwrite($fp, $map); fclose($fp); } } chmod($newfile_path, 0644); if ($fname[2] == 'draw') { $comment = sprintf("Drawing '%s' uploaded", $upfilename); $REMOTE_ADDR = $_SERVER['REMOTE_ADDR']; $DBInfo->addLogEntry($keyname, $REMOTE_ADDR, $comment, "ATTDRW"); } return; } if (!$name) { $title = _("Fatal error !"); $formatter->send_header("Status: 406 Not Acceptable", $options); $formatter->send_title($title, "", $options); print "<h2>" . _("No filename given") . "</h2>"; $formatter->send_footer("", $options); return; } $gifname = _rawurlencode($name); if (empty($_GET['mode']) or $_GET['mode'] != 'attach') { $gifname = 'Draw_' . $gifname; } $imgpath = "{$_dir}/{$gifname}"; $ufname = $gifname; $dummy = 0; while (file_exists($imgpath)) { $dummy = $dummy + 1; $ufname = $gifname . "_" . $dummy; // rename file $imgpath = "{$_dir}/{$ufname}"; } $draw_url = "{$DBInfo->upload_dir_url}/{$keyname}/{$ufname}.draw"; $gif_url = "{$DBInfo->upload_dir_url}/{$keyname}/{$ufname}.gif"; $formatter->send_header("", $options); $formatter->send_title(_("Edit drawing"), "", $options); $prefix = $formatter->prefix; $now = time(); $url_exit = $formatter->link_url($options['page'], "?ts={$now}"); $url_save = $formatter->link_url($options['page'], "?action=draw"); $url_help = $formatter->link_url("HotDraw"); $pubpath = $DBInfo->url_prefix . "/applets/TWikiDrawPlugin"; print "<h2>" . _("Edit new drawing") . "</h2>\n"; print <<<APPLET <applet code="CH.ifa.draw.twiki.TWikiDraw.class" archive="twikidraw.jar" codebase="{$pubpath}" width='500' height='40' align="center"> <param name="drawpath" value="{$draw_url}"> <param name="gifpath" value="{$gif_url}"> <param name="savepath" value="{$url_save}"> <param name="viewpath" value="{$url_exit}"> <param name="helppath" value="{$url_help}"> <b>NOTE:</b> You need a Java enabled browser to edit the drawing example. </applet><br /> APPLET; $formatter->send_footer("", $options); return; }
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>'; }
function macro_Gallery($formatter, $value, &$options) { global $DBInfo; # add some actions at the bottom of the page if (!$value and !in_array('UploadFile', $formatter->actions)) { $formatter->actions[] = 'UploadFile'; $formatter->actions[] = 'UploadedFiles'; } $default_column = 3; $default_row = 4; $col = (!empty($options['col']) and $options['col'] > 0) ? (int) $options['col'] : 0; $row = (!empty($options['row']) and $options['row'] > 0) ? (int) $options['row'] : 0; $sort = !empty($options['sort']) ? $options['sort'] : ''; $nocomment = !empty($options['nocomment']) ? $options['nocomment'] : ''; $href_attr = ''; if (!empty($DBInfo->gallery_use_lightbox) and !empty($DBInfo->use_lightbox)) { $use_lightbox = 1; if (is_string($DBInfo->gallery_use_lightbox)) { $href_attr = ' rel="' . $DBInfo->gallery_use_lightbox . '[gallery]" '; } else { $href_attr = ' rel="lightbox[gallery]" '; } } // parse args preg_match("/^(('|\")([^\\2]+)\\2)?,?(\\s*,?\\s*.*)?\$/", $value, $match); $opts = explode(',', $match[4]); foreach ($opts as $opt) { if ($opt == 'showall') { $show_all = 1; } else { if ($opt == 'nocomment') { $nocomment = 1; } else { if (($p = strpos($opt, '=')) !== false) { $k = substr($opt, 0, $p); $v = substr($opt, $p + 1); if ($k == 'col') { $col = $v; } else { if ($k == 'row') { $row = $v; } else { if ($k == 'sort') { $sort = $v; } } } } else { if ($opt == 'sort') { $sort = 1; } } } } } if (!in_array($sort, array(0, 1, 'name', 'date'))) { $sort = 0; } $img_default_width = 150; $col_td_width = ''; if ($col > 1) { $col_td_width = (int) (100 / $col); $col_td_width = ' width="' . $col_td_width . '%"'; $img_default_width = (int) (100 / $col) * 5; // XXX assume 500px } $default_width = !empty($DBInfo->gallery_img_width) ? $DBInfo->gallery_img_width : 600; $img_class = "gallery-img"; $col = ($col <= 0 or $col > 10) ? $default_column : $col; $row = ($row <= 0 or $row > 7) ? $default_row : $row; $perpage = $col * $row; $img_style = ''; if ($col == 1) { $img_style = ' style="float:left"'; } if (!empty($match[3])) { # arg has a pagename $value = $match[3]; } else { $value = $formatter->page->name; } $key = $DBInfo->pageToKeyname($value); if ($key != $value) { $prefix = $formatter->link_url(_rawurlencode($value), "?action=download&value="); } $dir = $DBInfo->upload_dir . "/{$key}"; if (empty($prefix)) { $prefix = $DBInfo->url_prefix . "/" . $dir . "/"; } if (!file_exists($dir)) { umask(00); mkdir($dir, 0777); } $top_link = ''; $bot_link = ''; $upfiles = array(); $comments = array(); if (file_exists($dir . "/list.txt")) { $cache = file($dir . "/list.txt"); foreach ($cache as $line) { #list($name,$mtime,$comment)=explode("\t",rtrim($line),3); $tmp = explode("\t", rtrim($line), 3); $name = $tmp[0]; $upfiles[$name] = $tmp[1]; if (isset($tmp[2])) { $comments[$name] = $tmp[2]; } } } if ($sort) { if ($sort == 1) { arsort($upfiles); } elseif ($sort == 'name') { ksort($upfiles); } } else { asort($upfiles); } if (!empty($options['value'])) { $file = urldecode($options['value']); } if (!empty($file) and !empty($upfiles[$file]) and !empty($options['comments'])) { // admin: edit all comments $comment = _stripslashes($options['comments']); $comment = str_replace("<", "<", $comment); $comment = str_replace("\r", "", $comment); $comment = preg_replace("/\n----\n/", "\t", $comment); $comment = str_replace("\n", "\\n", $comment); $comments[$file] = $comment; $update = 1; } else { if (!empty($file) and !empty($upfiles[$file]) and !empty($options['comment'])) { // add new comment $comment = $text = _stripslashes($options['comment']); // spam filtering $fts = preg_split('/(\\||,)/', $DBInfo->spam_filter); foreach ($fts as $ft) { $text = $formatter->filter_repl($ft, $text, $options); } if ($text != $comment) { $options['err'] = _("Sorry, can not save page because some messages are blocked in this wiki."); } else { if ($options['id'] == 'Anonymous') { $name = $_SERVER['REMOTE_ADDR']; } else { $name = $options['id']; } if ($options['name']) { $name = $options['name']; } $date = date("(Y-m-d H:i:s) "); $comment = str_replace("\r", "", $comment); $comment = str_replace("\n", "\\n", $comment); $comment = str_replace("\t", " ", $comment); $comment = str_replace("<", "<", $comment); $comment .= " -- {$name} {$date}"; $comments[$file] = $comment . "\t" . $comments[$file]; $update = 1; } } else { if (!empty($file) and !empty($upfiles[$file])) { // show comments of the selected item $mtime = $upfiles[$file]; $comment = !empty($comments[$file]) ? $comments[$file] : ''; $values = array_keys($upfiles); $prev_value = $values[array_search($file, $values) - 1]; $next_value = $values[array_search($file, $values) + 1]; unset($values); $upfiles = array(); $comments = array(); $upfiles[$file] = $mtime; $comments[$file] = $comment; $selected = 1; $img_class = "gallery-sel"; if (!empty($prev_value)) { $prev_link = "<div class='gallery-prev-link'><a href='" . $formatter->link_url($formatter->page->urlname, "?action=gallery&value={$prev_value}") . "'><span class='gallery-prev-text'>«Prev</span></a></div>"; } else { $prev_link = ''; } if (!empty($next_value)) { $next_link = "<div class='gallery-next-link'><a href='" . $formatter->link_url($formatter->page->urlname, "?action=gallery&value={$next_value}") . "'><span class='gallery-next-text'>Next»</span></a></div>"; } else { $next_link = ''; } if (!empty($next_link) or !empty($prev_link)) { $top_link = "<div class='gallery-top-link'>{$prev_link}{$next_link}</div>"; $bot_link = "<div class='gallery-bottom-link'>{$prev_link}{$next_link}</div>"; } } } } $width = !empty($selected) ? $default_width : $img_default_width; $thumb_width = !empty($DBInfo->thumb_width) ? $DBInfo->thumb_width : '250'; $mtime = file_exists($dir . "/list.txt") ? filemtime($dir . "/list.txt") : 0; if (filemtime($dir) > $mtime or !empty($update)) { unset($upfiles); $handle = opendir($dir); $cache = ''; $cr = ''; while ($file = readdir($handle)) { if ($file[0] == '.' or $file == 'list.txt' or is_dir($dir . "/{$file}")) { continue; } $mtime = filemtime($dir . "/" . $file); $cache .= $cr . $file . "\t" . $mtime; $upfiles[$file] = $mtime; if (!empty($comments[$file])) { $cache .= "\t" . $comments[$file]; } $cr = "\n"; } closedir($handle); $fp = @fopen($dir . "/list.txt", 'w'); if ($fp) { fwrite($fp, $cache); fclose($fp); } } if (empty($upfiles)) { return "<h3>" . _("No files found") . "</h3>\n"; } $out = "<table width='100%' border='0' cellpadding='2'>\n<tr>\n"; $idx = 1; $pages = intval(sizeof($upfiles) / $perpage); if (sizeof($upfiles) % $perpage) { $pages++; } if (!empty($options['p']) and $options['p'] > 1) { $slice_index = $perpage * intval($options['p'] - 1); $upfiles = array_slice($upfiles, $slice_index); } $extra = $sort ? "&sort=" . $sort : ''; $extra .= $nocomment ? "&nocomment=1" : ''; $pnut = ''; if ($pages > 1) { $pnut = get_pagelist($formatter, $pages, '?action=gallery&col=' . $col . '&row=' . $row . $extra . '&p=', !empty($options['p']) ? $options['p'] : '', $perpage); } if (!file_exists($dir . "/thumbnails")) { @mkdir($dir . "/thumbnails", 0777); } while (list($file, $mtime) = each($upfiles)) { $size = filesize($dir . "/" . $file); $id = rawurlencode($file); $linksrc = $key == $value ? $prefix . $id : str_replace('value=', 'value=' . $id, $prefix); $link = (!empty($selected) or !empty($use_lightbox)) ? $linksrc : $formatter->link_url($formatter->page->urlname, "?action=gallery{$extra}&value={$id}"); $date = date("Y-m-d", $mtime); if (preg_match("/\\.(jpg|jpeg|gif|png)\$/i", $file)) { if (!empty($DBInfo->use_convert_thumbs) and !file_exists($dir . "/thumbnails/" . $file)) { if (function_exists('gd_info')) { $fname = $dir . '/' . $file; list($w, $h) = getimagesize($fname); if ($w > $thumb_width) { $nh = $thumb_width * $h / $w; $thumb = imagecreatetruecolor($thumb_width, $nh); // XXX only jpeg for testing now. if (preg_match("/\\.(jpg|jpeg)\$/i", $file)) { $imgtype = 'jpeg'; } else { if (preg_match("/\\.png\$/i", $file)) { $imgtype = 'png'; } else { if (preg_match("/\\.gif\$/i", $file)) { $imgtype = 'gif'; } } } $myfunc = 'imagecreatefrom' . $imgtype; $source = $myfunc($fname); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $nh, $w, $h); #imagecopyresized($thumb, $source, 0,0,0,0, $thumb_width, $nh, $w, $h); $myfunc = 'image' . $imgtype; $myfunc($thumb, $dir . '/thumbnails/' . $file); } } else { $fp = popen("convert -scale " . $thumb_width . " " . $dir . "/" . $file . " " . $dir . "/thumbnails/" . $file . $formatter->NULL, 'r'); @pclose($fp); } } if (empty($selected) and file_exists($dir . "/thumbnails/" . $file)) { $thumb = $key == $value ? $prefix . 'thumbnails/' . $id : str_replace('value=', 'value=thumbnails/' . $id, $prefix); if ($thumb_width > $width) { $mywidth = " width='" . $width . "' "; } else { $mywidth = ''; } $object = "<img class='imgGallery' src='{$thumb}' {$mywidth} alt='{$file}' />"; } else { $nwidth = $width; if (function_exists('getimagesize')) { list($nwidth, $height, $type, $attr) = getimagesize($dir . '/' . $file); $nwidth = $nwidth > $width ? $width : $nwidth; } $object = "<img class='imgGallery' src='{$linksrc}' width='{$nwidth}' alt='{$file}' />"; } } else { $object = $file; } $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB'); $i = 0; for (; $i < 4; $i++) { if ($size <= 1024) { $size = round($size, 2) . ' ' . $unit[$i]; break; } $size = $size / 1024; } # $size=round($size,2).' '.$unit[$i]; $comment = ''; if ($width > 100) { $comment_btn = ''; $comment_btn = $nocomment ? '' : _("add comment"); $imginfo = (!$nocomment or $selected) ? "{$date} ({$size}) " : ''; if (!empty($comments[$file]) and !empty($options['value'])) { $comment = $comments[$file]; $comment = str_replace("\\n", "\n", $comment); $options['comments'] = str_replace("\t", "\n----\n", $comment); $comment = str_replace("\t", "<div class='separator'><hr /></div>", $comment); $comment = str_replace("\n", "<br/>\n", $comment); } else { if ((empty($nocomment) or !empty($selected)) and !empty($comments[$file])) { if (empty($show_all)) { $comment_btn = _("show comments"); //list($comment,$dum)=explode("\t",$comments[$file],2); $tmp = explode("\t", $comments[$file], 2); $comment = $tmp[0]; } else { $comment_btn = _("add comment"); $comment = str_replace("\t", "<div class='separator'><hr /></div>\n", $comments[$file]); } $comment = str_replace("\\n", "<br/>\n", $comment); } } } $out .= "<td {$col_td_width} align='center' valign='top'>{$top_link}<div class='{$img_class}' {$img_style}><a href='{$link}'{$href_attr}>{$object}</a>"; if (!empty($imginfo)) { $out .= "<br />" . $imginfo; } if (!empty($comment_btn)) { $out .= '[' . $formatter->link_tag($formatter->page->urlname, "?action=gallery&value={$id}", $comment_btn) . "]<br />\n"; } $out .= '</div>' . $bot_link; if (!empty($comment)) { $out .= "<div class='gallery-comments'>{$comment}</div>"; } $out .= "</td>\n"; if ($idx % $col == 0) { $out .= "</tr>\n<tr>\n"; } $idx++; if ($idx > $perpage) { break; } } $idx--; $out .= "</tr></table>\n"; if (!in_array('UploadFile', $formatter->actions)) { $formatter->actions[] = 'UploadFile'; } return $pnut . '<div class="gallery">' . $out . '</div>' . $pnut; }
function macro_Attachment($formatter, $value, $options = array()) { global $DBInfo; if (!is_array($options) and $options == 1) { $options = array('link' => 1); } // compatible $attr = ''; if (!empty($DBInfo->force_download) or !empty($DBInfo->pull_url)) { $force_download = 1; } if (!empty($DBInfo->download_action)) { $mydownload = $DBInfo->download_action; } else { $mydownload = 'download'; } $extra_action = ''; $pull_url = $fetch_url = ''; if (!empty($DBInfo->pull_url)) { $pull_url = $DBInfo->pull_url; if (empty($formatter->fetch_action)) { $fetch_url = $formatter->link_url('', '?action=fetch&url='); } else { $fetch_url = $formatter->fetch_action; } } $text = ''; $caption = ''; $cap_bra = ''; $cap_ket = ''; $bra = ''; $ket = ''; if ($options and !$DBInfo->security->is_allowed($mydownload, $options)) { return $text; } if (!empty($formatter->wikimarkup) and empty($options['nomarkup'])) { $ll = $rr = ''; if (strpos($value, ' ') !== false) { $ll = '['; $rr = ']'; } $bra = "<span class='wikiMarkup'><!-- wiki:\n{$ll}attachment:{$value}{$rr}\n-->"; $ket = '</span>'; } # if ($value[0]=='"' and ($p2=strpos(substr($value,1),'"')) !== false) # $value=substr($value,1,$p2); # attachment:"my image.png" => my image.png # FIXME attachment:"hello.png" => error if (($p = strpos($value, ' ')) !== false and strpos(substr($value, 0, $p), ',') === false) { // [[Attachment(my.png,width=100,height=200,caption="Hello(space)World")]] // [attachment:my.ext(space)hello] // [attachment:my.ext(space)attachment:my.png] // [attachment:my.ext(space)http://url/../my.png] if ($value[0] == '"' and ($p2 = strpos(substr($value, 1), '"')) !== false) { $text = $ntext = substr($value, $p2 + 3); $dummy = substr($value, 1, $p2); # "my image.png" => my image.png $args = substr($value, $p2 + 2); $value = $dummy . $args; # append query string } else { $text = $ntext = substr($value, $p + 1); $value = substr($value, 0, $p); } if (substr($text, 0, 11) == 'attachment:') { $fname = substr($text, 11); $ntext = macro_Attachment($formatter, $fname, array('link' => 1)); } if (preg_match("/\\.(png|gif|jpeg|jpg|bmp)\$/i", $ntext)) { $_l_ntext = _l_filename($ntext); if (!file_exists($_l_ntext)) { $fname = preg_replace('/^"([^"]*)"$/', "\\1", $fname); $mydownload = 'UploadFile&rename=' . $fname; $text = sprintf(_("Upload new Attachment \"%s\""), $fname); $text = str_replace('"', '\'', $text); } $ntext = qualifiedUrl($DBInfo->url_prefix . '/' . $ntext); $img_link = '<img src="' . $ntext . '" alt="' . $text . '" border="0" />'; } else { if (($q = strpos($ntext, ',')) !== false) { $alt = substr($ntext, 0, $q); $caption = substr($ntext, $q + 1); } else { $alt = $ntext; } } } else { $value = str_replace('%20', ' ', $value); } $lightbox_attr = ''; $imgalign = ''; // allowed thumb widths. $thumb_widths = isset($DBInfo->thumb_widths) ? $DBInfo->thumb_widths : array('120', '240', '320', '480', '600', '800', '1024'); // parse query string of macro arguments if ($dummy = strpos($value, '?')) { # for attachment: syntax parse_str(substr($value, $dummy + 1), $attrs); $value = substr($value, 0, $dummy); } else { if (($dummy = strpos($value, ',')) !== false) { # for Attachment macro $tmp = substr($value, $dummy + 1); $tmp = preg_replace('/,+\\s*/', ',', $tmp); $tmp = preg_replace('/\\s*=\\s*/', '=', $tmp); $tmp = str_replace(',', '&', $tmp); parse_str($tmp, $attrs); $value = substr($value, 0, $dummy); } } $use_thumb = !empty($DBInfo->use_thumb_by_default) && empty($options['link_url']) ? true : false; if (!empty($attrs)) { if (!empty($attrs['action'])) { // check extra_action if ($attrs['action'] == 'deletefile') { $extra_action = $attrs['action']; } else { $mydownload = $attrs['action']; } unset($attrs['action']); } foreach ($attrs as $k => $v) { if (in_array($k, array('width', 'height'))) { $attr .= "{$k}=\"{$v}\" "; if (!empty($DBInfo->use_lightbox)) { $lightbox_attr = ' rel="lightbox" '; } } else { if ($k == 'align') { $imgalign = 'img' . ucfirst($v); } else { if (in_array($k, array('caption', 'alt', 'title'))) { $caption = preg_replace("/^([\"'])([^\\1]+)\\1\$/", "\\2", $v); $caption = trim($caption); } else { if (in_array($k, array('thumb', 'thumbwidth', 'thumbheight'))) { if ($k == 'thumbwidth' || $k == 'thumbheight') { if (!empty($thumb_widths)) { if (in_array($v, $thumb_widths)) { $thumb[$k] = $v; } } else { $thumb[$k] = $v; } } else { $thumb[$k] = $v; } } } } } } if (!empty($thumb)) { $use_thumb = true; } } if (preg_match('/^data:image\\/(gif|jpe?g|png);base64,/', $value)) { // need to hack for IE ? return "<img src='" . $value . "' {$attr} />"; } $attr .= $lightbox_attr; $info = ''; if (($p = strrpos($value, ':')) !== false or ($p = strrpos($value, '/')) !== false) { $subpage = substr($value, 0, $p); $file = substr($value, $p + 1); $value = $subpage . '/' . $file; # normalize page arg if (isset($subpage[0])) { $pagename = $subpage; $key = $DBInfo->pageToKeyname($subpage); $value = $file; } else { $pagename = ''; $key = ''; } } else { $pagename = $formatter->page->name; $key = $DBInfo->pageToKeyname($formatter->page->name); $file = $value; } if (isset($key[0])) { $dir = $DBInfo->upload_dir . '/' . $key; // support hashed upload_dir if (!is_dir($dir) and !empty($DBInfo->use_hashed_upload_dir)) { $pre = get_hashed_prefix($key); $dir = $DBInfo->upload_dir . '/' . $pre . $key; if (!is_dir($dir)) { $dir = $DBInfo->upload_dir; } } } else { $dir = $DBInfo->upload_dir; } // check file name XXX if (!$file) { if (!empty($options['link']) and $options['link'] == 1) { return 'attachment:' . $value; } return $bra . 'attachment:/' . $ket; } $upload_file = $dir . '/' . $file; if (!empty($options['link']) and $options['link'] == 1) { return $upload_file; } if (!$text) { $text = $file; } $_l_file = _l_filename($file); $_l_upload_file = $dir . '/' . $_l_file; if (file_exists($_l_upload_file)) { $file_ok = 1; } else { if (!empty($pull_url)) { if (isset($subpage[0])) { $pagename = $subpage; $val = _urlencode($file); } else { $val = _urlencode($value); } $url = $pull_url . _rawurlencode($pagename) . "?action={$mydownload}&value=" . $val; $hsz = $formatter->macro_repl('ImageFileSize', $url); $info = ' (' . $hsz . ')'; $url = $fetch_url . str_replace(array('&', '?'), array('%26', '%3f'), $url); // check url to retrieve the size of file if (empty($formatter->preview) or floatval($sz) != 0) { $file_ok = 2; } } } if (empty($file_ok) and !empty($formatter->wikimarkup) and empty($options['nomarkup'])) { if (!empty($DBInfo->swfupload_depth) and $DBInfo->swfupload_depth > 2) { $depth = $DBInfo->swfupload_depth; } else { $depth = 2; } if (session_id() == '') { // ip based $myid = md5($_SERVER['REMOTE_ADDR'] . '.' . 'MONIWIKI'); // FIXME } else { $myid = session_id(); } $prefix = substr($myid, 0, $depth); $mydir = $DBInfo->upload_dir . '/.swfupload/' . $prefix . '/' . $myid; if (file_exists($mydir . '/' . $_l_file)) { if (!$img_link && preg_match("/\\.(png|gif|jpeg|jpg|bmp)\$/i", $upload_file)) { $ntext = qualifiedUrl($DBInfo->url_prefix . '/' . $mydir . '/' . $text); $img_link = '<img src="' . $ntext . '" alt="' . $text . '" border="0" />'; return $bra . "<span class=\"attach\">{$img_link}</span>" . $ket; } else { $sz = filesize($mydir . '/' . $_l_file); $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB'); for ($i = 0; $i < 4; $i++) { if ($sz <= 1024) { #$sz= round($sz,2).' '.$unit[$i]; break; } $sz = $sz / 1024; } $info = ' (' . round($sz, 2) . ' ' . $unit[$i] . ') '; return $bra . "<span class=\"attach\">" . $formatter->icon['attach'] . $text . '</span>' . $info . $ket; } } } if (!empty($file_ok)) { $imgcls = 'imgAttach'; if ($imgalign == 'imgCenter' or $caption && empty($imgalign)) { if ($file_ok == 1 and !$attrs['width']) { $size = getimagesize($_l_upload_file); // XXX $attrs['width'] = $size[0]; } } $img_width = ''; if (!empty($attrs['width'])) { $img_width = ' style="width:' . $attrs['width'] . 'px"'; } if ($caption) { $cls = $imgalign ? 'imgContainer ' . $imgalign : 'imgContainer'; $cap_bra = '<div class="' . $cls . '"' . '>'; $cap_ket = '</div>'; $img_width = ''; } else { $imgcls = $imgalign ? 'imgAttach ' . $imgalign : 'imgAttach'; } if ($file_ok == 1) { $sz = filesize($_l_upload_file); $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB'); for ($i = 0; $i < 4; $i++) { if ($sz <= 1024) { break; } $sz = $sz / 1024; } $info = ' (' . round($sz, 2) . ' ' . $unit[$i] . ')'; } if (!in_array('UploadedFiles', $formatter->actions)) { $formatter->actions[] = 'UploadedFiles'; } if (empty($img_link) && preg_match("/\\.(png|gif|jpeg|jpg|bmp)\$/i", $upload_file, $m)) { // get the extension of the image $ext = $m[1]; $type = strtoupper($m[1]); if (!empty($caption)) { $caption = '<div class="caption">' . $caption . ' <span>[' . $type . ' ' . _("image") . $info . ']</span></div>'; } else { $caption = '<div class="info"><span>[' . $type . ' ' . _("image") . $info . ']</span></div>'; } if ($file_ok == 1 and !empty($use_thumb)) { $thumb_width = !empty($DBInfo->thumb_width) ? $DBInfo->thumb_width : 320; if (!empty($thumb['thumbwidth'])) { $thumb_width = $thumb['thumbwidth']; } // guess thumbnails $thumbfiles = array(); $thumbfiles[] = $_l_file; $thumbfiles[] = preg_replace('@' . $ext . '$@i', 'w' . $thumb_width . '.' . $ext, $_l_file); $thumb_ok = false; foreach ($thumbfiles as $thumbfile) { if (file_exists($dir . '/thumbnails/' . $thumbfile)) { $thumb_ok = true; break; } } // auto generate thumbnail if (!empty($DBInfo->use_convert_thumbs) and !$thumb_ok) { if (!file_exists($dir . "/thumbnails")) { @mkdir($dir . "/thumbnails", 0777); } $fname = $dir . '/' . $_l_file; list($w, $h) = getimagesize($fname); // generate thumbnail using the gd func or the ImageMagick(convert) if ($w > $thumb_width) { require_once 'lib/mediautils.php'; resize_image($ext, $fname, $dir . '/thumbnails/' . $thumbfile, $w, $h, $thumb_width); $thumb_ok = true; } } } $alt = !empty($alt) ? $alt : $file; if ($key != $pagename || !empty($force_download)) { $val = _urlencode($value); if ($thumb_ok and !empty($use_thumb)) { if (($p = strrpos($val, '/')) > 0) { $val = substr($val, 0, $p) . '/thumbnails/' . $thumbfile; } else { $val = 'thumbnails/' . $thumbfile; } // use download link ? if (!empty($DBInfo->use_thumb_with_download_link)) { $extra_action = 'download'; } } if ($file_ok == 2 and !empty($pull_url)) { if (isset($subpage[0])) { $pagename = $subpage; $val = _urlencode($file); } $url = $fetch_url . str_replace(array('&', '?'), array('%26', '%3f'), $pull_url . urlencode(_rawurlencode($pagename)) . "?action={$mydownload}&value=" . $val); if ($use_thumb and isset($thumb['thumb'])) { $url .= '&thumb=' . $thumb['thumb']; } } else { $url = $formatter->link_url(_rawurlencode($pagename), "?action={$mydownload}&value=" . $val); } } else { if ($thumb_ok and !empty($use_thumb)) { // FIXME $url = str_replace($DBInfo->upload_dir, $DBInfo->upload_dir_url, $dir . '/thumbnails/' . _urlencode($thumbfile)); } else { $_my_file = str_replace($DBInfo->upload_dir, $DBInfo->upload_dir_url, $dir . '/' . $file); $url = _urlencode($_my_file); } } if (!empty($options['link_url'])) { return qualifiedUrl($url); } $img = "<img src='{$url}' title='{$alt}' alt='{$alt}' style='border:0' {$attr}/>"; if ($extra_action) { $url = $formatter->link_url(_rawurlencode($pagename), "?action={$extra_action}&value=" . urlencode($value)); if ($file_ok == 2 and !empty($pull_url)) { if (isset($subpage[0])) { $pagename = $subpage; } $url = $fetch_url . str_replace(array('&', '?'), array('%26', '%3f'), $pull_url . urlencode(_rawurlencode($pagename)) . "?action={$mydownload}&value=" . $val); } $img = "<a href='{$url}'>{$img}</a>"; } else { if (preg_match('@^(https?|ftp)://@', $alt)) { $img = "<a href='{$alt}'>{$img}</a>"; } } return $bra . $cap_bra . "<div class=\"{$imgcls}\"><div>{$img}{$caption}</div></div>" . $cap_ket . $ket; #return $bra.$cap_bra."<span class=\"$cls\">$img$caption</span>".$cap_ket.$ket; } else { $mydownload = $extra_action ? $extra_action : $mydownload; $link = $formatter->link_url(_rawurlencode($pagename), "?action={$mydownload}&value=" . urlencode($value), $text); if (!empty($options['link_url'])) { return qualifiedUrl($link); } if (!empty($img_link)) { return $bra . "<span class=\"attach\"><a href='{$link}'>{$img_link}</a></span>" . $ket; } return $bra . "<span class=\"attach\">" . $formatter->icon['attach'] . '<a href="' . $link . '">' . $text . '</a></span>' . $info . $ket; } } // no attached file found. if (!empty($options['link_url'])) { return 'attachment:' . $value; } if ($formatter->_macrocache and empty($options['call'])) { return $formatter->macro_cache_repl('Attachment', $value); } if (empty($options['call'])) { $formatter->_dynamic_macros['@Attachment'] = 1; } $paste = ''; if (!empty($DBInfo->use_clipmacro) and preg_match('/^(.*)\\.png$/i', $file, $m)) { $now = time(); $url = $formatter->link_url($pagename, "?action=clip&value={$m['1']}&now={$now}"); $paste = " <a href='{$url}'>" . _("or paste a new png picture") . "</a>"; } if (!empty($DBInfo->use_drawmacro) and preg_match('/^(.*)\\.gif$/i', $file, $m)) { $now = time(); $url = $formatter->link_url($pagename, "?action=draw&mode=attach&value={$m['1']}&now={$now}"); $paste = " <a href='{$url}'>" . _("or draw a new gif picture") . "</a>"; } if ($pagename == $formatter->page->name) { return $bra . '<span class="attach">' . $formatter->link_to("?action=UploadFile&rename=" . urlencode($file), sprintf(_("Upload new Attachment \"%s\""), $file)) . $paste . '</span>' . $ket; } if (!$pagename) { $pagename = 'UploadFile'; } return $bra . '<span class="attach">' . $formatter->link_tag($pagename, "?action=UploadFile&rename=" . urlencode($file), sprintf(_("Upload new Attachment \"%s\" on the \"%s\""), $file, $pagename)) . $paste . '</span>' . $ket; }
function macro_Scrap($formatter, $value = '', $options = array()) { global $DBInfo; $user =& $DBInfo->user; # get cookie if ($user->id == 'Anonymous') { return ''; } $userinfo = $DBInfo->udb->getUser($user->id); $pages = array(); if (!empty($userinfo->info['scrapped_pages'])) { $pages = explode("\t", $userinfo->info['scrapped_pages']); } $scrapped = 0; $pgname = ''; if (!empty($formatter->page->name)) { $pgname = $formatter->page->name; if (!in_array($formatter->page->name, $pages)) { $pages[] = $options['page']; } else { $scrapped = 1; } } $out = ''; if ($value == 'js') { // get the scrapped pages dynamically $script = get_scriptname() . $DBInfo->query_prefix; $pgname = _rawurlencode($pgname); $js = <<<JS <script type="text/javascript"> /*<![CDATA[*/ (function() { var script_name = "{$script}"; var page_name = "{$pgname}"; function get_scrap() { var scrap = document.getElementById('scrap'); if (scrap == null) { // silently ignore return; } var pgname = decodeURIComponent(page_name); var scrapped = false; // get the scrapped pages var qp = '?'; // query_prefix var loc = '//' + location.host; if (location.port) loc+= ':' + location.port; loc+= location.pathname + qp + 'action=scrap/ajax'; var ret = HTTPGet(loc); if (ret) { var list = JSON.parse(ret); var html = ''; for (i = 0; i < list.length; i++) { if (list[i] == pgname) scrapped = true; html+= '<li><a href="' + script_name + list[i] + '">' + list[i] + "</a></li>\\n"; } if (html != '') scrap.innerHTML = "<ul>" + html + "</ul>"; if (scrapped) { // change scrap icon var iconmenu = document.getElementById("wikiIcon"); var icons = iconmenu.getElementsByTagName("A"); for (i = 0; i < icons.length; i++) { if (icons[i].href.match(/action=scrap/)) { icons[i].href = icons[i].href.replace(/=scrap/, '=scrap&unscrap=1'); icons[i].firstChild.firstChild.src = icons[i].firstChild.firstChild.src.replace('scrap', 'unscrap'); break; } } } } } // onload var oldOnload = window.onload; window.onload = function(ev) { try { oldOnload(); } catch(e) {}; get_scrap(); } })(); /*]]>*/ </script> JS; #$formatter->register_javascripts('local/scrap.js'); $formatter->register_javascripts($js); return '<i></i>'; // dummy } foreach ($pages as $p) { if ($DBInfo->hasPage($p)) { $out .= '<li>' . $formatter->link_tag(_urlencode($p), '', $p) . '</li>'; } else { if (!empty($p)) { $list = $formatter->macro_repl('PageList', $p, array('rawre' => 1)); if (empty($list)) { $out .= substr($list, 4, -6); } } } } if (!empty($out)) { return '<ul>' . $out . '</ul>'; } return ''; }
function do_rss_rc($formatter, $options) { global $DBInfo, $Config; // get members to hide log $members = $DBInfo->members; $days = !empty($DBInfo->rc_days) ? $DBInfo->rc_days : RSS_DEFAULT_DAYS; $options['quick'] = 1; if (!empty($options['c'])) { $options['items'] = $options['c']; } $lines = $DBInfo->editlog_raw_lines($days, $options); if (!empty($DBInfo->rss_rc_options)) { $opts = $DBInfo->rss_rc_options; $opts = explode(',', $opts); foreach ($opts as $opt) { $options[$opt] = 1; // FIXME } } // HTTP conditional get $mtime = $DBInfo->mtime(); $lastmod = gmdate('D, d M Y H:i:s \\G\\M\\T', $mtime); $cache_ttl = !empty($DBInfo->rss_rc_ttl) ? $DBInfo->rss_rc_ttl : 60; /* 60 seconds */ // make etag based on some options and mtime. $check_opts = array('quick', 'items', 'oe', 'diffs', 'raw', 'nomsg', 'summary'); $check = array(); foreach ($check_opts as $c) { if (isset($options[$c])) { $check[$c] = $options[$c]; } } $etag = md5($mtime . $DBInfo->logo_img . serialize($check) . $cache_ttl . $options['id']); $headers = array(); $headers[] = 'Pragma: cache'; $maxage = $cache_ttl; $public = 'public'; if ($options['id'] != 'Anonymous') { $public = 'private'; } $headers[] = 'Cache-Control: ' . $public . ', max-age=' . $maxage; $headers[] = 'Last-Modified: ' . $lastmod; $headers[] = 'ETag: "' . $etag . '"'; $need = http_need_cond_request($mtime, $lastmod, $etag); if (!$need) { $headers[] = 'HTTP/1.0 304 Not Modified'; } foreach ($headers as $h) { header($h); } if (!$need) { @ob_end_clean(); return; } $cache = new Cache_Text('rss_rc'); $cache_delay = min($cache_ttl, 30); $mtime = $cache->mtime($etag); $val = false; if (empty($formatter->refresh)) { if (($val = $cache->fetch($etag)) !== false and $DBInfo->checkUpdated($mtime, $cache_delay)) { header("Content-Type: text/xml"); echo $val; return; } } // need to update cache if ($val !== false and $cache->exists($etag . '.lock')) { header("Content-Type: text/xml"); echo $val . '<!-- cached at ' . date('Y-m-d H:i:s', $mtime) . ' -->'; return; } if ($cache->exists($etag . '.lock')) { header("Content-Type: text/xml"); echo ''; return; } $cache->update($etag . '.lock', array('lock'), 5); // 5s lock $time_current = time(); # $secs_per_day= 60*60*24; # $days_to_show= 30; # $time_cutoff= $time_current - ($days_to_show * $secs_per_day); $URL = qualifiedURL($formatter->prefix); $img_url = qualifiedURL($DBInfo->logo_img); $url = qualifiedUrl($formatter->link_url("RecentChanges")); $channel = <<<CHANNEL <channel rdf:about="{$URL}"> <title>{$DBInfo->sitename}</title> <link>{$url}</link> <description>RecentChanges at {$DBInfo->sitename}</description> <image rdf:resource="{$img_url}"></image> <items> <rdf:Seq> CHANNEL; $items = ""; $ratchet_day = FALSE; if (!$lines) { $lines = array(); } foreach ($lines as $line) { $parts = explode("\t", $line); $page_name = $DBInfo->keyToPagename($parts[0]); // hide log if (!empty($members) && !in_array($options['id'], $members) && !empty($Config['ruleset']['hidelog'])) { if (in_array($page_name, $Config['ruleset']['hidelog'])) { continue; } } $addr = $parts[1]; $ed_time = $parts[2]; $user = $parts[4]; $log = _stripslashes($parts[5]); $act = rtrim($parts[6]); # if ($ed_time < $time_cutoff) # break; $url = qualifiedUrl($formatter->link_url(_rawurlencode($page_name))); $diff_url = qualifiedUrl($formatter->link_url(_rawurlencode($page_name), '?action=diff')); $extra = "<br /><a href='{$diff_url}'>" . _("show changes") . "</a>\n"; if (!$DBInfo->hasPage($page_name)) { $status = 'deleted'; $html = '<![CDATA[' . "<a href='{$url}'>" . $page_name . "</a> is deleted" . ']]>' . "\n"; } else { $status = 'updated'; if (!empty($options['diffs'])) { $p = new WikiPage($page_name); $f = new Formatter($p); $options['raw'] = 1; $options['nomsg'] = 1; $html = $f->macro_repl('Diff', '', $options); if (!$html) { ob_start(); $f->send_page('', array('fixpath' => 1)); #$f->send_page(''); $html = ob_get_contents(); ob_end_clean(); $extra = ''; } $html = str_replace(']', ']', $html); $html = "<![CDATA[" . $html . $extra . "]]>"; #$html=strtr($html.$extra,array('&'=>'&','<'=>'<')); } else { if (!empty($options['summary'])) { $p = new WikiPage($page_name); $f = new Formatter($p); $f->section_edit = 0; $f->sister_on = 0; $f->perma_icon = ''; $options['nomsg'] = 1; $b = $p->_get_raw_body(); $chunks = preg_split('/\\n#{4,}/', $b); # summary breaker is #### ob_start(); if ($chunks) { $f->send_page($chunks[0], array('fixpath' => 1)); } else { $f->send_page('', array('fixpath' => 1)); } #$f->send_page(''); $html = ob_get_contents(); ob_end_clean(); $chunks = preg_split('/<!-- break -->/', $html); # <!-- break --> if ($chunks[0]) { $html = $chunks[0]; } $html = str_replace(']', ']', $html); $html = "<![CDATA[" . $html . "]]>"; } else { $html = str_replace('&', '&', $log); } } } $zone = "+00:00"; $date = gmdate("Y-m-d\\TH:i:s", $ed_time) . $zone; #$datetag = gmdate("YmdHis",$ed_time); $channel .= "<rdf:li rdf:resource=\"{$url}\"></rdf:li>\n"; $valid_page_name = preg_replace('/&(?!#?\\w+;)/', '&', _html_escape($page_name)); $items .= "<item rdf:about=\"{$url}\">\n"; $items .= " <title>{$valid_page_name}</title>\n"; $items .= " <link>{$url}</link>\n"; $items .= " <description>{$html}</description>\n"; $items .= " <dc:date>{$date}</dc:date>\n"; $items .= "<dc:creator>{$user}</dc:creator>\n"; $items .= "<dc:contributor>{$user}</dc:contributor>\n"; # $items.=" <dc:contributor>\n <rdf:Description>\n" # ." <rdf:value>$user</rdf:value>\n" # ." </rdf:Description>\n </dc:contributor>\n"; $items .= " <wiki:status>{$status}</wiki:status>\n"; $items .= " <wiki:diff>{$diff_url}</wiki:diff>\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 (!empty($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}"?> <?xml-stylesheet href="{$DBInfo->url_prefix}/css/_feed.css" type="text/css"?> <rdf:RDF xmlns="http://purl.org/rss/1.0/" \txmlns:wiki="http://purl.org/rss/1.0/modules/wiki/" \txmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" \txmlns:xlink="http://www.w3.org/1999/xlink" \txmlns:dc="http://purl.org/dc/elements/1.1/"> <!-- Add "diffs=1" to add change diffs to the description of each items. Add "summary=1" to add summary to the description of each items. Add "oe=utf-8" to convert the charset of this rss to UTF-8. --> HEAD; header("Content-Type: text/xml"); if ($new) { $out = $head . $new; } else { $out = $head . $channel . $items . $form; } $out .= "</rdf:RDF>\n"; echo $out; $cache->update($etag, $out); $cache->remove($etag . '.lock'); }
function do_OeKaki($formatter, $options) { global $DBInfo; if ($_SERVER['REQUEST_METHOD'] == 'POST' && !$DBInfo->security->writable($options)) { $options['title'] = _("Page is not writable"); return do_invalid($formatter, $options); } $oekaki_dir = $DBInfo->upload_dir . '/OeKaki'; $pagename = $options['page']; $name = $options['value']; # $fp=fopen('php://stderr','w'); # fputs($fp,"name=$name\n"); # fputs($fp,"page=$options[page]\n"); # if ($_SERVER['REQUEST_METHOD']=='POST') { # $len = $_SERVER['CONTENT_LENGTH']; # fputs($fp,"len=$len\n"); # fputs($fp,"method=POST\n"); # } if (!$name) { $name = time(); } # XXX $pngname = 'OeKaki_' . _rawurlencode($name); $imgurl = "{$DBInfo->url_prefix}/{$oekaki_dir}/{$pngname}.png"; $imgpath = "{$oekaki_dir}/{$pngname}.png"; $dummy = 0; $backup_imgpath = $imgpath; while (file_exists($backup_imgpath)) { $dummy = $dummy + 1; $ufname = $pngname . "_" . $dummy; // rename file $upfilename = $ufname . ".png"; $backup_imgpath = "{$oekaki_dir}/{$upfilename}"; } if ($GLOBALS['HTTP_RAW_POST_DATA']) { if ($formatter->page->exists()) { $body = $formatter->page->get_raw_body(); } else { $body = ''; } if (!preg_match("/\n?\\[\\[OeKaki\\({$name}\\)\\]\\]\n?/i", $body)) { if (preg_match("/\n##Draw\n/i", $body)) { $body = preg_replace("/\n##Draw\n/", "\n##Draw\n[[OeKaki({$name})]]\n", $body); } else { $body .= "[[OeKaki({$name})]]\n"; } $log = "Oekaki drawing added"; $formatter->page->write($body); # XXX Oekaki post does not hav any information about user id. $DBInfo->savePage($formatter->page, $log, $options); } if ($backup_imgpath != $imgpath) { copy($imgpath, $backup_imgpath); } $raw = $GLOBALS['HTTP_RAW_POST_DATA']; $p = strpos($raw, "\r"); if ($p < 0) { header("Content-type: text/plain"); print "error\n\n"; } else { $img = fopen($imgpath, 'w'); if (is_resource($img)) { fwrite($img, substr($raw, $p + 2)); fclose($img); } } header("Content-type: text/plain"); print "ok\n\n"; print $imgpath; return; } if ($options['size'] and preg_match("/(\\d{3})x(\\d{3})/", $options['size'], $match)) { $sizex = $match[1]; $sizey = $match[2]; if ($sizex < 100 or $sizex > 600) { $sizex = 300; } if ($sizey < 100 or $sizey > 600) { $sizey = 300; } } else { $sizex = 300; $sizey = 300; } $extra = "<param name='image_canvas' value='{$imgurl}'>"; $formatter->send_header("", $options); $formatter->send_title(_("Create new picture"), "", $options); $prefix = $formatter->prefix; $now = time(); $urlpgname = _rawurlencode($options['page']); $imgname = _rawurlencode($name); $url_exit = $formatter->link_url($urlpgname, "?ts={$now}"); $url_save = $formatter->link_url($urlpgname, "----OeKaki----{$imgname}"); $pubpath = $DBInfo->url_prefix . "/applets/OekakiPlugin"; print "<h2>" . _("Edit Image") . "</h2>\n"; print <<<APPLET <applet code="pbbs.PaintBBS.class" archive="PaintBBS.jar" codebase="{$pubpath}" name="{$pngname}.png" width="400" height="400" align="center"> <param name="image_width" value="{$sizex}"> <param name="image_height" value="{$sizey}"> <param name="image_bkcolor" value="#ffffff"> {$extra} <param name="image_jpeg" value="true"> <param name="image_size" value="60"> <param name="compress_level" value="15"> <param name="undo" value="60"> <param name="undo_in_mg" value="15"> <param name="color_text"value="#708090"> <param name="color_bk" value="#A0A0BB"> <param name="color_bk2" value="#A0A0BB"> <param name="color_icon" value="#eeeeee"> <param name="color_bar" value="#8f93a1"> <param name="color_bar_hl" value="#ffffff"> <param name="color_bar_frame_hl" value="#eeeeee"> <param name="color_bar_frame_shadow" value="#aaaaaa"> <param name="bar_size" value="15"> <param name="url_save" value="{$url_save}"> <param name="url_exit" value="{$url_exit}"> <param name="tool_advance" value="true"> <param name="send_advance" value="true"> <param name="send_header" value=""> <param name="send_header_image_type" value="false"> <param name="poo" value="true"> <param name="thumbnail_width" value="100%%"> <param name="thumbnail_height" value="100%%"> <param name="security_click" value="0"> <param name="security_timer" value="0"> <param name="security_url" value=""> <param name="security_post" value="false"> <b>NOTE:</b> You need a Java enabled browser to edit the drawing example. </applet><br> APPLET; $formatter->send_footer("", $options); return; }
function macro_FullSearch($formatter, $value = "", &$opts) { global $DBInfo; $needle = $value; if ($value === true) { $needle = $value = $formatter->page->name; $options['noexpr'] = 1; } else { # for MoinMoin compatibility with [[FullSearch("blah blah")]] #$needle = preg_replace("/^('|\")([^\\1]*)\\1/","\\2",$value); $needle = $value; } // for pagination $offset = ''; if (!empty($opts['offset']) and is_numeric($opts['offset'])) { if ($opts['offset'] > 0) { $offset = $opts['offset']; } } $url = $formatter->link_url($formatter->page->urlname); $fneedle = _html_escape($needle); $tooshort = !empty($DBInfo->fullsearch_tooshort) ? $DBInfo->fullsearch_tooshort : 2; $m1 = _("Display context of search results"); $m2 = _("Search BackLinks only"); $m3 = _("Case-sensitive searching"); $msg = _("Go"); $bchecked = !empty($DBInfo->use_backlinks) ? 'checked="checked"' : ''; $form = <<<EOF <form method='get' action='{$url}'> <input type='hidden' name='action' value='fullsearch' /> <input name='value' size='30' value="{$fneedle}" /> <span class='button'><input type='submit' class='button' value='{$msg}' /></span><br /> <input type='checkbox' name='backlinks' value='1' {$bchecked} />{$m2}<br /> <input type='checkbox' name='context' value='20' />{$m1}<br /> <input type='checkbox' name='case' value='1' />{$m3}<br /> </form> EOF; if (!isset($needle[0]) or !empty($opts['form'])) { # or blah blah $opts['msg'] = _("No search text"); return $form; } $opts['form'] = $form; # XXX $excl = array(); $incl = array(); if (!empty($opts['noexpr'])) { $tmp = preg_split("/\\s+/", $needle); $needle = $value = join('|', $tmp); $raw_needle = implode(' ', $tmp); $needle = preg_quote($needle); } else { if (empty($opts['backlinks'])) { $terms = preg_split('/((?<!\\S)[-+]?"[^"]+?"(?!\\S)|\\S+)/s', $needle, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $common_words = array('the', 'that', 'where', 'what', 'who', 'how', 'too', 'are'); $common = array(); foreach ($terms as $term) { if (trim($term) == '') { continue; } if (preg_match('/^([-+]?)("?)([^\\2]+?)\\2$/', $term, $match)) { $word = str_replace(array('\\', '.', '*'), '', $match[3]); $len = strlen($word); if (!$match[1] and $match[2] != '"') { if ($len < $tooshort or in_array($word, $common_words)) { $common[] = $word; continue; } } if ($match[1] == '-') { $excl[] = $word; } else { $incl[] = $word; } } } $needle = implode('|', $incl); $needle = _preg_search_escape($needle); $raw_needle = implode(' ', $incl); $test = validate_needle($needle); if ($test === false) { // invalid regex $tmp = array_map('preg_quote', $incl); $needle = implode('|', $tmp); } $excl_needle = implode('|', $excl); $test = validate_needle($excl_needle); if ($test2 === false) { // invalid regex $tmp = array_map('preg_quote', $excl); $excl_needle = implode('|', $tmp); } } else { $cneedle = _preg_search_escape($needle); $test = validate_needle($cneedle); if ($test === false) { $needle = preg_quote($needle); } else { $needle = $cneedle; } } } $test3 = trim($needle); if (!isset($test3[0])) { $opts['msg'] = _("Empty expression"); return $form; } # set arena and sid if (!empty($opts['backlinks'])) { $arena = 'backlinks'; } else { if (!empty($opts['keywords'])) { $arena = 'keywords'; } else { $arena = 'fullsearch'; } } if ($arena == 'fullsearch') { $sid = md5($value . 'v' . $offset); } else { $sid = $value; } $delay = !empty($DBInfo->default_delaytime) ? $DBInfo->default_delaytime : 0; # retrieve cache $fc = new Cache_text($arena); if (!$formatter->refresh and $fc->exists($sid)) { $data = $fc->fetch($sid); if (!empty($opts['backlinks'])) { // backlinks are not needed to check it. $hits = $data; // also fetch redirects $r = new Cache_Text('redirects'); $redirects = $r->fetch($sid); } else { if (is_array($data)) { # check cache mtime $cmt = $fc->mtime($sid); # check update or not $dmt = $DBInfo->mtime(); if ($dmt > $cmt + $delay) { # XXX crude method $data = array(); } else { # XXX smart but incomplete method if (isset($data['hits'])) { $hits =& $data['hits']; } else { $hits =& $data; } foreach ($hits as $p => $c) { $mp = $DBInfo->getPage($p); $mt = $mp->mtime(); if ($mt > $cmt + $delay) { $data = array(); break; } } } if (isset($data['searched'])) { extract($data); } else { if (!empty($data)) { $hits = $data; } } } } } $pattern = '/' . $needle . '/'; if (!empty($excl_needle)) { $excl_pattern = '/' . $excl_needle . '/'; } if (!empty($opts['case'])) { $pattern .= "i"; $excl_pattern .= "i"; } if (isset($hits)) { if (in_array($arena, array('backlinks', 'keywords'))) { $test = key($hits); if (is_int($test) and $hits[$test] != -1) { // fix compatible issue for keywords, backlinks $hits = array_flip($hits); foreach ($hits as $k => $v) { $hits[$k] = -1; } reset($hits); } // check invert redirect index if (!empty($redirects)) { $redirects = array_flip($redirects); ksort($redirects); foreach ($redirects as $k => $v) { $hits[$k] = -2; } reset($hits); } } //continue; } else { $hits = array(); set_time_limit(0); if (!empty($opts['backlinks']) and empty($DBInfo->use_backlink_search)) { $hits = array(); } else { if (!empty($opts['keywords']) and empty($DBInfo->use_keyword_search)) { $hits = array(); } else { if (!empty($opts['backlinks'])) { $pages = $DBInfo->getPageLists(); #$opts['context']=-1; # turn off context-matching $cache = new Cache_text("pagelinks"); foreach ($pages as $page_name) { $links = $cache->fetch($page_name); if (is_array($links)) { if (in_array($value, $links)) { $hits[$page_name] = -1; } // ignore count if < 0 } } } else { if (!empty($opts['keywords'])) { $pages = $DBInfo->getPageLists(); $opts['context'] = -1; # turn off context-matching $cache = new Cache_text("keyword"); foreach ($pages as $page_name) { $links = $cache->fetch($page_name); // XXX if (is_array($links)) { if (stristr(implode(' ', $links), $needle)) { $hits[$page_name] = -1; } // ignore count if < 0 } } } else { $params = array(); $ret = array(); $params['ret'] =& $ret; $params['offset'] = $offset; $params['search'] = 1; $params['incl'] = $incl; $params['excl'] = $excl; $pages = $DBInfo->getPageLists($params); // set time_limit $mt = explode(' ', microtime()); $timestamp = $mt[0] + $mt[1]; $j = 0; $time_limit = isset($DBInfo->process_time_limit) ? $DBInfo->process_time_limit : 3; // default 3-seconds $j = 0; while (list($_, $page_name) = each($pages)) { // check time_limit if ($time_limit and $j % 30 == 0) { $mt = explode(' ', microtime()); $now = $mt[0] + $mt[1]; if ($now - $timestamp > $time_limit) { break; } } $j++; $p = new WikiPage($page_name); if (!$p->exists()) { continue; } $body = $p->_get_raw_body(); #$count = count(preg_split($pattern, $body))-1; $count = preg_match_all($pattern, $body, $matches); if ($count) { foreach ($excl as $ex) { if (stristr($body, $ex)) { continue; } } foreach ($incl as $in) { if (!stristr($body, $in)) { continue; } } $hits[$page_name] = $count; } } $searched = $j > 0 ? $j : 0; $offset = !empty($offset) ? $offset + $j : $j; } } } } #krsort($hits); #ksort($hits); $name = array_keys($hits); array_multisort($hits, SORT_DESC, $name, SORT_ASC); if (in_array($arena, array('backlinks', 'keywords'))) { $fc->update($sid, $name); } else { $fc->update($sid, array('hits' => $hits, 'offset' => $offset, 'searched' => $searched)); } } $opts['hits'] = $hits; $opts['hit'] = count($hits); $opts['all'] = $DBInfo->getCounter(); if ($opts['all'] > $searched) { $opts['next'] = $offset; $opts['searched'] = $searched; } if (!empty($opts['call'])) { return $hits; } $out = "<!-- RESULT LIST START -->"; // for search plugin $out .= "<ul class='fullsearchResult'>"; $idx = 1; $checkbox = ''; while (list($page_name, $count) = each($hits)) { $pgname = _html_escape($page_name); if (!empty($opts['checkbox'])) { $checkbox = "<input type='checkbox' name='pagenames[]' value=\"{$pgname}\" />"; } $out .= '<!-- RESULT ITEM START -->'; // for search plugin $out .= '<li>' . $checkbox . $formatter->link_tag(_rawurlencode($page_name), '?action=highlight&value=' . _urlencode($value), $pgname, 'tabindex="' . $idx . '"'); if ($count > 0) { $out .= ' . . . . ' . sprintf($count == 1 ? _("%d match") : _("%d matches"), $count); } else { if ($count == -2) { $out .= " <span class='redirectIcon'><span>" . _("Redirect page") . "</span></span>\n"; } } if (!empty($opts['context']) and $opts['context'] > 0) { # search matching contexts $p = new WikiPage($page_name); if ($p->exists()) { $body = $p->_get_raw_body(); $out .= find_needle($body, $needle, $excl_needle, $opts['context']); } } $out .= "</li>\n"; $out .= '<!-- RESULT ITEM END -->'; // for search plugin $idx++; #if ($idx > 50) break; } $out .= "</ul>\n"; $out .= "<!-- RESULT LIST END -->"; // for search plugin return $out; }
function word_repl($word, $text = '', $attr = '', $nogroup = 0, $islink = 1) { require_once dirname(__FILE__) . '/lib/xss.php'; global $DBInfo; $nonexists = 'nonexists_' . $this->nonexists; $word = $page = trim($word, '[]'); // trim out [[Hello World]] => Hello World $extended = false; if (($word[0] == '"' or $word[0] == 'w') and preg_match('/^(?:wiki\\:)?((")?[^"]+\\2)((\\s+|\\|)?(.*))?$/', $word, $m)) { # ["extended wiki name"] # ["Hello World" Go to Hello] # [wiki:"Hello World" Go to Main] $word = substr($m[1], 1, -1); if (isset($m[5][0])) { $text = $m[5]; } // text arg ignored $extended = true; $page = $word; } else { if (($p = strpos($word, '|')) !== false) { // or MediaWiki/WikiCreole like links $text = substr($word, $p + 1); $word = substr($word, 0, $p); $page = $word; } else { // check for [[Hello attachment:foo.png]] case $tmp = strtok($word, ' |'); $last = strtok(''); if (($p = strpos($last, ' ')) === false && substr($last, 0, 11) == 'attachment:') { $text = $last; $word = $tmp; $page = $word; } } } if (!$extended and empty($DBInfo->mediawiki_style)) { #$page=preg_replace("/\s+/","",$word); # concat words $page = normalize($word); # concat words } if (empty($DBInfo->use_twikilink)) { $islink = 0; } list($page, $page_text, $gpage) = normalize_word($page, $this->group, $this->page->name, $nogroup, $islink); if (isset($text[0])) { if (preg_match("/^(http|ftp|attachment).*\\.(png|gif|jpeg|jpg)\$/i", $text)) { if (substr($text, 0, 11) == 'attachment:') { $fname = substr($text, 11); $ntext = $this->macro_repl('attachment', $fname, 1); if (!file_exists($ntext)) { $word = $this->macro_repl('attachment', $fname); } else { $text = qualifiedUrl($this->url_prefix . '/' . $ntext); $word = "<img style='border:0' alt='{$text}' src='{$text}' /></a>"; } } else { $text = str_replace('&', '&', $text); // trash dummy query string $text = preg_replace('@(\\?|&)\\.(png|gif|jpe?g)$@', '', $text); if (!empty($this->fetch_images) and !preg_match('@^https?://' . $_SERVER['HTTP_HOST'] . '@', $text)) { $text = $this->fetch_action . str_replace(array('&', '?'), array('%26', '%3f'), $text); } $word = "<img style='border:0' alt='{$word}' src='{$text}' /></a>"; } } else { $word = preg_replace($this->baserule, $this->baserepl, $text); $word = str_replace('<', '<', $word); // revert from baserule $word = _xss_filter($word); } } else { $word = $text = $page_text ? $page_text : $word; #echo $text; $word = _html_escape($word); } $url = _urlencode($page); $url_only = strtok($url, '#?'); # for [WikiName#tag] [wiki:WikiName#tag Tag] #$query= substr($url,strlen($url_only)); if ($extended) { $page = rawurldecode($url_only); } else { $page = urldecode($url_only); } $url = $this->link_url($url); #check current page if ($page == $this->page->name) { $attr .= ' class="current"'; } if (!empty($this->forcelink)) { return $this->nonexists_always($word, $url, $page); } //$url=$this->link_url(_rawurlencode($page)); # XXX $idx = 0; // XXX if (isset($this->pagelinks[$page])) { $idx = $this->pagelinks[$page]; switch ($idx) { case 0: #return "<a class='nonexistent' href='$url'>?</a>$word"; return call_user_func(array(&$this, $nonexists), $word, $url, $page); case -1: $title = ''; $tpage = urlencode($page); if ($tpage != $word) { $title = 'title="' . _html_escape($page) . '" '; } return "<a href='{$url}' {$title}{$attr}>{$word}</a>"; case -2: return "<a href='{$url}' {$attr}>{$word}</a>" . "<tt class='sister'><a href='{$url}'>›</a></tt>"; case -3: #$url=$this->link_url(_rawurlencode($gpage)); return $this->link_tag(_rawurlencode($gpage), '', $this->icon['main'], 'class="main"') . "<a href='{$url}' {$attr}>{$word}</a>"; default: return "<a href='{$url}' {$attr}>{$word}</a>" . "<tt class='sister'><a href='#sister{$idx}'>›{$idx}</a></tt>"; } } else { if ($DBInfo->hasPage($page)) { $title = ''; $this->pagelinks[$page] = -1; $tpage = urlencode($page); if ($tpage != $word) { $title = 'title="' . _html_escape($page) . '" '; } return "<a href='{$url}' {$title}{$attr}>{$word}</a>"; } else { if ($gpage and $DBInfo->hasPage($gpage)) { $this->pagelinks[$page] = -3; #$url=$this->link_url(_rawurlencode($gpage)); return $this->link_tag(_rawurlencode($gpage), '', $this->icon['main'], 'class="main"') . "<a href='{$url}' {$attr}>{$word}</a>"; } if (!empty($this->aliases[$page])) { return $this->aliases[$page]; } if (!empty($this->sister_on)) { if (empty($DBInfo->metadb)) { $DBInfo->initMetaDB(); } $sisters = $DBInfo->metadb->getSisterSites($page, $DBInfo->use_sistersites); if ($sisters === true) { $this->pagelinks[$page] = -2; return "<a href='{$url}'>{$word}</a>" . "<tt class='sister'><a href='{$url}'>›</a></tt>"; } if (!empty($sisters)) { if (!empty($this->use_easyalias) and !preg_match('/^\\[wiki:[A-Z][A-Za-z0-9]+:.*$/', $sisters)) { # this is a alias $this->use_easyalias = 0; $tmp = explode("\n", $sisters); $url = $this->link_repl(substr($tmp[0], 0, -1) . ' ' . $word . ']'); $this->use_easyalias = 1; $this->aliases[$page] = $url; return $url; } $this->sisters[] = "<li><tt class='foot'><a id='sister{$this->sister_idx}'></a>" . "<a href='#rsister{$this->sister_idx}'>{$this->sister_idx}›</a></tt> " . "{$sisters} </li>"; $this->pagelinks[$page] = $this->sister_idx++; $idx = $this->pagelinks[$page]; } if ($idx > 0) { return "<a href='{$url}'>{$word}</a>" . "<tt class='sister'>" . "<a id='rsister{$idx}'></a>" . "<a href='#sister{$idx}'>›{$idx}</a></tt>"; } } $this->pagelinks[$page] = 0; #return "<a class='nonexistent' href='$url'>?</a>$word"; return call_user_func(array(&$this, $nonexists), $word, $url, $page); } } }
function macro_TitleSearch($formatter = "", $needle = "", &$opts) { global $DBInfo; $type = 'o'; $url = $formatter->link_url($formatter->page->urlname); $hneedle = _html_escape($needle); $msg = _("Go"); $form = "<form method='get' action='{$url}'>\n <input type='hidden' name='action' value='titlesearch' />\n <input name='value' size='30' value=\"{$hneedle}\" />\n <span class='button'><input type='submit' class='button' value='{$msg}' /></span>\n </form>"; if (!isset($needle[0])) { $opts['msg'] = _("Use more specific text"); if (!empty($opts['call'])) { $opts['form'] = $form; return $opts; } return $form; } $opts['form'] = $form; $opts['msg'] = sprintf(_("Title search for \"%s\""), $hneedle); $cneedle = _preg_search_escape($needle); if ($opts['noexpr']) { $needle = preg_quote($needle); } else { if (validate_needle($cneedle) === false) { $needle = preg_quote($needle); } else { // good expr $needle = $cneedle; } } // return the exact page or all similar pages $noexact = true; if (isset($opts['noexact'])) { $noexact = $opts['noexact']; } $limit = !empty($DBInfo->titlesearch_page_limit) ? $DBInfo->titlesearch_page_limit : 100; if (isset($opts['limit'])) { $limit = $opts['limit']; } $indexer = $DBInfo->lazyLoad('titleindexer'); $pages = $indexer->getLikePages($needle, $limit); $opts['all'] = $DBInfo->getCounter(); if (empty($DBInfo->alias)) { $DBInfo->initAlias(); } $alias = $DBInfo->alias->getAllPages(); $pages = array_merge($pages, $alias); $hits = array(); $exacts = array(); if ($noexact) { // return all search results foreach ($pages as $page) { if (preg_match("/" . $needle . "/i", $page)) { $hits[] = $page; } } } else { // return exact pages foreach ($pages as $page) { if (preg_match("/^" . $needle . "\$/i", $page)) { $hits[] = $page; $exacts[] = $page; if (empty($DBInfo->titlesearch_exact_all)) { $hits = $exacts; break; } } } } if (empty($hits) and empty($exacts)) { // simple title search by ignore spaces $needle2 = str_replace(' ', "\\s*", $needle); $ws = preg_split("/([\\x{AC00}-\\x{D7F7}])/u", $needle2, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $needle2 = implode("\\s*", $ws); $hits = $indexer->getLikePages($needle2); foreach ($alias as $page) { if (preg_match("/" . $needle2 . "/i", $page)) { $hits[] = $page; } } } sort($hits); $idx = 1; if (!empty($opts['linkto'])) { $idx = 10; } $out = ''; foreach ($hits as $pagename) { $pagetext = _html_escape(urldecode($pagename)); if (!empty($opts['linkto'])) { $out .= '<li>' . $formatter->link_to("{$opts['linkto']}{$pagename}", $pagetext, "tabindex='{$idx}'") . "</li>\n"; } else { $out .= '<li>' . $formatter->link_tag(_rawurlencode($pagename), "", $pagetext, "tabindex='{$idx}'") . "</li>\n"; } $idx++; } if ($out) { $out = "<{$type}l>{$out}</{$type}l>\n"; } $opts['hits'] = count($hits); if ($opts['hits'] == 1) { $opts['value'] = array_pop($hits); } if (!empty($exacts)) { $opts['exact'] = 1; } if (!empty($opts['call'])) { $opts['out'] = $out; return $opts; } return $out; }
function do_post_rename($formatter, $options) { global $DBInfo; $new = $options['name']; if ($new[0] == '~' and ($p = strpos($new, '/')) !== false) { // Namespace renaming $dummy = substr($new, 1, $p - 1); $dummy2 = substr($new, $p + 1); $options['name'] = $dummy . '~' . $dummy2; } if (isset($options['name']) and trim($options['name'])) { if ($DBInfo->hasPage($options['page']) && !$DBInfo->hasPage($options['name'])) { $title = sprintf(_("\"%s\" is renamed !"), $options['page']); $formatter->send_header("", $options); $formatter->send_title($title, "", $options); $new_encodedname = _rawurlencode($options['name']); if ($options['pagenames'] and is_array($options['pagenames'])) { $regex = preg_quote($options['page']); $options['minor'] = 1; foreach ($options['pagenames'] as $page) { $p = new WikiPage($page); if (!$p->exists()) { continue; } $f = new Formatter($p); $body = $p->_get_raw_body(); $body = preg_replace("/{$regex}/m", $options['name'], $body); $f->page->write($body); if (!$options['show_only']) { $DBInfo->savePage($f->page, '', $options); } $msg .= sprintf(_("'%s' is changed"), $f->link_tag(_rawurlencode($page), "?action=highlight&value=" . $new_encodedname)) . "<br />"; } } print $msg; if (!$options['show_only']) { $DBInfo->renamePage($options['page'], $options['name'], $options); } print sprintf(_("'%s' is renamed as '%s' successfully."), $options['page'], $formatter->link_tag($options['name'], "?action=highlight&value=" . $new_encodedname)); $formatter->send_footer("", $options); return; } else { $title = sprintf(_("Fail to rename \"%s\" !"), $options['page']); $formatter->send_header("", $options); $formatter->send_title($title, "", $options); $formatter->send_footer("", $options); return; } } $title = sprintf(_("Rename \"%s\" ?"), $options['page']); $formatter->send_header("", $options); $formatter->send_title($title, "", $options); #<tr><td align='right'><input type='checkbox' name='show' checked='checked' />show only </td><td><input type='password' name='passwd'> $obtn = _("Old name:"); $nbtn = _("New name:"); print "<form method='post'>\n<table border='0'>\n<tr><td align='right'>{$obtn} </td><td><b>{$options['page']}</b></td></tr>\n<tr><td align='right'>{$nbtn} </td><td><input name='name' /></td></tr>\n"; $rename_button = _("Rename"); if ($options['value'] == 'check_backlinks') { print "<tr><td colspan='2'>\n"; print check_backlinks($formatter, $options); print "</td></tr>\n"; $rename_button = _("Rename and fix Backlinks"); } if ($DBInfo->security->is_protected("rename", $options)) { print "<tr><td align='right'>" . _("Password") . ": </td><td><input type='password' name='passwd' /> " . _("Only WikiMaster can rename this page") . "</td></tr>\n"; } print "<tr><td colspan='2'><input type='checkbox' name='history' />" . _("with revision history") . "</td></tr>\n"; print "<tr><td colspan='2'><input type='checkbox' name='show_only' checked='checked' />" . _("show only") . "</td></tr>\n"; print "<tr><td></td><td><input type='submit' name='button_rename' value='{$rename_button}' />"; print " <a href='?action=rename&value=check_backlinks'>" . _("Check backlinks") . "</a>"; print "</td></tr>\n"; print "\n</table>\n <input type=hidden name='action' value='rename' />\n </form>"; # $formatter->send_page(); $formatter->send_footer("", $options); }
function do_post_fixbacklinks($formatter, $options = array()) { global $DBInfo; if ($_SERVER['REQUEST_METHOD'] == 'POST' && !$DBInfo->security->writable($options)) { $options['title'] = _("Page is not writable"); return do_invalid($formatter, $options); } $options['name'] = trim($options['name']); $new = $options['name']; if (!empty($DBInfo->use_namespace) and $new[0] == '~' and ($p = strpos($new, '/')) !== false) { // Namespace renaming ~foo/bar -> foo~bar $dummy = substr($new, 1, $p - 1); $dummy2 = substr($new, $p + 1); $options['name'] = $dummy . '~' . $dummy2; } if (isset($options['name'][0]) and $options['name']) { if ($DBInfo->hasPage($options['name'])) { $formatter->send_header('', $options); $new_encodedname = _rawurlencode($options['name']); $fixed = 0; $msg = ''; $title = sprintf(_("backlinks of \"%s\" page are fixed !"), $options['page']); $comment = sprintf(_("Fixed \"%s\" to \"%s\""), $options['page'], $options['name']); if ($options['pagenames'] and is_array($options['pagenames'])) { $regex = preg_quote($options['page']); //$options['minor'] = 1; # disable log foreach ($options['pagenames'] as $page) { $p = new WikiPage($page); if (!$p->exists()) { continue; } $f = new Formatter($p); $body = $p->_get_raw_body(); $nbody = preg_replace("/{$regex}/m", $options['name'], $body); // FIXME if ($nbody !== false && $body != $nbody) { $f->page->write($nbody); if (!$options['show_only']) { $DBInfo->savePage($f->page, $comment, $options); } $msg .= sprintf(_("'%s' is changed"), $f->link_tag(_rawurlencode($page), "?action=highlight&value=" . $new_encodedname, _html_escape($page))) . "<br />"; $fixed++; } } } if ($fixed == 0) { $title = _("No pages are fixed!"); } $formatter->send_title($title, '', $options); if ($fixed > 0) { print $msg; print sprintf(_("'%s' links are successfully fixed as '%s'."), _html_escape($options['page']), $formatter->link_tag($new_encodedname, "?action=highlight&value=" . $new_encodedname, _html_escape($options['name']))); } $formatter->send_footer('', $options); return; } else { $title = sprintf(_("Fail to fix backlinks of \"%s\" !"), $options['page']); $options['msg'] = sprintf(_("New pagename \"%s\" is not exists!"), $options['name']); $formatter->send_header('', $options); $formatter->send_title($title, '', $options); $formatter->send_footer('', $options); return; } } $title = sprintf(_("Fix backlinks of \"%s\" ?"), $options['page']); $formatter->send_header('', $options); $formatter->send_title($title, '', $options); $obtn = _("Old name:"); $nbtn = _("New name:"); $pgname = _html_escape($options['page']); print "<form method='post'>\n <table border='0'>\n <tr><td align='right'>{$obtn} </td><td><b>{$pgname}</b></td></tr>\n <tr><td align='right'>{$nbtn} </td><td><input name='name' /></td></tr>\n"; if (!empty($options['value']) and $options['value'] == 'check_backlinks') { $button = _("Fix backlinks"); print "<tr><td colspan='2'>\n"; print check_backlinks($formatter, $options); print "</td></tr>\n"; } else { $button = _("Check backlinks"); } if ($DBInfo->security->is_protected("fixbacklinks", $options)) { print "<tr><td align='right'>" . _("Password") . ": </td><td><input type='password' name='passwd' /> " . _("Only WikiMaster can fix backlinks of this page") . "</td></tr>\n"; } if (!empty($options['value']) and $options['value'] == 'check_backlinks') { print "<tr><td colspan='2'><input type='checkbox' name='show_only' checked='checked' />" . _("show only") . "</td></tr>\n"; } print "<tr><td></td><td><input type='submit' name='button_fixbacklinks' value='{$button}' />"; print "<input type='hidden' name='value' value='check_backlinks' />"; print "</td></tr>\n"; print "\n </table>\n <input type='hidden' name='action' value='fixbacklinks' />\n </form>"; $formatter->send_footer('', $options); }
function macro_foaf($formatter, $value) { global $DBInfo; $xml_parser = xml_parser_create(); preg_match("/([^,]+)?(?:\\s*,\\s*)?(.*)?\$/", $value, $match); if ($match) { $value = $match[1]; $key = _rawurlencode($match[1]); $args = explode(",", str_replace(" ", "", $match[2])); if (in_array("project", $args)) { $options['project'] = 1; } if (in_array("picture", $args)) { $options['picture'] = 1; } if (in_array("homepage", $args)) { $options['homepage'] = 1; } if (in_array("comment", $args)) { $options['comment'] = 1; } } $info = array(); // XXX $rss_parser = new FoafParser($info); xml_set_object($xml_parser, $rss_parser); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); $cache = new Cache_text("foaf"); if (!empty($_GET['update']) or !$cache->exists($key)) { $fp = @fopen("{$value}", "r"); if (!$fp) { return "[[FOAF(ERR: not a valid URL! {$value})]]"; } while ($data = fread($fp, 4096)) { $xml_data .= $data; } fclose($fp); $cache->update($key, $xml_data); } else { $xml_data = $cache->fetch($key); } $ret = xml_parse($xml_parser, $xml_data); if (!$ret) { return sprintf("[[FOAF(XML error: %s at line %d)]]", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)); } xml_parser_free($xml_parser); ## $out = "<a href='" . $DBInfo->interwiki['FOAF'] . "{$value}'><img align='middle' border='0' alt='FOAF:' title='FOAF:' src='{$DBInfo->imgs_url_interwiki}" . "foaf-16.png'>"; if ($options['homepage']) { $out .= "</a><a href='{$info['homepage']}'>{$info['name']}</a>"; } else { $out .= "{$info['name']}</a>"; } $br = " "; if ($options['picture']) { $out .= "<br /><img src='{$info['picture']}' />"; $br = "<br />"; } if ($options['homepage']) { $out .= "{$br}<a href='{$info['homepage']}'>{$info['homepage']}</a>"; } if (strtoupper($DBInfo->charset) != 'UTF-8') { $out = iconv('utf-8', $DBInfo->charset, $out); } return $out; }
function do_keywords($formatter, $options) { global $DBInfo; $supported_lang = array('ko'); $page = $formatter->page->name; if (empty($options['update']) and !empty($options['value'])) { $page = $options['value']; } if (!$DBInfo->hasPage($page)) { $options['err'] = _("You are not able to add keywords."); $options['title'] = _("Page does not exists"); do_invalid($formatter, $options); return; } if (!empty($options['update']) or !empty($options['refresh'])) { $lk = $DBInfo->getPage(LOCAL_KEYWORDS); $force_charset = ''; if ($DBInfo->force_charset) { $force_charset = '; charset=' . $DBInfo->charset; } $formatter->send_header("Content-type: text/plain" . $force_charset); if (!$lk->exists()) { print sprintf(_("%s is not found."), LOCAL_KEYWORDS); return; } $raw = $lk->get_raw_body(); # update keylinks of LocalKeywords $kc = new Cache_text('keylinks'); $lines = explode("\n", $raw); $all_keys = array(); foreach ($lines as $l) { $l = trim($l); if ($l[0] == '#' or !$l) { continue; } $ws = preg_split('/((?<!\\S)(["\'])[^\\2]+?\\2(?!\\S)|\\S+)/', $l, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $ws = array_flip(array_unique($ws)); unset($ws['"']); // delete delims unset($ws["'"]); unset($ws[' ']); $ws = array_flip($ws); $ws = array_map(create_function('$a', 'return preg_replace("/^([\\"\'])(.*)\\\\1$/","\\\\2",$a);'), $ws); // delete ",' $ws = array_unique($ws); $all_keys = array_merge($all_keys, $ws); foreach ($ws as $k) { $rels = array_diff($ws, array($k)); $krels = $kc->fetch($k); if (is_array($krels)) { if ($nrels = array_diff($rels, $krels)) { $rs = array_unique(array_merge($nrels, $krels)); $kc->update($k, $rs); print "***** updated {$k}\n"; } } else { if (sizeof($rels) > 1 and is_array($rels)) { $kc->update($k, $rels); print "***** save {$k}\n"; } } } } print_r($all_keys); print "OK"; return; } $args = array(); $formatter->send_header('', $options); if (empty($options['suggest']) and (!empty($options['key']) and is_array($options['key']) or !empty($options['keywords']))) { if (!empty($options['keywords'])) { // following keyword list are acceptable separated with spaces. // Chemistry "Physical Chemistry" "Bio Chemistry" ... $keywords = _stripslashes($options['keywords']); $ws = preg_split('/((?<!\\S)(["\'])[^\\2]+?\\2(?!\\S)|\\S+)/', $keywords, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $ws = array_flip(array_unique($ws)); unset($ws['"']); // delete delims unset($ws["'"]); unset($ws[' ']); $ws = array_flip($ws); $ws = array_map(create_function('$a', 'return preg_replace("/^([\\"\'])(.*)\\\\1$/","\\\\2",$a);'), $ws); // delete ",' if (!is_array($options['key'])) { $options['key'] = array(); } $options['key'] = array_merge($options['key'], $ws); } if (!empty($options['common'])) { $raw = "#format plain"; $lang = $formatter->pi['#language'] ? $formatter->pi['#language'] : ''; $lang = $options['lang'] ? $options['lang'] : $lang; if (in_array($lang, $supported_lang)) { $common_word_page = LOCAL_KEYWORDS . '/CommonWords' . ucfirst($lang); } else { $common_word_page = LOCAL_KEYWORDS . '/CommonWords'; } if ($DBInfo->hasPage($common_word_page)) { $p = $DBInfo->getPage($common_word_page); if (!$p->exists()) { $dict = array(); } else { $raw = $p->get_raw_body(); $raw = rtrim($raw); $lines = explode("\n", $raw); $body = ''; foreach ($lines as $line) { if ($line[0] == '#' or $line == '') { continue; } $body .= $line . "\n"; } $body = rtrim($body); $dict = explode("\n", $body); } $commons = array_diff(array_values($options['key']), $dict); } else { $p = $DBInfo->getPage($common_word_page); $commons = $options['key']; } if (!empty($commons)) { sort($commons); $raw .= "\n" . implode("\n", $commons); $p->write($raw); $DBInfo->savePage($p, "Common words are added", $options); } $formatter->send_title(sprintf(_("Common words are updated"), $options['page']), '', $options); $formatter->send_footer($args, $options); return; } $cache = new Cache_text('keyword'); $keys = $options['key']; $keys = array_flip($keys); unset($keys['']); $cache->update($page, array_keys($keys)); # update 'keylinks' caches #$kc=new Cache_text('keylinks'); #foreach ($options['key'] as $k) { # // XXX # $kv=unserialize($kc->fetch($k)); # if (!in_array($page,$kv)) { # $kv[]=$page; # $kc->update($k,serialize($kv)); # } #} $raw = "#format plain"; $lk = $DBInfo->getPage(LOCAL_KEYWORDS); if (!$lk->exists()) { $dict = array(); } else { $raw = $lk->get_raw_body(); $raw = rtrim($raw); $lines = explode("\n", $raw); $body = ''; foreach ($lines as $line) { if ($line[0] == '#' or $line == '') { continue; } $body .= $line . "\n"; } $body = rtrim($body); } if (!empty($options['key'])) { // XXX $ks = array_map(create_function('$a', 'return (strpos($a," ") !== false) ? "\\"$a\\"":$a;'), $options['key']); $raw .= "\n" . implode(' ', $ks) . "\n"; $lk->write($raw); $DBInfo->savePage($lk, "Keywords are added", $options); } $formatter->send_title(sprintf(_("Keywords for %s are updated"), $page), '', $options); $ret = ''; foreach ($keys as $key => $val) { $ret .= $key . ','; } $ret = substr($ret, 0, strlen($ret) - 1); print "<tt>#keywords {$ret}</tt>\n"; if (!empty($DBInfo->use_keywords) or !empty($options['update'])) { # auto update the page with selected keywords. $body = $formatter->page->get_raw_body(); $pi = $formatter->page->get_instructions($dum); if (!empty($pi['#keywords'])) { $tag = preg_quote($pi['#keywords']); $nbody = preg_replace('/^#keywords\\s+' . $tag . '/', '#keywords ' . $ret, $body, 1); if ($nbody != $body) { $ok = 1; } } else { $nbody = '#keywords ' . $ret . "\n" . $body; $ok = 2; } if (!empty($ok)) { if ($ok == 1) { $comment = "Keywords are updated"; } else { $comment = "Keywords are added"; } $formatter->page->write($nbody); $DBInfo->savePage($formatter->page, $comment, $options); print "<h2>" . _("Keywords are updated") . "</h2>"; } else { print "<h2>" . _("There are no changes found") . "</h2>"; } } else { # user confirmation $link = $formatter->link_url(_rawurlencode($page), ''); $keys = explode(',', $ret); $ret = ''; foreach ($keys as $key) { if ($key and strpos($key, ' ') !== false) { $key = '"' . $key . '"'; } $ret .= $key . ' '; } $btn = _("Update with these Keywords"); $form = "<form method='post' action='{$link}'>"; $form .= '<input type="hidden" name="action" value="keywords" />'; $form .= '<input type="hidden" name="update" value="1" />'; $form .= '<input type="hidden" name="keywords" value=\'' . $ret . '\' />'; $form .= "<input type='submit' value='{$btn}' />\n"; $form .= "</form>"; print $form; } $formatter->send_footer($args, $options); return; } if (!empty($options['all']) or !empty($options['tour'])) { if (!empty($optiopns['sort']) and $options['sort'] == 'freq') { $sort = 'freq'; } $formatter->send_title('', '', $options); $myq = '?' . $_SERVER['QUERY_STRING']; $myq = preg_replace('/&sort=[^&]+/i', '', $myq); if ($sort != 'freq') { $myq .= '&sort=freq'; $txt = _("alphabetically"); $ltxt = _("by frequency"); } else { $txt = _("by size"); $ltxt = _("alphabetically"); } $link = $formatter->link_tag(_rawurlencode($page), $myq, $ltxt); print "<h2>"; print sprintf(_("Keywords list %s (or %s)"), $txt, $link); print "</h2>\n"; if (!$options['limit']) { $options['limit'] = 0; } } else { $formatter->send_title(sprintf(_("Select keywords for %s"), $options['page']), '', $options); $options['merge'] = 1; $options['add'] = 1; } print macro_KeyWords($formatter, $options['page'], $options); //$args['editable']=1; $formatter->send_footer($args, $options); }
function do_atom($formatter, $options) { global $DBInfo, $Config; global $_release; define('ATOM_DEFAULT_DAYS', 7); // get members to hide log $members = $DBInfo->members; $days = $DBInfo->rc_days ? $DBInfo->rc_days : ATOM_DEFAULT_DAYS; $options['quick'] = 1; if ($options['c']) { $options['items'] = $options['c']; } $lines = $DBInfo->editlog_raw_lines($days, $options); // HTTP conditional get $mtime = $DBInfo->mtime(); $lastmod = gmdate('D, d M Y H:i:s \\G\\M\\T', $mtime); $cache_ttl = !empty($DBInfo->atom_ttl) ? $DBInfo->atom_ttl : 60 * 30; /* 30 minutes */ // make etag based on some options and mtime. $check_opts = array('quick', 'items', 'c'); $check = array(); foreach ($check_opts as $c) { if (isset($options[$c])) { $check[$c] = $options[$c]; } } $etag = md5($mtime . $DBInfo->logo_img . serialize($check) . $cache_ttl . $options['id']); $headers = array(); $headers[] = 'Pragma: cache'; $maxage = $cache_ttl; $public = 'public'; if ($options['id'] != 'Anonymous') { $public = 'private'; } $headers[] = 'Cache-Control: ' . $public . ', max-age=' . $maxage; $headers[] = 'Last-Modified: ' . $lastmod; $headers[] = 'ETag: "' . $etag . '"'; $need = http_need_cond_request($mtime, $lastmod, $etag); if (!$need) { $headers[] = 'HTTP/1.0 304 Not Modified'; } foreach ($headers as $h) { header($h); } if (!$need) { @ob_end_clean(); return; } $cache = new Cache_Text('atom'); $cache_delay = min($cache_ttl, 30); $mtime = $cache->mtime($etag); $time_current = time(); $val = false; if (empty($formatter->refresh)) { if (($val = $cache->fetch($etag)) !== false and $DBInfo->checkUpdated($mtime, $cache_delay)) { header("Content-Type: application/xml"); echo $val; return; } } // need to update cache if ($val !== false and $cache->exists($etag . '.lock')) { header("Content-Type: application/xml"); echo $val . '<!-- cached at ' . date('Y-m-d H:i:s', $mtime) . ' -->'; return; } if ($cache->exists($etag . '.lock')) { header("Content-Type: application/xml"); echo ''; return; } $cache->update($etag . '.lock', array('lock'), 30); // 30s lock $URL = qualifiedURL($formatter->prefix); $img_url = qualifiedURL($DBInfo->logo_img); $url = qualifiedUrl($formatter->link_url($DBInfo->frontpage)); $surl = qualifiedUrl($formatter->link_url($options['page'] . '?action=atom')); $channel = <<<CHANNEL <title>{$DBInfo->sitename}</title> <link href="{$url}"></link> <link rel="self" type="application/atom+xml" href="{$surl}" /> <subtitle>RecentChanges at {$DBInfo->sitename}</subtitle> <generator version="{$_release}">MoniWiki Atom feeder</generator> CHANNEL; $items = ""; $ratchet_day = FALSE; if (!$lines) { $lines = array(); } foreach ($lines as $line) { $parts = explode("\t", $line); $page_name = $DBInfo->keyToPagename($parts[0]); // hide log if (!empty($members) && !in_array($options['id'], $members) && !empty($Config['ruleset']['hidelog'])) { if (in_array($page_name, $Config['ruleset']['hidelog'])) { continue; } } $addr = $parts[1]; $ed_time = $parts[2]; $user = $parts[4]; $user_uri = ''; if ($user != 'Anonymous' && $DBInfo->hasPage($user)) { $user_uri = $formatter->link_url(_rawurlencode($user), "", $user); $user_uri = '<uri>' . $user_uri . '</uri>'; } $log = _stripslashes($parts[5]); $act = rtrim($parts[6]); $url = qualifiedUrl($formatter->link_url(_rawurlencode($page_name))); $diff_url = qualifiedUrl($formatter->link_url(_rawurlencode($page_name), '?action=diff')); $extra = "<br /><a href='{$diff_url}'>" . _("show changes") . "</a>\n"; $content = ''; if (!$DBInfo->hasPage($page_name)) { $status = 'deleted'; $content = "<content type='html'><a href='{$url}'>{$page_name}</a> is deleted</content>\n"; } else { $status = 'updated'; if ($options['diffs']) { $p = new WikiPage($page_name); $f = new Formatter($p); $options['raw'] = 1; $options['nomsg'] = 1; $html = $f->macro_repl('Diff', '', $options); if (!$html) { ob_start(); $f->send_page('', array('fixpath' => 1)); #$f->send_page(''); $html = ob_get_contents(); ob_end_clean(); $extra = ''; } $content = " <content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>{$html}</content>\n"; } else { if ($log) { $html = str_replace('&', '&', $log); $content = "<content type='text'>" . $html . "</content>\n"; } else { $content = "<content type='text'>updated</content>\n"; } } } $zone = '+00:00'; $date = gmdate("Y-m-d\\TH:i:s", $ed_time) . $zone; if (!isset($updated)) { $updated = $date; } #$datetag = gmdate("YmdHis",$ed_time); $valid_page_name = str_replace('&', '&', $page_name); $items .= "<entry>\n"; $items .= " <title>{$valid_page_name}</title>\n"; $items .= " <link href='{$url}'></link>\n"; $items .= ' ' . $content; $items .= " <author><name>{$user}</name>{$user_uri}</author>\n"; $items .= " <updated>{$date}</updated>\n"; $items .= " <contributor><name>{$user}</name>{$user_uri}</contributor>\n"; $items .= "</entry>\n"; } $updated = " <updated>{$updated}</updated>\n"; $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}"?> <!--<?xml-stylesheet href="{$DBInfo->url_prefix}/css/_feed.css" type="text/css"?>--> <feed xmlns="http://www.w3.org/2005/Atom"> <!-- Add "diffs=1" to add change diffs to the description of each items. Add "oe=utf-8" to convert the charset of this rss to UTF-8. --> HEAD; header("Content-Type: application/xml"); $out = ''; if ($new) { $out = $head . $new; } else { $out = $head . $channel . $updated . $items . $form; } $out .= "</feed>\n"; echo $out; $cache->update($etag, $out); $cache->remove($etag . '.lock'); }