GenericControls.template.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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. var current_value = this.getWysiwygEditorValue() + "\n" + text;
  36. // @TODO make it put the quote close to the current selection
  37. if (!bIsSource)
  38. this.toggleTextMode();
  39. this.setTextareaValue(current_value);
  40. if (!bIsSource)
  41. this.toggleTextMode();
  42. }
  43. };
  44. $.extend(true, $[\'sceditor\'].prototype, extensionMethods);
  45. })(jQuery);
  46. $(document).ready(function() {
  47. $("#' . $editor_id . '").sceditorBBCodePlugin({
  48. style: "' . $settings['default_theme_url'] . '/css/jquery.sceditor.default.css"';
  49. // Show the smileys.
  50. if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
  51. {
  52. echo ',
  53. emoticons:
  54. {';
  55. $countLocations = count($context['smileys']);
  56. foreach ($context['smileys'] as $location => $smileyRows)
  57. {
  58. $countLocations--;
  59. if ($location == 'postform')
  60. echo '
  61. dropdown:
  62. {';
  63. elseif ($location == 'popup')
  64. echo '
  65. more:
  66. {';
  67. $numRows = count($smileyRows);
  68. foreach ($smileyRows as $smileyRow)
  69. {
  70. foreach ($smileyRow['smileys'] as $smiley)
  71. {
  72. echo '
  73. ', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape(str_replace($boardurl . '/', '', $settings['smileys_url'] . '/' . $smiley['filename'])), empty($smiley['isLast']) ? ',' : '';
  74. }
  75. if (empty($smileyRow['isLast']) && $numRows != 1)
  76. echo ',
  77. \'\': \'\',';
  78. }
  79. echo '
  80. }', $countLocations != 0 ? ',' : '';
  81. }
  82. echo '
  83. }';
  84. /*
  85. emoticons:
  86. {
  87. // emoticons to be included in the dropdown
  88. dropdown: {
  89. ":)": "emoticons/smile.png",
  90. ":angel:": "emoticons/angel.png"
  91. },
  92. // emoticons to be included in the more section
  93. more: {
  94. ":alien:": "emoticons/alien.png",
  95. ":blink:": "emoticons/blink.png"
  96. },
  97. // emoticons that are not shwon in the dropdown but will be converted ATY
  98. hidden: {
  99. ":aliasforalien:": "emoticons/alien.png",
  100. ":aliasforblink:": "emoticons/blink.png"
  101. }
  102. },*/
  103. }
  104. // Show the smileys.
  105. // if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
  106. // {
  107. // echo '
  108. // var oSmileyBox_', $editor_id, ' = new smc_SmileyBox({
  109. // sUniqueId: ', JavaScriptEscape('smileyBox_' . $editor_id), ',
  110. // sContainerDiv: ', JavaScriptEscape($smileyContainer), ',
  111. // sClickHandler: ', JavaScriptEscape('oEditorHandle_' . $editor_id . '.insertSmiley'), ',
  112. // oSmileyLocations: {';
  113. //
  114. // foreach ($context['smileys'] as $location => $smileyRows)
  115. // {
  116. // echo '
  117. // ', $location, ': [';
  118. // foreach ($smileyRows as $smileyRow)
  119. // {
  120. // echo '
  121. // [';
  122. // foreach ($smileyRow['smileys'] as $smiley)
  123. // echo '
  124. // {
  125. // sCode: ', JavaScriptEscape($smiley['code']), ',
  126. // sSrc: ', JavaScriptEscape($settings['smileys_url'] . '/' . $smiley['filename']), ',
  127. // sDescription: ', JavaScriptEscape($smiley['description']), '
  128. // }', empty($smiley['isLast']) ? ',' : '';
  129. //
  130. // echo '
  131. // ]', empty($smileyRow['isLast']) ? ',' : '';
  132. // }
  133. // echo '
  134. // ]', $location === 'postform' ? ',' : '';
  135. // }
  136. // echo '
  137. // },
  138. // sSmileyBoxTemplate: ', JavaScriptEscape('
  139. // %smileyRows% %moreSmileys%
  140. // '), ',
  141. // sSmileyRowTemplate: ', JavaScriptEscape('
  142. // <div>%smileyRow%</div>
  143. // '), ',
  144. // sSmileyTemplate: ', JavaScriptEscape('
  145. // <img src="%smileySource%" align="bottom" alt="%smileyDescription%" title="%smileyDescription%" id="%smileyId%" />
  146. // '), ',
  147. // sMoreSmileysTemplate: ', JavaScriptEscape('
  148. // <a href="#" id="%moreSmileysId%">[' . (!empty($context['smileys']['postform']) ? $txt['more_smileys'] : $txt['more_smileys_pick']) . ']</a>
  149. // '), ',
  150. // sMoreSmileysLinkId: ', JavaScriptEscape('moreSmileys_' . $editor_id), ',
  151. // sMoreSmileysPopupTemplate: ', JavaScriptEscape('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  152. // <html>
  153. // <head>
  154. // <title>' . $txt['more_smileys_title'] . '</title>
  155. // <link rel="stylesheet" type="text/css" href="' . $settings['theme_url'] . '/css/index' . $context['theme_variant'] . '.css?alp21" />
  156. // </head>
  157. // <body id="help_popup">
  158. // <div class="padding windowbg">
  159. // <div class="cat_bar">
  160. // <h3 class="catbg">
  161. // ' . $txt['more_smileys_pick'] . '
  162. // </h3>
  163. // </div>
  164. // <div class="padding">
  165. // %smileyRows%
  166. // </div>
  167. // <div class="smalltext centertext">
  168. // <a href="#" id="%moreSmileysCloseLinkId%">' . $txt['more_smileys_close_window'] . '</a>
  169. // </div>
  170. // </div>
  171. // </body>
  172. // </html>'), '
  173. // });';
  174. // }
  175. // if ($context['show_bbc'] && $bbcContainer !== null)
  176. // {
  177. // echo '
  178. // var oBBCBox_', $editor_id, ' = new smc_BBCButtonBox({
  179. // sUniqueId: ', JavaScriptEscape('BBCBox_' . $editor_id), ',
  180. // sContainerDiv: ', JavaScriptEscape($bbcContainer), ',
  181. // sButtonClickHandler: ', JavaScriptEscape('oEditorHandle_' . $editor_id . '.handleButtonClick'), ',
  182. // sSelectChangeHandler: ', JavaScriptEscape('oEditorHandle_' . $editor_id . '.handleSelectChange'), ',
  183. // aButtonRows: [';
  184. //
  185. // // Here loop through the array, printing the images/rows/separators!
  186. // foreach ($context['bbc_tags'] as $i => $buttonRow)
  187. // {
  188. // echo '
  189. // [';
  190. // foreach ($buttonRow as $tag)
  191. // {
  192. // // Is there a "before" part for this bbc button? If not, it can't be a button!!
  193. // if (isset($tag['before']))
  194. // echo '
  195. // {
  196. // sType: \'button\',
  197. // bEnabled: ', empty($context['disabled_tags'][$tag['code']]) ? 'true' : 'false', ',
  198. // sImage: ', file_exists($settings['theme_dir'] . '/images/bbc/' . $tag['image'] . '.png') ? JavaScriptEscape($settings['images_url'] . '/bbc/' . $tag['image'] . '.png') : JavaScriptEscape($settings['images_url'] . '/bbc/' . $tag['image'] . '.gif'), ',
  199. // sCode: ', JavaScriptEscape($tag['code']), ',
  200. // sBefore: ', JavaScriptEscape($tag['before']), ',
  201. // sAfter: ', isset($tag['after']) ? JavaScriptEscape($tag['after']) : 'null', ',
  202. // sDescription: ', JavaScriptEscape($tag['description']), '
  203. // }', empty($tag['isLast']) ? ',' : '';
  204. //
  205. // // Must be a divider then.
  206. // else
  207. // echo '
  208. // {
  209. // sType: \'divider\'
  210. // }', empty($tag['isLast']) ? ',' : '';
  211. // }
  212. //
  213. // // Add the select boxes to the first row.
  214. // if ($i == 0)
  215. // {
  216. // // Show the font drop down...
  217. // if (!isset($context['disabled_tags']['font']))
  218. // echo ',
  219. // {
  220. // sType: \'select\',
  221. // sName: \'sel_face\',
  222. // oOptions: {
  223. // \'\': ', JavaScriptEscape($txt['font_face']), ',
  224. // \'courier\': \'Courier\',
  225. // \'arial\': \'Arial\',
  226. // \'arial black\': \'Arial Black\',
  227. // \'impact\': \'Impact\',
  228. // \'verdana\': \'Verdana\',
  229. // \'times new roman\': \'Times New Roman\',
  230. // \'georgia\': \'Georgia\',
  231. // \'andale mono\': \'Andale Mono\',
  232. // \'trebuchet ms\': \'Trebuchet MS\',
  233. // \'comic sans ms\': \'Comic Sans MS\'
  234. // }
  235. // }';
  236. //
  237. // // Font sizes anyone?
  238. // if (!isset($context['disabled_tags']['size']))
  239. // echo ',
  240. // {
  241. // sType: \'select\',
  242. // sName: \'sel_size\',
  243. // oOptions: {
  244. // \'\': ', JavaScriptEscape($txt['font_size']), ',
  245. // \'1\': \'8pt\',
  246. // \'2\': \'10pt\',
  247. // \'3\': \'12pt\',
  248. // \'4\': \'14pt\',
  249. // \'5\': \'18pt\',
  250. // \'6\': \'24pt\',
  251. // \'7\': \'36pt\'
  252. // }
  253. // }';
  254. //
  255. // // Print a drop down list for all the colors we allow!
  256. // if (!isset($context['disabled_tags']['color']))
  257. // echo ',
  258. // {
  259. // sType: \'select\',
  260. // sName: \'sel_color\',
  261. // oOptions: {
  262. // \'\': ', JavaScriptEscape($txt['change_color']), ',
  263. // \'black\': ', JavaScriptEscape($txt['black']), ',
  264. // \'red\': ', JavaScriptEscape($txt['red']), ',
  265. // \'yellow\': ', JavaScriptEscape($txt['yellow']), ',
  266. // \'pink\': ', JavaScriptEscape($txt['pink']), ',
  267. // \'green\': ', JavaScriptEscape($txt['green']), ',
  268. // \'orange\': ', JavaScriptEscape($txt['orange']), ',
  269. // \'purple\': ', JavaScriptEscape($txt['purple']), ',
  270. // \'blue\': ', JavaScriptEscape($txt['blue']), ',
  271. // \'beige\': ', JavaScriptEscape($txt['beige']), ',
  272. // \'brown\': ', JavaScriptEscape($txt['brown']), ',
  273. // \'teal\': ', JavaScriptEscape($txt['teal']), ',
  274. // \'navy\': ', JavaScriptEscape($txt['navy']), ',
  275. // \'maroon\': ', JavaScriptEscape($txt['maroon']), ',
  276. // \'limegreen\': ', JavaScriptEscape($txt['lime_green']), ',
  277. // \'white\': ', JavaScriptEscape($txt['white']), '
  278. // }
  279. // }';
  280. // }
  281. // echo '
  282. // ]', $i == count($context['bbc_tags']) - 1 ? '' : ',';
  283. // }
  284. // echo '
  285. // ],
  286. // sButtonTemplate: ', JavaScriptEscape('
  287. // <img id="%buttonId%" src="%buttonSrc%" align="bottom" width="23" height="22" alt="%buttonDescription%" title="%buttonDescription%" />
  288. // '), ',
  289. // sButtonBackgroundImage: ', JavaScriptEscape($settings['images_url'] . '/bbc/bbc_bg.png'), ',
  290. // sButtonBackgroundImageHover: ', JavaScriptEscape($settings['images_url'] . '/bbc/bbc_hoverbg.png'), ',
  291. // sActiveButtonBackgroundImage: ', JavaScriptEscape($settings['images_url'] . '/bbc/bbc_hoverbg.png'), ',
  292. // sDividerTemplate: ', JavaScriptEscape('
  293. // <img src="' . $settings['images_url'] . '/bbc/divider.png" alt="|" style="margin: 0 3px;" />
  294. // '), ',
  295. // sSelectTemplate: ', JavaScriptEscape('
  296. // <select name="%selectName%" id="%selectId%" style="margin-bottom: 1ex; font-size: x-small;">
  297. // %selectOptions%
  298. // </select>
  299. // '), ',
  300. // sButtonRowTemplate: ', JavaScriptEscape('
  301. // <div>%buttonRow%</div>
  302. // '), '
  303. // });';
  304. // }
  305. // // Now it's all drawn out we'll actually setup the box.
  306. // echo '
  307. // var oEditorHandle_', $editor_id, ' = new smc_Editor({
  308. // sSessionId: smf_session_id,
  309. // sSessionVar: smf_session_var,
  310. // sFormId: ', JavaScriptEscape($editor_context['form']), ',
  311. // sUniqueId: ', JavaScriptEscape($editor_id), ',
  312. // bRTL: ', $txt['lang_rtl'] ? 'true' : 'false', ',
  313. // bWysiwyg: ', $editor_context['rich_active'] ? 'true' : 'false', ',
  314. // sText: ', JavaScriptEscape($editor_context['rich_active'] ? $editor_context['rich_value'] : ''), ',
  315. // sEditWidth: ', JavaScriptEscape($editor_context['width']), ',
  316. // sEditHeight: ', JavaScriptEscape($editor_context['height']), ',
  317. // bRichEditOff: ', empty($modSettings['disable_wysiwyg']) ? 'false' : 'true', ',
  318. // oSmileyBox: ', !empty($context['smileys']['postform']) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null ? 'oSmileyBox_' . $editor_id : 'null', ',
  319. // oBBCBox: ', $context['show_bbc'] && $bbcContainer !== null ? 'oBBCBox_' . $editor_id : 'null', '
  320. // });
  321. // smf_editorArray[smf_editorArray.length] = oEditorHandle_', $editor_id, ';';
  322. echo '
  323. });
  324. });
  325. // ]]></script>';
  326. }
  327. function template_control_richedit_buttons($editor_id)
  328. {
  329. global $context, $settings, $options, $txt, $modSettings, $scripturl;
  330. $editor_context = &$context['controls']['richedit'][$editor_id];
  331. echo '
  332. <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" />';
  333. if ($editor_context['preview_type'])
  334. echo '
  335. <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" />';
  336. if ($context['show_spellchecking'])
  337. echo '
  338. <input type="button" value="', $txt['spell_check'], '" tabindex="', $context['tabindex']++, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button_submit" />';
  339. }
  340. // What's this, verification?!
  341. function template_control_verification($verify_id, $display_type = 'all', $reset = false)
  342. {
  343. global $context, $settings, $options, $txt, $modSettings;
  344. $verify_context = &$context['controls']['verification'][$verify_id];
  345. // Keep track of where we are.
  346. if (empty($verify_context['tracking']) || $reset)
  347. $verify_context['tracking'] = 0;
  348. // How many items are there to display in total.
  349. $total_items = count($verify_context['questions']) + ($verify_context['show_visual'] ? 1 : 0);
  350. // If we've gone too far, stop.
  351. if ($verify_context['tracking'] > $total_items)
  352. return false;
  353. // Loop through each item to show them.
  354. for ($i = 0; $i < $total_items; $i++)
  355. {
  356. // If we're after a single item only show it if we're in the right place.
  357. if ($display_type == 'single' && $verify_context['tracking'] != $i)
  358. continue;
  359. if ($display_type != 'single')
  360. echo '
  361. <div id="verification_control_', $i, '" class="verification_control">';
  362. // Do the actual stuff - image first?
  363. if ($i == 0 && $verify_context['show_visual'])
  364. {
  365. if ($context['use_graphic_library'])
  366. echo '
  367. <img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '" />';
  368. else
  369. echo '
  370. <img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1" />
  371. <img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2" />
  372. <img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3" />
  373. <img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4" />
  374. <img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5" />
  375. <img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6" />';
  376. if (WIRELESS)
  377. echo '<br />
  378. <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" />';
  379. else
  380. echo '
  381. <div class="smalltext" style="margin: 4px 0 8px 0;">
  382. <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 />
  383. ', $txt['visual_verification_description'], ':', $display_type != 'quick_reply' ? '<br />' : '', '
  384. <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" />
  385. </div>';
  386. }
  387. else
  388. {
  389. // Where in the question array is this question?
  390. $qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
  391. echo '
  392. <div class="smalltext">
  393. ', $verify_context['questions'][$qIndex]['q'], ':<br />
  394. <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" />
  395. </div>';
  396. }
  397. if ($display_type != 'single')
  398. echo '
  399. </div>';
  400. // If we were displaying just one and we did it, break.
  401. if ($display_type == 'single' && $verify_context['tracking'] == $i)
  402. break;
  403. }
  404. // Assume we found something, always,
  405. $verify_context['tracking']++;
  406. // Tell something displaying piecemeal to keep going.
  407. if ($display_type == 'single')
  408. return true;
  409. }
  410. ?>