Esempio n. 1
0
 /**
  * Test generating proper span
  *
  * @group laravel
  */
 public function testGeneratingSpan()
 {
     $html1 = HTML::span('foo');
     $html2 = HTML::span('foo', array('class' => 'badge'));
     $this->assertEquals('<span>foo</span>', $html1);
     $this->assertEquals('<span class="badge">foo</span>', $html2);
 }
Esempio n. 2
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     $maincat = $dbi->getPage(_("CategoryCategory"));
     $bi = $maincat->getBackLinks(false);
     $bl = array();
     while ($b = $bi->next()) {
         $name = $b->getName();
         if (preg_match("/^" . _("Template") . "/", $name)) {
             continue;
         }
         $pages = $b->getBackLinks(false);
         $bl[] = array('name' => $name, 'count' => $pages->count());
     }
     usort($bl, 'cmp_by_count');
     $html = HTML::ul();
     $i = 0;
     foreach ($bl as $b) {
         $i++;
         $name = $b['name'];
         $count = $b['count'];
         if ($count < $mincount) {
             break;
         }
         if ($i > $limit) {
             break;
         }
         $wo = preg_replace("/^(" . _("Category") . "|" . _("Topic") . ")/", "", $name);
         $wo = HTML(HTML::span($wo), HTML::raw("&nbsp;"), HTML::small("(" . $count . ")"));
         $link = WikiLink($name, 'auto', $wo);
         $html->pushContent(HTML::li($link));
     }
     return $html;
 }
Esempio n. 3
0
 public function __construct(array $objects, $edit = null, $add = true, $delete = true)
 {
     $this->list = '';
     foreach ($objects as $object) {
         $properties = $this->getProperties($object);
         $propertyList = '';
         foreach ($properties as $class => $property) {
             $propertyList .= HTML::span(['class' => $class], $property);
         }
         $id = $object->getId();
         if ($edit) {
             $properties = HTML::span(['class' => 'properties'], HTML::a(['href' => "/edit/{$edit}/{$id}"], $propertyList));
         } else {
             $properties = HTML::span(['class' => 'properties'], $propertyList);
         }
         if ($delete) {
             $deleteLink = HTML::span(['class' => 'delete'], HTML::a(['href' => "/delete/{$edit}/{$id}"], 'x'));
         } else {
             $deleteLink = '';
         }
         $this->list .= HTML::div(['class' => 'objectRow'], $properties . $deleteLink);
     }
     if ($add && $edit) {
         $this->list .= HTML::div(HTML::span(HTML::a(['href' => "/edit/{$edit}/"], 'add ' . $edit)));
     }
     $this->list = HTML::div(['class' => 'objectList'], $this->list);
 }
Esempio n. 4
0
 function linkUnknownWikiWord($wikiword, $linktext = '')
 {
     global $request;
     // Get rid of anchors on unknown wikiwords
     if (isa($wikiword, 'WikiPageName')) {
         $default_text = $wikiword->shortName;
         $wikiword = $wikiword->name;
     } else {
         $default_text = $wikiword;
     }
     $url = WikiURL($wikiword, array('action' => 'create'));
     //$link = HTML::span(HTML::a(array('href' => $url), '?'));
     $button = $this->makeButton('?', $url);
     $button->addTooltip(sprintf(_("Create: %s"), $wikiword));
     $link = HTML::span($button);
     if (!empty($linktext)) {
         $link->unshiftContent(HTML::u($linktext));
         $link->setAttr('class', 'named-wikiunknown');
     } else {
         $link->unshiftContent(HTML::u($this->maybeSplitWikiWord($default_text)));
         $link->setAttr('class', 'wikiunknown');
     }
     if ($request->getArg('frame')) {
         $link->setAttr('target', '_top');
     }
     return $link;
 }
Esempio n. 5
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $rss_parser = new RSSParser();
     if (!empty($url)) {
         $rss_parser->parse_url($url, $debug);
     }
     if (!empty($rss_parser->channel['title'])) {
         $feed = $rss_parser->channel['title'];
     }
     if (!empty($rss_parser->channel['link'])) {
         $url = $rss_parser->channel['link'];
     }
     if (!empty($rss_parser->channel['description'])) {
         $description = $rss_parser->channel['description'];
     }
     if (!empty($feed)) {
         if (!empty($url)) {
             $titre = HTML::span(HTML::a(array('href' => $rss_parser->channel['link']), $rss_parser->channel['title']));
         } else {
             $titre = HTML::span($rss_parser->channel['title']);
         }
         $th = HTML::div(array('class' => 'feed'), $titre);
         if (!empty($description)) {
             $th->pushContent(HTML::p(array('class' => 'chandesc'), HTML::raw($description)));
         }
     } else {
         $th = HTML();
     }
     if (!empty($rss_parser->channel['date'])) {
         $th->pushContent(HTML::raw("<!--" . $rss_parser->channel['date'] . "-->"));
     }
     $html = HTML::div(array('class' => 'rss'), $th);
     if ($rss_parser->items) {
         // only maxitem's
         if ($maxitem > 0) {
             $rss_parser->items = array_slice($rss_parser->items, 0, $maxitem);
         }
         foreach ($rss_parser->items as $item) {
             $cell = HTML::div(array('class' => 'rssitem'));
             if ($item['link'] and empty($item['title'])) {
                 $item['title'] = $item['link'];
             }
             $cell_title = HTML::div(array('class' => 'itemname'), HTML::a(array('href' => $item['link']), HTML::raw($item['title'])));
             $cell->pushContent($cell_title);
             if (!empty($item['description'])) {
                 $cell->pushContent(HTML::div(array('class' => 'itemdesc'), HTML::raw($item['description'])));
             }
             $html->pushContent($cell);
         }
     } else {
         $html = HTML::div(array('class' => 'rss'), HTML::em(_("no RSS items")));
     }
     if (!check_php_version(5)) {
         $rss_parser->__destruct();
     }
     return $html;
 }
Esempio n. 6
0
 function linkUnknownWikiWord($wikiword, $linktext = '')
 {
     global $request;
     if (isa($wikiword, 'WikiPageName')) {
         $default_text = $wikiword->shortName;
         $wikiword = $wikiword->name;
     } else {
         $default_text = $wikiword;
     }
     $url = WikiURL($wikiword, array('action' => 'create'));
     $link = HTML::span(HTML::a(array('href' => $url, 'rel' => 'nofollow'), '?'));
     if (!empty($linktext)) {
         $link->unshiftContent(HTML::u($linktext));
         $link->setAttr('class', 'named-wikiunknown');
     } else {
         $link->unshiftContent(HTML::u($this->maybeSplitWikiWord($default_text)));
         $link->setAttr('class', 'wikiunknown');
     }
     return $link;
 }
Esempio n. 7
0
 public function __toString()
 {
     $lbl_span = \HTML::span($this->label);
     if (is_null($this->icon) or empty($this->icon) or !is_string($this->icon)) {
         $icon = '';
     } else {
         if (strpos('<i', $this->icon) !== false) {
             $icon = $this->icon;
         } else {
             $icon = '<i class="' . $this->icon . '"></i>';
         }
     }
     $icon .= PHP_EOL;
     if (is_null($this->action) or !is_string($this->action)) {
         $button = '';
     } else {
         if ($this->action == static::BUTTON_FILE or $this->action == 'file') {
             $input = '<input type="file" name="' . $this->fileInputName . '[]" multiple>';
             $button = '<span class="' . $this->class . '"' . \HTML::attributes($this->attributes) . '>';
             $button .= $icon . $lbl_span . $input;
             $button .= '</span>';
         } else {
             if ($this->action == static::BUTTON_START) {
                 $type = 'submit';
             } else {
                 if ($this->action == static::BUTTON_CANCEL) {
                     $type = 'reset';
                 } else {
                     //if ($this->action == static::BUTTON_DELETE)
                     $type = 'button';
                 }
             }
             $button = '<button type="' . $type . '" class="' . $this->class . '"' . \HTML::attributes($this->attributes) . '>';
             $button .= $icon . $lbl_span;
             $button .= '</button>';
         }
     }
     return $button . PHP_EOL;
 }
