Skip to content

Commit

Permalink
- filecounter rewritten. Now we used some more arrays and TYPO3-API. …
Browse files Browse the repository at this point in the history
…3 new functions.

- 2 new hooks in filecounter:
modifyPathArray: Explodes the current path into directories. This is useful, when you want to save directory names like "DE", "EN", ... into db
modifyFileDataBeforeQueue: One to modify fieldset before saving and the other to 

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/ke_stats/trunk@47522 735d13b6-9817-0410-8766-e36946ffe9aa
  • Loading branch information
froemken committed May 10, 2011
1 parent 2401319 commit e61eaf3
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 85 deletions.
136 changes: 100 additions & 36 deletions filecounter/class.tx_kestats_filecounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,51 +100,60 @@ function initTYPO3() {
*
*/
public function countFile() {
$file = realpath($_SERVER['DOCUMENT_ROOT'] . $_SERVER['REQUEST_URI']);

// check if file exists
if (is_file($file)) {
$fileinfo = pathinfo($file);
$filename = $fileinfo['basename'];
$filepath = $fileinfo['dirname'];
$fileextension = strtolower($fileinfo['extension']);
$request = t3lib_div::getIndpEnv('REQUEST_URI');
if($test == 'url') {
$file = realpath($_SERVER['DOCUMENT_ROOT'] . urldecode($request));
} else {
$file = realpath($_SERVER['DOCUMENT_ROOT'] . $request);
}

// Must be set in order to use ke_stats
// get fileinfomations if possible
if($fileinfo = $this->getFileInfo($file)) {
t3lib_div::devlog('fi', 'fi', -1, array(
$fileinfo
));
// Must be set in order to use ke_stats
$GLOBALS['TSFE']->config['config']['language'] = 0;

if (t3lib_extMgm::isLoaded('ke_stats')) {
if(t3lib_extMgm::isLoaded('ke_stats')) {
$keStatsObj = t3lib_div::getUserObj('EXT:ke_stats/pi1/class.tx_kestats_pi1.php:tx_kestats_pi1');
$keStatsObj->initApi();

// don't count access from robots
if (!$keStatsObj->statData['is_robot']) {

$category = $this->messages['backend_tabname'];
$compareFieldList = 'element_uid,element_title,year,month';
//$element_title = htmlspecialchars(strip_tags($filename)) . ' (' . $filepath . ')';
$element_title = htmlspecialchars(strip_tags($filename));
$element_uid = 0;
$element_pid = $this->extConf['fileAccessCountOnPage'] ? intval($this->extConf['fileAccessCountOnPage']) : 0;
$element_language = $GLOBALS['TSFE']->sys_page->sys_language_uid;
$element_type = 0;
$stat_type = 'extension';
$amount = 0;
$parent_uid = 0;
$additionalData = '';
$counter = 1;
if(!$keStatsObj->statData['is_robot']) {

$fields['category'] = $this->messages['backend_tabname'];
$fields['compareFieldList'] = 'element_uid,element_title,year,month';
$fields['elementTitle'] = $fileinfo['file'];
$fields['elementUid'] = 0;
$fields['elementPid'] = $this->extConf['fileAccessCountOnPage'] ? intval($this->extConf['fileAccessCountOnPage']) : 0;
$fields['elementLanguage'] = $GLOBALS['TSFE']->sys_page->sys_language_uid;
$fields['elementType'] = 0;
$fields['statType'] = 'extension';
$fields['parentUid'] = 0;
$fields['additionalData'] = '';
$fields['counter'] = 1;

// hook for individual modifications of the statistical filedata
if(is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_stats']['modifyFileDataBeforeQueue'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_stats']['modifyFileDataBeforeQueue'] as $_classRef) {
$_procObj = &t3lib_div::getUserObj($_classRef);
$_procObj->modifyFileDataBeforeQueue($fields, $fileinfo, $keStatsObj, $this);
}
}

$keStatsObj->increaseCounter(
$category,
$compareFieldList,
$element_title,
$element_uid,
$element_pid,
$element_language,
$element_type,
$stat_type,
$parent_uid,
$additionalData,
$counter
$fields['category'],
$fields['compareFieldList'],
$fields['elementTitle'],
$fields['elementUid'],
$fields['elementPid'],
$fields['elementLanguage'],
$fields['elementType'],
$fields['statType'],
$fields['parentUid'],
$fields['additionalData'],
$fields['counter']
);
}
unset($keStatsObj);
Expand All @@ -165,4 +174,59 @@ public function countFile() {
echo $this->messages['file_not_found'];
}
}

/**
* Try to get all available file informations
*
* @param string $file
* @return array
*/
public function getFileInfo($file) {
// check if file is available
if(is_file($file)) {
$fileinfo = t3lib_div::split_fileref($file);
$fileinfo['file'] = $this->cleanFileName($fileinfo['file']);
$fileinfo['dirInfo'] = $this->getDirInfo($file);

return $fileinfo;
} else {
return false;
}
}

/**
* removes or replaces special entities from filename
*
* @param string $file
* @return string cleaned filename
*/
public function cleanFileName($file) {
$file = strip_tags($file);
$file = htmlspecialchars($file);

return $file;
}

/**
* explodes the dirname into seperate pieces
*
* @param string $path
* @return array seperated dirname parts
*/
public function getDirInfo($file) {
$pathArray = array();
$pathArray['fullPath'] = $fullPath = t3lib_div::dirname($file) . '/'; // /var/www/projects/myProject/fileadmin/user_upload/
$pathArray['rootPath'] = $rootPath = str_replace(PATH_site, '', $fullPath); // /fileadmin/user_upload/

// hook for adding some more path modifications
// this is useful, if you use foldernames as year or language and you want to save this data, too
if(is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_stats']['modifyPathArray'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_stats']['modifyPathArray'] as $_classRef) {
$_procObj = &t3lib_div::getUserObj($_classRef);
$_procObj->modifyPathArray($file, $pathArray, $this);
}
}

return $pathArray;
}
}
5 changes: 2 additions & 3 deletions inc/search_engines.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

// List of search_engines (referer)

$GLOBALS['search_engines'] = array(/*{{{*/
$GLOBALS['search_engines'] = array(
'www.google' => 'Google',
'images.google' => 'Google Images',
'search.live' => 'MSN',
Expand All @@ -48,6 +48,5 @@
'search.icq.com' => 'Icq.com',
'search.sweetim.com' => 'Sweetim.com',
'search.ch' => 'Search.ch'
);/*}}}*/

);
?>
36 changes: 9 additions & 27 deletions lib/class.tx_kestats_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class tx_kestats_lib {
* @access public
* @return void
*/
function tx_kestats_lib() {/* {{{ */
function tx_kestats_lib() {
$this->now = time();
$this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ke_stats']);
$this->extConf['asynchronousDataRefreshing'] = $this->extConf['asynchronousDataRefreshing'] ? 1 : 0;
Expand All @@ -58,8 +58,6 @@ function tx_kestats_lib() {/* {{{ */
$this->extConf['enableBackendModuleCaching'] = $this->extConf['enableBackendModuleCaching'] ? 1 : 0;
}

/* }}} */

/**
* Increases a statistics counter for the given $category.
* $compareFieldList is a comma-separated list.
Expand All @@ -81,7 +79,7 @@ function tx_kestats_lib() {/* {{{ */
* @access public
* @return void
*/
function increaseCounter($category, $compareFieldList, $element_title='', $element_uid=0, $element_pid=0, $element_language=0, $element_type=0, $stat_type=STAT_TYPE_PAGES, $parent_uid=0, $additionalData='', $counter = 1) {/* {{{ */
function increaseCounter($category, $compareFieldList, $element_title='', $element_uid=0, $element_pid=0, $element_language=0, $element_type=0, $stat_type=STAT_TYPE_PAGES, $parent_uid=0, $additionalData='', $counter = 1) {

// hook for individual modifications of the statistical data
// before submitting it to the queue or updatign it directly
Expand Down Expand Up @@ -150,8 +148,6 @@ function increaseCounter($category, $compareFieldList, $element_title='', $eleme
}
}

/* }}} */

/**
* refreshOverviewPageData
*
Expand All @@ -164,7 +160,7 @@ function increaseCounter($category, $compareFieldList, $element_title='', $eleme
* @access public
* @return void
*/
function refreshOverviewPageData($pageUid=0) {/* {{{ */
function refreshOverviewPageData($pageUid=0) {
$overviewPageData = array();

// all languages and types will be shown in the overview page
Expand Down Expand Up @@ -261,8 +257,6 @@ function refreshOverviewPageData($pageUid=0) {/* {{{ */
return $overviewPageData;
}

/* }}} */

/**
* Returns an array with statistical data of a certain time period.
*
Expand All @@ -278,7 +272,7 @@ function refreshOverviewPageData($pageUid=0) {/* {{{ */
* @param int $element_type
* @return array
*/
function getStatResults($statType='pages', $statCategory, $columns, $onlySum=0, $orderBy='counter DESC', $groupBy='', $encode_title_to_utf8=0, $fromToArray=array(), $element_language=0, $element_type=0) {/* {{{ */
function getStatResults($statType='pages', $statCategory, $columns, $onlySum=0, $orderBy='counter DESC', $groupBy='', $encode_title_to_utf8=0, $fromToArray=array(), $element_language=0, $element_type=0) {
$resultArray = array();
$yearArray = $this->getDateArray($fromToArray['from_year'], $fromToArray['from_month'], $fromToArray['to_year'], $fromToArray['to_month']);

Expand Down Expand Up @@ -441,8 +435,6 @@ function getStatResults($statType='pages', $statCategory, $columns, $onlySum=0,
return $resultArray;
}

/* }}} */

/**
* getSubPages
*
Expand All @@ -454,7 +446,7 @@ function getStatResults($statType='pages', $statCategory, $columns, $onlySum=0,
* @access public
* @return void
*/
function getSubPages($page_uid=0) {/* {{{ */
function getSubPages($page_uid=0) {
if ($page_uid) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid=' . intval($page_uid));
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
Expand All @@ -469,8 +461,6 @@ function getSubPages($page_uid=0) {/* {{{ */
}
}

/* }}} */

/**
* getDateArray
*
Expand All @@ -484,7 +474,7 @@ function getSubPages($page_uid=0) {/* {{{ */
* @return array
* @author Christoph Bl�mer <[email protected]>
*/
function getDateArray($from_year, $from_month, $to_year, $to_month) {/* {{{ */
function getDateArray($from_year, $from_month, $to_year, $to_month) {
$fromToArray = array();
$fromToArray['from_year'] = $from_year;
$fromToArray['to_year'] = $to_year;
Expand Down Expand Up @@ -523,8 +513,6 @@ function getDateArray($from_year, $from_month, $to_year, $to_month) {/* {{{ */
return $dayPerMonth;
}

/* }}} */

/**
* Increases a statistics counter.
* If no counter exists that matches all fields the $compareFieldList, a new one is created.
Expand Down Expand Up @@ -625,7 +613,7 @@ function updateStatisticsTable($category, $compareFieldList, $element_title='',
* @param string $additionalData Additional data, must be processed by a custom hook.
* @return void
*/
function getStatEntry($category, $compareFieldList, $element_uid, $element_pid, $element_title, $element_language, $element_type, $stat_type, $parent_uid, $additionalData) {/* {{{ */
function getStatEntry($category, $compareFieldList, $element_uid, $element_pid, $element_title, $element_language, $element_type, $stat_type, $parent_uid, $additionalData) {
$statEntry = array();
$compareData = $this->statData;
$compareData['element_uid'] = $element_uid;
Expand Down Expand Up @@ -673,16 +661,14 @@ function getStatEntry($category, $compareFieldList, $element_uid, $element_pid,
return $statEntry;
}

/* }}} */

/**
* getOldestQueueEntry
* find and return the oldest entry in the queue table
*
* @access public
* @return array or false
*/
function getOldestQueueEntry() {/* {{{ */
function getOldestQueueEntry() {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_kestats_queue', '1=1', '', 'uid ASC', '1');
if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
$result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
Expand All @@ -692,8 +678,6 @@ function getOldestQueueEntry() {/* {{{ */
return $result;
}

/* }}} */

/**
* debugMail
*
Expand All @@ -705,7 +689,7 @@ function getOldestQueueEntry() {/* {{{ */
* @access public
* @return void
*/
function debugMail($email='', $content='', $subject = 'TYPO3 tx_kestats_lib DEBUG') {/* {{{ */
function debugMail($email='', $content='', $subject = 'TYPO3 tx_kestats_lib DEBUG') {
if (is_array($content)) {
$content = t3lib_div::view_array($content);
}
Expand All @@ -716,8 +700,6 @@ function debugMail($email='', $content='', $subject = 'TYPO3 tx_kestats_lib DEBU

mail($email, $subject, $content, $header);
}

/* }}} */
}

?>
Loading

0 comments on commit e61eaf3

Please sign in to comment.