GenericControls.template.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 + "\n" : this.getTextareaValue(false) + "\n" + text + "\n";
  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. var popup_exists = false;
  76. content = $(\'<div />\').attr({class: "sceditor-insertemoticon"});
  77. line = $(\'<div />\');
  78. base = this;
  79. for (smiley_popup in this.options.emoticons.popup)
  80. {
  81. popup_exists = true;
  82. break;
  83. }
  84. if (popup_exists)
  85. {
  86. this.options.emoticons.more = this.options.emoticons.popup;
  87. moreButton = $(\'<div />\').attr({class: "sceditor-more"}).text(', JavaScriptEscape('[' . $txt['more'] . ']'), ').click(function () {
  88. if ($(".sceditor-smileyPopup").length > 0)
  89. {
  90. $(".sceditor-smileyPopup").fadeIn(\'fast\');
  91. }
  92. else
  93. {
  94. var emoticons = $.extend({}, base.options.emoticons.popup);
  95. var basement = $(\'<div />\').attr({class: "sceditor-popup"});
  96. allowHide = true;
  97. popupContent = $(\'<div />\');
  98. line = $(\'<div />\');
  99. closeButton = $(\'<span />\').text(', JavaScriptEscape('[' . $txt['find_close'] . ']'), ').click(function () {
  100. $(".sceditor-smileyPopup").fadeOut(\'fast\');
  101. });
  102. $.each(emoticons, base.appendEmoticon);
  103. if (line.children().length > 0)
  104. popupContent.append(line);
  105. if (typeof closeButton !== "undefined")
  106. popupContent.append(closeButton);
  107. // IE needs unselectable attr to stop it from unselecting the text in the editor.
  108. // The editor can cope if IE does unselect the text it\'s just not nice.
  109. if(base.ieUnselectable !== false) {
  110. content = $(content);
  111. content.find(\':not(input,textarea)\').filter(function() { return this.nodeType===1; }).attr(\'unselectable\', \'on\');
  112. }
  113. $dropdown = $(\'<div class="sceditor-dropdown sceditor-smileyPopup" />\').append(popupContent);
  114. $dropdown.appendTo($(\'body\'));
  115. dropdownIgnoreLastClick = true;
  116. $dropdown.css({
  117. position: "fixed",
  118. top: $(window).height() * 0.2,
  119. left: $(window).width() * 0.5 - ($dropdown.width() / 2),
  120. "max-width": "50%"
  121. });
  122. // stop clicks within the dropdown from being handled
  123. $dropdown.click(function (e) {
  124. e.stopPropagation();
  125. });
  126. }
  127. });
  128. }
  129. $.each(emoticons, base.appendEmoticon);
  130. if (typeof moreButton !== "undefined")
  131. content.append(moreButton);
  132. }
  133. };
  134. $.extend(true, $[\'sceditor\'].prototype, extensionMethods);
  135. })(jQuery);
  136. $(document).ready(function() {
  137. $.sceditor.setCommand(
  138. \'ftp\',
  139. function (caller) {
  140. var editor = this,
  141. content = $(this._(\'<form><div><label for="link">{0}</label> <input type="text" id="link" value="ftp://" /></div>\' +
  142. \'<div><label for="des">{1}</label> <input type="text" id="des" value="" /></div></form>\',
  143. this._("URL:"),
  144. this._("Description (optional):")
  145. ))
  146. .submit(function () {return false;});
  147. content.append($(
  148. this._(\'<div><input type="button" class="button" value="{0}" /></div>\',
  149. this._("Insert")
  150. )).click(function (e) {
  151. var val = $(this).parent("form").find("#link").val(),
  152. description = $(this).parent("form").find("#des").val();
  153. if(val !== "" && val !== "ftp://") {
  154. // needed for IE to reset the last range
  155. editor.focus();
  156. if(!editor.getRangeHelper().selectedHtml() || description)
  157. {
  158. if(!description)
  159. description = val;
  160. editor.wysiwygEditorInsertHtml(\'<a href="\' + val + \'">\' + description + \'</a>\');
  161. }
  162. else
  163. editor.execCommand("createlink", val);
  164. }
  165. editor.closeDropDown(true);
  166. e.preventDefault();
  167. }));
  168. editor.createDropDown(caller, "insertlink", content);
  169. },
  170. ', javaScriptEscape($txt['ftp']), '
  171. );
  172. $.sceditor.setCommand(
  173. \'glow\',
  174. function () {
  175. this.wysiwygEditorInsertHtml(\'[glow=red,2,300]\', \'[/glow]\');
  176. },
  177. ', javaScriptEscape($txt['glow']), '
  178. );
  179. $.sceditor.setCommand(
  180. \'shadow\',
  181. function () {
  182. this.wysiwygEditorInsertHtml(\'[shadow=red,left]\', \'[/shadow]\');
  183. },
  184. ', javaScriptEscape($txt['shadow']), '
  185. );
  186. $.sceditor.setCommand(
  187. \'tt\',
  188. function () {
  189. this.wysiwygEditorInsertHtml(\'<tt>\', \'</tt>\');
  190. },
  191. ', javaScriptEscape($txt['teletype']), '
  192. );
  193. $("#', $editor_id, '").sceditorBBCodePlugin({
  194. style: "', $settings['default_theme_url'], '/css/jquery.sceditor.default.css",
  195. emoticonsCompat: true,
  196. colors: "black,red,yellow,pink,green,orange,purple,blue,beige,brown,teal,navy,maroon,limegreen,white"';
  197. // Show the smileys.
  198. if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
  199. {
  200. echo ',
  201. emoticons:
  202. {';
  203. $countLocations = count($context['smileys']);
  204. foreach ($context['smileys'] as $location => $smileyRows)
  205. {
  206. $countLocations--;
  207. if ($location == 'postform')
  208. echo '
  209. dropdown:
  210. {';
  211. elseif ($location == 'popup')
  212. echo '
  213. popup:
  214. {';
  215. $numRows = count($smileyRows);
  216. foreach ($smileyRows as $smileyRow)
  217. {
  218. foreach ($smileyRow['smileys'] as $smiley)
  219. {
  220. echo '
  221. ', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape(str_replace($boardurl . '/', '', $settings['smileys_url'] . '/' . $smiley['filename'])), empty($smiley['isLast']) ? ',' : '';
  222. }
  223. if (empty($smileyRow['isLast']) && $numRows != 1)
  224. echo ',
  225. \'\': \'\',';
  226. }
  227. echo '
  228. }', $countLocations != 0 ? ',' : '';
  229. }
  230. echo '
  231. }';
  232. }
  233. if ($context['show_bbc'] && $bbcContainer !== null)
  234. {
  235. echo ',
  236. toolbar: "emoticon,';
  237. $count_tags = count($context['bbc_tags']);
  238. foreach ($context['bbc_toolbar'] as $i => $buttonRow)
  239. {
  240. echo implode('|', $buttonRow);
  241. $count_tags--;
  242. if (!empty($count_tags))
  243. echo '||';
  244. }
  245. echo '",';
  246. }
  247. else
  248. echo ',
  249. toolbar: "emoticon,source",';
  250. echo '
  251. })
  252. $("#', $editor_id, '").data("sceditor").createPermanentDropDown();
  253. $(".sceditor-container").width("100%").height("100%");',
  254. /*$editor_context['rich_active'] ? '$("#' . $editor_id . '").toggleTextMode();' :*/ '', '
  255. });';
  256. // Now for backward compatibility let's collect few infos in the good ol' style
  257. echo '
  258. var oEditorHandle_', $editor_id, ' = new smc_Editor({
  259. sSessionId: smf_session_id,
  260. sSessionVar: smf_session_var,
  261. sFormId: ', JavaScriptEscape($editor_context['form']), ',
  262. sUniqueId: ', JavaScriptEscape($editor_id), ',
  263. bRTL: ', $txt['lang_rtl'] ? 'true' : 'false', ',
  264. bWysiwyg: ', $editor_context['rich_active'] ? 'true' : 'false', ',
  265. sText: ', JavaScriptEscape($editor_context['rich_active'] ? $editor_context['rich_value'] : ''), ',
  266. sEditWidth: ', JavaScriptEscape($editor_context['width']), ',
  267. sEditHeight: ', JavaScriptEscape($editor_context['height']), ',
  268. bRichEditOff: ', empty($modSettings['disable_wysiwyg']) ? 'false' : 'true', ',
  269. oSmileyBox: null,
  270. oBBCBox: null
  271. });
  272. // smf_editorArray[smf_editorArray.length] = oEditorHandle_', $editor_id, ';
  273. // ]]></script>';
  274. }
  275. function template_control_richedit_buttons($editor_id)
  276. {
  277. global $context, $settings, $options, $txt, $modSettings, $scripturl;
  278. $editor_context = &$context['controls']['richedit'][$editor_id];
  279. echo '
  280. <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" />';
  281. if ($editor_context['preview_type'])
  282. echo '
  283. <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" />';
  284. if ($context['show_spellchecking'])
  285. echo '
  286. <input type="button" value="', $txt['spell_check'], '" tabindex="', $context['tabindex']++, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button_submit" />';
  287. }
  288. // What's this, verification?!
  289. function template_control_verification($verify_id, $display_type = 'all', $reset = false)
  290. {
  291. global $context, $settings, $options, $txt, $modSettings;
  292. $verify_context = &$context['controls']['verification'][$verify_id];
  293. // Keep track of where we are.
  294. if (empty($verify_context['tracking']) || $reset)
  295. $verify_context['tracking'] = 0;
  296. // How many items are there to display in total.
  297. $total_items = count($verify_context['questions']) + ($verify_context['show_visual'] ? 1 : 0);
  298. // If we've gone too far, stop.
  299. if ($verify_context['tracking'] > $total_items)
  300. return false;
  301. // Loop through each item to show them.
  302. for ($i = 0; $i < $total_items; $i++)
  303. {
  304. // If we're after a single item only show it if we're in the right place.
  305. if ($display_type == 'single' && $verify_context['tracking'] != $i)
  306. continue;
  307. if ($display_type != 'single')
  308. echo '
  309. <div id="verification_control_', $i, '" class="verification_control">';
  310. // Do the actual stuff - image first?
  311. if ($i == 0 && $verify_context['show_visual'])
  312. {
  313. if ($context['use_graphic_library'])
  314. echo '
  315. <img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '" />';
  316. else
  317. echo '
  318. <img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1" />
  319. <img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2" />
  320. <img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3" />
  321. <img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4" />
  322. <img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5" />
  323. <img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6" />';
  324. if (WIRELESS)
  325. echo '<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. else
  328. echo '
  329. <div class="smalltext" style="margin: 4px 0 8px 0;">
  330. <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 />
  331. ', $txt['visual_verification_description'], ':', $display_type != 'quick_reply' ? '<br />' : '', '
  332. <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" />
  333. </div>';
  334. }
  335. else
  336. {
  337. // Where in the question array is this question?
  338. $qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
  339. echo '
  340. <div class="smalltext">
  341. ', $verify_context['questions'][$qIndex]['q'], ':<br />
  342. <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" />
  343. </div>';
  344. }
  345. if ($display_type != 'single')
  346. echo '
  347. </div>';
  348. // If we were displaying just one and we did it, break.
  349. if ($display_type == 'single' && $verify_context['tracking'] == $i)
  350. break;
  351. }
  352. // Assume we found something, always,
  353. $verify_context['tracking']++;
  354. // Tell something displaying piecemeal to keep going.
  355. if ($display_type == 'single')
  356. return true;
  357. }
  358. ?>