source: extensions/header_manager/include/functions.inc.php @ 15854

Last change on this file since 15854 was 15854, checked in by mistic100, 12 years ago

initial release

File size: 3.3 KB
Line 
1<?php
2if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
3
4/**
5 * give a list of available banners
6 * @param: bool delete_orphans (from unachieved cropping process)
7 */
8function list_banners($delete_orphans=false)
9{
10  $dir = scandir(HEADER_MANAGER_DIR);
11  $banners = array();
12 
13  foreach ($dir as $file)
14  {
15    if ( in_array($file, array('.','..','index.php','.svn')) ) continue;
16    if ( !in_array(strtolower(get_extension($file)), array('jpg','jpeg','png','gif')) ) continue;
17    if ( strpos($file, '-thumbnail')!==false ) continue;
18
19    array_push($banners, get_banner($file));
20   
21    if ( $delete_orphans and !file_exists($banners[ count($banners)-1 ]['THUMB']) )
22    {
23      @unlink($banners[ count($banners)-1 ]['PATH']);
24      array_pop($banners);
25    }
26  }
27 
28  return $banners;
29}
30
31/**
32 * get full size and thumbnail urls and size for a banner
33 * @param: string filename
34 */
35function get_banner($file)
36{
37  if (file_exists(HEADER_MANAGER_DIR . $file))
38  {
39    return array(
40      'NAME' => $file,
41      'PATH' => HEADER_MANAGER_DIR . $file,
42      'THUMB' => HEADER_MANAGER_DIR . get_filename_wo_extension($file) . '-thumbnail.'. get_extension($file),
43      'SIZE' => getimagesize(HEADER_MANAGER_DIR . $file),
44      );
45  }
46  else
47  {
48    return false;
49  }
50}
51
52/**
53 * get properties of the jCrop window
54 * @param: array picture(width, height[, coi])
55 * @return: array crop(display_width, display_height, l, r, t, b, coi(x, y))
56 */
57function get_crop_display($picture)
58{
59  global $conf;
60 
61  // find coi
62  if (!empty($picture['coi']))
63  {
64    $picture['coi'] = array(
65      'l' => char_to_fraction($picture['coi'][0])*$picture['width'],
66      't' => char_to_fraction($picture['coi'][1])*$picture['height'],
67      'r' => char_to_fraction($picture['coi'][2])*$picture['width'],
68      'b' => char_to_fraction($picture['coi'][3])*$picture['height'],
69      );
70  }
71  else
72  {
73    $picture['coi'] = array(
74      'l' => 0,
75      't' => 0,
76      'r' => $picture['width'],
77      'b' => $picture['height'],
78      );
79  }
80  $crop['coi']['x'] = ($picture['coi']['r']+$picture['coi']['l'])/2;
81  $crop['coi']['y'] = ($picture['coi']['b']+$picture['coi']['t'])/2;
82 
83  // define default crop frame
84  if ($picture['width'] > $conf['header_manager']['width'])
85  {
86    $crop['display_width'] = $conf['header_manager']['width'];
87    $crop['display_height'] = round($picture['height']*$crop['display_width']/$picture['width']);
88   
89    $crop['coi']['x'] = round($crop['coi']['x']*$crop['display_width']/$picture['width']);
90    $crop['coi']['y'] = round($crop['coi']['y']*$crop['display_height']/$picture['height']);
91   
92    $crop['l'] = 0;
93    $crop['r'] = $conf['header_manager']['width'];
94    $crop['t'] = max(0, $crop['coi']['y']-$conf['header_manager']['height']/2);
95    $crop['b'] = min($crop['display_height'], $crop['t']+$conf['header_manager']['height']);
96  }
97  else
98  {
99    $crop['display_width'] = $picture['width'];
100    $crop['display_height'] = $picture['height'];
101   
102    $adapted_crop_height = round($conf['header_manager']['height']*$picture['width']/$conf['header_manager']['width']);
103   
104    $crop['l'] = 0;
105    $crop['r'] = $picture['width'];
106    $crop['t'] = max(0, $crop['coi']['y']-$adapted_crop_height/2);
107    $crop['b'] = min($crop['display_height'], $crop['t']+$adapted_crop_height);
108  }
109 
110  return $crop;
111}
112
113?>
Note: See TracBrowser for help on using the repository browser.