3
* Xibo - Digital Signage - http://www.xibo.org.uk
4
* Copyright (C) 2006,2007,2008 Daniel Garner and James Packer
6
* This file is part of Xibo.
8
* Xibo is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Affero General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
13
* Xibo is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
18
* You should have received a copy of the GNU Affero General Public License
19
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
23
defined('XIBO') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");
25
define('VAR_FOR_SQL',1);
27
define('MSG_MODE_MANUAL',2);
28
define('MSG_MODE_AUTO',1);
30
define('AJAX_REDIRECT',3);
31
define('AJAX_SUCCESS_NOREDIRECT',4);
32
define('AJAX_SUCCESS_REFRESH',5);
33
define('AJAX_LOAD_FORM',6);
36
* Sets a message to display, this is checked when each page loads
38
* @param string $message
40
function setMessage($message) {
41
if (!isset($_SESSION['message'])) $_SESSION['message'] = "";
42
$_SESSION['message'] = $message;
45
function listcontent($list_string, $list_name, $selected = "", $callback = "")
47
//generates a list based on a list option | value, list
48
if ($list_string == "") return "Empty list content";
50
$list_string = rtrim($list_string,","); //clean up
52
$list_values = explode(",", $list_string); //gives us each option value pair
55
<select name="$list_name" id="$list_name" $callback>
57
foreach ($list_values as $list_option)
60
$option = explode("|", $list_option);
65
if ($col0 == $selected)
67
$list .= "<option value='" . $col0 . "' selected>" . $col1 . "</option>\n";
71
$list .= "<option value='" . $col0 . "'>" . $col1 . "</option>\n";
74
$list .= "</select>\n";
81
* Sets a session variable from a javascript call (so when we XMLHTTPRequest we can set a sesson var)
85
* @param $value Object
87
function setSession($page, $var, $value)
89
$_SESSION[$page][$var] = $value;
94
function sec2hms($sec, $padHours = false)
96
// holds formatted string
99
// there are 3600 seconds in an hour, so if we
100
// divide total seconds by 3600 and throw away
101
// the remainder, we've got the number of hours
102
$hours = intval(intval($sec) / 3600);
104
// add to $hms, with a leading 0 if asked for
105
$hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT) . ':':$hours . ':';
107
// dividing the total seconds by 60 will give us
108
// the number of minutes, but we're interested in
109
// minutes past the hour: to get that, we need to
110
// divide by 60 again and keep the remainder
111
$minutes = intval(($sec / 60) % 60);
113
// then add to $hms (with a leading 0 if needed)
114
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT) . ':';
116
// seconds are simple - just divide the total
117
// seconds by 60 and keep the remainder
118
$seconds = intval($sec % 60);
120
// add to $hms, again with a leading 0 if needed
121
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
129
* Based on code from the Web - cannot find source.
130
* If this is your code please send a mail to info@xibo.org.uk
131
* to arrange for correct acknowledgement to be printed.
133
* @param $file Object The Source File
134
* @param $target Object The Target File
135
* @param $width Object[optional] The Width
136
* @param $height Object[optional] The Height
137
* @param $proportional Object[optional] Proportional Resize
138
* @param $output Object[optional] file|browser|return
139
* @param $delete_original Object[optional]
140
* @param $use_linux_commands Object[optional]
142
function ResizeImage( $file, $target = "", $width = 0, $height = 0, $proportional = false, $output = 'file', $delete_original = false, $use_linux_commands = false )
144
if ( $height <= 0 && $width <= 0 )
149
$info = getimagesize($file);
154
list($width_old, $height_old) = $info;
158
if ($width == 0) $factor = $height/$height_old;
159
elseif ($height == 0) $factor = $width/$width_old;
160
else $factor = min ( $width / $width_old, $height / $height_old);
162
$final_width = round ($width_old * $factor);
163
$final_height = round ($height_old * $factor);
168
$final_width = ( $width <= 0 ) ? $width_old : $width;
169
$final_height = ( $height <= 0 ) ? $height_old : $height;
175
$image = imagecreatefromgif($file);
178
$image = imagecreatefromjpeg($file);
181
$image = imagecreatefrompng($file);
187
$image_resized = imagecreatetruecolor( $final_width, $final_height );
189
if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) )
191
$trnprt_indx = imagecolortransparent($image);
193
// If we have a specific transparent color
194
if ($trnprt_indx >= 0)
197
// Get the original image's transparent color's RGB values
198
$trnprt_color = imagecolorsforindex($image, $trnprt_indx);
200
// Allocate the same color in the new image resource
201
$trnprt_indx = imagecolorallocate($image_resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
203
// Completely fill the background of the new image with allocated color.
204
imagefill($image_resized, 0, 0, $trnprt_indx);
206
// Set the background color for new image to transparent
207
imagecolortransparent($image_resized, $trnprt_indx);
209
// Always make a transparent background color for PNGs that don't have one allocated already
210
elseif ($info[2] == IMAGETYPE_PNG)
212
// Turn off transparency blending (temporarily)
213
imagealphablending($image_resized, false);
215
// Create a new transparent color for image
216
$color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
218
// Completely fill the background of the new image with allocated color.
219
imagefill($image_resized, 0, 0, $color);
221
// Restore transparency blending
222
imagesavealpha($image_resized, true);
226
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);
228
if ( $delete_original )
230
if ( $use_linux_commands )
236
switch ( strtolower($output) )
239
$mime = image_type_to_mime_type($info[2]);
240
header("Content-type: $mime");
247
return $image_resized;
253
switch ( $info[2] ) {
255
imagegif($image_resized, $output);
258
imagejpeg($image_resized, $output, 70);
261
imagepng($image_resized, $output, 5);
271
* Creates a form token
274
function CreateFormToken($tokenName = "token")
276
//Store in the users session
277
$token = md5(uniqid()."xsmsalt".time());
279
$_SESSION[$tokenName] = $token;
280
$_SESSION[$tokenName.'_timeout'] = time();
286
* Checks a form token
287
* @param string token
290
function CheckFormToken($token, $tokenName = "token")
294
if ($token == $_SESSION[$tokenName])
296
// See if its still in Date
297
if (($_SESSION[$tokenName.'_timeout'] + 1200) <= time())
305
unset($_SESSION[$tokenName]);
307
Log::error("Form token incorrect from: ". $_SERVER['REMOTE_ADDR']. " with token [$token] for session_id [" . session_id() . ']');
313
* Convert a shorthand byte value from a PHP configuration directive to an integer value
314
* @param string $value
317
function convertBytes( $value )
319
if ( is_numeric( $value ) )
325
$value_length = strlen( $value );
326
$qty = substr( $value, 0, $value_length - 1 );
327
$unit = strtolower( substr( $value, $value_length - 1 ) );
b'\\ No newline at end of file'