Example #1
0
function qa_create_blob($content, $format, $sourcefilename = null, $userid = null, $cookieid = null, $ip = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'db/blobs.php';
    $blobid = qa_db_blob_create(defined('QA_BLOBS_DIRECTORY') ? null : $content, $format, $sourcefilename, $userid, $cookieid, $ip);
    if (isset($blobid) && defined('QA_BLOBS_DIRECTORY')) {
        if (!qa_write_blob_file($blobid, $content, $format)) {
            qa_db_blob_set_content($blobid, $content);
        }
    }
    // still write content to the database if writing to disk failed
    return $blobid;
}
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;
}
Example #3
0
        }
        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-db-blobs.php';
                $newblobid = qa_db_blob_create($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_db_blob_delete($oldblobid);
                }
            } else {
                $errors['avatar_default_show'] = qa_lang_sub('main/image_not_read', implode(', ', qa_gd_image_formats()));
            }
        }
    }
}
Example #4
0
 function process_request($request)
 {
     $message = '';
     $url = '';
     if (is_array($_FILES) && count($_FILES)) {
         //	Check that we're allowed to upload images (if not, no other uploads are allowed either)
         if (!qa_opt('wysiwyg_editor_upload_images')) {
             $message = qa_lang('users/no_permission');
         }
         //	Check that we haven't reached the upload limit and are not blocked
         if (empty($message)) {
             require_once QA_INCLUDE_DIR . 'qa-app-users.php';
             require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
             switch (qa_user_permit_error(null, QA_LIMIT_UPLOADS)) {
                 case 'limit':
                     $message = qa_lang('main/upload_limit');
                     break;
                 case false:
                     qa_limits_increment(qa_get_logged_in_userid(), QA_LIMIT_UPLOADS);
                     break;
                 default:
                     $message = qa_lang('users/no_permission');
                     break;
             }
         }
         //	Find out some information about the uploaded file and check it's not too large
         if (empty($message)) {
             require_once QA_INCLUDE_DIR . 'qa-app-blobs.php';
             $file = reset($_FILES);
             $pathinfo = pathinfo($file['name']);
             $extension = strtolower(@$pathinfo['extension']);
             $filesize = $file['size'];
             $maxsize = min(qa_opt('wysiwyg_editor_upload_max_size'), qa_get_max_upload_size());
             if ($filesize <= 0 || $filesize > $maxsize) {
                 // if file was too big for PHP, $filesize will be zero
                 $message = qa_lang_sub('main/max_upload_size_x', number_format($maxsize / 1048576, 1) . 'MB');
             }
         }
         //	If it's only allowed to be an image, check it's an image
         if (empty($message)) {
             if (qa_get('qa_only_image') || !qa_opt('wysiwyg_editor_upload_all')) {
                 // check if we need to confirm it's an image
                 switch ($extension) {
                     case 'png':
                         // these are allowed image extensions
                     // these are allowed image extensions
                     case 'gif':
                     case 'jpeg':
                     case 'jpg':
                         if (function_exists('getimagesize')) {
                             // getimagesize() does not require GD library
                             if (!is_array(@getimagesize($file['tmp_name']))) {
                                 $message = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG');
                             }
                         }
                         break;
                     default:
                         $message = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG');
                         break;
                 }
             }
         }
         //	If there have been no errors, looks like we're all set...
         if (empty($message)) {
             require_once QA_INCLUDE_DIR . 'qa-db-blobs.php';
             $userid = qa_get_logged_in_userid();
             $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
             $blobid = qa_db_blob_create(file_get_contents($file['tmp_name']), $extension, @$file['name'], $userid, $cookieid, qa_remote_ip_address());
             if (isset($blobid)) {
                 $url = qa_get_blob_url($blobid, true);
             } else {
                 $message = 'Failed to create object in database - please try again';
             }
         }
     }
     echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(" . qa_js(qa_get('CKEditorFuncNum')) . ", " . qa_js($url) . ", " . qa_js($message) . ");</script>";
     return null;
 }