Esempio n. 8
0
 function link($link, $linktext = false)
 {
     global $WikiTheme;
     list($moniker, $page) = explode(":", $link, 2);
     if (!isset($this->_map[$moniker])) {
         return HTML::span(array('class' => 'bad-interwiki'), $linktext ? $linktext : $link);
     }
     $url = $this->_map[$moniker];
     // localize Upload:links for WIKIDUMP
     if (!empty($WikiTheme->DUMP_MODE) and $moniker == 'Upload') {
         global $request;
         include_once "lib/config.php";
         $url = getUploadFilePath();
         // calculate to a relative local path to /uploads for pdf images.
         $doc_root = $request->get("DOCUMENT_ROOT");
         $ldir = NormalizeLocalFileName($url);
         $wikiroot = NormalizeLocalFileName('');
         if (isWindows()) {
             $ldir = strtolower($ldir);
             $doc_root = strtolower($doc_root);
             $wikiroot = strtolower($wikiroot);
         }
         if (string_starts_with($ldir, $doc_root)) {
             $link_prefix = substr($url, strlen($doc_root));
         } elseif (string_starts_with($ldir, $wikiroot)) {
             $link_prefix = NormalizeWebFileName(substr($url, strlen($wikiroot)));
         }
     }
     // Urlencode page only if it's a query arg.
     // FIXME: this is a somewhat broken heuristic.
     if ($moniker == 'Upload') {
         $page_enc = $page;
         $page = rawurldecode($page);
     } else {
         $page_enc = strstr($url, '?') ? rawurlencode($page) : $page;
     }
     if (strstr($url, '%s')) {
         $url = sprintf($url, $page_enc);
     } else {
         $url .= $page_enc;
     }
     $link = HTML::a(array('href' => $url));
     if (!$linktext) {
         $link->pushContent(PossiblyGlueIconToText('interwiki', "{$moniker}:"), HTML::span(array('class' => 'wikipage'), $page));
         $link->setAttr('class', 'interwiki');
     } else {
         $link->pushContent(PossiblyGlueIconToText('interwiki', $linktext));
         $link->setAttr('class', 'named-interwiki');
     }
     return $link;
 }
Esempio n. 9
0
 function navItem($name, $page_id, $act_page_id)
 {
     return HTML::div('menu_item', HTML::span('menu_link', HTML::a('index.php?id=' . $page_id, $name)));
 }
Esempio n. 10
0
function LinkPhpwikiURL($url, $text = '', $basepage = false)
{
    $args = array();
    if (!preg_match('/^ phpwiki: ([^?]*) [?]? (.*) $/x', $url, $m)) {
        return HTML::span(array('class' => 'error'), _("BAD phpwiki: URL"));
    }
    if ($m[1]) {
        $pagename = urldecode($m[1]);
    }
    $qargs = $m[2];
    if (empty($pagename) && preg_match('/^(diff|edit|links|info)=([^&]+)$/', $qargs, $m)) {
        // Convert old style links (to not break diff links in
        // RecentChanges).
        $pagename = urldecode($m[2]);
        $args = array("action" => $m[1]);
    } else {
        $args = SplitQueryArgs($qargs);
    }
    if (empty($pagename)) {
        $pagename = $GLOBALS['request']->getArg('pagename');
    }
    if (isset($args['action']) && $args['action'] == 'browse') {
        unset($args['action']);
    }
    /*FIXME:
        if (empty($args['action']))
        $class = 'wikilink';
        else if (is_safe_action($args['action']))
        $class = 'wikiaction';
      */
    if (empty($args['action']) || is_safe_action($args['action'])) {
        $class = 'wikiaction';
    } else {
        // Don't allow administrative links on unlocked pages.
        $dbi = $GLOBALS['request']->getDbh();
        $page = $dbi->getPage($basepage ? $basepage : $pagename);
        if (!$page->get('locked')) {
            return HTML::span(array('class' => 'wikiunsafe'), HTML::u(_("Lock page to enable link")));
        }
        $class = 'wikiadmin';
    }
    if (!$text) {
        $text = HTML::span(array('class' => 'rawurl'), $url);
    }
    $wikipage = new WikiPageName($pagename);
    if (!$wikipage->isValid()) {
        global $WikiTheme;
        return $WikiTheme->linkBadWikiWord($wikipage, $url);
    }
    return HTML::a(array('href' => WikiURL($pagename, $args), 'class' => $class), $text);
}
Esempio n. 11
0
<?php

HTML::macro('glyph', function ($what, $class = '') {
    $a = ['class' => "glyphicon glyphicon-{$what}"];
    if (!empty($class)) {
        $a['class'] .= ' ' . $class;
    }
    return HTML::span('', $a);
});
HTML::macro('pageHeader', function ($innards) {
    return '<div class="page-header"><h1>' . $innards . '</h1></div>';
});
HTML::macro('label', function ($name, $value = null, $options = array(), $optional = false) {
    if ($optional) {
        return HTML::label_optional($name, $value, $options);
    }
    return Form::label($name, $value, $options);
});
HTML::macro('label_optional', function ($name, $value = null, $options = array()) {
    $optional = ' <small><span class="text-muted label-optional">(optional)</span></small>';
    return HTML::decode(Form::label($name, $value . $optional, $options));
});
HTML::macro('bootstrap_label', function ($what, $type = null, $attributes = null, $class = '') {
    // default | primary | success | info | warning | danger
    $type = is_null($type) ? 'default' : $type;
    $class = !empty($class) ? ' ' . $class : $class;
    return '<span class="label label-' . $type . $class . '"' . HTML::atts($attributes) . '>' . $what . '</span>';
});
Esempio n. 12
0
 /**
  * Build a range of numeric pagination links.
  *
  * For the current page, an HTML span element will be generated instead of a link.
  *
  * @param  int     $start
  * @param  int     $end
  * @return string
  */
 protected function range($start, $end)
 {
     $pages = array();
     // To generate the range of page links, we will iterate through each page
     // and, if the current page matches the page, we will generate a span,
     // otherwise we will generate a link for the page. The span elements
     // will be assigned the "current" CSS class for convenient styling.
     for ($page = $start; $page <= $end; $page++) {
         if ($this->page == $page) {
             $pages[] = HTML::span($page, array('class' => 'current'));
         } else {
             $pages[] = $this->link($page, $page, null);
         }
     }
     return implode(' ', $pages);
 }
Esempio n. 13
0
 function checkBox(&$post_args, $name, $msg)
 {
     $checkbox = HTML::input(array('type' => 'checkbox', 'name' => 'admin_rename[' . $name . ']', 'value' => 1));
     if (!empty($post_args[$name])) {
         $checkbox->setAttr('checked', 'checked');
     }
     return HTML::div($checkbox, ' ', HTML::span($msg));
 }
