示例#1
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if ($Longitude === '') {
         return $this->error(fmt("%s parameter missing", "'Longitude'"));
     }
     if ($Latitude === '') {
         return $this->error(fmt("%s parameter missing", "'Latitude'"));
     }
     $maps = JavaScript('', array('src' => "http://maps.google.com/maps?file=api&v=1&key=" . GOOGLE_LICENSE_KEY));
     $id = GenerateId("googlemap");
     switch ($MapType) {
         case "Satellite":
             $type = "_SATELLITE_TYPE";
             break;
         case "Map":
             $type = "_MAP_TYPE";
             break;
         case "Hybrid":
             $type = "_HYBRID_TYPE";
             break;
         default:
             return $this->error(sprintf(_("invalid argument %s"), $MapType));
     }
     $div = HTML::div(array('id' => $id, 'style' => 'width: ' . $width . '; height: ' . $height));
     // TODO: Check for multiple markers or polygons
     if (!$InfoText) {
         $Marker = false;
     }
     // Create a marker whose info window displays the given text
     if ($Marker) {
         if ($InfoText) {
             include_once "lib/BlockParser.php";
             $page = $dbi->getPage($request->getArg('pagename'));
             $rev = $page->getCurrentRevision(false);
             $markup = $rev->get('markup');
             $markertext = TransformText($InfoText, $markup, $basepage);
         }
         $markerjs = JavaScript("\nfunction createMarker(point, text) {\n  var marker = new GMarker(point);\n  var html = text + \"<br><br><font size='-1'>[" . _("new&nbsp;window") . "]</font>\";\n  GEvent.addListener(marker, \"click\", function() {marker.openInfoWindowHtml(html);});\n  return marker;\n}");
     }
     $run = JavaScript("\nvar map = new GMap(document.getElementById('" . $id . "'));\n" . ($SmallMapControl ? "map.addControl(new GSmallMapControl());\n" : "map.addControl(new GLargeMapControl());\n") . "\nmap.addControl(new GMapTypeControl());\nmap.centerAndZoom(new GPoint(" . $Longitude . ", " . $Latitude . "), " . $ZoomFactor . ");\nmap.setMapType(" . $type . ");" . ($Marker ? "\nvar point = new GPoint(" . $Longitude . "," . $Latitude . ");\nvar marker = createMarker(point, '" . $markertext->asXml() . "'); map.addOverlay(marker);" : ""));
     if ($Marker) {
         return HTML($markerjs, $maps, $div, $run);
     } else {
         return HTML($maps, $div, $run);
     }
 }
