require_once QA_INCLUDE_DIR . 'qa-util-string.php';
             $optionvalue = implode(' , ', qa_block_words_explode($optionvalue));
             break;
     }
     qa_set_option($optionname, $optionvalue);
 }
 $formokhtml = qa_lang_html('admin/options_saved');
 //	Uploading default avatar
 if (is_array(@$_FILES['avatar_default_file']) && $_FILES['avatar_default_file']['size']) {
     require_once QA_INCLUDE_DIR . 'qa-util-image.php';
     $oldblobid = qa_opt('avatar_default_blobid');
     $toobig = qa_image_file_too_big($_FILES['avatar_default_file']['tmp_name'], qa_opt('avatar_store_size'));
     if ($toobig) {
         $errors['avatar_default_show'] = qa_lang_sub('main/image_too_big_x_pc', (int) ($toobig * 100));
     } else {
         $imagedata = qa_image_constrain_data(file_get_contents($_FILES['avatar_default_file']['tmp_name']), $width, $height, qa_opt('avatar_store_size'));
         if (isset($imagedata)) {
             require_once QA_INCLUDE_DIR . 'qa-app-blobs.php';
             $newblobid = qa_create_blob($imagedata, 'jpeg');
             if (isset($newblobid)) {
                 qa_set_option('avatar_default_blobid', $newblobid);
                 qa_set_option('avatar_default_width', $width);
                 qa_set_option('avatar_default_height', $height);
                 qa_set_option('avatar_default_show', 1);
             }
             if (strlen($oldblobid)) {
                 qa_delete_blob($oldblobid);
             }
         } else {
             $errors['avatar_default_show'] = qa_lang_sub('main/image_not_read', implode(', ', qa_gd_image_formats()));
         }
$content = qa_db_cache_get($cachetype, $blobid);
// see if we've cached the scaled down version
header('Cache-Control: max-age=2592000, public');
// allows browsers and proxies to cache images too
if (isset($content)) {
    header('Content-Type: image/jpeg');
    echo $content;
} else {
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-blobs.php';
    require_once QA_INCLUDE_DIR . 'qa-util-image.php';
    //	Otherwise retrieve the raw image and scale as appropriate
    $blob = qa_read_blob($blobid);
    if (isset($blob)) {
        if ($size > 0) {
            $content = qa_image_constrain_data($blob['content'], $width, $height, $size);
        } else {
            $content = $blob['content'];
        }
        if (isset($content)) {
            header('Content-Type: image/jpeg');
            echo $content;
            if (strlen($content) && $size > 0) {
                $cachesizes = qa_get_options(array('avatar_profile_size', 'avatar_users_size', 'avatar_q_page_q_size', 'avatar_q_page_a_size', 'avatar_q_page_c_size', 'avatar_q_list_size'));
                // to prevent cache being filled with inappropriate sizes
                if (array_search($size, $cachesizes)) {
                    qa_db_cache_set($cachetype, $blobid, $content);
                }
            }
        }
    }
function qa_set_user_avatar($userid, $imagedata, $oldblobid = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'qa-util-image.php';
    $imagedata = qa_image_constrain_data($imagedata, $width, $height, qa_opt('avatar_store_size'));
    if (isset($imagedata)) {
        require_once QA_INCLUDE_DIR . 'qa-db-blobs.php';
        $newblobid = qa_db_blob_create($imagedata, 'jpeg', null, $userid, null, qa_remote_ip_address());
        if (isset($newblobid)) {
            qa_db_user_set($userid, 'avatarblobid', $newblobid);
            qa_db_user_set($userid, 'avatarwidth', $width);
            qa_db_user_set($userid, 'avatarheight', $height);
            qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_AVATAR, true);
            qa_db_user_set_flag($userid, QA_USER_FLAGS_SHOW_GRAVATAR, false);
            if (isset($oldblobid)) {
                qa_db_blob_delete($oldblobid);
            }
            return true;
        }
    }
    return false;
}