GenericControls.template.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. <div style="width: 98.8%;">
  20. <div>
  21. <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>
  22. </div>
  23. <div id="', $editor_id, '_resizer" class="richedit_resize"></div>
  24. </div>
  25. </div>
  26. <input type="hidden" name="', $editor_id, '_mode" id="', $editor_id, '_mode" value="0" />
  27. <script type="text/javascript"><!-- // --><![CDATA[
  28. var bbc_quote_from = \'', $txt['quote_from'], '\'
  29. var bbc_quote = \'', $txt['quote'], '\'
  30. var bbc_search_on = \'', $txt['search_on'], '\';
  31. (function($) {
  32. var extensionMethods = {
  33. InsertText: function(text) {
  34. var bIsSource = this.inSourceMode();
  35. // @TODO make it put the quote close to the current selection
  36. if (!bIsSource)
  37. this.toggleTextMode();
  38. var current_value = this.getTextareaValue(false) + "\n" + text;
  39. this.setTextareaValue(current_value);
  40. if (!bIsSource)
  41. this.toggleTextMode();
  42. },
  43. getText: function() {
  44. if(this.inSourceMode())
  45. var current_value = this.getTextareaValue(false);
  46. else
  47. var current_value = this.getWysiwygEditorValue();
  48. return current_value;
  49. },
  50. appendEmoticon: function (code, emoticon) {
  51. if (code == \'\')
  52. line.append($(\'<br />\'));
  53. else
  54. line.append($(\'<img />\')
  55. .attr({
  56. src: emoticon,
  57. alt: code,
  58. })
  59. .click(function (e) {
  60. var start = \'\', end = \'\';
  61. if (base.options.emoticonsCompat)
  62. {
  63. start = \'<span> \';
  64. end = \' </span>\';
  65. }
  66. if (base.inSourceMode())
  67. base.textEditorInsertText(\' \' + $(this).attr(\'alt\') + \' \');
  68. else
  69. base.wysiwygEditorInsertHtml(start + \'<img src="\' + $(this).attr("src") +
  70. \'" data-sceditor-emoticon="\' + $(this).attr(\'alt\') + \'" />\' + end);
  71. e.preventDefault();
  72. })
  73. );
  74. if (line.children().length > 0)
  75. content.append(line);
  76. $(".sceditor-toolbar").append(content);
  77. },
  78. createPermanentDropDown: function() {
  79. var emoticons = $.extend({}, this.options.emoticons.dropdown);
  80. content = $(\'<div />\').attr({class: "sceditor-insertemoticon"});
  81. line = $(\'<div />\');
  82. base = this;
  83. if (typeof this.options.emoticons.popup !== "undefined")
  84. {
  85. this.options.emoticons.more = this.options.emoticons.popup;
  86. moreButton = $(\'<div />\').attr({class: "sceditor-more"}).text(', JavaScriptEscape('[' . $txt['more'] . ']'), ').click(function () {
  87. if ($(".sceditor-smileyPopup").length > 0)
  88. {
  89. $(".sceditor-smileyPopup").fadeIn(\'fast\');
  90. }
  91. else
  92. {
  93. var emoticons = $.extend({}, base.options.emoticons.popup);
  94. var basement = $(\'<div />\').attr({class: "sceditor-popup"});
  95. allowHide = true;
  96. popupContent = $(\'<div />\');
  97. line = $(\'<div />\');
  98. closeButton = $(\'<span />\').text(', JavaScriptEscape('[' . $txt['find_close'] . ']'), ').click(function () {
  99. $(".sceditor-smileyPopup").fadeOut(\'fast\');
  100. });
  101. $.each(emoticons, base.appendEmoticon);
  102. if (line.children().length > 0)
  103. popupContent.append(line);
  104. if (typeof closeButton !== "undefined")
  105. popupContent.append(closeButton);
  106. // IE needs unselectable attr to stop it from unselecting the text in the editor.
  107. // The editor can cope if IE does unselect the text it\'s just not nice.
  108. if(base.ieUnselectable !== false) {
  109. content = $(content);
  110. content.find(\':not(input,textarea)\').filter(function() { return this.nodeType===1; }).attr(\'unselectable\', \'on\');
  111. }
  112. $dropdown = $(\'<div class="sceditor-dropdown sceditor-smileyPopup" />\').append(popupContent);
  113. $dropdown.appendTo($(\'body\'));
  114. dropdownIgnoreLastClick = true;
  115. $dropdown.css({
  116. position: "fixed",
  117. top: $(window).height() * 0.2,
  118. left: $(window).width() * 0.5 - ($dropdown.width() / 2),
  119. "max-width": "50%"
  120. });
  121. // stop clicks within the dropdown from being handled
  122. $dropdown.click(function (e) {
  123. e.stopPropagation();
  124. });
  125. }
  126. });
  127. }
  128. $.each(emoticons, base.appendEmoticon);
  129. if (typeof moreButton !== "undefined")
  130. content.append(moreButton);
  131. }
  132. };
  133. $.extend(true, $[\'sceditor\'].prototype, extensionMethods);
  134. })(jQuery);
  135. $(document).ready(function() {
  136. $.sceditor.setCommand(
  137. \'ftp\',
  138. function (caller) {
  139. var editor = this,
  140. content = $(this._(\'<form><div><label for="link">{0}</label> <input type="text" id="link" value="ftp://" /></div>\' +
  141. \'<div><label for="des">{1}</label> <input type="text" id="des" value="" /></div></form>\',
  142. this._("URL:"),
  143. this._("Description (optional):")
  144. ))
  145. .submit(function () {return false;});
  146. content.append($(
  147. this._(\'<div><input type="button" class="button" value="{0}" /></div>\',
  148. this._("Insert")
  149. )).click(function (e) {
  150. var val = $(this).parent("form").find("#link").val(),
  151. description = $(this).parent("form").find("#des").val();
  152. if(val !== "" && val !== "ftp://") {
  153. // needed for IE to reset the last range
  154. editor.focus();
  155. if(!editor.getRangeHelper().selectedHtml() || description)
  156. {
  157. if(!description)
  158. description = val;
  159. editor.wysiwygEditorInsertHtml(\'<a href="\' + val + \'">\' + description + \'</a>\');
  160. }
  161. else
  162. editor.execCommand("createlink", val);
  163. }
  164. editor.closeDropDown(true);
  165. e.preventDefault();
  166. }));
  167. editor.createDropDown(caller, "insertlink", content);
  168. },
  169. ', javaScriptEscape($txt['ftp']), '
  170. );
  171. $.sceditor.setCommand(
  172. \'glow\',
  173. function () {
  174. this.wysiwygEditorInsertText(\'[glow=red,2,300][/glow]\');
  175. },
  176. ', javaScriptEscape($txt['glow']), '
  177. );
  178. $.sceditor.setCommand(
  179. \'shadow\',
  180. function () {
  181. this.wysiwygEditorInsertText(\'[shadow=red,left][/shadow]\');
  182. },
  183. ', javaScriptEscape($txt['shadow']), '
  184. );
  185. $.sceditor.setCommand(
  186. \'tt\',
  187. function () {
  188. this.wysiwygEditorInsertHtml(\'<tt>\', \'</tt>\');
  189. },
  190. ', javaScriptEscape($txt['teletype']), '
  191. );
  192. $("#', $editor_id, '").sceditorBBCodePlugin({
  193. style: "', $settings['default_theme_url'], '/css/jquery.sceditor.default.css",
  194. emoticonsCompat: true,
  195. colors: "black,red,yellow,pink,green,orange,purple,blue,beige,brown,teal,navy,maroon,limegreen,white"';
  196. // Show the smileys.
  197. if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
  198. {
  199. echo ',
  200. emoticons:
  201. {';
  202. $countLocations = count($context['smileys']);
  203. foreach ($context['smileys'] as $location => $smileyRows)
  204. {
  205. $countLocations--;
  206. if ($location == 'postform')
  207. echo '
  208. dropdown:
  209. {';
  210. elseif ($location == 'popup')
  211. echo '
  212. popup:
  213. {';
  214. $numRows = count($smileyRows);
  215. foreach ($smileyRows as $smileyRow)
  216. {
  217. foreach ($smileyRow['smileys'] as $smiley)
  218. {
  219. echo '
  220. ', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape(str_replace($boardurl . '/', '', $settings['smileys_url'] . '/' . $smiley['filename'])), empty($smiley['isLast']) ? ',' : '';
  221. }
  222. if (empty($smileyRow['isLast']) && $numRows != 1)
  223. echo ',
  224. \'\': \'\',';
  225. }
  226. echo '
  227. }', $countLocations != 0 ? ',' : '';
  228. }
  229. echo '
  230. }';
  231. }
  232. if ($context['show_bbc'] && $bbcContainer !== null)
  233. {
  234. echo ',
  235. toolbar: "emoticon,';
  236. $count_tags = count($context['bbc_tags']);
  237. foreach ($context['bbc_toolbar'] as $i => $buttonRow)
  238. {
  239. echo implode('|', $buttonRow);
  240. $count_tags--;
  241. if (!empty($count_tags))
  242. echo '||';
  243. }
  244. echo '",';
  245. }
  246. else
  247. echo ',
  248. toolbar: "emoticon,source",';
  249. /*
  250. // // Now it's all drawn out we'll actually setup the box.
  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: ', !empty($context['smileys']['postform']) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null ? 'oSmileyBox_' . $editor_id : 'null', ',
  264. // oBBCBox: ', $context['show_bbc'] && $bbcContainer !== null ? 'oBBCBox_' . $editor_id : 'null', '
  265. // });
  266. // smf_editorArray[smf_editorArray.length] = oEditorHandle_', $editor_id, ';';
  267. */
  268. echo '
  269. })
  270. $("#', $editor_id, '").data("sceditor").createPermanentDropDown();
  271. $(".sceditor-container").width("100%");
  272. });
  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. ?>