register_plugin( 'audit-trail', __FILE__); $this->add_action( 'admin_menu' ); $this->add_action( 'activate_audit-trail/audit-trail.php', 'activate' ); $this->add_action( 'load-tools_page_audit-trail', 'admin_head' ); $this->add_action( 'admin_footer-tools_page_audit-trail', 'admin_footer' ); // Ajax functions if ( defined( 'DOING_AJAX' ) ) { include_once dirname( __FILE__ ).'/ajax.php'; $this->ajax = new AuditAjax(); } $this->register_plugin_settings( __FILE__ ); } // Add ourself to the Audit Trail functions $this->auditor = new AT_Auditor; $this->add_action( 'plugins_loaded' ); } function plugin_settings( $links) { $settings_link = ''.__('Trail', 'audit-trail' ).''; array_unshift( $links, $settings_link ); return $links; } /** * After all the plugins have loaded this starts listening for all registered filters/actions * * @return void **/ function plugins_loaded() { $methods = get_option( 'audit_methods' ); if ( !empty( $methods) && is_array( $methods ) ) { foreach( $methods AS $name) do_action( 'audit_listen', $name); } } function base_url() { return __FILE__; } /** * Creates the database and upgrades any existing data * * @return void **/ function activate() { global $wpdb; if ( get_option( 'audit_trail' ) == '0.1' || get_option( 'audit_trail' ) == 'true' ) $wpdb->query( "DROP TABLE {$wpdb->prefix}audit_trail"); if ( get_option( 'audit_trail' ) != '0.2' ) { $wpdb->query( "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}audit_trail`( `id` int(11) NOT NULL auto_increment, `operation` varchar(40) NOT NULL default '', `user_id` int(11) NOT NULL, `ip` int(11) unsigned NOT NULL default '0', `happened_at` datetime NOT NULL, `item_id` int(11) default NULL, `data` longtext, `title` varchar(100) default NULL, PRIMARY KEY ( `id`) )"); } if ( get_option( 'audit_trail' ) != '0.3' ) $wpdb->query( "ALTER TABLE `{$wpdb->prefix}audit_trail` CHANGE `ip` `ip` int(11) UNSIGNED NOT NULL DEFAULT '0'"); update_option( 'audit_trail', AUDIT_TRAIL_VERSION); } /** * Inject Audit Trail into the menu * * @return void **/ function admin_menu() { if ( current_user_can( 'edit_plugins' ) || current_user_can( 'audit_trail' ) ) add_management_page( __("Audit Trail",'audit-trail' ), __("Audit Trail",'audit-trail' ), "publish_posts", basename( __FILE__), array( $this, "admin_screen") ); } /** * Inserts the edit box into the edit post/page area * * @return void **/ function edit_box() { global $post; $this->render_admin( 'edit_box', array( 'trail' => AT_Audit::get_by_post( $post->ID) )); } function edit_box_advanced() { global $post; $this->render_admin( 'edit_box_25', array( 'trail' => AT_Audit::get_by_post( $post->ID) )); } function submenu( $inwrap = false) { // Decide what to do $sub = isset( $_GET['sub']) ? $_GET['sub'] : ''; if ( !in_array( $sub, array( 'options', 'support' ) ) ) $sub = ''; if ( $inwrap == true) $this->render_admin( 'submenu', array( 'sub' => $sub, 'class' => 'class="subsubsub"', 'trail' => ' | ' ) ); return $sub; } /** * Displays the admin screen * * @return void **/ function admin_screen() { if ( !current_user_can( 'edit_plugins' ) && !current_user_can( 'audit_trail' ) ) return; // Decide what to do $sub = $this->submenu(); AT_Audit::expire( get_option( 'audit_expiry' ) === false ? 30 : get_option( 'audit_expiry' ) ); if ( $sub == '' ) $this->screen_trail(); else if ( $sub == 'options' ) $this->screen_options(); else if ( $sub == 'support' ) $this->render_admin( 'support' ); } /** * Displays the audit trail log * * @return void **/ function screen_trail() { $table = new Audit_Trail_Table(); $table->prepare_items(); $this->render_admin( 'trail', array( 'table' => $table ) ); } /** * Display audit trail options * * @return void **/ function screen_options() { if ( isset( $_POST['save']) && check_admin_referer( 'audittrail-update_options' ) ) { update_option( 'audit_methods', stripslashes_deep( $_POST['methods'] ) ); update_option( 'audit_expiry', intval( $_POST['expiry']) ); update_option( 'audit_post', isset( $_POST['post']) ? true : false); update_option( 'audit_post_order', isset( $_POST['post_order']) ? true : false); update_option( 'audit_version', isset( $_POST['version']) ? 'true' : 'false' ); update_option( 'audit_ignore', preg_replace( '/[^0-9,]/', '', $_POST['ignore_users']) ); update_option( 'audit_support', isset( $_POST['support'] ) ? true : false ); update_option( 'audit_error_log', isset( $_POST['error_log'] ) ? true : false ); $this->render_message( __( 'Options have been updated', 'audit-trail' ) ); } $current = get_option( 'audit_methods' ); if ( !is_array( $current) ) $current = array(); $methods = apply_filters( 'audit_collect', array() ); if ( is_array( $methods) ) ksort( $methods); $error_log = get_option( 'audit_error_log' ); $support = get_option( 'audit_support' ); $expiry = get_option( 'audit_expiry' ); if ( $expiry === false) $expiry = 30; $this->render_admin( 'options', array( 'methods' => $methods, 'current' => $current, 'support' => $support, 'expiry' => $expiry, 'error_log' => $error_log, 'post' => get_option( 'audit_post' ), 'post_order' => get_option( 'audit_post_order' ), 'version' => get_option( 'audit_version' ) == 'false' ? false : true, 'ignore_users' => get_option( 'audit_ignore' ) )); } function admin_head() { wp_enqueue_style( 'audit-trail', plugin_dir_url( __FILE__ ).'admin.css' ); } function admin_footer() { $support = get_option( 'audit_support' ); if ( $support == false ) { ?>