Skip to content

Commit

Permalink
Better handling of debug functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Roman committed Feb 26, 2012
1 parent d479f58 commit 6198bc9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
8 changes: 7 additions & 1 deletion admin.php
Expand Up @@ -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);
Expand All @@ -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' );


?>
Expand Down Expand Up @@ -72,13 +74,17 @@
<th scope="row"><label>Debug mode:</label></th>
<td><input type="checkbox" name="tnwsc_debug" value="1"<?php echo $debug ? ' checked="checked"' : ''; ?> /> Enable debug mode to write to a log file instead of to the database</td>
</tr>
<tr valign="top">
<th scope="row"><label>Path to log file:</label></th>
<td><input type="text" name="tnwsc_log_path" value="<?php echo esc_html($log_path)?>" size="30" /> (Only if debug mode is active - Make sure it is writable)</td>
</tr>
<tr valign="top">
<th scope="row"><label>Frequency of update:</label></th>
<td><input type="text" name="tnwsc_sync_frequency" value="<?php echo esc_html($sync_frequency)?>" size="10" /> seconds (Default: One check per hour)</td>
</tr>
<tr valign="top">
<th scope="row"><label>Sync social count for posts published before:</label></th>
<td><input type="text" name="tnwsc_post_range" value="<?php echo esc_html($post_range)?>" /> seconds (Default: 7 days)</td>
<td><input type="text" name="tnwsc_post_range" value="<?php echo esc_html($post_range)?>" size="10" /> seconds (Default: 7 days)</td>
</tr>
</tbody>
</table>
Expand Down
5 changes: 2 additions & 3 deletions config.php
Expand Up @@ -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';

?>
24 changes: 9 additions & 15 deletions index.php
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down Expand Up @@ -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' );
Expand Down

0 comments on commit 6198bc9

Please sign in to comment.