Esempio n. 14
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $attributes = $attrib ? explode(",", $attrib) : array();
     $photos = array();
     $html = HTML();
     $count = 0;
     // check all parameters
     // what type do we have?
     if (!$src) {
         $showdesc = 'none';
         $src = $request->getArg('pagename');
         $error = $this->fromLocation($src, $photos);
     } else {
         $error = $this->fromFile($src, $photos, $url);
     }
     if ($error) {
         return $this->error($error);
     }
     if ($numcols < 1) {
         $numcols = 1;
     }
     if ($align != 'left' && $align != 'center' && $align != 'right') {
         $align = 'center';
     }
     if (count($photos) == 0) {
         return;
     }
     if (in_array("sort", $attributes)) {
         sort($photos);
     }
     if ($p) {
         $mode = "normal";
     }
     if ($mode == "column") {
         $mode = "normal";
         $numcols = "1";
     }
     // set some fixed properties for each $mode
     if ($mode == 'thumbs' || $mode == 'tiles') {
         $attributes = array_merge($attributes, "alt");
         $attributes = array_merge($attributes, "nowrap");
         $cellwidth = 'auto';
         // else cell won't nowrap
         $width = 50;
     } elseif ($mode == 'list') {
         $numcols = 1;
         $cellwidth = "auto";
         $width = 50;
     } elseif ($mode == 'slide') {
         $tableheight = 0;
         $cell_width = 0;
         $numcols = count($photos);
         $keep = $photos;
         while (list($key, $value) = each($photos)) {
             list($x, $y, $s, $t) = @getimagesize($value['src']);
             if ($height != 'auto') {
                 $y = $this->newSize($y, $height);
             }
             if ($width != 'auto') {
                 $y = round($y * $this->newSize($x, $width) / $x);
             }
             if ($x > $cell_width) {
                 $cell_width = $x;
             }
             if ($y > $tableheight) {
                 $tableheight = $y;
             }
         }
         $tableheight += 50;
         $photos = $keep;
         unset($x, $y, $s, $t, $key, $value, $keep);
     }
     $row = HTML();
     $duration = 1000 * $duration;
     if ($mode == 'slide') {
         $row->pushContent(JavaScript("\ni = 0;\nfunction display_slides() {\n  j = i - 1;\n  cell0 = document.getElementsByName('wikislide' + j);\n  cell = document.getElementsByName('wikislide' + i);\n  if (cell0.item(0) != null)\n    cell0.item(0).style.display='none';\n  if (cell.item(0) != null)\n    cell.item(0).style.display='block';\n  i += 1;\n  if (cell.item(0) == null) i = 0;\n  setTimeout('display_slides()',{$duration});\n}\ndisplay_slides();"));
     }
     while (list($key, $value) = each($photos)) {
         if ($p && basename($value["name"]) != "{$p}") {
             continue;
         }
         if ($h && basename($value["name"]) == "{$h}") {
             $color = $hlcolor ? $hlcolor : $bgcolor;
         } else {
             $color = $bgcolor;
         }
         // $params will be used for each <img > tag
         $params = array('src' => $value["name"], 'src_tile' => $value["name_tile"], 'border' => "0", 'alt' => ($value["desc"] != "" and in_array("alt", $attributes)) ? $value["desc"] : basename($value["name"]));
         if (!@empty($value['location'])) {
             $params = array_merge($params, array("location" => $value['location']));
         }
         // check description
         switch ($showdesc) {
             case 'none':
                 $value["desc"] = '';
                 break;
             case 'name':
                 $value["desc"] = basename($value["name"]);
                 break;
             case 'desc':
                 break;
             default:
                 // 'both'
                 if (!$value["desc"]) {
                     $value["desc"] = basename($value["name"]);
                 }
                 break;
         }
         // FIXME: get getimagesize to work with names with spaces in it.
         // convert $value["name"] from webpath to local path
         $size = @getimagesize($value["name"]);
         // try " " => "\\ "
         if (!$size and !empty($value["src"])) {
             $size = @getimagesize($value["src"]);
             if (!$size) {
                 trigger_error("Unable to getimagesize(" . $value["name"] . ")", E_USER_NOTICE);
             }
         }
         $newwidth = $this->newSize($size[0], $width);
         if ($mode == 'thumbs' || $mode == 'tiles' || $mode == 'list') {
             if (!empty($size[0])) {
                 $newheight = round(50 * $size[1] / $size[0]);
             } else {
                 $newheight = '';
             }
             if ($height == 'auto') {
                 $height = 150;
             }
         } else {
             $newheight = $this->newSize($size[1], $height);
         }
         if ($width != 'auto' && $newwidth > 0) {
             $params = array_merge($params, array("width" => $newwidth));
         }
         if ($height != 'auto' && $newheight > 0) {
             $params = array_merge($params, array("height" => $newheight));
         }
         // cell operations
         $cell = array('align' => "center", 'valign' => "top", 'bgcolor' => "{$color}");
         if ($cellwidth != 'auto') {
             if ($cellwidth == 'equal') {
                 $newcellwidth = round(100 / $numcols) . "%";
             } else {
                 if ($cellwidth == 'image') {
                     $newcellwidth = $newwidth;
                 } else {
                     $newcellwidth = $cellwidth;
                 }
             }
             $cell = array_merge($cell, array("width" => $newcellwidth));
         }
         if (in_array("nowrap", $attributes)) {
             $cell = array_merge($cell, array("nowrap" => "nowrap"));
         }
         //create url to display single larger version of image on page
         $url = WikiURL($request->getPage(), array("p" => basename($value["name"]))) . "#" . basename($value["name"]);
         $b_url = WikiURL($request->getPage(), array("h" => basename($value["name"]))) . "#" . basename($value["name"]);
         $url_text = $link ? HTML::a(array("href" => "{$url}"), basename($value["desc"])) : basename($value["name"]);
         if (!$p) {
             if ($mode == 'normal' || $mode == 'slide') {
                 if (!@empty($params['location'])) {
                     $params['src'] = $params['location'];
                 }
                 unset($params['location'], $params['src_tile']);
                 $url_image = $link ? HTML::a(array("id" => basename($value["name"])), HTML::a(array("href" => "{$url}"), HTML::img($params))) : HTML::img($params);
             } else {
                 $keep = $params;
                 if (!@empty($params['src_tile'])) {
                     $params['src'] = $params['src_tile'];
                 }
                 unset($params['location'], $params['src_tile']);
                 $url_image = $link ? HTML::a(array("id" => basename($value["name"])), HTML::a(array("href" => "{$url}"), ImageTile::image_tile($params))) : HTML::img($params);
                 $params = $keep;
                 unset($keep);
             }
         } else {
             if (!@empty($params['location'])) {
                 $params['src'] = $params['location'];
             }
             unset($params['location'], $params['src_tile']);
             $url_image = $link ? HTML::a(array("id" => basename($value["name"])), HTML::a(array("href" => "{$b_url}"), HTML::img($params))) : HTML::img($params);
         }
         if ($mode == 'list') {
             $url_text = HTML::a(array("id" => basename($value["name"])), $url_text);
         }
         // here we use different modes
         if ($mode == 'tiles') {
             $row->pushContent(HTML::td($cell, HTML::table(array("cellpadding" => 1, "border" => 0), HTML::tr(HTML::td(array("valign" => "top", "rowspan" => 2), $url_image), HTML::td(array("valign" => "top", "nowrap" => 0), HTML::span(array('class' => 'boldsmall'), $url_text), HTML::br(), HTML::span(array('class' => 'gensmall'), $size[0] . " x " . $size[1] . " pixels"))))));
         } elseif ($mode == 'list') {
             $desc = $showdesc != 'none' ? $value["desc"] : '';
             $row->pushContent(HTML::td(array("valign" => "top", "nowrap" => 0, "bgcolor" => $color), HTML::span(array('class' => 'boldsmall'), $url_text)));
             $row->pushContent(HTML::td(array("valign" => "top", "nowrap" => 0, "bgcolor" => $color), HTML::span(array('class' => 'gensmall'), $size[0] . " x " . $size[1] . " pixels")));
             if ($desc != '') {
                 $row->pushContent(HTML::td(array("valign" => "top", "nowrap" => 0, "bgcolor" => $color), HTML::span(array('class' => 'gensmall'), $desc)));
             }
         } elseif ($mode == 'thumbs') {
             $desc = $showdesc != 'none' ? HTML::p(HTML::a(array("href" => "{$url}"), $url_text)) : '';
             $row->pushContent(HTML::td($cell, $url_image, HTML::span(array('class' => 'gensmall'), $desc)));
         } elseif ($mode == 'normal') {
             $desc = $showdesc != 'none' ? HTML::p($value["desc"]) : '';
             $row->pushContent(HTML::td($cell, $url_image, HTML::span(array('class' => 'gensmall'), $desc)));
         } elseif ($mode == 'slide') {
             if ($newwidth == 'auto' || !$newwidth) {
                 $newwidth = $this->newSize($size[0], $width);
             }
             if ($newwidth == 'auto' || !$newwidth) {
                 $newwidth = $size[0];
             }
             if ($newheight != 'auto') {
                 $newwidth = round($size[0] * $newheight / $size[1]);
             }
             $desc = $showdesc != 'none' ? HTML::p($value["desc"]) : '';
             if ($count == 0) {
                 $cell = array('style' => 'display: block; ' . 'position: absolute; ' . 'left: 50% ; ' . 'margin-left: -' . round($newwidth / 2) . 'px;' . 'text-align: center; ' . 'vertical-align: top', 'name' => "wikislide" . $count);
             } else {
                 $cell = array('style' => 'display: none; ' . 'position: absolute ;' . 'left: 50% ;' . 'margin-left: -' . round($newwidth / 2) . 'px;' . 'text-align: center; ' . 'vertical-align: top', 'name' => "wikislide" . $count);
             }
             if ($align == 'left' || $align == 'right') {
                 if ($count == 0) {
                     $cell = array('style' => 'display: block; ' . 'position: absolute; ' . $align . ': 50px; ' . 'vertical-align: top', 'name' => "wikislide" . $count);
                 } else {
                     $cell = array('style' => 'display: none; ' . 'position: absolute; ' . $align . ': 50px; ' . 'vertical-align: top', 'name' => "wikislide" . $count);
                 }
             }
             $row->pushContent(HTML::td($cell, $url_image, HTML::span(array('class' => 'gensmall'), $desc)));
             $count++;
         } elseif ($mode == 'row') {
             $desc = $showdesc != 'none' ? HTML::p($value["desc"]) : '';
             $row->pushContent(HTML::table(array("style" => "display: inline"), HTML::tr(HTML::td($url_image)), HTML::tr(HTML::td(array("class" => "gensmall", "style" => "text-align: center; " . "background-color: {$color}"), $desc))));
         } else {
             return $this->error(fmt("Invalid argument: %s=%s", 'mode', $mode));
         }
         // no more images in one row as defined by $numcols
         if (($key + 1) % $numcols == 0 || $key + 1 == count($photos) || $p) {
             if ($mode == 'row') {
                 $html->pushcontent(HTML::span($row));
             } else {
                 $html->pushcontent(HTML::tr($row));
             }
             $row->setContent('');
         }
     }
     //create main table
     $table_attributes = array("border" => 0, "cellpadding" => 5, "cellspacing" => 2, "width" => $tablewidth);
     if (!@empty($tableheight)) {
         $table_attributes = array_merge($table_attributes, array("height" => $tableheight));
     }
     if ($mode != 'row') {
         $html = HTML::table($table_attributes, $html);
     }
     // align all
     return HTML::div(array("align" => $align), $html);
 }