示例#2
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     include_once "lib/BlockParser.php";
     // MediawikiTablePlugin markup is new.
     $markup = 2.0;
     // We allow the compact Mediawiki syntax with:
     // - multiple cells on the same line (separated by "||"),
     // - multiple header cells on the same line (separated by "!!").
     $argstr = str_replace("||", "\n| ", $argstr);
     $argstr = str_replace("!!", "\n! ", $argstr);
     $lines = preg_split('/\\n/', $argstr);
     $table = HTML::table();
     // We always generate an Id for the table.
     // This is convenient for tables of class "sortable".
     // If user provides an Id, the generated Id will be overwritten below.
     $table->setAttr("id", GenerateId("MediawikiTable"));
     if (substr($lines[0], 0, 2) == "{|") {
         // Start of table
         $lines[0] = substr($lines[0], 2);
     }
     if ($lines[0][0] != '|' and $lines[0][0] != '!') {
         $line = array_shift($lines);
         $attrs = parse_attributes($line);
         foreach ($attrs as $key => $value) {
             if (in_array($key, array("id", "class", "title", "style", "bgcolor", "frame", "rules", "border", "cellspacing", "cellpadding", "summary", "align", "width"))) {
                 $table->setAttr($key, $value);
             }
         }
     }
     if (count($lines) == 1) {
         // empty table, we only have closing "|}" line
         return HTML::raw('');
     }
     foreach ($lines as $line) {
         if (substr($line, 0, 2) == "|}") {
             // End of table
             continue;
         }
         if (substr($line, 0, 2) == "|-") {
             if (isset($row)) {
                 if (isset($cell)) {
                     if (isset($content)) {
                         if (is_numeric(trim($content))) {
                             $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
                         } else {
                             $cell->pushContent(TransformText(trim($content), $markup, $basepage));
                         }
                         unset($content);
                     }
                     $row->pushContent($cell);
                     unset($cell);
                 }
                 if (isset($thead)) {
                     $thead->pushContent($row);
                     $table->pushContent($thead);
                     unset($thead);
                     $tbody = HTML::tbody();
                 } else {
                     $tbody->pushContent($row);
                 }
             }
             $row = HTML::tr();
             $attrs = parse_attributes(substr($line, 2));
             foreach ($attrs as $key => $value) {
                 if (in_array($key, array("id", "class", "title", "style", "bgcolor", "align", "valign"))) {
                     $row->setAttr($key, $value);
                 }
             }
             continue;
         }
         // Table summary
         if (substr($line, 0, 2) == "|=") {
             $line = substr($line, 2);
             $table->setAttr("summary", trim($line));
         }
         // Table caption
         if (substr($line, 0, 2) == "|+") {
             $caption = HTML::caption();
             $line = substr($line, 2);
             $pospipe = strpos($line, "|");
             $posbracket = strpos($line, "[");
             if ($pospipe !== false && ($posbracket === false || $posbracket > $pospipe)) {
                 $attrs = parse_attributes(substr($line, 0, $pospipe));
                 foreach ($attrs as $key => $value) {
                     if (in_array($key, array("id", "class", "title", "style", "align", "lang"))) {
                         $caption->setAttr($key, $value);
                     }
                 }
                 $line = substr($line, $pospipe + 1);
             }
             $caption->pushContent(trim($line));
             $table->pushContent($caption);
         }
         if ((substr($line, 0, 1) == "|" or substr($line, 0, 1) == "!") and isset($row)) {
             if (isset($cell)) {
                 if (isset($content)) {
                     if (is_numeric(trim($content))) {
                         $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
                     } else {
                         $cell->pushContent(TransformText(trim($content), $markup, $basepage));
                     }
                     unset($content);
                 }
                 $row->pushContent($cell);
             }
             if (substr($line, 0, 1) == "!") {
                 $cell = HTML::th();
                 // Header
                 $thead = HTML::thead();
             } else {
                 $cell = HTML::td();
                 if (!isset($tbody)) {
                     $tbody = HTML::tbody();
                 }
             }
             $line = substr($line, 1);
             // If there is a "|" in the line, the start of line
             // (before the "|") is made of attributes.
             // The end of the line (after the "|") is the cell content
             // This is not true if the pipe is inside [], {{}} or {{{}}}
             // | [foo|bar]
             // The following cases must work:
             // | foo
             // | [foo|bar]
             // | class="xxx" | foo
             // | class="xxx" | [foo|bar]
             // | {{tmpl|arg=val}}
             // | {{image.png|alt}}
             // | {{{ xxx | yyy }}}
             $pospipe = strpos($line, "|");
             $posbracket = strpos($line, "[");
             $poscurly = strpos($line, "{");
             if ($pospipe !== false && ($posbracket === false || $posbracket > $pospipe) && ($poscurly === false || $poscurly > $pospipe)) {
                 $attrs = parse_attributes(substr($line, 0, $pospipe));
                 foreach ($attrs as $key => $value) {
                     if (in_array($key, array("id", "class", "title", "style", "colspan", "rowspan", "width", "height", "bgcolor", "align", "valign"))) {
                         $cell->setAttr($key, $value);
                     }
                 }
                 $line = substr($line, $pospipe + 1);
                 if (is_numeric(trim($line))) {
                     $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($line)));
                 } else {
                     $cell->pushContent(TransformText(trim($line), $markup, $basepage));
                 }
                 continue;
             }
         }
         if (isset($row) and isset($cell)) {
             $line = str_replace("?\\>", "?>", $line);
             $line = str_replace("\\~", "~", $line);
             if (empty($content)) {
                 $content = '';
             }
             $content .= $line . "\n";
         }
     }
     if (isset($row)) {
         if (isset($cell)) {
             if (isset($content)) {
                 if (is_numeric(trim($content))) {
                     $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content)));
                 } else {
                     $cell->pushContent(TransformText(trim($content), $markup, $basepage));
                 }
             }
             $row->pushContent($cell);
         }
         $tbody->pushContent($row);
         $table->pushContent($tbody);
     }
     return $table;
 }
示例#3
0
 function expand($basepage, &$markup)
 {
     $loader = $this->_getLoader();
     $xml = $loader->expandPI($this->_pi, $GLOBALS['request'], $markup, $basepage);
     $div = HTML::div(array('class' => 'plugin'));
     if (is_array($plugin_cmdline = $loader->parsePI($this->_pi)) and $plugin_cmdline[1]) {
         $id = GenerateId($plugin_cmdline[1]->getName() . 'Plugin');
     }
     if (isset($this->_tightenable)) {
         if ($this->_tightenable == 3) {
             $span = HTML::span(array('class' => 'plugin'), $xml);
             if (!empty($id)) {
                 $span->setAttr('id', $id);
             }
             return $span;
         }
         $div->setInClass('tightenable');
         $div->setInClass('top', ($this->_tightenable & 1) != 0);
         $div->setInClass('bottom', ($this->_tightenable & 2) != 0);
     }
     if (!empty($id)) {
         $div->setAttr('id', $id);
     }
     $div->pushContent($xml);
     return $div;
 }
