How to integrate wysiwyg in your module
Post new topic   Reply to topic   Printer Friendly Page     Forum IndexExplain Please
Author Message
DJ Maze
Developer


Joined: Apr 19, 2004
Posts: 5668
Location: http://tinyurl.com/5z8dmv

PostPost subject: How to integrate wysiwyg in your module
Posted: Wed Sep 28, 2005 12:50 am
Reply with quote

We've noticed a lot of people don't know how to integrate wysiwyg into their modules.
One of the reasons we don't provide much detail is that it could harm your website more then actualy make it cooler.

WARNING: The wysiwyg editors DON'T check the input (posted data) on any malicious code so it would be easy to generate a XSS exploit.

However if you still want to use it here's an example module index.php
PHP:
<?php
/**
* CPG Dragonfly CMS
* Copyright (c) 2004-2005 by CPG-Nuke Dev Team, www.dragonflycms.com
* Released under the GNU GPL version 2 or any later version
* $Id: index.php,v 1.2 2005/02/13 23:53:06 trevor Exp $
*/

# protect against direct access
if (!defined('CPG_NUKE')) { exit; }

# load the wysiwyg system
require(CORE_PATH.'wysiwyg/wysiwyg.inc');

# initiate an wysiwyg instance for a <textarea>
$wysiwyg = new Wysiwyg('form_name', 'area1', '100%', '400px', '<h1>Area 1</h1>');

# initiate another wysiwyg instance for a <textarea>
$wysiwyg2 = new Wysiwyg('form_name', 'area2', '100%', '400px', 'some text in <b>area 2</b>');

# set the wysiwyg headers that are needed for header.php
# You only have to call it once, so no need for $wysiwyg2
$wysiwyg->setHeader();

# initiate the page title
$pagetitle .= 'WYSIWYG Example';

# Now you include the header to start the page
require_once('header.php');

# start a new table in which we will show some text
OpenTable();

# Open a <form>
echo open_form(getlink(), 'form_name', 'The Wysiwyg Example');

# Output the Wysiwyg selector
echo $wysiwyg->getSelect().'<br /><br />';

# Output the Wysiwyg <textarea>
echo $wysiwyg->getHTML().'<br /><br />';

# Output the other Wysiwyg <textarea>
echo $wysiwyg2->getHTML().'<br /><br />';

# close the form
echo '<input type="submit" name="preview" value="Preview">'.close_form();

# close the table that we have created
CloseTable();


DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Fedora 12 / 2.2.15 / 5.1.47 / 5.3.3 / CVS
Back to top
View user's profile Visit poster's website Yahoo Messenger
DJ Maze
Developer


Joined: Apr 19, 2004
Posts: 5668
Location: http://tinyurl.com/5z8dmv

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Wed Sep 28, 2005 12:44 pm
Reply with quote

You need to get one or more wysiwyg editors first
dragonflycms.org/cvs/wysiwyg/

And upload the folder to /includes/wysiwyg/


DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Fedora 12 / 2.2.15 / 5.1.47 / 5.3.3 / CVS
Back to top
View user's profile Visit poster's website Yahoo Messenger
Kendle
500+ Posts Club


Joined: Dec 16, 2004
Posts: 529

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Thu Sep 29, 2005 11:49 am
Reply with quote

The wysiwyg Class has changed (includes/wysiwyg/wysiwyg.inc). Once upon a time you would pass the name of the editor you wished to use to the Class constructor, now the user's preferred choice is stored in the session variable and the constructor no longer accepts the editor name.

This has broken WYSIWYG functionality in my mKnow module.

I need to know at which version of DragonFly it changed so I can allow for it in my code.

edit: I've answered my own question, it was 9.0.4.0, damned annoying though as it means a fair bit of re-coding required now. I'll have to update the session variable because I can't use the new method of adding a selector to the input form (changing editor means submitting the form)


Kendle's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
mc__
Debugger


Joined: Jul 12, 2005
Posts: 451
Location: QLD, Australia

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Thu Sep 29, 2005 12:53 pm
Reply with quote

thankyou DJmaze for this post and the advice. its appreciated.
_________________


mc__'s server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux (Kernel: 2.4.21-27.0.2.ELsmp)/1.3.33 (Unix)/4.0.24-standard/4.3.11/9.0.5.0
Back to top
View user's profile Visit poster's website MSN Messenger
RedGerry
Silver Supporter


Joined: Jun 29, 2004
Posts: 448
Location: Alloa, Scotland

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Thu Sep 29, 2005 2:35 pm
Reply with quote

Yes cheers.. I have the functionality built in to my RG_Sports module but it stopped working. On my todo list to fix. This info will make the job a lot easier.

After the data is posted I'm passing it through Fix_Quotes prior to inserting into DB. Would you recommend anything else to protect against vulnerabilities?

