コード例 #1
0
ファイル: Profile.subs.php プロジェクト: scripple/Elkarte
/**
 * Load avatar context data.
 *
 * @return boolean
 */
function profileLoadAvatarData()
{
    global $context, $cur_profile, $modSettings, $scripturl;
    $context['avatar_url'] = $modSettings['avatar_url'];
    $valid_protocol = substr($cur_profile['avatar'], 0, 7) === 'http://' || substr($cur_profile['avatar'], 0, 8) === 'https://';
    // Default context.
    $context['member']['avatar'] += array('custom' => $valid_protocol ? $cur_profile['avatar'] : 'http://', 'selection' => $valid_protocol ? $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'), 'allow_gravatar' => allowedTo('profile_gravatar') || !$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.png', '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 ($valid_protocol && $context['member']['avatar']['allow_external']) {
        $context['member']['avatar'] += array('choice' => 'external', 'server_pic' => 'blank.png', 'external' => $cur_profile['avatar']);
    } elseif ($cur_profile['avatar'] == 'gravatar' && $context['member']['avatar']['allow_gravatar']) {
        $context['member']['avatar'] += array('choice' => 'gravatar', 'server_pic' => 'blank.png', 'external' => 'http://');
    } 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.png' : $cur_profile['avatar'], 'external' => 'http://');
    } else {
        $context['member']['avatar'] += array('choice' => 'none', 'server_pic' => 'blank.png', 'external' => 'http://');
    }
    // Get a list of all the avatars.
    if ($context['member']['avatar']['allow_server_stored']) {
        require_once SUBSDIR . '/Attachments.subs.php';
        $context['avatar_list'] = array();
        $context['avatars'] = is_dir($modSettings['avatar_directory']) ? getServerStoredAvatars('', 0) : array();
    } else {
        $context['avatar_list'] = array();
        $context['avatars'] = array();
    }
    // Second level selected avatar...
    $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
    return true;
}
コード例 #2
0
ファイル: Attachments.subs.php プロジェクト: KeiroD/Elkarte
/**
 * Recursive function to retrieve server-stored avatar files
 *
 * @package Attachments
 * @param string $directory
 * @param int $level
 * @return array
 */
function getServerStoredAvatars($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.png', '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.png', 'checked' => in_array($context['member']['avatar']['server_pic'], array('', 'blank.png')), 'name' => $txt['no_pic'], 'is_dir' => false);
    }
    foreach ($dirs as $line) {
        $tmp = getServerStoredAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
        if (!empty($tmp)) {
            $result[] = array('filename' => htmlspecialchars($line, ENT_COMPAT, 'UTF-8'), 'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false, 'name' => '[' . htmlspecialchars(str_replace('_', ' ', $line), ENT_COMPAT, 'UTF-8') . ']', '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, ENT_COMPAT, 'UTF-8'), 'checked' => $line == $context['member']['avatar']['server_pic'], 'name' => htmlspecialchars(str_replace('_', ' ', $filename), ENT_COMPAT, 'UTF-8'), 'is_dir' => false);
        if ($level == 1) {
            $context['avatar_list'][] = $directory . '/' . $line;
        }
    }
    return $result;
}