Пример #1
0
function submitImage($objid, $fileVar, $thumbVar, &$thumbError, &$imageChanged)
{
    global $_config, $_auth;
    $imageChanged = true;
    if ($fileVar == "" && $thumbVar == "") {
        $imageChanged = false;
        $thumbError = _SUBMIT_THUMB_REQUIRED;
        return false;
    }
    // Query old objLastEdit, so we can delete the old thumb and file.
    $sql = "SELECT `objExtension`, `objLastEdit`, `objFilename` " . "FROM `objects`, `objExtData`" . dbWhere(array("objid*" => "objEid", "objEid" => $objid));
    $result = sql_query($sql);
    $oldData = mysql_fetch_assoc($result);
    // Delete the old thumbnail and file.
    $oldThumbFilename = applyIdToPath("files/thumbs/", $objid) . "-" . preg_replace('/[^0-9]/', "", $oldData["objLastEdit"]) . ".jpg";
    $oldFilename = applyIdToPath("files/data/", $objid) . "-" . preg_replace('/[^0-9]/', "", $oldData["objLastEdit"]) . "." . $oldData["objExtension"];
    /*
    //Do not delete old files
    if(file_exists($oldThumbFilename)) @unlink($oldThumbFilename);
    if(file_exists($oldFilename)) @unlink($oldFilename);
    */
    // Update objLastEdit and get the new value, so we have the new objLastEdit
    // in $newRevisionDate and the old value in $oldData["objLastEdit"].
    $sql = "UPDATE `objects`" . dbSet(array("objLastEdit!" => "NOW()")) . dbWhere(array("objid" => $objid));
    sql_query($sql);
    $sql = "SELECT `objLastEdit` FROM `objects`" . dbWhere(array("objid" => $objid));
    $result = sql_query($sql);
    if (mysql_num_rows($result) > 0) {
        $newRevisionDate = preg_replace('/[^0-9]/', "", mysql_result($result, 0));
    } else {
        $newRevisionDate = date("YmdHis");
    }
    // Make a thumbnail and store it to /files/thumbs/#/#####/.
    $thumbFilename = applyIdToPath("files/thumbs/", $objid) . "-" . $newRevisionDate . ".jpg";
    list($thumbMaxWidth, $thumbMaxHeight) = preg_split('/x/', $_config["thumbResolution"]);
    if ($thumbVar == "") {
        // Automatic thumbnail generation.
        if ($fileVar == "" || !thumbifyImage($_FILES[$fileVar]["tmp_name"], $thumbFilename, $thumbMaxWidth, $thumbMaxHeight)) {
            $thumbError = _SUBMIT_THUMB_REQUIRED;
            return false;
        }
    } else {
        // Manually added thumbnail.
        if (!thumbifyImage($_FILES[$thumbVar]["tmp_name"], $thumbFilename, $thumbMaxWidth, $thumbMaxHeight)) {
            $thumbError = _SUBMIT_THUMB_ERROR;
            return false;
        }
    }
    // Gather thumbnail size information.
    if (file_exists($thumbFilename)) {
        $size = getimagesize($thumbFilename);
        $thumbWidth = $size[0];
        $thumbHeight = $size[1];
    } else {
        // If $thumbWidth == $thumbHeight == 0 it means there is no thumbnail.
        $thumbWidth = 0;
        $thumbHeight = 0;
    }
    // Upload the file.
    $imageFilename = applyIdToPath("files/data/", $objid) . "-" . $newRevisionDate;
    if ($fileVar != "") {
        uploadFile($fileVar, $imageFilename, $extension);
    } else {
        $imageChanged = false;
        $extension = $oldData["objExtension"];
        rename($oldFilename, $imageFilename . "." . $extension);
    }
    // Gather image size information.
    $imageFilename .= "." . $extension;
    $imageFileSize = filesize($imageFilename);
    $imageNonResizeable = true;
    if ($oldData["objExtension"] == "txt") {
        $imageWidth = 0;
        $imageHeight = 0;
    } else {
        $size = getimagesize($imageFilename);
        $imageWidth = $size[0];
        $imageHeight = $size[1];
        if ($size[2] == 2 || $size[2] == 3) {
            $imageNonResizeable = false;
        }
    }
    // Make a preview image, if possible.
    $previewWidth = 0;
    $previewHeight = 0;
    if ($imageWidth > 0 && $imageHeight > 0 && !$imageNonResizeable) {
        $previewFilename = applyIdToPath("files/preview/", $objid) . "-" . $newRevisionDate . ".jpg";
        $coeff = sqrt($_config["previewMaxArea"] / ($imageWidth * $imageHeight));
        // Require significant size reduction, so that images wouldn't become
        // very blurry with just an unnoticeable size change.
        if ($coeff > 0.9) {
            $coeff = 1.0;
        }
        $previewMaxWidth = round($imageWidth * $coeff);
        $previewMaxHeight = round($imageHeight * $coeff);
        thumbifyImage($imageFilename, $previewFilename, $previewMaxWidth, $previewMaxHeight, 86);
        if (file_exists($previewFilename)) {
            $size = getimagesize($previewFilename);
            $previewWidth = $size[0];
            $previewHeight = $size[1];
            // In case we've accidentally generated a larger file of the same
            // resolution, throw it away (why would we need a preview file that
            // is larger than the original image file?)
            if ($imageWidth == $previewWidth && $imageHeight == $previewHeight && filesize($imageFilename) * 0.8 < filesize($previewFilename)) {
                $previewWidth = 0;
                $previewHeight = 0;
                unlink($previewFilename);
            }
        }
    }
    // Update the filename in the database.
    $objFilename = $fileVar != "" ? $_FILES[$fileVar]["name"] : $oldData["objFilename"];
    $sql = "UPDATE `objects`" . dbSet(array("objLastEdit" => $newRevisionDate, "objThumbWidth" => $thumbWidth, "objThumbHeight" => $thumbHeight, "objThumbDefault" => "0")) . dbWhere(array("objid" => $objid));
    sql_query($sql);
    $userIp = getHexIp($_SERVER["REMOTE_ADDR"]);
    $sql = "UPDATE `objExtData`" . dbSet(array("objImageWidth" => $imageWidth, "objImageHeight" => $imageHeight, "objImageSize" => $imageFileSize, "objPreviewWidth" => $previewWidth, "objPreviewHeight" => $previewHeight, "objExtension" => $extension, "objEditIp" => $userIp, "objFilename" => $objFilename)) . dbWhere(array("objEid" => $objid));
    sql_query($sql);
    // Touch user's last submission time.
    $sql = "UPDATE `users`" . dbSet(array("useLastSubmission!" => "NOW()")) . dbWhere(array("useid" => $_auth["useid"]));
    sql_query($sql);
    return true;
}
Пример #2
0
     $imageNonResizeable = false;
 }
 $previewWidth = 0;
 $previewHeight = 0;
 if ($imageWidth > 0 && $imageHeight > 0 && !$imageNonResizeable) {
     $newRevisionDate = preg_replace('/[^0-9]/', "", $objData["objLastEdit"]);
     $previewFilename = applyIdToPath("files/preview/", $objid) . "-" . $newRevisionDate . ".jpg";
     $coeff = sqrt($_config["previewMaxArea"] / ($imageWidth * $imageHeight));
     // Require significant size reduction, so that images wouldn't become
     // very blurry with just an unnoticeable size change.
     if ($coeff > 0.9) {
         $coeff = 1.0;
     }
     $previewMaxWidth = round($imageWidth * $coeff);
     $previewMaxHeight = round($imageHeight * $coeff);
     thumbifyImage($imageFilename, $previewFilename, $previewMaxWidth, $previewMaxHeight, 86);
     if (file_exists($previewFilename)) {
         $size = getimagesize($previewFilename);
         $previewWidth = $size[0];
         $previewHeight = $size[1];
         // In case we've accidentally generated a larger file of the same
         // resolution, throw it away (why would we need a preview file that
         // is larger than the original image file?)
         if ($imageWidth == $previewWidth && $imageHeight == $previewHeight && $imageFileSize * 0.8 < filesize($previewFilename)) {
             $previewWidth = 0;
             $previewHeight = 0;
             unlink($previewFilename);
         }
     }
 }
 sql_query("UPDATE `objExtData` " . "SET `objPreviewWidth` = '{$previewWidth}', " . "`objPreviewHeight` = '{$previewHeight}', " . "`objImageSize` = '{$imageFileSize}' " . "WHERE `objEid` = '{$objid}' LIMIT 1");