My members can post match reports after games are complete and they do this regularly, it adds good content to my site. I MUST give them WYSIWYG as these reports end up as huge lumps of text otherwise.

example: www.scottishwomensfoot...=2820.html

_________________
gerry @ redgerry.com
redgerry.com - Home of RG_Sports
scottishwomensfootball.co.uk
scottishjuniorfootball.co.uk

RedGerry's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Suse9.3/Apache2.6.8-24.14/MySQL4.0.21Max/PHP4.3.8/CVS on Athlon64
Back to top
View user's profile Visit poster's website ICQ Number MSN Messenger
DJ Maze
Developer


Joined: Apr 19, 2004
Posts: 5668
Location: http://tinyurl.com/5z8dmv

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Thu Sep 29, 2005 3:23 pm
Reply with quote

Fix_Quotes() will not prevent anyone for using <script> and "on<task>" which are javascript commands.
I'm building such XSS prevention functions to strip all javascript functionality.
I will post my test functions here so you all can try.

NOTE: this code is highly untested so please report issues or extension in here.

Code:
function strip_javascript($text, $events=true)
{
	$patterns = array(
			'/<\s*script[^>]*?>.*?<\/\s*script\s*>/i',
			'/href\s*=\s*\'\s*javascript.*\'/i',
			'/href\s*=\s*"\s*javascript.*"/i'
	);
	$replace = array('','','');
	if ($events) {
		$patterns[] = '/(<.*?)on[\w]+\s*=[^<>]*?>/i';
		$replace[] = '\\1>';
	}
	return preg_replace($patterns,$replace,$text);
}

function strip_tags($text, $tables=false, $lists=false, $fonts=false,
	$phrase=false, $blocks=false, $group=false, $misc=false,
	$image=false, $media=true, $forms=true)
{
	$allowed_tags = '<a><br><center><hr><p>';
	if (!$tables) { $allowed_tags .= '<caption><multicol><table><tbody><col><colgroup><td><tfoot><thead><th><tr>'; }
	if (!$lists)  { $allowed_tags .= '<dl><dt><dd><dir><menu><li><ol><ul>'; }
	if (!$fonts)  { $allowed_tags .= '<font><sub><sup><big><b><i><small><s><strike><tt><u>'; }
	if (!$phrase) { $allowed_tags .= '<cite><code><dfn><em><kbd><samp><strong><var><abbr><acronym>'; }
	if (!$blocks) { $allowed_tags .= '<blockquote><h><plaintext><pre>'; }
	if (!$group)  { $allowed_tags .= '<div><span><fieldset><legend>'; }
	if (!$misc)   { $allowed_tags .= '<nobr><spacer><wbr>'; }
	if (!$image)  { $allowed_tags .= '<img><map><area>'; }
	if (!$media)  { $allowed_tags .= '<applet><object><param><embed><marquee>'; }
	if (!$forms)  { $allowed_tags .= '<form><input><select><option><optgroup><textarea><button>'; }
	return strip_tags($text, $allowable_tags);
}


DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Fedora 12 / 2.2.15 / 5.1.47 / 5.3.3 / CVS
Back to top
View user's profile Visit poster's website Yahoo Messenger
mc__
Debugger


Joined: Jul 12, 2005
Posts: 451
Location: QLD, Australia

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Fri Sep 30, 2005 3:55 am
Reply with quote

why dont you all take a look at this: pixel-apes.com/downloa...ripped.zip

which comes from pixel-apes.com/safehtml#h248-2

EDIT: I propose that this be integrated into dragonfly's core. It is very helpful function and doesn't add much to the overall distro size (about 80kb uncompressed in total), and additionally it is released under the BSD license.

Seems like a helpfull little fucntion to have, very good for a cms that's all about security. This way module developer's don't even need to come up with their own parser's whcih could contain fatal flaws etc. Good idea?

the usage example is like so:
PHP:
$parser =& new SafeHTML();
$result = $parser->parse($doc);
pretty simple.

_________________


mc__'s server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux (Kernel: 2.4.21-27.0.2.ELsmp)/1.3.33 (Unix)/4.0.24-standard/4.3.11/9.0.5.0
Back to top
View user's profile Visit poster's website MSN Messenger
DJ Maze
Developer


Joined: Apr 19, 2004
Posts: 5668
Location: http://tinyurl.com/5z8dmv

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Mon Oct 03, 2005 3:28 am
Reply with quote

Thanks mc__ i will look into that code.

DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Fedora 12 / 2.2.15 / 5.1.47 / 5.3.3 / CVS
Back to top
View user's profile Visit poster's website Yahoo Messenger
rosbif
500+ Posts Club


Joined: Jan 13, 2005
Posts: 571
Location: Paris, France

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Fri Feb 03, 2006 8:30 am
Reply with quote

DJMaze,

Did anything come of this?


rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.2.11/5.0.77/5.2.8/9.2.1
Back to top
View user's profile Visit poster's website
HEairsoft
Nice poster


Joined: Jul 26, 2005
Posts: 58

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Sun Jun 11, 2006 6:03 pm
Reply with quote

PHP:
$wysiwyg->getSelect();
Is there any way to display the wysiwyg editor by default without using this select box?

Kendle wrote:
I'll have to update the session variable because I can't use the new method of adding a selector to the input form (changing editor means submitting the form)
Were you able to fix this? I am having the same problem and I will have to rely on the select box if there is no way to default the editor to wysiwyg.


HEairsoft's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/1.3.33/4.0.27/4.4.4/9.1.1
Back to top
View user's profile Visit poster's website
Kendle
500+ Posts Club


Joined: Dec 16, 2004
Posts: 529

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Fri Jun 16, 2006 8:34 pm
Reply with quote

If you want to enforce a particular WYSIWYG editor you'll have to manipulate the user's session variable, like so:-

PHP:

if (CPG_NUKE > '9.0.3.0') {
global
$CPG_SESS;
$CPG_SESS['wysiwyg'] = 'EditorName';
}

Note: the check for version number is because it was at 9.0.3.0 that the WYSIWYG class changed. If that's not relevant to your application then remove it, obviously.

If you are writing something that users of versions prior to 9.0.3.0 might want you'll also need to adjust the call to the WYSIWYG class as the parameters changed:-

<= 9.0.3.0

PHP:

$wysiwyg
= new Wysiwyg('EditorName', 'FieldName', 'width', 'height', $fieldvariable);

> 9.0.3.0

PHP:

$wysiwyg
= new Wysiwyg('FormName', 'FieldName', 'width', 'height', $fieldvariable);

_________________
Gaming League / Cup - www.leaguecms.co.uk :: Other DragonFly modules - www.cmsdreams.co.uk

Kendle's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
HEairsoft
Nice poster


Joined: Jul 26, 2005
Posts: 58

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Fri Jun 16, 2006 8:51 pm
Reply with quote

Alright cool, thanks Kendle Razz

HEairsoft's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/1.3.33/4.0.27/4.4.4/9.1.1
Back to top
View user's profile Visit poster's website
DJ Maze
Developer


Joined: Apr 19, 2004
Posts: 5668
Location: http://tinyurl.com/5z8dmv

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Fri Jun 23, 2006 10:30 pm
Reply with quote

mc__ wrote:
why dont you all take a look at this: pixel-apes.com/downloa...ripped.zip

which comes from pixel-apes.com/safehtml#h248-2

EDIT: I propose that this be integrated into dragonfly's core. It is very helpful function and doesn't add much to the overall distro size (about 80kb uncompressed in total), and additionally it is released under the BSD license.

Not possible, can't mix GPL and BSD in one package.
It works nicely though.


DJ Maze's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Fedora 12 / 2.2.15 / 5.1.47 / 5.3.3 / CVS
Back to top
View user's profile Visit poster's website Yahoo Messenger
harbrum
Heavy poster


Joined: May 19, 2004
Posts: 155
Location: Drachten, Nederland

PostPost subject: Re: How to integrate wysiwyg in your module
Posted: Sat Jul 29, 2006 4:34 am
Reply with quote

I cannot browse or download images with a wysisyg browser.
Could it be caused by a .htaccess file?

_________________
Wonder is the beginning of all wisdom.
Verwondering is het begin van alle wijsheid.

harbrum's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Windows xp/Apache 2.0/mysql 5.0.51a (client: 5.0.51a) php 5.2.5/ CPGNuke 9.2.1
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   Printer Friendly Page     Forum IndexExplain Please All times are GMT
Page 1 of 1


Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

stopsoftwarepatents.eu petition banner
User Info [x]

Welcome Anonymous

Nickname
Password
(Register)

Last CVS commits [x]

Languages [x]

Community [x]

Support for DragonflyCMS in a other languages:

Deutsch
Español

X-links [x]
UltraEdit Browse Happy logo Firefox MySQL PostgreSQL Valid CSS! Valid XHTML 1.0! Unicode Encoded Badge NukeBiz Resources Raven DragonflyCMS Dedicated Now InsideSupport Lampe Berger

Preview theme [x]
Each user can view the site with a different theme.
Themes marked with a * also change the forum look.


You are seeing squares or questionmarks on this page?

All content of this website is copyrighted by the Creative Commons NC-SA
The logos and trademarks used on this site are the property of their respective owners
We are not responsible for comments posted by our users, as they are the property of the poster.
Our server runs on a P3 1.2GHz with 512MB RAM with no accelerators
Support GoPHP5.org
This page generated in 1.6211 seconds with 16 DB Queries in 0.0915 seconds
Memory Usage: 3.05 MB
Interactive software released under GNU GPL, Code Credits, Privacy Policy