Esempio n. 15
0
 function link($link, $linktext = false)
 {
     list($moniker, $page) = split(":", $link, 2);
     if (!isset($this->_map[$moniker])) {
         return HTML::span(array('class' => 'bad-interwiki'), $linktext ? $linktext : $link);
     }
     $url = $this->_map[$moniker];
     // Urlencode page only if it's a query arg.
     // FIXME: this is a somewhat broken heuristic.
     $page_enc = strstr($url, '?') ? rawurlencode($page) : $page;
     if (strstr($url, '%s')) {
         $url = sprintf($url, $page_enc);
     } else {
         $url .= $page_enc;
     }
     $link = HTML::a(array('href' => $url));
     if (!$linktext) {
         $link->pushContent(PossiblyGlueIconToText('interwiki', "{$moniker}:"), HTML::span(array('class' => 'wikipage'), $page));
         $link->setAttr('class', 'interwiki');
     } else {
         $link->pushContent(PossiblyGlueIconToText('interwiki', $linktext));
         $link->setAttr('class', 'named-interwiki');
     }
     return $link;
 }
Esempio n. 16
0
function RevertPage(&$request)
{
    $mesg = HTML::div();
    $pagename = $request->getArg('pagename');
    $version = $request->getArg('version');
    if (!$version) {
        PrintXML(HTML::p(fmt("Revert"), " ", WikiLink($pagename)), HTML::p(_("missing required version argument")));
        return;
    }
    $dbi =& $request->_dbi;
    $page = $dbi->getPage($pagename);
    $current = $page->getCurrentRevision();
    $currversion = $current->getVersion();
    if ($currversion == 0) {
        $mesg->pushContent(' ', _("no page content"));
        PrintXML(HTML::p(fmt("Revert"), " ", WikiLink($pagename)), $mesg);
        flush();
        return;
    }
    if ($currversion == $version) {
        $mesg->pushContent(' ', _("same version page"));
        PrintXML(HTML::p(fmt("Revert"), " ", WikiLink($pagename)), $mesg);
        flush();
        return;
    }
    if ($request->getArg('cancel')) {
        $mesg->pushContent(' ', _("Cancelled"));
        PrintXML(HTML::p(fmt("Revert"), " ", WikiLink($pagename)), $mesg);
        flush();
        return;
    }
    if (!$request->getArg('verify')) {
        $mesg->pushContent(HTML::p(fmt("Are you sure to revert %s to version {$version}?", WikiLink($pagename))), HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'), HiddenInputs($request->getArgs(), false, array('verify')), HiddenInputs(array('verify' => 1)), Button('submit:verify', _("Yes"), 'button'), HTML::Raw('&nbsp;'), Button('submit:cancel', _("Cancel"), 'button')));
        $rev = $page->getRevision($version);
        $html = HTML(HTML::fieldset($mesg), HTML::hr(), $rev->getTransformedContent());
        $template = Template('browse', array('CONTENT' => $html));
        GeneratePage($template, $pagename, $rev);
        $request->checkValidators();
        flush();
        return;
    }
    $rev = $page->getRevision($version);
    $content = $rev->getPackedContent();
    $versiondata = $rev->_data;
    $versiondata['summary'] = sprintf(_("revert to version %d"), $version);
    $new = $page->save($content, $currversion + 1, $versiondata);
    $dbi->touch();
    $mesg = HTML::span();
    $pagelink = WikiLink($pagename);
    $mesg->pushContent(fmt("Revert: %s", $pagelink), fmt("- version %d saved to database as version %d", $version, $new->getVersion()));
    // Force browse of current page version.
    $request->setArg('version', false);
    $template = Template('savepage', array());
    $template->replace('CONTENT', $new->getTransformedContent());
    GeneratePage($template, $mesg, $new);
    flush();
}
Esempio n. 17
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $page = $dbi->getPage($pagename);
     $current = $page->getCurrentRevision();
     $source = $current->getPackedContent();
     if (empty($source)) {
         return $this->error(fmt("empty source"));
     }
     if ($basepage == _("SpellCheck")) {
         return $this->error(fmt("Cannot SpellCheck myself"));
     }
     $lang = $page->get('lang');
     if (empty($lang)) {
         $lang = $GLOBALS['LANG'];
     }
     $html = HTML();
     if (!function_exists('pspell_new_config')) {
         // use the aspell commandline interface
         include_once "lib/WikiPluginCached.php";
         $args = "";
         $source = preg_replace("/^/m", "^", $source);
         if (ASPELL_DATA_DIR) {
             $args .= " --data-dir=" . ASPELL_DATA_DIR;
         }
         // MAYBE TODO: do we have the language dictionary?
         $args .= " --lang=" . $lang;
         // use -C or autosplit wikiwords in the text
         $commandLine = ASPELL_EXE . " -a -C {$args} ";
         $cache = new WikiPluginCached();
         $code = $cache->filterThroughCmd($source, $commandLine);
         if (empty($code)) {
             return $this->error(fmt("Couldn't start commandline '%s'", $commandLine));
         }
         $sugg = array();
         foreach (preg_split("/\n/", $code) as $line) {
             if (preg_match("/^& (\\w+) \\d+ \\d+: (.+)\$/", $line, $m)) {
                 $sugg[$m[1]] = preg_split("/, /", $m[2]);
             }
         }
         /*$pre = HTML::pre(HTML::raw($code));
           $html->pushContent($pre);*/
     } else {
         $sugg = pspell_check($source, $lang);
     }
     //$html->pushContent(HTML::hr(),HTML::h1(_("Spellcheck")));
     $page = $request->getPage();
     if ($version) {
         $revision = $page->getRevision($version);
         if (!$revision) {
             NoSuchRevision($request, $page, $version);
         }
     } else {
         $revision = $page->getCurrentRevision();
     }
     $GLOBALS['request']->setArg('suggestions', $sugg);
     include_once "lib/BlockParser.php";
     $ori_html = TransformText($revision, $revision->get('markup'), $page);
     $GLOBALS['request']->setArg('suggestions', false);
     $html->pushContent($ori_html, HTML::hr(), HTML::h1(_("SpellCheck result")));
     $list = HTML::ul();
     foreach ($sugg as $word => $suggs) {
         $w = HTML::span(array('class' => 'spell-wrong'), $word);
         // TODO: optional replace-link. jscript or request button with word replace.
         $r = HTML();
         foreach ($suggs as $s) {
             $r->pushContent(HTML::a(array('class' => 'spell-sugg', 'href' => "javascript:do_replace('{$word}','{$s}')"), $s), ", ");
         }
         $list->pushContent(HTML::li($w, ": ", $r));
     }
     $html->pushContent($list);
     return $html;
 }
