root/userbar.php

Revision 307, 2.4 kB (checked in by Nafania, 2 years ago)

Создаем табличку для чата (забыл совсем про нее). Меняем записи в логе о редактировании торрента и ставим flags = 9, только тогда, когда надо а не всегда. Замена везде exit на нормальные функции, которые вырубает кеш и закрывают соединение с базой, ибо это правильно. Небольшая фича на форуме, выделяем текст поста + клик на нике = быстрая цитата. Баны в чате и закрытие комментов в юзер панели. Вроде все.

Line 
1 <?php</span>
2 <span class="code-lang">$root_path = './';
3
4 $digits_template = $root_path . 'pic/font_visitor.png';
5 $template_file = $root_path . 'pic/userbar_template.png';
6
7 $rating_x = 306;
8 $rating_y = 6;
9
10 $class_x = 205;
11 $class_y = 6;
12
13 $digits_ini = array();
14 $n = 0;</span>
15 <span class="code-lang">for ( $i = 45; $i < 91; ++$i ) {
16     $digits_ini[chr($i)] = array(0 => $n, 1 => 7);
17     $n += 7;
18 }
19 $digits_ini[' '] = array(0 => 98, 1 => 7);
20 $users_class_name_arr = array('Leecher', 'User', 'Power user', 'VIP', 'Uploader', 'Moderator', 'Admin', 'Sysop');
21
22 $gd_enabled = ( function_exists('gd_info') ? true : false );</span>
23 <span class="code-lang">
24 if ( !$gd_enabled ) {
25     gc("GD library not installed");
26 }
27
28 $query = strtolower($_SERVER['REQUEST_URI']);</span>
29 <span class="code-lang">if ( !preg_match("/^(.*)userbar\.php\/(.*)\.png$/si", $query, $res) ) {
30     exit('invalid user');
31 }
32 $username = trim(urldecode($res[2]));
33 $img_file = $root_path . 'cache/png/' . $username . '.png';</span>
34 <span class="code-lang">
35 if ( !$digits_img = @imagecreatefrompng($digits_template) ) {
36     exit("Cannot Initialize new GD image stream!");
37 }
38 if ( !($img = @imagecreatefrompng($template_file)) ) {
39     exit("Cannot Initialize new GD image stream!");
40 }
41
42 if ( file_exists($img_file) && filemtime($img_file) > time() - 120 * 60 ) {
43     header('Content-type: image/png');
44     echo file_get_contents($img_file);
45 }
46 else {
47     require ($root_path . 'include/config.php');
48
49     $db->sql_return_on_error(true);
50
51     $sql = 'SELECT uploaded, downloaded, class FROM ' . USERS_TABLE . ' WHERE name = ' . "'" . $db->sql_escape($username) . "'";
52     $result = $db->sql_query($sql);
53     if ( !$row = $db->sql_fetchrow($result) ) {
54         gc('user not found');
55     }
56     else {
57         $ratio = 'R:' . ( $row['downloaded'] ? number_format($row['uploaded'] / $row['downloaded'], 1) : ( $row['uploaded'] ? 'INF.' : '---' ) );
58
59         for ($i = 0; $i < strlen($ratio); $i++) {
60             $d_x=$digits_ini[$ratio[$i]][0];
61             $d_w=$digits_ini[$ratio[$i]][1];
62             imagecopy($img, $digits_img, $rating_x, $rating_y, $d_x, 0, $d_w, imagesy($digits_img));
63             $rating_x=$rating_x+$d_w-1;
64         }
65
66         $class = $users_class_name_arr[$row['class']];
67         $class = 'CLASS:' . strtoupper($class);
68         for ($i = 0; $i < strlen($class); $i++) {
69             $d_x = $digits_ini[$class[$i]][0];
70             $d_w = $digits_ini[$class[$i]][1];
71             imagecopy($img, $digits_img, $class_x, $class_y, $d_x, 0, $d_w, imagesy($digits_img));
72             $class_x = $class_x + $d_w-1;
73         }
74         ImagePNG($img, $img_file);
75         header('Content-type: image/png');
76         ImagePNG($img);
77     }
78 }
79 ?>
Note: See TracBrowser for help on using the browser.