[[php_dhtml:exemple4]]
 
Table of Contents

Exemple 4 - Wiki editor

This one use the winApp class with some kind of Office XP look & feel.

It needs:

Result

Code

<?
/**
 * php_dhtml
 * Copyright (C) 2004  Eric Colinet <e.colinet@laposte.net>
 * http://wildphp.free.fr
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
 
include 'dhtml/winApp.inc';
include './wiki2xhtml/class.wiki2xhtml.php';
 
//$GLOBALS['WINAPP_RC_PATH']=  '../rc/winapp_classic/';
$GLOBALS['WINAPP_RC_PATH']=  '../rc/winapp_xp/';
 
 
class EditorApp extends winApp {
	var $preview;
	var $filename;
	var $ie; // Ie com handle
	var $title= 'Wiki2XHtml Editor';
 
	function EditorApp() {
		$this->preview= &new Preview;
		parent::winApp($this->title);
	}
 
	function on_init() {
		$this->toolbar->add_button( 
			'file', 'File', 'buttons/new.png', 
			array(
				'file_new' => 'New',
				'file_open' => 'Open',
 
				'file_save' => 'Save',
				'file_save_as' => 'Save As ...',
				'-',
				'file_quit' => 'Quit',
				)
			);
		$this->toolbar->add_button( 'preview', 'Preview' );
		$this->toolbar->add_button( 'publish', 'Publish' );
		$this->toolbar->add_button( 'help', '', 'buttons/help.png',
				array(
					'help_wiki2xhtml' => 'Wiki2XHtml exemples',
					'-',
					'help_about' => 'About',
					'help_about_php' => 'About Php'
				)
			);
 
		// Timer for auto-refresh the preview (annoying !)
		//$this->set_timer(1, 10000);
	}	
 
	function on_page_load($url) {
		parent::on_page_load($url);
		$html= '<textarea id="edit" style="width:100%; height:100%; border: none"></textarea>';
		$this->id_html('window_frame', $html);
	}
	
	function close() {
		$this->preview->close();
		parent::close(); 
	}
 
	function on_timer($id) {
		if( $id==1 ) {
			$this->preview->text= $this->id_value('edit');
			$this->preview->refresh();
		}
	}
 
	function on_command_publish() {
		$this->warning("Publish is not implemented !\nThey are still work to do here :-)");
	}
 
	function on_command_preview() {
		$this->preview->text= $this->id_value('edit');
		$this->preview->refresh();
		$this->preview->show();
		$this->set_status('Preview');
	}
 
	function on_command_file_new() {
		$this->id_value('edit', '');
		$this->filename= '';
		$this->preview->text= '';
		$this->preview->refresh();
		$this->set_status('New file');
	}
 
	function on_command_file_open() {
		if( !function_exists('win_browse_file') ) {
			$this->warning("You don't have win32std installed.");
			return;
		}
 
		$filename= win_browse_file(true, '.');
		if( !$filename ) {
			$this->set_status('Open canceled');
			return;
		}
 
		$txt= file_get_contents($filename);
		if( $txt===false ) {
			$this->warning("Can't open ".$this->filename);
			return;
		}
 
		$this->filename= $filename;
		$this->id_value('edit', $txt);
		$this->preview->text= $txt;
		$this->preview->refresh();
 
		$this->set_status("Opened '{$this->filename}'");
		$this->set_title($this->title." - ".$this->filename);
	}
	
	function on_command_file_save_as() {
		if( !function_exists('win_browse_file') ) return $this->warning("You don't have win32std installed.");
 
		$filename= win_browse_file(false);
		if( !$filename ) {
			$this->set_status('Save canceled');
			return;
		}
		$this->filename= $filename;
		$this->save();
	}
 
	function on_command_file_save() {
		if( !$this->filename ) return $this->on_command_file_save_as();
		$this->save();
	}
 
	function save() {
		$txt= $this->id_value('edit');
		if( !$txt ) return $this->warning('Nothing to save');
 
		$f= fopen($this->filename, 'wb');
		if( $f ) {
			fwrite($f, $txt);
			fclose($f);
			$this->set_title($this->title." - ".$this->filename);
			$this->set_status("Saved to '{$this->filename}'");
			return;
		}
 
		$this->warning("Unable to open '{$this->filename}'");
	}
 
	function on_request($url) {
		if( ereg('^http(s)?://', $url) ) {
			$this->browse_url($url);
			return true;
		}
	}
 
	function warning($txt) {
		if( !function_exists('win_message_box') )
			win_message_box($txt);
		else new MessageBox($this, nl2br($txt), "Weird !");
		$this->set_warning($txt);
	}
 
	function on_command_file_quit() { 
		$this->close();
	}
	
	function on_command_help_about() {
		$this->set_status('About');
		new MessageBox($this, "<H4>Wiki2XHtml App</h4>", "Wiki2XHtml App");
	}
	
	function on_command_help_about_php() {
		$this->set_status('About PHP');
		about_php($this);
	}
 
	function on_command_help_wiki2xhtml($url) {
		$this->browse_url('http://www.neokraft.net/sottises/wiki2xhtml/demo.html');
	}
 
 
	function browse_url($url) {
		$this->set_status('Navigate to: '.$url);
		if( function_exists('win_shell_execute') )
			win_shell_execute($url); // Default browser is used
		else {
			if( $this->ie && $this->ie->Navigate($url) ) return;
			$this->ie = new COM("InternetExplorer.Application");
			$this->ie->Visible = true;
			$this->ie->Navigate($url); 
		}
	}
 
}
 
class Preview extends dhtml {
 
	var $text;
	
	function Preview() { 
		parent::dhtml('Wiki2XHtml preview', false, false); 
		$this->set_scrollbar();
	}
 
	function on_init() {
		$this->load_default();
	}	
 
	function on_page_load($url) {
		$html= '<table width="100%" height="100%" border="0"><tr><td id="content" valign="top" style="border: 1px solid black">&nbsp;</td></tr><tr><td height="20px" align="center" valign="center"><input type="button" onClick="document.location=\'#close\'" value="Hide"></td></tr></table>';
		$this->id_html('body', $html);
	}
 
	function refresh() {
		if( $this->text ) {
			$obj= new wiki2xhtml;
			$text= $obj->transform($this->text);
		}
		else {
			$text= '<div align="center"><font color="#C0C0C0"><i>No content</i></font></div>';
		}
		$this->id_html('content', $text);
	}
 
	function on_close() {
		$this->hide();
		return 1;
	}
 
	function on_command_reload() {
		$this->refresh();
	}
 
	function on_command_close() {
		$this->hide();
	}
}
 
new EditorApp();
winApp::run();
?>
 
  php_dhtml/exemple4.txt · Last modified: 2005/01/15 19:37
 
Recent changes RSS feed Powered by PHP Driven by DokuWiki