GenericControls.template.php 17 KB

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