News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

The SMF Text Editor

Started by Poor_Knight, August 07, 2008, 06:29:12 PM

Previous topic - Next topic

Poor_Knight

I've been using SSI to do some stuff on a web site and I'm curious to know if its possible to load the SMF text editor and use its functions outside of the SMF forum. I have the forum running on a subdomain and a site that uses the forum users on the main domain. Some form areas use a WYSIWYG editor but I'd like to keep the consistency of the text editor on the forum.

Is this possible?
"Life moves pretty fast. If you don't stop and look around once in a while, you could miss it."
~Ferris Bueller

niko

Yes it's possible.

There is function "create_control_richedit" in Subs-Editor.php

Initializing:

	
require_once(
$sourcedir '/Subs-Editor.php');

	
$context['post_box_name'] = 'details';

	
$editorOptions = array(
	
	
'id' => $context['post_box_name'],
	
	
'value' => 'Default text'// BBC coded not html
	
	
'labels' => array(
	
	
	
'post_button' => 'Post',
	
	
),
	
);
	
create_control_richedit($editorOptions);


HTML Output: (template)

global $context;

// FORM Code (example)
echo '
	
<form action="URL" method="post" accept-charset="'
$context['character_set'], '" name="testform" id="testform" onsubmit="submitonce(this);" enctype="multipart/form-data">';

// BBC
template_control_richedit($context['post_box_name'], 'bbc');
// Smileys
template_control_richedit($context['post_box_name'], 'smileys');
// Buttons (submit, preview)
template_control_richedit($context['post_box_name'], 'buttons');


HTML To BBC (used before saving)

	
if (!empty(
$_REQUEST['details_mode']) && isset($_REQUEST['details']))
	
{
	
	
require_once(
$sourcedir '/Subs-Editor.php');

	
	
$_REQUEST['details'] = html_to_bbc($_REQUEST['details']);
	
	
$_REQUEST['details'] = un_htmlspecialchars($_REQUEST['details']);
	
	
$_POST['details'] = $_REQUEST['details'];
	
}


After that $_REQUEST['details'] would be BBC code.

(every instance of "details" is post box name as defined in first code).
Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

Poor_Knight

Awesome - I'll give this a whirl.
Thanks for the thorough reply!
"Life moves pretty fast. If you don't stop and look around once in a while, you could miss it."
~Ferris Bueller

pokepoke

Does this only apply to v2? If so, how can this be done in 1.1.5?

ccbtimewiz

Quote from: pokepoke on August 11, 2008, 09:28:24 PM
Does this only apply to v2? If so, how can this be done in 1.1.5?

SMF 1.1.5 doesn't have a WYSIWYG editor. Thus this code would not work.

metallica48423

I'm having one minor issue with this... and that is, i'm getting a javascript error.

"SmfEditor is not defined"
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Dragooon

Actually in sources it does a $context['html_headers'] .= to add the script call so that index.template includes the JS for editor.
You'd need to divide your script into template and source then in template you'd need to echo $context['html_headers']

metallica48423

or i can just include the editor.js.. ;) it works.

Its not clean, per-se.  But it will work until i can launch my site revision and clean things up :)
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Deprecated

I'm trying to understand if I can apply this concept to add the WYSIWYG to a modification I'm developing. I hope I can get some feedback as to whether it's practical.

Long story short my modification requires a large text field that must be configured. I have a tab installed in the Admin -> Configuration -> Modifications page, right next to Miscellaneous. Currently I am using a 'large text' in the $config_vars array in my modification routine in ManageSettings.php. This works fine, and as far as I can tell my mod is done if I'm willing to settle for no WYSIWYG. Of course the text contains BB codes or I wouldn't be needing the WYSIWYG. Honestly, I got my mod working without understanding how the Modify ..... Settings() functions work, by just hacking away at other similar routines until I got it working. I don't see how I can modify my routine in ManageSettings.php to add the WYSIWYG.

