Exemple #1
0
function create_control_richedit($editorOptions)
{
    global $txt, $modSettings, $options, $smcFunc;
    global $context, $settings, $user_info, $sourcedir, $scripturl;
    // Load the Post language file... for the moment at least.
    loadLanguage('Post');
    // Every control must have a ID!
    assert(isset($editorOptions['id']));
    assert(isset($editorOptions['value']));
    // Is this the first richedit - if so we need to ensure some template stuff is initialised.
    if (empty($context['controls']['richedit'])) {
        // Some general stuff.
        $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
        // This really has some WYSIWYG stuff.
        $context['html_headers'] .= '
		<script type="text/javascript"><!-- // --><![CDATA[
			var smf_smileys_url = \'' . $settings['smileys_url'] . '\';
			var oEditorStrings= {
				wont_work: \'' . addcslashes($txt['rich_edit_wont_work'], "'") . '\',
				func_disabled: \'' . addcslashes($txt['rich_edit_function_disabled'], "'") . '\',
				prompt_text_email: \'' . addcslashes($txt['prompt_text_email'], "'") . '\',
				prompt_text_ftp: \'' . addcslashes($txt['prompt_text_ftp'], "'") . '\',
				prompt_text_url: \'' . addcslashes($txt['prompt_text_url'], "'") . '\',
				prompt_text_img: \'' . addcslashes($txt['prompt_text_img'], "'") . '\'
			}
		// ]]></script>
		<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/editor.js' . $context['jsver'] . '"></script>';
    }
    // Start off the editor...
    $context['controls']['richedit'][$editorOptions['id']] = array('id' => $editorOptions['id'], 'value' => $editorOptions['value'], 'rich_value' => bbc_to_html($editorOptions['value']), 'rich_active' => empty($modSettings['disable_wysiwyg']) && (!empty($options['wysiwyg_default']) || !empty($editorOptions['force_rich']) || !empty($_REQUEST[$editorOptions['id'] . '_mode'])), 'disable_smiley_box' => !empty($editorOptions['disable_smiley_box']), 'columns' => isset($editorOptions['columns']) ? $editorOptions['columns'] : 60, 'rows' => isset($editorOptions['rows']) ? $editorOptions['rows'] : 20, 'width' => isset($editorOptions['width']) ? $editorOptions['width'] : '70%', 'height' => isset($editorOptions['height']) ? $editorOptions['height'] : '150px', 'form' => isset($editorOptions['form']) ? $editorOptions['form'] : 'postmodify', 'bbc_level' => !empty($editorOptions['bbc_level']) ? $editorOptions['bbc_level'] : 'full', 'preview_type' => isset($editorOptions['preview_type']) ? (int) $editorOptions['preview_type'] : 1, 'labels' => !empty($editorOptions['labels']) ? $editorOptions['labels'] : array());
    // Switch between default images and back... mostly in case you don't have an PersonalMessage template, but do have a Post template.
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $temp1 = $settings['theme_url'];
        $settings['theme_url'] = $settings['default_theme_url'];
        $temp2 = $settings['images_url'];
        $settings['images_url'] = $settings['default_images_url'];
        $temp3 = $settings['theme_dir'];
        $settings['theme_dir'] = $settings['default_theme_dir'];
    }
    if (empty($context['bbc_tags'])) {
        // The below array makes it dead easy to add images to this control. Add it to the array and everything else is done for you!
        $context['bbc_tags'] = array();
        $context['bbc_tags'][] = array(array('image' => 'bold', 'code' => 'b', 'before' => '[b]', 'after' => '[/b]', 'description' => $txt['bold']), array('image' => 'italicize', 'code' => 'i', 'before' => '[i]', 'after' => '[/i]', 'description' => $txt['italic']), array('image' => 'underline', 'code' => 'u', 'before' => '[u]', 'after' => '[/u]', 'description' => $txt['underline']), array('image' => 'strike', 'code' => 's', 'before' => '[s]', 'after' => '[/s]', 'description' => $txt['strike']), array(), array('image' => 'pre', 'code' => 'pre', 'before' => '[pre]', 'after' => '[/pre]', 'description' => $txt['preformatted']), array('image' => 'left', 'code' => 'left', 'before' => '[align=left]', 'after' => '[/align]', 'description' => $txt['left_align']), array('image' => 'center', 'code' => 'center', 'before' => '[align=center]', 'after' => '[/align]', 'description' => $txt['center']), array('image' => 'right', 'code' => 'right', 'before' => '[align=right]', 'after' => '[/align]', 'description' => $txt['right_align']));
        $context['bbc_tags'][] = array(array('image' => 'emoticon', 'code' => 'showemoticons', 'before' => '', 'description' => $txt['more_smileys_pick']), array(), array('image' => 'flash', 'code' => 'flash', 'before' => '[flash=200,200]', 'after' => '[/flash]', 'description' => $txt['flash']), array('image' => 'img', 'code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $txt['image']), array('image' => 'url', 'code' => 'url', 'before' => '[url]', 'after' => '[/url]', 'description' => $txt['hyperlink']), array('image' => 'email', 'code' => 'email', 'before' => '[email]', 'after' => '[/email]', 'description' => $txt['insert_email']), array(), array('image' => 'sup', 'code' => 'sup', 'before' => '[sup]', 'after' => '[/sup]', 'description' => $txt['superscript']), array('image' => 'sub', 'code' => 'sub', 'before' => '[sub]', 'after' => '[/sub]', 'description' => $txt['subscript']), array('image' => 'tele', 'code' => 'tt', 'before' => '[tt]', 'after' => '[/tt]', 'description' => $txt['teletype']), array(), array('image' => 'table', 'code' => 'table', 'before' => '[table]\\n[tr]\\n[td]', 'after' => '[/td]\\n[/tr]\\n[/table]', 'description' => $txt['table']), array('image' => 'code', 'code' => 'code', 'before' => '[code]', 'after' => '[/code]', 'description' => $txt['bbc_code']), array('image' => 'quote', 'code' => 'quote', 'before' => '[quote]', 'after' => '[/quote]', 'description' => $txt['bbc_quote']), array(), array('image' => 'list', 'code' => 'list', 'before' => '[list]\\n[li]', 'after' => '[/li]\\n[li][/li]\\n[/list]', 'description' => $txt['list_unordered']), array('image' => 'orderlist', 'code' => 'orderlist', 'before' => '[list type=decimal]\\n[li]', 'after' => '[/li]\\n[li][/li]\\n[/list]', 'description' => $txt['list_ordered']), array('image' => 'hr', 'code' => 'hr', 'before' => '[hr]', 'description' => $txt['horizontal_rule']));
        // Allow mods to modify BBC buttons.
        HookAPI::callHook('integrate_bbc_buttons', array(&$context['bbc_tags']));
        // Show the toggle?
        if (empty($modSettings['disable_wysiwyg'])) {
            $context['bbc_tags'][count($context['bbc_tags']) - 1][] = array();
            $context['bbc_tags'][count($context['bbc_tags']) - 1][] = array('image' => 'unformat', 'code' => 'unformat', 'before' => '', 'description' => $txt['unformat_text']);
            $context['bbc_tags'][count($context['bbc_tags']) - 1][] = array('image' => 'toggle', 'code' => 'toggle', 'before' => '', 'description' => $txt['toggle_view']);
        }
        $context['bbc_tags'][count($context['bbc_tags']) - 1][] = array();
        $context['bbc_tags'][count($context['bbc_tags']) - 1][] = array('image' => 'zoom', 'code' => 'zoom', 'before' => '', 'description' => $txt['zoom_editor']);
        foreach ($context['bbc_tags'] as $row => $tagRow) {
            $context['bbc_tags'][$row][count($tagRow) - 1]['isLast'] = true;
        }
    }
    // Initialize smiley array... if not loaded before.
    if (empty($context['smileys']) && empty($editorOptions['disable_smiley_box'])) {
        $context['smileys'] = array('postform' => array(), 'popup' => array());
        // Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
        if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
            $context['smileys']['postform'][] = array('smileys' => array(array('code' => ':)', 'filename' => 'smiley.gif', 'description' => $txt['icon_smiley']), array('code' => ';)', 'filename' => 'wink.gif', 'description' => $txt['icon_wink']), array('code' => ':D', 'filename' => 'cheesy.gif', 'description' => $txt['icon_cheesy']), array('code' => ';D', 'filename' => 'grin.gif', 'description' => $txt['icon_grin']), array('code' => '>:(', 'filename' => 'angry.gif', 'description' => $txt['icon_angry']), array('code' => ':(', 'filename' => 'sad.gif', 'description' => $txt['icon_sad']), array('code' => ':o', 'filename' => 'shocked.gif', 'description' => $txt['icon_shocked']), array('code' => '8)', 'filename' => 'cool.gif', 'description' => $txt['icon_cool']), array('code' => '???', 'filename' => 'huh.gif', 'description' => $txt['icon_huh']), array('code' => '::)', 'filename' => 'rolleyes.gif', 'description' => $txt['icon_rolleyes']), array('code' => ':P', 'filename' => 'tongue.gif', 'description' => $txt['icon_tongue']), array('code' => ':-[', 'filename' => 'embarrassed.gif', 'description' => $txt['icon_embarrassed']), array('code' => ':-X', 'filename' => 'lipsrsealed.gif', 'description' => $txt['icon_lips']), array('code' => ':-\\', 'filename' => 'undecided.gif', 'description' => $txt['icon_undecided']), array('code' => ':-*', 'filename' => 'kiss.gif', 'description' => $txt['icon_kiss']), array('code' => ':\'(', 'filename' => 'cry.gif', 'description' => $txt['icon_cry'], 'isLast' => true)), 'isLast' => true);
        } elseif ($user_info['smiley_set'] != 'none') {
            if (($temp = CacheAPI::getCache('posting_smileys', 480)) == null) {
                $request = smf_db_query('
					SELECT code, filename, description, smiley_row, hidden
					FROM {db_prefix}smileys
					WHERE hidden IN (0, 2)
					ORDER BY smiley_row, smiley_order', array());
                while ($row = mysql_fetch_assoc($request)) {
                    $row['filename'] = htmlspecialchars($row['filename']);
                    $row['description'] = htmlspecialchars($row['description']);
                    $context['smileys']['postform'][$row['smiley_row']]['smileys'][] = $row;
                }
                mysql_free_result($request);
                foreach ($context['smileys'] as $section => $smileyRows) {
                    foreach ($smileyRows as $rowIndex => $smileys) {
                        $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
                    }
                    if (!empty($smileyRows)) {
                        $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
                    }
                }
                CacheAPI::putCache('posting_smileys', $context['smileys'], 480);
            } else {
                $context['smileys'] = $temp;
            }
        }
    }
    // Set a flag so the sub template knows what to do...
    $context['show_bbc'] = !empty($modSettings['enableBBC']) && !empty($settings['show_bbc']);
    // Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
    $disabled_tags = array();
    if (!empty($modSettings['disabledBBC'])) {
        $disabled_tags = explode(',', $modSettings['disabledBBC']);
    }
    $disabled_tags[] = 'flash';
    foreach ($disabled_tags as $tag) {
        if ($tag == 'list') {
            $context['disabled_tags']['orderlist'] = true;
        }
        $context['disabled_tags'][trim($tag)] = true;
    }
    // Switch the URLs back... now we're back to whatever the main sub template is.  (like folder in PersonalMessage.)
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $settings['theme_url'] = $temp1;
        $settings['images_url'] = $temp2;
        $settings['theme_dir'] = $temp3;
    }
}
Exemple #2
0
function create_control_richedit($editorOptions)
{
    global $txt, $modSettings, $options, $smcFunc;
    global $context, $settings, $user_info, $sourcedir, $scripturl;
    // Load the Post language file... for the moment at least.
    loadLanguage('Post');
    // Every control must have a ID!
    assert(isset($editorOptions['id']));
    assert(isset($editorOptions['value']));
    // Is this the first richedit - if so we need to ensure some template stuff is initialised.
    if (empty($context['controls']['richedit'])) {
        // Some general stuff.
        $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
        // This really has some WYSIWYG stuff.
        loadTemplate('GenericControls', $context['browser']['is_ie'] ? 'editor_ie' : 'editor');
        $context['html_headers'] .= '
		<script type="text/javascript"><!-- // --><![CDATA[
			var smf_smileys_url = \'' . $settings['smileys_url'] . '\';
			var oEditorStrings= {
				wont_work: \'' . addcslashes($txt['rich_edit_wont_work'], "'") . '\',
				func_disabled: \'' . addcslashes($txt['rich_edit_function_disabled'], "'") . '\',
				prompt_text_email: \'' . addcslashes($txt['prompt_text_email'], "'") . '\',
				prompt_text_ftp: \'' . addcslashes($txt['prompt_text_ftp'], "'") . '\',
				prompt_text_url: \'' . addcslashes($txt['prompt_text_url'], "'") . '\',
				prompt_text_img: \'' . addcslashes($txt['prompt_text_img'], "'") . '\'
			}
		// ]]></script>
		<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/editor.js?fin20"></script>';
        $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new');
        if ($context['show_spellchecking']) {
            $context['html_headers'] .= '
		<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/spellcheck.js"></script>';
            // Some hidden information is needed in order to make the spell checking work.
            if (!isset($_REQUEST['xml'])) {
                $context['insert_after_template'] .= '
		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
			<input type="hidden" name="spellstring" value="" />
		</form>';
            }
            // Also make sure that spell check works with rich edit.
            $context['html_headers'] .= '
		<script type="text/javascript"><!-- // --><![CDATA[
		function spellCheckDone()
		{
			for (i = 0; i < smf_editorArray.length; i++)
				setTimeout("smf_editorArray[" + i + "].spellCheckEnd()", 150);
		}
		// ]]></script>';
        }
    }
    // Start off the editor...
    $context['controls']['richedit'][$editorOptions['id']] = array('id' => $editorOptions['id'], 'value' => $editorOptions['value'], 'rich_value' => bbc_to_html($editorOptions['value']), 'rich_active' => empty($modSettings['disable_wysiwyg']) && (!empty($options['wysiwyg_default']) || !empty($editorOptions['force_rich']) || !empty($_REQUEST[$editorOptions['id'] . '_mode'])), 'disable_smiley_box' => !empty($editorOptions['disable_smiley_box']), 'columns' => isset($editorOptions['columns']) ? $editorOptions['columns'] : 60, 'rows' => isset($editorOptions['rows']) ? $editorOptions['rows'] : 12, 'width' => isset($editorOptions['width']) ? $editorOptions['width'] : '70%', 'height' => isset($editorOptions['height']) ? $editorOptions['height'] : '150px', 'form' => isset($editorOptions['form']) ? $editorOptions['form'] : 'postmodify', 'bbc_level' => !empty($editorOptions['bbc_level']) ? $editorOptions['bbc_level'] : 'full', 'preview_type' => isset($editorOptions['preview_type']) ? (int) $editorOptions['preview_type'] : 1, 'labels' => !empty($editorOptions['labels']) ? $editorOptions['labels'] : array());
    // Switch between default images and back... mostly in case you don't have an PersonalMessage template, but do have a Post template.
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $temp1 = $settings['theme_url'];
        $settings['theme_url'] = $settings['default_theme_url'];
        $temp2 = $settings['images_url'];
        $settings['images_url'] = $settings['default_images_url'];
        $temp3 = $settings['theme_dir'];
        $settings['theme_dir'] = $settings['default_theme_dir'];
    }
    if (empty($context['bbc_tags'])) {
        // The below array makes it dead easy to add images to this control. Add it to the array and everything else is done for you!
        $context['bbc_tags'] = array();
        $context['bbc_tags'][] = array(array('image' => 'bold', 'code' => 'b', 'before' => '[b]', 'after' => '[/b]', 'description' => $txt['bold']), array('image' => 'italicize', 'code' => 'i', 'before' => '[i]', 'after' => '[/i]', 'description' => $txt['italic']), array('image' => 'underline', 'code' => 'u', 'before' => '[u]', 'after' => '[/u]', 'description' => $txt['underline']), array('image' => 'strike', 'code' => 's', 'before' => '[s]', 'after' => '[/s]', 'description' => $txt['strike']), array(), array('image' => 'pre', 'code' => 'pre', 'before' => '[pre]', 'after' => '[/pre]', 'description' => $txt['preformatted']), array('image' => 'left', 'code' => 'left', 'before' => '[left]', 'after' => '[/left]', 'description' => $txt['left_align']), array('image' => 'center', 'code' => 'center', 'before' => '[center]', 'after' => '[/center]', 'description' => $txt['center']), array('image' => 'right', 'code' => 'right', 'before' => '[right]', 'after' => '[/right]', 'description' => $txt['right_align']));
        $context['bbc_tags'][] = array(array('image' => 'flash', 'code' => 'flash', 'before' => '[flash=200,200]', 'after' => '[/flash]', 'description' => $txt['flash']), array('image' => 'img', 'code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $txt['image']), array('image' => 'url', 'code' => 'url', 'before' => '[url]', 'after' => '[/url]', 'description' => $txt['hyperlink']), array('image' => 'quote', 'code' => 'quote', 'before' => '[quote]', 'after' => '[/quote]', 'description' => $txt['bbc_quote']), array('image' => 'email', 'code' => 'email', 'before' => '[email]', 'after' => '[/email]', 'description' => $txt['insert_email']), array('image' => 'ftp', 'code' => 'ftp', 'before' => '[ftp]', 'after' => '[/ftp]', 'description' => $txt['ftp']), array('image' => 'nsfw', 'code' => 'nsfw', 'before' => '[nsfw]', 'after' => '[/nsfw]', 'description' => 'NSFW content'), array('image' => 'spoiler', 'code' => 'spoiler', 'before' => '[spoiler]', 'after' => '[/spoiler]', 'description' => 'Spoiler'), array(), array('image' => 'glow', 'code' => 'glow', 'before' => '[glow=red,2,300]', 'after' => '[/glow]', 'description' => $txt['glow']), array('image' => 'shadow', 'code' => 'shadow', 'before' => '[shadow=red,left]', 'after' => '[/shadow]', 'description' => $txt['shadow']), array('image' => 'move', 'code' => 'move', 'before' => '[move]', 'after' => '[/move]', 'description' => $txt['marquee']), array('image' => 'sup', 'code' => 'sup', 'before' => '[sup]', 'after' => '[/sup]', 'description' => $txt['superscript']), array('image' => 'sub', 'code' => 'sub', 'before' => '[sub]', 'after' => '[/sub]', 'description' => $txt['subscript']), array('image' => 'tele', 'code' => 'tt', 'before' => '[tt]', 'after' => '[/tt]', 'description' => $txt['teletype']), array(), array('image' => 'table', 'code' => 'table', 'before' => '[table]\\n[tr]\\n[td]', 'after' => '[/td]\\n[/tr]\\n[/table]', 'description' => $txt['table']), array('image' => 'code', 'code' => 'code', 'before' => '[code]', 'after' => '[/code]', 'description' => $txt['bbc_code']), array('image' => 'list', 'code' => 'list', 'before' => '[list]\\n[li]', 'after' => '[/li]\\n[li][/li]\\n[/list]', 'description' => $txt['list_unordered']), array('image' => 'orderlist', 'code' => 'orderlist', 'before' => '[list type=decimal]\\n[li]', 'after' => '[/li]\\n[li][/li]\\n[/list]', 'description' => $txt['list_ordered']), array('image' => 'hr', 'code' => 'hr', 'before' => '[hr]', 'description' => $txt['horizontal_rule']), array(), array('image' => 'video', 'code' => 'video', 'before' => '[video]', 'after' => '[/video]', 'description' => 'looped video (webm, ogg, mp4)'));
        // Allow mods to modify BBC buttons.
        call_integration_hook('integrate_bbc_buttons', array(&$context['bbc_tags']));
        // Show the toggle?
        if (empty($modSettings['disable_wysiwyg'])) {
            $context['bbc_tags'][count($context['bbc_tags']) - 1][] = array();
            $context['bbc_tags'][count($context['bbc_tags']) - 1][] = array('image' => 'unformat', 'code' => 'unformat', 'before' => '', 'description' => $txt['unformat_text']);
            /**
            			$context['bbc_tags'][count($context['bbc_tags']) - 1][] = array(
            				'image' => 'toggle',
            				'code' => 'toggle',
            				'before' => '',
            				'description' => $txt['toggle_view'],
            			);
                        **/
        }
        foreach ($context['bbc_tags'] as $row => $tagRow) {
            $context['bbc_tags'][$row][count($tagRow) - 1]['isLast'] = true;
        }
    }
    // Initialize smiley array... if not loaded before.
    if (empty($context['smileys']) && empty($editorOptions['disable_smiley_box'])) {
        $context['smileys'] = array('postform' => array(), 'popup' => array());
        // Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
        if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
            $context['smileys']['postform'][] = array('smileys' => array(array('code' => ':)', 'filename' => 'smiley.gif', 'description' => $txt['icon_smiley']), array('code' => ';)', 'filename' => 'wink.gif', 'description' => $txt['icon_wink']), array('code' => ':D', 'filename' => 'cheesy.gif', 'description' => $txt['icon_cheesy']), array('code' => ';D', 'filename' => 'grin.gif', 'description' => $txt['icon_grin']), array('code' => '>:(', 'filename' => 'angry.gif', 'description' => $txt['icon_angry']), array('code' => ':(', 'filename' => 'sad.gif', 'description' => $txt['icon_sad']), array('code' => ':o', 'filename' => 'shocked.gif', 'description' => $txt['icon_shocked']), array('code' => '8)', 'filename' => 'cool.gif', 'description' => $txt['icon_cool']), array('code' => '???', 'filename' => 'huh.gif', 'description' => $txt['icon_huh']), array('code' => '::)', 'filename' => 'rolleyes.gif', 'description' => $txt['icon_rolleyes']), array('code' => ':P', 'filename' => 'tongue.gif', 'description' => $txt['icon_tongue']), array('code' => ':-[', 'filename' => 'embarrassed.gif', 'description' => $txt['icon_embarrassed']), array('code' => ':-X', 'filename' => 'lipsrsealed.gif', 'description' => $txt['icon_lips']), array('code' => ':-\\', 'filename' => 'undecided.gif', 'description' => $txt['icon_undecided']), array('code' => ':-*', 'filename' => 'kiss.gif', 'description' => $txt['icon_kiss']), array('code' => ':\'(', 'filename' => 'cry.gif', 'description' => $txt['icon_cry'], 'isLast' => true)), 'isLast' => true);
        } elseif ($user_info['smiley_set'] != 'none') {
            if (($temp = cache_get_data('posting_smileys', 480)) == null) {
                $request = $smcFunc['db_query']('', '
					SELECT code, filename, description, smiley_row, hidden
					FROM {db_prefix}smileys
					WHERE hidden IN (0, 2)
					ORDER BY smiley_row, smiley_order', array());
                while ($row = $smcFunc['db_fetch_assoc']($request)) {
                    $row['filename'] = htmlspecialchars($row['filename']);
                    $row['description'] = htmlspecialchars($row['description']);
                    $context['smileys'][empty($row['hidden']) ? 'postform' : 'popup'][$row['smiley_row']]['smileys'][] = $row;
                }
                $smcFunc['db_free_result']($request);
                foreach ($context['smileys'] as $section => $smileyRows) {
                    foreach ($smileyRows as $rowIndex => $smileys) {
                        $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
                    }
                    if (!empty($smileyRows)) {
                        $context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
                    }
                }
                cache_put_data('posting_smileys', $context['smileys'], 480);
            } else {
                $context['smileys'] = $temp;
            }
        }
    }
    // Set a flag so the sub template knows what to do...
    $context['show_bbc'] = !empty($modSettings['enableBBC']) && !empty($settings['show_bbc']);
    // Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
    $disabled_tags = array();
    if (!empty($modSettings['disabledBBC'])) {
        $disabled_tags = explode(',', $modSettings['disabledBBC']);
    }
    if (empty($modSettings['enableEmbeddedFlash'])) {
        $disabled_tags[] = 'flash';
    }
    foreach ($disabled_tags as $tag) {
        if ($tag == 'list') {
            $context['disabled_tags']['orderlist'] = true;
        }
        $context['disabled_tags'][trim($tag)] = true;
    }
    // Switch the URLs back... now we're back to whatever the main sub template is.  (like folder in PersonalMessage.)
    if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) {
        $settings['theme_url'] = $temp1;
        $settings['images_url'] = $temp2;
        $settings['theme_dir'] = $temp3;
    }
}
Exemple #3
0
function shd_post_reply()
{
    global $context, $user_info, $sourcedir, $txt, $scripturl, $smcFunc, $reply_request, $modSettings, $settings, $options, $memberContext;
    checkSession('get');
    $new_reply = $_REQUEST['sa'] == 'reply';
    // Things we need
    loadTemplate('sd_template/SimpleDesk-Post');
    require_once $sourcedir . '/Subs-Post.php';
    require_once $sourcedir . '/sd_source/Subs-SimpleDeskPost.php';
    require_once $sourcedir . '/Subs-Editor.php';
    $context['template_layers'][] = 'shd_post_nojs';
    $ticketinfo = shd_load_ticket();
    $context['shd_department'] = $ticketinfo['dept'];
    $reply = array();
    // So, at this point, we can see it, but no guarantee we can reply to it.
    // Can we reply to any? If so, just go right along. If not, we need to do more work.
    if ($new_reply) {
        if (!shd_allowed_to('shd_reply_ticket_any', $ticketinfo['dept'])) {
            if (shd_allowed_to('shd_reply_ticket_own', $ticketinfo['dept'])) {
                if (!$ticketinfo['is_own']) {
                    fatal_lang_error('shd_cannot_reply_any_but_own', false);
                }
            } else {
                fatal_lang_error('shd_cannot_reply_any', false);
            }
            // can't do nuthin'
        }
    } else {
        $_REQUEST['msg'] = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
        $query = shd_db_query('', '
			SELECT id_msg, id_member, body, modified_time, modified_member, modified_name
			FROM {db_prefix}helpdesk_ticket_replies
			WHERE id_msg = {int:msg}
				AND id_ticket = {int:ticket}', array('msg' => $_REQUEST['msg'], 'ticket' => $context['ticket_id']));
        if ($smcFunc['db_num_rows']($query) == 0) {
            $smcFunc['db_free_result']($query);
            fatal_lang_error('shd_no_ticket', false);
        }
        $reply = $smcFunc['db_fetch_assoc']($query);
        if (!shd_allowed_to('shd_edit_reply_any', $ticketinfo['dept'])) {
            if (shd_allowed_to('shd_edit_reply_own', $ticketinfo['dept'])) {
                if ($reply['id_member'] != $user_info['id']) {
                    fatal_lang_error('shd_cannot_edit_reply_any_but_own', false);
                }
            } else {
                fatal_lang_error('shd_cannot_edit_reply_any', false);
            }
        }
        // Fix the body up for later
        $reply['body'] = un_preparsecode($reply['body']);
        censorText($reply['body']);
    }
    // So it's either our ticket and we can reply to our own, or we can reply to any because we're awesome
    // or we're editing and we can haz such powarz
    $context['ticket_form'] = array('dept' => $ticketinfo['dept'], 'form_title' => !empty($reply['id_msg']) ? $txt['shd_ticket_edit_reply'] : $txt['shd_reply_ticket'], 'form_action' => $scripturl . '?action=helpdesk;sa=savereply', 'first_msg' => $new_reply ? 0 : $ticketinfo['id_first_msg'], 'message' => shd_format_text($ticketinfo['body'], $ticketinfo['smileys_enabled'], $new_reply ? '' : 'shd_reply_' . $ticketinfo['id_first_msg']), 'subject' => $ticketinfo['subject'], 'ticket' => $context['ticket_id'], 'msg' => !empty($reply['id_msg']) ? $reply['id_msg'] : 0, 'ticket_link' => '<a href="' . $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $context['ticket_id'] . '">' . $ticketinfo['subject'] . '</a>', 'reply_link' => $new_reply ? 0 : '<a href="' . $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $context['ticket_id'] . '.msg' . $reply['id_msg'] . '#msg' . $reply['id_msg'] . '">' . $txt['response_prefix'] . ' ' . $ticketinfo['subject'] . '</a>', 'display_id' => str_pad($context['ticket_id'], $modSettings['shd_zerofill'], '0', STR_PAD_LEFT), 'status' => $ticketinfo['status'], 'urgency' => array('setting' => $ticketinfo['urgency']), 'private' => array('setting' => $ticketinfo['private'], 'can_change' => false, 'options' => array(0 => 'shd_ticket_notprivate', 1 => 'shd_ticket_private')), 'errors' => array(), 'member' => array('name' => $ticketinfo['starter_name'], 'id' => $ticketinfo['starter_id'], 'link' => shd_profile_link($ticketinfo['starter_name'], $ticketinfo['starter_id'])), 'assigned' => array('id' => $ticketinfo['assigned_id'], 'name' => !empty($ticketinfo['assigned_id']) ? $ticketinfo['assigned_name'] : $txt['shd_unassigned'], 'link' => !empty($ticketinfo['assigned_id']) ? shd_profile_link($ticketinfo['assigned_name'], $ticketinfo['assigned_id']) : '<span class="error">' . $txt['shd_unassigned'] . '</span>'), 'num_replies' => !empty($ticketinfo['num_replies']) ? $ticketinfo['num_replies'] : 0, 'do_attach' => shd_allowed_to('shd_post_attachment', $ticketinfo['dept']), 'reply' => !empty($reply['body']) ? $reply['body'] : '', 'return_to_ticket' => isset($_REQUEST['goback']), 'disable_smileys' => !$new_reply ? !empty($_REQUEST['no_smileys']) : $ticketinfo['smileys_enabled'] == 0);
    $context['can_solve'] = shd_allowed_to('shd_resolve_ticket_any', $ticketinfo['dept']) || shd_allowed_to('shd_resolve_ticket_own', $ticketinfo['dept']) && $ticketinfo['starter_id'] == $user_info['id'];
    $context['can_silent_update'] = $new_reply && shd_allowed_to('shd_silent_update', $ticketinfo['dept']);
    shd_posting_additional_options();
    shd_load_canned_replies();
    $context['can_ping'] = $new_reply && shd_allowed_to('shd_singleton_email', $context['ticket_form']['dept']);
    // Ticket privacy
    if (empty($modSettings['shd_privacy_display']) || $modSettings['shd_privacy_display'] == 'smart') {
        $context['display_private'] = shd_allowed_to('shd_view_ticket_private_any', $ticketinfo['dept']) || shd_allowed_to('shd_alter_privacy_own', $ticketinfo['dept']) || shd_allowed_to('shd_alter_privacy_any', $ticketinfo['dept']) || $context['ticket_form']['private']['setting'];
    } else {
        $context['display_private'] = true;
    }
    loadMemberData($ticketinfo['starter_id']);
    if (loadMemberContext($ticketinfo['starter_id'])) {
        $context['ticket_form']['member']['avatar'] = $memberContext[$ticketinfo['starter_id']]['avatar'];
    }
    if (!empty($ticketinfo['modified_time'])) {
        $context['ticket_form'] += array('modified' => array('name' => $ticketinfo['modified_name'], 'id' => $ticketinfo['modified_id'], 'time' => timeformat($ticketinfo['modified_time']), 'link' => shd_profile_link($ticketinfo['modified_name'], $ticketinfo['modified_id'])));
    }
    shd_get_urgency_options($ticketinfo['is_own'], $ticketinfo['dept']);
    $context['ticket_form']['urgency']['can_change'] = false;
    if (!empty($ticketinfo['num_replies'])) {
        shd_setup_replies($ticketinfo['id_first_msg']);
    }
    // A few basic checks
    if ($context['ticket_form']['status'] == TICKET_STATUS_CLOSED) {
        fatal_lang_error('shd_cannot_reply_closed', false);
    } elseif ($context['ticket_form']['status'] == TICKET_STATUS_DELETED) {
        fatal_lang_error('shd_cannon_reply_deleted', false);
    }
    shd_load_custom_fields(false, $context['ticket_form']['msg'], $context['ticket_form']['dept']);
    shd_load_attachments();
    shd_check_attachments();
    if (empty($options['no_new_reply_warning']) && isset($_REQUEST['num_replies'])) {
        $_REQUEST['num_replies'] = (int) $_REQUEST['num_replies'];
        $newReplies = $context['ticket_form']['num_replies'] > $_REQUEST['num_replies'] ? $context['ticket_form']['num_replies'] - $_REQUEST['num_replies'] : 0;
        if (!empty($newReplies)) {
            loadLanguage('Post');
            if ($newReplies > 1) {
                $txt['error_new_replies_reading'] = sprintf($txt['error_new_replies_reading'], $newReplies);
            }
            $context['shd_errors'][] = $newReplies == 1 ? 'new_reply_reading' : 'new_replies_reading';
        }
    }
    // Are we quoting something? Let's see if we do; we already know we can see the ticket
    $_REQUEST['quote'] = !empty($_REQUEST['quote']) ? (int) $_REQUEST['quote'] : 0;
    if (!empty($_REQUEST['quote'])) {
        $query = shd_db_query('', '
			SELECT hdtr.body, IFNULL(mem.real_name, hdtr.poster_name) AS poster_name, hdtr.poster_time
			FROM {db_prefix}helpdesk_ticket_replies AS hdtr
				LEFT JOIN {db_prefix}members AS mem ON (hdtr.id_member = mem.id_member)
			WHERE id_msg = {int:msg}
				AND id_ticket = {int:ticket}', array('msg' => $_REQUEST['quote'], 'ticket' => $context['ticket_id']));
        if ($row = $smcFunc['db_fetch_assoc']($query)) {
            $smcFunc['db_free_result']($query);
            $row['body'] = un_preparsecode($row['body']);
            // Censor the message!
            censorText($row['body']);
            $row['body'] = preg_replace('~<br ?/?' . '>~i', "\n", $row['body']);
            if (strpos($row['poster_name'], '[') !== false || strpos($row['poster_name'], ']') !== false) {
                $row['poster_name'] = '"' . $row['poster_name'] . '"';
            }
            // Make the body HTML if need be.
            if (!empty($_REQUEST['mode'])) {
                require_once $sourcedir . '/Subs-Editor.php';
                $row['body'] = strtr($row['body'], array('&lt;' => '#smlt#', '&gt;' => '#smgt#', '&amp;' => '#smamp#'));
                $row['body'] = bbc_to_html($row['body']);
                $lb = '<br />';
            } else {
                $lb = "\n";
            }
            $message = '[quote author=' . $row['poster_name'] . ' link=action=helpdesk;sa=ticket;ticket=' . $context['ticket_id'];
            if ($ticketinfo['id_first_msg'] != $_REQUEST['quote']) {
                // don't add the msg if we're quoting the ticket itself
                $message .= '.msg' . $_REQUEST['quote'] . '#msg' . $_REQUEST['quote'];
            }
            $message .= ' date=' . $row['poster_time'] . ']' . $lb . $row['body'] . $lb . '[/quote]';
            $context['ticket_form']['reply'] = $message;
        }
    }
    // Set up the awesomeness that is the rich editor
    shd_postbox('shd_message', $context['ticket_form']['reply'], array('post_button' => !empty($reply['id_msg']) ? $txt['shd_ticket_edit_reply'] : $txt['shd_reply_ticket']));
    // Build the link tree and navigation
    $context['linktree'][] = array('name' => $new_reply ? sprintf($txt['shd_reply_ticket_linktree'], $context['ticket_form']['ticket_link']) : sprintf($txt['shd_edit_reply_linktree'], $context['ticket_form']['reply_link']));
    $context['page_title'] = $txt['shd_helpdesk'];
    $context['sub_template'] = 'reply_post';
    // Register this form in the session variables.
    checkSubmitOnce('register');
}
Exemple #4
0
function QuoteFast()
{
    global $modSettings, $user_info, $txt, $settings, $context;
    global $sourcedir, $smcFunc;
    loadLanguage('Post');
    if (!isset($_REQUEST['xml'])) {
        loadTemplate('Post');
    }
    include_once $sourcedir . '/Subs-Post.php';
    $moderate_boards = boardsAllowedTo('moderate_board');
    // Where we going if we need to?
    $context['post_box_name'] = isset($_GET['pb']) ? $_GET['pb'] : '';
    $request = $smcFunc['db_query']('', '
		SELECT IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body, m.id_topic, m.subject,
			m.id_board, m.id_member, m.approved
		FROM {db_prefix}messages AS m
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
		WHERE m.id_msg = {int:id_msg}' . (isset($_REQUEST['modify']) || !empty($moderate_boards) && $moderate_boards[0] == 0 ? '' : '
			AND (t.locked = {int:not_locked}' . (empty($moderate_boards) ? '' : ' OR b.id_board IN ({array_int:moderation_board_list})') . ')') . '
		LIMIT 1', array('current_member' => $user_info['id'], 'moderation_board_list' => $moderate_boards, 'id_msg' => (int) $_REQUEST['quote'], 'not_locked' => 0));
    $context['close_window'] = $smcFunc['db_num_rows']($request) == 0;
    $row = $smcFunc['db_fetch_assoc']($request);
    $smcFunc['db_free_result']($request);
    $context['sub_template'] = 'quotefast';
    if (!empty($row)) {
        $can_view_post = $row['approved'] || $row['id_member'] != 0 && $row['id_member'] == $user_info['id'] || allowedTo('approve_posts', $row['id_board']);
    }
    if (!empty($can_view_post)) {
        // Remove special formatting we don't want anymore.
        $row['body'] = un_preparsecode($row['body']);
        // Censor the message!
        censorText($row['body']);
        $row['body'] = preg_replace('~<br ?/?' . '>~i', "\n", $row['body']);
        // Want to modify a single message by double clicking it?
        if (isset($_REQUEST['modify'])) {
            censorText($row['subject']);
            $context['sub_template'] = 'modifyfast';
            $context['message'] = array('id' => $_REQUEST['quote'], 'body' => $row['body'], 'subject' => addcslashes($row['subject'], '"'));
            return;
        }
        // Remove any nested quotes.
        if (!empty($modSettings['removeNestedQuotes'])) {
            $row['body'] = preg_replace(array('~\\n?\\[quote.*?\\].+?\\[/quote\\]\\n?~is', '~^\\n~', '~\\[/quote\\]~'), '', $row['body']);
        }
        // Make the body HTML if need be.
        if (!empty($_REQUEST['mode'])) {
            require_once $sourcedir . '/Subs-Editor.php';
            $row['body'] = strtr($row['body'], array('&lt;' => '#smlt#', '&gt;' => '#smgt#', '&amp;' => '#smamp#'));
            $row['body'] = bbc_to_html($row['body']);
            $lb = '<br />';
        } else {
            $lb = "\n";
        }
        // Add a quote string on the front and end.
        $context['quote']['xml'] = '[quote author=' . $row['poster_name'] . ' link=topic=' . $row['id_topic'] . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $row['poster_time'] . ']' . $lb . $row['body'] . $lb . '[/quote]';
        $context['quote']['text'] = strtr(un_htmlspecialchars($context['quote']['xml']), array('\'' => '\\\'', '\\' => '\\\\', "\n" => '\\n', '</script>' => '</\' + \'script>'));
        $context['quote']['xml'] = strtr($context['quote']['xml'], array('&nbsp;' => '&#160;', '<' => '&lt;', '>' => '&gt;'));
        $context['quote']['mozilla'] = strtr($smcFunc['htmlspecialchars']($context['quote']['text']), array('&quot;' => '"'));
    } elseif (isset($_REQUEST['modify'])) {
        $context['sub_template'] = 'modifyfast';
        $context['message'] = array('id' => 0, 'body' => '', 'subject' => '');
    } else {
        $context['quote'] = array('xml' => '', 'mozilla' => '', 'text' => '');
    }
}
/**
 *	Collects a canned reply from the database and serves it via XML for insertion.
 *
 *	Operations:
 *	- Session check; failing in a regular fashion (as opposed to normal return since we're using ;xml in the URL; the SMF handler can deal with that)
 *	- Checks for a department number in the URL, validates access to that department then queries for the requested template.
 *	- Call un_preparsecode to remove extraneous sanity encoding.
 *	- Convert to SMF style BBC-to-HTML if using WYSIWYG
 *	- Do other XML sanitising
 *	- Return via $context['ajax_raw'] for {@link shd_ajax()} to output
*/
function shd_ajax_canned()
{
    global $modSettings, $user_info, $txt, $settings, $context;
    global $sourcedir, $smcFunc;
    loadLanguage('Post');
    checkSession('get');
    include_once $sourcedir . '/Subs-Post.php';
    $_REQUEST['reply'] = !empty($_REQUEST['reply']) ? (int) $_REQUEST['reply'] : 0;
    $message = '';
    if (!empty($_REQUEST['reply']) && !empty($context['ticket_id'])) {
        $query = shd_db_query('', '
			SELECT hdt.id_member_started, hdt.id_dept, hdcr.body, hdcr.vis_user, hdcr.vis_staff
			FROM {db_prefix}helpdesk_tickets AS hdt
				INNER JOIN {db_prefix}helpdesk_cannedreplies_depts AS hdcrd ON (hdt.id_dept = hdcrd.id_dept)
				INNER JOIN {db_prefix}helpdesk_cannedreplies AS hdcr ON (hdcrd.id_reply = hdcr.id_reply)
			WHERE hdt.id_ticket = {int:ticket}
				AND hdcr.id_reply = {int:reply}
				AND hdcr.active = 1
				AND {query_see_ticket}', array('ticket' => $context['ticket_id'], 'reply' => $_REQUEST['reply']));
        if ($smcFunc['db_num_rows']($query) == 0) {
            $smcFunc['db_free_result']($query);
            return $context['ajax_raw'] = '<quote>' . $message . '</quote>';
        }
        $row = $smcFunc['db_fetch_assoc']($query);
        $smcFunc['db_free_result']($query);
        // Check ability to reply to this ticket. No ability to reply at all, no canned reply.
        if (!shd_allowed_to('shd_reply_ticket_own', $row['id_dept']) && !shd_allowed_to('shd_reply_ticket_any', $row['id_dept'])) {
            return $context['ajax_raw'] = '<quote>' . $message . '</quote>';
        }
        // Now check for can-reply-to-own (reply to any will pass this check correctly anyway)
        if (!shd_allowed_to('shd_reply_ticket_any', $row['id_dept']) && shd_allowed_to('shd_reply_ticket_own', $row['id_dept']) && $row['id_member_started'] != $user_info['id']) {
            return $context['ajax_raw'] = '<quote>' . $message . '</quote>';
        }
        // Now verify the per-reply visibility. Only applies to non admins anyway...
        if (!shd_allowed_to('admin_helpdesk', $row['id_dept']) && !$user_info['is_admin']) {
            if (shd_allowed_to('shd_staff', $row['id_dept']) && empty($row['vis_staff'])) {
                return $context['ajax_raw'] = '<quote>' . $message . '</quote>';
            } elseif (!shd_allowed_to('shd_staff', $row['id_dept']) && empty($row['vis_user'])) {
                return $context['ajax_raw'] = '<quote>' . $message . '</quote>';
            }
        }
        $message = un_preparsecode($row['body']);
        // Censor the message!
        censorText($message);
        $message = preg_replace('~<br ?/?' . '>~i', "\n", $row['body']);
        // Make the body HTML if need be.
        if (!empty($_REQUEST['mode'])) {
            require_once $sourcedir . '/Subs-Editor.php';
            $message = strtr($message, array('&lt;' => '#smlt#', '&gt;' => '#smgt#', '&amp;' => '#smamp#'));
            $message = bbc_to_html($message);
            $lb = '<br />';
        } else {
            $lb = "\n";
        }
    }
    $message = strtr($message, array('&nbsp;' => '&#160;', '<' => '&lt;', '>' => '&gt;'));
    $context['ajax_raw'] = '<quote>' . $message . '</quote>';
}