|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZTemplatesStatisticsReporter class 00004 // 00005 // Created on: <18-Feb-2005 17:21:17 dl> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file eztemplatesstatisticsreporter.php 00032 */ 00033 00034 /*! 00035 \class eZTemplatesStatisticsReporter eztemplatesstatisticsreporter.php 00036 \brief Generates statistics of tempate usage. 00037 00038 */ 00039 00040 //include_once( 'kernel/common/eztemplatedesignresource.php' ); 00041 //include_once( 'lib/eztemplate/classes/eztemplate.php' ); 00042 //include_once( 'lib/ezutils/classes/ezsys.php' ); 00043 00044 class eZTemplatesStatisticsReporter 00045 { 00046 /*! 00047 static 00048 */ 00049 static function generateStatistics( $as_html = true ) 00050 { 00051 $statStartTime = microtime( true ); 00052 $stats = ''; 00053 00054 if ( !eZTemplate::isTemplatesUsageStatisticsEnabled() ) 00055 return $stats; 00056 00057 if ( $as_html ) 00058 { 00059 $stats .= "<h2>Templates used to render the page:</h2>"; 00060 $stats .= ( "<table id='templateusage' summary='List of used templates' style='border: 1px dashed black;' cellspacing='0'>" . 00061 "<tr><th>Usage count</th>" . 00062 "<th>Requested template</th>" . 00063 "<th>Template</th>" . 00064 "<th>Template loaded</th>" . 00065 "<th>Edit</th>" . 00066 "<th>Override</th></tr>" ); 00067 } 00068 else 00069 { 00070 $formatString = "%-40s%-40s%-40s\n"; 00071 $stats .= "Templates usage statistics\n"; 00072 $stats .= sprintf( $formatString, 'Templates', 'Requested template', 'Template loaded' ); 00073 } 00074 00075 if ( $as_html ) 00076 { 00077 $iconSizeX = 16; 00078 $iconSizeY = 16; 00079 $templateViewFunction = 'visual/templateview'; 00080 eZURI::transformURI( $templateViewFunction ); 00081 $templateEditFunction = 'visual/templateedit'; 00082 eZURI::transformURI( $templateEditFunction ); 00083 $templateOverrideFunction = 'visual/templatecreate'; 00084 eZURI::transformURI( $templateOverrideFunction ); 00085 00086 $std_base = eZTemplateDesignResource::designSetting( 'standard' ); 00087 $wwwDir = eZSys::wwwDir(); 00088 $editIconFile = "$wwwDir/design/$std_base/images/edit.gif"; 00089 $overrideIconFile = "$wwwDir/design/$std_base/images/override-template.gif"; 00090 00091 $tdClass = 'used_templates_stats1'; 00092 $j = 0; 00093 00094 $currentSiteAccess = $GLOBALS['eZCurrentAccess']['name']; 00095 } 00096 00097 $templatesUsageStatistics = eZTemplate::templatesUsageStatistics(); 00098 00099 $alreadyListedTemplate = $templateCounts = array(); 00100 00101 //Generate usage count for each unique template first. 00102 foreach( $templatesUsageStatistics as $templateInfo ) 00103 { 00104 $actualTemplateName = $templateInfo['actual-template-name']; 00105 00106 if ( !array_key_exists( $actualTemplateName, $templateCounts ) ) 00107 { 00108 $templateCounts[$actualTemplateName] = 1; 00109 00110 } 00111 else 00112 { 00113 ++$templateCounts[$actualTemplateName]; 00114 } 00115 } 00116 00117 //Then create the actual listing 00118 foreach ($templatesUsageStatistics as $templateInfo) 00119 { 00120 $actualTemplateName = $templateInfo['actual-template-name']; 00121 $requestedTemplateName = $templateInfo['requested-template-name']; 00122 $templateFileName = $templateInfo['template-filename']; 00123 00124 if ( !in_array( $actualTemplateName, $alreadyListedTemplate ) ) 00125 { 00126 $alreadyListedTemplate[] = $actualTemplateName; 00127 if ( $as_html ) 00128 { 00129 $tdClass = ( $j % 2 == 0 ) ? 'used_templates_stats1' : 'used_templates_stats2'; 00130 00131 $requestedTemplateViewURI = $templateViewFunction . '/' . $requestedTemplateName; 00132 $actualTemplateViewURI = $templateViewFunction . '/' . $actualTemplateName; 00133 00134 $templateEditURI = $templateEditFunction . '/' . $templateFileName; 00135 $templateOverrideURI = $templateOverrideFunction . '/' . $actualTemplateName; 00136 00137 $actualTemplateNameOutput = ( $actualTemplateName == $requestedTemplateName ) ? "<span style=\"font-style: italic;\"><No override></span>" : $actualTemplateName; 00138 00139 $stats .= ( 00140 "<tr><td class=\"$tdClass\" style=\"text-align: center;\">$templateCounts[$actualTemplateName]</td>" . 00141 "<td class=\"$tdClass\"><a href=\"$requestedTemplateViewURI\">$requestedTemplateName</a></td>" . 00142 "<td class=\"$tdClass\">$actualTemplateNameOutput</td>" . 00143 "<td class=\"$tdClass\">$templateFileName</td>" . 00144 "<td class=\"$tdClass\" align=\"center\"><a href=\"$templateEditURI/(siteAccess)/$currentSiteAccess\"><img src=\"$editIconFile\" width=\"$iconSizeX\" height=\"$iconSizeY\" alt=\"Edit template\" title=\"Edit template\" /></a></td>". 00145 "<td class=\"$tdClass\" align=\"center\"><a href=\"$templateOverrideURI/(siteAccess)/$currentSiteAccess\"><img src=\"$overrideIconFile\" width=\"$iconSizeX\" height=\"$iconSizeY\" alt=\"Override template\" title=\"Override template\" /></a></td></tr>" ); 00146 00147 $j++; 00148 } 00149 else 00150 { 00151 $stats .= sprintf( $formatString, $requestedTemplateName, $actualTemplateName, $templateFileName ); 00152 } 00153 } 00154 } 00155 00156 $totalTemplatesCount = count( $templatesUsageStatistics ); 00157 $totalUniqueTemplatesCopunt = count( array_keys( $alreadyListedTemplate ) ); 00158 $statEndTime = microtime( true ); 00159 $timeUsage = number_format( $statEndTime - $statStartTime, 4 ); 00160 00161 if ( $as_html ) 00162 { 00163 $stats .= ( "<tr><td class=\"$tdClass\"> </td>" . 00164 "<td class=\"$tdClass\"> </td>" . 00165 "<td class=\"$tdClass\"> </td>" . 00166 "<td class=\"$tdClass\"> </td>". 00167 "<td class=\"$tdClass\"> </td>". 00168 "<td class=\"$tdClass\"> </td></tr>" ); 00169 $stats .= "<tr><td colspan=\"2\" style=\"text-align: left;\"><b> Number of times templates used: $totalTemplatesCount<br /> Number of unique templates used: $totalUniqueTemplatesCopunt</b></td></tr>"; 00170 $stats .= "<tr><td colspan=\"2\" style=\"text-align: left;\"><b> Time used to render template usage: $timeUsage secs</b></td></tr>"; 00171 $stats .= "</table>"; 00172 } 00173 else 00174 { 00175 $stats .= "\nTotal templates count: " . $totalTemplatesCount . "\n" . "Total unique templates count: " . $totalUniqueTemplatesCopunt . "\n"; 00176 } 00177 00178 return $stats; 00179 } 00180 } 00181 00182 ?>