So how practical is this? Perhaps I'll post some of my code if y'all tell me it's practical, but I think I should start a new thread to keep the present one on topic.

asmith

Will it work on SMF 1.1.7 ?

If I use the instructions on second post, Can I get it to work on SMF 1.1.7?  I have some non-forum pages, SSI and SMF javascript file included, Can use smf text editor on my own textarea?
Can someone sum it up please ?

niko

Quote from: asmith on December 09, 2008, 03:41:18 AM
Will it work on SMF 1.1.7 ?

If I use the instructions on second post, Can I get it to work on SMF 1.1.7?  I have some non-forum pages, SSI and SMF javascript file included, Can use smf text editor on my own textarea?
Can someone sum it up please ?

No, SMF 2.0 is required.
Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

asmith

Should I start a new thread about it for SMF 1.1.7 ?

It must be possible to have the editor in  SSI pages.

青山 素子

You can have the editor, but it'll show as plain text. The SMF 1.1 series does not support graphical editing (WYSIWYG).
Motoko-chan
Director, Simple Machines

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.


asmith

hmmm sorry didn't get you.

How it would show plain text?
To make myself more clear, I mean this editor we see on the top of textarea which is actually bb code editor.  when click on B in put [ b ] tags around it ...

What is plain text here?

[SiNaN]

Plain text is that you mean.

You can check the codes of this mod to see how you can use the SMF editor outside the post areas.
Former SMF Core Developer | My Mods | SimplePortal

metallica48423

This works pretty well -- I've been unsuccessful thusfar however in getting this to work with multiple instances on one page.

* metallica48423 goes back to the grind :)
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

[SiNaN]

theme_postbox() should be working when you change $context['post_box_name'] every time before you use it.
Former SMF Core Developer | My Mods | SimplePortal

metallica48423

This is what i've got going on.  I'm basically trying to have multiple instances of the editor as part of a post form for multi-page articles. 

In my source file i have it being set up like so:
                // We need the Editor source file...
                require_once($sourcedir . '/Subs-Editor.php');

                // The Number of Pages from $_POST
                $pages = (int) $_POST['pages'];

                //!!! This should PROBABLY not just die, but rather inform the user that their input is invalid.
                // If it wasn't a number, die right here and now.
                if (empty($pages))
                        die;

                // Create the editor for each page number.
                for($i=1;$i<=$pages;$i++)
                {

                        // Name SHOULD be Page#
                        $box_name = 'Page' . $i;

                        // We have the editor options! Which really aren't optional if we want this thing to work.
                        $editorOptions = array(
                                'id' => $box_name,
                                'rows' => 7,
                                'columns' => 120,
                                'width' => '99%',
                                'value' => 'Page ' . $i . ' text goes here',
                                'labels' => array(
                                        'post_button' => 'Post',
                                ),
                        );

                        create_control_richedit($editorOptions);
                }

                loadSiteTemplate();


The loadSiteTemplate is one of my own functions which calls the actual template.  What's going on in here is basically another for loop for the number of pages the user specifies, which calls these two functions:


                template_control_richedit('Page' . $i, 'bbc');
                template_control_richedit('Page' . $i, 'message');


I think i can see a flaw in the logic though in that the $editorOptions is overwritten for each loop of the source for loop, which is finished before the template loop can even begin. 
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Tyrsson

Is there a Php college that teaches this or have you all just figured this stuff out on your own?

Php college lol....

Seriously though.... Is there a school that teaches this?
PM at your own risk, some I answer, if they are interesting, some I ignore.

metallica48423

There are colleges which teach PHP and whatnot, yes.  I've done most of my learning by reading books, reading these forums, and messing with SMF :P.

Anyhow... I think, rather than do it this way, that i'm going to revise the logic behind the application.  I have an idea how i can make this user friendly without needing to display all 1-5 page editors at once.  Looking deeper at this, it really isn't designed for multiple uses on a single page, and i can forsee more issues with doing it this way

It was an interesting exercise with for loops and whatnot though :P
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Advertisement: