[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 727
  • Last Modified:

TinyMCE Toolbar not Loading (php)

I am having a problem implementing the TinyMCE WYSIWYG editor on my site.

When the page opens, only the editors text box and save button appear, but not the advanced toolbar.

I am wanting to be able to edit my pages. I have a header.html, and footer.html included in my index.php page. the the body part of the page, i am using .txt files. You click on a link, and then the corresponding .txt file opens in the page ready for editing.

At the moment though, only the text box and save button are appearing with the correct .txt file inside, but i need the advanced toolbar to appear aswell.

Can somebody see where i am going wrong please ?.
<?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;
}
 
// This step is checking to see if I have posted. 
// If I have posted the page contents, it opens up the 
// filename indicated by the query string, writes it out, 
// closes the file, shows  the new contents of the file, 
// sources the footer and quits.
if (isset($_POST['page'])) {
  $handle = fopen("../pages/$page", 'w');
  fwrite($handle, $_POST['page']);
  fclose($handle);
  include("../footer.html");
  exit;
}
 
// If I have specified a page that exists, read it into the 
// $text variable. If the page doesn't exist, 
// mention that I am creating a new one at the top of the page, 
// and set $text to an empty paragraph (<p></p>). 
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>";
}
 
 
// JavaScript is usually loaded in the <head> section of a page. 
// But since the <head> section is // in the shared header.html, 
// I don't want to load this up for every page, just the editing page. 
// Because of this, i am putting it in the <body> section. 
// The "init" section is where all the // options are for the editor. 
// "mode: textareas" means that all text areas on the page will become
// TinyMCE WYSIWYG texareas. 
echo <<< EOM
<script language="javascript" type="text/javascript" src="Testing/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
 
// General options
mode : "textareas",
theme : "advanced",
 
plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
 
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
 
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
 
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|",
 
theme_advanced_buttons4 : "moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,|,insertfile,insertimage",
 
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_resizing : true,
 
// Example content CSS (should be your site CSS)
content_css : "Testing/project.css",
 
// Drop lists for link/image/media/template dialogs
template_external_list_url : "js/template_list.js",
external_link_list_url : "js/link_list.js",
external_image_list_url : "js/image_list.js",
media_external_list_url : "js/media_list.js",
 
 
});
</script>
EOM;
 
// Here I create the form, the textarea and the "Save" button. 
// The "htmlspecialchars($text)" call reads the $text variable,
// and replaces all the special characters with the 
// HTML special character codes. This is so the HTML in 
// the file doesn't clash with the HTML on this page.
// The output of this function then gets passed to the textarea.
// When the "Save" is clicked, it calls the same page again 
// with the same query string, but this time there is some posted
// information containing the editing i did. 
// This is sent to the second section of code at the top
// of this page to be saved to a file.
 
$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");
 
// load the footer and close out the PHP script.
include("footer.html");
 
?>

Open in new window

0
LearningPHPMySQL
Asked:
LearningPHPMySQL
  • 3
  • 2
2 Solutions
 
joep1978Commented:
Check the location of tiny_mce.js -
http://www.numyspace.co.uk/~unn_r031923/Testing/secure/Testing/tinymce/jscripts/tiny_mce/tiny_mce.js does not link to a file

I saw the error in my browser:-

The requested URL /~unn_r031923/Testing/secure/Testing/tinymce/jscripts/tiny_mce/tiny_mce.js was not found on this server.
0
 
joep1978Commented:
Try this - the problem is your edit page script is inside /~unn_r031923/Testing/secure - the path of the script seems to be relative to /~unn_r031923/
<?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;
}
 
// This step is checking to see if I have posted. 
// If I have posted the page contents, it opens up the 
// filename indicated by the query string, writes it out, 
// closes the file, shows  the new contents of the file, 
// sources the footer and quits.
if (isset($_POST['page'])) {
  $handle = fopen("../pages/$page", 'w');
  fwrite($handle, $_POST['page']);
  fclose($handle);
  include("../footer.html");
  exit;
}
 
// If I have specified a page that exists, read it into the 
// $text variable. If the page doesn't exist, 
// mention that I am creating a new one at the top of the page, 
// and set $text to an empty paragraph (<p></p>). 
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>";
}
 
 
// JavaScript is usually loaded in the <head> section of a page. 
// But since the <head> section is // in the shared header.html, 
// I don't want to load this up for every page, just the editing page. 
// Because of this, i am putting it in the <body> section. 
// The "init" section is where all the // options are for the editor. 
// "mode: textareas" means that all text areas on the page will become
// TinyMCE WYSIWYG texareas. 
echo <<< EOM
<script language="javascript" type="text/javascript" src="/~unn_r031923/Testing/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
 
// General options
mode : "textareas",
theme : "advanced",
 
plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
 
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
 
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
 
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|",
 
theme_advanced_buttons4 : "moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,|,insertfile,insertimage",
 
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_resizing : true,
 
// Example content CSS (should be your site CSS)
content_css : "Testing/project.css",
 
// Drop lists for link/image/media/template dialogs
template_external_list_url : "js/template_list.js",
external_link_list_url : "js/link_list.js",
external_image_list_url : "js/image_list.js",
media_external_list_url : "js/media_list.js",
 
 
});
</script>
EOM;
 
// Here I create the form, the textarea and the "Save" button. 
// The "htmlspecialchars($text)" call reads the $text variable,
// and replaces all the special characters with the 
// HTML special character codes. This is so the HTML in 
// the file doesn't clash with the HTML on this page.
// The output of this function then gets passed to the textarea.
// When the "Save" is clicked, it calls the same page again 
// with the same query string, but this time there is some posted
// information containing the editing i did. 
// This is sent to the second section of code at the top
// of this page to be saved to a file.
 
$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");
 
// load the footer and close out the PHP script.
include("footer.html");
 
?>

Open in new window

0
 
LearningPHPMySQLAuthor Commented:
Thanks, that is now displaying correctly.

The problem i am having now though, Is when i edit a page and click "Save" , instead of showing the changes on the page, it is displaying the following errors.

Warning: fopen(../pages/social_events.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_r031923/public_html/Testing/secure/index.php on line 19

Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_r031923/public_html/Testing/secure/index.php on line 20

Warning: fclose(): supplied argument is not a valid stream resource in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_r031923/public_html/Testing/secure/index.php on line 21
0
 
joep1978Commented:
The file home.txt (and all the text files) need to be writable by the webserver.  Normally I'd recommend doing this in a database if it's a CMS you're building.

I'm a Linux man and I see you're doing this on Windows so I don't know exactly how you fix this but I found this posted by someone else on the web:-

Use the control center's file permissions tool to set the permissions for the EVERYONE user to READ / WRITE / EXEC / DEL for the directory in which your new directories will be created. Make sure to propagate the permissions to all sub files and folders.

In other words, if you wanted to create the directory "new_dir" you would have to do it in a folder that EVERYONE has R/W/E/D permissions to.

This way when PHP creates something new under that directory, it *should* inherrit the same permissions. You can remove the chmod command from your code. It will not do anything.
0
 
LearningPHPMySQLAuthor Commented:
Excellent. Got my TinyMCE editor working on my site now YaY : ).

I was having nightmares about it, worrying i would not get it fixed, but this has solved that. Thanks : )
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now