Aleksander Machniak
2015-09-28 0389faa32794f09836907f7a073908b282bb4022
PHP7: Fix "mktime(): You should be using the time() function instead" warning
3 files modified
92 ■■■■ changed files
plugins/database_attachments/database_attachments.php 2 ●●● patch | view | raw | blame | history
plugins/debug_logger/runlog/runlog.php 88 ●●●● patch | view | raw | blame | history
plugins/redundant_attachments/redundant_attachments.php 2 ●●● patch | view | raw | blame | history
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']);
    }
    /**
plugins/debug_logger/runlog/runlog.php
@@ -8,40 +8,34 @@
class runlog {
    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();
    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',
        $this->run_log[] = array(
                'type'    => 'start',
                                  'tag' => $tag,
                                  'index' => count($this->run_log),
                                  'value' => $name,
                                  'time' => microtime( TRUE ),
                'time'    => microtime(true),
                                  'parents' => $this->parent_stack,
                                  'ended' => false,
                                   );
        $this->parent_stack[] = $name;
        $this->print_to_console("start: ".$name, $tag, 'start');
@@ -53,22 +47,24 @@
    {
        $name = array_pop( $this->parent_stack );
        foreach ( $this->run_log as $k => $entry ) {
            if ( $entry['value'] == $name && $entry['type'] == 'start'  && $entry['ended'] == false) {
            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',
        $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,
                'time'     => microtime(true),
                'duration' => microtime(true) - $start,
                                  'parents' => $this->parent_stack,
                                   );
        $this->indent--;
        if($this->run_log[$lastk]['duration'] >= $this->threshold){ 
            $tag_report = "";
@@ -84,14 +80,17 @@
        }
    }
    public function increase_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']));
@@ -106,10 +105,12 @@
           $text .= "\n"; 
        }
        return $text;
    }
    public function set_file($filename, $tag = 'master'){
    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]){
@@ -118,42 +119,45 @@
        }
    }
    public function note( $msg, $tag = FALSE )
    public function note($msg, $tag = false)
    {
        if($tag){
            $this->increase_tag_count($tag);
        }
        if ( is_array( $msg )) {
            $msg = '<pre>' . print_r( $msg, TRUE ) . '</pre>';
            $msg = '<pre>' . print_r($msg, true) . '</pre>';
        }
        $this->debug_messages[] = $msg;
        $this->run_log[] = array( 'type' => 'note',
        $this->run_log[] = array(
                'type'    => 'note',
                                  'tag' => $tag ? $tag:"text",
                                  'value' => htmlentities($msg),
                                  'time' => microtime( TRUE ),
                'time'    => microtime(true),
                                  'parents' => $this->parent_stack,
             );
       $this->print_to_file($msg, $tag);
       $this->print_to_console($msg, $tag);
    }
    public function print_to_file($msg, $tag = FALSE, $type = FALSE){
    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);
                $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){
@@ -162,7 +166,7 @@
           $msg = str_replace("\n","",$msg);
           $buffer .= "$msg";
           if(!empty($this->timestamp)){
                $buffer = sprintf("[%s] %s",date($this->timestamp, mktime()), $buffer);
                $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)."...";
@@ -171,7 +175,8 @@
       }
    }
    public function print_to_console($msg, $tag=FALSE){
    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)){
@@ -192,14 +197,16 @@
        }
    }
    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");
@@ -207,7 +214,8 @@
        }
    }
    private function get_indent(){
    private function get_indent()
    {
           $buf = "";
           for($i = 0; $i < $this->indent; $i++){
               $buf .= "  "; 
@@ -216,12 +224,10 @@
    }
   function  __destruct(){
    function  __destruct()
    {
       foreach($this->file_handles as $handle){
            fclose($handle);
        }
    }
}
?>
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']);
    }
    /**