예제 #1
0
파일: Tour.php 프로젝트: ahastudio/moniwiki
function macro_Tour($formatter, $value, $options = array())
{
    global $DBInfo;
    $args = explode(',', $value);
    $value = '';
    $arena = '';
    foreach ($args as $arg) {
        $arg = trim($arg);
        if (($p = strpos($arg, '=')) !== false) {
            $k = strtok($arg, '=');
            $v = strtok('');
            if ($k == 'arena') {
                $arena = $v;
            }
        } else {
            $value = $arg;
        }
    }
    $query = '';
    if (!empty($options['arena']) or $arena) {
        $options['arena'] = !empty($arena) ? $arena : $options['arena'];
        $query = '&arena=' . $options['arena'];
        $arena = $options['arena'];
    }
    $head = '';
    if (!$value) {
        $value = $formatter->page->name;
    }
    #else if ($value != $formatter->page->name) XXX;
    $query2 = '';
    if ($arena == 'backlinks') {
        $head2 = _("BackLinks");
        $link = $formatter->link_tag(_html_escape($value));
    } else {
        if ($arena == 'keylinks' or $arena == 'keywords') {
            $query2 = '?action=fullsearch&keywords=1';
            $head2 = _("Keywords");
            if ($DBInfo->hasPage($value)) {
                $link = $value;
            } else {
                $link = $formatter->link_to('?action=fullsearch&value=' . $value, _html_escape($value));
            }
        }
    }
    if ($head2) {
        $head = sprintf(_(" from %s"), $link);
    }
    if ($head) {
        $head = sprintf(_("%s Tour %s"), $head2, $head);
    }
    $head = '<h2>' . $head . '</h2>';
    if (!empty($options['w']) and $options['w'] < 10) {
        $count = $options['w'];
    } else {
        $count = TOUR_LEAFCOUNT;
    }
    if (!empty($options['d']) and $options['d'] < 7) {
        $depth = $options['d'];
    } else {
        $depth = TOUR_DEPTH;
    }
    $color = array();
    $tree = new LinkTree($options['arena']);
    $tree->makeTree($value, $node, $color, $depth, $count);
    if (!$node) {
        $node = array($value => array());
    }
    $allnode = array_keys($node);
    asort($allnode);
    $id = 0;
    $outs = array();
    while (list($leafname, $leaf) = @each($node)) {
        if (empty($leafs[$leafname])) {
            $urlname = _rawurlencode($leafname);
            $leafs[$leafname] = 1;
            $url[$leafname] = $urlname;
        }
        $selected = array_intersect($node[$leafname], $allnode);
        asort($selected);
        foreach ($selected as $leaf) {
            if (empty($leafs[$leaf])) {
                $urlname = _rawurlencode($leaf);
                $url[$leaf] = $urlname;
                $id = $leafs[$leaf] = $leafs[$leafname] + 1;
                if (!empty($outs[$id])) {
                    $outs[$id] = array();
                }
                $outs[$id][] = $leaf;
            }
        }
    }
    if (isset($out[0])) {
        unset($out[0]);
    }
    if ($DBInfo->hasPage($url[$value])) {
        $pg = $url[$value];
        $extra = '';
    } else {
        $pg = $formatter->page->name;
        $extra = '&amp;value=' . $url[$value];
    }
    $wide = $formatter->link_tag($pg, "?action=tour{$query}{$extra}&amp;w=" . ($count + 1) . "&amp;d={$depth}", _("links"));
    $deep = $formatter->link_tag($pg, "?action=tour{$query}{$extra}&amp;w={$count}&amp;d=" . ($depth + 1), _("deeper"));
    $link = '<h3>' . sprintf(_("More %s or more %s"), $wide, $deep) . '</h3>';
    $pages = '';
    foreach ($allnode as $node) {
        if ($DBInfo->hasPage($url[$node])) {
            $pg = $url[$node];
            $extra = '';
        } else {
            $pg = $formatter->page->name;
            $extra = '&amp;value=' . $url[$node];
        }
        $pages .= '<li>' . $formatter->link_tag($pg, $query2 . $extra, _html_escape($node)) . "</li>\n";
    }
    if ($arena == 'keywords' or $arena == 'keylinks') {
        $title = '<h3>' . sprintf(_("Total %d related keywords"), sizeof($allnode)) . '</h3>';
    } else {
        $title = '<h3>' . sprintf(_("Total %d related pages"), sizeof($allnode)) . '</h3>';
    }
    $out = array();
    $dep = 1;
    foreach ($outs as $ls) {
        asort($ls);
        $temp = '';
        foreach ($ls as $leaf) {
            if ($DBInfo->hasPage($url[$leaf])) {
                $pg = $url[$leaf];
                $extra = '';
            } else {
                $pg = $formatter->page->name;
                $extra = '&amp;value=' . $url[$leaf];
            }
            $temp .= ' <li>' . $formatter->link_tag($pg, "?action=tour{$query}{$extra}", $leaf) . "</li>\n";
        }
        $out[] = "<ul class='depth-{$dep}'>" . $temp . '</ul>';
        $dep++;
    }
    $ret = implode("\n", $out);
    $ret = $head . '<div class="tourLeft">' . $link . $ret . '</div>' . "<div class=\"tourRight\">{$title}<ol>{$pages}</ol></div>\n" . "<div class=\"tourFoot\"></div>\n";
    return '<div class="wikiTour">' . $ret . "</div>\n";
}
예제 #2
0
파일: dot.php 프로젝트: ahastudio/moniwiki
function macro_Dot($formatter, $value = '', $options = array())
{
    global $DBInfo;
    #getLeafs($options[page],&$node);
    if (!empty($options['w']) and $options['w'] < 5) {
        $count = $options['w'];
    } else {
        $count = LEAFCOUNT;
    }
    if (!empty($options['d']) and $options['d'] < 6) {
        $depth = $options['d'];
    } else {
        $depth = DEPTH;
    }
    if (!empty($options['f']) and $options['f'] < 12 and $options['f'] > 7) {
        $fontsize = $options['f'];
    } else {
        $fontsize = FONTSIZE;
    }
    if (!empty($value) and $DBInfo->hasPage($value)) {
        $pgname = $value;
    } else {
        if ($DBInfo->hasPage($options['page'])) {
            $pgname = $options['page'];
        } else {
            return '';
            // XXX
        }
    }
    $fontsize = !empty($DBInfo->dot_fontsize) ? $DBInfo->dot_fontsize : $fontsize;
    $fontname = !empty($DBInfo->dot_fontname) ? $DBInfo->dot_fontname : FONTNAME;
    $dot_options = !empty($DBInfo->dot_options) ? $DBInfo->dot_options : '';
    $arena = !empty($options['arena']) ? $options['arena'] : '';
    $color = array();
    $tree = new LinkTree($arena);
    $tree->makeTree($pgname, $node, $color, $depth, $count * 2);
    if (!$node) {
        $node = array($pgname => array());
    }
    #print_r($color);
    foreach ($color as $key => $val) {
        $color[$key] = $val > 0 ? $depth - $val : -$val;
    }
    $color[$pgname] = 10;
    $myaction = 'visualtour';
    if (!empty($options['t']) and in_array($options['t'], array('visualtour', 'show'))) {
        $myaction = $options['t'];
    }
    #print_r($color);
    #print_r(array_keys($node));
    $visualtour = $formatter->link_url("VisualTour");
    $pageurl = qualifiedUrl($formatter->link_url("\\N", "?action={$myaction}"));
    $colref = array('gray71', 'olivedrab1', 'olivedrab2', 'olivedrab3', '"#A4DDF4"', '"#83D0ED"', '"#63C0E3"', 'gray53', 'gray40', 'orangered', 'yellow');
    $fcolref = array('gray71', 'olivedrab4', 'olivedrab4', 'olivedrab4', '"#A4DDF4"', '"#83D0ED"', '"#63C0E3"', 'gray53', 'gray40', 'white', 'black');
    $colidx = 0;
    $dot_head = <<<HEAD
digraph G {
  {$dot_options}
  ratio="compress"
  URL="{$visualtour}"
  node [URL="{$pageurl}", 
fontcolor=black, fontname={$fontname}, fontsize={$fontsize}]

HEAD;
    $allnode = array_keys($node);
    $out = '';
    while (list($leafname, $leaf) = @each($node)) {
        if (!empty($leafname) and empty($leafs[$urlname = _rawurlencode($leafname)])) {
            $leafs[$leafname] = $urlname;
            $extra = '';
            if ($fcolref[$color[$leafname]]) {
                $extra = ',fontcolor=' . $fcolref[$color[$leafname]];
            }
            $out .= '"' . $urlname . "\" [label=\"{$leafname}\"," . "style=filled,fillcolor=" . $colref[$color[$leafname]] . "{$extra}];\n";
        }
        #print $leafname."\n";
        #print_r($node[$leafname]);
        $selected = array_intersect($node[$leafname], $allnode);
        foreach ($selected as $leaf) {
            if (!empty($leaf) and empty($leafs[$urlname = _rawurlencode($leaf)])) {
                $leafs[$leaf] = $urlname;
                $extra = '';
                if ($fcolref[$color[$leaf]]) {
                    $extra = ',fontcolor=' . $fcolref[$color[$leaf]];
                }
                $out .= '"' . $urlname . "\" [label=\"{$leaf}\"," . "style=filled,fillcolor=" . $colref[$color[$leaf]] . "{$extra}];\n";
            }
            $out .= "\"" . $leafs[$leafname] . "\" ->\"" . $leafs[$leaf] . "\";\n";
        }
    }
    $out .= "};\n";
    $out = $dot_head . $out;
    if (strtoupper($DBInfo->charset) != 'UTF-8') {
        $new = iconv($DBInfo->charset, 'UTF-8', $out);
        if ($new) {
            return $new;
        }
    }
    return $out;
}