示例#4
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     extract($this->getArgs($argstr, $request));
     if ($pagename) {
         // Expand relative page names.
         $page = new WikiPageName($pagename, $basepage);
         $pagename = $page->name;
     }
     if (!$pagename) {
         return $this->error(_("no page specified"));
     }
     if (isBrowserIE() and browserDetect("Mac")) {
         $jshide = 0;
     }
     if ($notoc or $liststyle == 'ol') {
         $with_counter = 1;
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $pagename)) {
         return $this->error(sprintf(_("Illegal access to page %s: no read access"), $pagename));
     }
     $page = $dbi->getPage($pagename);
     $current = $page->getCurrentRevision();
     //FIXME: I suspect this only to crash with Apache2
     if (!$current->get('markup') or $current->get('markup') < 2) {
         if (in_array(php_sapi_name(), array('apache2handler', 'apache2filter'))) {
             trigger_error(_("CreateToc disabled for old markup"), E_USER_WARNING);
             return '';
         }
     }
     $content = $current->getContent();
     $html = HTML::div(array('class' => 'toc', 'id' => GenerateId("toc")));
     if ($notoc) {
         $html->setAttr('style', 'display:none;');
     }
     if ($position == "left" or $position == "right") {
         $html->setAttr('style', 'float:' . $position . '; width:' . $width . ';');
     }
     $toclistid = GenerateId("toclist");
     $list = HTML::div(array('id' => $toclistid, 'class' => 'toclist'));
     if (!strstr($headers, ",")) {
         $headers = array($headers);
     } else {
         $headers = explode(",", $headers);
     }
     $levels = array();
     foreach ($headers as $h) {
         //replace !!! with level 1, ...
         if (strstr($h, "!")) {
             $hcount = substr_count($h, '!');
             $level = min(max(1, $hcount), 3);
             $levels[] = $level;
         } else {
             $level = min(max(1, (int) $h), 5);
             $levels[] = $level;
         }
     }
     if (TOC_FULL_SYNTAX) {
         require_once "lib/InlineParser.php";
     }
     if ($headers = $this->extractHeaders($content, $dbi->_markup, $with_toclink, $with_counter, $levels, $firstlevelstyle, $basepage)) {
         foreach ($headers as $h) {
             // proper heading indent
             $level = $h['level'];
             $indent = $level - 1;
             $link = new WikiPageName($pagename, $page, $h['anchor']);
             $li = WikiLink($link, 'known', $h['text']);
             // Hack to suppress pagename before #
             // $li->_attr["href"] = strstr($li->_attr["href"], '#');
             $list->pushContent(HTML::p(HTML::raw(str_repeat($indentstr, $indent)), $li));
         }
     }
     $list->setAttr('style', 'display:' . ($jshide ? 'none;' : 'block;'));
     $open = DATA_PATH . '/' . $WikiTheme->_findFile("images/folderArrowOpen.png");
     $close = DATA_PATH . '/' . $WikiTheme->_findFile("images/folderArrowClosed.png");
     if ($noheader) {
     } else {
         $toctoggleid = GenerateId("toctoggle");
         if ($extracollapse) {
             $toclink = HTML(_("Table of Contents"), " ", HTML::a(array('id' => 'TOC')), HTML::img(array('id' => $toctoggleid, 'class' => 'wikiaction', 'title' => _("Click to display to TOC"), 'onclick' => "toggletoc(this, '" . $open . "', '" . $close . "', '" . $toclistid . "')", 'alt' => 'toctoggle', 'src' => $jshide ? $close : $open)));
         } else {
             $toclink = HTML::a(array('id' => 'TOC', 'class' => 'wikiaction', 'title' => _("Click to display"), 'onclick' => "toggletoc(this, '" . $open . "', '" . $close . "', '" . $toclistid . "')"), _("Table of Contents"), HTML::span(array('style' => 'display:none', 'id' => $toctoggleid), " "));
         }
         $html->pushContent(HTML::p(array('class' => 'toctitle'), $toclink));
     }
     $html->pushContent($list);
     if (count($headers) == 0) {
         // Do not display an empty TOC
         $html->setAttr('style', 'display:none;');
     }
     return $html;
 }