File: progress.php

package info (click to toggle)
fusiondirectory 1.0.8.2-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 28,984 kB
  • sloc: php: 74,645; xml: 3,645; perl: 1,555; pascal: 705; sh: 135; sql: 45; makefile: 19
file content (102 lines) | stat: -rw-r--r-- 2,909 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php

/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003-2010  Cajus Pollmeier
  Copyright (C) 2011-2013  FusionDirectory

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/

session_cache_limiter("private");

/* Check for parameter completenes */
if (!isset($_GET['x']) || !isset($_GET['y']) || !isset($_GET['p'])) {
  die ("Missing parameters!");
}
if (!is_numeric($_GET['x']) || !is_numeric($_GET['y'])) {
  die ("Parameters must be numeric!");
}

$p = (int)($_GET['p']);
$x = (int)($_GET['x']);
$y = (int)($_GET['y']);

/* Check percentage */
if ($p < 0) {
  $p = 0;
} elseif ($p > 100) {
  $p = 100;
}
$p = intval ($p);

/* Check dimensions */
if ($x < 3 || $x > 1000) {
  $x = 180;
}
if ($y < 3 || $y > 700) {
  $y = 20;
}

if (!function_exists("imagecreate")) {
  syslog(LOG_ERR, "FusionDirectory is missing the gd library, please install php5-gd to be able to see progress images.");
  echo "Please install the php5-gd library, FusionDirectory can't create images without it.";
  exit();
} else {

  $x_matches = FALSE;
  $y_matches = FALSE;
  foreach (array(7,6,5,4,3,2,1,0) as $font) {
    $fx = ImageFontWidth($font) * strlen("$p%");
    $fy = ImageFontHeight($font);

    /* Look if font size matches image size */
    if ($fx < ($x - 2)) {
      $x_matches = TRUE;
    }
    if ($fy < ($y - 2)) {
      $y_matches = TRUE;
    }
    if ($x_matches && $y_matches) {
      break;
    }
  }

  /* Draw image in GD image stream */
  $im = imagecreate ($x, $y)
    or die ("Cannot Initialize new GD image stream");

  /* Set colors */
  $bg_color = imagecolorallocate($im, 255,  255,  255);
  $br_color = imagecolorallocate($im, 0,    0,    0);
  $fi_color = imagecolorallocate($im, 0,    0,    180);
  $tx_color = imagecolorallocate($im, 240,  10,   90);

  /* Draw progress bar */
  imagerectangle ($im, 0, 0, $x - 1, $y - 1, $br_color);
  imagefilledrectangle ($im, 1, 1, (($x - 2) * $p / 100),
      $y - 2, $fi_color);

  /* Is font to big for progress bar? */
  if ($font != 0) {
    imagestring ($im, $font, ($x - $fx) / 2, ($y - $fy) / 2, "$p%", $tx_color);
  }

  /* Finally draw the image and remove context */
  header ("Content-type: image/png");
  imagepng ($im);
  imagedestroy ($im);
}
?>