Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatesstatisticsreporter.php
Go to the documentation of this file.
1 <?php
17 class eZTemplatesStatisticsReporter
18 {
22 static function generateStatistics( $as_html = true )
23 {
24 $stats = '';
25
26 if ( !eZTemplate::isTemplatesUsageStatisticsEnabled() )
27 return $stats;
28
29 if ( $as_html )
30 {
31 $stats .= "<h3>Templates used to render the page:</h3>";
32 $stats .= ( "<table id='templateusage' class='debug_resource_usage' title='List of used templates'>" .
33 "<tr><th title='Usage count of this particular template'>Usage</th>" .
34 "<th>Requested template</th>" .
35 "<th>Template</th>" .
36 "<th>Template loaded</th>" .
37 "<th>Edit</th>" .
38 "<th>Override</th></tr>" );
39 }
40 else
41 {
42 $formatString = "%-40s%-40s%-40s\n";
43 $stats .= "Templates usage statistics\n";
44 $stats .= sprintf( $formatString, 'Templates', 'Requested template', 'Template loaded' );
45 }
46
47 if ( $as_html )
48 {
49 $iconSizeX = 16;
50 $iconSizeY = 16;
51 $templateViewFunction = 'visual/templateview';
52 eZURI::transformURI( $templateViewFunction );
53 $templateEditFunction = 'visual/templateedit';
54 eZURI::transformURI( $templateEditFunction );
55 $templateOverrideFunction = 'visual/templatecreate';
56 eZURI::transformURI( $templateOverrideFunction );
57
58 $std_base = eZTemplateDesignResource::designSetting( 'standard' );
59 $wwwDir = htmlspecialchars( eZSys::wwwDir(), ENT_COMPAT, 'UTF-8' );
60 $editIconFile = "$wwwDir/design/$std_base/images/edit.gif";
61 $overrideIconFile = "$wwwDir/design/$std_base/images/override-template.gif";
62
63 $tdClass = 'used_templates_stats1';
64 $j = 0;
65
66 $currentSiteAccess = $GLOBALS['eZCurrentAccess']['name'];
67 }
68
69 $templatesUsageStatistics = eZTemplate::templatesUsageStatistics();
70
71 $alreadyListedTemplate = $templateCounts = array();
72
73 //Generate usage count for each unique template first.
74 foreach( $templatesUsageStatistics as $templateInfo )
75 {
76 $actualTemplateName = $templateInfo['actual-template-name'];
77
78 if ( !array_key_exists( $actualTemplateName, $templateCounts ) )
79 {
80 $templateCounts[$actualTemplateName] = 1;
81
82 }
83 else
84 {
85 ++$templateCounts[$actualTemplateName];
86 }
87 }
88
89 //Then create the actual listing
90 foreach ($templatesUsageStatistics as $templateInfo)
91 {
92 $actualTemplateName = $templateInfo['actual-template-name'];
93 $requestedTemplateName = $templateInfo['requested-template-name'];
94 $templateFileName = $templateInfo['template-filename'];
95
96 if ( !in_array( $actualTemplateName, $alreadyListedTemplate ) )
97 {
98 $alreadyListedTemplate[] = $actualTemplateName;
99 if ( $as_html )
100 {
101 $requestedTemplateViewURI = $templateViewFunction . '/' . $requestedTemplateName;
102 $actualTemplateViewURI = $templateViewFunction . '/' . $actualTemplateName;
103
104 $templateEditURI = $templateEditFunction . '/' . $templateFileName;
105 $templateOverrideURI = $templateOverrideFunction . '/' . $actualTemplateName;
106
107 $actualTemplateNameOutput = ( $actualTemplateName == $requestedTemplateName ) ? "<em>&lt;No override&gt;</em>" : $actualTemplateName;
108
109 $stats .= (
110 "<tr class='data'><td>$templateCounts[$actualTemplateName]</td>" .
111 "<td><a href=\"$requestedTemplateViewURI\">$requestedTemplateName</a></td>" .
112 "<td>$actualTemplateNameOutput</td>" .
113 "<td>$templateFileName</td>" .
114 "<td><a href=\"$templateEditURI/(siteAccess)/$currentSiteAccess\"><img src=\"$editIconFile\" width=\"$iconSizeX\" height=\"$iconSizeY\" alt=\"Edit template\" title=\"Edit template\" /></a></td>".
115 "<td><a href=\"$templateOverrideURI/(siteAccess)/$currentSiteAccess\"><img src=\"$overrideIconFile\" width=\"$iconSizeX\" height=\"$iconSizeY\" alt=\"Override template\" title=\"Override template\" /></a></td></tr>" );
116
117 $j++;
118 }
119 else
120 {
121 $stats .= sprintf( $formatString, $requestedTemplateName, $actualTemplateName, $templateFileName );
122 }
123 }
124 }
125
126 $totalTemplatesCount = count( $templatesUsageStatistics );
127 $totalUniqueTemplatesCopunt = count( array_keys( $alreadyListedTemplate ) );
128
129 if ( $as_html )
130 {
131 $stats .= "<tr><td colspan=\"6\"><b>&nbsp;Number of times templates used: $totalTemplatesCount<br />&nbsp;Number of unique templates used: $totalUniqueTemplatesCopunt</b></td></tr>";
132 $stats .= "</table>";
133 }
134 else
135 {
136 $stats .= "\nTotal templates count: " . $totalTemplatesCount . "\n" . "Total unique templates count: " . $totalUniqueTemplatesCopunt . "\n";
137 }
138
139 return $stats;
140 }
141 }
142
143 ?>
eZSys\wwwDir
static wwwDir()
Definition: ezsys.php:582
eZTemplateDesignResource\designSetting
static designSetting( $type='standard')
Definition: eztemplatedesignresource.php:175
eZTemplate\isTemplatesUsageStatisticsEnabled
static isTemplatesUsageStatisticsEnabled()
Definition: eztemplate.php:2509
eZTemplate\templatesUsageStatistics
static templatesUsageStatistics()
Definition: eztemplate.php:2601
eZTemplatesStatisticsReporter
Generates statistics of tempate usage.
Definition: eztemplatesstatisticsreporter.php:18
eZTemplatesStatisticsReporter\generateStatistics
static generateStatistics( $as_html=true)
Definition: eztemplatesstatisticsreporter.php:22
eZURI\transformURI
static transformURI(&$href, $ignoreIndexDir=false, $serverURL=null, $htmlEscape=true)
Definition: ezuri.php:599
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.