Skip to content

Commit c12e42a

Browse files
committed
WIP #140 Add avatar module
Allow relative and absolute paths for avatars
1 parent 67db488 commit c12e42a

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

boards/mybb/avatars.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ function generate_raw_filename($avatar)
8989
{
9090
global $import_session;
9191

92-
return ltrim(str_replace($import_session['relative_avatar_path'], '', $avatar['avatar']), '/');
92+
$filename = ltrim(str_replace($import_session['relative_avatar_path'], '', $avatar['avatar']), '/');
93+
return my_substr($filename, 0, strpos($filename, '?'));
9394
}
9495
}
9596

language/global.lang.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
$l['module_settings_updating'] = "Updating settings {1}";
176176

177177
$l['module_attachment_link'] = "Please type in the link to your {1} forum attachment directory";
178-
$l['module_attachment_label'] = "Link (URL) to your forum attachment directory";
178+
$l['module_attachment_label'] = "Link (URL) to your forum attachment directory<br /><span class='smalltext'>If possible use a relative or absolute path. Note that the <b>merge</b> directory is used as working directory</span>";
179179
$l['module_attachment_error'] = "Error transfering the attachment (ID: {1})";
180180
$l['module_attachment_not_found'] = "Error could not find the attachment (ID: {1})";
181181
$l['module_attachment_thumbnail_error'] = "Error transfering the attachment thumbnail (ID: {1})";
@@ -185,7 +185,7 @@
185185
$l['attmodule_ipadress2'] = "You may not use \"127.0.0.1\" in the URL. Please use your Internet IP Address (Please make sure Port 80 is open on your firewall and router).";
186186

187187
$l['module_avatar_link'] = "Please type in the link to your {1} avatar directory";
188-
$l['module_avatar_label'] = "Link (URL) to your forum avatar directory";
188+
$l['module_avatar_label'] = "Link (URL) to your forum avatar directory<br /><span class='smalltext'>If possible use a relative or absolute path. Note that the <b>merge</b> directory is used as working directory</span>";
189189
$l['module_avatar_error'] = "Error transfering the avatar (ID: {1})";
190190
$l['module_avatar_not_found'] = "Error could not find the avatar (ID: {1})";
191191

resources/functions.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,9 @@ function merge_fetch_remote_file($url, $post_data=array())
643643
$post_body = ltrim($post_body, '&');
644644
}
645645

646-
// Use this method if we have a relative or absolute path as our url
647-
if(my_substr($url, 0, 1) == '.' || my_substr($url, 0, 1) == '/' || my_substr($url, 1, 2) == ':\\')
646+
// Use fopen if we have an internal path
647+
// Internal pathes start either with a '.' (relative), a '/' (UNIX) or 'X:\' where X can be anything. Also Windows can be used with a slash instead of a backslash
648+
if(my_substr($url, 0, 1) == '.' || my_substr($url, 0, 1) == '/' || my_substr($url, 1, 2) == ':\\' || my_substr($url, 1, 2) == ':/')
648649
{
649650
@clearstatcache();
650651
if(is_readable($url))

resources/modules/avatars.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,16 @@ public function test_readability()
151151
$import_session['uploads_avatars_test'] = 0;
152152
}
153153

154-
if(!check_url_exists($mybb->input['avatarspath'])) {
154+
if(strpos($import_session['avatarspath'], '../') !== false || my_substr($import_session['avatarspath'], 0, 1) == '/' || my_substr($import_session['avatarspath'], 1, 1) == ':')
155+
{
156+
$readable = @is_readable($import_session['avatarspath']);
157+
}
158+
else
159+
{
160+
$readable = check_url_exists($import_session['avatarspath']);
161+
}
162+
163+
if(!$readable) {
155164
$this->debug->log->error("Avatar directory not readable");
156165
$this->errors[] = $lang->download_not_readable;
157166
$import_session['uploads_avatars_test'] = 0;
@@ -171,6 +180,7 @@ function after_insert($unconverted_data, $converted_data, $aid)
171180
}
172181

173182
// Transfer avatar
183+
$this->debug->log->error($import_session['avatarspath'].$this->generate_raw_filename($unconverted_data));
174184
$data_file = merge_fetch_remote_file($import_session['avatarspath'].$this->generate_raw_filename($unconverted_data));
175185
if(!empty($data_file))
176186
{

stylesheet.css

+5
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ label {
265265

266266
/* Misc */
267267

268+
.smalltext {
269+
font-size: 11px;
270+
font-weight: normal;
271+
}
272+
268273
.invisible {
269274
display: none;
270275
}

0 commit comments

Comments
 (0)