MyBB Community Forums

Full Version: Adding Hooks to js and arrays
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I know that this is a silly question, but there's no help on the web that I can find. Sad

1/. Adding strings into an array: Can it be done with a plug-in?

2/. Adding strings into .js files: Can it be done with a plug-in?

I'd like to know before I start trying something that ain't going to work, and maybe needs to left as a MOD. Big Grin
Lopalong Wrote:1/. Adding strings into an array: Can it be done with a plug-in?
Sorry, don't quite get you.
I'm assuming you're talking about PHP, so this?
$myarray = array('string1', 'string2');
???

Lopalong Wrote:2/. Adding strings into .js files: Can it be done with a plug-in?
Do you mean adding something to a .js file without requiring a code modification? It can't be done, but you can include another .js file.
Yes I know it's a little hard to understand without a verbose explanation, so this will indicate where I want the plug-in to change.

One thing at a time. Because NO to either question, will mean it has to stay a MOD. Wink

functions.php editor array.

I've made in uppercase and "pulled" to the left what I want to slot in there with a plug-in.

Possible or not ?
		$editor_lang_strings = array(
			"editor_title_bold",
			"editor_title_italic",
			"editor_title_underline",
			"editor_title_left",
			"editor_title_center",
			"editor_title_right",
			"editor_title_justify",
			"editor_title_numlist",
			"editor_title_bulletlist",
			"editor_title_image",
			"editor_title_hyperlink",
			"editor_title_email",
			"editor_title_quote",
			"editor_title_code",
			"editor_title_php",
			"editor_title_close_tags",
	"editor_title_FLASH",
	"editor_title_VIDEO",
	"editor_title_STREAM",
	"editor_title_YOUTUBE",
	"editor_title_MARQL",
	"editor_title_MARQU",
	"editor_title_MARQD",
	"editor_title_MARQR",
	"editor_title_STRIKE",
	"editor_title_SUB",
	"editor_title_SUP",
	"editor_title_SPOIL",
	"editor_title_HIGHSLIDE",
			"editor_enter_list_item",
			"editor_enter_url",
			"editor_enter_url_title",
			"editor_enter_email",
			"editor_enter_email_title",
			"editor_enter_image",
			"editor_size_xx_small",
			"editor_size_x_small",
			"editor_size_small",
			"editor_size_medium",
			"editor_size_large",
			"editor_size_x_large",
			"editor_size_xx_large",
			"editor_color_white",
			"editor_color_black",
			"editor_color_red",
			"editor_color_yellow",
			"editor_color_pink",
			"editor_color_green",
			"editor_color_orange",
			"editor_color_purple",
			"editor_color_blue",
			"editor_color_beige",
			"editor_color_brown",
			"editor_color_teal",
			"editor_color_navy",
			"editor_color_maroon",
			"editor_color_limegreen",
			"editor_font",
			"editor_size",
			"editor_color"
		);
editor.js

In between:


// Insert toolbar buttons.

And

// Create text area

I want to REMOVE all of the script and replace it with this code, because a second toolbar has been added, the url's have been changed, and so have the IE width and height parameters to accommodate the second toolbar:

Possible or not ? Wink

// Insert toolbar buttons.
		this.insertStandardButton(formatting, "b", "mycode_box/images/codebuttons/bold.gif", "b", "", this.options.lang.title_bold);
		this.insertStandardButton(formatting, "i", "mycode_box/images/codebuttons/italic.gif", "i", "", this.options.lang.title_italic);
		this.insertStandardButton(formatting, "u", "mycode_box/images/codebuttons/underline.gif", "u", "", this.options.lang.title_underline);
		this.insertSeparator(formatting);
		this.insertStandardButton(formatting, "align_left", "mycode_box/images/codebuttons/align_left.gif", "align", "left", this.options.lang.title_left);
		this.insertStandardButton(formatting, "align_center", "mycode_box/images/codebuttons/align_center.gif", "align", "center", this.options.lang.title_center);
		this.insertStandardButton(formatting, "align_right", "mycode_box/images/codebuttons/align_right.gif", "align", "right", this.options.lang.title_right);
		this.insertStandardButton(formatting, "align_justify", "mycode_box/images/codebuttons/align_justify.gif", "align", "justify", this.options.lang.title_justify);

		// Create insertable elements section of second toolbar.
		elements = document.createElement("div");
		elements.style.position = "absolute";
		
		if(this.options.rtl == 1)
		{
			elements.style.left = 0;
		}
		else
		{
			elements.style.right = 0;
		}

		toolbar2.appendChild(elements);
		this.insertStandardButton(elements, "list_num", "mycode_box/images/codebuttons/list_num.gif", "list", "1", this.options.lang.title_numlist);
		this.insertStandardButton(elements, "list_bullet", "mycode_box/images/codebuttons/list_bullet.gif", "list", "", this.options.lang.title_bulletlist);
		this.insertSeparator(elements);
		this.insertStandardButton(elements, "img", "mycode_box/images/codebuttons/image.gif", "image", "", this.options.lang.title_image);
		this.insertStandardButton(elements, "url", "mycode_box/images/codebuttons/link.gif", "url", "", this.options.lang.title_hyperlink);
		this.insertStandardButton(elements, "email", "mycode_box/images/codebuttons/email.gif", "email", "", this.options.lang.title_email);
		this.insertSeparator(elements);
		this.insertStandardButton(elements, "quote", "mycode_box/images/codebuttons/quote.gif", "quote", "", this.options.lang.title_quote);
		this.insertStandardButton(elements, "code", "mycode_box/images/codebuttons/code.gif", "code", "", this.options.lang.title_code);
		this.insertStandardButton(elements, "php", "mycode_box/images/codebuttons/php.gif", "php", "", this.options.lang.title_php);

		// Append the second toolbar to the editor
		editor.appendChild(toolbar2);