Esempio n. 18
0
 /**
  * HTML widget display
  *
  * This needs to be put in the <body> section of the page.
  *
  * @param pagename    Name of the page to rate
  * @param version     Version of the page to rate (may be "" for current)
  * @param imgPrefix   Prefix of the names of the images that display the rating
  *                    You can have two widgets for the same page displayed at
  *                    once iff the imgPrefix-s are different.
  * @param dimension   Id of the dimension to rate
  * @param small       Makes a smaller ratings widget if non-false
  *
  * Limitations: Currently this can only print the current users ratings.
  *              And only the widget, but no value (for buddies) also.
  */
 function RatingWidgetHtml($pagename, $version, $imgPrefix, $dimension, $small = false)
 {
     global $WikiTheme, $request;
     $dbi =& $request->_dbi;
     $version = $dbi->_backend->get_latest_version($pagename);
     $pageid = sprintf("%u", crc32($pagename));
     // MangleXmlIdentifier($pagename)
     $imgId = 'RateIt' . $pageid;
     $actionImgName = 'RateIt' . $pageid . 'Action';
     //$rdbi =& $this->_rdbi;
     $rdbi = RatingsDb::getTheRatingsDb();
     // check if the imgPrefix icons exist.
     if (!$WikiTheme->_findData("images/RateIt" . $imgPrefix . "Nk0.png", true)) {
         $imgPrefix = '';
     }
     // Protect against \'s, though not \r or \n
     $reImgPrefix = $this->_javascript_quote_string($imgPrefix);
     $reImgId = $this->_javascript_quote_string($imgId);
     $reActionImgName = $this->_javascript_quote_string($actionImgName);
     $rePagename = $this->_javascript_quote_string($pagename);
     //$dimension = $args['pagename'] . "rat";
     $html = HTML::span(array("class" => "rateit-widget", "id" => $imgId));
     for ($i = 0; $i < 2; $i++) {
         $ok[$i] = $WikiTheme->_findData("images/RateIt" . $imgPrefix . "Ok" . $i . ".png");
         // empty
         $nk[$i] = $WikiTheme->_findData("images/RateIt" . $imgPrefix . "Nk" . $i . ".png");
         // rated
         $rk[$i] = $WikiTheme->_findData("images/RateIt" . $imgPrefix . "Rk" . $i . ".png");
         // pred
     }
     if (empty($this->userid)) {
         $user = $request->getUser();
         $this->userid = $user->getId();
     }
     if (empty($this->rating)) {
         $this->rating = $rdbi->getRating($this->userid, $pagename, $dimension);
         if (!$this->rating and empty($this->pred)) {
             $this->pred = $rdbi->getPrediction($this->userid, $pagename, $dimension);
         }
     }
     for ($i = 1; $i <= 10; $i++) {
         $j = $i / 2;
         $a1 = HTML::a(array('href' => "javascript:clickRating('{$reImgPrefix}','{$rePagename}','{$version}'," . "'{$reImgId}','{$dimension}',{$j})"));
         $img_attr = array();
         $img_attr['src'] = $nk[$i % 2];
         if ($this->rating) {
             $img_attr['src'] = $ok[$i % 2];
             $img_attr['onmouseover'] = "displayRating('{$reImgId}','{$reImgPrefix}',{$j},0,1)";
             $img_attr['onmouseout'] = "displayRating('{$reImgId}','{$reImgPrefix}',{$this->rating},0,1)";
         } else {
             if (!$this->rating and $this->pred) {
                 $img_attr['src'] = $rk[$i % 2];
                 $img_attr['onmouseover'] = "displayRating('{$reImgId}','{$reImgPrefix}',{$j},1,1)";
                 $img_attr['onmouseout'] = "displayRating('{$reImgId}','{$reImgPrefix}',{$this->pred},1,1)";
             } else {
                 $img_attr['onmouseover'] = "displayRating('{$reImgId}','{$reImgPrefix}',{$j},0,1)";
                 $img_attr['onmouseout'] = "displayRating('{$reImgId}','{$reImgPrefix}',0,0,1)";
             }
         }
         //$imgName = 'RateIt'.$reImgId.$i;
         $img_attr['id'] = $imgId . $i;
         $img_attr['alt'] = $img_attr['id'];
         $a1->pushContent(HTML::img($img_attr));
         //$a1->addToolTip(_("Rate the topic of this page"));
         $html->pushContent($a1);
         //This adds a space between the rating smilies:
         //if (($i%2) == 0) $html->pushContent("\n");
     }
     $html->pushContent(HTML::Raw("&nbsp;"));
     $a0 = HTML::a(array('href' => "javascript:clickRating('{$reImgPrefix}','{$rePagename}','{$version}'," . "'{$reImgId}','{$dimension}','X')"));
     $msg = _("Cancel your rating");
     $imgprops = array('src' => $WikiTheme->getImageUrl("RateIt" . $imgPrefix . "Cancel"), 'id' => $imgId . $imgPrefix . 'Cancel', 'alt' => $msg, 'title' => $msg);
     if (!$this->rating) {
         $imgprops['style'] = 'display:none';
     }
     $a0->pushContent(HTML::img($imgprops));
     $a0->addToolTip($msg);
     $html->pushContent($a0);
     /*} elseif ($pred) {
           $msg = _("No opinion");
           $html->pushContent(HTML::img(array('src' => $WikiTheme->getImageUrl("RateItCancelN"),
                                              'id'  => $imgPrefix.'Cancel',
                                              'alt' => $msg)));
           //$a0->addToolTip($msg);
           //$html->pushContent($a0);
       }*/
     $img_attr = array();
     $img_attr['src'] = $WikiTheme->_findData("images/spacer.png");
     $img_attr['id'] = $actionImgName;
     $img_attr['alt'] = $img_attr['id'];
     $img_attr['height'] = 15;
     $img_attr['width'] = 20;
     $html->pushContent(HTML::img($img_attr));
     // Display your current rating if there is one, or the current prediction
     // or the empty widget.
     $pred = empty($this->pred) ? 0 : $this->pred;
     $js = '';
     if (!empty($this->avg)) {
         $js .= "avg['{$reImgId}']={$this->avg}; numusers['{$reImgId}']={$this->numusers};\n";
     }
     if ($this->rating) {
         $js .= "rating['{$reImgId}']={$this->rating}; prediction['{$reImgId}']={$pred};\n";
         $html->pushContent(JavaScript($js . "displayRating('{$reImgId}','{$reImgPrefix}',{$this->rating},0,1);"));
     } elseif (!empty($this->pred)) {
         $js .= "rating['{$reImgId}']=0; prediction['{$reImgId}']={$this->pred};\n";
         $html->pushContent(JavaScript($js . "displayRating('{$reImgId}','{$reImgPrefix}',{$this->pred},1,1);"));
     } else {
         $js .= "rating['{$reImgId}']=0; prediction['{$reImgId}']=0;\n";
         $html->pushContent(JavaScript($js . "displayRating('{$reImgId}','{$reImgPrefix}',0,0,1);"));
     }
     return $html;
 }
 function replaceForm(&$header, $post_args)
 {
     $header->pushContent(HTML::div(array('class' => 'hint'), _("Replace all occurences of the given string in the content of all pages.")), HTML::br());
     $header->pushContent(_("Replace: "));
     $header->pushContent(HTML::input(array('name' => 'admin_replace[from]', 'value' => $post_args['from'])));
     $header->pushContent(' ' . _("by") . ': ');
     $header->pushContent(HTML::input(array('name' => 'admin_replace[to]', 'value' => $post_args['to'])));
     $checkbox = HTML::input(array('type' => 'checkbox', 'name' => 'admin_replace[case_exact]', 'value' => 1));
     if (!empty($post_args['case_exact'])) {
         $checkbox->setAttr('checked', 'checked');
     }
     $header->pushContent(HTML::br(), $checkbox, " ", _("case-exact"));
     $checkbox_re = HTML::input(array('type' => 'checkbox', 'name' => 'admin_replace[regex]', 'value' => 1));
     if (!empty($post_args['regex'])) {
         $checkbox_re->setAttr('checked', 'checked');
     }
     $header->pushContent(HTML::br(), HTML::span($checkbox_re, " ", _("regex")));
     $header->pushContent(HTML::br());
     return $header;
 }
Esempio n. 20
0
 /**
  * Build a range of page links. 
  *
  * For the current page, an HTML span element will be generated instead of a link.
  *
  * @param  int     $start
  * @param  int     $end
  * @return string
  */
 private function range($start, $end)
 {
     $pages = '';
     for ($i = $start; $i <= $end; $i++) {
         $pages .= $this->page == $i ? HTML::span($i, array('class' => 'current')) . ' ' : $this->link($i, $i, null) . ' ';
     }
     return $pages;
 }
