コード例 #1
0
ファイル: results.php プロジェクト: BGCX262/zwf-svn-to-git
/**
 * Gallery results library
 *
 * @author Andrew Murphy 
 * @author Justin Johnson <johnsonj>, justin@zebrakick.com
 * @version 2.0.0 20080430 JJ
 * @version 1.0.5 20080204 AM
 * @version 1.0.4 20080201 AM
 * @version 1.0.4 20080125 JJ
 * @version 1.0.3 20071227 AM
 * @version 1.0.2 20071203 JJ
 * @version 1.0.1 20071120 AM
 *
 */
function getExamples()
{
    $link = null;
    db_get_resource($link);
    if ($link) {
        $stmt = $link->prepare("SELECT `title`, `listing_id` FROM " . DB_TABLE_LISTING);
        if ($stmt) {
            if ($stmt->execute()) {
                return $stmt->fetchAll(PDO::FETCH_ASSOC);
            }
        }
    }
    return false;
}
コード例 #2
0
ファイル: setter.php プロジェクト: BGCX262/zwf-svn-to-git
/**
 * Resizes and adds a photo and its title to the database associated to a user.
 *
 * @param int $listing_id The listing ID of the photo's owner.
 * @param string $filename The path to the image to be resized and added.
 *
 * @return array a[0] => bool: status of the operation; a[1] => int: The ID of the inserted photo if the operation was successful; error code.
 */
function photos_add($listing_id, $filename)
{
    // Make sure the photo is valid
    $image_info = array();
    $valid = photos_valid_file($filename, $image_info);
    if (!$valid[0]) {
        var_dump($valid);
        return $valid;
    }
    // Validate user ID
    $resp = db_column_data_exists(DB_TABLE_LISTING, 'listing_id', $listing_id);
    if (!$resp[1]) {
        return array(false, 'This user does not exist.');
    }
    // Full path to the file
    $file_path = PATH_UPLOAD_PHOTO . $filename;
    // Load the image resources
    $original_rsc = photos_imagecreate($file_path, $image_info[2]);
    // Resize the images and convert them to strings
    $thumb_blob = photos_image_string(photos_resize($original_rsc, PHOTOS_SIZE_THUMB, $image_info[0], $image_info[1]), $image_info[2]);
    $full_blob = photos_image_string(photos_resize($original_rsc, PHOTOS_SIZE_FULL, $image_info[0], $image_info[1]), $image_info[2]);
    // Get the height of the thumb
    $nwidth = PHOTOS_SIZE_THUMB_WIDTH_LIMIT;
    $nheight = PHOTOS_SIZE_THUMB_HEIGHT_LIMIT;
    photos_requires_resize($image_info[0], $image_info[1], $nwidth, $nheight);
    // Pump that 'ish into the database
    $link = null;
    db_get_resource($link);
    $stmt = $link->prepare('INSERT INTO ' . DB_TABLE_PHOTO . ' ' . '(listing_id, thumbnail, fullsize) ' . 'VALUES(:listing_id, :thumbnail, :fullsize)');
    $stmt->bindParam(':listing_id', $listing_id, PDO::PARAM_INT);
    $stmt->bindParam(':thumbnail', $thumb_blob, PDO::PARAM_LOB);
    $stmt->bindParam(':fullsize', $full_blob, PDO::PARAM_LOB);
    // Perform the SQL insert.  If it failed, return now.
    if (!$stmt->execute()) {
        var_dump($stmt->errorInfo());
        return array(false, 'Could not execute query');
    }
    // The insert was performed successfully.
    $stmt->closeCursor();
    return array(true, $link->lastInsertId());
}
コード例 #3
0
ファイル: pdo.php プロジェクト: BGCX262/zwf-svn-to-git
/**
 * Retrieve the valid options for an enum column
 * 
 * This function is cached at runtime for speed. If for any reason the function fails
 * an empty array is returned.
 *
 * @param string $table   The table that contains the column
 * @param string $column  The column to lookup 
 * 
 * @return string A limit clause or an empty string.
 */
function db_get_enum_options($table, $column)
{
    static $cache = array();
    $hash = $table . ',' . $column;
    if (isset($cache[$hash])) {
        return $cache[$hash];
    }
    if (preg_match('/[^\\w]/i', $table) || preg_match('/[^\\w]/i', $column)) {
        return $cache[$hash] = array();
    }
    $link = null;
    db_get_resource($link);
    $stmt = $link->prepare('SHOW COLUMNS FROM `' . $table . '`');
    if ($stmt && $stmt->execute()) {
        while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
            if ($data['Field'] == $column) {
                $type = $data['Type'];
                if (preg_match('/^enum/i', $type)) {
                    $beginList = strpos($type, '(') + 1;
                    $endList = strpos($type, ')');
                    $type = substr($type, $beginList, $endList - $beginList);
                    $type = strtr($type, array('\'' => '', '"' => ''));
                    return $cache[$hash] = split(',', $type);
                }
                break;
            }
        }
    }
    return $cache[$hash] = array();
}
コード例 #4
0
ファイル: getter.php プロジェクト: BGCX262/zwf-svn-to-git
/**
 * Gets the number of photos that belong to a given user
 * 
 * @param int $user_id The ID of the user to get the photo count for.
 * 
 * @return array a[0] => bool: The status of the operation; a[1] => int/array: The number of photos the user has or an array of errors.
 */
function photos_count($user_id)
{
    $value = array();
    $link = null;
    db_get_resource($link);
    $stmt = $link->prepare(' SELECT COUNT(*) as`photo_count`' . ' FROM ' . '`' . SALSA_TABLE_PHOTO . '`' . ' WHERE ' . '`user_id` = :user_id' . ' ORDER BY `posted` ASC');
    $stmt->bindValue(':user_id', $user_id, PDO::PARAM_INT);
    if ($stmt->execute()) {
        $value = array(true, $stmt->fetch(PDO::FETCH_ASSOC));
        if ($value[1]) {
            $value[1] = $value[1]['photo_count'];
        } else {
            $value[1] = 0;
        }
        $stmt->closeCursor();
    } else {
        $value = array(false, array(VALIDATE_ERR_DB, 'Unable to connect'));
        //do not cache
    }
    return $value;
}