GenericControls.template.php 16 KB

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