예제 #1
0
function _get_banner()
{
    $url_part = _get_sections();
    $mypath = "/var/www-d6/docroot";
    for ($len = count($url_part); $len >= 1; $len--) {
        $url = array_slice($url_part, 0, $len);
        $file_name = '/banner/' . join('_', $url) . '.jpg';
        if (is_file($mypath . $file_name)) {
            return $file_name;
        }
    }
    return "/banner/default.jpg";
}
예제 #2
0
function _import_override_css_files()
{
    $url_part = _get_sections();
    $mypath = "/var/www-d6/docroot";
    $output = '';
    for ($len = 1; $len <= count($url_part); $len++) {
        $url = array_slice($url_part, 0, $len);
        $file_name = '/css/' . join('_', $url) . '.css';
        if (is_file($mypath . $file_name)) {
            $output .= '@import "' . $file_name . "\";";
        }
    }
    return $output;
}
예제 #3
0
function _get_override_css_files()
{
    $url_part = _get_sections();
    $mypath = "/var/www-d6/docroot";
    $files = array();
    for ($len = 1; $len <= count($url_part); $len++) {
        $url = array_slice($url_part, 0, $len);
        $file_name = '/css/' . join('_', $url) . '.css';
        if (is_file($mypath . $file_name)) {
            $output .= '<link rel="stylesheet" type="text/css" href="' . $file_name . "\" />\n";
            $files[] = $file_name;
        }
    }
    return $files;
}
예제 #4
0
function _get_override_css_files()
{
    $url_part = _get_sections();
    $mypath = "/var/www-d6/docroot";
    $files = array();
    // FIXME temporary hack for avc development
    if (_get_bucket() == 'avc') {
        return array('/css/avc-sunshine.css');
    }
    for ($len = 1; $len <= count($url_part); $len++) {
        $url = array_slice($url_part, 0, $len);
        $file_name = '/css/' . join('_', $url) . '.css';
        if (is_file($mypath . $file_name)) {
            $output .= '<link rel="stylesheet" type="text/css" href="' . $file_name . "\" />\n";
            $files[] = $file_name;
        }
    }
    return $files;
}
예제 #5
0
function do_markup($formatter, $options)
{
    $formatter->section_edit = 0;
    $formatter->sister_on = 0;
    $formatter->perma_icon = '';
    $formatter->get_javascripts();
    // trash default javascripts
    //$options['fixpath']=1;
    $formatter->send_header("", $options);
    $formatter->postfilters = array('fiximgpath');
    if (!empty($options['preview'])) {
        $formatter->wikimarkup = 2;
    } else {
        if (empty($options['all'])) {
            $formatter->wikimarkup = 1;
        }
    }
    if (!empty($options['value'])) {
        $val = _stripslashes($options['value']);
        $val = preg_replace('/(\\r\\n|\\n|\\r)/', "\n", $val);
        // Win32 fix
        $formatter->send_page($val, $options);
    } else {
        if (isset($options['section'])) {
            $formatter->section_edit = 1;
            $formatter->sect_num = $options['section'] - 1;
            $raw_body = $formatter->page->get_raw_body($options);
            $sections = _get_sections($raw_body);
            if ($sections[$options['section']]) {
                $raw_body = $sections[$options['section']];
                $formatter->send_page($raw_body, $options);
            }
        } else {
            $formatter->section_edit = 1;
            $formatter->send_page('', $options);
        }
        #else ignore
    }
    print $formatter->get_javascripts();
    return;
}
예제 #6
0
function _import_override_css_files()
{
    $url_part = _get_sections();
    $mypath = "/var/www-d6/docroot";
    $output = '';
    for ($len = 1; $len <= count($url_part); $len++) {
        $url = array_slice($url_part, 0, $len);
        $file_name = '/css/' . join('_', $url) . '.css';
        if (is_file($mypath . $file_name)) {
            $output .= '<style type="text/css">@import url("' . $file_name . "\");</style>\n";
        }
        /*
            $file_name = '/css/' . join('_', $url) . '-ie.css';
            if (is_file($mypath . $file_name)) {
              $output .= <<<EOF
        <!--[if lte IE 6]>
        <style type="text/css">@import url("$file_name");</style>
        <![endif]-->
        EOF;
            }
        */
    }
    return $output;
}
예제 #7
0
function do_post_savepage($formatter, $options)
{
    global $DBInfo;
    if ($_SERVER['REQUEST_METHOD'] != 'POST' || !$DBInfo->security->writable($options)) {
        $options['title'] = _("Page is not writable");
        $options['button_preview'] = 1;
        // force preview
    }
    if (isset($_FILES['upfile']) and is_array($_FILES) or isset($options['MYFILES']) and is_array($options['MYFILES'])) {
        $retstr = false;
        $options['retval'] =& $retstr;
        include_once 'plugin/UploadFile.php';
        do_uploadfile($formatter, $options);
    }
    $savetext = $options['savetext'];
    $datestamp = $options['datestamp'];
    $hash = $options['hash'];
    $button_preview = !empty($options['button_preview']) ? 1 : 0;
    if ($button_preview) {
        $formatter->preview = 1;
    }
    $button_merge = !empty($options['button_merge']) ? 1 : 0;
    $button_merge = !empty($options['manual_merge']) ? 2 : $button_merge;
    $button_merge = !empty($options['force_merge']) ? 3 : $button_merge;
    $button_diff = !empty($options['button_changes']) ? 1 : 0;
    if ($button_diff) {
        $button_preview = 1;
    }
    $savetext = preg_replace("/\r\n|\r/", "\n", $savetext);
    $savetext = _stripslashes($savetext);
    $comment = _stripslashes($options['comment']);
    $comment = trim($comment);
    $section_savetext = '';
    if (isset($options['section'])) {
        if ($formatter->page->exists()) {
            $sections = _get_sections($formatter->page->get_raw_body());
            if ($sections[$options['section']]) {
                if (substr($savetext, -1) != "\n") {
                    $savetext .= "\n";
                }
                $sections[$options['section']] = $savetext;
            }
            $section_savetext = $savetext;
            $savetext = implode('', $sections);
        }
    }
    if ($savetext and $savetext[strlen($savetext) - 1] != "\n") {
        $savetext .= "\n";
    }
    $new = md5($savetext);
    $menu = $formatter->link_to("#editor", _("Goto Editor"), ' class="preview-anchor"');
    $diff = '';
    if ($formatter->page->exists()) {
        # check difference
        $body = $formatter->page->get_raw_body();
        $body = preg_replace("/\r\n|\r/", "\n", $body);
        $orig = md5($body);
        if ($orig == $new) {
            // same text. just update datestamp
            unset($options['datestamp']);
            $datestamp = $formatter->page->mtime();
        }
        # check datestamp
        if ($formatter->page->mtime() > $datestamp) {
            $options['msg'] = sprintf(_("Someone else saved the page while you edited %s"), $formatter->link_tag($formatter->page->urlname, "", _html_escape($options['page'])));
            $options['preview'] = 1;
            $options['conflict'] = 1;
            if ($button_merge) {
                $options['msg'] = sprintf(_("%s is merged with latest contents."), $formatter->link_tag($formatter->page->urlname, "", _html_escape($options['page'])));
                $options['title'] = sprintf(_("%s is merged successfully"), _html_escape($options['page']));
                $merge = $formatter->get_merge($savetext);
                if (preg_grep('/^<<<<<<<$/', explode("\n", $merge))) {
                    $options['conflict'] = 2;
                    $options['title'] = sprintf(_("Merge conflicts are detected for %s !"), _html_escape($options['page']));
                    $options['msg'] = sprintf(_("Merge cancelled on %s."), $formatter->link_tag($formatter->page->urlname, "", _html_escape($options['page'])));
                    $merge = preg_replace('/^>>>>>>>$/m', "=== /!\\ >>>>>>> " . _("NEW") . ' ===', $merge);
                    $merge = preg_replace('/^<<<<<<<$/m', "=== /!\\ <<<<<<< " . _("OLD") . ' ===', $merge);
                    $merge = preg_replace('/^=======$/m', "=== ======= ===", $merge);
                    if ($button_merge > 1) {
                        unset($options['datestamp']);
                        unset($options['section']);
                        unset($section_savetext);
                        $datestamp = $formatter->page->mtime();
                        $options['conflict'] = 0;
                        if ($button_merge == 2) {
                            $options['title'] = sprintf(_("Get merge conflicts for %s"), _html_escape($options['page']));
                            $options['msg'] = sprintf(_("Please resolve conflicts manually."));
                            if ($merge) {
                                $savetext = $merge;
                            }
                        } else {
                            $options['title'] = sprintf(_("Force merging for %s !"), _html_escape($options['page']));
                            $options['msg'] = sprintf(_("Please be careful, you could damage useful information."));
                        }
                    }
                } else {
                    $options['conflict'] = 0;
                    if ($merge) {
                        // successfully merged. reset datestamp
                        $savetext = $merge;
                        unset($options['datestamp']);
                        $datestamp = $formatter->page->mtime();
                    }
                }
                $button_preview = 1;
            } else {
                $options['title'] = _("Conflict error!");
                $button_preview = 1;
            }
            if ($options['conflict'] and !empty($merge)) {
                $diff = $formatter->get_diff($merge);
            } else {
                $diff = $formatter->get_diff($savetext);
            }
            // get diff
        } else {
            if ($datestamp > time()) {
                $options['msg'] = sprintf(_("Go back or return to %s"), $formatter->link_tag($formatter->page->urlname, "", _html_escape($options['page'])));
                $formatter->send_header("", $options);
                $formatter->send_title(_("Invalid access"), "", $options);
                $formatter->send_footer();
                return;
            } else {
                if (!empty($DBInfo->use_savepage_hash)) {
                    // check hash
                    $ticket = getTicket($datestamp . $DBInfo->user->id, $_SERVER['REMOTE_ADDR']);
                    if ($hash != md5($ticket)) {
                        $formatter->send_header("", $options);
                        $formatter->send_title(_("Invalid access"), "", $options);
                        $formatter->send_footer();
                        return;
                    }
                }
            }
        }
    }
    if (empty($button_preview) && !empty($orig) && $orig == $new) {
        $options['msg'] = sprintf(_("Go back or return to %s"), $formatter->link_tag($formatter->page->urlname, "", _html_escape($options['page'])));
        $formatter->send_header("", $options);
        $formatter->send_title(_("No difference found"), "", $options);
        $formatter->send_footer();
        return;
    }
    if ($comment && (function_exists('mb_strlen') and mb_strlen($comment, $DBInfo->charset) > 256) or strlen($comment) > 256) {
        //$options['msg']=sprintf(_("Go back or return to %s"),$formatter->link_tag($formatter->page->urlname,"",_html_escape($options['page'])));
        $options['title'] = _("Too long Comment");
        $button_preview = 1;
    }
    // XXX captcha
    $use_any = 0;
    if (!empty($DBInfo->use_textbrowsers)) {
        if (is_string($DBInfo->use_textbrowsers)) {
            $use_any = preg_match('/' . $DBInfo->use_textbrowsers . '/', $_SERVER['HTTP_USER_AGENT']) ? 1 : 0;
        } else {
            $use_any = preg_match('/Lynx|w3m|links/', $_SERVER['HTTP_USER_AGENT']) ? 1 : 0;
        }
    }
    $ok_ticket = 0;
    if (!$button_preview and !$use_any and !empty($DBInfo->use_ticket) and $options['id'] == 'Anonymous') {
        if ($options['__seed'] and $options['check']) {
            $mycheck = getTicket($options['__seed'], $_SERVER['REMOTE_ADDR'], 4);
            if ($mycheck == $options['check']) {
                $ok_ticket = 1;
            } else {
                $options['msg'] = _("Invalid ticket !");
                $button_preview = 1;
            }
        } else {
            if (!$button_preview) {
                $options['msg'] = _("You need a ticket !");
            }
            $button_preview = 1;
        }
    } else {
        $ok_ticket = 1;
    }
    // XXX
    if (!$button_preview and $DBInfo->spam_filter) {
        $text = $savetext;
        $fts = preg_split('/(\\||,)/', $DBInfo->spam_filter);
        foreach ($fts as $ft) {
            $text = $formatter->filter_repl($ft, $text, $options);
        }
        if ($text != $savetext) {
            $button_preview = 1;
            $options['msg'] = _("Sorry, can not save page because some messages are blocked in this wiki.");
        } else {
            if ($options['id'] == 'Anonymous' and !empty($comment) and !empty($DBInfo->spam_comment_filter)) {
                // comment filter for anonymous users
                $cmt = $comment;
                $fts = preg_split('/(\\||,)/', $DBInfo->spam_comment_filter);
                // bad comments file
                $options['.badcontents'] = !empty($DBInfo->comments_badcontents) ? $DBInfo->comments_badcontents : null;
                foreach ($fts as $ft) {
                    $cmt = $formatter->filter_repl($ft, $cmt, $options);
                }
                if ($cmt != $comment) {
                    $button_preview = 1;
                    $options['msg'] = _("Sorry, can not save page because some messages are blocked in this wiki.");
                }
            }
        }
    }
    $formatter->page->set_raw_body($savetext);
    // check license agreement
    $ok_agreement = true;
    if (!empty($DBInfo->use_agreement)) {
        if ($options['id'] != 'Anonymous') {
            $ok_agreement = !empty($DBInfo->user->info['join_agreement']) && $DBInfo->user->info['join_agreement'] == 'agree';
            if ($ok_agreement && !empty($DBInfo->agreement_version)) {
                $ok_agreement = $DBInfo->user->info['join_agreement_version'] == $DBInfo->agreement_version;
            }
        } else {
            $ok_agreement = false;
        }
    }
    if (empty($button_preview) && !$ok_agreement && empty($options['license_agree'])) {
        $button_preview = 1;
        if ($options['id'] == 'Anonymous') {
            $options['msg'] = _("Anonymous user have to agree the contribution agreement for this wiki.");
        } else {
            $options['msg'] = _("Sorry, you have to agree the contribution agreement or the join agreement of this wiki.");
        }
    }
    // check full permission to edit
    $full_permission = true;
    if (!empty($DBInfo->no_full_edit_permission) or $options['id'] == 'Anonymous' && !empty($DBInfo->anonymous_no_full_edit_permission)) {
        $full_permission = false;
    }
    // members always have full permission to edit
    if (in_array($options['id'], $DBInfo->members)) {
        $full_permission = true;
    }
    $minorfix = false;
    $options['editinfo'] = array();
    if (!$full_permission || !empty($DBInfo->use_abusefilter)) {
        // get diff
        if (!isset($diff[0])) {
            $diff = $formatter->get_diff($savetext);
        }
        // get total line numbers
        // test \n or \r or \r\n
        $crlf = "\n";
        if (preg_match("/(\r|\r\n|\n)\$/", $body, $match)) {
            $crlf = $match[1];
        }
        // count crlf
        $nline = substr_count($body, $crlf);
        // count diff lines, chars
        $changes = diffcount_lines($diff, $DBInfo->charset);
        // set return values
        $added = $changes[0];
        $deleted = $changes[1];
        $added_chars = $changes[2];
        $deleted_chars = $changes[3];
        // check minorfix
        $minorfix = $changes[4];
        $editinfo = array('add_lines' => $added, 'del_lines' => $deleted, 'add_chars' => $added_chars, 'del_chars' => $deleted_chars);
        $options['editinfo'] = $editinfo;
        if (!$button_diff) {
            $diff = '';
        }
    }
    if (!$full_permission) {
        $restricted = false;
        $delete_lines_restricted_ratio = !empty($DBInfo->allowed_max_lines_delete_ratio) ? $DBInfo->allowed_max_lines_delete_ratio : 0.5;
        if ($deleted > 0 && $deleted / $nline > $delete_lines_restricted_ratio) {
            $restricted = true;
        }
        // check the maximum number of characters allowed to add/delete
        $max_chars_add = !empty($DBInfo->allowed_max_chars_add) ? $DBInfo->allowed_max_chars_add : 300;
        $max_chars_del = !empty($DBInfo->allowed_max_chars_delete) ? $DBInfo->allowed_max_chars_delete : 180;
        if (!$restricted && ($added_chars > $max_chars_add || $deleted_chars > $max_chars_del)) {
            $restricted = true;
        }
        if ($restricted) {
            $options['title'] = _("You do not have full permission to edit this page on this wiki.");
            if ($options['id'] == 'Anonymous') {
                $options['msg'] = _("Anonymous user is restricted to delete a lot amount of page on this wiki.");
            } else {
                $options['msg'] = _("You are restricted to delete a lot amount of page on this wiki.");
            }
            $button_preview = true;
        }
    }
    if ($button_preview) {
        if (empty($options['title'])) {
            $options['title'] = sprintf(_("Preview of %s"), _html_escape($options['page']));
        }
        // http://stackoverflow.com/questions/1547884
        $header = '';
        if (!empty($DBInfo->preview_no_xss_protection)) {
            $header = 'X-XSS-Protection: 0';
        }
        $formatter->send_header($header, $options);
        $formatter->send_title("", "", $options);
        $options['preview'] = 1;
        $options['datestamp'] = $datestamp;
        $savetext = $section_savetext ? $section_savetext : $savetext;
        $options['savetext'] = $savetext;
        $formatter->preview = 1;
        $has_form = false;
        $options['has_form'] =& $has_form;
        $options['.minorfix'] = $minorfix;
        print '<div id="editor_area_wrap">' . macro_EditText($formatter, '', $options);
        echo $formatter->get_javascripts();
        if ($has_form and !empty($DBInfo->use_jsbuttons)) {
            $msg = _("Save");
            $onclick = ' onclick="submit_all_forms()"';
            $onclick1 = ' onclick="check_uploadform(this)"';
            echo "<div id='save-buttons'>\n";
            echo "<button type='button'{$onclick} tabindex='10'><span>{$msg}</span></button>\n";
            echo "<button type='button'{$onclick1} tabindex='11' name='button_preview' value='1'><span>" . _("Preview") . '</span></button>';
            if ($formatter->page->exists()) {
                echo "\n<button type='button'{$onclick1} tabindex='12' name='button_changes' value='1'><span>" . _("Show changes") . '</span></button>';
            }
            if ($button_preview) {
                echo ' ' . $formatter->link_to('#preview', _("Skip to preview"), ' class="preview-anchor"');
            }
            echo "</div>\n";
        }
        print '</div>';
        # XXX
        print $DBInfo->hr;
        print $menu;
        if ($button_diff and !isset($diff[0])) {
            $diff = $formatter->get_diff($options['section'] ? implode('', $sections) : $savetext);
            // get diff
            // strip diff header
            if (($p = strpos($diff, '@@')) !== false) {
                $diff = substr($diff, $p);
            }
        }
        if (isset($diff[0])) {
            echo "<div id='wikiDiffPreview'>\n";
            echo $formatter->processor_repl('diff', $diff, $options);
            //echo $formatter->macro_repl('Diff','',array('text'=>$diff,'type'=>'fancy'));
            echo "</div>\n";
        }
        print "<div id='wikiPreview'>\n";
        #$formatter->preview=1;
        $formatter->send_page($savetext);
        $formatter->preview = 0;
        print $DBInfo->hr;
        print "</div>\n";
        print $menu;
    } else {
        // check minorfix
        $options['.minorfix'] = $minorfix;
        if (empty($DBInfo->use_autodetect_minoredit)) {
            unset($options['.minorfix']);
        }
        if (!empty($options['category'])) {
            $savetext .= "----\n[[" . $options['category'] . "]]\n";
        }
        $options['minor'] = !empty($DBInfo->use_minoredit) ? $options['minor'] : 0;
        if ($options['minor']) {
            $user = $DBInfo->user;
            # get from COOKIE VARS
            if ($DBInfo->owners and in_array($user->id, $DBInfo->owners)) {
                $options['minor'] = 1;
            } else {
                $options['minor'] = 0;
            }
        }
        $formatter->page->write($savetext);
        $retval = array();
        $options['retval'] =& $retval;
        $ret = $DBInfo->savePage($formatter->page, $comment, $options);
        if ($ret != -1 and $DBInfo->notify and $options['minor'] != 1) {
            $options['noaction'] = 1;
            if (!function_exists('mail')) {
                $options['msg'] = sprintf(_("mail does not supported by default.")) . "<br />";
            } else {
                $ret2 = wiki_notify($formatter, $options);
                if ($ret2) {
                    $options['msg'] = sprintf(_("Sent notification mail.")) . "<br />";
                } else {
                    $options['msg'] = sprintf(_("No subscribers found.")) . "<br />";
                }
            }
        }
        if ($ret == -1) {
            if (!empty($options['retval']['msg'])) {
                $msg = $options['retval']['msg'];
            } else {
                $msg = sprintf(_("%s is not editable"), $formatter->link_tag($formatter->page->urlname, "", _html_escape($options['page'])));
            }
            $options['title'] = $msg;
        } else {
            $options['title'] = sprintf(_("%s is saved"), $formatter->link_tag($formatter->page->urlname, "?action=show", _html_escape($options['page'])));
        }
        $myrefresh = '';
        if (!empty($DBInfo->use_save_refresh)) {
            $lnk = $formatter->link_url($formatter->page->urlname, "?action=show");
            if (!empty($options['section'])) {
                $lnk .= '#sect-' . $options['section'];
            }
            if ($DBInfo->use_save_refresh > 0 || $ret == -1) {
                $sec = $DBInfo->use_save_refresh - 1;
                if ($sec < 0) {
                    $sec = 3;
                }
                $myrefresh = 'Refresh: ' . $sec . '; url=' . qualifiedURL($lnk);
            } else {
                $myrefresh = array('Status: 302', 'Location: ' . qualifiedURL($lnk));
            }
        }
        $formatter->send_header($myrefresh, $options);
        if (is_array($myrefresh)) {
            return;
        }
        $formatter->send_title("", "", $options);
        $opt['pagelinks'] = 1;
        $opt['refresh'] = 1;
        $formatter->page->pi = null;
        // call get_instruction() again
        # re-generates pagelinks
        print "<div id='wikiContent'>\n";
        $formatter->send_page("", $opt);
        print "</div>\n";
    }
    $args['editable'] = 0;
    $formatter->send_footer($args, $options);
}
예제 #8
0
function do_pageview($formatter, $options)
{
    global $DBInfo;
    $sections = _get_sections($formatter->page->get_raw_body(), 2);
    if ($options['p']) {
        $sect = $options['p'];
    } else {
        $sect = 1;
    }
    $act = $options['action'];
    // get head title section
    list($secthead, $dumm) = explode("\n", $sections[0]);
    preg_match('/^\\s*=\\s*([^=].*[^=])\\s*=\\s?$/', $secthead, $match);
    $secthead = rtrim($sections[0]);
    if ($match[1]) {
        $title = $match[1];
    }
    $sz = sizeof($sections);
    // get prev,next subtitle
    if ($sz > $sect + 1) {
        list($n_title, $dumm) = explode("\n", $sections[$sect + 1]);
        preg_match('/^\\s*==\\s*(.*)\\s*==\\s?$/', $n_title, $match);
        if ($match[1]) {
            $n_title = $match[1];
        } else {
            $n_title = '';
        }
    } else {
        list($o_title, $dumm) = explode("\n", $sections[1]);
        preg_match('/^\\s*==\\s*(.*)\\s*==\\s?$/', $o_title, $match);
        if ($match[1]) {
            $o_title = $match[1];
        } else {
            $o_title = '';
        }
    }
    if ($sect - 1 >= 1) {
        list($p_title, $dumm) = explode("\n", $sections[$sect - 1]);
        preg_match('/^\\s*==\\s*(.*)\\s*==\\s?$/', $p_title, $match);
        if ($match[1]) {
            $p_title = $match[1];
        } else {
            $p_title = '';
        }
    }
    $formatter->send_header("", $options);
    $formatter->send_title($title, "", $options);
    $save = $formatter->preview;
    $formatter->preview = 1;
    // show the head title
    if ($secthead) {
        $formatter->send_page($secthead);
    }
    // section number ?
    //$formatter->head_num='1.'.$sect;
    //$formatter->head_num=$sect; // XXX
    //$formatter->head_dep=0;
    //$formatter->toc=1;
    // show selected section
    $formatter->send_page($sections[$sect]);
    $formatter->preview = $save;
    // make link tags
    if ($o_title != '') {
        $olink = $formatter->link_tag($formatter->page->urlname, '?action=' . $act . '&amp;p=1', $o_title);
        $first = _("First:") . ' ' . $olink;
    }
    if ($n_title != '') {
        $nlink = $formatter->link_tag($formatter->page->urlname, '?action=' . $act . '&amp;p=' . ($sect + 1), $n_title);
        $next = _("Next:") . ' ' . $nlink;
        $nlink = "<div class='pageNext'>" . $nlink . " &raquo;</div>\n";
    }
    if ($p_title != '') {
        $plink = $formatter->link_tag($formatter->page->urlname, '?action=' . $act . '&amp;p=' . ($sect - 1), $p_title);
        $plink = "<div class='pagePrev'>&laquo; " . $plink . "</div>\n";
    }
    print "{$first}{$next}\n<div class='pageNav'>" . $plink . $nlink . "</div>\n";
    // render extra_macros
    if ($DBInfo->extra_macros) {
        if (!is_array($DBInfo->extra_macros)) {
            print '<div id="wikiExtra">' . "\n";
            print $formatter->macro_repl($DBInfo->extra_macros);
            print '</div>' . "\n";
        } else {
            print '<div id="wikiExtra">' . "\n";
            foreach ($DBInfo->extra_macros as $macro) {
                print $formatter->macro_repl($macro);
            }
            print '</div>' . "\n";
        }
    }
    $formatter->send_footer("", $options);
    return;
}
예제 #9
0
파일: Diff.php 프로젝트: sedrion/moniwiki
function macro_diff($formatter, $value, &$options = array())
{
    global $DBInfo;
    $option = '';
    $pi = $formatter->page->get_instructions();
    $formatter->pi = $pi;
    $processor_type = $pi['#format'];
    while ($DBInfo->default_markup != 'wiki') {
        // XXX
        $processor = $pi['#format'];
        if (!($f = function_exists("processor_" . $processor)) and !($c = class_exists('processor_' . $processor))) {
            $pf = getProcessor($processor);
            if (!$pf) {
                break;
            }
            include_once "plugin/processor/{$pf}.php";
            $processor = $pf;
            $name = 'processor_' . $pf;
            if (class_exists($name)) {
                $classname = 'processor_' . $processor;
                $myclass = new $classname($formatter, $options);
                $processor_type = $myclass->_type == 'wikimarkup' ? 'wiki' : $pi['#format'];
            }
        } else {
            if ($c = class_exists('processor_' . $processor)) {
                $classname = 'processor_' . $processor;
                $myclass = new $classname($formatter, $options);
                $processor_type = $myclass->_type == 'wikimarkup' ? 'wiki' : $pi['#format'];
            }
        }
        break;
    }
    //if (!in_array($pi['#format'],array('wiki','moni')) and !$options['type']) # is it not wiki format ?
    if ($processor_type != 'wiki' and !$options['type']) {
        # is it not wiki format ?
        $options['type'] = $DBInfo->diff_type;
    }
    # use default diff format
    if (empty($options['type']) and !empty($DBInfo->use_smartdiff)) {
        $options['type'] = 'smart';
    }
    if (!empty($options['type']) and function_exists($options['type'] . '_diff')) {
        $type = $options['type'] . '_diff';
    } else {
        $type = $DBInfo->diff_type . '_diff';
    }
    if (!empty($options['text'])) {
        $out = $options['text'];
        if (empty($options['raw'])) {
            $ret = call_user_func($type, $out, $options);
        } else {
            $ret = "<pre>{$out}</pre>\n";
        }
        return $ret;
    }
    $rev1 = !empty($options['rev']) ? $options['rev'] : '';
    // old
    $rev2 = !empty($options['rev2']) ? $options['rev2'] : '';
    // new
    // check revision number
    if (!empty($rev1) && !preg_match("/^[0-9a-f.]+\$/", $rev1) || !empty($rev2) && !preg_match("/^[0-9a-f.]+\$/", $rev2)) {
        return _("Invalid revision numbers");
    }
    if (!$rev1 and !$rev2) {
        $rev1 = $formatter->page->get_rev();
    } else {
        if (0 === strcmp($rev1, (int) $rev1)) {
            $rev1 = $formatter->page->get_rev($rev1);
            // date
        } else {
            if ($rev1 == $rev2) {
                $rev2 = '';
            }
        }
    }
    #if ($rev1) $option="-r$rev1 ";
    #if ($rev2) $option.="-r$rev2 ";
    if (!$rev1 && !$rev2) {
        $msg = _("No older revisions available");
        if (isset($options['retval'])) {
            $options['retval']['msg'] = $msg;
        }
        if (!empty($options['nomsg'])) {
            return '';
        }
        return "<h2>{$msg}</h2>";
    }
    if (!$DBInfo->version_class) {
        $msg = _("Version info is not available in this wiki");
        if (isset($options['retval'])) {
            $options['retval']['msg'] = $msg;
        }
        if (!empty($options['nomsg'])) {
            return '';
        }
        return "<h2>{$msg}</h2>";
    }
    $version = $DBInfo->lazyLoad('version', $DBInfo);
    if (isset($options['value'][0])) {
        $rev = trim($options['rev']);
        if (!preg_match('/^[0-9a-f.]+$/i', $rev)) {
            $rev = '';
        }
        $savetext = $options['value'];
        if (!empty($options['section'])) {
            if (!empty($rev)) {
                // get revision number
                $r = $formatter->page->get_rev($rev);
                $opts = array();
                if (!empty($r)) {
                    $opts['rev'] = $r;
                }
                // get raw text by selected revision
                $rawbody = $formatter->page->get_raw_body($opts);
            } else {
                $rawbody = $formatter->page->get_raw_body();
            }
            $sections = _get_sections($rawbody);
            if (isset($sections[$options['section']])) {
                if (substr($savetext, -1) != "\n") {
                    $savetext .= "\n";
                }
                $sections[$options['section']] = $savetext;
            }
        }
        // make a diff formatted text from given text
        $out = $formatter->get_diff(!empty($options['section']) ? implode('', $sections) : $savetext);
        // get diff
    } else {
        $out = $version->diff($formatter->page->name, $rev1, $rev2, $options);
    }
    $ret = '';
    if (!$out) {
        $msg = _("No difference found");
    } else {
        #$rev1=substr($rev1,0,5);
        #$rev2=substr($rev2,0,5);
        if ($rev1 == $rev2) {
            $msg = _("Difference between versions");
        } else {
            if ($rev1 and $rev2) {
                $msg = sprintf(_("Difference between r%s and r%s"), $rev1, $rev2);
            } else {
                if ($rev1 or $rev2) {
                    $msg = sprintf(_("Difference between r%s and the current"), $rev1 . $rev2);
                }
            }
        }
        if (empty($options['raw'])) {
            $ret = call_user_func($type, $out, $options);
            if (is_array($ret)) {
                // for smart_diff
                $dels = $ret[1];
                $ret = $ret[0];
                $rev = ($rev1 and $rev2) ? $rev2 : '';
                // get newest rev.
                if (!empty($rev)) {
                    $current = $formatter->page->get_raw_body(array('rev' => $rev));
                } else {
                    $current = $formatter->page->_get_raw_body();
                }
                $lines = explode("\n", $current);
                $nret = $ret;
                foreach ($ret as $k => $v) {
                    if ($v == "") {
                        continue;
                    }
                    $tmp = explode("\n", $v);
                    $tt = array_pop($tmp);
                    if ($tt != '') {
                        $tmp[] = $tt;
                    }
                    for ($kk = 0; $kk < sizeof($tmp); $kk++) {
                        $nret[$k + $kk] = $tmp[$kk];
                    }
                }
                foreach ($nret as $k => $v) {
                    $lines[$k] = $v;
                }
                # insert deleted lines
                if ($dels) {
                    foreach ($dels as $k => $v) {
                        $lines[$k] = $v . "\n" . $lines[$k];
                    }
                }
                $diffed = implode("\n", $lines);
                # change for headings
                $diffed = preg_replace("/^(|)(={1,5})\\s(.*)\\s\\2\\1\$/m", "\\2 \\1\\3\\1 \\2", $diffed);
                # change for lists
                $diffed = preg_replace("/(|)(\\s+)(\\*|\\d+\\.\\s)(.*)\\1/m", "\\2\\3\\1\\4\\1", $diffed);
                # fix <ins>{{{foobar</ins> to {{{<ins>foobar</ins>
                $diffed = preg_replace("/(|)({{{)(.*)\$/m", "\\2\\1\\3", $diffed);
                # fix <ins>foobar}}}</ins> to <ins>foobar</ins>}}}
                $diffed = preg_replace("/(|)(.*)(}}})(\\1)/m", "\\1\\2\\4\\3", $diffed);
                # change for hrs
                $diffed = preg_replace("/(|)(-{4,})\\1/m", "\\1\\2\n\\1", $diffed);
                # XXX FIXME
                # merge multiline diffs
                #$diffed=preg_replace("/\006([ ]*)\006$/m","\\1",$diffed);
                #$diffed=preg_replace("/\010([ ]*)\010$/m","\\1",$diffed);
                $diffed = preg_replace("/\n(?!\n)/m", "\n", $diffed);
                $diffed = preg_replace("/\n(?!\n)/m", "\n", $diffed);
                $options['nomsg'] = 0;
                $options['msg'] = $msg;
                $options['smart'] = 1;
                if (isset($options['retval'])) {
                    $options['retval']['msg'] = $msg;
                }
                #if (!in_array($pi['#format'],array('wiki','moni')))
                if ($processor_type != 'wiki') {
                    return '<pre class="code">' . $diffed . '</pre>';
                }
                ob_start();
                $formatter->send_page($diffed, $options);
                $out = ob_get_contents();
                ob_end_clean();
                #print "<pre>".str_replace(array("\010","\006"),array("+++","---"),$diffed)."</pre>";
                #print "<pre>".$diffed."</pre>";
                return $out;
            }
        } else {
            return $out;
        }
    }
    if (!empty($msg) && isset($options['retval'])) {
        $options['retval']['msg'] = $msg;
    }
    return $ret;
}
예제 #10
0
function macro_SlideShow($formatter, $value = '', $options = array())
{
    global $DBInfo;
    $depth = 2;
    // default depth
    if (!empty($options['d'])) {
        $depth = intval($options['d']);
    }
    $args = explode(',', $value);
    $sz = sizeof($args);
    for ($i = 0, $sz = sizeof($args); $i < $sz; $i++) {
        if (($p = strpos($args[$i], '=')) !== false) {
            $k = substr($args[$i], 0, $p);
            $v = substr($args[$i], $p + 1);
            if ($k == 'depth' or $k == 'dep') {
                $depth = intval($v);
            }
        } else {
            $pgname = $args[$i];
        }
    }
    if ($pgname) {
        if (!$DBInfo->hasPage($pgname)) {
            return '[[SlideShow(' . _("No page found") . ')]]';
        }
        $pg = $DBInfo->getPage($pgname);
        $sections = _get_sections($pg->get_raw_body(), $depth);
        $urlname = _urlencode($pgname);
    } else {
        $sections = _get_sections($formatter->page->get_raw_body(), $depth);
        $urlname = $formatter->page->urlname;
    }
    if (!empty($options['p'])) {
        list($sect, $dum) = explode('/', $options['p']);
        $sect = abs(intval($sect));
        $sect = $sect ? $sect : 1;
    } else {
        $sect = 1;
    }
    $act = !empty($options['action']) ? $options['action'] : 'SlideShow';
    $iconset = 'bluecurve';
    $icon_dir = $formatter->imgs_dir . '/plugin/SlideShow/' . $iconset . '/';
    // get head title section
    if ($depth == 2) {
        list($secthead, $dumm) = explode("\n", $sections[0]);
        preg_match('/^\\s*=\\s*([^=].*[^=])\\s*=\\s?$/', $secthead, $match);
        $secthead = rtrim($sections[0]);
        if (isset($match[1])) {
            $title = $match[1];
        }
    } else {
        $dep = '&amp;d=' . $depth;
    }
    $sz = sizeof($sections);
    // $sections[0]
    $sz--;
    //if (trim($sections[$sz-1])=='') $sz--;
    //print $sections[0];
    //print_r($sections);
    if ($sect > $sz) {
        $sect = $sz;
    }
    // get prev,next subtitle
    if ($sz > $sect) {
        list($n_title, $dumm) = explode("\n", $sections[$sect + 1]);
        preg_match("/^\\s*={" . $depth . '}\\s*(.*)\\s*={' . $depth . '}\\s?$/', $n_title, $match);
        if (isset($match[1])) {
            $n_title = $match[1];
        } else {
            $n_title = '';
        }
        list($e_title, $dumm) = explode("\n", $sections[$sz]);
        preg_match("/^[ ]*={" . $depth . "}\\s+(.*)\\s+={" . $depth . "}\\s?/", $e_title, $match);
        if (isset($match[1])) {
            $e_title = $match[1];
        } else {
            $e_title = '';
        }
    }
    $s_title = '';
    if (!empty($sections[1]) and (empty($options['action']) or $sect > 1)) {
        list($s_title, $dumm) = explode("\n", $sections[1]);
        preg_match("/^\\s*={" . $depth . "}\\s*(.*)\\s*={" . $depth . "}\\s?\$/", $s_title, $match);
        if (isset($match[1])) {
            $s_title = $match[1];
        }
    }
    if ($sect >= 1) {
        list($p_title, $dumm) = explode("\n", $sections[$sect - 1]);
        preg_match('/^\\s*={' . $depth . '}\\s*(.*)\\s*={' . $depth . '}\\s?$/', $p_title, $match);
        if (isset($match[1])) {
            $p_title = $match[1];
        } else {
            $p_title = '';
        }
    }
    // make link icons
    if (!empty($s_title) or empty($options['action'])) {
        $slink = $formatter->link_url($urlname, '?action=' . $act . $dep . '&amp;p=1');
        $icon = !empty($options['action']) ? 'start' : 'next';
        $start = '<a href="' . $slink . '" title="' . _("Start:") . ' ' . $s_title . '">' . '<img src="' . $icon_dir . $icon . '.png' . '" style="border:0" alt="&lt;|" /></a>';
    } else {
        $start = '<img src="' . $icon_dir . 'start_off.png' . '" style="border:0" alt="&lt;|" /></a>';
    }
    if (!empty($e_title) and !empty($options['action'])) {
        $elink = $formatter->link_url($urlname, '?action=' . $act . $dep . '&amp;p=' . $sz);
        $end = '<a href="' . $elink . '" title="' . _("End:") . ' ' . $e_title . '">' . '<img src="' . $icon_dir . 'end.png' . '" style="border:0" alt="|>" /></a>';
    } else {
        $end = '<img src="' . $icon_dir . 'end_off.png' . '" style="border:0" alt="|>" /></a>';
    }
    $np = '';
    if (!empty($n_title) and !empty($options['action'])) {
        $np = $sect + 1;
        $nlink = $formatter->link_url($urlname, '?action=' . $act . $dep . '&amp;p=' . ($sect + 1));
        $next = '<a href="' . $nlink . '" title="' . _("Next:") . ' ' . $n_title . '">' . '<img src="' . $icon_dir . 'next.png' . '" style="border:0" alt=">" /></a>';
    } else {
        $next = '<img src="' . $icon_dir . 'next_off.png' . '" style="border:0" alt=">" /></a>';
    }
    $pp = '';
    if (!empty($p_title)) {
        $pp = $sect - 1;
        $plink = $formatter->link_url($urlname, '?action=' . $act . $dep . '&amp;p=' . ($sect - 1));
        $prev = '<a href="' . $plink . '" title="' . _("Prev:") . ' ' . $p_title . '">' . '<img src="' . $icon_dir . 'prev.png' . '" style="border:0" alt="<" /></a>';
    } else {
        $prev = '<img src="' . $icon_dir . 'prev_off.png' . '" style="border:0" alt="<" /></a>';
    }
    $rlink = $formatter->link_url($urlname, '?action=show');
    $return = '<a href="' . $rlink . '" title="' . _("Return") . ' ' . $pgname . '">' . '<img src="' . $icon_dir . 'up.png' . '" style="border:0" alt="^" /></a>';
    if (!empty($options['action'])) {
        $form0 = '<form method="post" onsubmit="return false" action="' . $rlink . '">';
        $form0 .= '<input type="hidden" name="d" value="' . $depth . '" />';
        $form0 .= '<input type="hidden" name="action" value="slideshow" />';
        $form = '<span class="slideShow" style="vertical-align:bottom;">' . '<input style="text-align:center" type="text" name="p" value="' . $sect . '/' . $sz . '" onkeypress="slideshowhandler(event,this,' . "'{$rlink}','{$pp}','{$np}')" . '" /></span>';
        $form1 = "</form>\n";
        return array($sections, "{$form0}{$return}{$start}{$prev}{$form}{$next}{$end}{$form1}\n");
    }
    return "{$return}{$start}";
}