function initialize_page() { $post_action = isset($_POST['submit']) ? $_POST['submit'] : ""; if ($post_action == "Add Image" || $post_action == "Add and Return to List") { $title = cleanupSpecialChars($_POST['title']); $description = cleanupSpecialChars($_POST['description']); if (ALLOW_SHORT_PAGE_NAMES) { $name = $_POST['name'] == "" ? slug($_POST['title']) : slug($_POST['name']); } else { $name = slug($_POST['title']); } // Was a file uploaded? if (is_uploaded_file($_FILES["image"]["tmp_name"])) { $mimeType = $_FILES["image"]["type"]; $filetype = getFileExtension($_FILES["image"]["name"]); list($width) = getimagesize($_FILES["image"]["tmp_name"]); $max_width = 0; $max_height = 0; if (defined("MAX_IMAGE_HEIGHT")) { $max_height = MAX_IMAGE_HEIGHT; } if (defined("MAX_IMAGE_WIDTH")) { $max_width = MAX_IMAGE_WIDTH; } resizeToMultipleMaxDimensions($_FILES["image"]["tmp_name"], $max_width, $max_height, $filetype); // Open the uploaded file $file = fopen($_FILES["image"]["tmp_name"], "r"); // Read in the uploaded file $fileContents = fread($file, filesize($_FILES["image"]["tmp_name"])); // Escape special characters in the file $fileContents = AddSlashes($fileContents); /*if( copy($_FILES["image"]["tmp_name"], $_FILES["image"]["tmp_name"] . "_thumb") ) { resizeToMultipleMaxDimensions($_FILES["image"]["tmp_name"] . "_thumb", 200, 0); $image = open_image($_FILES["image"]["tmp_name"] . "_thumb"); if ( $image === false ) { die ('Unable to open image for resizing'); } $width = imagesx($image); // Open the thumbnail file $thumb_file = fopen($_FILES["image"]["tmp_name"] . "_thumb", "r"); // Read in the thumbnail file $thumb_fileContents = fread($thumb_file, filesize($_FILES["image"]["tmp_name"] . "_thumb")); // Escape special characters in the file $thumb_fileContents = AddSlashes($thumb_fileContents); }*/ $thumb_fileContents = NULL; } else { $fileContents = $thumb_fileContents = NULL; } $insertQuery = "INSERT INTO images VALUES (NULL, \"{$title}\", \"{$description}\", \"{$fileContents}\", \"{$thumb_fileContents}\", \"{$mimeType}\", \"{$name}\")"; $result = mysql_Query($insertQuery, MyActiveRecord::Connection()); if (empty($result)) { //die( $updateQuery ); setFlash("<h3>FAILURE – Please notify HCd of this error: " . mysql_error() . "</h3>"); } setFlash("<h3>Image uploaded</h3>"); if ($post_action == "Add and Return to List") { redirect("/admin/list_images"); } } }
function initialize_page() { $success = $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Add Item" || $post_action == "Add and Return to List") { // ! create item $item = MyActiveRecord::Create('Items'); $item->content = $_POST['item_content']; $item->display_name = $_POST['display_name']; $item->name = slug($_POST['display_name']); $item->location = $_POST['location']; $item->public = checkboxValue($_POST, 'public'); $item->mime_type = 0; $item->taxonomy = $_POST['taxonomy']; $item->date_created = date('Y-m-d H:i:s'); // optional fields $item->sku = ITEM_SKU ? $_POST['item_sku'] : null; $item->taxonomy = ITEM_TAXONOMY ? $_POST['taxonomy'] : null; $item->price = ITEM_PRICE ? $_POST['item_price'] : null; // synchronize the users area selections $selected_sections = array(); if (isset($_POST['selected_sections'])) { $selected_sections = $_POST['selected_sections']; } $item->save(); $item->updateSelectedSections($selected_sections); $item->setDisplayOrder(); $success .= "Item Saved / "; // ! create gallery and associate it $gallery = MyActiveRecord::Create('Galleries'); $gallery->name = $_POST['display_name'] . " Gallery"; $gallery->slug = "portfolioGal_" . $item->id . "_" . slug($_POST['display_name']); $gallery->save(); $success .= "Gallery Created / "; if (PORTFOLIOTHUMB_IMAGE) { // now check if a thumbnail was uploaded if (is_uploaded_file($_FILES["thumbnail"]["tmp_name"])) { $mimeType = $_FILES["thumbnail"]["type"]; $fileType = ""; switch ($mimeType) { case "image/gif": $fileType = "gif"; break; case "image/jpg": case "image/jpeg": $fileType = "jpg"; break; case "image/png": $fileType = "png"; break; case "image/x-MS-bmp": $fileType = "bmp"; break; } resizeToMultipleMaxDimensions($_FILES["thumbnail"]["tmp_name"], PORTFOLIOTHUMB_IMAGE_MAXWIDTH, PORTFOLIOTHUMB_IMAGE_MAXHEIGHT, $fileType); // Open the uploaded file $file = fopen($_FILES["thumbnail"]["tmp_name"], "r"); // Read in the uploaded file $fileContents = fread($file, filesize($_FILES["thumbnail"]["tmp_name"])); // Escape special characters in the file $fileContents = AddSlashes($fileContents); $updateQuery = "UPDATE items SET thumbnail = \"{$fileContents}\", mime_type = \"{$mimeType}\" WHERE id = {$item->id};"; if (mysql_Query($updateQuery, MyActiveRecord::Connection())) { $success .= "Thumbnail Added / "; } else { die(mysql_error()); } } } setFlash("<h3>" . substr($success, 0, -3) . "</h3>"); // Remember to get a section for the redirect link... $itemsection = array_shift($item->getSections()); redirect("/admin/portfolio_edit/" . $itemsection->name . "/" . $item->id); } }
function initialize_page() { $image_id = requestIdParam(); $image = Images::FindById($image_id); $post_action = isset($_POST['submit']) ? $_POST['submit'] : ""; if ($post_action == "Save Image" || $post_action == "Save and Return to List") { $success = ''; if (isset($_POST['delete'])) { $image->delete(true); setFlash("<h3>Image deleted</h3>"); redirect("/admin/list_images"); } else { $old_name = $image->name; $image->title = cleanupSpecialChars($_POST['title']); $image->description = cleanupSpecialChars($_POST['description']); if (ALLOW_SHORT_PAGE_NAMES) { $image->name = $_POST['name'] == "" ? slug($_POST['title']) : slug($_POST['name']); } else { $image->name = slug($_POST['title']); } //$image->save(); $updateQuery = "UPDATE images SET title='{$image->title}', name='{$image->name}', description='{$image->description}' WHERE id='{$image->id}';"; if (mysql_Query($updateQuery, MyActiveRecord::Connection())) { if ($old_name != $image->name) { Pages::UpdateImageReferences($old_name, $image->name); } $success .= "Image changes saved / "; } else { die($updateQuery); setFlash("<h3>FAILURE – Please notify HCd of this error: " . mysql_error() . "</h3>"); } // Replace an existing image with a new one if (is_uploaded_file($_FILES["new_image"]["tmp_name"])) { $mimeType = $_FILES["new_image"]["type"]; $filetype = getFileExtension($_FILES["new_image"]["name"]); //list($width) = getimagesize($_FILES["new_image"]["tmp_name"]); $max_width = 0; $max_height = 0; if (defined("MAX_IMAGE_WIDTH")) { $max_width = MAX_IMAGE_WIDTH; } if (defined("MAX_IMAGE_HEIGHT")) { $max_height = MAX_IMAGE_HEIGHT; } resizeToMultipleMaxDimensions($_FILES["new_image"]["tmp_name"], $max_width, $max_height, $filetype); // Open the uploaded file $file = fopen($_FILES["new_image"]["tmp_name"], "r"); // Read in the uploaded file $fileContents = fread($file, filesize($_FILES["new_image"]["tmp_name"])); // Escape special characters in the file $fileContents = AddSlashes($fileContents); $updateQuery2 = "UPDATE images SET original='{$fileContents}', mime_type='{$mimeType}' WHERE id='{$image->id}';"; if (mysql_Query($updateQuery2, MyActiveRecord::Connection())) { $success .= "Image replaced / "; } else { setFlash("FAILURE – Please notify HCd of this error: " . mysql_error() . "</h3>"); //die( $updateQuery2 ); } } } if ($post_action == "Save and Return to List") { redirect("/admin/list_images"); } setFlash("<h3>" . substr($success, 0, -3) . "</h3>"); } }
function save_uploaded_file($tmp_name, $file_name, $isportimg = false, $isentryimg = false, $maxwidth = 0, $maxheight = 0) { $filetype = getFileExtension($file_name); $file_name = slug(basename($file_name, $filetype)); $new_file_name = $this->id . "-" . $file_name . '.' . $filetype; move_uploaded_file($tmp_name, $this->get_local_image_path($new_file_name)); chmod($this->get_local_image_path($new_file_name), 0644); $max_width = 0; $max_height = 0; if ($maxwidth != 0) { $max_width = $maxwidth; } elseif ($maxheight != 0) { $max_height = $maxheight; } elseif ($isportimg) { if (defined("MAX_PORTFOLIO_IMAGE_HEIGHT")) { $max_height = MAX_PORTFOLIO_IMAGE_HEIGHT; } if (defined("MAX_PORTFOLIO_IMAGE_WIDTH")) { $max_width = MAX_PORTFOLIO_IMAGE_WIDTH; } } elseif ($isentryimg) { if (defined("MAX_ENTRY_IMAGE_HEIGHT")) { $max_height = MAX_ENTRY_IMAGE_HEIGHT; } if (defined("MAX_ENTRY_IMAGE_WIDTH")) { $max_width = MAX_ENTRY_IMAGE_WIDTH; } } else { if (defined("MAX_GALLERY_IMAGE_HEIGHT")) { $max_height = MAX_GALLERY_IMAGE_HEIGHT; } if (defined("MAX_GALLERY_IMAGE_WIDTH")) { $max_width = MAX_GALLERY_IMAGE_WIDTH; } } $this->filename = $new_file_name; $this->save(); resizeToMultipleMaxDimensions($this->get_local_image_path($new_file_name), $max_width, $max_height, $filetype); //$query = "UPDATE photos SET filename = $file_name WHERE id = {$this->id};"; //return mysql_query( $query, MyActiveRecord::Connection() ) or die( $query ); }