📄 stats_view.php
字号:
while($data = $query->FetchRow()) { $array_users[$data[0]] = $data[1]; } $array_users[0] = 'anonymous'; /** * get views, downloads, comments */ foreach($array_users AS $key=>$value) { $array_users_data[$key]['username'] = $value; /** * get views */ $query_views = $GLOBALS['db']->Execute("SELECT count(id) AS nr_count"."\n" . "FROM ".PREFIX."stats"."\n" . "WHERE type = 'view'"."\n" . "AND stats_time >= '".$timestamp_from."'"."\n". "AND stats_time <= '".$timestamp_to."'"."\n". "AND stats_user = '".$key."'"."\n"); $data_views = $query_views->FetchRow(); $array_users_data[$key]['view'] = $data_views[0]; /** * get downloads */ $query_views = $GLOBALS['db']->Execute("SELECT md5sum AS nr_count"."\n" . "FROM ".PREFIX."stats"."\n" . "WHERE type = 'download'"."\n" . "AND stats_time >= '".$timestamp_from."'"."\n". "AND stats_time <= '".$timestamp_to."'"."\n". "AND stats_user = '".$key."'"."\n"); $array_users_data[$key]['download'] = $query_views->RecordCount(); /** * Getting filesize for thousands of downloads and a large number * of users takes to much time. We use some bad hack here to prevent * counting each time if nothing has changed. * This is somekind of trick, as we have no regular "anonymous" user * (and for sure we don't want it.) So save values for anonymous in * linpha_config instead of linpha_users... * Use only for alltime downloads (e.g. do not recalculate if "this week, * this month" and so on is selected) * Takes care of admin option "realtime stats" */ /** * take care of anonymous */ if($key == "0") // anonymous user { $user_downloads = read_config('stats_anonymous_downloads'); $array_users_data[$key]['download_size'] = read_config('stats_anonymous_downloads_size'); } else // regular user from linpha_users { $userinfo = $GLOBALS['db']->Execute("SELECT downloads, downloads_size " . "FROM ".PREFIX."users " . "WHERE id = '".$key."' "); $data = $userinfo->FetchRow(); $user_downloads = $data[0]; $array_users_data[$key]['download_size'] = $data[1]; } /** * refresh stats if realtime is enabled or if stats cache timed out */ if(read_config('stats_realtime') || (time() - ((read_config('stats_cache_time')*3600)) > read_config('stats_last_refresh'))) { /** * Prevent filesize counting if no new downloads for user, but do it * just for all time downloads and as second performance boost */ if($array_users_data[$key]['download'] > $user_downloads || $timestamp_from != '0' && $timestamp_to != '9999999999') { /** * calculate filesize */ $array_users_data[$key]['download_size'] = 0; while($data_views = $query_views->FetchRow()) { $query_filename = $GLOBALS['db']->Execute("SELECT prev_path, filename " . "FROM ".PREFIX."photos " . "WHERE md5sum = '".$data_views[0]."'"); $data_filename = $query_filename->FetchRow(); $filename = TOP_DIR.'/'.$data_filename['prev_path'].'/'.$data_filename['filename']; if(file_exists($filename)) { $array_users_data[$key]['download_size'] += filesize($filename); } } /** * Save new values */ if($key == "0") { update_config($array_users_data[$key]['download'], 'stats_anonymous_downloads'); update_config($array_users_data[$key]['download_size'], 'stats_anonymous_downloads_size'); } else { $update = $GLOBALS['db']->Execute("UPDATE ".PREFIX."users SET ". "downloads='".linpha_addslashes($array_users_data[$key]['download'])."', ". "downloads_size='".linpha_addslashes($array_users_data[$key]['download_size'])."' ". "WHERE id='".linpha_addslashes($key)."'"); } } update_config(time(), 'stats_last_refresh'); } /** * get comments */ $date_query = $GLOBALS['db']->Execute("SELECT date " . "FROM ".PREFIX."image_comments ". "WHERE comment <> ''". "AND author = '".$value."'"); $user_comments = "0"; while($result = $date_query->FetchRow()) { $date = $GLOBALS['db']->UnixTimeStamp($result[0]); if($date >= $timestamp_from && $date <= $timestamp_to) { $user_comments++; } } $array_users_data[$key]['comment'] = $user_comments; unset($user_comments); } /** * sort data */ if(!isset($_REQUEST['sort']) OR !isset($_REQUEST['asc'])) { $_REQUEST['sort'] = 'username'; $_REQUEST['asc'] = 1; } $array_users_data_sorted = multi_sort($array_users_data, $global_key = $_REQUEST['sort'], $global_asc = $_REQUEST['asc']); /** * print table */ ?> <div style="padding-left: 10px; "> <strong><?php echo $stats_over_users; ?></strong> <?php echo count($array_users)-1; ?> </div> <br /> <div align="center"> <table class='admintable' width="95%" border="1"> <tr> <th class='maintable'><a href="<?php echo $adress_link; ?> &mode=user&sort=username&asc=1"><?php echo $login_name; ?></a></th> <th class='maintable'><a href="<?php echo $adress_link; ?> &mode=user&sort=view&asc=0"><?php echo (str_replace("v", "V", $views)); ?></a></th> <th class='maintable'><a href="<?php echo $adress_link; ?> &mode=user&sort=download&asc=0"><?php echo $stats_downloads; ?></a></th> <th class='maintable'><a href="<?php echo $adress_link; ?> &mode=user&sort=download_size&asc=0"><?php echo $stats_downl_size; ?></a></th> <th class='maintable'><a href="<?php echo $adress_link; ?> &mode=user&sort=comment&asc=0"><?php echo $stats_over_comment; ?></a></th> </tr> <?php foreach($array_users_data_sorted AS $key=>$value) { ?> <tr> <td class='admintable'><?php echo $value['username']; ?></td> <td class='admintable' align="right"><?php echo $value['view']; ?></td> <td class='admintable' align="right"><?php echo $value['download']; ?></td> <td class='admintable' align="right"><?php echo round($value['download_size']/1024/1024).' MB'; ?></td> <td class='admintable' align="right"><?php echo $value['comment']; ?></td> </tr> <?php } ?> </table> </div> <?phpbreak; // end case usercase 'comment': $link = base64_encode('plugins/stats/stats_view.php?mode=comment'); $sql = sql_query_str( Array( PREFIX."image_comments.id", PREFIX."image_comments.comment", PREFIX."image_comments.author", PREFIX."image_comments.md5sum", PREFIX."image_comments.date", ), P.".md5sum = ".PREFIX."image_comments.md5sum ". "AND ".PREFIX."image_comments.comment <> ' '", 'date', Array("image_comments") ); $info = $GLOBALS['db']->SelectLimit($sql, 50, 0); $query = $GLOBALS['db']->Execute("SELECT count(id) " . "FROM ".PREFIX."image_comments " . "WHERE comment <> ''"); $data = $query->FetchRow(); ?> <div style="padding-left: 10px; "> <strong><?php echo $stats_coments_total.":"; ?></strong> <?php echo $data[0]; ?> <br /> <strong><?php echo $stats_coments_sel.":"; ?></strong> <?php echo $info->RecordCount(); ?> </div> <br /> <div align="center"> <table class='admintable' width='95%' cellspacing='1' border='0'> <tr><th class='maintable' colspan='4'><?php echo $comment_last_comments; ?></th></tr> <?php while($comment=$info->FetchRow()) { $date = $GLOBALS['db']->UnixTimeStamp($comment[4]); if($date >= $timestamp_from && $date <= $timestamp_to) { $query = $GLOBALS['db']->Execute("SELECT id, prev_path " . "FROM ".PREFIX."photos WHERE md5sum = '".$comment[3]."'"); $data = $query->FetchRow(); /** * catch old comments which haven't an image anymore */ if(empty($data[0])) { $old_comments[] = $comment; } else { $stage = get_stage_from_prev_path($data[1]); $albid = get_albid($data[1],$stage); ?> <tr> <td class='admintable' width='5%' align='center'> <a href='<?php echo TOP_DIR."/viewer.php?imgid=".$data[0]."&albid=".$albid."&stage=".$stage; ?>' title="<?php echo $thumb_hint_msg; ?>"> <img src='<?php echo TOP_DIR."/get_thumbs.php?id=".$data[0]; ?>' border='0' alt='thumbnail''></a> </td> <td class='admintable' width='20%' align='center'> <?php echo nice_date($comment[0]); ?><br /> <b><?php echo $comment[2]; ?></b> </td> <td class='admintable' valign='top'> <?php echo htmltag(stripslashes($comment[1])); ?> </td> <td class='admintable' width='5%'> <?php if($passed && in_group('admin')) { echo "<a href='".TOP_DIR."/actions/delete_comment.php?id=".$comment[0]."&" . "job=comment&ref=".$link."'>[".STR_DELETE."]</a>"; } ?> </td> </tr> <?php } } } echo "</table>"; if(isset($old_comments)) { echo "<br />"; echo "<table class='admintable' width='100%' cellspacing='1' border='0'>"; echo "<tr><th class='maintable' colspan='4'>".$str_old_comments."</th></tr>"; foreach($old_comments AS $comment) { print("<tr>". "<td class='admintable' width='20%' align='center'>". nice_date($comment[0])."<br />". "<b>$comment[2]</b></td>". "<td class='admintable' valign='top' colspan='2'>".htmltag(stripslashes($comment[1])). "<td class='admintable' width='5%'>". "<a href='actions/delete_comment.php?id={$comment[0]}&job=comment&ref=".$link."'>[".STR_DELETE."]". "</td></tr>"); } echo "</table>"; } echo "</div>";break;}?><br /></td></tr><?phpinclude_once(TOP_DIR.'/footer.php');function multi_sort($array, $akey){ usort($array, "compare_asc_desc"); return $array;}function compare_asc_desc($a, $b){ global $global_key, $global_asc; /** * sort ascending */ if($global_asc) { if ($a[$global_key] == $b[$global_key]) return 0; if ($a[$global_key] < $b[$global_key]) return -1; return 1; } else { if ($a[$global_key] == $b[$global_key]) return 0; if ($a[$global_key] < $b[$global_key]) return 1; return -1; }}/** * calculate number of albums (recursive) * * it does not work correctly if this function is in the switch statement above!! * the function can be declared in the switch statement, but we try to access this * functione, i get on a hosting server an "internal server error" * on all other server it works normal * very strange..!! */function get_all_albums($dir_name, $countit, $choice, $highest){ global $countit; global $highest; global $the_name; if(is_readable($dir_name)) { $dirs = dir($dir_name); while($entry = $dirs->read()) { if ($entry{0} != "." && $entry != "Thumbs.db" && $entry != "ZbThumbnail.info") { if (is_dir("$dir_name/$entry")) { $albums_array[]=array("$dir_name/$entry"=>"$entry"); $countit++; get_all_albums("$dir_name/$entry", $countit, $choice, $highest); } } } $dirs->close(); clearstatcache(); } /* return either number of albums or most visited album */ if($choice=="albums") { /* return number of albums */ return $countit; } else { /* return most visited album */ $i=0; while(list($prev_path, $name) = @each($albums_array[$i])) { $query_visits=$GLOBALS['db']->Execute("SELECT SUM(res) ". "FROM ".PREFIX."photos ". "WHERE prev_path='".linpha_addslashes($prev_path)."' ". "AND name='".linpha_addslashes($name)."' ". "AND res !='0'"); $num_visits=$query_visits->fetchRow(); $visits_array[]=array("$prev_path" => "$num_visits[0]"); $i++; } } $i=0; while (list($path, $value) = @each ($visits_array[$i])) { if($value>$highest) { $highest=$value; $the_name=$path." [$highest]"; } $i++; } return $the_name;}function switch_dates($switch_dates){ $year = date("Y"); $month = date("n"); $day = date("j"); $weekday = date("w"); $this_week_from = $day-$weekday; $this_week_to = $day-$weekday+6; switch($switch_dates) { case 'all': break; case 'custom': $timestamp_from = ''; $timestamp_to = ''; break; case 'year_this': $timestamp_from = mktime(0,0,0,1,1,$year); $timestamp_to = mktime(23,59,59,12,31,$year); break; case 'year_last': $timestamp_from = mktime(0,0,0,1,1,$year-1); $timestamp_to = mktime(23,59,59,12,31,$year-1); break; case 'month_this': $timestamp_from = mktime(0,0,0,$month,1,$year); $timestamp_to = mktime(23,59,59,$month+1,0,$year); // mktime(hour,minute,sec,month,day,year) day=1 => 1., day=0 => 31., day=-1 => 30. break; case 'month_last': $timestamp_from = mktime(0,0,0,$month-1,1,$year); $timestamp_to = mktime(23,59,59,$month-1+1,0,$year); break; case 'week_this': $timestamp_from = mktime(0,0,0,$month,$this_week_from,$year); $timestamp_to = mktime(23,59,59,$month,$this_week_to,$year); break; case 'week_last': $timestamp_from = mktime(0,0,0,$month,$this_week_from-7,$year); $timestamp_to = mktime(23,59,59,$month,$this_week_to-7,$year); break; case 'today': $timestamp_from = mktime(0,0,0,$month,$day,$year); $timestamp_to = mktime(23,59,59,$month,$day,$year); break; case 'yesterday': $timestamp_from = mktime(0,0,0,$month,$day-1,$year); $timestamp_to = mktime(23,59,59,$month,$day-1,$year); break; default: echo "FATAL: no matching switching date"; break; } return Array($timestamp_from,$timestamp_to);}/** * take good care of date input fields */function is_valid_date($string){ if (eregi("^[0-9]{4}:[0-9]{2}:[0-9]{2}$", $string)) { $date_arr = explode(':', $string); if (checkdate($date_arr[1], $date_arr[2], $date_arr[0])) { unset($date_arr); return true; } else { unset($date_arr); return false; } } else { return false; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -