1 | <?php |
---|
2 | |
---|
3 | final class SrcImage |
---|
4 | { |
---|
5 | public $rel_path; |
---|
6 | public $coi=null; |
---|
7 | private $size=null; |
---|
8 | |
---|
9 | function __construct($infos) |
---|
10 | { |
---|
11 | global $conf; |
---|
12 | |
---|
13 | $ext = get_extension($infos['path']); |
---|
14 | if (in_array($ext, $conf['picture_ext'])) |
---|
15 | { |
---|
16 | $this->rel_path = $infos['path']; |
---|
17 | } |
---|
18 | elseif (!empty($infos['representative_ext'])) |
---|
19 | { |
---|
20 | $pi = pathinfo($infos['path']); |
---|
21 | $file_wo_ext = get_filename_wo_extension($pi['basename']); |
---|
22 | $this->rel_path = $pi['dirname'].'/pwg_representative/' |
---|
23 | .$file_wo_ext.'.'.$infos['representative_ext']; |
---|
24 | } |
---|
25 | else |
---|
26 | { |
---|
27 | $this->rel_path = get_themeconf('mime_icon_dir').strtolower($ext).'.png'; |
---|
28 | } |
---|
29 | |
---|
30 | $this->coi = @$infos['coi']; |
---|
31 | if (isset($infos['width']) && isset($infos['height'])) |
---|
32 | { |
---|
33 | $this->size = array($infos['width'], $infos['height']); |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | function get_size() |
---|
38 | { |
---|
39 | if ($this->size == null) |
---|
40 | not_implemented(); // get size from file |
---|
41 | return $this->size; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | final class DerivativeImage |
---|
46 | { |
---|
47 | public $src_image; |
---|
48 | private $params; |
---|
49 | private $rel_path, $rel_url; |
---|
50 | |
---|
51 | function __construct($type, $infos) |
---|
52 | { |
---|
53 | $this->src_image = new SrcImage($infos); |
---|
54 | self::build($type, $src_image, $this->rel_path, $this->rel_url, $this->params); |
---|
55 | } |
---|
56 | |
---|
57 | static function thumb_url($infos) |
---|
58 | { |
---|
59 | $src_image = new SrcImage($infos); |
---|
60 | self::build(IMG_THUMB, $src_image, $rel_path, $rel_url); |
---|
61 | //die($rel_url); |
---|
62 | return get_root_url().$rel_url; |
---|
63 | } |
---|
64 | |
---|
65 | static function url($type, $infos) |
---|
66 | { |
---|
67 | $src_image = new SrcImage($infos); |
---|
68 | self::build($type, $src_image, $rel_path, $rel_url); |
---|
69 | return get_root_url().$rel_url; |
---|
70 | } |
---|
71 | |
---|
72 | private static function build($type, $src, &$rel_path, &$rel_url, &$params = null) |
---|
73 | { |
---|
74 | if (is_string($type)) |
---|
75 | { |
---|
76 | $params = ImageStdParams::get_by_type($type); |
---|
77 | } |
---|
78 | else |
---|
79 | { |
---|
80 | $type = IMG_CUSTOM; |
---|
81 | } |
---|
82 | |
---|
83 | // todo check if we should not downgrade to a different type because |
---|
84 | // original file is too small ... |
---|
85 | // we are using a mime type icon ... |
---|
86 | // etc... |
---|
87 | |
---|
88 | $tokens=array(); |
---|
89 | $tokens[] = substr($type,0,2); |
---|
90 | |
---|
91 | if (!empty($src->coi)) |
---|
92 | { |
---|
93 | $tokens[] = 'ci'.$src->coi; |
---|
94 | } |
---|
95 | |
---|
96 | if ($type==IMG_CUSTOM) |
---|
97 | { |
---|
98 | $params->add_url_tokens($tokens); |
---|
99 | } |
---|
100 | |
---|
101 | $loc = $src->rel_path; |
---|
102 | if (substr_compare($loc, '../', 0, 3)==0) |
---|
103 | { |
---|
104 | $loc = substr($loc, 3); |
---|
105 | } |
---|
106 | $loc = substr_replace($loc, '-'.implode('_', $tokens), strrpos($loc, '.'), 0 ); |
---|
107 | |
---|
108 | $rel_path = PWG_DERIVATIVE_DIR.$loc; |
---|
109 | |
---|
110 | global $conf; |
---|
111 | $url_style=$conf['derivative_url_style']; |
---|
112 | if (!$url_style) |
---|
113 | { |
---|
114 | $mtime = @filemtime(PHPWG_ROOT_PATH.$rel_path); |
---|
115 | if ($mtime===false) |
---|
116 | { |
---|
117 | $url_style = 2; |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | $url_style = 1; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | if ($url_style == 2) |
---|
126 | { |
---|
127 | $rel_url = 'i'; |
---|
128 | if ($conf['php_extension_in_urls']) $rel_url .= '.php'; |
---|
129 | if (!$conf['question_mark_in_urls']) $rel_url.= '?'; |
---|
130 | $rel_url .= $loc; |
---|
131 | } |
---|
132 | else |
---|
133 | { |
---|
134 | $rel_url = $rel_path; |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | /* returns the size of the derivative image*/ |
---|
139 | function get_size() |
---|
140 | { |
---|
141 | return $this->params->compute_final_size($this->src_image->get_size(), $this->src_image->coi); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | ?> |
---|