Esempio n. 1
0
/**
 * Create thumbnail of image.
 * @param string $source Source image.
 * @param string $dest Thumbnail path.
 * @param array $source_dimensions Source image dimensions.
 * @param array $type Image file type.
 * @param int $resize_x Thumbnail width.
 * @param int $resize_y Thumbnail height.
 * @return array|boolean
 * thumbnail dimensions or FALSE if any error occurred. Also in case of error
 * set last error to appropriate error object.
 */
function create_thumbnail($source, $dest, $source_dimensions, $type, $resize_x, $resize_y)
{
    $result = array();
    // small image doesn't need to be thumbnailed
    if ($source_dimensions['x'] < $resize_x && $source_dimensions['y'] < $resize_y) {
        // big file but small image is some kind of trolling
        if (filesize($source) > Config::SMALLIMAGE_LIMIT_FILE_SIZE) {
            kotoba_set_last_error(new MaxSmallImgSizeError());
            return FALSE;
        }
        $result['x'] = $source_dimensions['x'];
        $result['y'] = $source_dimensions['y'];
        link_file($source, $dest);
        return $result;
    }
    return $type['upload_handler_name']($source, $dest, $source_dimensions, $type, $resize_x, $resize_y);
}
Esempio n. 2
0
/**
 * Load user settings.
 * @param MySQLi $link Link to database.
 * @param string $keyword Keyword hash.
 * @return array|boolean Returns array of user settings or boolean FALSE if any
 * error occurred and set last error to appropriate error object.
 */
function db_users_get_by_keyword($link, $keyword)
{
    $query = "call sp_users_get_by_keyword('{$keyword}')";
    if (mysqli_multi_query($link, $query) == FALSE) {
        throw new DBException(mysqli_error($link));
    }
    // User settings.
    if (($result = mysqli_store_result($link)) == FALSE) {
        throw new DBException(mysqli_error($link));
    }
    if (($row = mysqli_fetch_assoc($result)) !== NULL) {
        $user_settings['id'] = $row['id'];
        $user_settings['posts_per_thread'] = $row['posts_per_thread'];
        $user_settings['threads_per_page'] = $row['threads_per_page'];
        $user_settings['lines_per_post'] = $row['lines_per_post'];
        $user_settings['language'] = $row['language'];
        $user_settings['stylesheet'] = $row['stylesheet'];
        $user_settings['password'] = $row['password'];
        $user_settings['goto'] = $row['goto'];
    } else {
        kotoba_set_last_error(new UserNotExistsError($keyword));
        return FALSE;
    }
    mysqli_free_result($result);
    if (!mysqli_next_result($link)) {
        throw new DBException(mysqli_error($link));
    }
    // Groups.
    if (($result = mysqli_store_result($link)) == FALSE) {
        throw new DBException(mysqli_error($link));
    }
    $user_settings['groups'] = array();
    while (($row = mysqli_fetch_assoc($result)) !== NULL) {
        array_push($user_settings['groups'], $row['name']);
    }
    if (count($user_settings['groups']) <= 0) {
        throw new UserWithoutGroupException($user_settings['id']);
    }
    // Cleanup.
    mysqli_free_result($result);
    db_cleanup_link($link);
    return $user_settings;
}
Esempio n. 3
0
/**
 * Check youtube video code.
 * @param string $code Code of vide.
 * @return string|boolean
 * safe code of video or FALSE if file link too long and set last error to
 * appropriate error value.
 */
function videos_check_code($code)
{
    $code = RawURLEncode($code);
    if (strlen($code) > Config::MAX_FILE_LINK) {
        kotoba_set_last_error(new MaxFileLinkError());
        return FALSE;
    }
    return RawURLEncode($code);
}