Esempio n. 1
0
function getAvatars($directory, $level)
{
    global $context, $txt, $modSettings;
    $result = array();
    // Open the directory..
    $dir = dir($modSettings['avatar_directory'] . (!empty($directory) ? '/' : '') . $directory);
    $dirs = array();
    $files = array();
    if (!$dir) {
        return array();
    }
    while ($line = $dir->read()) {
        if (in_array($line, array('.', '..', 'blank.gif', 'index.php'))) {
            continue;
        }
        if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) {
            $dirs[] = $line;
        } else {
            $files[] = $line;
        }
    }
    $dir->close();
    // Sort the results...
    natcasesort($dirs);
    natcasesort($files);
    if ($level == 0) {
        $result[] = array('filename' => 'blank.gif', 'checked' => in_array($context['member']['avatar']['server_pic'], array('', 'blank.gif')), 'name' => &$txt[422], 'is_dir' => false);
    }
    foreach ($dirs as $line) {
        $tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
        if (!empty($tmp)) {
            $result[] = array('filename' => htmlspecialchars($line), 'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false, 'name' => '[' . htmlspecialchars(str_replace('_', ' ', $line)) . ']', 'is_dir' => true, 'files' => $tmp);
        }
        unset($tmp);
    }
    foreach ($files as $line) {
        $filename = substr($line, 0, strlen($line) - strlen(strrchr($line, '.')));
        $extension = substr(strrchr($line, '.'), 1);
        // Make sure it is an image.
        if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) {
            continue;
        }
        $result[] = array('filename' => htmlspecialchars($line), 'checked' => $line == $context['member']['avatar']['server_pic'], 'name' => htmlspecialchars(str_replace('_', ' ', $filename)), 'is_dir' => false);
        if ($level == 1) {
            $context['avatar_list'][] = $directory . '/' . $line;
        }
    }
    return $result;
}
Esempio n. 2
0
function profileLoadAvatarData()
{
    global $context, $cur_profile, $modSettings, $scripturl;
    $context['avatar_url'] = $modSettings['avatar_url'];
    // Default context.
    $context['member']['avatar'] += array('custom' => stristr($cur_profile['avatar'], 'http://') ? $cur_profile['avatar'] : 'http://', 'selection' => $cur_profile['avatar'] == '' || stristr($cur_profile['avatar'], 'http://') ? '' : $cur_profile['avatar'], 'id_attach' => $cur_profile['id_attach'], 'filename' => $cur_profile['filename'], 'allow_server_stored' => allowedTo('profile_server_avatar') || !$context['user']['is_owner'] && allowedTo('profile_extra_any'), 'allow_upload' => allowedTo('profile_upload_avatar') || !$context['user']['is_owner'] && allowedTo('profile_extra_any'), 'allow_external' => allowedTo('profile_remote_avatar') || !$context['user']['is_owner'] && allowedTo('profile_extra_any'));
    if ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) {
        $context['member']['avatar'] += array('choice' => 'upload', 'server_pic' => 'blank.gif', 'external' => 'http://');
        $context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
    } elseif (stristr($cur_profile['avatar'], 'http://') && $context['member']['avatar']['allow_external']) {
        $context['member']['avatar'] += array('choice' => 'external', 'server_pic' => 'blank.gif', 'external' => $cur_profile['avatar']);
    } elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) {
        $context['member']['avatar'] += array('choice' => 'server_stored', 'server_pic' => $cur_profile['avatar'] == '' ? 'blank.gif' : $cur_profile['avatar'], 'external' => 'http://');
    } else {
        $context['member']['avatar'] += array('choice' => 'none', 'server_pic' => 'blank.gif', 'external' => 'http://');
    }
    // Get a list of all the avatars.
    if ($context['member']['avatar']['allow_server_stored']) {
        $context['avatar_list'] = array();
        $context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
    } else {
        $context['avatars'] = array();
    }
    // Second level selected avatar...
    $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
    return true;
}