Index: rawlog.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/rawlog/rawlog.module,v
retrieving revision 1.3.2.19
diff -u -r1.3.2.19 rawlog.module
--- rawlog.module	28 Nov 2010 18:28:13 -0000	1.3.2.19
+++ rawlog.module	3 Jan 2011 15:01:09 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: rawlog.module,v 1.3.2.19 2010/11/28 18:28:13 vitoa Exp $
+// $Id: rawlog.module,v 1.3.2.17 2010/06/26 21:49:54 vitoa Exp $
 
 /**
  * Implementation of hook_help().
@@ -42,21 +42,28 @@
     WATCHDOG_INFO     => t('Info'),
     WATCHDOG_DEBUG    => t('Debug'),
   );
-
+  
   return $severity_list;
 }
 
 /**
  * Creates a log file.
  */
-function rawlog_create_logfile($filename = '', $type = '', $update_filename = TRUE) {
-  $logfile = rawlog_update_filename($filename, $type);
-  if (!($fp = fopen($logfile, "w"))) {
+function rawlog_create_logfile($filename = '') {
+  $logfile = rawlog_update_filename($filename);
+  if (strstr($logfile, '/') == 0) {
+  	$fullpath = $logfile;
+  }
+  else {
+    $fullpath = realpath('./') . DIRECTORY_SEPARATOR . $logfile;
+  }
+
+  if (!($fp = _rawlog_fopen($fullpath, "w"))) {
     drupal_set_message(t('Rawlog: Failed to create log file @file.', array('@file' => $logfile)));
   }
   else {
     drupal_set_message(t('Rawlog: Log file @file was created.', array('@file' => $logfile)));
-    if (!empty($filename) && $update_filename) {
+    if (!empty($filename)) {
       variable_set('rawlog_filename', $filename);
     }
     variable_set('rawlog_logfile', $logfile);
@@ -68,77 +75,24 @@
 }
 
 /**
- * hook_token_values
- */
-function rawlog_token_values($type, $object = NULL, $options = array()) {
-	$tokens = array();
-  $all_tokens_list = new StdClass;
-  $all_tokens_list->tokens = array();
-  if (module_exists('token')) {
-    $all_tokens_list = token_get_values();
-  }
-  if ($type == 'global') {
-  	$rawlog_date = date(variable_get('rawlog_filedate_format', 'Y-m-d_H-i-s'));
-		$rawlog_tokens_list = array(
-		  'date' => $rawlog_date,
-		  'rawlog-date' => $rawlog_date,
-		);
-		foreach ($rawlog_tokens_list as $key => $rawlog_token_item) {
-		  if (!in_array($key, array_values($all_tokens_list->tokens))) {
-		    $tokens[$key] = $rawlog_token_item;
-		  }
-		}
-  }
-
-  return $tokens;
-}
-
-/**
  * Helper function to translate tokens in filename.
  */
-function rawlog_update_filename($filename = '', $type = '') {
+function rawlog_update_filename($filename = '') {
+  $currdate = date(variable_get('rawlog_filedate_format', 'Y-m-d_H-i-s'));
   $filename = !empty($filename) ? $filename : variable_get('rawlog_filename', $_SERVER['DOCUMENT_ROOT'] .'/'. drupal_get_path('module', 'rawlog') .'/rawlog.log');
-  $logfile = variable_get('rawlog_logfile', $_SERVER['DOCUMENT_ROOT'] .'/'. drupal_get_path('module', 'rawlog') .'/rawlog.log');
-	$rawlog_different_files_by_type = variable_get('rawlog_different_files_by_type', FALSE);
-  $update = TRUE;
-	if ($rawlog_different_files_by_type && !empty($type)) {
-	  $filename = rawlog_different_files($type);
-    $rawlog_logs_rotation = variable_get('rawlog_logs_rotation', 'never');
-    $rawlog_timestamp = variable_get('rawlog_timestamp', 0);
-    if ($rawlog_logs_rotation && (($next_period = strtotime("+1 ". $rawlog_logs_rotation, $rawlog_timestamp)) !== false) && time() < $next_period) {
-      $logfile_file = basename($logfile);
-    	if (!empty($type) && strpos($logfile_file, strtolower(str_replace(' ', '_', $type))) === 0) {
-    		$filename = $logfile;
-        $update = FALSE;
-    	}
-    }
-	}
-	if ($update) {
-	  $currdate = date(variable_get('rawlog_filedate_format', 'Y-m-d_H-i-s'));
-	  if (strpos($filename, '@date') !== FALSE) {
-	    $filename = t($filename, array('@date' => $currdate));
-	  }
-	  if (module_exists('token')) {
-	    $filename = token_replace($filename);
-	  }
-	  elseif (strpos($filename, '[date]') !== FALSE) {
-	    $filename = str_replace('[date]', $currdate, $filename);
-	  }
-	}
-
-  return $filename;
+  return t($filename, array('@date' => $currdate));
 }
 
 /**
  * Rotates a log file.
  */
-function rawlog_rotate_logfile($filename = '') {
+function rawlog_rotate_logfile() {
   $logfile = variable_get('rawlog_logfile', $_SERVER['DOCUMENT_ROOT'] .'/'. drupal_get_path('module', 'rawlog') .'/rawlog.log');
   if (($rawlog_logs_rotation = variable_get('rawlog_logs_rotation', 'never')) != 'never') {
     $curr_timestamp = time();
     $rawlog_timestamp = variable_get('rawlog_timestamp', 0);
     if ((($next_period = strtotime("+1 ". $rawlog_logs_rotation, $rawlog_timestamp)) !== false) && $curr_timestamp > $next_period) {
-      $logfile = rawlog_update_filename($filename);
+      $logfile = rawlog_update_filename();
       variable_set('rawlog_logfile', $logfile);
       variable_set('rawlog_timestamp', $curr_timestamp);
     }
@@ -148,44 +102,11 @@
 }
 
 /**
- * Returns log file name for the case of different log files depending on message type.
- */
-function rawlog_different_files($type) {
-	$rawlog_prefix = '';
-  $rawlog_suffix = '';
-  $tokens = array();
-  if (module_exists('token')) {
-    $all_tokens_list = token_get_values();
-  }
-  else {
-    $all_tokens_list = array_keys(rawlog_token_values('global'));
-  }
-  foreach ($all_tokens_list as $key => $rawlog_token_item) {
-  	$all_tokens_list[$key] = '['. $rawlog_token_item .']';
-  }
-	$rawlog_tokens_list = array_merge($all_tokens_list, array('@date'));
-	$filename = variable_get('rawlog_filename', $_SERVER['DOCUMENT_ROOT'] .'/'. drupal_get_path('module', 'rawlog') .'/rawlog.log');
-	foreach ($rawlog_tokens_list as $key => $rawlog_token_item) {
-	  if ($rawlog_token_pos = strpos($filename, $rawlog_token_item) !== FALSE) {
-	    if ($rawlog_token_pos == 0) {
-	      $rawlog_prefix .= $rawlog_token_item;
-	    }
-	    else {
-	      $rawlog_suffix .= '_'. $rawlog_token_item;
-	    }
-	  }
-	}
-	$logfile = dirname($filename) .'/'. $rawlog_prefix . strtolower(str_replace(' ', '_', $type)) . $rawlog_suffix .'.log';
-
-	return $logfile;
-}
-
-/**
  * Implementation of hook_watchdog().
  */
 function rawlog_watchdog($log_entry) {
   global $base_url, $language;
-
+  
   $message_fields_array = array(
     'Timestamp',
     'Site',
@@ -198,7 +119,7 @@
     'Link',
     'Message'
   );
-
+  
   $message_values_array = array(
     '@timestamp',
     '@base_url',
@@ -211,7 +132,7 @@
     '@link',
     "\n\n@message"
   );
-
+  
   $severity_list = rawlog_severity_list();
 
   $to = 'someone@example.com';
@@ -223,7 +144,7 @@
 
   $rawlog_file_format = variable_get('rawlog_file_format', 'medium');
   $delimiter = $rawlog_file_format == 'full' ? "\n" : ", ";
-
+  
   $params['message'] = '';
   for ($i = 0; $i < count($message_fields_array); $i++) {
     $field = $message_fields_array[$i]. ': ';
@@ -259,7 +180,7 @@
     '@request_uri'   => $log_entry['request_uri'],
     '@referer_uri'   => $log_entry['referer'],
     '@uid'           => $log_entry['user']->uid,
-    '@name'          => !empty($log_entry['user']->name) ? $log_entry['user']->name : 'anonymous',
+    '@name'          => isset($log_entry['user']->name) ? $log_entry['user']->name : 'anonymous',
     '@link'          => strip_tags($log_entry['link']),
     '@message'       => strip_tags($log_entry['message']) . $suffix,
   ));
@@ -300,17 +221,8 @@
   if ($log_entry['severity'] <= $rawlog_severity_level || ($rawlog_enable_tags && $rawlog_tags_present)) {
     $logfile = variable_get('rawlog_logfile', $_SERVER['DOCUMENT_ROOT'] .'/'. drupal_get_path('module', 'rawlog') .'/rawlog.log');
     $rawlog_logs_rotation = variable_get('rawlog_logs_rotation', 'never');
-    $rawlog_different_files_by_type = variable_get('rawlog_different_files_by_type', FALSE);
-    $file_by_type = '';
-	  if ($rawlog_different_files_by_type) {
-      $file_by_type = rawlog_different_files($log_entry['type']);
-      $logfile = rawlog_update_filename($file_by_type, $log_entry['type']);
-	  }
-    if ($file_by_type && !file_exists($logfile)) {
-      $logfile = rawlog_create_logfile($file_by_type, $log_entry['type'], FALSE);
-    }
     if ($logfile && file_exists($logfile) && $rawlog_logs_rotation != 'never') {
-      $logfile = rawlog_rotate_logfile($file_by_type);
+      $logfile = rawlog_rotate_logfile();
     }
     if ($logfile && !file_exists($logfile)) {
       $logfile = rawlog_create_logfile();
@@ -322,3 +234,14 @@
     }
   }
 }
+
+function _rawlog_fopen($path, $mode, $chmod = 0755){ 
+  $directory = str_replace(basename($path), '', $path);
+  $file = basename($path);
+  if (!is_dir($directory)) {
+    if (!mkdir($directory, $chmod, 1)) {
+      return FALSE;
+    }
+  }
+ return fopen($path, $mode);
+}