Esempio n. 21
0
 /**
  * HTML widget display
  *
  * This needs to be put in the <body> section of the page.
  *
  * @param pagename    Name of the page to rate
  * @param version     Version of the page to rate (may be "" for current)
  * @param imgPrefix   Prefix of the names of the images that display the rating
  *                    You can have two widgets for the same page displayed at
  *                    once iff the imgPrefix-s are different.
  * @param dimension   Id of the dimension to rate
  * @param small       Makes a smaller ratings widget if non-false
  *
  * Limitations: Currently this can only print the current users ratings.
  *              And only the widget, but no value (for buddies) also.
  */
 function RatingWidgetHtml($pagename, $version, $imgPrefix, $dimension, $small = false)
 {
     global $WikiTheme, $request;
     $imgId = MangleXmlIdentifier($pagename) . $imgPrefix;
     $actionImgName = $imgId . 'RateItAction';
     $dbi =& $GLOBALS['request']->_dbi;
     $version = $dbi->_backend->get_latest_version($pagename);
     //$rdbi =& $this->_rdbi;
     $rdbi = RatingsDb::getTheRatingsDb();
     // check if the imgPrefix icons exist.
     if (!$WikiTheme->_findData("images/RateIt" . $imgPrefix . "Nk0.png", true)) {
         $imgPrefix = '';
     }
     // Protect against 's, though not \r or \n
     $reImgPrefix = $this->_javascript_quote_string($imgPrefix);
     $reActionImgName = $this->_javascript_quote_string($actionImgName);
     $rePagename = $this->_javascript_quote_string($pagename);
     //$dimension = $args['pagename'] . "rat";
     $html = HTML::span(array("id" => $imgId));
     for ($i = 0; $i < 2; $i++) {
         $nk[$i] = $WikiTheme->_findData("images/RateIt" . $imgPrefix . "Nk" . $i . ".png");
         $none[$i] = $WikiTheme->_findData("images/RateIt" . $imgPrefix . "Rk" . $i . ".png");
     }
     $user = $request->getUser();
     $userid = $user->getId();
     //if (!isset($args['rating']))
     $rating = $rdbi->getRating($userid, $pagename, $dimension);
     if (!$rating) {
         $pred = $rdbi->getPrediction($userid, $pagename, $dimension);
     }
     for ($i = 1; $i <= 10; $i++) {
         $a1 = HTML::a(array('href' => 'javascript:click(\'' . $reActionImgName . '\',\'' . $rePagename . '\',\'' . $version . '\',\'' . $reImgPrefix . '\',\'' . $dimension . '\',' . $i / 2 . ')'));
         $img_attr = array();
         $img_attr['src'] = $nk[$i % 2];
         //if (!$rating and !$pred)
         //  $img_attr['src'] = $none[$i%2];
         $img_attr['name'] = $imgPrefix . $i;
         $img_attr['alt'] = $img_attr['name'];
         $img_attr['border'] = 0;
         $a1->pushContent(HTML::img($img_attr));
         $a1->addToolTip(_("Rate the topic of this page"));
         $html->pushContent($a1);
         //This adds a space between the rating smilies:
         // if (($i%2) == 0) $html->pushContent(' ');
     }
     $html->pushContent(HTML::Raw('&nbsp;'));
     $a0 = HTML::a(array('href' => 'javascript:click(\'' . $reActionImgName . '\',\'' . $rePagename . '\',\'' . $version . '\',\'' . $reImgPrefix . '\',\'' . $dimension . '\',\'X\')'));
     $msg = _("Cancel rating");
     $a0->pushContent(HTML::img(array('src' => $WikiTheme->getImageUrl("RateIt" . $imgPrefix . "Cancel"), 'name' => $imgPrefix . 'Cancel', 'alt' => $msg)));
     $a0->addToolTip($msg);
     $html->pushContent($a0);
     /*} elseif ($pred) {
           $msg = _("No opinion");
           $html->pushContent(HTML::img(array('src' => $WikiTheme->getImageUrl("RateItCancelN"),
                                              'name'=> $imgPrefix.'Cancel',
                                              'alt' => $msg)));
           //$a0->addToolTip($msg);
           //$html->pushContent($a0);
       }*/
     $img_attr = array();
     $img_attr['src'] = $WikiTheme->_findData("images/RateItAction.png");
     $img_attr['name'] = $actionImgName;
     $img_attr['alt'] = $img_attr['name'];
     //$img_attr['class'] = 'k' . $i;
     $img_attr['border'] = 0;
     $html->pushContent(HTML::img($img_attr));
     // Display the current rating if there is one
     if ($rating) {
         $html->pushContent(JavaScript('displayRating(\'' . $reImgPrefix . '\',' . $rating . ',0)'));
     } elseif ($pred) {
         $html->pushContent(JavaScript('displayRating(\'' . $reImgPrefix . '\',' . $pred . ',1)'));
     } else {
         $html->pushContent(JavaScript('displayRating(\'' . $reImgPrefix . '\',0,0)'));
     }
     return $html;
 }
Esempio n. 22
0
 function summaryAsHTML($rev)
 {
     if (!($summary = $this->summary($rev))) {
         return '';
     }
     return HTML::span(array('class' => 'wiki-summary'), "[", $summary, "]");
 }
Esempio n. 23
0
 function markup($match)
 {
     return HTML::span($match);
 }
Esempio n. 24
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;
 }
Esempio n. 25
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if (empty($action)) {
         return $this->error(fmt("A required argument '%s' is missing.", "action"));
     }
     $form = HTML::form(array('action' => $request->getPostURL(), 'method' => strtolower($method), 'class' => 'wikiaction', 'accept-charset' => $GLOBALS['charset']), HiddenInputs(array('action' => $action, 'group_id' => GROUP_ID)));
     $nbsp = HTML::Raw('&nbsp;');
     $already_submit = 0;
     foreach ($this->inputbox as $inputbox) {
         foreach ($inputbox as $inputtype => $input) {
             if ($inputtype == 'radiobutton') {
                 $inputtype = 'radio';
             }
             // convert from older versions
             $input['type'] = $inputtype;
             $text = '';
             if ($inputtype != 'submit') {
                 if (empty($input['name'])) {
                     return $this->error(fmt("A required argument '%s' is missing.", $inputtype . "[][name]"));
                 }
                 if (!isset($input['text'])) {
                     $input['text'] = gettext($input['name']);
                 }
                 $text = $input['text'];
                 unset($input['text']);
             }
             switch ($inputtype) {
                 case 'checkbox':
                 case 'radio':
                     if (empty($input['value'])) {
                         $input['value'] = 1;
                     }
                     if (is_array($input['value'])) {
                         $div = HTML::div(array('class' => $class));
                         $values = $input['value'];
                         $name = $input['name'];
                         $input['name'] = $inputtype == 'checkbox' ? $name . "[]" : $name;
                         foreach ($values as $val) {
                             $input['value'] = $val;
                             if ($request->getArg($name)) {
                                 if ($request->getArg($name) == $val) {
                                     $input['checked'] = 'checked';
                                 } else {
                                     unset($input['checked']);
                                 }
                             }
                             $div->pushContent(HTML::input($input), $nbsp, $val, $nbsp, "\n");
                             if (!$nobr) {
                                 $div->pushContent(HTML::br());
                             }
                         }
                         $form->pushContent($div);
                     } else {
                         if (empty($input['checked'])) {
                             if ($request->getArg($input['name'])) {
                                 $input['checked'] = 'checked';
                             }
                         } else {
                             $input['checked'] = 'checked';
                         }
                         if ($nobr) {
                             $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
                         } else {
                             $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
                         }
                     }
                     break;
                 case 'editbox':
                     $input['type'] = 'text';
                     if (empty($input['value']) and $s = $request->getArg($input['name'])) {
                         $input['value'] = $s;
                     }
                     if ($nobr) {
                         $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
                     } else {
                         $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
                     }
                     break;
                 case 'combobox':
                     // TODO: moACDROPDOWN
                     $values = $input['value'];
                     unset($input['value']);
                     $input['type'] = 'text';
                     if (is_string($values)) {
                         $values = explode(",", $values);
                     }
                     if (empty($values)) {
                         if ($input['method']) {
                             $input['value'] = xmlrequest($input['method']);
                         } elseif ($s = $request->getArg($input['name'])) {
                             $input['value'] = $s;
                         }
                     } elseif (is_array($values)) {
                         $name = $input['name'];
                         unset($input['name']);
                         foreach ($values as $val) {
                             $input = array('value' => $val);
                             if ($request->getArg($name)) {
                                 if ($request->getArg($name) == $val) {
                                     $input['selected'] = 'selected';
                                 } else {
                                     unset($input['selected']);
                                 }
                             }
                             //$select->pushContent(HTML::option($input, $val));
                         }
                     }
                     if ($nobr) {
                         $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
                     } else {
                         $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
                     }
                     break;
                 case 'pulldown':
                     $values = $input['value'];
                     unset($input['value']);
                     unset($input['type']);
                     $select = HTML::select($input);
                     if (is_string($values)) {
                         $values = explode(",", $values);
                     }
                     if (empty($values) and $s = $request->getArg($input['name'])) {
                         $select->pushContent(HTML::option(array('value' => $s), $s));
                     } elseif (is_array($values)) {
                         $name = $input['name'];
                         unset($input['name']);
                         foreach ($values as $val) {
                             $input = array('value' => $val);
                             if ($request->getArg($name)) {
                                 if ($request->getArg($name) == $val) {
                                     $input['selected'] = 'selected';
                                 } else {
                                     unset($input['selected']);
                                 }
                             }
                             $select->pushContent(HTML::option($input, $val));
                         }
                     }
                     $form->pushContent($text, $nbsp, $select);
                     break;
                 case 'reset':
                 case 'hidden':
                     $form->pushContent(HTML::input($input));
                     break;
                     // change the order of inputs, by explicitly placing a submit button here.
                 // change the order of inputs, by explicitly placing a submit button here.
                 case 'submit':
                     //$input['type'] = 'submit';
                     if (empty($input['value'])) {
                         $input['value'] = $buttontext ? $buttontext : $action;
                     }
                     unset($input['text']);
                     if (empty($input['class'])) {
                         $input['class'] = $class;
                     }
                     if ($nobr) {
                         $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
                     } else {
                         $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
                     }
                     // unset the default submit button
                     $already_submit = 1;
                     break;
             }
         }
     }
     if ($request->getArg('start_debug')) {
         $form->pushContent(HTML::input(array('name' => 'start_debug', 'value' => $request->getArg('start_debug'), 'type' => 'hidden')));
     }
     if (!USE_PATH_INFO) {
         $form->pushContent(HiddenInputs(array('pagename' => $basepage)));
     }
     if (!$already_submit) {
         if (empty($buttontext)) {
             $buttontext = $action;
         }
         $submit = Button('submit:', $buttontext, $class);
         if ($cancel) {
             $form->pushContent(HTML::span(array('class' => $class), $submit, Button('submit:cancel', _("Cancel"), $class)));
         } else {
             $form->pushContent(HTML::span(array('class' => $class), $submit));
         }
     }
     return $form;
 }
