GenericControls.template.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2014 Simple Machines and individual contributors
  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, $modSettings;
  16. $editor_context = &$context['controls']['richedit'][$editor_id];
  17. echo '
  18. <div>
  19. <div>
  20. <div>
  21. <textarea class="editor" name="', $editor_id, '" id="', $editor_id, '" rows="" cols="600" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="', $context['tabindex']++, '" style="width: ', $editor_context['width'], ';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. $(document).ready(function() {
  29. ', !empty($context['bbcodes_handlers']) ? $context['bbcodes_handlers'] : '', '
  30. $("#', $editor_id, '").sceditor({
  31. style: "', $settings['default_theme_url'], '/css/jquery.sceditor.default.css",
  32. emoticonsCompat: true,',
  33. !empty($editor_context['locale']) ? '
  34. locale: \'' . $editor_context['locale'] . '\',' : '', '
  35. colors: "black,red,yellow,pink,green,orange,purple,blue,beige,brown,teal,navy,maroon,limegreen,white",
  36. plugins: "bbcode",
  37. parserOptions: {
  38. quoteType: $.sceditor.BBCodeParser.QuoteType.auto
  39. }';
  40. // Show the smileys.
  41. if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
  42. {
  43. echo ',
  44. emoticons:
  45. {';
  46. $countLocations = count($context['smileys']);
  47. foreach ($context['smileys'] as $location => $smileyRows)
  48. {
  49. $countLocations--;
  50. if ($location == 'postform')
  51. echo '
  52. dropdown:
  53. {';
  54. elseif ($location == 'popup')
  55. echo '
  56. popup:
  57. {';
  58. $numRows = count($smileyRows);
  59. // This is needed because otherwise the editor will remove all the duplicate (empty) keys and leave only 1 additional line
  60. $emptyPlaceholder = 0;
  61. foreach ($smileyRows as $smileyRow)
  62. {
  63. foreach ($smileyRow['smileys'] as $smiley)
  64. {
  65. echo '
  66. ', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape($settings['smileys_url'] . '/' . $smiley['filename']), empty($smiley['isLast']) ? ',' : '';
  67. }
  68. if (empty($smileyRow['isLast']) && $numRows != 1)
  69. echo ',
  70. \'-', $emptyPlaceholder++, '\': \'\',';
  71. }
  72. echo '
  73. }', $countLocations != 0 ? ',' : '';
  74. }
  75. echo '
  76. }';
  77. }
  78. else
  79. echo ',
  80. emoticons:
  81. {}';
  82. if ($context['show_bbc'] && $bbcContainer !== null)
  83. {
  84. echo ',
  85. toolbar: "emoticon,';
  86. $count_tags = count($context['bbc_tags']);
  87. foreach ($context['bbc_toolbar'] as $i => $buttonRow)
  88. {
  89. echo implode('|', $buttonRow);
  90. $count_tags--;
  91. if (!empty($count_tags))
  92. echo '||';
  93. }
  94. echo '",';
  95. }
  96. else
  97. echo ',
  98. toolbar: "emoticon,source",';
  99. echo '
  100. });
  101. $("#', $editor_id, '").data("sceditor").createPermanentDropDown();
  102. $(".sceditor-container").width("100%").height("100%");',
  103. $editor_context['rich_active'] ? '' : '
  104. $("#' . $editor_id . '").data("sceditor").setTextMode();', '
  105. if (!(is_ie || is_ie11 || is_ff || is_opera || is_safari || is_chrome))
  106. {
  107. $("#' . $editor_id . '").data("sceditor").setTextMode();
  108. $(".sceditor-button-source").hide();
  109. }', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? '
  110. $(".sceditor-container").find("textarea").each(function() {$(this).css({border: "1px solid red"})});
  111. $(".sceditor-container").find("iframe").each(function() {$(this).css({border: "1px solid red"})});' : '', '
  112. });';
  113. // Now for backward compatibility let's collect few infos in the good ol' style
  114. echo '
  115. var oEditorHandle_', $editor_id, ' = new smc_Editor({
  116. sUniqueId: ', JavaScriptEscape($editor_id), ',
  117. sEditWidth: ', JavaScriptEscape($editor_context['width']), ',
  118. sEditHeight: ', JavaScriptEscape($editor_context['height']), ',
  119. bRichEditOff: ', empty($modSettings['disable_wysiwyg']) ? 'false' : 'true', ',
  120. oSmileyBox: null,
  121. oBBCBox: null
  122. });
  123. smf_editorArray[smf_editorArray.length] = oEditorHandle_', $editor_id, ';
  124. // ]]></script>';
  125. }
  126. function template_control_richedit_buttons($editor_id)
  127. {
  128. global $context, $settings, $options, $txt, $modSettings, $scripturl;
  129. $editor_context = &$context['controls']['richedit'][$editor_id];
  130. echo '
  131. <span class="smalltext">
  132. ', $context['shortcuts_text'], '
  133. </span>
  134. <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" />';
  135. if ($editor_context['preview_type'])
  136. echo '
  137. <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" />';
  138. if ($context['show_spellchecking'])
  139. echo '
  140. <input type="button" value="', $txt['spell_check'], '" tabindex="', $context['tabindex']++, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button_submit" />';
  141. if (!empty($context['drafts_save']))
  142. {
  143. // Show the save draft button
  144. echo '
  145. <input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', $context['tabindex']++, '" onclick="return confirm(' . JavaScriptEscape($txt['draft_save_note']) . ') && submitThisOnce(this);" accesskey="d" class="button_submit" />
  146. <input type="hidden" id="id_draft" name="id_draft" value="', empty($context['id_draft']) ? 0 : $context['id_draft'], '" />';
  147. // Start an instance of the auto saver if its enabled
  148. if (!empty($context['drafts_autosave']) && !empty($options['drafts_autosave_enabled']))
  149. echo '
  150. <br />
  151. <span class="righttext padding" style="display: block">
  152. <span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon" />&nbsp;</span>
  153. <span id="draft_lastautosave" ></span>
  154. </span>
  155. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/drafts.js?alp21"></script>
  156. <script type="text/javascript"><!-- // --><![CDATA[
  157. var oDraftAutoSave = new smf_DraftAutoSave({
  158. sSelf: \'oDraftAutoSave\',
  159. sLastNote: \'draft_lastautosave\',
  160. sLastID: \'id_draft\',
  161. sSceditorID: \'', $editor_id, '\',
  162. sType: \'post\',
  163. iBoard: ', (empty($context['current_board']) ? 0 : $context['current_board']), ',
  164. iFreq: ', $context['drafts_autosave_frequency'], '
  165. });
  166. // ]]></script>';
  167. }
  168. if (!empty($context['drafts_pm_save']))
  169. {
  170. // The PM draft save button
  171. echo '
  172. <input type="submit" name="save_draft" value="', $txt['draft_save'], '" tabindex="', $context['tabindex']++, '" onclick="submitThisOnce(this);" accesskey="d" class="button_submit" />
  173. <input type="hidden" id="id_pm_draft" name="id_pm_draft" value="', empty($context['id_pm_draft']) ? 0 : $context['id_pm_draft'], '" />';
  174. // Load in the PM autosaver if its enabled and the user wants to use it
  175. if (!empty($context['drafts_autosave']) && !empty($options['drafts_autosave_enabled']))
  176. echo '
  177. <span class="righttext padding" style="display: block">
  178. <span id="throbber" style="display:none"><img src="' . $settings['images_url'] . '/loading_sm.gif" alt="" class="centericon" />&nbsp;</span>
  179. <span id="draft_lastautosave" ></span>
  180. </span>
  181. <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/drafts.js?alp21"></script>
  182. <script type="text/javascript"><!-- // --><![CDATA[
  183. var oDraftAutoSave = new smf_DraftAutoSave({
  184. sSelf: \'oDraftAutoSave\',
  185. sLastNote: \'draft_lastautosave\',
  186. sLastID: \'id_pm_draft\',
  187. sSceditorID: \'', $editor_id, '\',
  188. sType: \'post\',
  189. bPM: true,
  190. iBoard: 0,
  191. iFreq: ', (empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000), '
  192. });
  193. // ]]></script>';
  194. }
  195. }
  196. // What's this, verification?!
  197. function template_control_verification($verify_id, $display_type = 'all', $reset = false)
  198. {
  199. global $context, $options, $txt, $modSettings;
  200. $verify_context = &$context['controls']['verification'][$verify_id];
  201. // Keep track of where we are.
  202. if (empty($verify_context['tracking']) || $reset)
  203. $verify_context['tracking'] = 0;
  204. // How many items are there to display in total.
  205. $total_items = count($verify_context['questions']) + ($verify_context['show_visual'] ? 1 : 0);
  206. // If we've gone too far, stop.
  207. if ($verify_context['tracking'] > $total_items)
  208. return false;
  209. // Loop through each item to show them.
  210. for ($i = 0; $i < $total_items; $i++)
  211. {
  212. // If we're after a single item only show it if we're in the right place.
  213. if ($display_type == 'single' && $verify_context['tracking'] != $i)
  214. continue;
  215. if ($display_type != 'single')
  216. echo '
  217. <div id="verification_control_', $i, '" class="verification_control">';
  218. // Display empty field, but only if we have one, and it's the first time.
  219. if ($verify_context['empty_field'] && empty($i))
  220. echo '
  221. <div class="smalltext vv_special">
  222. ', $txt['visual_verification_hidden'], ':
  223. <input type="text" name="', $_SESSION[$verify_id . '_vv']['empty_field'], '" autocomplete="off" size="30" value="" />
  224. </div>
  225. <br />';
  226. // Do the actual stuff - image first?
  227. if ($i == 0 && $verify_context['show_visual'])
  228. {
  229. if ($context['use_graphic_library'])
  230. echo '
  231. <img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '" />';
  232. else
  233. echo '
  234. <img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1" />
  235. <img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2" />
  236. <img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3" />
  237. <img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4" />
  238. <img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5" />
  239. <img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6" />';
  240. if (WIRELESS)
  241. echo '<br />
  242. <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" />';
  243. else
  244. echo '
  245. <div class="smalltext" style="margin: 4px 0 8px 0;">
  246. <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 />
  247. ', $txt['visual_verification_description'], ':', $display_type != 'quick_reply' ? '<br />' : '', '
  248. <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" />
  249. </div>';
  250. }
  251. else
  252. {
  253. // Where in the question array is this question?
  254. $qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
  255. echo '
  256. <div class="smalltext">
  257. ', $verify_context['questions'][$qIndex]['q'], ':<br />
  258. <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" />
  259. </div>';
  260. }
  261. if ($display_type != 'single')
  262. echo '
  263. </div>';
  264. // If we were displaying just one and we did it, break.
  265. if ($display_type == 'single' && $verify_context['tracking'] == $i)
  266. break;
  267. }
  268. // Assume we found something, always,
  269. $verify_context['tracking']++;
  270. // Tell something displaying piecemeal to keep going.
  271. if ($display_type == 'single')
  272. return true;
  273. }
  274. ?>