1 | <?php |
---|
2 | /** |
---|
3 | * @copyright 2005-2006 OpenPNE Project |
---|
4 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
---|
5 | */ |
---|
6 | |
---|
7 | function smarty_function_t_img_url($params, &$smarty) |
---|
8 | { |
---|
9 | $p = _smarty_function_t_img_url($params); |
---|
10 | $html = true; |
---|
11 | if (isset($params['_html'])) { |
---|
12 | $html = (bool)$params['_html']; |
---|
13 | unset($params['_html']); |
---|
14 | } |
---|
15 | $urlencode = false; |
---|
16 | if (isset($params['_urlencode'])) { |
---|
17 | $urlencode = (bool)$params['_urlencode']; |
---|
18 | unset($params['_urlencode']); |
---|
19 | } |
---|
20 | |
---|
21 | if (OPENPNE_IMG_URL) { |
---|
22 | $url = OPENPNE_IMG_URL; |
---|
23 | } else { |
---|
24 | $url = OPENPNE_URL; |
---|
25 | } |
---|
26 | |
---|
27 | if (!OPENPNE_IMG_CACHE_PUBLIC) { |
---|
28 | $url .= 'img.php'; |
---|
29 | |
---|
30 | include_once 'PHP/Compat/Function/http_build_query.php'; |
---|
31 | if ($q = http_build_query($p)) { |
---|
32 | if ($html) { |
---|
33 | $url .= '?' . htmlspecialchars($q); |
---|
34 | } else { |
---|
35 | $url .= '?' . $q; |
---|
36 | } |
---|
37 | } |
---|
38 | } else { |
---|
39 | include_once 'OpenPNE/Img.php'; |
---|
40 | if (!$p['f']) { |
---|
41 | $parts = explode('.', $p['filename']); |
---|
42 | $f = array_pop($parts); |
---|
43 | switch ($f) { |
---|
44 | case 'jpg': |
---|
45 | case 'gif': |
---|
46 | case 'png': |
---|
47 | $p['f'] = $f; |
---|
48 | break; |
---|
49 | default: |
---|
50 | $p['f'] = 'jpg'; |
---|
51 | break; |
---|
52 | } |
---|
53 | } |
---|
54 | $path = OpenPNE_Img::get_cache_path($p['filename'], $p['w'], $p['h'], $p['f']); |
---|
55 | $url .= 'img/' . $path; |
---|
56 | } |
---|
57 | |
---|
58 | if ($urlencode) { |
---|
59 | $url = urlencode($url); |
---|
60 | } |
---|
61 | |
---|
62 | return $url; |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * validate params |
---|
67 | * @param array $params |
---|
68 | * @return array |
---|
69 | */ |
---|
70 | function _smarty_function_t_img_url($params) |
---|
71 | { |
---|
72 | $result = array(); |
---|
73 | |
---|
74 | if (!empty($params['filename']) && preg_match('/^\w+(?:\.((?:jpe?g)|(?:gif)|(?:png)))?$/', $params['filename'])) { |
---|
75 | $filename = $params['filename']; |
---|
76 | } else { |
---|
77 | if (!empty($params['noimg'])) { |
---|
78 | $filename = db_get_c_skin_filename4skinname($params['noimg']); |
---|
79 | } else { |
---|
80 | $filename = db_get_c_skin_filename4skinname('no_image'); |
---|
81 | } |
---|
82 | } |
---|
83 | $result['filename'] = $filename; |
---|
84 | |
---|
85 | if (!empty($params['w']) && (intval($params['w']) > 0)) { |
---|
86 | $result['w'] = intval($params['w']); |
---|
87 | } |
---|
88 | if (!empty($params['h']) && (intval($params['h']) > 0)) { |
---|
89 | $result['h'] = intval($params['h']); |
---|
90 | } |
---|
91 | |
---|
92 | if (!empty($params['f'])) { |
---|
93 | switch ($params['f']) { |
---|
94 | case 'jpg': |
---|
95 | case 'gif': |
---|
96 | case 'png': |
---|
97 | $result['f'] = $params['f']; |
---|
98 | break; |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | return $result; |
---|
103 | } |
---|
104 | |
---|
105 | ?> |
---|