-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueries.php
136 lines (103 loc) · 3.95 KB
/
queries.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* @version $Id$
* @package joomlafox
* @subpackage plugin
* @author Webdesign Engenharia {@link http://www.webdesign.eng.br}
* @author Emerson da Rocha Luiz {@link http://www.fititnt.org}
* @author Created on 20-Oct-2009
*/
defined('_JEXEC') or die('Access Denied');
// Load language file
$this->loadLanguage('plg_system_debug');
$db =& JFactory::getDBO();
ob_start();
$newlineKeywords = '#\b(FROM|LEFT|INNER|OUTER|WHERE|SET|VALUES|ORDER|GROUP|HAVING|LIMIT|ON|AND)\b#i';
$db = JFactory::getDbo();
echo '<h4>'.JText::sprintf('PLG_DEBUG_QUERIES_LOGGED', $db->getTicker()).'</h4>';
if ($log = $db->getLog()) {
echo '<ol>';
$selectQueryTypeTicker = array();
$otherQueryTypeTicker = array();
foreach ($log as $k => $sql) {
// Start Query Type Ticker Additions
$fromStart = stripos($sql, 'from');
$whereStart = stripos($sql, 'where', $fromStart);
if ($whereStart === false) {
$whereStart = stripos($sql, 'order by', $fromStart);
}
if ($whereStart === false) {
$whereStart = strlen($sql) - 1;
}
$fromString = substr($sql, 0, $whereStart);
$fromString = str_replace("\t", " ", $fromString);
$fromString = str_replace("\n", " ", $fromString);
$fromString = trim($fromString);
// Initialize the select/other query type counts the first time:
if (!isset($selectQueryTypeTicker[$fromString])) {
$selectQueryTypeTicker[$fromString] = 0;
}
if (!isset($otherQueryTypeTicker[$fromString])) {
$otherQueryTypeTicker[$fromString] = 0;
}
// Increment the count:
if (stripos($sql, 'select') === 0) {
$selectQueryTypeTicker[$fromString] = $selectQueryTypeTicker[$fromString] + 1;
unset($otherQueryTypeTicker[$fromString]);
}
else {
$otherQueryTypeTicker[$fromString] = $otherQueryTypeTicker[$fromString] + 1;
unset($selectQueryTypeTicker[$fromString]);
}
// Finish Query Type Ticker Additions
$text = htmlspecialchars($sql, ENT_QUOTES);
$text = preg_replace($newlineKeywords, '<br />  \\0', $text);
echo '<li>'.$text.'</li>';
}
echo '</ol>';
if ($this->params->get('query_types', 1)) {
// Get the totals for the query types:
$totalSelectQueryTypes = count($selectQueryTypeTicker);
$totalOtherQueryTypes = count($otherQueryTypeTicker);
$totalQueryTypes = $totalSelectQueryTypes + $totalOtherQueryTypes;
echo '<h4>'.JText::sprintf('PLG_DEBUG_QUERY_TYPES_LOGGED', $totalQueryTypes) . '</h4>';
if ($totalSelectQueryTypes) {
echo '<h5>'.JText::sprintf('PLG_DEBUG_SELECT_QUERIES').'</h5>';
arsort($selectQueryTypeTicker);
echo '<ol>';
foreach($selectQueryTypeTicker as $table => $occurrences)
{
echo '<li>'.JText::sprintf('PLG_DEBUG_QUERY_TYPE_AND_OCCURRENCES', $table, $occurrences).'</li>';
}
echo '</ol>';
}
if ($totalOtherQueryTypes) {
echo '<h5>'.JText::sprintf('PLG_DEBUG_OTHER_QUERIES').'</h5>';
arsort($otherQueryTypeTicker);
echo '<ol>';
foreach($otherQueryTypeTicker as $table => $occurrences)
{
echo '<li>'.JText::sprintf('PLG_DEBUG_QUERY_TYPE_AND_OCCURRENCES', $table, $occurrences).'</li>';
}
echo '</ol>';
}
}
}
$sqlqueries = ob_get_contents();
ob_end_clean();
//$sqlqueries = ob_get_contents();
$queriesfox = '
<div id="jfox_queries" style="display:none;" >
<fieldset><legend>SQL</legend>' .
$sqlqueries .
'</fieldset>
</div>';
if (!JDEBUG){
$queriesfox = '
<div id="jfox_queries" style="display:none;" >
<fieldset><legend>SQL</legend>
For use this fuction, you must enable go to <strong>Joomla Administrator > Global Configuration > System > Debug Settings</strong> and enable <em>Debug System</em><br />
Please remember that even if you enable <em>Debug System</em>, you can still disable <em>System - Debug</em> plugin and use just JFox for see your queries.
</fieldset>
</div>';
}