예제 #1
0
function filter_antispam($formatter, $value, $options)
{
    global $Config;
    $blacklist_pages = array('BadContent', 'LocalBadContent');
    $whitelist_pages = array('GoodContent', 'LocalGoodContent');
    if (!in_array($formatter->page->name, $blacklist_pages) and !in_array($formatter->page->name, $whitelist_pages)) {
        $badcontents_file = !empty($options['.badcontents']) ? $options['.badcontents'] : $Config['badcontents'];
        if (!file_exists($badcontents_file)) {
            return $value;
        }
        $badcontent = file_get_contents($badcontents_file);
        foreach ($blacklist_pages as $list) {
            $p = new WikiPage($list);
            if ($p->exists()) {
                $badcontent .= $p->get_raw_body();
            }
        }
        if (!$badcontent) {
            return $value;
        }
        $badcontents = explode("\n", $badcontent);
        $pattern[0] = '';
        $i = 0;
        foreach ($badcontents as $line) {
            if (isset($line[0]) and $line[0] == '#') {
                continue;
            }
            $line = preg_replace('/[ ]*#.*$/', '', $line);
            $test = @preg_match("/{$line}/i", "");
            if ($test === false) {
                $line = preg_quote($line, '/');
            }
            if ($line) {
                $pattern[$i] .= $line . '|';
            }
            if (strlen($pattern[$i]) > 4000) {
                $i++;
                $pattern[$i] = '';
            }
        }
        for ($k = 0; $k <= $i; $k++) {
            $pattern[$k] = '/(' . substr($pattern[$k], 0, -1) . ')/i';
        }
        #foreach ($whitelist_pages as $list) {
        #    $p=new WikiPage($list);
        #    if ($p->exists()) $goodcontent.=$p->get_raw_body();
        #}
        #$goodcontents=explode("\n",$goodcontent);
        return preg_replace($pattern, "''''''[[HTML(<span class='blocked'>)]]\\1[[HTML(</span>)]]''''''", $value);
    }
    return $value;
}
예제 #2
0
function macro_Edit($formatter, $value, $options = '')
{
    global $DBInfo;
    $options['mode'] = !empty($options['mode']) ? $options['mode'] : '';
    $edit_rows = $DBInfo->edit_rows ? $DBInfo->edit_rows : 16;
    $cols = get_textarea_cols();
    $use_js = preg_match('/Lynx|w3m|links/', $_SERVER['HTTP_USER_AGENT']) ? 0 : 1;
    $rows = (!empty($options['rows']) and $options['rows'] > 5) ? $options['rows'] : $edit_rows;
    $rows = $rows < 60 ? $rows : $edit_rows;
    $cols = (!empty($options['cols']) and $options['cols'] > 60) ? $options['cols'] : $cols;
    $text = !empty($options['savetext']) ? $options['savetext'] : '';
    $editlog = !empty($options['editlog']) ? $options['editlog'] : "";
    if (empty($editlog) and !empty($options['comment'])) {
        $editlog = _stripslashes($options['comment']);
    }
    $editlog = _html_escape($editlog);
    $args = explode(',', $value);
    if (in_array('nohints', $args)) {
        $options['nohints'] = 1;
    }
    if (in_array('nomenu', $args)) {
        $options['nomenu'] = 1;
    }
    $preview = !empty($options['preview']) ? $options['preview'] : 0;
    if ($options['action'] == 'edit') {
        $saveaction = 'savepage';
    } else {
        $saveaction = $options['action'];
    }
    $extraform = !empty($formatter->_extra_form) ? $formatter->_extra_form : '';
    $options['notmpl'] = isset($options['notmpl']) ? $options['notmpl'] : 0;
    $form = '';
    if (!$options['notmpl'] and (!empty($options['template']) or !$formatter->page->exists()) and !$preview) {
        $options['linkto'] = "?action=edit&amp;template=";
        $options['limit'] = -1;
        $tmpls = macro_TitleSearch($formatter, $DBInfo->template_regex, $options);
        if ($tmpls) {
            $tmpls = '<div>' . _("Use one of the following templates as an initial release :\n") . $tmpls;
            $tmpls .= sprintf(_("To create your own templates, add a page with '%s' pattern."), $DBInfo->template_regex) . "\n</div>\n";
        }
        if (isset($options['tmpls'])) {
            $options['tmpls'] = $tmpls;
            $tmpls = '';
        }
    }
    $merge_btn = _("Merge");
    $merge_btn2 = _("Merge manually");
    $merge_btn3 = _("Ignore conflicts");
    $extra = '';
    if (!empty($options['conflict'])) {
        $extra = '<span class="button"><input type="submit" class="button" name="button_merge" value="' . $merge_btn . '" /></span>';
        if ($options['conflict'] == 2) {
            $extra .= ' <span class="button"><input type="submit" class="button" name="manual_merge" value="' . $merge_btn2 . '" /></span>';
            if ($DBInfo->use_forcemerge) {
                $extra .= ' <span class="button"><input type="submit" class="button" name="force_merge" value="' . $merge_btn3 . '" /></span>';
            }
        }
    }
    $hidden = '';
    if (!empty($options['section'])) {
        $hidden = '<input type="hidden" name="section" value="' . $options['section'] . '" />';
    }
    if (!empty($options['mode'])) {
        $hidden = '<input type="hidden" name="mode" value="' . $options['mode'] . '" />';
    }
    # make a edit form
    if (empty($options['simple'])) {
        $form .= "<a id='editor'></a>\n";
    }
    if (isset($DBInfo->use_preview_anchor)) {
        $preview_anchor = '#preview';
    } else {
        $preview_anchor = '';
    }
    if (isset($options['page'][0])) {
        $previewurl = $formatter->link_url(_rawurlencode($options['page']), $preview_anchor);
    } else {
        $previewurl = $formatter->link_url($formatter->page->urlname, $preview_anchor);
    }
    $menu = '';
    $sep = '';
    if (empty($DBInfo->use_resizer) and (empty($options['noresizer']) or !$use_js)) {
        $sep = ' | ';
        $menu = $formatter->link_to("?action=edit&amp;rows=" . ($rows - 3), _("ReduceEditor"));
        $menu .= $sep . $formatter->link_to("?action=edit&amp;rows=" . ($rows + 3), _("EnlargeEditor"));
    }
    if (empty($options['nomenu'])) {
        $menu .= $sep . $formatter->link_tag('InterWiki', "", _("InterWiki"));
        $sep = ' | ';
        $menu .= $sep . $formatter->link_tag('HelpOnEditing', "", _("HelpOnEditing"));
    }
    $form .= $menu;
    $ajax = '';
    $js = '';
    if (!empty($options['action_mode']) and $options['action_mode'] == 'ajax') {
        $ajax = " onsubmit='savePage(this);return false'";
    }
    $formh = sprintf('<form id="editform" method="post" action="%s"' . $ajax . '>', $previewurl);
    if ($text) {
        $raw_body = preg_replace("/\r\n|\r/", "\n", $text);
    } else {
        if (!empty($options['template'])) {
            $p = new WikiPage($options['template']);
            $raw_body = preg_replace("/\r\n|\r/", "\n", $p->get_raw_body());
        } else {
            if (isset($formatter->_raw_body)) {
                # low level XXX
                $raw_body = preg_replace("/\r\n|\r/", "\n", $formatter->_raw_body);
            } else {
                if ($options['mode'] != 'edit' and $formatter->page->exists()) {
                    $raw_body = preg_replace("/\r\n|\r/", "\n", $formatter->page->_get_raw_body());
                    if (isset($options['section'])) {
                        $sections = _get_sections($raw_body);
                        if ($sections[$options['section']]) {
                            $raw_body = $sections[$options['section']];
                        }
                        #else ignore
                    }
                } else {
                    $raw_body = '';
                    if (!empty($options['orig_pagename'])) {
                        $raw_body = "#title {$options['orig_pagename']}\n";
                    }
                    if (strpos($options['page'], ' ') > 0) {
                        #$raw_body="#title $options[page]\n";
                        $options['page'] = '["' . $options['page'] . '"]';
                    }
                    $guide = sprintf(_("Describe %s here"), $options['page']);
                    if (empty($DBInfo->use_edit_placeholder)) {
                        $raw_body .= $guide;
                        $guide = '';
                    } else {
                        $guide = ' placeholder="' . _html_escape($guide) . '"';
                    }
                    $js = <<<EOF
<script type="text/javascript">
/*<![CDATA[*/
(function() {
    function selectGuide() {
        var txtarea = document.getElementById('editor-textarea');
        if (!txtarea) return;

        txtarea.focus();
        var txt = txtarea.value;
        var pos = 0;
        if (txt.indexOf('#title ') == 0) {
            pos = txt.indexOf("\\n") + 1;
        }
        var end = txt.length;

        if (txtarea.selectionStart || txtarea.selectionStart == '0') {
            // goto
            txtarea.selectionStart = pos;
            txtarea.selectionEnd = end;
        } else if (document.selection && !is_gecko && !is_opera) {
            // IE
            var r = document.selection.createRange();
            var range = r.duplicate();

            range.moveStart('character', pos);
            range.moveEnd('character', end - pos);
            r.setEndPoint('StartToStart', range);
            range.select();
        }
    }

    var oldOnLoad = window.onLoad;
    window.onload = function() {
        try { oldOnLoad() } catch(e) {};
        selectGuide();
    }
})();
/*]]>*/
</script>

EOF;
                }
            }
        }
    }
    $summary_guide = '';
    if (!empty($options['.minorfix'])) {
        $summary_guide = _("This ia a minor edit.");
    }
    if (empty($DBInfo->use_edit_placeholder)) {
        $summary_guide = '';
    } else {
        $summary_guide = ' placeholder="' . _html_escape($summary_guide) . '"';
    }
    # for conflict check
    if (!empty($options['datestamp'])) {
        $datestamp = $options['datestamp'];
    } else {
        if (!empty($formatter->_mtime)) {
            # low level control XXX
            $datestamp = $formatter->_mtime;
        } else {
            $datestamp = $formatter->page->mtime();
        }
    }
    if (!empty($DBInfo->use_savepage_hash)) {
        // generate hash
        $ticket = getTicket($datestamp . $DBInfo->user->id, $_SERVER['REMOTE_ADDR']);
        $hash = md5($ticket);
        $hidden .= "\n<input type=\"hidden\" name=\"hash\" value=\"" . $hash . "\" />\n";
    }
    $raw_body = str_replace(array("&", "<"), array("&amp;", "&lt;"), $raw_body);
    # get categories
    $select_category = '';
    if (!empty($DBInfo->use_category) and empty($options['nocategories'])) {
        $categories = $DBInfo->getLikePages($DBInfo->category_regex, -1);
        if ($categories) {
            $select_category = "<label for='category-select'>" . _("Category") . "</label><select id='category-select' name='category' tabindex='4'>\n";
            $mlen = 0;
            $opts = '';
            foreach ($categories as $category) {
                $len = mb_strwidth($category);
                $category = _html_escape($category);
                if ($len > $mlen) {
                    $mlen = $len;
                }
                $opts .= "<option value=\"{$category}\">{$category}</option>\n";
            }
            $lab = _(" Select ");
            $len = intval(($mlen - mb_strwidth($lab)) / 2);
            $pad = str_repeat('-', $len);
            $select_category .= "<option value=''>" . $pad . $lab . $pad . "</option>\n" . $opts;
            $select_category .= "</select>\n";
        }
    }
    $extra_check = '';
    if (empty($options['minor']) and !empty($DBInfo->use_minoredit)) {
        $user =& $DBInfo->user;
        # get from COOKIE VARS
        if (!empty($DBInfo->owners) and in_array($user->id, $DBInfo->owners)) {
            $extra_check = ' ' . _("Minor edit") . "<input type='checkbox' tabindex='3' name='minor' />";
        }
    }
    $captcha = '';
    if ($use_js and !empty($DBInfo->use_ticket) and $options['id'] == 'Anonymous') {
        $msg = _("Refresh");
        $seed = md5(base64_encode(time()));
        $ticketimg = $formatter->link_url($formatter->page->urlname, '?action=ticket&amp;__seed=' . $seed . '&amp;t=');
        $onclick = " onclick=\"document.getElementById('captcha_img').src ='" . $ticketimg . "'+ Math.random()\"";
        $captcha = <<<EXTRA
  <div class='captcha' style='float:right'><div><span class='captchaImg'><img id="captcha_img" src="{$ticketimg}" alt="captcha" /></span></div>
  <button type='button' class='refresh-icon'{$onclick}><span>{$msg}</span></button><input type="text" tabindex="2" size="10" name="check" />
<input type="hidden" name="__seed" value="{$seed}" /></div>
EXTRA;
    }
    $summary_msg = _("Summary");
    $wysiwyg_btn = '';
    $skip_preview = '';
    if (empty($options['simple'])) {
        $preview_btn = '<span class="button"><input type="submit" class="button" tabindex="6" name="button_preview" class="preview-button" value="' . _("Preview") . '" /></span>';
        $changes_btn = '';
        if ($formatter->page->exists()) {
            $changes_btn = ' <span class="button"><input type="submit" class="button" tabindex="6" name="button_changes" class="preview-button" value="' . _("Show changes") . '" /></span>';
        }
        if ($preview and empty($options['conflict'])) {
            $skip_preview = ' ' . $formatter->link_to('#preview', _("Skip to preview"), ' class="preview-anchor"');
        }
        if (!empty($DBInfo->use_wikiwyg)) {
            $confirm = 'false';
            if (!empty($DBInfo->wikiwyg_confirm)) {
                $confirm = 'null';
            }
            $wysiwyg_msg = _("GUI");
            $wysiwyg_btn .= '&nbsp;<button type="button" tabindex="7"' . ' onclick="javascript:sectionEdit(null,' . $confirm . ',null)" ><span>' . $wysiwyg_msg . '</span></button>';
        }
        $summary = <<<EOS
<span id='edit-summary'><label for='input-summary'>{$summary_msg}</label><input name="comment" id='input-summary' value="{$editlog}" size="60" maxlength="128" tabindex="2" {$summary_guide} />{$extra_check}</span>
EOS;
        $emailform = '';
        if (!empty($DBInfo->anonymous_friendly) and $options['id'] == 'Anonymous') {
            $useremail = isset($DBInfo->user->verified_email) ? $DBInfo->user->verified_email : '';
            if ($useremail) {
                $email_msg = _("E-Mail");
                $send_msg = sprintf(_("Send mail to %s"), "<span class='email'>" . $useremail . "</span>");
                #<label for='input-email'>$email_msg</label>
                #<span id='edit-email'><label for='input-email'>$email_msg</label><input name="email" id='input-email' value="$useremail" size="40" maxlength="60" tabindex="3" /></span>
                $emailform = <<<EOS
        {$send_msg} <input type='checkbox' tabindex='3' checked='checked' name='cc' />
EOS;
            }
        }
        // show contributor license agreement form
        $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 (!$ok_agreement) {
            if ($options['id'] != 'Anonymous') {
                if (!empty($DBInfo->contributor_license_agreement)) {
                    $agree_msg = $DBInfo->contributor_license_agreement;
                } else {
                    $agree_msg = _("Agree to the contributor license agreement on this wiki");
                }
            } else {
                if (!empty($DBInfo->irrevocable_contribution_agreement)) {
                    $agree_msg = $DBInfo->irrevocable_contribution_agreement;
                } else {
                    $agree_msg = _("Agree to the contribution agreement for Anonymous doner");
                }
            }
            $emailform .= <<<EOS
      {$agree_msg} <input type='checkbox' tabindex='3' checked='checked' name='license_agree' />
EOS;
        }
        if (isset($emailform[0])) {
            $emailform = '<div id="contribution_agreement">' . $emailform . '</div>';
        }
    }
    $save_msg = _("Save");
    if ($use_js and !empty($DBInfo->use_resizer)) {
        if ($DBInfo->use_resizer == 1) {
            $resizer = <<<EOS
<script type="text/javascript" language='javascript'>
/*<![CDATA[*/
function resize(obj,val) {
  rows= obj.savetext.rows;
  rows+=val;
  if (rows > 60) rows=16;
  else if (rows < 5) rows=16;
  obj.savetext.rows=rows;
}

var resizer=document.createElement('div');
resizer.setAttribute('id','wikiResize');
resizer.innerHTML="<input type='button' class='inc' value='+' onclick='resize(this.form,3)' />\\n<input type='button' class='dec' value='-' onclick='resize(this.form,-3)' />";

var toolbar=document.getElementById('toolbar');
if (toolbar) {
  toolbar.insertBefore(resizer, toolbar.firstChild);
} else {
  var editor=document.getElementById('wikiEditor');
  editor.insertBefore(resizer, editor.firstChild);
}
/*]]>*/
</script>
EOS;
        } else {
            $formatter->register_javascripts('textarea.js');
        }
    }
    $form .= <<<EOS
<div id="editor_area">
{$formh}
<div class="resizable-textarea" style='position:relative'><!-- IE hack -->
<div id="save_state"></div>
<textarea id="editor-textarea" wrap="virtual" name="savetext" tabindex="1"
 rows="{$rows}" cols="{$cols}" class="wiki resizable"{$guide}>{$raw_body}</textarea>
{$captcha}
</div>
{$extraform}
<div id="editor_info">
<ul>
<li>{$summary} {$emailform}</li>
<li>{$select_category}
<span>
<input type="hidden" name="action" value="{$saveaction}" />
<input type="hidden" name="datestamp" value="{$datestamp}" />
{$hidden}
<span class="button"><input type="submit" class='save-button' tabindex="5" accesskey="x" value="{$save_msg}" /></span>
<!-- <input type="reset" value="Reset" />&nbsp; -->
{$preview_btn}{$changes_btn}{$wysiwyg_btn}{$skip_preview}
{$extra}
</span>
</li></ul>
</div>
</form>
</div>
EOS;
    if (empty($options['nohints'])) {
        $form .= $formatter->macro_repl('EditHints');
    }
    if (empty($options['simple'])) {
        $form .= "<a id='preview'></a>";
    }
    return $form . $resizer . $js . $tmpls;
}
예제 #3
0
파일: bts.php 프로젝트: ahastudio/moniwiki
function processor_bts($formatter, $value = '', $options = '')
{
    global $DBInfo;
    $rating_script =& $GLOBALS['rating_script'];
    $script = <<<SCRIPT
<script type="text/javascript">
/*<![CDATA[*/
/* from bugzilla script with small fix */
  /* Outputs a link to call replyToComment(); used to reduce HTML output */
  function addReplyLink(id) {
    /* XXX this should really be updated to use the DOM Core's
     * createElement, but finding a container isn't trivial */
    document.write('[<a href="#add_comment" onclick="replyToComment(' + 
        id + ');">reply<' + '/a>]');
  }

  /* Adds the reply text to the `comment' textarea */
  function replyToComment(id) {
    /* pre id="comment_name_N" */
    var text_elem = document.getElementById('comment_text_'+id);
    var text = getText(text_elem);

    /* make sure we split on all newlines -- IE or Moz use \\r and \\n
     * respectively */
    text = text.split(/\\r|\\n/);

    var replytext = "";
    for (var i=0; i < text.length; i++) {
        replytext += "> " + text[i] + "\\n"; 
    }

    replytext = "(In reply to comment #" + id + ")\\n" + replytext + "\\n";

    /* <textarea name="savetext"> */
    var textarea = document.getElementsByTagName('textarea');
    textarea[0].value += replytext;

    textarea[0].focus();
  }

  if (!Node) {
    /* MSIE doesn't define Node, so provide a compatibility array */
    var Node = {
        TEXT_NODE: 3,
        ENTITY_REFERENCE_NODE: 5
    };
  }

  /* Concatenates all text from element's childNodes. This is used
   * instead of innerHTML because we want the actual text (and
   * innerText is non-standard) */
  function getText(element) {
    var child, text = "";
    for (var i=0; i < element.childNodes.length; i++) {
        child = element.childNodes[i];
        var type = child.nodeType;
        if (type == Node.TEXT_NODE || type == Node.ENTITY_REFERENCE_NODE) {
            text += child.nodeValue;
        } else {
            /* recurse into nodes of other types */
            text += getText(child);
        }
    }
    return text;
  }
/*]]>*/
</script>
SCRIPT;
    if ($value[0] == '#' and $value[1] == '!') {
        list($arg, $value) = explode("\n", $value, 2);
    }
    if (!empty($arg)) {
        # get parameters
        list($tag, $user, $date, $title) = explode(" ", $line, 4);
        if (preg_match('/\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/', $user)) {
            $user = "******";
        }
        if ($date && $date[10] == 'T') {
            $date[10] = ' ';
            $time = strtotime($date . ' GMT');
            $date = '@ ' . date('Y-m-d [h:i a]', $time);
        }
    }
    $bts_conf = 'BugTrack/Config';
    if ($DBInfo->hasPage($bts_conf)) {
        $p = new WikiPage($bts_conf);
        $config_raw = $p->get_raw_body();
        $confs = _get_btsConfig($config_raw);
        #print_r($confs);
    }
    $body = $value;
    # parse metadata
    $meta = '';
    while (true) {
        list($line, $body) = explode("\n", $body, 2);
        if (isset($line[0]) and $line[0] == '#') {
            continue;
        }
        if (strpos($line, ':') === false or !trim($line)) {
            break;
        }
        $meta .= $line . "\n";
    }
    $metas = getMetadata($meta);
    $head = "##[[InputForm(form:get:bts)]]\n##[[HTML(<table width='100%'><tr><td @@ valign='top'>)]]\n";
    $extra = '';
    $attr = '<tablewidth="100%">';
    $sep = 1;
    foreach ($metas as $k => $v) {
        $kk = $k;
        if (in_array($k, array('Version', 'Component'))) {
            $kk = str_replace(' ', '-', ucwords($metas['Product'])) . '-' . $k;
        }
        if ($k[0] == 'X' and $k[1] == '-') {
            if (isset($confs[$kk])) {
                $v = '[[InputForm(:' . _($kk) . ':' . str_replace($v, $v . ' 1', $confs[$kk]) . ')]]';
            }
            $k = substr($k, 2);
            if (substr($k, 0, 9) == 'Separator') {
                $sep++;
                $head .= "\n##\n##[[HTML(</td><td @@ valign='top'>)]]\n";
                $attr = '<tablewidth="100%">';
            } else {
                if (substr($k, 0, 4) == 'Date') {
                    $v = '[[DateTime(' . $v . ')]]';
                }
                $head .= "||" . $attr . " ''" . $k . "'' || " . $v . " ||\n";
                $attr = '';
            }
        } else {
            if ($k == 'Summary' or $k == 'Keywords') {
                $v = str_replace(':', '&#58;', $v);
                $v = '[[InputForm(input:' . _($k) . ':' . $confs[$k] . ':' . $v . ')]]';
                $extra .= "|| '''" . _($k) . "'''''':'''||{$v}||\n";
            } else {
                if (isset($confs[$kk])) {
                    $v = '[[InputForm(:' . _($kk) . ':' . str_replace($v, $v . ' 1', $confs[$kk]) . ')]]';
                }
                $head .= "||" . $attr . "<width='30%'> '''" . _($k) . "'''''':'''||" . $v . " ||\n";
                $attr = '';
            }
        }
    }
    $attr = 'width="100%"';
    if ($sep > 1) {
        $attr = 'width="' . 100 / $sep . '%"';
    }
    $head = preg_replace('/@@/', $attr, $head);
    $head .= "\n##\n##[[HTML(</td></tr></table>)]]\n" . $extra . "\n" . "[[InputForm(submit:" . _("Save Changes") . ")]]\n##[[InputForm]]";
    #print '<pre>'.$head.'</pre>';
    print <<<HEAD
<fieldset id="bts-properties"><legend>Change Properties</legend>
HEAD;
    $formatter->send_page($head, $options);
    print <<<TAIL
</fieldset>
TAIL;
    if ($body) {
        $options['nosisters'] = 1;
        $copy = $body;
        $hidden = '';
        #list($comment,$copy)=explode("----\n",$copy,2);
        $tmp = explode("----\n", $copy, 2);
        $comment = $tmp[0];
        $copy = isset($tmp[1]) ? $tmp[1] : '';
        while (!empty($comment)) {
            #list($comment,$copy)=explode("----\n",$copy,2);
            $tmp = explode("----\n", $copy, 2);
            $comment = $tmp[0];
            $copy = isset($tmp[1]) ? $tmp[1] : '';
            if (preg_match('/^Comment-Id:\\s*(\\d+)/i', $comment, $m)) {
                list($myhead, $my) = explode("\n\n", $comment, 2);
                $hidden .= '<pre style="display:none;" id="comment_text_' . $m[1] . '">' . _html_escape($my) . '</pre>';
            }
        }
        ob_start();
        # add some basic rule/repl for bts
        $rule = "/----\nComment-Id:\\s*(\\d+)\n" . "From:\\s*([^\n]+)\nDate:\\s*([^\n]+)\n\n/im";
        $repl = "----\n'''Comment-Id:''' [#c\\1][#c\\1 #\\1] by \\2 on [[DateTime(\\3)]] [reply \\1]\n\n";
        $body = preg_replace($rule, $repl, $body);
        $formatter->quote_style = 'bts-comment';
        $options['usemeta'] = 1;
        #
        $formatter->baserule[] = "/^((-=)+-?\$)/";
        $formatter->baserule[] = "/ comment #(\\d+)\\b/";
        $formatter->baserule[] = "/Bug #?(\\d+)\\b/";
        $formatter->baserule[] = "/\\[reply (\\d+)\\]/";
        $formatter->baserepl[] = "<hr />\n";
        $formatter->baserepl[] = " comment [#c\\1 #\\1]";
        $formatter->baserepl[] = "wiki:BugTrack:\\1";
        $formatter->baserepl[] = "<script type='text/javascript'><!--\n            addReplyLink(\\1); //--></script>";
        #
        $formatter->send_page($body, $options);
        $msg = ob_get_contents();
        ob_end_clean();
    }
    $msg .= $formatter->macro_repl('Comment(meta)', '', $options);
    if (!empty($bts_script)) {
        return $msg . $hidden;
    }
    $bts_script = 1;
    return $script . $msg . $hidden;
}
예제 #4
0
파일: ISBN.php 프로젝트: ahastudio/moniwiki
function macro_ISBN($formatter, $value = "")
{
    global $DBInfo;
    // http://www.isbn-international.org/en/identifiers/allidentifiers.html
    $default_map = array('89' => 'Aladdin');
    $ISBN_MAP = "IsbnMap";
    $DEFAULT = <<<EOS
Amazon http://www.amazon.com/exec/obidos/ISBN= http://images.amazon.com/images/P/\$ISBN.01.MZZZZZZZ.gif
Aladdin http://www.aladdin.co.kr/shop/wproduct.aspx?ISBN= http://image.aladdin.co.kr/cover/cover/\$ISBN_1.gif @(http://image\\..*/cover/(?:[^\\s_/]*\$ISBN_\\d\\.(?:jpe?g|gif)))@
Gang http://kangcom.com/common/qsearch/search.asp?s_flag=T&s_text= http://kangcom.com/l_pic/\$ISBN.jpg @bookinfo\\.asp\\?sku=(\\d+)"@

EOS;
    $DEFAULT_ISBN = "Amazon";
    $re_isbn = "/^([0-9\\-]+[xX]?)(?:,\\s*)?(([A-Z][A-Za-z]*)?(?:,)?(.*))?/x";
    if ($value != '') {
        $test = preg_match($re_isbn, $value, $match);
        if ($test === false) {
            return "<p><strong class=\"error\">Invalid ISBN \"%value\"</strong></p>";
        }
    }
    $list = $DEFAULT;
    $map = new WikiPage($ISBN_MAP);
    if ($map->exists()) {
        $list .= $map->get_raw_body();
    }
    $lists = explode("\n", $list);
    $ISBN_list = array();
    foreach ($lists as $line) {
        if (!$line or !preg_match("/^[A-Z]/", $line[0])) {
            continue;
        }
        $dum = explode(" ", rtrim($line));
        $re = '';
        $sz = sizeof($dum);
        if (!preg_match('/^(http|ftp)/', $dum[1])) {
            continue;
        }
        if ($sz == 2) {
            $dum[] = $ISBN_list[$DEFAULT_ISBN][1];
        } else {
            if ($sz != 3) {
                if ($sz == 4) {
                    if (($p = strpos(substr($dum[3], 1), $dum[3][0])) !== false) {
                        $retest = substr($dum[3], 0, $p + 2);
                    } else {
                        $retest = $dum[3];
                    }
                    if (preg_match($retest, '') !== false) {
                        $re = $dum[3];
                    }
                } else {
                    continue;
                }
            }
        }
        $ISBN_list[$dum[0]] = array($dum[1], $dum[2], $re);
    }
    if ($value == '') {
        $out = "<ul>";
        foreach ($ISBN_list as $interwiki => $v) {
            $href = $ISBN_list[$interwiki][0];
            if (strpos($href, '$ISBN') === false) {
                $url = $href . '0738206679';
            } else {
                $url = str_replace('$ISBN', '0738206679', $href);
            }
            $icon = $DBInfo->imgs_url_interwiki . strtolower($interwiki) . '-16.png';
            $sx = 16;
            $sy = 16;
            if ($DBInfo->intericon[$interwiki]) {
                $icon = $DBInfo->intericon[$interwiki][2];
                $sx = $DBInfo->intericon[$interwiki][0];
                $sy = $DBInfo->intericon[$interwiki][1];
            }
            $out .= "<li><img src='{$icon}' width='{$sx}' height='{$sy}' " . "align='middle' alt='{$interwiki}:' /><a href='{$url}'>{$interwiki}</a>: " . "<tt class='link'>{$href}</tt></li>";
        }
        $out .= "</ul>\n";
        return $out;
    }
    $isbn2 = $match[1];
    $isbn = str_replace('-', '', $isbn2);
    #print_r($match);
    if ($match[3]) {
        if (strtolower($match[2][0]) == 'k') {
            $lang = 'Aladdin';
        } else {
            $lang = $match[3];
        }
    } else {
        $cl = strlen($isbn);
        if ($cl == 13) {
            $lang_code = substr($isbn, 3, 2);
        } else {
            $lang_code = substr($isbn, 0, 2);
        }
        // 89
        if (!empty($default_map[$lang_code])) {
            $lang = $default_map[$lang_code];
        } else {
            $lang = $DEFAULT_ISBN;
        }
    }
    $attr = '';
    $ext = '';
    if ($match[2]) {
        $args = explode(',', $match[2]);
        foreach ($args as $arg) {
            $arg = trim($arg);
            if ($arg == 'noimg') {
                $noimg = 1;
            } else {
                if (strtolower($arg) == 'k') {
                    $lang = 'Aladdin';
                } else {
                    $name = strtok($arg, '=');
                    $val = strtok(' ');
                    if ($val) {
                        $attr .= $name . '="' . $val . '" ';
                    }
                    #XXX
                    if ($name == 'align') {
                        $attr .= 'class="img' . ucfirst($val) . '" ';
                    }
                    if ($name == 'img') {
                        $ext = $val;
                    }
                }
            }
        }
    }
    if ($ISBN_list[$lang]) {
        $booklink = $ISBN_list[$lang][0];
        $imglink = $ISBN_list[$lang][1];
        $imgre = $ISBN_list[$lang][2];
    } else {
        $booklink = $ISBN_list[$DEFAULT_ISBN][0];
        $imglink = $ISBN_list[$DEFAULT_ISBN][1];
    }
    if (strpos($booklink, '$ISBN') === false) {
        $booklink .= $isbn;
    } else {
        if (strpos($booklink, '$ISBN2') === false) {
            $booklink = str_replace('$ISBN', $isbn, $booklink);
        } else {
            $booklink = str_replace('$ISBN2', $isbn2, $booklink);
        }
    }
    if (empty($noimg) and $imgre and get_cfg_var('allow_url_fopen')) {
        if (($p = strpos(substr($imgre, 1), $imgre[0])) !== false) {
            $imgrepl = substr($imgre, $p + 2);
            $imgre = substr($imgre, 0, $p + 2);
            if ($imgrepl == '@') {
                $imgrepl = '';
            }
            $imgre = str_replace('$ISBN', $isbn, $imgre);
        }
        $md5sum = md5($booklink);
        // check cache
        $bcache = new Cache_text('isbn');
        if (empty($formatter->refresh) and $bcache->exists($md5sum)) {
            $imgname = trim($bcache->fetch($md5sum));
            $fetch_ok = 1;
        } else {
            // fetch the bookinfo page and grep the imagname of the book.
            $fd = fopen($booklink, 'r');
            if (is_resource($fd)) {
                while (!feof($fd)) {
                    $line = fgets($fd, 1024);
                    preg_match($imgre, $line, $match);
                    if (!empty($match[1])) {
                        $bcache->update($md5sum, $match[1]);
                        $imgname = $match[1];
                        $fetch_ok = 1;
                        break;
                    }
                }
                fclose($fd);
            }
        }
        if ($fetch_ok) {
            if ($imgrepl) {
                $imglink = preg_replace('@' . $imgrepl . '@', $imgname, $imglink);
            } else {
                if (!preg_match('/^https?:/', $imgname)) {
                    $imglink = str_replace('$ISBN', $imgname, $imglink);
                } else {
                    $imglink = $imgname;
                }
            }
        }
        if (!empty($fetch_ok) and !empty($DBInfo->isbn_img_download)) {
            # some sites such as the IMDB check the referer and
            # do not permit to show any of its images
            # the $isbn_img_download option is needed to show such images
            preg_match('/^(.*)\\.(jpeg|jpg|gif|png)$/i', $imglink, $m);
            if (!empty($m[1]) and isset($m[2])) {
                $myimglink = md5($m[1]) . '.' . $m[2];
            }
            if (isset($m[2])) {
                # skip XXX
            } else {
                if (file_exists($DBInfo->upload_dir . '/isbn/' . $myimglink)) {
                    $mlink = $formatter->macro_repl('attachment', 'isbn:' . $myimglink, 1);
                    $imglink = qualifiedUrl($DBInfo->url_prefix . '/' . $mlink);
                } else {
                    $fd = fopen($imglink, 'r');
                    if (is_resource($fd)) {
                        $myimg = '';
                        while (!feof($fd)) {
                            $myimg .= fread($fd, 1024);
                        }
                        fclose($fd);
                        if (!is_dir($DBInfo->upload_dir . '/isbn/')) {
                            umask(00);
                            mkdir($DBInfo->upload_dir . '/isbn/', 0777);
                            umask($DBInfo->umask);
                        }
                        $fd = fopen($DBInfo->upload_dir . '/isbn/' . $myimglink, 'w');
                        if (is_resource($fd)) {
                            fwrite($fd, $myimg);
                            fclose($fd);
                        }
                    }
                }
            }
        }
    }
    if (empty($fetch_ok)) {
        if (strpos($imglink, '$ISBN') === false) {
            $imglink .= $isbn;
        } else {
            if (strpos($imglink, '$ISBN2') === false) {
                $imglink = str_replace('$ISBN', $isbn, $imglink);
            } else {
                $imglink = str_replace('$ISBN2', $isbn2, $imglink);
            }
            if ($ext) {
                $imglink = preg_replace('/\\.(gif|jpeg|jpg|png|bmp)$/i', $ext, $imglink);
            }
        }
    }
    if (!empty($noimg)) {
        $icon = $DBInfo->imgs_url_interwiki . strtolower($lang) . '-16.png';
        $sx = 16;
        $sy = 16;
        if (!empty($DBInfo->intericon[$lang])) {
            $icon = $DBInfo->intericon[$lang][2];
            $sx = $DBInfo->intericon[$lang][0];
            $sy = $DBInfo->intericon[$lang][1];
        }
        return "<img src='{$icon}' alt='{$lang}:' align='middle' width='{$sx}' height='{$sy}' title='{$lang}' />" . "[<a href='{$booklink}'>ISBN-{$isbn2}</a>]";
    } else {
        return "<a href='{$booklink}'><img src='{$imglink}' border='1' title='{$lang}" . ":ISBN-{$isbn}' alt='[ISBN-{$isbn2}]' class='isbn' {$attr} /></a>";
    }
}
예제 #5
0
파일: bts.php 프로젝트: ahastudio/moniwiki
function do_bts($formatter, $options)
{
    global $DBInfo;
    $fields = array('Type', 'Priority', 'Product', 'Severity', 'Summary', 'Keywords', 'Submit');
    $basic = <<<EOF
 * Type: Bug,Enhancement,Task,Support
EOF;
    #    if ($DBInfo->hasPage($options['page'])) {
    #        $p=new WikiPage($options['page']);
    #        $bts_raw=$p->get_raw_body();
    #        $meta=_get_btsConfig($bts_raw);
    #    }
    $bts_conf = 'BugTrack/Config';
    if ($DBInfo->hasPage($bts_conf)) {
        $p = new WikiPage($bts_conf);
        $config_raw = $p->get_raw_body();
        if (substr($basic, -1, 1) != "\n") {
            $basic .= "\n";
        }
        $confs = _get_btsConfig($basic . $config_raw);
        #print_r($confs);
    }
    $myform = '';
    foreach ($fields as $field) {
        if (isset($confs[$field])) {
            $myform .= ':' . $field . ':' . $confs[$field] . "\n";
        } else {
            if ($field == 'Submit') {
                $myform .= "hidden:action:bts\n";
                $myform .= "hidden:mode:write\n";
                $myform .= 'submit::' . $field . "\n";
            } else {
                $myform .= 'input:' . $field . "\n";
            }
        }
    }
    #header("Content-Type:text/plain");
    #print '<pre>';
    #print $myform;
    #print '</pre>';
    $formatter->send_header('', $options);
    $formatter->send_title('', '', $options);
    print $formatter->processor_repl('form', $myform, $options);
    #    # parse metadata
    #    $meta='';
    #    while(true) {
    #        list($line,$body)=explode("\n",$body,2);
    #        if ($line[0]=='#') continue;
    #        if (strpos($line,':')===false or !trim($line)) break;
    #        $meta.=$line."\n";
    #    }
    #    print "<pre>";
    #    print_r($options);
    #    print "</pre>";
    #
    #
    #    foreach ($meta as $k=>$v) {
    #        if (!empty($options[$k])) $meta[$k]=$options[$k];
    #    }
    #    print "<pre>";
    #    print_r($meta);
    #    print "</pre>";
    $formatter->send_footer('', $options);
    return;
}
예제 #6
0
파일: Cite.php 프로젝트: ahastudio/moniwiki
function macro_Cite($formatter = "", $value = "")
{
    $CITE_MAP = "CiteMap";
    $DEFAULT = <<<EOS
JCP,J.Chem.Phys. http://jcp.aip.org/jcp/top.jsp?vol=\$VOL&amp;pg=\$PAGE
JACS,J.Am.Chem.Soc. http://pubs.acs.org/journals/query/subscriberResults.jsp?Research=true&amp;yearrange1=ASAP&amp;yearrange3=current&amp;cit_qjrn=jacsat&styear=YYYY&endyear=YYYY&vol=\$VOL&spn=\$PAGE
JPC,J.Phys.Chem. http://pubs.acs.org/journals/query/subscriberResults.jsp?Research=true&amp;yearrange1=ASAP&amp;yearrange3=current&amp;cit_qjrn=jpchax&styear=YYYY&endyear=YYYY&vol=\$VOL&spn=\$PAGE
JPCA,J.Phys.Chem.A http://pubs.acs.org/journals/query/subscriberResults.jsp?Research=true&amp;yearrange1=ASAP&amp;yearrange3=current&amp;cit_qjrn=jpcafh&styear=YYYY&endyear=YYYY&vol=\$VOL&spn=\$PAGE
ChemRev,Chem.Rev. http://pubs.acs.org/journals/query/subscriberResults.jsp?Research=true&amp;yearrange1=ASAP&amp;yearrange3=current&amp;cit_qjrn=chreay&styear=YYYY&endyear=YYYY&vol=\$VOL&spn=\$PAGE
RMP,Rev.Mod.Phys. http://link.aps.org/volpage?journal=RMP&volume=\$VOL&id=\$PAGE
PR,Phys.Rev. http://link.aps.org/volpage?journal=PR&volume=\$VOL&id=\$PAGE
PRL,Phys.Rev.Lett. http://link.aps.org/doi/10.1103/PhysRevLett.\$VOL.\$PAGE
CPL,Chem.Phys.Lett. http://www.sciencedirect.com/science/journal/00092614

EOS;
    $CITE_list = array('JCP' => array('http://jcp.aip.org/jcp/top.jsp?vol=$VOL&amp;pg=$PAGE', '', 'J.Chem.Phys.'));
    $DEFAULT_CITE = "JCP";
    $re_cite = "/([A-Z][A-Za-z]*)?\\s*([0-9\\-]+\\s*,\\s*[0-9]+)/x";
    $test = preg_match($re_cite, $value, $match);
    if ($test === false) {
        return "<p><strong class=\"error\">Invalid CITE \"%value\"</strong></p>";
    }
    list($vol, $page) = explode(',', preg_replace('/ /', '', $match[2]));
    if (!empty($match[1])) {
        if (strtolower($match[1][0]) == "k") {
            $cite = "JKCS";
        } else {
            $cite = $match[1];
        }
    } else {
        $cite = $DEFAULT_CITE;
    }
    $attr = '';
    if (!empty($match[3])) {
        $args = explode(",", $match[3]);
        foreach ($args as $arg) {
            if ($arg == "noimg") {
                $noimg = 1;
            } else {
                $name = strtok($arg, '=');
                $val = strtok(' ');
                $attr .= $name . '="' . $val . '" ';
                if ($name == 'align') {
                    $attr .= 'class="img' . ucfirst($val) . '" ';
                }
            }
        }
    }
    $list = $DEFAULT;
    $map = new WikiPage($CITE_MAP);
    if ($map->exists()) {
        $list .= $map->get_raw_body();
    }
    $lists = explode("\n", $list);
    foreach ($lists as $line) {
        if (empty($line) or !preg_match("/^[A-Z]/", $line[0])) {
            continue;
        }
        $dum = explode(" ", rtrim($line));
        if (sizeof($dum) == 2) {
            $dum[] = $CITE_list[$DEFAULT_CITE][1];
        } else {
            if (sizeof($dum) != 3) {
                continue;
            }
        }
        list($dum[0], $name) = explode(',', $dum[0]);
        $CITE_list[$dum[0]] = array($dum[1], $dum[2], $name);
    }
    if (!empty($CITE_list[$cite])) {
        $citelink = $CITE_list[$cite][0];
        $imglink = $CITE_list[$cite][1];
        $citename = $CITE_list[$cite][2];
        if ($citename) {
            $cite = str_replace('.', '. ', $citename);
        }
    } else {
        $citelink = $CITE_list[$DEFAULT_CITE][0];
        $imglink = $CITE_list[$DEFAULT_CITE][1];
    }
    $citelink = str_replace('$VOL', $vol, $citelink);
    $citelink = str_replace('$PAGE', $page, $citelink);
    return $formatter->icon['www'] . '<a href=' . "'{$citelink}'>" . $cite . ' <strong>' . $vol . '</strong>, ' . $page . '</a> ';
}