Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tominated

macrumors 68000
Original poster
Jul 7, 2006
1,723
0
Queensland, Australia
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");

?>
 
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));
 
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.
 
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));

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.
 
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. ^-^
 
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;)
 
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
 
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.
 
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'
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.