A little php help needed

Discussion in 'Web Design and Development' started by tominated, Jun 24, 2007.

  1. tominated macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #1
    Ok, so I am following this tutorial, but modifying it slightly for use with another superior editor: XStandard. The problem is that when using the code supplied for the editor they are using (TinyMCE), it works fine, but modifying the code for XStandard makes the page blank when it loads, i even checked the source and it was blank. here is what the code supplied looks like for the edit page

    PHP:
    <?php
    include("../header.html");

    // Get the page name from the query string
    $page $_GET['page'] . '.txt';

    if (!
    $_GET['page']) {
      echo(
    "<h1>Page name not specified</h1>\n");
      include(
    "../footer.html");
      exit;
    }

    if (
    $_POST['page']) {
      
    $handle fopen("../pages/$page"'w');
      
    fwrite($handle$_POST['page']);
      
    fclose($handle);
      include(
    "../pages/$page");
      include(
    "../footer.html");
      exit;


    if (
    file_exists("../pages/$page")) {
      
    $FILE fopen("../pages/$page""rt");
      while (!
    feof($FILE)) {
        
    $text .= fgets($FILE);
      }
      
    fclose($FILE);
    } else {
       echo(
    "<h1>New Page: $page</h1>\n");
      
    $text "<p></p>";
    }

    echo <<< EOM
    <script language="javascript" type="text/javascript" src="/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
    <script language="javascript" type="text/javascript">
     tinyMCE.init({
      mode : "textareas",
      theme : "advanced",
      theme_advanced_toolbar_location : "top",
      theme_advanced_toolbar_align : "left",
      theme_advanced_path_location : "bottom"
     });
    </script>
    EOM;

    $page $_GET['page'] . '.txt';
    $a $_GET['page'];





    $a 1//$_SERVER['PHP_SELF'];

    $this_page $_SERVER['PHP_SELF'];
    $query_string $_SERVER['QUERY_STRING'];
    echo(
    "<form method=\"post\" action=\"$this_page?$query_string\">\n");
    echo(
    "<textarea id=\"page\" name=\"page\" rows=25 cols=80>\n");
    echo(
    htmlspecialchars($text));
    echo(
    "</textarea>\n");
    echo(
    "<input type=\"submit\" value=\"Save\">\n");
    echo(
    "</form>\n"); 

    include(
    "../footer.html");

    ?> 
    and here is my modified version. BTW: it says how to use XStandard here
    PHP:
    <?php
    include("../header.html");

    // Get the page name from the query string
    $page $_GET['page'] . '.txt';

    if (!
    $_GET['page']) {
      echo(
    "<h1>Page name not specified</h1>\n");
      include(
    "../footer.html");
      exit;
    }

    if (
    $_POST['page']) {
      
    $handle fopen("../pages/$page"'w');
      
    fwrite($handle$_POST['page']);
      
    fclose($handle);
      include(
    "../data/$page");
      include(
    "../footer.html");
      exit;


    if (
    file_exists("../data/$page")) {
      
    $FILE fopen("../data/$page""rt");
      while (!
    feof($FILE)) {
        
    $text .= fgets($FILE);
      }
      
    fclose($FILE);
    } else {
       echo(
    "<h1>New Page: $page</h1>\n");
      
    $text "<p></p>";
    }

    $page $_GET['page'] . '.txt';
    $a $_GET['page'];

    $a 1//$_SERVER['PHP_SELF'];

    $this_page $_SERVER['PHP_SELF'];
    $query_string $_SERVER['QUERY_STRING'];
    echo(
    "<form method=\"post\" action=\"$this_page?$query_string\">\n");
    echo(
    "<object name=\"page\" type=\"application/x-xstandard\" width=\"100%\" height=\"500\">\n");
    echo(
    "<param name=\"Value\" value=\"")
    echo(
    htmlspecialchars($text));
    echo(
    "\" />");
    echo(
    "</object>\n");
    echo(
    "<input type=\"submit\" value=\"Save\" />\n");
    echo(
    "</form>\n"); 

    include(
    "../footer.html");

    ?>
     
  2. Aea macrumors 6502a

    Aea

    Joined:
    May 23, 2007
    Location:
    Denver, Colorado
    #2
    Code:
    echo("<object name=\"page\" type=\"application/x-xstandard\" width=\"100%\" height=\"500\">\n");
    echo("<param name=\"Value\" value=\"[COLOR="Red"][b]\[/b][/COLOR]")[COLOR="Red"][b];[/b][/COLOR]
    echo(htmlspecialchars($text)); 
    
     
  3. tominated thread starter macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #3
    Awesome! Thanks Aea! that fixed the loading problem, but now it wont write to/create files! If anybody could help here it would be much appreciated.
     
  4. angelneo macrumors 68000

    Joined:
    Jun 13, 2004
    Location:
    afk
    #4
    Did you check the write access?
     
  5. Matteh117 macrumors regular

    Joined:
    May 24, 2007
    Location:
    Surrey, UK
    #5
    To save yourself backslashing why not use single quotation marks instead like so?
    Code:
    echo('<object name="page" type="application/x-xstandard" width="100%" height="500"><br />');
    As long as you use one for PHP and the other for HTML you can use this throughout.
     
  6. tominated thread starter macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #6
    YAY! the ANSWER! it works all good now!
     
  7. Winterfell macrumors regular

    Joined:
    Apr 3, 2007
    Location:
    Tulsa, Oklahoma
    #7
    In addition to saving you time by not having to type those escape slashes, it's also more efficient for PHP to process "literal" strings, or strings encapsulated by single quotes, because it doesn't have to search through the string and look for variables and other escaped characters.

    So echo('Hi there, ' . $name . "\n"); is actually faster than echo("Hi there, $name\n"); Of course on a string that small, there really won't be any difference, but when you get to large strings, such as loading pages like you're doing here, it will make a difference. ^-^
     
  8. tominated thread starter macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #8
    thanks winterfell! I have made some progress in that I have made the page show the list of files to edit with links to delete (trying to work out a confirm dialog) or edit them when a page is not specified. All I have to do now is make the menu dynamically load the items (obviously in a similar way to the editing files list). Does anybody know if there is a way that when the user clicks a delete button, a javascript confirmation dialog displays asking if you are sure? I have gotten the popup and everything, but I don't know how to get it to stop loading the page if the user clicks cancel. Anybody know? BTW: I have this setup like this:

    PHP:
    echo "<li>$file  »  <a href=\"index.php?page=$file\" class=\"edit\"></a><a href=\"delete.php?page=$file\" onclick=\"del_confirm()\" class=\"delete\"></a></li>\n";
    the del_confirm function calls up a confirm dialoge and it does nothing if ok is pressed, but I don't know what it should do to stop loading the delete page (that checks for the page the way the others do the uses the unlink command).
    Thanks in advance guys;)
     
  9. Winterfell macrumors regular

    Joined:
    Apr 3, 2007
    Location:
    Tulsa, Oklahoma
    #9
    I don't know exactly what your JavaScript function del_confirm() is doing (e.g. is it using an alert() dialog or a confirm() dialog)?

    If it's using confirm(), that will automatically return false if the user presses cancel. Otherwise, it will return true if they press okay and proceed with the rest of the function. Hope that's clear as mud. :p
     
  10. tominated thread starter macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia
    #10
    yeah, it is a confirm(), but when it returns false, i don't know what to make it stop loading the php script. Another way I could do it is if i knew how to make the function take a parameter (like del_confirm(The name of the php script) ). Can someone tell me how to do this because I would be able to make the php echo a variable where the parameter is needed. BTW: the reason I need your help is that I am making a basic CMS for a client.
     
  11. Matteh117 macrumors regular

    Joined:
    May 24, 2007
    Location:
    Surrey, UK
    #11
    Ps quoation marks..
    PHP:
    echo '<li>$file  »  <a href="index.php?page=$file" class="edit"></a><a href="delete.php?page=$file" onclick="del_confirm()" class="delete"></a></li>\n'
     
  12. tominated thread starter macrumors 68000

    tominated

    Joined:
    Jul 7, 2006
    Location:
    Queensland, Australia

Share This Page