MyBB Community Forums

Full Version: [1.8] How add sceditor in quick reply and quick edit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Good, this will be the first plugin for my MyBB 1.8
(2014-07-16, 08:21 AM)dragonexpert Wrote: [ -> ]
(2014-07-14, 08:52 AM)Eldenroot Wrote: [ -> ]@martec - no problem, but I think this should be in core - I dont know why mybb team doenst wanna this with enable/disable settings... every other board soft has it inside

Quick Reply means quick reply.  It doesn't mean full editor.

I've seen a lot of other software loading their WYSIWYG editors on focus in Quick Reply. That would (and should these days, IMHO) be a handy solution.
(2014-08-13, 07:48 PM)Shade Wrote: [ -> ]I've seen a lot of other software loading their WYSIWYG editors on focus in Quick Reply. That would (and should these days, IMHO) be a handy solution.

I agree with Shade. Do someone plan to make a tutorial about how to load WYSIWYG editor on click?

Thanks!
Yes, many other forum board have a setting for this - better than add another plugin...
(2014-08-13, 09:12 PM)Adriano Wrote: [ -> ]
(2014-08-13, 07:48 PM)Shade Wrote: [ -> ]I've seen a lot of other software loading their WYSIWYG editors on focus in Quick Reply. That would (and should these days, IMHO) be a handy solution.

I agree with Shade. Do someone plan to make a tutorial about how to load WYSIWYG editor on click?

Thanks!

yes possible...
i will make in on the weekend
Alpha version: Show editor in quick reply only after focused in textarea:

​<?php 
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

// Plugin info
function quickadveditor_info ()
{
    return array(
        "name"            => "Quick Advanced Editor",
        "description"    => "Advanced editor in quick reply",
        "website"        => "",
        "author"        => "martec",
        "authorsite"    => "",
        "version"        => "2.0",
        "guid"             => "",
        "compatibility" => "17*,18*"
    );
}