Пример #3
0
         $imageName = $item["imgname"];
         list($thumbMaxWidth, $thumbMaxHeight) = preg_split('/x/', $item["res"]);
         if ($useSWF) {
             $filesize = filesize($imageName);
             if ($filesize > $_config["idSWFMaxSize"]) {
                 notice(sprintf("Your Flash animation is %d bytes. Maximum is %d bytes.", $filesize, $_config["idSWFMaxSize"]));
             } else {
                 move_uploaded_file($imageName, $newName);
                 chmod($newName, 0644);
             }
         } else {
             if (!thumbifyImage($imageName, $newName, $thumbMaxWidth, $thumbMaxHeight, 86)) {
                 // If it's impossible to read the original image (e.g. it's a text file
                 // or a Flash animation), then make the featured image from the thumbnail.
                 $imageName = $item["imgname2"];
                 thumbifyImage($imageName, $newName, $thumbMaxWidth, $thumbMaxHeight, 86);
             }
         }
     }
 }
 // Profile options
 $_auth["useCustomTitle"] = $_POST["useCustomTitle"];
 $_auth["useRealName"] = $_POST["useRealName"];
 $_auth["useShowRealName"] = isset($_POST["useShowRealName"]) ? 1 : 0;
 $_auth["useProfile"] = $_POST["useProfile"];
 $_auth["useAIM"] = $_POST["useAIM"];
 $_auth["useICQ"] = $_POST["useICQ"];
 $_auth["useMSN"] = $_POST["useMSN"];
 $_auth["useYIM"] = $_POST["useYIM"];
 $_auth["useJabber"] = $_POST["useJabber"];
 // Update the database