1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
<?php
/**
*
* @package avatar
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Handles avatars selected from the board gallery
* @package avatars
*/
class phpbb_avatar_driver_local extends phpbb_avatar_driver
{
/**
* @inheritdoc
*/
public function get_data($row, $ignore_config = false)
{
if ($ignore_config || $this->config['allow_avatar_local'])
{
return array(
'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'],
'width' => $row['avatar_width'],
'height' => $row['avatar_height'],
);
}
else
{
return array(
'src' => '',
'width' => 0,
'height' => 0,
);
}
}
/**
* @inheritdoc
*/
public function prepare_form($template, $row, &$error)
{
$avatar_list = $this->get_avatar_list();
$category = request_var('av_local_cat', '');
$categories = array_keys($avatar_list);
foreach ($categories as $cat)
{
if (!empty($avatar_list[$cat]))
{
$template->assign_block_vars('av_local_cats', array(
'NAME' => $cat,
'SELECTED' => ($cat == $category),
));
}
}
if (!empty($avatar_list[$category]))
{
foreach ($avatar_list[$category] as $img => $data)
{
$template->assign_block_vars('av_local_imgs', array(
'AVATAR_IMAGE' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $data['file'],
'AVATAR_NAME' => $data['name'],
'AVATAR_FILE' => $data['filename'],
));
}
}
return true;
}
/**
* @inheritdoc
*/
public function process_form($template, $row, &$error)
{
$avatar_list = $this->get_avatar_list();
$category = request_var('av_local_cat', '');
$file = request_var('av_local_file', '');
if (!isset($avatar_list[$category][urldecode($file)]))
{
$error[] = 'AVATAR_URL_NOT_FOUND';
return false;
}
return array(
'avatar' => $category . '/' . $file,
'avatar_width' => $avatar_list[$category][urldecode($file)]['width'],
'avatar_height' => $avatar_list[$category][urldecode($file)]['height'],
);
}
/**
* @TODO
*/
private function get_avatar_list()
{
$avatar_list = ($this->cache == null) ? false : $this->cache->get('av_local_list');
if (!$avatar_list)
{
$avatar_list = array();
$path = $this->phpbb_root_path . $this->config['avatar_gallery_path'];
$dh = @opendir($path);
if ($dh)
{
while (($cat = readdir($dh)) !== false) {
if ($cat[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $cat) && is_dir("$path/$cat"))
{
if ($ch = @opendir("$path/$cat"))
{
while (($image = readdir($ch)) !== false)
{
// Match all images in the gallery folder
if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $image))
{
if (function_exists('getimagesize'))
{
$dims = getimagesize($this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $cat . '/' . $image);
}
else
{
$dims = array(0, 0);
}
$avatar_list[$cat][$image] = array(
'file' => rawurlencode($cat) . '/' . rawurlencode($image),
'filename' => rawurlencode($image),
'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $image))),
'width' => $dims[0],
'height' => $dims[1],
);
}
}
@closedir($ch);
}
}
}
@closedir($dh);
}
@ksort($avatar_list);
if ($this->cache != null)
{
$this->cache->put('av_local_list', $avatar_list);
}
}
return $avatar_list;
}
}
|