Esempio n. 26
0
 function showForm(&$dbi, &$request, $args)
 {
     global $WikiTheme;
     $action = $request->getPostURL();
     $hiddenfield = HiddenInputs($request->getArgs(), '', array('action', 'page', 's', 'semsearch', 'relation', 'attribute'));
     $pagefilter = HTML::input(array('name' => 'page', 'value' => $args['page'], 'title' => _("Search only in these pages. With autocompletion."), 'class' => 'dropdown', 'acdropdown' => 'true', 'autocomplete_complete' => 'true', 'autocomplete_matchsubstring' => 'false', 'autocomplete_list' => 'xmlrpc:wiki.titleSearch ^[S] 4'), '');
     $allrelations = $dbi->listRelations(false, false, true);
     $svalues = empty($allrelations) ? "" : join("','", $allrelations);
     $reldef = JavaScript("var semsearch_relations = new Array('" . $svalues . "')");
     $relation = HTML::input(array('name' => 'relation', 'value' => $args['relation'], 'title' => _("Filter by this relation. With autocompletion."), 'class' => 'dropdown', 'style' => 'width:10em', 'acdropdown' => 'true', 'autocomplete_assoc' => 'false', 'autocomplete_complete' => 'true', 'autocomplete_matchsubstring' => 'true', 'autocomplete_list' => 'array:semsearch_relations'), '');
     $queryrel = HTML::input(array('name' => 's', 'value' => $args['s'], 'title' => _("Filter by this link. These are pagenames. With autocompletion."), 'class' => 'dropdown', 'acdropdown' => 'true', 'autocomplete_complete' => 'true', 'autocomplete_matchsubstring' => 'true', 'autocomplete_list' => 'xmlrpc:wiki.titleSearch ^[S] 4'), '');
     $relsubmit = Button('submit:semsearch[relations]', _("Relations"), false);
     // just testing some dhtml... not yet done
     $enhancements = HTML();
     $nbsp = HTML::raw('&nbsp;');
     $this_uri = $_SERVER['REQUEST_URI'] . '#';
     $andbutton = new Button(_("AND"), $this_uri, 'wikiaction', array('onclick' => "addquery('rel', 'and')", 'title' => _("Add an AND query")));
     $orbutton = new Button(_("OR"), $this_uri, 'wikiaction', array('onclick' => "addquery('rel', 'or')", 'title' => _("Add an OR query")));
     if (DEBUG) {
         $enhancements = HTML::span($andbutton, $nbsp, $orbutton);
     }
     $instructions = _("Search in pages for a relation with that value (a pagename).");
     $form1 = HTML::form(array('action' => $action, 'method' => 'post', 'accept-charset' => $GLOBALS['charset']), $reldef, $hiddenfield, HiddenInputs(array('attribute' => '')), $instructions, HTML::br(), HTML::table(array('border' => 0, 'cellspacing' => 2), HTML::colgroup(array('span' => 6)), HTML::thead(HTML::tr(HTML::th('Pagefilter'), HTML::th('Relation'), HTML::th(), HTML::th('Links'), HTML::th())), HTML::tbody(HTML::tr(HTML::td($pagefilter, ": "), HTML::td($relation), HTML::td(HTML::strong(HTML::tt('  ::  '))), HTML::td($queryrel), HTML::td($nbsp, $relsubmit, $nbsp, $enhancements)))));
     $allattrs = $dbi->listRelations(false, true, true);
     if (empty($allrelations) and empty($allattrs)) {
         // be nice to the dummy.
         $this->_norelations_warning = 1;
     }
     $svalues = empty($allattrs) ? "" : join("','", $allattrs);
     $attdef = JavaScript("var semsearch_attributes = new Array('" . $svalues . "')\n" . "var semsearch_op = new Array('" . join("','", $this->_supported_operators) . "')");
     // TODO: We want some more tricks: Autofill the base unit of the selected
     // attribute into the s area.
     $attribute = HTML::input(array('name' => 'attribute', 'value' => $args['attribute'], 'title' => _("Filter by this attribute name. With autocompletion."), 'class' => 'dropdown', 'style' => 'width:10em', 'acdropdown' => 'true', 'autocomplete_complete' => 'true', 'autocomplete_matchsubstring' => 'true', 'autocomplete_assoc' => 'false', 'autocomplete_list' => 'array:semsearch_attributes'), '');
     $attr_op = HTML::input(array('name' => 'attr_op', 'value' => $args['attr_op'], 'title' => _("Comparison operator. With autocompletion."), 'class' => 'dropdown', 'style' => 'width:2em', 'acdropdown' => 'true', 'autocomplete_complete' => 'true', 'autocomplete_matchsubstring' => 'true', 'autocomplete_assoc' => 'false', 'autocomplete_list' => 'array:semsearch_op'), '');
     $queryatt = HTML::input(array('name' => 's', 'value' => $args['s'], 'title' => _("Filter by this numeric attribute value. With autocompletion."), 'class' => 'dropdown', 'acdropdown' => 'false', 'autocomplete_complete' => 'true', 'autocomplete_matchsubstring' => 'false', 'autocomplete_assoc' => 'false', 'autocomplete_list' => 'plugin:SemanticSearch page=' . $args['page'] . ' attribute=^[S] attr_op==~'), '');
     $andbutton = new Button(_("AND"), $this_uri, 'wikiaction', array('onclick' => "addquery('attr', 'and')", 'title' => _("Add an AND query")));
     $orbutton = new Button(_("OR"), $this_uri, 'wikiaction', array('onclick' => "addquery('attr', 'or')", 'title' => _("Add an OR query")));
     if (DEBUG) {
         $enhancements = HTML::span($andbutton, $nbsp, $orbutton);
     }
     $attsubmit = Button('submit:semsearch[attributes]', _("Attributes"), false);
     $instructions = HTML::span(_("Search in pages for an attribute with that numeric value."), "\n");
     if (DEBUG) {
         $instructions->pushContent(HTML(" ", new Button(_("Advanced..."), _("SemanticSearchAdvanced"))));
     }
     $form2 = HTML::form(array('action' => $action, 'method' => 'post', 'accept-charset' => $GLOBALS['charset']), $attdef, $hiddenfield, HiddenInputs(array('relation' => '')), $instructions, HTML::br(), HTML::table(array('border' => 0, 'cellspacing' => 2), HTML::colgroup(array('span' => 6)), HTML::thead(HTML::tr(HTML::th('Pagefilter'), HTML::th('Attribute'), HTML::th('Op'), HTML::th('Value'), HTML::th())), HTML::tbody(HTML::tr(HTML::td($pagefilter, ": "), HTML::td($attribute), HTML::td($attr_op), HTML::td($queryatt), HTML::td($nbsp, $attsubmit, $nbsp, $enhancements)))));
     return HTML($form1, $form2);
 }
