GenericControls.template.php 15 KB

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