PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/application/maxsite/plugins/spoiler/index.php

https://code.google.com/p/maxsite/
PHP | 200 lines | 169 code | 13 blank | 18 comment | 13 complexity | adfb2068087b1b45e00a9de858ff3bff MD5 | raw file
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * For MaxSite CMS
  4. * Spoiler Plugin
  5. * Author: (c) Tux
  6. * Plugin URL: http://6log.ru/spoiler
  7. */
  8. # ??????? ??????????????? ???????
  9. function spoiler_autoload($args = array())
  10. {
  11. mso_hook_add( 'head', 'spoiler_head');
  12. mso_hook_add( 'content', 'spoiler_custom'); # ??? ?? ????? ????????
  13. $options_key = 'plugin_spoiler';
  14. $options = mso_get_option($options_key, 'plugins', array());
  15. if ( isset($options['comments']) and ( $options['comments'] == 1) )
  16. {
  17. mso_hook_add( 'comments_content_out', 'spoiler_custom');
  18. }
  19. }
  20. # ??????? ??????????? ??? ???????????? ???????
  21. function spoiler_uninstall($args = array())
  22. {
  23. // ?????????
  24. $options_key = 'plugin_spoiler';
  25. mso_delete_option($options_key,'plugins');
  26. return $args;
  27. }
  28. # ??????? ???????
  29. function spoiler_custom($text)
  30. {
  31. // ?????????
  32. $options_key = 'plugin_spoiler';
  33. /* ?????????*/
  34. $options = mso_get_option($options_key, 'plugins', array());
  35. if ( !isset($options['hide']) ) $options['hide'] = t('??????',__FILE__);
  36. if ( !isset($options['show']) ) $options['show'] = t('????????...',__FILE__);
  37. if ( !isset($options['comments']) ) $options['comments'] = 0;
  38. $showtext = $options['show'];
  39. $hidetext = $options['hide'];
  40. // dont edit!
  41. //$pattern = '@(\[spoiler\](.*?)\[/spoiler\])@is';
  42. $pattern = "@\[spoiler(=)?(.*?)\](.*?)\[\/spoiler\]@is";
  43. // ?????? [spoiler]...[/spoiler] ?????
  44. if (preg_match_all($pattern, $text, $matches))
  45. {
  46. for ($i = 0; $i < count($matches[0]); $i++)
  47. {
  48. //$id = 'id'.rand();
  49. $id = 'id' . rand(100,999);
  50. $html = '';
  51. if ($matches[1][$i] == '=')
  52. {
  53. if ( strpos($matches[2][$i], "/") !== false )
  54. {
  55. $matches[2][$i] = str_replace("'", "\'", $matches[2][$i]);
  56. $matches[2][$i] = str_replace("\"", "&quot;", $matches[2][$i]);
  57. $tm = explode("/", $matches[2][$i]);
  58. if ( strpos($matches[2][$i], "/") === 0 )
  59. {
  60. $hidetext = $tm[1];
  61. $showtext = $options['show'];
  62. }
  63. else
  64. {
  65. $hidetext = $tm[1];
  66. $showtext = $tm[0];
  67. }
  68. }
  69. else
  70. {
  71. $showtext = $matches[2][$i];
  72. $hidetext = $options['hide'];
  73. }
  74. }
  75. else
  76. {
  77. $showtext = $options['show'];
  78. $hidetext = $options['hide'];
  79. }
  80. $html .= '<a class="spoiler_link_show" href="javascript:void(0)" onclick="SpoilerToggle(\'' . $id . '\', this, \'' . $showtext.'\', \'' . $hidetext . '\')">' . $showtext . '</a></p>';
  81. $html .= '<div class="spoiler_div" id="' . $id . '" style="display:none"><p>' . $matches[3][$i] . '</p></div>';
  82. //$text = str_replace($matches[0][$i], $html, $text);
  83. $text = preg_replace($pattern, $html, $text, 1);
  84. }
  85. }
  86. return $text;
  87. }
  88. # JavaScript & css text ????????? ? head
  89. function spoiler_head($args = array())
  90. {
  91. $options_key = 'plugin_spoiler';
  92. $options = mso_get_option($options_key, 'plugins', array());
  93. if ( !isset($options['style']) ) $options['style'] = '';
  94. if ($options['style'] != '')
  95. {
  96. echo '
  97. <link rel="stylesheet" href="' . getinfo('plugins_url') . 'spoiler/style/'.$options['style']. '" type="text/css" media="screen">';
  98. }
  99. echo '
  100. <script type="text/javascript">
  101. function SpoilerToggle(id, link, showtext, hidetext)
  102. {
  103. var spoiler = document.getElementById(id);
  104. if (spoiler.style.display != "none")
  105. {
  106. spoiler.style.display = "none";
  107. link.innerHTML = showtext;
  108. link.className = "spoiler_link_show";
  109. }
  110. else
  111. {
  112. spoiler.style.display = "block";
  113. link.innerHTML = hidetext;
  114. link.className = "spoiler_link_hide";
  115. }
  116. }
  117. </script>
  118. ';
  119. }
  120. # ??????? ?????????????? ????????? ??????? (function ??????_mso_options)
  121. function spoiler_mso_options()
  122. {
  123. mso_cur_dir_lang(__FILE__);
  124. //// ????? ?? wp-converter
  125. $CI = & get_instance();
  126. // ?????? ??? ????? ?? ????? *.css
  127. $CI->load->helper('directory');
  128. // $dir = directory_map(getinfo('uploads_dir'), true); // ?????? ? ??????? ????????
  129. $path = getinfo('plugins_dir').'spoiler/style/';
  130. $dir = directory_map($path, true);
  131. if (!$dir) $dir = array();
  132. natsort($dir);
  133. $option_select = '';
  134. $option_select .= '||' . t('??? ??????');
  135. foreach ($dir as $file)
  136. {
  137. if (@is_dir(getinfo('plugins_url').'spoiler/style/' . $file)) continue; // ??? ???????
  138. if (preg_match('|(.*?)\.css|', $file))
  139. {
  140. $option_select .= '#'. $file . '||' . $file;
  141. }
  142. }
  143. ////
  144. # ????, ???, ????? ???????
  145. mso_admin_plugin_options('plugin_spoiler', 'plugins',
  146. array(
  147. 'hide' => array(
  148. 'type' => 'text',
  149. 'name' => t('????????:'),
  150. 'description' => t('????? ????????? ????? ????? ???????? ? ????????? ????'),
  151. 'default' => t('??????')
  152. ),
  153. 'show' => array(
  154. 'type' => 'text',
  155. 'name' => t('????????:'),
  156. 'description' => t('????? ????????? ????? ????? ???????? ? ??????? ????'),
  157. 'default' => t('????????...')
  158. ),
  159. 'style' => array(
  160. 'type' => 'select',
  161. 'name' => t('???? ??????:'),
  162. 'description' => t('????? ????? ? ????????? ?????: (.../plugins/spoiler/style/)'),
  163. 'values' => $option_select,
  164. 'default' => ''
  165. ),
  166. 'comments' => array(
  167. 'type' => 'checkbox',
  168. 'name' => t('???????????? ???????? ? ????????????'),
  169. 'description' => t(' '),
  170. 'default' => 0
  171. ),
  172. ),
  173. t('????????? ??????? Spoiler'), // ?????
  174. t('<p>? ??????? ????? ??????? ?? ?????? ???????? ????? ??? ???????.<br>??? ????????????? ??????? ???????? ?????? ????? ? ??? [spoiler]??? ?????[/spoiler]</p><p class="info">????? ???????? ????? ????????: <br>[spoiler=????????]??? ?????[/spoiler], [spoiler=????????/????????]??? ?????[/spoiler], [spoiler=/????????]??? ?????[/spoiler]</p>') // ????
  175. );
  176. }
  177. ?>