Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Poor_Knight on August 07, 2008, 06:29:12 PM

Title: The SMF Text Editor
Post by: Poor_Knight on August 07, 2008, 06:29:12 PM
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?
Title: Re: The SMF Text Editor
Post by: niko on August 08, 2008, 05:53:44 AM
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).
Title: Re: The SMF Text Editor
Post by: Poor_Knight on August 10, 2008, 04:46:18 PM
Awesome - I'll give this a whirl.
Thanks for the thorough reply!
Title: Re: The SMF Text Editor
Post by: 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?
Title: Re: The SMF Text Editor
Post by: ccbtimewiz on August 11, 2008, 10:30:47 PM
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.
Title: Re: The SMF Text Editor
Post by: metallica48423 on August 15, 2008, 03:11:04 AM
I'm having one minor issue with this... and that is, i'm getting a javascript error.

"SmfEditor is not defined"
Title: Re: The SMF Text Editor
Post by: Dragooon on August 15, 2008, 03:23:04 AM
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']
Title: Re: The SMF Text Editor
Post by: metallica48423 on August 15, 2008, 03:36:01 AM
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 :)
Title: Re: The SMF Text Editor
Post by: Deprecated on August 15, 2008, 06:58:51 PM
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.
Title: Re: The SMF Text Editor
Post by: 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 ?
Title: Re: The SMF Text Editor
Post by: niko on December 09, 2008, 04:02:56 AM
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.
Title: Re: The SMF Text Editor
Post by: asmith on December 09, 2008, 04:47:25 AM
Should I start a new thread about it for SMF 1.1.7 ?

It must be possible to have the editor in  SSI pages.
Title: Re: The SMF Text Editor
Post by: 青山 素子 on December 09, 2008, 11:51:41 AM
You can have the editor, but it'll show as plain text. The SMF 1.1 series does not support graphical editing (WYSIWYG).
Title: Re: The SMF Text Editor
Post by: asmith on December 09, 2008, 02:28:32 PM
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?
Title: Re: The SMF Text Editor
Post by: [SiNaN] on December 11, 2008, 04:17:56 PM
Plain text is that you mean.

You can check the codes of this (http://custom.simplemachines.org/mods/index.php?mod=1275) mod to see how you can use the SMF editor outside the post areas.
Title: Re: The SMF Text Editor
Post by: metallica48423 on December 13, 2008, 07:26:00 PM
This works pretty well -- I've been unsuccessful thusfar however in getting this to work with multiple instances on one page.

/me goes back to the grind :)
Title: Re: The SMF Text Editor
Post by: [SiNaN] on December 15, 2008, 12:51:13 AM
theme_postbox() should be working when you change $context['post_box_name'] every time before you use it.
Title: Re: The SMF Text Editor
Post by: metallica48423 on December 15, 2008, 01:14:12 AM
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. 
Title: Re: The SMF Text Editor
Post by: Tyrsson on December 15, 2008, 01:48:12 AM
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?
Title: Re: The SMF Text Editor
Post by: metallica48423 on December 15, 2008, 02:06:08 AM
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
Title: Re: The SMF Text Editor
Post by: inter on July 06, 2011, 05:52:09 AM
Thanks for the helpful information, Niko  :)