GenericControls.template.php 19 KB

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