function quickadveditor_activate()
{
	global $db;
    include_once MYBB_ROOT.'inc/adminfunctions_templates.php';
	
	$template = array(
		"tid"		=> NULL,
		"title"		=> "codebutquick",
		"template"	=> "<link rel=\"stylesheet\" href=\"{\$mybb->asset_url}/jscripts/sceditor/editor_themes/{\$theme[\'editortheme\']}\" type=\"text/css\" media=\"all\" />
<script type=\"text/javascript\" src=\"{\$mybb->asset_url}/jscripts/sceditor/jquery.sceditor.bbcode.min.js\"></script>
<script type=\"text/javascript\" src=\"{\$mybb->asset_url}/jscripts/bbcodes_sceditor.js\"></script>
<script type=\"text/javascript\">
var partialmode = {\$mybb->settings[\'partialmode\']},
opt_editor = {
	plugins: \"bbcode\",
	height: 270,
	style: \"{\$mybb->asset_url}/jscripts/sceditor/jquery.sceditor.mybb.css\",
	rtl: {\$lang->settings[\'rtl\']},
	locale: \"mybblang\",
	emoticonsEnabled: {\$emoticons_enabled},
	emoticons: {
		// Emoticons to be included in the dropdown
		dropdown: {
			{\$dropdownsmilies}
		},
		// Emoticons to be included in the more section
		more: {
			{\$moresmilies}
		},
		// Emoticons that are not shown in the dropdown but will still be converted. Can be used for things like aliases
		hidden: {
			{\$hiddensmilies}
		}
	},
	emoticonsCompat: true,
	toolbar: \"{\$basic1}{\$align}{\$font}{\$size}{\$color}{\$removeformat}{\$basic2}image,{\$email}{\$link}|video{\$emoticon}|{\$list}{\$code}quote|maximize,source\",
};
{\$editor_language}

(\$.fn.on || \$.fn.live).call(\$(document), \'focus\', \'textarea[name*=\"value\"]\', function () {
    \$(this).sceditor(opt_editor);
    {\$sourcemode}
});

(\$.fn.on || \$.fn.live).call(\$(document), \'focus\', \'#message\', function () {
    \$(this).sceditor(opt_editor);
	MyBBEditor = \$(\"#message\").sceditor(\"instance\");
    {\$sourcemode}
});

/**********************************
 * Thread compatibility functions *
 **********************************/
if(typeof Thread !== \'undefined\')
{
    var quickReplyFunc = Thread.quickReply;
    Thread.quickReply = function(e) {

        if(MyBBEditor) {
            MyBBEditor.updateOriginal();
            $(\'form[id*=\"quick_reply_form\"]\').bind(\'reset\', function() {
                MyBBEditor.val(\'\').emoticons(true);
            });
        }
        
        return quickReplyFunc.call(this, e);        
    };
};
</script>",
		"sid"		=> "-1"
	);
	$db->insert_query("templates", $template);

    find_replace_templatesets(
        'showthread_quickreply',
        '#' . preg_quote('</textarea>') . '#i',
        '</textarea>{$codebutquick}'
    );

    find_replace_templatesets(
        'showthread_quickreply',
        '#' . preg_quote('<span class="smalltext">{$lang->message_note}<br />') . '#i',
        '<span class="smalltext">{$lang->message_note}<br />{$smilieinserter}'
    );
}

function quickadveditor_deactivate()
{
	global $db;
    include_once MYBB_ROOT."inc/adminfunctions_templates.php";

	$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='codebutquick'");	

    find_replace_templatesets(
        'showthread_quickreply',
        '#' . preg_quote('</textarea>{$codebutquick}') . '#i',
        '</textarea>'
    );

    find_replace_templatesets(
        'showthread_quickreply',
        '#' . preg_quote('<span class="smalltext">{$lang->message_note}<br />{$smilieinserter}') . '#i',
        '<span class="smalltext">{$lang->message_note}<br />'
    );
}

function mycode_inserter_quick($smilies = true)
{
	global $db, $mybb, $theme, $templates, $lang, $smiliecache, $cache;

	if($mybb->settings['bbcodeinserter'] != 0)
	{
		$editor_lang_strings = array(
			"editor_bold" => "Bold",
			"editor_italic" => "Italic",
			"editor_underline" => "Underline",
			"editor_strikethrough" => "Strikethrough",
			"editor_subscript" => "Subscript",
			"editor_superscript" => "Superscript",
			"editor_alignleft" => "Align left",
			"editor_center" => "Center",
			"editor_alignright" => "Align right",
			"editor_justify" => "Justify",
			"editor_fontname" => "Font Name",
			"editor_fontsize" => "Font Size",
			"editor_fontcolor" => "Font Color",
			"editor_removeformatting" => "Remove Formatting",
			"editor_cut" => "Cut",
			"editor_cutnosupport" => "Your browser does not allow the cut command. Please use the keyboard shortcut Ctrl/Cmd-X",
			"editor_copy" => "Copy",
			"editor_copynosupport" => "Your browser does not allow the copy command. Please use the keyboard shortcut Ctrl/Cmd-C",
			"editor_paste" => "Paste",
			"editor_pastenosupport" => "Your browser does not allow the paste command. Please use the keyboard shortcut Ctrl/Cmd-V",
			"editor_pasteentertext" => "Paste your text inside the following box:",
			"editor_pastetext" => "PasteText",
			"editor_numlist" => "Numbered list",
			"editor_bullist" => "Bullet list",
			"editor_undo" => "Undo",
			"editor_redo" => "Redo",
			"editor_rows" => "Rows:",
			"editor_cols" => "Cols:",
			"editor_inserttable" => "Insert a table",
			"editor_inserthr" => "Insert a horizontal rule",
			"editor_code" => "Code",
			"editor_width" => "Width (optional):",
			"editor_height" => "Height (optional):",
			"editor_insertimg" => "Insert an image",
			"editor_email" => "E-mail:",
			"editor_insertemail" => "Insert an email",
			"editor_url" => "URL:",
			"editor_insertlink" => "Insert a link",
			"editor_unlink" => "Unlink",
			"editor_more" => "More",
			"editor_insertemoticon" => "Insert an emoticon",
			"editor_videourl" => "Video URL:",
			"editor_videotype" => "Video Type:",
			"editor_insert" => "Insert",
			"editor_insertyoutubevideo" => "Insert a YouTube video",
			"editor_currentdate" => "Insert current date",
			"editor_currenttime" => "Insert current time",
			"editor_print" => "Print",
			"editor_viewsource" => "View source",
			"editor_description" => "Description (optional):",
			"editor_enterimgurl" => "Enter the image URL:",
			"editor_enteremail" => "Enter the e-mail address:",
			"editor_enterdisplayedtext" => "Enter the displayed text:",
			"editor_enterurl" => "Enter URL:",
			"editor_enteryoutubeurl" => "Enter the YouTube video URL or ID:",
			"editor_insertquote" => "Insert a Quote",
			"editor_invalidyoutube" => "Invalid YouTube video",
			"editor_dailymotion" => "Dailymotion",
			"editor_metacafe" => "MetaCafe",
			"editor_veoh" => "Veoh",
			"editor_vimeo" => "Vimeo",
			"editor_youtube" => "Youtube",
			"editor_facebook" => "Facebook",
			"editor_liveleak" => "LiveLeak",
			"editor_insertvideo" => "Insert a video",
			"editor_php" => "PHP",
			"editor_maximize" => "Maximize"
		);
		$editor_language = "(function ($) {\n$.sceditor.locale[\"mybblang\"] = {\n";

		$editor_languages_count = count($editor_lang_strings);
		$i = 0;
		foreach($editor_lang_strings as $lang_string => $key)
		{
			$i++;
			$js_lang_string = str_replace("\"", "\\\"", $key);
			$string = str_replace("\"", "\\\"", $lang->$lang_string);
			$editor_language .= "\t\"{$js_lang_string}\": \"{$string}\"";

			if($i < $editor_languages_count)
			{
				$editor_language .= ",";
			}

			$editor_language .= "\n";
		}

		$editor_language .= "}})(jQuery);";

		if(defined("IN_ADMINCP"))
		{
			global $page;
			$codeinsertquick = $page->build_codebuttons_editor($editor_language, $smilies);
		}
		else
		{
			// Smilies
			$emoticon = "";
			$emoticons_enabled = "false";
			if($smilies && $mybb->settings['smilieinserter'] != 0 && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'])
			{
				$emoticon = ",emoticon";
				$emoticons_enabled = "true";

				if(!$smiliecache)
				{
					if(!is_array($smilie_cache))
					{
						$smilie_cache = $cache->read("smilies");
					}
					foreach($smilie_cache as $smilie)
					{
						if($smilie['showclickable'] != 0)
						{
							$smilie['image'] = str_replace("{theme}", $theme['imgdir'], $smilie['image']);
							$smiliecache[$smilie['sid']] = $smilie;
						}
					}
				}

				unset($smilie);

				if(is_array($smiliecache))
				{
					reset($smiliecache);

					$dropdownsmilies = $moresmilies = $hiddensmilies = "";
					$i = 0;

					foreach($smiliecache as $smilie)
					{
						$finds = explode("\n", $smilie['find']);
						$finds_count = count($finds);

						// Only show the first text to replace in the box
						$smilie['find'] = $finds[0];

						$find = htmlspecialchars_uni($smilie['find']);
						$image = htmlspecialchars_uni($smilie['image']);
						if($i < $mybb->settings['smilieinsertertot'])
						{
							$dropdownsmilies .= '"'.$find.'": "'.$image.'",';
						}
						else
						{
							$moresmilies .= '"'.$find.'": "'.$image.'",';
						}

						for($j = 1; $j < $finds_count; ++$j)
						{
							$find = htmlspecialchars_uni($finds[$j]);
							$hiddensmilies .= '"'.$find.'": "'.$image.'",';
						}
						++$i;
					}
				}
			}

			$basic1 = $basic2 = $align = $font = $size = $color = $removeformat = $email = $link = $list = $code = $sourcemode = "";

			if($mybb->settings['allowbasicmycode'] == 1)
			{
				$basic1 = "bold,italic,underline,strike|";
				$basic2 = "horizontalrule,";
			}

			if($mybb->settings['allowalignmycode'] == 1)
			{
				$align = "left,center,right,justify|";
			}

			if($mybb->settings['allowfontmycode'] == 1)
			{
				$font = "font,";
			}

			if($mybb->settings['allowsizemycode'] == 1)
			{
				$size = "size,";
			}

			if($mybb->settings['allowcolormycode'] == 1)
			{
				$color = "color,";
			}

			if($mybb->settings['allowfontmycode'] == 1 || $mybb->settings['allowsizemycode'] == 1 || $mybb->settings['allowcolormycode'] == 1)
			{
				$removeformat = "removeformat|";
			}

			if($mybb->settings['allowemailmycode'] == 1)
			{
				$email = "email,";
			}

			if($mybb->settings['allowlinkmycode'] == 1)
			{
				$link = "link,unlink";
			}

			if($mybb->settings['allowlistmycode'] == 1)
			{
				$list = "bulletlist,orderedlist|";
			}

			if($mybb->settings['allowcodemycode'] == 1)
			{
				$code = "code,php,";
			}

			if($mybb->user['sourceeditor'] == 1)
			{
				$sourcemode = "MyBBEditor.sourceMode(true);";
			}

			eval("\$codeinsertquick = \"".$templates->get("codebutquick")."\";");
		}
	}

	return $codeinsertquick;
}

$plugins->add_hook("showthread_start", "codebuttonsquick");     

function codebuttonsquick () {

    global $smilieinserter, $codebutquick;
	
	$codebutquick = mycode_inserter_quick();
	$smilieinserter = build_clickable_smilies();
}

?>
Is it working for quick edit too? I havent tested
Thank you, it works perfectly Big Grin used "Without Smilies box and with Quick Edit"
Pages: 1 2