Make WordPress Core

Changeset 41


Ignore:
Timestamp:
05/23/2003 12:12:22 AM (22 years ago)
Author:
saxmatt
Message:

Clean up entire file, improved error messages and HTML, fixed editing problem, double-checekd security.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/b2template.php

    r40 r41  
    3838switch($action) {
    3939
    40 case "update":
     40case 'update':
    4141
    42     $standalone=1;
    43     require_once("./b2header.php");
     42    $standalone = 1;
     43    require("b2header.php");
    4444
    4545    if ($user_level < 3) {
    46         die("You have no right to edit the template for this blog.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)");
     46        die('<p>You have no right to edit the template for this blog.<br />Ask for a promotion to your <a href="mailto:$admin_email">blog admin</a>. :)</p>');
    4747    }
    4848
    4949    $newcontent = stripslashes($HTTP_POST_VARS["newcontent"]);
    5050    $file = $HTTP_POST_VARS["file"];
    51     $f = fopen($file,"w+");
    52     fwrite($f,$newcontent);
     51    $f = fopen($file, 'w+');
     52    fwrite($f, $newcontent);
    5353    fclose($f);
    5454
     55    $file = str_replace('../', '', $file);
    5556    header("Location: b2template.php?file=$file&a=te");
    5657    exit();
     
    6061default:
    6162
    62     include("./b2header.php");
     63    require('b2header.php');
    6364
    6465    if ($user_level <= 3) {
    65         die("You have no right to edit the template for this blog.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)");
     66        die('<p>You have no right to edit the template for this blog.<br>Ask for a promotion to your <a href="mailto:$admin_email">blog admin</a>. :)</p>');
    6667    }
    6768
    68     if ($file=="") {
    69         if ($blogfilename != "") {
     69    if ('' == $file) {
     70        if ('' != $blogfilename) {
    7071            $file = $blogfilename;
    7172        } else {
    72             $file = "b2.php";
     73            $file = 'index.php';
    7374        }
    7475    }
    7576   
    76     if (substr($file,0,2) == "..")
    77         die ("Sorry, can't edit files that are up one directory or more.");
     77    if ('..' == substr($file,0,2))
     78        die ('Sorry, can&#8217;t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.');
    7879   
    79     if (substr($file,1,1) == ":")
    80         die ("Sorry, can't call files with their real path.");
     80    if (':' == substr($file,1,1))
     81        die ('Sorry, can&#8217;t call files with their real path.');
    8182
    82     if (substr($file,0,1) == "/")
    83         $file = ".".$file;
     83    if ('/' == substr($file,0,1))
     84        $file = '.' . $file;
     85   
     86    $file = stripslashes($file);
     87    $file = '../' . $file;
    8488   
    8589    if (!is_file($file))
    8690        $error = 1;
    8791
    88     $file = stripslashes($file);
    89 
    90     if ((substr($file,0,2) == "b2") and (substr($file,-4,4) == ".php") and ($file != "b2.php"))
    91         $warning = " - this is a b2 file, be careful when editing it !";
    92 
     92    if ((substr($file,0,2) == 'b2') and (substr($file,-4,4) == '.php') and ($file != 'b2.php'))
     93        $warning = ' &#8212; this is a WordPress file, be careful when editing it!';
     94   
    9395    if (!$error) {
    94         $f = fopen($file,"r");
    95         $content = fread($f,filesize($file));
    96 //      $content = template_simplify($content);
     96        $f = fopen($file, 'r');
     97        $content = fread($f, filesize($file));
    9798        $content = htmlspecialchars($content);
    9899//      $content = str_replace("</textarea","&lt;/textarea",$content);
    99100    }
    100101
    101     echo $blankline;
    102     echo $tabletop;
    103102    ?>
    104     <table width="100%" cellpadding="5" cellspacing="0">
    105     <tr>
    106     <td>
     103<div class="wrap">
    107104    <?php
    108     echo "Listing <b>$file</b>".$warning;
    109     if ($a == "te")
    110         echo "<i> [ file edited ! ]</i>";
     105    echo "Listing <strong>$file</strong> $warning";
     106    if ('te' == $a)
     107        echo "<em>File edited successfully.</em>";
    111108   
    112109    if (!$error) {
     
    127124    <?php
    128125    } else {
    129         echo "<p>oops, no such file !</p>";
     126        echo '<p>Oops, no such file exists! Double check the name and try again, merci.</p>';
    130127    }
    131     echo $tablebottom;
    132128    ?>
    133     </td>
    134     </table>
    135     <br />
    136     <?php   echo $tabletop; ?>
    137     You can also edit the <a href="b2template.php?file=b2comments.php">comments' template</a> or the <a href="b2template.php?file=b2commentspopup.php">popup comments' template</a>, or edit any other file (provided it's writable by the server, e.g. CHMOD 766).<br />
    138     <br />
    139     To edit a file, type its name here:
    140     <form name="file" action="b2template.php" method="get">
     129</div>
     130
     131<div class="wrap">
     132  <p>You can also edit the <a href="b2template.php?file=b2comments.php">comments
     133    template</a> or the <a href="b2template.php?file=b2commentspopup.php">popup
     134    comments template</a>, or edit any other file (provided it&#8217;s writable by
     135    the server, e.g. CHMOD 766).</p>
     136    <p>To edit a file, type its name here:</p>
     137  <form name="file" action="b2template.php" method="get">
    141138    <input type="text" name="file" />
    142139    <input type="submit" name="submit"  class="search" value="go" />
    143140    </form>
    144     <br />
    145     Note: of course, you can also edit the files/templates in your text editor and upload them. This online editor is only meant to be used when you don't have access to a text editor...
    146141   
    147 <?php   echo $tablebottom; ?>
     142  <p>Note: of course, you can also edit the files/templates in your text editor
     143    and upload them. This online editor is only meant to be used when you don't
     144    have access to a text editor.</p>
     145</div>
    148146   
    149147
Note: See TracChangeset for help on using the changeset viewer.