PageRenderTime 61ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/yet-another-related-posts-plugin/options.php

https://github.com/howardlei82/IGSM-Website
PHP | 279 lines | 230 code | 37 blank | 12 comment | 32 complexity | 60aee53e3bfbe205d608c3ee63c6f3e6 MD5 | raw file
  1. <?php
  2. global $wpdb, $yarpp_value_options, $yarpp_binary_options, $wp_version, $yarpp_cache, $yarpp_templateable, $yarpp_myisam;
  3. // Reenforce YARPP setup:
  4. if (!get_option('yarpp_version'))
  5. yarpp_activate();
  6. else
  7. yarpp_upgrade_check();
  8. // if action=flush, reset the cache
  9. if (isset($_GET['action']) && $_GET['action'] == 'flush') {
  10. $yarpp_cache->flush();
  11. }
  12. // check to see that templates are in the right place
  13. $yarpp_templateable = (count(glob(STYLESHEETPATH . '/yarpp-template-*.php')) > 0);
  14. if (!$yarpp_templateable) {
  15. yarpp_set_option('use_template',false);
  16. yarpp_set_option('rss_use_template',false);
  17. }
  18. // 3.3: move version checking here, in PHP:
  19. if ( current_user_can('update_plugins' ) ) {
  20. $yarpp_version_info = yarpp_version_info();
  21. // these strings are not localizable, as long as the plugin data on wordpress.org
  22. // cannot be.
  23. $slug = 'yet-another-related-posts-plugin';
  24. $plugin_name = 'Yet Another Related Posts Plugin';
  25. $file = basename(YARPP_DIR) . '/yarpp.php';
  26. if ( $yarpp_version_info['result'] == 'new' ) {
  27. // make sure the update system is aware of this version
  28. $current = get_site_transient( 'update_plugins' );
  29. if ( !isset( $current->response[ $file ] ) ) {
  30. delete_site_transient( 'update_plugins' );
  31. wp_update_plugins();
  32. }
  33. echo '<div class="updated"><p>';
  34. $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $slug . '&TB_iframe=true&width=600&height=800');
  35. printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a> or <a href="%5$s">update automatically</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $yarpp_version_info['current']['version'], wp_nonce_url( self_admin_url('update.php?action=upgrade-plugin&plugin=') . $file, 'upgrade-plugin_' . $file) );
  36. echo '</p></div>';
  37. } else if ( $yarpp_version_info['result'] == 'newbeta' ) {
  38. echo '<div class="updated"><p>';
  39. printf(__("There is a new beta (%s) of Yet Another Related Posts Plugin. You can <a href=\"%s\">download it here</a> at your own risk.","yarpp"), $yarpp_version_info['beta']['version'], $yarpp_version_info['beta']['url']);
  40. echo '</p></div>';
  41. }
  42. }
  43. if (isset($_POST['myisam_override'])) {
  44. yarpp_set_option('myisam_override',1);
  45. echo "<div class='updated'>"
  46. .__("The MyISAM check has been overridden. You may now use the \"consider titles\" and \"consider bodies\" relatedness criteria.",'yarpp')
  47. ."</div>";
  48. }
  49. $yarpp_myisam = true;
  50. if (!yarpp_get_option('myisam_override')) {
  51. $yarpp_check_return = yarpp_myisam_check();
  52. if ($yarpp_check_return !== true) { // if it's not *exactly* true
  53. echo "<div class='updated'>"
  54. .sprintf(__("YARPP's \"consider titles\" and \"consider bodies\" relatedness criteria require your <code>%s</code> table to use the <a href='http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html'>MyISAM storage engine</a>, but the table seems to be using the <code>%s</code> engine. These two options have been disabled.",'yarpp'),$wpdb->posts,$yarpp_check_return)
  55. ."<br />"
  56. .sprintf(__("To restore these features, please update your <code>%s</code> table by executing the following SQL directive: <code>ALTER TABLE `%s` ENGINE = MyISAM;</code> . No data will be erased by altering the table's engine, although there are performance implications.",'yarpp'),$wpdb->posts,$wpdb->posts)
  57. ."<br />"
  58. .sprintf(__("If, despite this check, you are sure that <code>%s</code> is using the MyISAM engine, press this magic button:",'yarpp'),$wpdb->posts)
  59. ."<br />"
  60. ."<form method='post'><input type='submit' class='button' name='myisam_override' value='"
  61. .__("Trust me. Let me use MyISAM features.",'yarpp')
  62. ."'></input></form>"
  63. ."</div>";
  64. yarpp_set_option('title',1);
  65. yarpp_set_option('body',1);
  66. $yarpp_myisam = false;
  67. }
  68. }
  69. if ($yarpp_myisam && !yarpp_enabled()) {
  70. echo '<div class="updated"><p>';
  71. if (yarpp_activate()) {
  72. _e('The YARPP database had an error but has been fixed.','yarpp');
  73. } else {
  74. _e('The YARPP database has an error which could not be fixed.','yarpp');
  75. printf(__('Please try <a href="%s" target="_blank">manual SQL setup</a>.','yarpp'), 'http://mitcho.com/code/yarpp/sql.php?prefix='.urlencode($wpdb->prefix));
  76. }
  77. echo '</div></p>';
  78. }
  79. if (isset($_POST['update_yarpp'])) {
  80. foreach (array_keys($yarpp_value_options) as $option) {
  81. if (isset($_POST[$option]) && is_string($_POST[$option]))
  82. yarpp_set_option($option,addslashes($_POST[$option]));
  83. }
  84. foreach (array('title','body','tags','categories') as $key) {
  85. if (!isset($_POST[$key])) yarpp_set_option($key,1);
  86. }
  87. if (isset($_POST['discats'])) {
  88. yarpp_set_option('discats',implode(',',array_keys($_POST['discats']))); // discats is different
  89. } else {
  90. yarpp_set_option('discats','');
  91. }
  92. if (isset($_POST['distags'])) {
  93. yarpp_set_option('distags',implode(',',array_keys($_POST['distags']))); // distags is also different
  94. } else {
  95. yarpp_set_option('distags','');
  96. }
  97. foreach (array_keys($yarpp_binary_options) as $option) {
  98. (isset($_POST[$option])) ? yarpp_set_option($option,1) : yarpp_set_option($option,0);
  99. }
  100. echo '<div class="updated fade"><p>'.__('Options saved!','yarpp').'</p></div>';
  101. }
  102. ?>
  103. <script type="text/javascript">
  104. //<!--
  105. // since 3.3: add screen option toggles
  106. jQuery(function() {
  107. postboxes.add_postbox_toggles(pagenow);
  108. });
  109. var spinner = '<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>';
  110. function load_display_demo_web() {
  111. jQuery.ajax({type:'POST',
  112. url: ajaxurl,
  113. data:'action=yarpp_display_demo_web',
  114. beforeSend:function(){jQuery('#display_demo_web').eq(0).html('<img src="' + spinner + '" alt="loading..."/>')},
  115. success:function(html){jQuery('#display_demo_web').eq(0).html('<pre>'+html+'</pre>')},
  116. dataType:'html'}
  117. )
  118. }
  119. function load_display_demo_rss() {
  120. jQuery.ajax({type:'POST',
  121. url: ajaxurl,
  122. data:'action=yarpp_display_demo_rss',
  123. beforeSend:function(){jQuery('#display_demo_rss').eq(0).html('<img src="'+spinner+'" alt="loading..."/>')},
  124. success:function(html){jQuery('#display_demo_rss').eq(0).html('<pre>'+html+'</pre>')},
  125. dataType:'html'}
  126. )
  127. }
  128. function load_display_distags() {
  129. jQuery.ajax({type:'POST',
  130. url: ajaxurl,
  131. data:'action=yarpp_display_distags',
  132. beforeSend:function(){jQuery('#display_distags').eq(0).html('<img src="'+spinner+'" alt="loading..."/>')},
  133. success:function(html){jQuery('#display_distags').eq(0).html(html)},
  134. dataType:'html'}
  135. )
  136. }
  137. function load_display_discats() {
  138. jQuery.ajax({type:'POST',
  139. url: ajaxurl,
  140. data:'action=yarpp_display_discats',
  141. beforeSend:function(){jQuery('#display_discats').eq(0).html('<img src="'+spinner+'" alt="loading..."/>')},
  142. success:function(html){jQuery('#display_discats').eq(0).html(html)},
  143. dataType:'html'}
  144. )
  145. }
  146. //-->
  147. </script>
  148. <div class="wrap">
  149. <h2>
  150. <?php _e('Yet Another Related Posts Plugin Options','yarpp');?> <small><?php
  151. echo yarpp_get_option('version');
  152. ?></small>
  153. </h2>
  154. <?php echo "<div id='yarpp-version' style='display:none;'>".yarpp_get_option('version')."</div>"; ?>
  155. <form method="post">
  156. <div id="yarpp_author_text">
  157. <small><?php printf(__('by <a href="%s" target="_blank">mitcho (Michael 芳貴 Erlewine)</a>','yarpp'), 'http://yarpp.org/');?></small>
  158. </div>
  159. <!-- <div style='border:1px solid #ddd;padding:8px;'>-->
  160. <?php
  161. wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
  162. wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
  163. ?>
  164. <div id="poststuff" class="metabox-holder has-right-sidebar">
  165. <div class="inner-sidebar" id="side-info-column">
  166. <?php
  167. do_meta_boxes('settings_page_yarpp', 'side', array());
  168. ?>
  169. </div>
  170. <div id="post-body-content">
  171. <?php
  172. do_meta_boxes('settings_page_yarpp', 'normal', array());
  173. ?>
  174. </div>
  175. <script language="javascript">
  176. //<!--
  177. function template() {
  178. if (jQuery('.template').eq(0).attr('checked')) {
  179. jQuery('.templated').show();
  180. jQuery('.not_templated').hide();
  181. } else {
  182. jQuery('.templated').hide();
  183. jQuery('.not_templated').show();
  184. }
  185. excerpt();
  186. }
  187. jQuery('.template').click(template);
  188. function excerpt() {
  189. if (!jQuery('.template').eq(0).attr('checked') && jQuery('.show_excerpt').eq(0).attr('checked'))
  190. jQuery('.excerpted').show();
  191. else
  192. jQuery('.excerpted').hide();
  193. }
  194. jQuery('.show_excerpt,.template').click(excerpt);
  195. function rss_display() {
  196. if (jQuery('.rss_display').eq(0).attr('checked'))
  197. jQuery('.rss_displayed').show();
  198. else
  199. jQuery('.rss_displayed').hide();
  200. rss_excerpt();
  201. }
  202. jQuery('.rss_display').click(rss_display);
  203. function rss_template() {
  204. if (jQuery('.rss_template').eq(0).attr('checked')) {
  205. jQuery('.rss_templated').show();
  206. jQuery('.rss_not_templated').hide();
  207. } else {
  208. jQuery('.rss_templated').hide();
  209. jQuery('.rss_not_templated').show();
  210. }
  211. rss_excerpt();
  212. }
  213. jQuery('.rss_template').click(rss_template);
  214. function rss_excerpt() {
  215. if (jQuery('.rss_display').eq(0).attr('checked') && jQuery('.rss_show_excerpt').eq(0).attr('checked'))
  216. jQuery('.rss_excerpted').show();
  217. else
  218. jQuery('.rss_excerpted').hide();
  219. }
  220. jQuery('.rss_display,.rss_show_excerpt').click(rss_excerpt);
  221. function yarpp_js_init() {
  222. template();
  223. rss_template();
  224. load_display_discats();
  225. load_display_distags();
  226. load_display_demo_web();
  227. load_display_demo_rss();
  228. var version = jQuery('#yarpp-version').html();
  229. }
  230. jQuery(yarpp_js_init);
  231. //-->
  232. </script>
  233. <div>
  234. <p class="submit">
  235. <input type="submit" class='button-primary' name="update_yarpp" value="<?php _e("Update options",'yarpp')?>" />
  236. <!--<input type="submit" onclick='return confirm("<?php _e("Do you really want to reset your configuration?",'yarpp');?>");' class="yarpp_warning" name="reset_yarpp" value="<?php _e('Reset options','yarpp')?>" />-->
  237. </p>
  238. </div>
  239. <!--cache engine: <?php echo $yarpp_cache->name;?>; cache status: <?php echo $yarpp_cache->cache_status();?>-->
  240. </form>