register_plugin ('audit-trail', __FILE__); $this->add_action( 'admin_menu' ); $this->add_action( 'activate_audit-trail/audit-trail.php', 'activate' ); $this->add_action( 'admin_head', 'wp_print_styles' ); $this->add_action( 'admin_print_styles', 'wp_print_styles' ); // $this->add_filter( 'contextual_help', 'contextual_help', 10, 2 ); $this->add_action( '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 contextual_help($help, $screen) { if ($screen == 'settings_page_audittrail' ) { $help .= '
' . __('Audit Trail Help', 'audit-trail') . '
'; $help .= ''.__ ('Audit Trail Documentation', 'audit-trail').'
'; $help .= ''.__ ('Audit Trail Support Forum', 'audit-trail').'
'; $help .= ''.__ ('Audit Trail Bug Tracker', 'audit-trail').'
'; $help .= __ ('Please read the documentation and check the bug tracker before asking a question.', 'audit-trail'); $help .= '
'; } return $help; } 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); } } /** * 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); } function is_25 () { global $wp_version; if (version_compare ('2.5', $wp_version) <= 0) return true; return false; } /** * 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'] : ''; $url = explode ('&', $_SERVER['REQUEST_URI']); $url = $url[0]; if (!$this->is_25 () && $inwrap == false) $this->render_admin ('submenu', array ('url' => $url, 'sub' => $sub, 'class' => 'id="subsubmenu"')); else if ($this->is_25 () && $inwrap == true) $this->render_admin ('submenu', array ('url' => $url, '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 () { if ( isset( $_POST['item'] ) && isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' ) { foreach ( $_POST['item'] AS $id ) { AT_Audit::delete( intval( $id ) ); } } $pager = new AT_Pager ($_REQUEST, $_SERVER['REQUEST_URI'], 'happened_at', 'DESC'); $this->render_admin ('trail', array ('trail' => AT_Audit::get_all ($pager), 'pager' => $pager)); } /** * 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 ); $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); $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, '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 wp_print_styles() { if ( ( isset ($_GET['page']) && $_GET['page'] == 'audit-trail.php') ) { echo ''; if (!function_exists ('wp_enqueue_style')) echo ''; } } function locales() { $locales = array(); $readme = @file_get_contents( dirname( __FILE__ ).'/readme.txt' ); if ( $readme ) { if ( preg_match_all( '/^\* (.*?) by \[(.*?)\]\((.*?)\)/m', $readme, $matches ) ) { foreach ( $matches[1] AS $pos => $match ) { $locales[$match] = ''.$matches[2][$pos].''; } } } ksort( $locales ); return $locales; } function admin_footer() { if ( isset($_GET['page']) && $_GET['page'] == basename( __FILE__ ) ) { $support = get_option ('audit_support'); if ( $support == false ) { ?>