From 0389faa32794f09836907f7a073908b282bb4022 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Mon, 28 Sep 2015 13:33:13 -0400 Subject: [PATCH] PHP7: Fix "mktime(): You should be using the time() function instead" warning --- plugins/debug_logger/runlog/runlog.php | 272 +++++++++++++++++++++++++++-------------------------- plugins/database_attachments/database_attachments.php | 2 plugins/redundant_attachments/redundant_attachments.php | 2 3 files changed, 141 insertions(+), 135 deletions(-) diff --git a/plugins/database_attachments/database_attachments.php b/plugins/database_attachments/database_attachments.php index 31747b3..6bf1b2c 100644 --- a/plugins/database_attachments/database_attachments.php +++ b/plugins/database_attachments/database_attachments.php @@ -138,7 +138,7 @@ protected function _key($args) { $uname = $args['path'] ? $args['path'] : $args['name']; - return $args['group'] . md5(mktime() . $uname . $_SESSION['user_id']); + return $args['group'] . md5(time() . $uname . $_SESSION['user_id']); } /** diff --git a/plugins/debug_logger/runlog/runlog.php b/plugins/debug_logger/runlog/runlog.php index 0c766a1..0f43df8 100644 --- a/plugins/debug_logger/runlog/runlog.php +++ b/plugins/debug_logger/runlog/runlog.php @@ -1,47 +1,41 @@ <?php /** - * runlog - * - * @author Ziba Scott <ziba@umich.edu> + * runlog + * + * @author Ziba Scott <ziba@umich.edu> */ class runlog { - private $start_time = FALSE; - + private $start_time = FALSE; private $parent_stack = array(); + private $file_handles = array(); + private $indent = 0; + private $run_log = array(); public $print_to_console = FALSE; - - private $file_handles = array(); - - private $indent = 0; - - public $threshold = 0; - - public $tag_count = array(); - - public $timestamp = "d-M-Y H:i:s O"; - - public $max_line_size = 150; - - private $run_log = array(); + public $threshold = 0; + public $tag_count = array(); + public $timestamp = "d-M-Y H:i:s O"; + public $max_line_size = 150; function runlog() { - $this->start_time = microtime( TRUE ); + $this->start_time = microtime(true); } - public function start( $name, $tag = FALSE ) + public function start($name, $tag = false) { - $this->run_log[] = array( 'type' => 'start', - 'tag' => $tag, - 'index' => count($this->run_log), - 'value' => $name, - 'time' => microtime( TRUE ), - 'parents' => $this->parent_stack, - 'ended' => false, - ); + $this->run_log[] = array( + 'type' => 'start', + 'tag' => $tag, + 'index' => count($this->run_log), + 'value' => $name, + 'time' => microtime(true), + 'parents' => $this->parent_stack, + 'ended' => false, + ); + $this->parent_stack[] = $name; $this->print_to_console("start: ".$name, $tag, 'start'); @@ -51,140 +45,151 @@ public function end() { - $name = array_pop( $this->parent_stack ); - foreach ( $this->run_log as $k => $entry ) { - if ( $entry['value'] == $name && $entry['type'] == 'start' && $entry['ended'] == false) { + $name = array_pop($this->parent_stack); + foreach ($this->run_log as $k => $entry) { + if ($entry['value'] == $name && $entry['type'] == 'start' && !$entry['ended']) { $lastk = $k; } } - $start = $this->run_log[$lastk]['time']; - $this->run_log[$lastk]['duration'] = microtime( TRUE ) - $start; - $this->run_log[$lastk]['ended'] = true; - $this->run_log[] = array( 'type' => 'end', - 'tag' => $this->run_log[$lastk]['tag'], - 'index' => $lastk, - 'value' => $name, - 'time' => microtime( TRUE ), - 'duration' => microtime( TRUE ) - $start, - 'parents' => $this->parent_stack, - ); + $start = $this->run_log[$lastk]['time']; + $this->run_log[$lastk]['duration'] = microtime(true) - $start; + $this->run_log[$lastk]['ended'] = true; + $this->run_log[] = array( + 'type' => 'end', + 'tag' => $this->run_log[$lastk]['tag'], + 'index' => $lastk, + 'value' => $name, + 'time' => microtime(true), + 'duration' => microtime(true) - $start, + 'parents' => $this->parent_stack, + ); + $this->indent--; - if($this->run_log[$lastk]['duration'] >= $this->threshold){ + if ($this->run_log[$lastk]['duration'] >= $this->threshold) { $tag_report = ""; - foreach($this->tag_count as $tag=>$count){ + foreach($this->tag_count as $tag => $count){ $tag_report .= "$tag: $count, "; } - if(!empty($tag_report)){ + if (!empty($tag_report)) { // $tag_report = "\n$tag_report\n"; } - $end_txt = sprintf("end: $name - %0.4f seconds $tag_report", $this->run_log[$lastk]['duration'] ); - $this->print_to_console($end_txt, $this->run_log[$lastk]['tag'] , 'end'); + $end_txt = sprintf("end: $name - %0.4f seconds $tag_report", $this->run_log[$lastk]['duration']); + $this->print_to_console($end_txt, $this->run_log[$lastk]['tag'], 'end'); $this->print_to_file($end_txt, $this->run_log[$lastk]['tag'], 'end'); } } - public function increase_tag_count($tag){ - if(!isset($this->tag_count[$tag])){ - $this->tag_count[$tag] = 0; - } - $this->tag_count[$tag]++; + public function increase_tag_count($tag) + { + if (!isset($this->tag_count[$tag])) { + $this->tag_count[$tag] = 0; + } + + $this->tag_count[$tag]++; } - public function get_text(){ + public function get_text() + { $text = ""; - foreach($this->run_log as $entry){ - $text .= str_repeat(" ",count($entry['parents'])); - if($entry['tag'] != 'text'){ - $text .= $entry['tag'].': '; - } - $text .= $entry['value']; + foreach ($this->run_log as $entry){ + $text .= str_repeat(" ",count($entry['parents'])); + if ($entry['tag'] != 'text'){ + $text .= $entry['tag'].': '; + } + $text .= $entry['value']; - if($entry['tag'] == 'end'){ - $text .= sprintf(" - %0.4f seconds", $entry['duration'] ); - } + if ($entry['tag'] == 'end') { + $text .= sprintf(" - %0.4f seconds", $entry['duration']); + } - $text .= "\n"; + $text .= "\n"; } + return $text; } - public function set_file($filename, $tag = 'master'){ - if(!isset($this->file_handle[$tag])){ + public function set_file($filename, $tag = 'master') + { + if (!isset($this->file_handle[$tag])) { $this->file_handles[$tag] = fopen($filename, 'a'); - if(!$this->file_handles[$tag]){ + if (!$this->file_handles[$tag]) { trigger_error('Could not open file for writing: '.$filename); } } } - public function note( $msg, $tag = FALSE ) + public function note($msg, $tag = false) { - if($tag){ + if ($tag) { $this->increase_tag_count($tag); } - if ( is_array( $msg )) { - $msg = '<pre>' . print_r( $msg, TRUE ) . '</pre>'; + if (is_array($msg)) { + $msg = '<pre>' . print_r($msg, true) . '</pre>'; } $this->debug_messages[] = $msg; - $this->run_log[] = array( 'type' => 'note', - 'tag' => $tag ? $tag:"text", - 'value' => htmlentities($msg), - 'time' => microtime( TRUE ), - 'parents' => $this->parent_stack, - ); + $this->run_log[] = array( + 'type' => 'note', + 'tag' => $tag ? $tag:"text", + 'value' => htmlentities($msg), + 'time' => microtime(true), + 'parents' => $this->parent_stack, + ); - $this->print_to_file($msg, $tag); - $this->print_to_console($msg, $tag); - + $this->print_to_file($msg, $tag); + $this->print_to_console($msg, $tag); } - public function print_to_file($msg, $tag = FALSE, $type = FALSE){ - if(!$tag){ - $file_handle_tag = 'master'; - } - else{ - $file_handle_tag = $tag; - } - if($file_handle_tag != 'master' && isset($this->file_handles[$file_handle_tag])){ - $buffer = $this->get_indent(); - $buffer .= "$msg\n"; - if(!empty($this->timestamp)){ - $buffer = sprintf("[%s] %s",date($this->timestamp, mktime()), $buffer); - } - fwrite($this->file_handles[$file_handle_tag], wordwrap($buffer, $this->max_line_size, "\n ")); + public function print_to_file($msg, $tag = false, $type = false) + { + if (!$tag) { + $file_handle_tag = 'master'; } - if(isset($this->file_handles['master']) && $this->file_handles['master']){ - $buffer = $this->get_indent(); - if($tag){ - $buffer .= "$tag: "; - } - $msg = str_replace("\n","",$msg); - $buffer .= "$msg"; - if(!empty($this->timestamp)){ - $buffer = sprintf("[%s] %s",date($this->timestamp, mktime()), $buffer); - } - if(strlen($buffer) > $this->max_line_size){ - $buffer = substr($buffer,0,$this->max_line_size - 3)."..."; - } - fwrite($this->file_handles['master'], $buffer."\n"); - } + else{ + $file_handle_tag = $tag; + } + + if ($file_handle_tag != 'master' && isset($this->file_handles[$file_handle_tag])) { + $buffer = $this->get_indent(); + $buffer .= "$msg\n"; + if (!empty($this->timestamp)) { + $buffer = sprintf("[%s] %s",date($this->timestamp, time()), $buffer); + } + fwrite($this->file_handles[$file_handle_tag], wordwrap($buffer, $this->max_line_size, "\n ")); + } + + if (isset($this->file_handles['master']) && $this->file_handles['master']) { + $buffer = $this->get_indent(); + if ($tag) { + $buffer .= "$tag: "; + } + $msg = str_replace("\n","",$msg); + $buffer .= "$msg"; + if (!empty($this->timestamp)) { + $buffer = sprintf("[%s] %s",date($this->timestamp, time()), $buffer); + } + if(strlen($buffer) > $this->max_line_size){ + $buffer = substr($buffer,0,$this->max_line_size - 3) . "..."; + } + fwrite($this->file_handles['master'], $buffer."\n"); + } } - public function print_to_console($msg, $tag=FALSE){ - if($this->print_to_console){ - if(is_array($this->print_to_console)){ - if(in_array($tag, $this->print_to_console)){ + public function print_to_console($msg, $tag = false) + { + if ($this->print_to_console) { + if (is_array($this->print_to_console)) { + if (in_array($tag, $this->print_to_console)) { echo $this->get_indent(); - if($tag){ + if ($tag) { echo "$tag: "; } echo "$msg\n"; } } - else{ + else { echo $this->get_indent(); - if($tag){ + if ($tag) { echo "$tag: "; } echo "$msg\n"; @@ -192,36 +197,37 @@ } } - public function print_totals(){ + public function print_totals() + { $totals = array(); foreach ($this->run_log as $entry) { - if ( $entry['type'] == 'start' && $entry['ended'] == true) { + if ($entry['type'] == 'start' && $entry['ended']) { $totals[$entry['value']]['duration'] += $entry['duration']; $totals[$entry['value']]['count'] += 1; } } - if($this->file_handle){ - foreach($totals as $name=>$details){ - fwrite($this->file_handle,$name.": ".number_format($details['duration'],4)."sec, ".$details['count']." calls \n"); - } + + if ($this->file_handle) { + foreach ($totals as $name => $details) { + fwrite($this->file_handle,$name.": ".number_format($details['duration'],4)."sec, ".$details['count']." calls \n"); + } } } - private function get_indent(){ - $buf = ""; - for($i = 0; $i < $this->indent; $i++){ - $buf .= " "; - } - return $buf; + private function get_indent() + { + $buf = ""; + for ($i = 0; $i < $this->indent; $i++) { + $buf .= " "; + } + return $buf; } - function __destruct(){ - foreach($this->file_handles as $handle){ + function __destruct() + { + foreach ($this->file_handles as $handle) { fclose($handle); } } - } - -?> diff --git a/plugins/redundant_attachments/redundant_attachments.php b/plugins/redundant_attachments/redundant_attachments.php index fc7e06e..e202a86 100644 --- a/plugins/redundant_attachments/redundant_attachments.php +++ b/plugins/redundant_attachments/redundant_attachments.php @@ -86,7 +86,7 @@ private function _key($args) { $uname = $args['path'] ? $args['path'] : $args['name']; - return $args['group'] . md5(mktime() . $uname . $_SESSION['user_id']); + return $args['group'] . md5(time() . $uname . $_SESSION['user_id']); } /** -- Gitblit v1.9.1