コード例 #1
0
ファイル: rawblog.php プロジェクト: ahastudio/moniwiki
function do_rawblog($formatter, $options)
{
    global $DBInfo;
    global $HTTP_USER_AGENT;
    $COLS_MSIE = 80;
    $COLS_OTHER = 85;
    $cols = preg_match('/MSIE/', $HTTP_USER_AGENT) ? $COLS_MSIE : $COLS_OTHER;
    $rows = (!empty($options['rows']) and $options['rows'] > 5) ? $options['rows'] : 8;
    $cols = (!empty($options['cols']) and $options['cols'] > 60) ? $options['cols'] : $cols;
    $url = $formatter->link_url($formatter->page->urlname);
    $formatter->send_header("", $options);
    $quote = '';
    #
    $lines = array();
    $title = '';
    if ($options['value']) {
        $raw_body = $formatter->page->_get_raw_body();
        $lines = explode("\n", $raw_body);
        $count = count($lines);
        for ($i = 0; $i < $count; $i++) {
            if (preg_match("/^({{{)?#!blog (.*)\$/", $lines[$i], $match)) {
                if (md5($match[2]) == $options['value']) {
                    list($tag, $user, $date, $title) = explode(" ", $lines[$i], 4);
                    $found = 1;
                    $lines[$i] = '#!blog ' . $match[2];
                    break;
                }
            }
        }
        if ($found) {
            for (; $i < $count; $i++) {
                if (preg_match("/^}}}\$/", $lines[$i])) {
                    unset($lines[$i]);
                    break;
                }
                $quote .= $lines[$i] . "\n";
                unset($lines[$i]);
            }
            $quote = str_replace('\\}}}', '}}}', $quote);
        } else {
            $formatter->send_title("Error: No entry found!", "", $options);
            $formatter->send_footer("", $options);
            return;
        }
        if (!isset($title[0])) {
            $title = $options['page'];
        }
        $formatter->send_title(sprintf(_("Delete Blog entry \"%s\""), $title), "", $options);
    }
    $options['noaction'] = 1;
    print <<<FORM
<textarea class="wiki" id="content" wrap="virtual" name="savetext"
 rows="{$rows}" cols="{$cols}" class="wiki">{$quote}</textarea><br />
FORM;
    $options['savetext'] = implode("\n", $lines);
    $options['editlog'] = sprintf(_("Delete Blog entry \"%s\""), $title);
    echo macro_Edit($formatter, "", $options);
    $formatter->send_footer("", $options);
    return;
}
コード例 #2
0
ファイル: wikilib.php プロジェクト: reviforks/moniwiki
function macro_EditText($formatter, $value, $options)
{
    global $DBInfo;
    # simple == 1 : do not use EditTextForm, simple == 2 : do not use GUI/Preview
    $has_form = false;
    $form = '';
    if (empty($options['simple']) or $options['simple'] != 1) {
        if (!empty($DBInfo->editform) and file_exists($DBInfo->editform)) {
            $form = file_get_contents($DBInfo->editform);
        } else {
            if ($DBInfo->hasPage('EditTextForm')) {
                $p = $DBInfo->getPage('EditTextForm');
                $form = $p->get_raw_body();
            }
        }
    }
    $tmpls = '';
    if (isset($form[0])) {
        $form = preg_replace('/\\[\\[EditText\\]\\]/i', '#editform', $form);
        ob_start();
        $opi = $formatter->pi;
        // save pi
        $formatter->pi = array('#linenum' => 0);
        // XXX override pi
        $save = $formatter->auto_linebreak;
        $formatter->auto_linebreak = 0;
        $formatter->send_page("#format wiki\n" . rtrim($form), $options);
        $formatter->auto_linebreak = $save;
        $formatter->pi = $opi;
        // restore pi
        $form = ob_get_contents();
        ob_end_clean();
        preg_match('@(</form>)@i', $form, $m);
        if (isset($options['has_form'])) {
            $has_form =& $options['has_form'];
        }
        if (isset($m[1])) {
            $has_form = true;
        }
        $options['tmpls'] =& $tmpls;
        $editform = macro_Edit($formatter, 'nohints,nomenu', $options);
        $new = str_replace("#editform", $editform, $form);
        // XXX
        if ($form == $new) {
            $form .= $editform;
        } else {
            $form = $new;
        }
    } else {
        $form = macro_Edit($formatter, $value, $options);
    }
    $js = '';
    $css = '';
    if (empty($DBInfo->edit_with_sidebar)) {
        $sidebar_style = "#wikiSideMenu { display: none; }\n";
    }
    if ($has_form and !empty($DBInfo->use_jsbuttons)) {
        $css = <<<CSS
<style type='text/css'>
/*<![CDATA[*/
#mycontent button.save-button { display: none; }
#mycontent button.preview-button { display: none; }
button.save-button { display: none; }
{$sidebar_style}
/*]]>*/
</style>
CSS;
        $js = <<<JS
<script type='text/javascript'>
/*<![CDATA[*/
function submit_all_forms() {
  var form = document.getElementById('editform'); // main edit form
  var all = document.getElementById('all-forms');
  var all_forms = all.getElementsByTagName('form'); // all extra forms
  for (var i=0; i < all_forms.length; i++) {
    if (all_forms[i] == form) continue;
    if (all_forms[i].encoding == "multipart/form-data" || all_forms[i].enctype == "multipart/form-data") {
      form.encoding = "multipart/form-data";
      form.encoding = "multipart/form-data";
    }
    for (var j=0; j < all_forms[i].elements.length; j++) {
      if (all_forms[i].elements[j].type == 'button' || all_forms[i].elements[j].type == 'submit') continue;
      if (all_forms[i].elements[j].name == 'action' || all_forms[i].elements[j].name == '') continue;
      var newopt = all_forms[i].elements[j];
      //newopt.setAttribute('style', 'display:none');
      form.appendChild(newopt);
    }
  }
  form.elements['button_preview'].value = '';
  form.submit();
}

function check_uploadform(obj) {
  var form = document.getElementById('editform'); // main edit form
  var all = document.getElementById('all-forms');
  var all_forms = all.getElementsByTagName('form'); // all extra forms
  for (var i=0; i < all_forms.length; i++) {
    if (all_forms[i].encoding == "multipart/form-data" || all_forms[i].enctype == "multipart/form-data") {
      for (var j=0; j < all_forms[i].elements.length; j++) {
        if (all_forms[i].elements[j].type == 'file' && all_forms[i].elements[j].value != '') {
          alert("Please upload your files first!");
          return;
        }
      }
    }
  }
  if (obj.name != "") {
    var newopt = document.createElement('input');
    newopt.setAttribute('name', obj.name);
    newopt.setAttribute('value','dummy');
    newopt.setAttribute('type','hidden');
    form.appendChild(newopt);
  }
  form.submit();
}
/*]]>*/
</script>

JS;
    } else {
        if (!empty($sidebar_style)) {
            $css = <<<CSS
<style type='text/css'>
/*<![CDATA[*/
{$sidebar_style}
/*]]>*/
</style>

CSS;
        }
    }
    return $css . $js . '<div id="all-forms">' . $form . '</div>' . $tmpls;
}