Code:
<?php
// ensure this file is being included by a parent file
if( !defined( '_JEXEC' ) && !defined( '_VALID_MOS' ) ) die( 'Restricted access' );
/**
* @version $Id: edit.php 105 2008-05-31 13:38:38Z soeren $
* @package eXtplorer
* @copyright soeren 2007
* @author The eXtplorer project (http://sourceforge.net/projects/extplorer)
* @author The The QuiX project (http://quixplorer.sourceforge.net)
*
* @license
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU General Public License Version 2 or later (the "GPL"), in
* which case the provisions of the GPL are applicable instead of
* those above. If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use
* your version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice and
* other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this file
* under either the MPL or the GPL."
*
*
*/
/**
* File-Edit Functions
*
*/
class ext_Edit extends ext_Action {
function execAction($dir, $item) { // edit file
global $mainframe, $mosConfig_live_site;
if(($GLOBALS["permissions"]&01)!=01) {
ext_Result::sendResult('edit', false, ext_Lang::err('accessfunc' ));
}
$fname = get_abs_item($dir, $item);
if(!get_is_file(utf8_decode($fname))) {
ext_Result::sendResult('edit', false, $item.": ".ext_Lang::err('fileexist' ));
}
if(!get_show_item($dir, $item)) {
ext_Result::sendResult('edit', false, $item.": ".ext_Lang::err('accessfile' ));
}
if(isset($GLOBALS['__POST']["dosave"]) && $GLOBALS['__POST']["dosave"]=="yes") {
// Save / Save As
$item=basename(stripslashes($GLOBALS['__POST']["fname"]));
$fname2=get_abs_item($dir, $item);
if(!isset($item) || $item=="") {
ext_Result::sendResult('edit', false, ext_Lang::err('miscnoname' ));
}
if($fname!=$fname2 && @$GLOBALS['ext_File']->file_exists($fname2)) {
ext_Result::sendResult('edit', false, $item.": ".ext_Lang::err('itemdoesexist' ));
}
$this->savefile($fname2);
$fname=$fname2;
ext_Result::sendResult('edit', true, ext_Lang::msg('savefile').': '.$item );
}
// header
$s_item=get_rel_item($dir,$item); if(strlen($s_item)>50) $s_item="...".substr($s_item,-47);
$s_info = pathinfo( $s_item );
$s_extension = str_replace('.', '', $s_info['extension'] );
switch (strtolower($s_extension)) {
case 'txt':
$cp_lang = 'text'; break;
case 'cs':
$cp_lang = 'csharp'; break;
case 'css':
$cp_lang = 'css'; break;
case 'html':
case 'htm':
case 'xml':
case 'xhtml':
$cp_lang = 'html'; break;
case 'java':
$cp_lang = 'java'; break;
case 'js':
$cp_lang = 'javascript'; break;
case 'pl':
$cp_lang = 'perl'; break;
case 'ruby':
$cp_lang = 'ruby'; break;
case 'sql':
$cp_lang = 'sql'; break;
case 'vb':
case 'vbs':
$cp_lang = 'vbscript'; break;
case 'php':
$cp_lang = 'php'; break;
default:
$cp_lang = 'generic';
}
?>
<div style="width:auto;">
<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>
<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">
<h3 style="margin-bottom:5px;"><?php
echo $GLOBALS["messages"]["actedit"].": /".$s_item .' ';
?></h3>
<div id="adminForm">
</div>
</div></div></div>
<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>
</div>
<?php
// Show File In TextArea
$content = $GLOBALS['ext_File']->file_get_contents( $fname );
if( get_magic_quotes_runtime()) {
$content = stripslashes( $content );
}
//$content = htmlspecialchars( $content );
?><script type="text/javascript">//<!--
dialog.setContentSize( 700, 500 );
simple = new Ext.form.Form({
labelAlign: 'top',
url:'<?php echo basename( $GLOBALS['script_name']) ?>'
});
simple.add(
new Ext.form.TextArea({
fieldLabel: 'File Contents',
name: 'thecode',
id: 'ext_codefield',
fieldClass: 'x-form-field',
value: '<?php echo str_replace(Array("\r", "\n", '<', '>'), Array('\r', '\n', '<', '>') , addslashes($content)) ?>',
width: '100%',
height: 300
})
);
simple.column( {width: 250 },
new Ext.form.TextField({
fieldLabel: '<?php echo ext_Lang::msg('copyfile', true ) ?>',
name: 'fname',
value: '<?php echo $item ?>',
width:175
})
);
simple.column( {width: 250, style:'margin-left:10px', clear:true },
new Ext.form.Checkbox({
fieldLabel: '<?php echo ext_Lang::msg('returndir', true ) ?>',
name: 'return_to_dir',
width:175
})
);
simple.addButton('<?php echo ext_Lang::msg('btnsave', true ) ?>', function() {
statusBarMessage( '<?php echo ext_Lang::msg('save_processing', true ) ?>', true );
simple.submit({
//waitMsg: 'Processing Data, please wait...',
//reset: true,
reset: false,
success: function(form, action) {
datastore.reload();
statusBarMessage( action.result.message, false, true );
if( simple.findField('return_to_dir').getValue() ) {
dialog.destroy();
}
},
failure: function(form, action) {
statusBarMessage( action.result.error, false, false );
Ext.MessageBox.alert('<?php echo ext_Lang::err('error', true) ?>!', action.result.error);
},
scope: simple,
// add some vars to the request, similar to hidden fields
params: {option: 'com_extplorer',
action: 'edit',
code: editAreaLoader.getValue("ext_codefield"),
dir: '<?php echo stripslashes($dir) ?>',
item: '<?php echo stripslashes($item) ?>',
dosave: 'yes'
}
});
});
simple.addButton('<?php echo ext_Lang::msg('btnclose', true ) ?>', function() { dialog.destroy(); } );
simple.render('adminForm');
simple.findField('thecode').setValue(simple.findField( 'thecode').getValue().replace( />/g, '>').replace( /</g, '<'));
editAreaLoader.baseURL = "<?php echo _EXT_URL ?>/scripts/editarea/";
editAreaLoader.init({
id : "ext_codefield" // textarea id
,syntax: "<?php echo $cp_lang ?>" // syntax to be uses for highgliting
,start_highlight: true // to display with highlight mode on start-up
,display: "later"
});
editAreaLoader.start("ext_codefield");
// -->
</script><?php
}
function savefile($file_name) { // save edited file
if( get_magic_quotes_gpc() ) {
$code = stripslashes($GLOBALS['__POST']["code"]);
}
else {
$code = $GLOBALS['__POST']["code"];
}
$res = $GLOBALS['ext_File']->file_put_contents( $file_name, $code );
if( $res==false || PEAR::isError( $res )) {
$err = basename($file_name).": ".ext_Lang::err('savefile' );
if( PEAR::isError( $res ) ) {
$err .= $res->getMessage();
}
ext_Result::sendResult( 'edit', false, $err );
}
}
}
//------------------------------------------------------------------------------
?>
That is the code from the eXtplorers edit page Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Full featured example</title>
<!-- TinyMCE -->
<script type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "safari,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",
// 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",
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/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
<!-- /TinyMCE -->
</head>
<body>
<form method="post" action="http://tinymce.moxiecode.com/dump.php?example=true">
<div>
<h3>Full featured example</h3>
<p>
This page shows all available buttons and plugins that are included in the TinyMCE core package.
There are more examples on how to use TinyMCE in the <a href="http://wiki.moxiecode.com/examples/tinymce/">Wiki</a>.
</p>
<!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded -->
<div>
<textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%">
<p>
This is some example text that you can edit inside the <strong>TinyMCE editor</strong>.
</p>
<p>
Nam nisi elit, cursus in rhoncus sit amet, pulvinar laoreet leo. Nam sed lectus quam, ut sagittis tellus. Quisque dignissim mauris a augue rutrum tempor. Donec vitae purus nec massa vestibulum ornare sit amet id tellus. Nunc quam mauris, fermentum nec lacinia eget, sollicitudin nec ante. Aliquam molestie volutpat dapibus. Nunc interdum viverra sodales. Morbi laoreet pulvinar gravida. Quisque ut turpis sagittis nunc accumsan vehicula. Duis elementum congue ultrices. Cras faucibus feugiat arcu quis lacinia. In hac habitasse platea dictumst. Pellentesque fermentum magna sit amet tellus varius ullamcorper. Vestibulum at urna augue, eget varius neque. Fusce facilisis venenatis dapibus. Integer non sem at arcu euismod tempor nec sed nisl. Morbi ultricies, mauris ut ultricies adipiscing, felis odio condimentum massa, et luctus est nunc nec eros.
</p>
</textarea>
</div>
<!-- Some integration calls -->
<a href="javascript:;" onmousedown="tinyMCE.get('elm1').show();">[Show]</a>
<a href="javascript:;" onmousedown="tinyMCE.get('elm1').hide();">[Hide]</a>
<a href="javascript:;" onmousedown="tinyMCE.get('elm1').execCommand('Bold');">[Bold]</a>
<a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').getContent());">[Get contents]</a>
<a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').selection.getContent());">[Get selected HTML]</a>
<a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').selection.getContent({format : 'text'}));">[Get selected text]</a>
<a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').selection.getNode().nodeName);">[Get selected element]</a>
<a href="javascript:;" onmousedown="tinyMCE.execCommand('mceInsertContent',false,'<b>Hello world!!</b>');">[Insert HTML]</a>
<a href="javascript:;" onmousedown="tinyMCE.execCommand('mceReplaceContent',false,'<b>{$selection}</b>');">[Replace selection]</a>
<br />
<input type="submit" name="save" value="Submit" />
<input type="reset" name="reset" value="Reset" />
</div>
</form>
</body>
</html>
This is an example code from tiny MCE
Bookmarks