source: trunk/libs/Debug.php @ 1280

Revision 1280, 3.4 KB checked in by nick_ramsay, 3 years ago (diff)

[TRUNK] Widgets 0.8, Thickbox 0.3 and other minor changes. Not sure yet if the simplepie.inc file works in PHP 5.3.

Line 
1<?php
2/**
3 * Debugging functions
4 *
5 * PHP version 5
6 *
7 * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
18 *
19 * @category  Content Management System
20 * @package   HotaruCMS
21 * @author    Nick Ramsay <admin@hotarucms.org>
22 * @copyright Copyright (c) 2009, Hotaru CMS
23 * @license   http://www.gnu.org/copyleft/gpl.html GNU General Public License
24 * @link      http://www.hotarucms.org/
25 */
26class Debug
27{
28    protected $fh = array();    // file handlers
29    protected $log = array();   // file paths
30   
31    /**
32     * Shows number of database queries and the time it takes for a page to load
33     */
34    public function showQueriesAndTime($h)
35    {
36        if ($h->isDebug) {
37       
38            $mysql_version = $h->db->get_var("SELECT VERSION() AS VE");
39           
40            echo "<p class='debug'>";
41            echo $h->lang['main_hotaru_db_queries'] . $h->db->num_queries . " | ";
42            echo $h->lang['main_hotaru_page_load_time'] . timer_stop(1) . $h->lang['main_times_secs'] . " | ";
43            echo $h->lang['main_hotaru_memory_usage'] . display_filesize(memory_get_usage()) . " | ";
44            echo $h->lang['main_hotaru_php_version'] . phpversion() . " | ";
45            echo $h->lang['main_hotaru_mysql_version'] . $mysql_version . " | ";
46            echo $h->lang['main_hotaru_hotaru_version'] . $h->version;
47            echo "</p>";
48        }
49
50        if ($h->currentUser->loggedIn) {echo "<span id='loggedIn' class='loggedIn_true'/>"; } else {"<span id='loggedIn' class='loggedIn_false'/>";}
51    }
52
53
54    /**
55     * Open file for logging
56     *
57     * @param string $type "speed", "error", etc.
58     * @param string $mode e.g. 'a' or 'w'.
59     * @link http://php.net/manual/en/function.fopen.php
60     */
61    public function openLog($type = 'debug', $mode = 'a+')
62    {
63        $this->log[$type] = CACHE . "debug_logs/" . $type . ".txt";
64       
65        // auto-delete the file after 1 week:
66        /*
67        $last_modified = filemtime($this->log[$type]);
68        $expire = (7 * 24 * 60 * 60); // 1 week
69        if ($last_modified < (time() - $expire)) { unlink ($this->log[$type]); }
70        */
71       
72        // open/create a file:
73        $this->fh[$type] = fopen($this->log[$type], $mode) or die("can't open file");
74    }
75   
76   
77    /**
78     * Log performance and errors
79     *
80     * @param string $type "error", "speed", etc.
81     */
82    public function writeLog($type = 'debug', $string = '')
83    {
84        if ($string) {
85            $string = date('d M Y H:i:s', time()) . ": " . $string . "\n";
86            fwrite($this->fh[$type], $string);
87        }
88    }
89   
90   
91    /**
92     * Close log file
93     *
94     * @param string $type "speed", "error", etc.
95     */
96    public function closeLog($type = 'debug')
97    {
98        if (isset($this->fh[$type])) { fclose($this->fh[$type]); }
99    }
100}
101?>
Note: See TracBrowser for help on using the repository browser.