From 6198bc947049e398e350b404a7131451858f5990 Mon Sep 17 00:00:00 2001 From: Pablo Roman Date: Sun, 26 Feb 2012 15:20:26 +0000 Subject: [PATCH] Better handling of debug functions --- admin.php | 8 +++++++- config.php | 5 ++--- index.php | 24 +++++++++--------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/admin.php b/admin.php index b1dc625..6265b6c 100644 --- a/admin.php +++ b/admin.php @@ -33,6 +33,7 @@ update_option( 'tnwsc_sync_frequency', $postdata['tnwsc_sync_frequency'] ); update_option( 'tnwsc_active_sync', (int) ! empty($postdata['tnwsc_active_sync']) ); update_option( 'tnwsc_debug', (int) ! empty($postdata['tnwsc_debug']) ); + update_option( 'tnwsc_log_path', $postdata['tnwsc_log_path'] ); if( get_option( 'tnwsc_active_sync' ) == 1 ) { tnwsc_schedule_sync(true); @@ -44,6 +45,7 @@ $post_range = get_option( 'tnwsc_post_range' ); $tnwsc_services = get_option( 'tnwsc_services' ); $debug = get_option( 'tnwsc_debug' ); +$log_path = get_option( 'tnwsc_log_path' ); ?> @@ -72,13 +74,17 @@ /> Enable debug mode to write to a log file instead of to the database + + + (Only if debug mode is active - Make sure it is writable) + seconds (Default: One check per hour) - seconds (Default: 7 days) + seconds (Default: 7 days) diff --git a/config.php b/config.php index 08cb224..fd15b0b 100644 --- a/config.php +++ b/config.php @@ -14,9 +14,8 @@ 'tnwsc_sync_frequency' => 3600, // - Frequency (in seconds) of update the social count; Defaults to one check per hour 'tnwsc_post_range' => 604800, // - Sync social count for posts published before this number of seconds; Defaults to ( -7 days ) 'tnwsc_active_sync' => 0, // - Whether the sync is active ( 1 or 0 ). Defaults to inactive - 'tnwsc_debug' => 1 + 'tnwsc_debug' => 1, + 'tnwsc_log_path' => dirname( __FILE__).'/tnwsc.log' ); -$tnwsc_error_log_path = dirname( __FILE__).'./tnwsc.log'; - ?> \ No newline at end of file diff --git a/index.php b/index.php index 7e59ce0..4cd119d 100644 --- a/index.php +++ b/index.php @@ -25,24 +25,18 @@ function tnwsc_deactivate() foreach($tnwsc_wp_options as $key => $value) { delete_option($key); } + $hook = "tnwsc_sync"; + wp_clear_scheduled_hook( $hook ); } -function tnwsc_init() -{ -/* - if ( isset( $_GET['tnwsc_sync'] ) ) { - tnwsc_process(); - exit; - } -*/ -} - function tnwsc_log($message) { - global $tnwsc_error_log_path; - error_log(date('Y-m-d H:i:s', time())." - ".$message."\n", 3, $tnwsc_error_log_path); + $tnwsc_log_path = get_option( 'tnwsc_log_path' ); + if( is_writable( dirname( $tnwsc_log_path ) ) ) { + error_log( date('Y-m-d H:i:s', time())." - ".$message."\n", 3, $tnwsc_log_path); + } } function tnwsc_process() @@ -54,15 +48,17 @@ function tnwsc_process() if( $posts ) { foreach( $posts as $post ) { $permalink = get_permalink( $post->ID ); + $debug_info = ''; foreach( $tnwsc_services as $service_name => $enabled ) { if( $enabled ) { $count = tnwsc_get_count( $permalink, $service_name ); - tnwsc_log("Request: ".$permalink." / ". $service_name." / ". $count); + $debug_info .= ' / '.$service_name." (".$count.")"; if($tnwsc_debug == 0) { tnwsc_update_post_meta( $post->ID, $service_name, $count ); } } } + tnwsc_log("Request: ".$permalink. $debug_info); } } if( get_option( 'tnwsc_active_sync' ) == 1) { @@ -188,9 +184,7 @@ function tnwsc_schedule_sync( $immediate = false ) } } - // Backend actions -add_action( 'init', 'tnwsc_init' ); add_action( 'tnwsc_sync', 'tnwsc_process' ); register_activation_hook( __FILE__, 'tnwsc_setup' );