// Create a new toolbar under the existing toolbars.
toolbar3 = document.createElement("div");
toolbar3.style.height = "28px";
toolbar3.style.position = "relative";

// Create formatting section of the new toolbar.
toolbar3area = document.createElement("div");
toolbar3area.style.position = "absolute";
toolbar3.appendChild(toolbar3area);

// Insert toolbar3area buttons.
this.insertStandardButton(toolbar3area, "flash", "mycode_box/images/codebuttons/flash.gif", "flash", "", this.options.lang.title_flash);
this.insertStandardButton(toolbar3area, "video", "mycode_box/images/codebuttons/video.gif", "video", "", this.options.lang.title_video);
this.insertStandardButton(toolbar3area, "music", "mycode_box/images/codebuttons/stream.gif", "music", "", this.options.lang.title_music);
this.insertStandardButton(toolbar3area, "youtube", "mycode_box/images/codebuttons/youtube.gif", "youtube", "", this.options.lang.title_youtube);
		this.insertSeparator(toolbar3area);
this.insertStandardButton(toolbar3area, "marql", "mycode_box/images/codebuttons/marql.gif", "marql", "", this.options.lang.title_marql);
this.insertStandardButton(toolbar3area, "marqu", "mycode_box/images/codebuttons/marqu.gif", "marqu", "", this.options.lang.title_marqu);
this.insertStandardButton(toolbar3area, "marqd", "mycode_box/images/codebuttons/marqd.gif", "marqd", "", this.options.lang.title_marqd);
this.insertStandardButton(toolbar3area, "marqr", "mycode_box/images/codebuttons/marqr.gif", "marqr", "", this.options.lang.title_marqr);
		this.insertSeparator(toolbar3area);
this.insertStandardButton(toolbar3area, "strike", "mycode_box/images/codebuttons/strike.gif", "strike", "", this.options.lang.title_strike);
this.insertStandardButton(toolbar3area, "sub", "mycode_box/images/codebuttons/sub.gif", "sub", "", this.options.lang.title_sub);
this.insertStandardButton(toolbar3area, "sup", "mycode_box/images/codebuttons/sup.gif", "sup", "", this.options.lang.title_sup);
		this.insertSeparator(toolbar3area);
this.insertStandardButton(toolbar3area, "spoil", "mycode_box/images/codebuttons/spoil.gif", "spoil", "", this.options.lang.title_spoil);
this.insertStandardButton(toolbar3area, "img", "mycode_box/images/codebuttons/highslide.gif", "img", "", this.options.lang.title_highslide);
// Insert the new toolbar into the editor
editor.appendChild(toolbar3); 

		// Create our new text area
		areaContainer = document.createElement("div");
		areaContainer.style.clear = "both";

		// Set the height of the area
		subtract = subtract2 = 0;
		if(MyBB.browser != "ie" || (MyBB.browser == "ie" && MyBB.useragent.indexOf('msie 7.') != -1))
		{
			subtract = subtract2 = 35;
		}
		areaContainer.style.height = parseInt(editor.style.height)-parseInt(toolBar.style.height)-parseInt(toolbar2.style.height)-subtract+"px";

		// Set the width of the area
		subtract = subtract3 = 0;
		if(MyBB.browser != "ie" || (MyBB.browser == "ie" && MyBB.useragent.indexOf('msie 7.') != -1))
		{
			subtract = subtract3 = 8;
		}

		areaContainer.style.width = parseInt(editor.style.width)-subtract3+"px";
		
// Create text area
For the /inc/functions.php modification, it's not possible through a plugin alone, as there is no plugin hook in that function - you're stuck with a code edit.
If you're planning on making a plugin which allows a user to, for example, add editor buttons from the AdminCP, you can ask them to put a plugin hook there.

For the /jscripts/editor.js file, I don't think it's possible without a code edit.
Thanks for the feedback.

I knew it was too messy for a plug-in, so a MOD it will stay. Wink

I add all the extra BBCODE with a single .php file with (require_once) into class_parser.php.

Actually it calls a config.php file and that calls a lot of the other functions I've made.

At least it's not a lot of editing core files for it to work. Big Grin