diff --git a/admin/intro.php b/admin/intro.php index 0be9e70a2..af8fd8c97 100644 --- a/admin/intro.php +++ b/admin/intro.php @@ -187,6 +187,199 @@ SELECT MIN(date_available) trigger_notify('loc_end_intro'); +// +-----------------------------------------------------------------------+ +// | get activity data | +// +-----------------------------------------------------------------------+ + +$number_week = 4; +$date = new DateTime(); +//Array for the JS tooltip +$activity_last_weeks = array(); +//Count mondays +$mondays = 0; +//Get mondays date (day + month) for the chart legend +$mondays_date = array(); +//Array for sorting days in circle size +$temp_data = array(); + +//Get data from $number_week last weeks +while ($mondays < $number_week) +{ + $date_string = $date->format('Y-m-d'); + $query = ' +SELECT * + FROM `'.ACTIVITY_TABLE.'` + WHERE occured_on LIKE "'.$date_string.'%" +;'; + + $result = query2array($query, null); + + $this_day = array('number' => 0); + foreach ($result as $act) { + if(isset($this_day['details'][ucfirst($act['object'])][ucfirst($act['action'])])) + { + $this_day['details'][ucfirst($act['object'])][ucfirst($act['action'])] += 1; + } else { + $this_day['details'][ucfirst($act['object'])][ucfirst($act['action'])] = 1; + } + $this_day['number'] += 1; + } + + if ($this_day['number'] > 0) + { + $temp_data[] = array('x' => $this_day['number'], 'd'=>$date->format('N'), 'w'=>$mondays); + } + + + $activity_last_weeks[$mondays][intval($date->format('N'))] = $this_day; + + if ($date->format('D') == 'Mon') { + $mondays_date[$mondays]['m'] = $date->format('m'); + $mondays_date[$mondays]['d'] = $date->format('d'); + $mondays += 1; + } + $date->sub(new DateInterval('P1D')); +} + +// Algorithm to sort days in circle size : +// * Get the difference between sorted numbers of activity per day (only not null numbers) +// * Split days max $circle_sizes time on the biggest difference (but not below 120%) +// * Set the sizes according to the groups created + +//Function to sort days by number of activity +function cmp_day($a, $b) +{ + if ($a['x'] == $b['x']) { + return 0; + } + return ($a['x'] < $b['x']) ? -1 : 1; +} + +usort($temp_data, 'cmp_day'); + +//Get the percent difference +$diff_x = array(); + +for ($i=1; $i < count($temp_data); $i++) +{ + $diff_x[] = $temp_data[$i]['x']/$temp_data[$i-1]['x']*100; +} + +$split = 0; +//Split (split represented by -1) +while (max($diff_x) > 120) { + $diff_x[array_search(max($diff_x), $diff_x)] = -1; + $split++; +} + +//Fill empty chart data for the template +$chart_data = array(); +for ($i=0; $i < $number_week; $i++) { + for ($j=1; $j <= 7; $j++) { + $chart_data[$i][$j] = 0; + } +} + +$size = 1; +$chart_data[$temp_data[0]['w']][$temp_data[0]['d']] = $size; +//Set sizes in chart data +for ($i=1; $i < count($temp_data); $i++) { + if ($diff_x[$i-1] == -1) {$size++;} + $chart_data[$temp_data[$i]['w']][$temp_data[$i]['d']] = $size; +} + +//Assign data for the template +$template->assign('ACTIVITY_MONDAYS_DATE',array_reverse($mondays_date)); +$template->assign('ACTIVITY_LAST_WEEKS', array_reverse($activity_last_weeks)); +$template->assign('ACTIVITY_CHART_DATA',array_reverse($chart_data)); +$template->assign('ACTIVITY_CHART_NUMBER_SIZES',$size); + + +// +-----------------------------------------------------------------------+ +// | get storage data | +// +-----------------------------------------------------------------------+ + +$video_format = array('webm','webmv','ogg','ogv','mp4','m4v'); +$data_storage = array(); + +//Select files in Image_Table +$query = ' +SELECT file, filesize + FROM `'.IMAGES_TABLE.'` +;'; + +$result = query2array($query, null); + +foreach ($result as $file) +{ + $tabString = explode('.',$file['file']); + $ext = $tabString[count($tabString) -1]; + $size = $file['filesize']; + if (in_array($ext, $conf['picture_ext'])) + { + if (isset($data_storage['Photos'])) + { + $data_storage['Photos'] += $size; + } else { + $data_storage['Photos'] = $size; + } + } elseif (in_array($ext, $video_format)) { + if (isset($data_storage['Videos'])) + { + $data_storage['Videos'] += $size; + } else { + $data_storage['Videos'] = $size; + } + } else { + if (isset($data_storage['Others'])) + { + $data_storage['Others'] += $size; + } else { + $data_storage['Others'] = $size; + } + } +} + +//Select files from format table +$query = ' +SELECT SUM(filesize) + FROM `'.IMAGE_FORMAT_TABLE.'` +;'; + +$result = query2array($query); + +if (isset($result[0]['SUM(filesize)'])) +{ + $data_storage['Format'] = $result[0]['SUM(filesize)']; +} + +//If the host is not windows, get the cache size +if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') +{ + $f = './_data'; + $io = popen ( '/usr/bin/du -sk ' . $f, 'r' ); + $size = fgets ($io, 4096); + $size = substr ( $size, 0, strpos ( $size, "\t" ) ); + pclose ( $io ); + $data_storage['Cache'] = $size; +} + +//Calculate total storage +$total_storage = 0; +foreach ($data_storage as $value) +{ + $total_storage += $value; +} + +//Get percentage of the total storage +foreach ($data_storage as $key=>$value) +{ + $data_storage[$key] = $value/$total_storage*100; +} + +//Pass data to HTML +$template->assign('STORAGE_TOTAL',$total_storage/1000); +$template->assign('STORAGE_CHART_DATA',$data_storage); // +-----------------------------------------------------------------------+ // | sending html code | // +-----------------------------------------------------------------------+ diff --git a/admin/themes/default/template/intro.tpl b/admin/themes/default/template/intro.tpl index a9f253f8d..10602ff0a 100644 --- a/admin/themes/default/template/intro.tpl +++ b/admin/themes/default/template/intro.tpl @@ -7,7 +7,7 @@ var piwigo_need_update_msg = '{'A new version o var ext_need_update_msg = '{'Some upgrades are available for extensions.'|@translate|@escape:"javascript"} '; {literal} -jQuery().ready(function(){ + jQuery().ready(function(){ jQuery('.cluetip').cluetip({ width: 300, splitTitle: '|', @@ -61,6 +61,7 @@ jQuery().ready(function(){
+ {"%s Activities"|@translate:$ACTIVITY_LAST_WEEKS[$WEEK_NUMBER][$DAY_NUMBER]["number"]}
+ {foreach from=$ACTIVITY_LAST_WEEKS[$WEEK_NUMBER][$DAY_NUMBER]["details"] item=actions key=cat}
+
{$cat} : {foreach from=$actions item=number key=action} ({$action}) {$number} {/foreach}
+ {/foreach}
+
{round($value)}%
+ {/foreach} +{$type|translate}
{if $ENABLE_SYNCHRONIZATION}
{'Quick Local Synchronization'|translate}
@@ -149,4 +196,4 @@ jQuery().ready(function(){
{if isset($SUBSCRIBE_BASE_URL)}
{/if}
-