1 | <?php |
---|
2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | function parse_video_url($source_url, $safe_mode=false) |
---|
5 | { |
---|
6 | $source_url = 'http://'.preg_replace('#^http(s?)://#', null, trim($source_url)); |
---|
7 | |
---|
8 | $url = parse_url($source_url); |
---|
9 | $url['host'] = str_replace('www.', null, $url['host']); |
---|
10 | $url['host'] = explode('.', $url['host']); |
---|
11 | |
---|
12 | $video = array( |
---|
13 | 'type' => null, |
---|
14 | 'video_id' => null, |
---|
15 | 'url' => null, |
---|
16 | 'title' => null, |
---|
17 | 'description' => null, |
---|
18 | 'thumbnail' => null, |
---|
19 | 'author' => null, |
---|
20 | 'tags' => null, |
---|
21 | ); |
---|
22 | |
---|
23 | switch ($url['host'][0]) |
---|
24 | { |
---|
25 | /* youtube */ |
---|
26 | case 'youtube': |
---|
27 | { |
---|
28 | parse_str($url['query'], $url['query']); |
---|
29 | if (empty($url['query']['v'])) return false; |
---|
30 | |
---|
31 | $video['video_id'] = $url['query']['v']; |
---|
32 | } |
---|
33 | |
---|
34 | case 'youtu': // youtu.be (short-url service) |
---|
35 | { |
---|
36 | $video['type'] = 'youtube'; |
---|
37 | |
---|
38 | if (empty($video['video_id'])) |
---|
39 | { |
---|
40 | if ($url['host'][1] != 'be') return false; |
---|
41 | $url['path'] = explode('/', $url['path']); |
---|
42 | $video['video_id'] = $url['path'][1]; |
---|
43 | } |
---|
44 | |
---|
45 | $video['url'] = 'http://youtube.com/watch?v='.$video['video_id']; |
---|
46 | $video['title'] = 'YouTube #'.$video['video_id']; |
---|
47 | |
---|
48 | if (!$safe_mode) |
---|
49 | { |
---|
50 | $api_url = 'http://gdata.youtube.com/feeds/api/videos/'.$video['video_id'].'?v=2&alt=json'; |
---|
51 | $json = gvideo_download_remote_file($api_url, true); |
---|
52 | |
---|
53 | if ($json===false || $json=='file_error') return false; |
---|
54 | if (strip_tags($json) == 'GDataInvalidRequestUriExceptionInvalid id') return false; // unknown video |
---|
55 | if (strip_tags($json) == 'GDataServiceForbiddenExceptionPrivate video') return false; // private video |
---|
56 | |
---|
57 | $json = json_decode($json, true); |
---|
58 | $video = array_merge($video, array( |
---|
59 | 'title' => $json['entry']['media$group']['media$title']['$t'], |
---|
60 | 'description' => $json['entry']['media$group']['media$description']['$t'], |
---|
61 | 'thumbnail' => $json['entry']['media$group']['media$thumbnail'][2]['url'], |
---|
62 | 'author' => $json['entry']['author'][0]['name']['$t'], |
---|
63 | )); |
---|
64 | if (!empty($json['entry']['media$group']['media$keywords']['$t'])) |
---|
65 | { |
---|
66 | $video['tags'] = $json['entry']['media$group']['media$keywords']['$t']; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | break; |
---|
71 | } |
---|
72 | |
---|
73 | /* vimeo */ |
---|
74 | case 'vimeo': |
---|
75 | { |
---|
76 | $video['type'] = 'vimeo'; |
---|
77 | |
---|
78 | $url['path'] = explode('/', $url['path']); |
---|
79 | $video['video_id'] = $url['path'][1]; |
---|
80 | |
---|
81 | $video['url'] = 'http://vimeo.com/'.$video['video_id']; |
---|
82 | $video['title'] = 'Vimeo #'.$video['video_id']; |
---|
83 | |
---|
84 | if (!$safe_mode) |
---|
85 | { |
---|
86 | // simple API for public videos |
---|
87 | $api_url_1 = 'http://vimeo.com/api/v2/video/'.$video['video_id'].'.json'; |
---|
88 | $json = gvideo_download_remote_file($api_url_1, true); |
---|
89 | |
---|
90 | if ($json!==false && $json!='file_error' && trim($json)!=$video['video_id'].' not found.') |
---|
91 | { |
---|
92 | $json = json_decode($json, true); |
---|
93 | $video = array_merge($video, array( |
---|
94 | 'title' => $json[0]['title'], |
---|
95 | 'description' => $json[0]['description'], |
---|
96 | 'thumbnail' => $json[0]['thumbnail_large'], |
---|
97 | 'author' => $json[0]['user_name'], |
---|
98 | 'tags' => $json[0]['tags'], |
---|
99 | )); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | // oEmbed API, for private videos, doesn't return keywords |
---|
104 | $api_url_2 = 'http://vimeo.com/api/oembed.json?url='.rawurlencode($video['url']); |
---|
105 | $json = gvideo_download_remote_file($api_url_2, true); |
---|
106 | |
---|
107 | if ($json===false || $json=='file_error') return false; |
---|
108 | |
---|
109 | $json = json_decode($json, true); |
---|
110 | $video = array_merge($video, array( |
---|
111 | 'title' => $json['title'], |
---|
112 | 'description' => $json['description'], |
---|
113 | 'thumbnail' => $json['thumbnail_url'], |
---|
114 | 'author' => $json['author_name'], |
---|
115 | )); |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | break; |
---|
120 | } |
---|
121 | |
---|
122 | /* dailymotion */ |
---|
123 | case 'dailymotion': |
---|
124 | { |
---|
125 | $url['path'] = explode('/', $url['path']); |
---|
126 | if ($url['path'][1] != 'video') return false; |
---|
127 | $video['video_id'] = $url['path'][2]; |
---|
128 | } |
---|
129 | |
---|
130 | case 'dai': // dai.ly (short-url service) |
---|
131 | { |
---|
132 | $video['type'] = 'dailymotion'; |
---|
133 | |
---|
134 | if (empty($video['video_id'])) |
---|
135 | { |
---|
136 | if ($url['host'][1] != 'ly') return false; |
---|
137 | $video['video_id'] = ltrim($url['path'], '/'); |
---|
138 | } |
---|
139 | |
---|
140 | $video['url'] = 'http://dailymotion.com/video/'.$video['video_id']; |
---|
141 | $video['title'] = 'Dailymotion #'.$video['video_id']; |
---|
142 | |
---|
143 | if (!$safe_mode) |
---|
144 | { |
---|
145 | $api_url = 'https://api.dailymotion.com/video/'.$video['video_id'].'?fields=description,thumbnail_large_url,title,owner.username,tags'; // DM doesn't accept non secure connection |
---|
146 | $json = gvideo_download_remote_file($api_url, true); |
---|
147 | |
---|
148 | if ($json===false || $json=='file_error') return false; |
---|
149 | |
---|
150 | $json = json_decode($json, true); |
---|
151 | if (@$json['error']['type'] == 'access_forbidden') return false; // private video |
---|
152 | $json['thumbnail_large_url'] = preg_replace('#\?([0-9]+)$#', null, $json['thumbnail_large_url']); |
---|
153 | |
---|
154 | $video = array_merge($video, array( |
---|
155 | 'title' => $json['title'], |
---|
156 | 'description' => $json['description'], |
---|
157 | 'thumbnail' => $json['thumbnail_large_url'], |
---|
158 | 'author' => $json['owner.username'], |
---|
159 | 'tags' => implode(',', $json['tags']), |
---|
160 | )); |
---|
161 | } |
---|
162 | |
---|
163 | break; |
---|
164 | } |
---|
165 | |
---|
166 | /* wat */ |
---|
167 | case 'wat': |
---|
168 | { |
---|
169 | if ($safe_mode) return false; |
---|
170 | |
---|
171 | $html = gvideo_download_remote_file($source_url, true); |
---|
172 | |
---|
173 | if ($html===false || $html=='file_error') return false; |
---|
174 | |
---|
175 | $video['type'] = 'wat'; |
---|
176 | $video['url'] = $source_url; |
---|
177 | |
---|
178 | preg_match('#<meta name="twitter:player" content="https://www.wat.tv/embedframe/([^">]+)">#', $html, $matches); |
---|
179 | if (empty($matches[1])) return false; |
---|
180 | $video['video_id'] = $matches[1]; |
---|
181 | |
---|
182 | preg_match('#<meta property="og:title" content="([^">]*)">#', $html, $matches); |
---|
183 | $video['title'] = $matches[1]; |
---|
184 | |
---|
185 | preg_match('#<meta property="og:description" content="([^">]*)">#s', $html, $matches); |
---|
186 | $video['description'] = $matches[1]; |
---|
187 | |
---|
188 | preg_match('#<meta property="og:image" content="([^">]+)">#', $html, $matches); |
---|
189 | $video['thumbnail'] = $matches[1]; |
---|
190 | |
---|
191 | preg_match('#<meta property="video:director" content="http://www.wat.tv/([^">]+)">#', $html, $matches); |
---|
192 | $video['author'] = $matches[1]; |
---|
193 | |
---|
194 | preg_match_all('#<meta property="video:tag" content="([^">]+)">#', $html, $matches); |
---|
195 | $video['tags'] = implode(',', $matches[1]); |
---|
196 | |
---|
197 | break; |
---|
198 | } |
---|
199 | |
---|
200 | /* wideo */ |
---|
201 | case 'wideo': |
---|
202 | { |
---|
203 | $video['type'] = 'wideo'; |
---|
204 | |
---|
205 | $url['path'] = explode('/', $url['path']); |
---|
206 | $video['video_id'] = rtrim($url['path'][2], '.html'); |
---|
207 | |
---|
208 | $video['url'] = 'http://wideo.fr/video/'.$video['video_id'].'.html'; |
---|
209 | $video['title'] = 'Wideo #'.$video['video_id']; |
---|
210 | |
---|
211 | if (!$safe_mode) |
---|
212 | { |
---|
213 | $html = gvideo_download_remote_file($source_url, true); |
---|
214 | |
---|
215 | if ($html===false || $html=='file_error') return false; |
---|
216 | |
---|
217 | preg_match('#<meta property="og:title" content="([^">]*)" />#', $html, $matches); |
---|
218 | $video['title'] = $matches[1]; |
---|
219 | |
---|
220 | preg_match('#<meta property="og:description" content="([^">]*)" />#s', $html, $matches); |
---|
221 | $video['description'] = $matches[1]; |
---|
222 | |
---|
223 | preg_match('#<meta property="og:image" content="([^">]+)" />#', $html, $matches); |
---|
224 | $video['thumbnail'] = $matches[1]; |
---|
225 | |
---|
226 | preg_match('#<li id="li_author">Auteur : <a href=(?:[^>]*)><span>(.*?)</span></a>#', $html, $matches); |
---|
227 | $video['author'] = $matches[1]; |
---|
228 | |
---|
229 | preg_match('#<meta name="keywords" content="([^">]+)" />#', $html, $matches); |
---|
230 | $video['tags'] = $matches[1]; |
---|
231 | } |
---|
232 | |
---|
233 | break; |
---|
234 | } |
---|
235 | |
---|
236 | default: |
---|
237 | return false; |
---|
238 | } |
---|
239 | |
---|
240 | return $video; |
---|
241 | } |
---|
242 | |
---|
243 | /** |
---|
244 | * @params: |
---|
245 | * $video (from parse_video_url) |
---|
246 | * $config : |
---|
247 | * - category, integer |
---|
248 | * - add_film_frame, boolean |
---|
249 | * - sync_description, boolean |
---|
250 | * - sync_tags, boolean |
---|
251 | * - with, integer |
---|
252 | * - height, integer |
---|
253 | * - autoplay, integer (0-1) |
---|
254 | */ |
---|
255 | function add_video($video, $config) |
---|
256 | { |
---|
257 | global $page, $conf; |
---|
258 | |
---|
259 | $query = ' |
---|
260 | SELECT picture_id |
---|
261 | FROM '.GVIDEO_TABLE.' |
---|
262 | WHERE type = "'.$video['type'].'" |
---|
263 | AND video_id = "'.$video['video_id'].'" |
---|
264 | ;'; |
---|
265 | $result = pwg_query($query); |
---|
266 | |
---|
267 | if (pwg_db_num_rows($result)) |
---|
268 | { |
---|
269 | $page['warnings'][] = l10n('This video was already registered'); |
---|
270 | list($image_id) = pwg_db_fetch_row($result); |
---|
271 | return $image_id; |
---|
272 | } |
---|
273 | |
---|
274 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); |
---|
275 | |
---|
276 | // download thumbnail |
---|
277 | $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']); |
---|
278 | $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext; |
---|
279 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
280 | |
---|
281 | if (empty($video['thumbnail']) or gvideo_download_remote_file($video['thumbnail'], $thumb_source) !== true) |
---|
282 | { |
---|
283 | $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg'; |
---|
284 | copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source); |
---|
285 | } |
---|
286 | |
---|
287 | if ($config['add_film_frame']) |
---|
288 | { |
---|
289 | add_film_frame($thumb_source); |
---|
290 | } |
---|
291 | |
---|
292 | // add image and update infos |
---|
293 | $image_id = add_uploaded_file($thumb_source, $thumb_name, array($config['category'])); |
---|
294 | |
---|
295 | $updates = array( |
---|
296 | 'name' => pwg_db_real_escape_string($video['title']), |
---|
297 | 'author' => pwg_db_real_escape_string($video['author']), |
---|
298 | 'is_gvideo' => 1, |
---|
299 | ); |
---|
300 | |
---|
301 | if ($config['sync_description'] and !empty($video['description'])) |
---|
302 | { |
---|
303 | $updates['comment'] = pwg_db_real_escape_string($video['description']); |
---|
304 | } |
---|
305 | |
---|
306 | if ($config['sync_tags'] and !empty($video['tags'])) |
---|
307 | { |
---|
308 | $tags = pwg_db_real_escape_string($video['tags']); |
---|
309 | set_tags(get_tag_ids($tags), $image_id); |
---|
310 | } |
---|
311 | |
---|
312 | single_update( |
---|
313 | IMAGES_TABLE, |
---|
314 | $updates, |
---|
315 | array('id' => $image_id), |
---|
316 | true |
---|
317 | ); |
---|
318 | |
---|
319 | // register video |
---|
320 | if (!preg_match('#^([0-9]*)$#', $config['width']) or !preg_match('#^([0-9]*)$#', $config['height'])) |
---|
321 | { |
---|
322 | $config['width'] = $config['height'] = ''; |
---|
323 | } |
---|
324 | if ($config['autoplay']!='0' and $config['autoplay']!='1') |
---|
325 | { |
---|
326 | $config['autoplay'] = ''; |
---|
327 | } |
---|
328 | |
---|
329 | $insert = array( |
---|
330 | 'picture_id' => $image_id, |
---|
331 | 'url' => $video['url'], |
---|
332 | 'type' => $video['type'], |
---|
333 | 'video_id' => $video['video_id'], |
---|
334 | 'width' => $config['width'], |
---|
335 | 'height' => $config['height'], |
---|
336 | 'autoplay' => $config['autoplay'], |
---|
337 | ); |
---|
338 | |
---|
339 | single_insert( |
---|
340 | GVIDEO_TABLE, |
---|
341 | $insert |
---|
342 | ); |
---|
343 | |
---|
344 | return $image_id; |
---|
345 | } |
---|
346 | |
---|
347 | /** |
---|
348 | * test if a download method is available |
---|
349 | * @return: bool |
---|
350 | */ |
---|
351 | if (!function_exists('test_remote_download')) |
---|
352 | { |
---|
353 | function test_remote_download() |
---|
354 | { |
---|
355 | return function_exists('curl_init') || ini_get('allow_url_fopen'); |
---|
356 | } |
---|
357 | } |
---|
358 | |
---|
359 | /** |
---|
360 | * download a remote file |
---|
361 | * - needs cURL or allow_url_fopen |
---|
362 | * - take care of SSL urls |
---|
363 | * |
---|
364 | * @param: string source url |
---|
365 | * @param: mixed destination file (if true, file content is returned) |
---|
366 | */ |
---|
367 | function gvideo_download_remote_file($src, $dest, $headers=array()) |
---|
368 | { |
---|
369 | if (empty($src)) |
---|
370 | { |
---|
371 | return false; |
---|
372 | } |
---|
373 | |
---|
374 | $return = ($dest === true) ? true : false; |
---|
375 | |
---|
376 | $headers[] = 'Accept-language: en'; |
---|
377 | |
---|
378 | /* curl */ |
---|
379 | if (function_exists('curl_init')) |
---|
380 | { |
---|
381 | if (!$return) |
---|
382 | { |
---|
383 | $newf = fopen($dest, "wb"); |
---|
384 | } |
---|
385 | $ch = curl_init(); |
---|
386 | |
---|
387 | curl_setopt($ch, CURLOPT_URL, $src); |
---|
388 | curl_setopt($ch, CURLOPT_HEADER, false); |
---|
389 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
---|
390 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'); |
---|
391 | curl_setopt($ch, CURLOPT_TIMEOUT, 30); |
---|
392 | if (!ini_get('safe_mode')) |
---|
393 | { |
---|
394 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
---|
395 | curl_setopt($ch, CURLOPT_MAXREDIRS, 1); |
---|
396 | } |
---|
397 | if (strpos($src, 'https://') !== false) |
---|
398 | { |
---|
399 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
---|
400 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
---|
401 | } |
---|
402 | if (!$return) |
---|
403 | { |
---|
404 | curl_setopt($ch, CURLOPT_FILE, $newf); |
---|
405 | } |
---|
406 | else |
---|
407 | { |
---|
408 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
---|
409 | } |
---|
410 | |
---|
411 | $out = curl_exec($ch); |
---|
412 | curl_close($ch); |
---|
413 | |
---|
414 | if ($out === false) |
---|
415 | { |
---|
416 | return 'file_error'; |
---|
417 | } |
---|
418 | else if (!$return) |
---|
419 | { |
---|
420 | fclose($newf); |
---|
421 | return true; |
---|
422 | } |
---|
423 | else |
---|
424 | { |
---|
425 | return $out; |
---|
426 | } |
---|
427 | } |
---|
428 | /* file get content */ |
---|
429 | else if (ini_get('allow_url_fopen')) |
---|
430 | { |
---|
431 | if (strpos($src, 'https://') !== false and !extension_loaded('openssl')) |
---|
432 | { |
---|
433 | return false; |
---|
434 | } |
---|
435 | |
---|
436 | $opts = array( |
---|
437 | 'http' => array( |
---|
438 | 'method' => "GET", |
---|
439 | 'user_agent' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)', |
---|
440 | 'header' => implode("\r\n", $headers), |
---|
441 | ) |
---|
442 | ); |
---|
443 | |
---|
444 | $context = stream_context_create($opts); |
---|
445 | |
---|
446 | if (($file = file_get_contents($src, false, $context)) === false) |
---|
447 | { |
---|
448 | return 'file_error'; |
---|
449 | } |
---|
450 | |
---|
451 | if (!$return) |
---|
452 | { |
---|
453 | file_put_contents($dest, $file); |
---|
454 | return true; |
---|
455 | } |
---|
456 | else |
---|
457 | { |
---|
458 | return $file; |
---|
459 | } |
---|
460 | } |
---|
461 | |
---|
462 | return false; |
---|
463 | } |
---|
464 | |
---|
465 | /** |
---|
466 | * and film frame to an image (need GD library) |
---|
467 | * @param: string source |
---|
468 | * @param: string destination (if null, the source is modified) |
---|
469 | * @return: void |
---|
470 | */ |
---|
471 | function add_film_frame($src, $dest=null) |
---|
472 | { |
---|
473 | if (empty($dest)) |
---|
474 | { |
---|
475 | $dest = $src; |
---|
476 | } |
---|
477 | |
---|
478 | // we need gd library |
---|
479 | if (!function_exists('imagecreatetruecolor')) |
---|
480 | { |
---|
481 | if ($dest != $src) copy($src, $dest); |
---|
482 | return; |
---|
483 | } |
---|
484 | |
---|
485 | // open source image |
---|
486 | switch (strtolower(get_extension($src))) |
---|
487 | { |
---|
488 | case 'jpg': |
---|
489 | case 'jpeg': |
---|
490 | $srcImage = imagecreatefromjpeg($src); |
---|
491 | break; |
---|
492 | case 'png': |
---|
493 | $srcImage = imagecreatefrompng($src); |
---|
494 | break; |
---|
495 | case 'gif': |
---|
496 | $srcImage = imagecreatefromgif($src); |
---|
497 | break; |
---|
498 | default: |
---|
499 | if ($dest != $src) copy($src, $dest); |
---|
500 | return; |
---|
501 | } |
---|
502 | |
---|
503 | // source properties |
---|
504 | $srcWidth = imagesx($srcImage); |
---|
505 | $srcHeight = imagesy($srcImage); |
---|
506 | $const = intval($srcWidth * 0.04); |
---|
507 | $bandRadius = floor($const/8); |
---|
508 | |
---|
509 | // band properties |
---|
510 | $imgBand = imagecreatetruecolor($srcWidth + 6*$const, $srcHeight + 3*$const); |
---|
511 | |
---|
512 | $black = imagecolorallocate($imgBand, 0, 0, 0); |
---|
513 | $white = imagecolorallocate($imgBand, 245, 245, 245); |
---|
514 | |
---|
515 | // and dots |
---|
516 | $y_start = intval(($srcHeight + 3*$const) / 2); |
---|
517 | $aug = intval($y_start / 5) + 1; |
---|
518 | $i = 0; |
---|
519 | |
---|
520 | while ($y_start + $i*$aug < $srcHeight + 3*$const) |
---|
521 | { |
---|
522 | imagefilledroundrectangle($imgBand, (3/4)*$const, $y_start + $i*$aug - $const/2, (9/4)*$const - 1, $y_start + $i*$aug + $const/2 - 1, $white, $bandRadius); |
---|
523 | imagefilledroundrectangle($imgBand, (3/4)*$const, $y_start - $i*$aug - $const/2, (9/4)*$const - 1, $y_start - $i*$aug + $const/2 - 1, $white, $bandRadius); |
---|
524 | |
---|
525 | imagefilledroundrectangle($imgBand, $srcWidth + (15/4)*$const, $y_start + $i*$aug - $const/2, $srcWidth + (21/4)*$const - 1, $y_start + $i*$aug + $const/2 - 1, $white, $bandRadius); |
---|
526 | imagefilledroundrectangle($imgBand, $srcWidth + (15/4)*$const, $y_start - $i*$aug - $const/2, $srcWidth + (21/4)*$const - 1, $y_start - $i*$aug + $const/2 - 1, $white, $bandRadius); |
---|
527 | |
---|
528 | ++$i; |
---|
529 | } |
---|
530 | |
---|
531 | // add source to band |
---|
532 | imagecopy($imgBand, $srcImage, 3*$const, (3/2)*$const, 0, 0, $srcWidth, $srcHeight); |
---|
533 | |
---|
534 | // save image |
---|
535 | switch (strtolower(get_extension($dest))) |
---|
536 | { |
---|
537 | case 'jpg': |
---|
538 | case 'jpeg': |
---|
539 | imagejpeg($imgBand, $dest, 85); |
---|
540 | break; |
---|
541 | case 'png': |
---|
542 | imagepng($imgBand, $dest); |
---|
543 | break; |
---|
544 | case 'gif': |
---|
545 | imagegif($imgBand, $dest); |
---|
546 | break; |
---|
547 | } |
---|
548 | } |
---|
549 | |
---|
550 | /** |
---|
551 | * create a rectangle with round corners |
---|
552 | * http://www.php.net/manual/fr/function.imagefilledrectangle.php#42815 |
---|
553 | */ |
---|
554 | function imagefilledroundrectangle(&$img, $x1, $y1, $x2, $y2, $color, $radius) |
---|
555 | { |
---|
556 | imagefilledrectangle($img, $x1+$radius, $y1, $x2-$radius, $y2, $color); |
---|
557 | |
---|
558 | if ($radius > 0) |
---|
559 | { |
---|
560 | imagefilledrectangle($img, $x1, $y1+$radius, $x2, $y2-$radius, $color); |
---|
561 | imagefilledellipse($img, $x1+$radius, $y1+$radius, $radius*2, $radius*2, $color); |
---|
562 | imagefilledellipse($img, $x2-$radius, $y1+$radius, $radius*2, $radius*2, $color); |
---|
563 | imagefilledellipse($img, $x1+$radius, $y2-$radius, $radius*2, $radius*2, $color); |
---|
564 | imagefilledellipse($img, $x2-$radius, $y2-$radius, $radius*2, $radius*2, $color); |
---|
565 | } |
---|
566 | } |
---|