Esempio n. 27
0
function displayPage(&$request, $template = false)
{
    global $WikiTheme, $pv;
    $pagename = $request->getArg('pagename');
    $version = $request->getArg('version');
    $page = $request->getPage();
    if ($version) {
        $revision = $page->getRevision($version);
        if (!$revision) {
            NoSuchRevision($request, $page, $version);
        }
    } else {
        $revision = $page->getCurrentRevision();
    }
    if (isSubPage($pagename)) {
        $pages = explode(SUBPAGE_SEPARATOR, $pagename);
        $last_page = array_pop($pages);
        // deletes last element from array as side-effect
        $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle'), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR)));
        $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
        array_shift($pages);
        foreach ($pages as $p) {
            if ($pv != 2) {
                //Add the Backlink in page title
                $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR)));
            } else {
                // Remove Backlinks
                $pageheader->pushContent(HTML::h1($pagename));
            }
            $first_pages .= $p . SUBPAGE_SEPARATOR;
        }
        if ($pv != 2) {
            $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page));
            $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
        } else {
            $backlink = HTML::h1($pagename);
        }
        $pageheader->pushContent($backlink);
    } else {
        if ($pv != 2) {
            $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename));
            $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
        } else {
            $pageheader = HTML::h1($pagename);
            //Remove Backlinks
        }
        if ($request->getArg('frame')) {
            $pageheader->setAttr('target', '_top');
        }
    }
    // {{{ Codendi hook to insert stuff between navbar and header
    $eM =& EventManager::instance();
    $ref_html = '';
    $crossref_fact = new CrossReferenceFactory($pagename, ReferenceManager::REFERENCE_NATURE_WIKIPAGE, GROUP_ID);
    $crossref_fact->fetchDatas();
    if ($crossref_fact->getNbReferences() > 0) {
        $ref_html .= '<h3>' . $GLOBALS['Language']->getText('cross_ref_fact_include', 'references') . '</h3>';
        $ref_html .= $crossref_fact->getHTMLDisplayCrossRefs();
    }
    $additional_html = false;
    $eM->processEvent('wiki_before_content', array('html' => &$additional_html, 'group_id' => GROUP_ID, 'wiki_page' => $pagename));
    if ($additional_html) {
        $beforeHeader = HTML();
        $beforeHeader->pushContent($additional_html);
        $beforeHeader->pushContent(HTML::raw($ref_html));
        $toks['BEFORE_HEADER'] = $beforeHeader;
    } else {
        $beforeHeader = HTML();
        $beforeHeader->pushContent(HTML::raw($ref_html));
        $toks['BEFORE_HEADER'] = $beforeHeader;
    }
    // }}} /Codendi hook
    $pagetitle = SplitPagename($pagename);
    if ($redirect_from = $request->getArg('redirectfrom')) {
        $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from)));
        // abuse the $redirected template var for some status update notice
    } elseif ($request->getArg('errormsg')) {
        $redirect_message = $request->getArg('errormsg');
        $request->setArg('errormsg', false);
    }
    $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime')));
    /*
        // FIXME: This is also in the template...
        if ($request->getArg('action') != 'pdf' and !headers_sent()) {
          // FIXME: enable MathML/SVG/... support
          if (ENABLE_XHTML_XML
                 and (!isBrowserIE()
                      and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
                header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
            else
                header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
        }
    */
    $page_content = $revision->getTransformedContent();
    // if external searchengine (google) referrer, highlight the searchterm
    // FIXME: move that to the transformer?
    // OR: add the searchhightplugin line to the content?
    if ($result = isExternalReferrer($request)) {
        if (DEBUG and !empty($result['query'])) {
            //$GLOBALS['SearchHighlightQuery'] = $result['query'];
            /* simply add the SearchHighlight plugin to the top of the page. 
               This just parses the wikitext, and doesn't highlight the markup */
            include_once 'lib/WikiPlugin.php';
            $loader = new WikiPluginLoader();
            $xml = $loader->expandPI('<' . '?plugin SearchHighlight s="' . $result['query'] . '"?' . '>', $request, $markup);
            if ($xml and is_array($xml)) {
                foreach (array_reverse($xml) as $line) {
                    array_unshift($page_content->_content, $line);
                }
                array_unshift($page_content->_content, HTML::div(_("You searched for: "), HTML::strong($result['query'])));
            }
            if (0) {
                /* Parse the transformed (mixed HTML links + strings) lines?
                     This looks like overkill.
                   */
                require_once "lib/TextSearchQuery.php";
                $query = new TextSearchQuery($result['query']);
                $hilight_re = $query->getHighlightRegexp();
                //$matches = preg_grep("/$hilight_re/i", $revision->getContent());
                // FIXME!
                for ($i = 0; $i < count($page_content->_content); $i++) {
                    $found = false;
                    $line = $page_content->_content[$i];
                    if (is_string($line)) {
                        while (preg_match("/^(.*?)({$hilight_re})/i", $line, $m)) {
                            $found = true;
                            $line = substr($line, strlen($m[0]));
                            $html[] = $m[1];
                            // prematch
                            $html[] = HTML::strong(array('class' => 'search-term'), $m[2]);
                            // match
                        }
                    }
                    if ($found) {
                        $html[] = $line;
                        // postmatch
                        $page_content->_content[$i] = HTML::span(array('class' => 'search-context'), $html);
                    }
                }
            }
        }
    }
    $toks['CONTENT'] = new Template('browse', $request, $page_content);
    $toks['TITLE'] = $pagetitle;
    // <title> tag
    $toks['HEADER'] = $pageheader;
    // h1 with backlink
    $toks['revision'] = $revision;
    if (!empty($redirect_message)) {
        $toks['redirected'] = $redirect_message;
    }
    $toks['ROBOTS_META'] = 'index,follow';
    $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
    $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
    if (!$template) {
        $template = new Template('html', $request);
    }
    $template->printExpansion($toks);
    $page->increaseHitCount();
    if ($request->getArg('action') != 'pdf') {
        $request->checkValidators();
    }
    flush();
}
Esempio n. 28
0
 function expand($basepage, &$markup)
 {
     return HTML::span(array('class' => 'search-term', 'title' => _("Found by ") . $this->engine), $this->_word);
 }
Esempio n. 29
0
 function linkBadWikiWord($wikiword, $linktext = '')
 {
     global $ErrorManager;
     if ($linktext) {
         $text = $linktext;
     } elseif (isa($wikiword, 'WikiPageName')) {
         $text = $wikiword->shortName;
     } else {
         $text = $wikiword;
     }
     if (isa($wikiword, 'WikiPageName')) {
         $message = $wikiword->getWarnings();
     } else {
         $message = sprintf(_("'%s': Bad page name"), $wikiword);
     }
     $ErrorManager->warning($message);
     return HTML::span(array('class' => 'badwikiword'), $text);
 }
Esempio n. 30
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'post', 'class' => 'wikiadmin', 'accept-charset' => $GLOBALS['charset']), HiddenInputs(array('action' => $action, 'pagename' => $basepage)));
     $input = array('type' => 'text', 'value' => $default, 'size' => $size);
     switch ($action) {
         case 'loadfile':
             $input['name'] = 'source';
             if (!$default) {
                 $input['value'] = DEFAULT_DUMP_DIR;
             }
             if (!$buttontext) {
                 $buttontext = _("Load File");
             }
             $class = false;
             break;
         case 'login':
             $input['name'] = 'source';
             if (!$buttontext) {
                 $buttontext = _("Login");
             }
             $class = 'wikiadmin';
             break;
         case 'dumpserial':
             $input['name'] = 'directory';
             if (!$default) {
                 $input['value'] = DEFAULT_DUMP_DIR;
             }
             if (!$buttontext) {
                 $buttontext = _("Dump Pages");
             }
             $class = 'wikiadmin';
             break;
         case 'dumphtml':
             $input['name'] = 'directory';
             if (!$default) {
                 $input['value'] = HTML_DUMP_DIR;
             }
             if (!$buttontext) {
                 $buttontext = _("Dump Pages as XHTML");
             }
             $class = 'wikiadmin';
             break;
         case 'upload':
             $form->setAttr('enctype', 'multipart/form-data');
             $form->pushContent(HTML::input(array('name' => 'MAX_FILE_SIZE', 'value' => MAX_UPLOAD_SIZE, 'type' => 'hidden')));
             $input['name'] = 'file';
             $input['type'] = 'file';
             if (!$buttontext) {
                 $buttontext = _("Upload");
             }
             $class = false;
             // local OS function, so use native OS button
             break;
         default:
             return HTML::p(fmt("WikiForm: %s: unknown action", $action));
     }
     $input = HTML::input($input);
     $input->addTooltip($buttontext);
     $button = Button('submit:', $buttontext, $class);
     if ($request->getArg('start_debug')) {
         $form->pushContent(HTML::input(array('name' => 'start_debug', 'value' => $request->getArg('start_debug'), 'type' => 'hidden')));
     }
     $form->pushContent(HTML::span(array('class' => $class), $input, $button));
     return $form;
 }