Jump to content

TinyMCE not loading saved changes, possible php problem?


CarbonCopy

Recommended Posts

I have a TinyMCE setup to edit my website. However, when I submit my form, the changes are written to the database, I'm redirected back the editor page, and TinyMCE refuses to load the updated content. It's not so much a TinyMCE problem I think, since the text area is showing the wrong content as well. I have to Shift + Reload to see the new html, even regular refreshing won't work.

 

I've disabled caching in the index.php page (Which loads everything else) using this code:

 

header( 'Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0' );
header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // Date in the past
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );

 

and my save page does this

 

$page = mysql_real_escape_string( $_REQUEST['page'] );
$name = mysql_real_escape_string( htmlentities( $_POST['page_name'] ) );
$html = mysql_real_escape_string( $_POST['html'] );

$query1 = mysql_query( "SELECT * FROM `html` WHERE `name` = '$page' ORDER BY ABS(`revision`) DESC LIMIT 1" );
$data1  = mysql_fetch_assoc( $query1 );
$rev    = $data1['revision']+1;
$user   = $_SESSION['id'];
$time   = time();

mysql_query( "INSERT INTO `html` ( `name`,`title`,`content`,`date_modified`,`modified_by`,`revision` ) VALUES ( '$page','$name','$html','$time','$user','$rev')" );

header( 'Location: index.php?act=redirect&to=index.php%3Fact%3Dedit%26type%3Dreg%26page%3D'.$page );

 

I tried using two header redirects which is what that last part is. It redirects to index which redirects again to the editor page.

 

This is my TinyMCE code

 

<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	// General options
	mode : "textareas",
	theme : "advanced",
	plugins : "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,wordcount,advlist,autosave",

	// 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,|,fullscreen",
	theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,

	// Example content CSS (should be your site CSS)
	content_css : "../css/main.css",

	// Drop lists for link/image/media/template dialogs
	external_link_list_url : "admin/tiny_mce/lists/link_list.js",
	external_image_list_url : "admin/tiny_mce/lists/image_list.js",
	//media_external_list_url : "tiny_mce/lists/link_list.php",

	remove_script_host : false,
	relative_urls : false,
	document_base_url : "<?=$_CONFIG['site_path']?>",
});
</script>

 

and this is my editor

 

$page   = mysql_real_escape_string( $_REQUEST['page'] );

if ( isset( $_POST['revision'] ) )
{
	$rev = intval( $_POST['revision'] );
	$query1 = mysql_query( "SELECT * FROM `html` WHERE `name` = '$page' AND `revision` = '$rev'" );

	if ( mysql_num_rows( $query1 ) == 0 )
	{
		$query1 = mysql_query( "SELECT * FROM `html` WHERE `name` = '$page' ORDER BY ABS(`revision`) DESC LIMIT 1" );
	}
}
else
{
	$query1 = mysql_query( "SELECT * FROM `html` WHERE `name` = '$page' ORDER BY ABS(`revision`) DESC LIMIT 1" );
}

if ( mysql_num_rows( $query1 ) == 0 ) 
{
	include( 'view/edit/home.html' );
	include( 'template/layout.php' );	
	exit();
}

$query2 = mysql_query( "SELECT `revision` FROM `html` WHERE `name` = '$page' ORDER BY ABS(`revision`) DESC LIMIT 1" );
$data2  = mysql_fetch_assoc( $query2 );

$data1 = mysql_fetch_assoc( $query1 );
$html  = htmlentities( $data1['content'] );
$rev   = $data2['revision']+1;
$date  = $data1['date_modified']; 

$query3 = mysql_query( "SELECT `username` FROM `users` WHERE `id` = '{$data1['modified_by']}'" );
$data3  = mysql_fetch_assoc( $query3 );

if ( empty( $data3['username'] ) )
{
	$user = 'Unknown User';
}
else
{
	$user = $data3['username'];	
}

$query3 = mysql_query( "SELECT `revision`,`date_modified` FROM `html` WHERE `name` = '$page' ORDER BY ABS(`revision`) DESC" );
$revisions = '';

while ( $row = mysql_fetch_assoc( $query3 ) )
{
	$dater = date( 'l, F jS @ g:i A' , $row['date_modified'] );
	$revisions .= "<option value='{$row['revision']}'>Revision {$row['revision']} From $dater</option>\n";
}

$sidebar = false;
include( 'view/edit/regular_edit.html' );
include( 'template/layout.php' );

 

    <textarea style="width:90%;height:450px;" name="html">
        <?=$html?>
    </textarea>

 

The editor will either load the newest content or the specified revision.

 

I do NOT have this issue with a wordpress installation on the same server when using TinyMCE

Thanks to Freenode, I was able to get this issue solved.

 

// Disable caching
function http_last_modified( $time = NULL )
{
if ( $time === NULL ) $time = time();

$new_last_modified = gmdate( 'D, d M Y H:i:s' , $time ) . ' GMT';
if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) 
{
	$if_modified_since = preg_replace( '/;.*$/' , '' , $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); 
	if ( $if_modified_since == $new_last_modified ) 
	{
		header( 'HTTP/1.0 304 Not Modified' );
		exit(0);
	}
}
header( "Last-Modified: $new_last_modified" );
}
http_last_modified();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.