GenericControls.template.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. <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>
  20. </div>
  21. <input type="hidden" name="', $editor_id, '_mode" id="', $editor_id, '_mode" value="0" />
  22. <script type="text/javascript"><!-- // --><![CDATA[
  23. var bbc_quote_from = \'', $txt['quote_from'], '\'
  24. var bbc_quote = \'', $txt['quote'], '\'
  25. var bbc_search_on = \'', $txt['search_on'], '\';
  26. $(document).ready(function() {
  27. ', !empty($context['bbcodes_hanlders']) ? $context['bbcodes_hanlders'] : '', '
  28. $("#', $editor_id, '").sceditorBBCodePlugin({
  29. style: "', $settings['default_theme_url'], '/css/jquery.sceditor.default.css",
  30. emoticonsCompat: true,
  31. supportedWysiwyg: (((is_ie5up && !is_ie50) || is_ff || is_opera95up || is_safari || is_chrome) && !(is_iphone || is_android)),',
  32. !empty($txt['lang_locale']) && substr($txt['lang_locale'], 0, 5) != 'en_US' ? '
  33. locale: \'' . $txt['lang_locale'] . '\',' : '', '
  34. colors: "black,red,yellow,pink,green,orange,purple,blue,beige,brown,teal,navy,maroon,limegreen,white"';
  35. // Show the smileys.
  36. if ((!empty($context['smileys']['postform']) || !empty($context['smileys']['popup'])) && !$editor_context['disable_smiley_box'] && $smileyContainer !== null)
  37. {
  38. echo ',
  39. emoticons:
  40. {';
  41. $countLocations = count($context['smileys']);
  42. foreach ($context['smileys'] as $location => $smileyRows)
  43. {
  44. $countLocations--;
  45. if ($location == 'postform')
  46. echo '
  47. dropdown:
  48. {';
  49. elseif ($location == 'popup')
  50. echo '
  51. popup:
  52. {';
  53. $numRows = count($smileyRows);
  54. foreach ($smileyRows as $smileyRow)
  55. {
  56. foreach ($smileyRow['smileys'] as $smiley)
  57. {
  58. echo '
  59. ', JavaScriptEscape($smiley['code']), ': ', JavaScriptEscape(str_replace($boardurl . '/', '', $settings['smileys_url'] . '/' . $smiley['filename'])), empty($smiley['isLast']) ? ',' : '';
  60. }
  61. if (empty($smileyRow['isLast']) && $numRows != 1)
  62. echo ',
  63. \'\': \'\',';
  64. }
  65. echo '
  66. }', $countLocations != 0 ? ',' : '';
  67. }
  68. echo '
  69. }';
  70. }
  71. if ($context['show_bbc'] && $bbcContainer !== null)
  72. {
  73. echo ',
  74. toolbar: "emoticon,';
  75. $count_tags = count($context['bbc_tags']);
  76. foreach ($context['bbc_toolbar'] as $i => $buttonRow)
  77. {
  78. echo implode('|', $buttonRow);
  79. $count_tags--;
  80. if (!empty($count_tags))
  81. echo '||';
  82. }
  83. echo '",';
  84. }
  85. else
  86. echo ',
  87. toolbar: "emoticon,source",';
  88. echo '
  89. });
  90. $("#', $editor_id, '").data("sceditor").createPermanentDropDown();
  91. $(".sceditor-container").width("100%").height("100%");',
  92. $editor_context['rich_active'] ? '' : '
  93. $("#' . $editor_id . '").data("sceditor").setTextMode();', '
  94. if (!(((is_ie5up && !is_ie50) || is_ff || is_opera95up || is_safari || is_chrome) && !(is_iphone || is_android)))
  95. {
  96. $("#' . $editor_id . '").data("sceditor").setTextMode();
  97. $(".sceditor-button-source").hide();
  98. }
  99. });';
  100. // Now for backward compatibility let's collect few infos in the good ol' style
  101. echo '
  102. var oEditorHandle_', $editor_id, ' = new smc_Editor({
  103. sUniqueId: ', JavaScriptEscape($editor_id), ',
  104. sEditWidth: ', JavaScriptEscape($editor_context['width']), ',
  105. sEditHeight: ', JavaScriptEscape($editor_context['height']), ',
  106. bRichEditOff: ', empty($modSettings['disable_wysiwyg']) ? 'false' : 'true', ',
  107. oSmileyBox: null,
  108. oBBCBox: null
  109. });
  110. smf_editorArray[smf_editorArray.length] = oEditorHandle_', $editor_id, ';
  111. // ]]></script>';
  112. }
  113. function template_control_richedit_buttons($editor_id)
  114. {
  115. global $context, $settings, $options, $txt, $modSettings, $scripturl;
  116. $editor_context = &$context['controls']['richedit'][$editor_id];
  117. echo '
  118. <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" />';
  119. if ($editor_context['preview_type'])
  120. echo '
  121. <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" />';
  122. if ($context['show_spellchecking'])
  123. echo '
  124. <input type="button" value="', $txt['spell_check'], '" tabindex="', $context['tabindex']++, '" onclick="oEditorHandle_', $editor_id, '.spellCheckStart();" class="button_submit" />';
  125. }
  126. // What's this, verification?!
  127. function template_control_verification($verify_id, $display_type = 'all', $reset = false)
  128. {
  129. global $context, $settings, $options, $txt, $modSettings;
  130. $verify_context = &$context['controls']['verification'][$verify_id];
  131. // Keep track of where we are.
  132. if (empty($verify_context['tracking']) || $reset)
  133. $verify_context['tracking'] = 0;
  134. // How many items are there to display in total.
  135. $total_items = count($verify_context['questions']) + ($verify_context['show_visual'] ? 1 : 0);
  136. // If we've gone too far, stop.
  137. if ($verify_context['tracking'] > $total_items)
  138. return false;
  139. // Loop through each item to show them.
  140. for ($i = 0; $i < $total_items; $i++)
  141. {
  142. // If we're after a single item only show it if we're in the right place.
  143. if ($display_type == 'single' && $verify_context['tracking'] != $i)
  144. continue;
  145. if ($display_type != 'single')
  146. echo '
  147. <div id="verification_control_', $i, '" class="verification_control">';
  148. // Do the actual stuff - image first?
  149. if ($i == 0 && $verify_context['show_visual'])
  150. {
  151. if ($context['use_graphic_library'])
  152. echo '
  153. <img src="', $verify_context['image_href'], '" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '" />';
  154. else
  155. echo '
  156. <img src="', $verify_context['image_href'], ';letter=1" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_1" />
  157. <img src="', $verify_context['image_href'], ';letter=2" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_2" />
  158. <img src="', $verify_context['image_href'], ';letter=3" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_3" />
  159. <img src="', $verify_context['image_href'], ';letter=4" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_4" />
  160. <img src="', $verify_context['image_href'], ';letter=5" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_5" />
  161. <img src="', $verify_context['image_href'], ';letter=6" alt="', $txt['visual_verification_description'], '" id="verification_image_', $verify_id, '_6" />';
  162. if (WIRELESS)
  163. echo '<br />
  164. <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" />';
  165. else
  166. echo '
  167. <div class="smalltext" style="margin: 4px 0 8px 0;">
  168. <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 />
  169. ', $txt['visual_verification_description'], ':', $display_type != 'quick_reply' ? '<br />' : '', '
  170. <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" />
  171. </div>';
  172. }
  173. else
  174. {
  175. // Where in the question array is this question?
  176. $qIndex = $verify_context['show_visual'] ? $i - 1 : $i;
  177. echo '
  178. <div class="smalltext">
  179. ', $verify_context['questions'][$qIndex]['q'], ':<br />
  180. <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" />
  181. </div>';
  182. }
  183. if ($display_type != 'single')
  184. echo '
  185. </div>';
  186. // If we were displaying just one and we did it, break.
  187. if ($display_type == 'single' && $verify_context['tracking'] == $i)
  188. break;
  189. }
  190. // Assume we found something, always,
  191. $verify_context['tracking']++;
  192. // Tell something displaying piecemeal to keep going.
  193. if ($display_type == 'single')
  194. return true;
  195. }
  196. ?>