GenericControls.template.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. // This function displays all the stuff you get with a richedit box - BBC, smileys etc.
  13. function template_control_richedit($editor_id, $smileyContainer = null, $bbcContainer = null)
  14. {
  15. global $context, $settings, $options, $txt, $modSettings, $scripturl, $boardurl;
  16. $editor_context = &$context['controls']['richedit'][$editor_id];
  17. echo '
  18. <div>
  19. <textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" rows="', $editor_context['rows'], '" cols="600" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="', $context['tabindex']++, '" style="height: ', $editor_context['height'], '; ', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? 'border: 1px solid red;' : '', '">', $editor_context['value'], '</textarea>
  20. </div>
  21. <input type="hidden" name="', $editor_id, '_mode" id="', $editor_id, '_mode" value="0" />
  22. <script type="text/javascript"><!-- // --><![CDATA[
  23. var bbc_quote_from = \'', $txt['quote_from'], '\'
  24. var bbc_quote = \'', $txt['quote'], '\'
  25. var bbc_search_on = \'', $txt['search_on'], '\';
  26. (function($) {
  27. var extensionMethods = {
  28. InsertText: function(text, bClear) {
  29. var bIsSource = this.inSourceMode();
  30. // @TODO make it put the quote close to the current selection
  31. if (!bIsSource)
  32. this.toggleTextMode();
  33. var current_value = bClear ? text : this.getTextareaValue(false) + "\n" + text;
  34. this.setTextareaValue(current_value);
  35. if (!bIsSource)
  36. this.toggleTextMode();
  37. },
  38. getText: function() {
  39. if(this.inSourceMode())
  40. var current_value = this.getTextareaValue(false);
  41. else
  42. var current_value = this.getWysiwygEditorValue();
  43. return current_value;
  44. },
  45. appendEmoticon: function (code, emoticon) {
  46. if (code == \'\')
  47. line.append($(\'<br />\'));
  48. else
  49. line.append($(\'<img />\')
  50. .attr({
  51. src: emoticon,
  52. alt: code,
  53. })
  54. .click(function (e) {
  55. var start = \'\', end = \'\';
  56. if (base.options.emoticonsCompat)
  57. {
  58. start = \'<span> \';
  59. end = \' </span>\';
  60. }
  61. if (base.inSourceMode())
  62. base.textEditorInsertText(\' \' + $(this).attr(\'alt\') + \' \');
  63. else
  64. base.wysiwygEditorInsertHtml(start + \'<img src="\' + $(this).attr("src") +
  65. \'" data-sceditor-emoticon="\' + $(this).attr(\'alt\') + \'" />\' + end);
  66. e.preventDefault();
  67. })
  68. );
  69. if (line.children().length > 0)
  70. content.append(line);
  71. $(".sceditor-toolbar").append(content);
  72. },
  73. createPermanentDropDown: function() {
  74. var emoticons = $.extend({}, this.options.emoticons.dropdown);
  75. content = $(\'<div />\').attr({class: "sceditor-insertemoticon"});
  76. line = $(\'<div />\');
  77. base = this;
  78. if (typeof this.options.emoticons.popup !== "undefined")
  79. {
  80. this.options.emoticons.more = this.options.emoticons.popup;
  81. moreButton = $(\'<div />\').attr({class: "sceditor-more"}).text(', JavaScriptEscape('[' . $txt['more'] . ']'), ').click(function () {
  82. if ($(".sceditor-smileyPopup").length > 0)
  83. {
  84. $(".sceditor-smileyPopup").fadeIn(\'fast\');
  85. }
  86. else
  87. {
  88. var emoticons = $.extend({}, base.options.emoticons.popup);
  89. var basement = $(\'<div />\').attr({class: "sceditor-popup"});
  90. allowHide = true;
  91. popupContent = $(\'<div />\');
  92. line = $(\'<div />\');
  93. closeButton = $(\'<span />\').text(', JavaScriptEscape('[' . $txt['find_close'] . ']'), ').click(function () {
  94. $(".sceditor-smileyPopup").fadeOut(\'fast\');
  95. });
  96. $.each(emoticons, base.appendEmoticon);
  97. if (line.children().length > 0)
  98. popupContent.append(line);
  99. if (typeof closeButton !== "undefined")
  100. popupContent.append(closeButton);
  101. // IE needs unselectable attr to stop it from unselecting the text in the editor.
  102. // The editor can cope if IE does unselect the text it\'s just not nice.
  103. if(base.ieUnselectable !== false) {
  104. content = $(content);
  105. content.find(\':not(input,textarea)\').filter(function() { return this.nodeType===1; }).attr(\'unselectable\', \'on\');
  106. }
  107. $dropdown = $(\'<div class="sceditor-dropdown sceditor-smileyPopup" />\').append(popupContent);
  108. $dropdown.appendTo($(\'body\'));
  109. dropdownIgnoreLastClick = true;
  110. $dropdown.css({
  111. position: "fixed",
  112. top: $(window).height() * 0.2,
  113. left: $(window).width() * 0.5 - ($dropdown.width() / 2),
  114. "max-width": "50%"
  115. });
  116. // stop clicks within the dropdown from being handled
  117. $dropdown.click(function (e) {
  118. e.stopPropagation();
  119. });
  120. }
  121. });
  122. }
  123. $.each(emoticons, base.appendEmoticon);
  124. if (typeof moreButton !== "undefined")
  125. content.append(moreButton);
  126. }
  127. };
  128. $.extend(true, $[\'sceditor\'].prototype, extensionMethods);
  129. })(jQuery);
  130. $(document).ready(function() {
  131. $.sceditor.setCommand(
  132. \'ftp\',
  133. function (caller) {
  134. var editor = this,
  135. content = $(this._(\'<form><div><label for="link">{0}</label> <input type="text" id="link" value="ftp://" /></div>\' +
  136. \'<div><label for="des">{1}</label> <input type="text" id="des" value="" /></div></form>\',
  137. this._("URL:"),
  138. this._("Description (optional):")
  139. ))
  140. .submit(function () {return false;});
  141. content.append($(
  142. this._(\'<div><input type="button" class="button" value="{0}" /></div>\',
  143. this._("Insert")
  144. )).click(function (e) {
  145. var val = $(this).parent("form").find("#link").val(),
  146. description = $(this).parent("form").find("#des").val();
  147. if(val !== "" && val !== "ftp://") {
  148. // needed for IE to reset the last range
  149. editor.focus();
  150. if(!editor.getRangeHelper().selectedHtml() || description)
  151. {
  152. if(!description)
  153. description = val;
  154. editor.wysiwygEditorInsertHtml(\'<a href="\' + val + \'">\' + description + \'</a>\');
  155. }
  156. else
  157. editor.execCommand("createlink", val);
  158. }
  159. editor.closeDropDown(true);
  160. e.preventDefault();
  161. }));
  162. editor.createDropDown(caller, "insertlink", content);
  163. },
  164. ', javaScriptEscape($txt['ftp']), '
  165. );
  166. $.sceditor.setCommand(
  167. \'glow\',
  168. function () {
  169. this.wysiwygEditorInsertHtml(\'[glow=red,2,300]\', \'[/glow]\');
  170. },
  171. ', javaScriptEscape($txt['glow']), '
  172. );
  173. $.sceditor.setCommand(
  174. \'shadow\',
  175. function () {
  176. this.wysiwygEditorInsertHtml(\'[shadow=red,left]\', \'[/shadow]\');
  177. },
  178. ', javaScriptEscape($txt['shadow']), '
  179. );
  180. $.sceditor.setCommand(
  181. \'tt\',
  182. function () {
  183. this.wysiwygEditorInsertHtml(\'<tt>\', \'</tt>\');
  184. },
  185. ', javaScriptEscape($txt['teletype']), '
  186. );
  187. $("#', $editor_id, '").sceditorBBCodePlugin({
  188. style: "', $settings['default_theme_url'], '/css/jquery.sceditor.default.css",
  189. emoticonsCompat: true,
  190. colors: "black,red,yellow,pink,green,orange,purple,blue,beige,brown,teal,navy,maroon,limegreen,white"';
  191. // Show the smileys.
  192. if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
  193. {
  194. echo ',
  195. emoticons:
  196. {';
  197. $countLocations = count($context['smileys']);
  198. foreach ($context['smileys'] as $location => $smileyRows)
  199. {
  200. $countLocations--;
  201. if ($location == 'postform')
  202. echo '
  203. dropdown:
  204. {';
  205. elseif ($location == 'popup')
  206. echo '
  207. popup:
  208. {';
  209. $numRows = count($smileyRows);
  210. foreach ($smileyRows as $smileyRow)
  211. {
  212. foreach ($smileyRow['smileys'] as $smiley)
  213. {
  214. echo '
  215. ', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape(str_replace($boardurl . '/', '', $settings['smileys_url'] . '/' . $smiley['filename'])), empty($smiley['isLast']) ? ',' : '';
  216. }
  217. if (empty($smileyRow['isLast']) && $numRows != 1)
  218. echo ',
  219. \'\': \'\',';
  220. }
  221. echo '
  222. }', $countLocations != 0 ? ',' : '';
  223. }
  224. echo '
  225. }';
  226. }
  227. if ($context['show_bbc'] && $bbcContainer !== null)
  228. {
  229. echo ',
  230. toolbar: "emoticon,';
  231. $count_tags = count($context['bbc_tags']);
  232. foreach ($context['bbc_toolbar'] as $i => $buttonRow)
  233. {
  234. echo implode('|', $buttonRow);
  235. $count_tags--;
  236. if (!empty($count_tags))
  237. echo '||';
  238. }
  239. echo '",';
  240. }
  241. else
  242. echo ',
  243. toolbar: "emoticon,source",';
  244. echo '
  245. })
  246. $("#', $editor_id, '").data("sceditor").createPermanentDropDown();
  247. $(".sceditor-container").width("100%").height("100%");',
  248. /*$editor_context['rich_active'] ? '$("#' . $editor_id . '").toggleTextMode();' :*/ '', '
  249. });';
  250. // Now for backward compatibility let's collect few infos in the good ol' style
  251. echo '
  252. var oEditorHandle_', $editor_id, ' = new smc_Editor({
  253. sSessionId: smf_session_id,
  254. sSessionVar: smf_session_var,
  255. sFormId: ', JavaScriptEscape($editor_context['form']), ',
  256. sUniqueId: ', JavaScriptEscape($editor_id), ',
  257. bRTL: ', $txt['lang_rtl'] ? 'true' : 'false', ',
  258. bWysiwyg: ', $editor_context['rich_active'] ? 'true' : 'false', ',
  259. sText: ', JavaScriptEscape($editor_context['rich_active'] ? $editor_context['rich_value'] : ''), ',
  260. sEditWidth: ', JavaScriptEscape($editor_context['width']), ',
  261. sEditHeight: ', JavaScriptEscape($editor_context['height']), ',
  262. bRichEditOff: ', empty($modSettings['disable_wysiwyg']) ? 'false' : 'true', ',
  263. oSmileyBox: null,
  264. oBBCBox: null
  265. });
  266. // smf_editorArray[smf_editorArray.length] = oEditorHandle_', $editor_id, ';
  267. // ]]></script>';
  268. }
  269. function template_control_richedit_buttons($editor_id)
  270. {
  271. global $context, $settings, $options, $txt, $modSettings, $scripturl;
  272. $editor_context = &$context['controls']['richedit'][$editor_id];
  273. echo '
  274. <input type="submit" value="', isset($editor_context['labels']['post_button']) ? $editor_context['labels']['post_button'] : $txt['post'], '" tabindex="', $context['tabindex']++, '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />';
  275. if ($editor_context['preview_type'])
  276. echo '
  277. <input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', $context['tabindex']++, '" onclick="', $editor_context['preview_type'] == 2 ? 'return event.ctrlKey || previewPost();' : 'return submitThisOnce(this);', '" accesskey="p" class="button_submit" />';
  278. if ($context['show_spellchecking'])
  279. echo '
  280. <input type="button" value="', $txt['spell_check'], '" tabindex="', $context['tabindex']++, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button_submit" />';
  281. }
  282. // What's this, verification?!
  283. function template_control_verification($verify_id, $display_type = 'all', $reset = false)
  284. {
  285. global $context, $settings, $options, $txt, $modSettings;
  286. $verify_context = &$context['controls']['verification'][$verify_id];
  287. // Keep track of where we are.
  288. if (empty($verify_context['tracking']) || $reset)
  289. $verify_context['tracking'] = 0;
  290. // How many items are there to display in total.
  291. $total_items = count($verify_context['questions']) + ($verify_context['show_visual'] ? 1 : 0);
  292. // If we've gone too far, stop.
  293. if ($verify_context['tracking'] > $total_items)
  294. return false;
  295. // Loop through each item to show them.
  296. for ($i = 0; $i < $total_items; $i++)
  297. {
  298. // If we're after a single item only show it if we're in the right place.
  299. if ($display_type == 'single' && $verify_context['tracking'] != $i)
  300. continue;
  301. if ($display_type != 'single')
  302. echo '
  303. <div id="verification_control_', $i, '" class="verification_control">';
  304. // Do the actual stuff - image first?
  305. if ($i == 0 && $verify_context['show_visual'])
  306. {
  307. if ($context['use_graphic_library'])
  308. echo '
  309. <img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '" />';
  310. else
  311. echo '
  312. <img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1" />
  313. <img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2" />
  314. <img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3" />
  315. <img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4" />
  316. <img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5" />
  317. <img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6" />';
  318. if (WIRELESS)
  319. echo '<br />
  320. <input type="text" name="', $verify_id, '_vv[code]" value="', !empty($verify_context['text_value']) ? $verify_context['text_value'] : '', '" size="30" tabindex="', $context['tabindex']++, '" class="input_text" />';
  321. else
  322. echo '
  323. <div class="smalltext" style="margin: 4px 0 8px 0;">
  324. <a href="', $verify_context['image_href'], ';sound" id="visual_verification_', $verify_id, '_sound" rel="nofollow">', $txt['visual_verification_sound'], '</a> / <a href="#visual_verification_', $verify_id, '_refresh" id="visual_verification_', $verify_id, '_refresh">', $txt['visual_verification_request_new'], '</a>', $display_type != 'quick_reply' ? '<br />' : '', '<br />
  325. ', $txt['visual_verification_description'], ':', $display_type != 'quick_reply' ? '<br />' : '', '
  326. <input type="text" name="', $verify_id, '_vv[code]" value="', !empty($verify_context['text_value']) ? $verify_context['text_value'] : '', '" size="30" tabindex="', $context['tabindex']++, '" class="input_text" />
  327. </div>';
  328. }
  329. else
  330. {
  331. // Where in the question array is this question?
  332. $qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
  333. echo '
  334. <div class="smalltext">
  335. ', $verify_context['questions'][$qIndex]['q'], ':<br />
  336. <input type="text" name="', $verify_id, '_vv[q][', $verify_context['questions'][$qIndex]['id'], ']" size="30" value="', $verify_context['questions'][$qIndex]['a'], '" ', $verify_context['questions'][$qIndex]['is_error'] ? 'style="border: 1px red solid;"' : '', ' tabindex="', $context['tabindex']++, '" class="input_text" />
  337. </div>';
  338. }
  339. if ($display_type != 'single')
  340. echo '
  341. </div>';
  342. // If we were displaying just one and we did it, break.
  343. if ($display_type == 'single' && $verify_context['tracking'] == $i)
  344. break;
  345. }
  346. // Assume we found something, always,
  347. $verify_context['tracking']++;
  348. // Tell something displaying piecemeal to keep going.
  349. if ($display_type == 'single')
  350. return true;
  351. }
  352. ?>