Exemplo n.º 1
0
 /**
  * Establishes dimensions for the image, then sends for processing
  *
  * @param array $file
  * @return string    Image path on success or FALSE on failure
  */
 public function check_image($file, $dir = NULL, $rename = TRUE)
 {
     $img_ctrl = new ImageControl();
     if (isset($dir) && strlen($dir) > 0) {
         $img_ctrl->dir = $dir;
         $img_ctrl->checkDir();
     }
     // If no errors occurred in the upload, process the image
     if ($file['error'] == 0) {
         // Make sure it's processed as the right type of image
         if ($file['type'] !== IMG_JPG || $file['type'] !== IMG_GIF || $file['type'] !== IMG_PNG) {
             $extension = array_shift(array_reverse(explode('.', $file['name'])));
             if ($extension === 'jpg') {
                 $file['type'] = IMG_JPG;
             } else {
                 if ($extension === 'gif') {
                     $file['type'] = IMG_GIF;
                 } else {
                     if ($extension === 'png') {
                         $file['type'] = IMG_PNG;
                     } else {
                         ECMS_Error::log_exception(new Exception("Unrecognized file type"));
                     }
                 }
             }
         }
         $img_ctrl->max_dims = array(IMG_MAX_WIDTH, IMG_MAX_HEIGHT);
         try {
             // Store the image
             $stored = $img_ctrl->processUploadedImage($file, $rename);
             if (!$stored) {
                 return FALSE;
             } else {
                 // Create a preview of the image
                 $img_ctrl->preview = TRUE;
                 $img_ctrl->max_dims = array(IMG_PREV_WIDTH, IMG_PREV_HEIGHT);
                 if (!$img_ctrl->processStoredImage($stored)) {
                     throw new Exception("Couldn't create image preview!");
                 }
                 // Create a square thumbnail of the image
                 $img_ctrl->preview = FALSE;
                 $img_ctrl->max_dims = array(IMG_THUMB_SIZE, IMG_THUMB_SIZE);
                 if ($img_ctrl->processStoredImage($stored, TRUE)) {
                     return substr($stored, 0, 1) === '/' ? $stored : '/' . $stored;
                 } else {
                     return FALSE;
                 }
             }
         } catch (Exception $e) {
             ECMS_Error::log_exception($e);
         }
     } else {
         return FALSE;
     }
 }
Exemplo n.º 2
0
 /**
  * Writes data to the database; either updates or creates an entry
  *
  * @return bool        Returns true on success or false on error
  */
 public function save_entry()
 {
     // Initialize all variables to prevent any notices
     $entry_id = '';
     $page_id = '';
     $title = NULL;
     $entry = NULL;
     $excerpt = NULL;
     $slug = "";
     $tags = NULL;
     $extra = array();
     $var_names = array('entry_id', 'page_id', 'title', 'entry', 'excerpt', 'slug', 'tags', 'author', 'created');
     // Loop through the POST array and define all variables
     foreach ($_POST as $key => $val) {
         if (!in_array($key, array('page', 'action', 'token', 'form-submit')) && !in_array($key, $var_names)) {
             $extra[$key] = $val;
         } else {
             if ($key === "entry" || $key === "excerpt") {
                 ${$key} = $val;
             } else {
                 // If it's not the body of the entry, escape all entities
                 ${$key} = htmlentities($val, ENT_QUOTES, 'UTF-8', FALSE);
             }
         }
     }
     foreach ($_FILES as $key => $val) {
         // If a file was uploaded, handle it here
         if (is_array($_FILES[$key]) && $_FILES[$key]['error'] === 0) {
             // First, see if the file is an image
             ${$key} = ImageControl::check_image($_FILES[$key]);
             // If not, just save the file
             if (!${$key}) {
                 ${$key} = Utilities::store_uploaded_file($_FILES[$key]);
             }
             $extra[$key] = ${$key};
         } else {
             if (!empty($_POST[$key . '-value'])) {
                 $extra[$key] = SIV::clean_output($_POST[$key . '-value'], FALSE, FALSE);
             }
         }
     }
     // If a slug wasn't set, save a URL version of the title
     $slug = empty($slug) ? Utilities::make_url($title) : $slug;
     // Make sure an order value exists
     $order = !empty($order) ? $order : 0;
     // If an excerpt wasn't set, create a text preview
     $excerpt = empty($excerpt) ? strip_tags(Utilities::text_preview($entry)) : $excerpt;
     // Store the author's name and a timestamp
     $author = $_SESSION['user']['name'];
     $created = time();
     // Set up the query to insert or update the entry
     $sql = "INSERT INTO `" . DB_NAME . "`.`" . DB_PREFIX . "entries`\n                (" . self::ENTRY_FIELDS . "\n                )\n                VALUES\n                (\n                    :entry_id,\n                    (\n                        SELECT `page_id`\n                        FROM `" . DB_NAME . "`.`" . DB_PREFIX . "pages`\n                        WHERE `page_slug`=:page_slug\n                        LIMIT 1\n                    ), :title, :entry, :excerpt, :slug, :tags,\n                    :order, :extra, :author, :created\n                )\n                ON DUPLICATE KEY UPDATE\n                    `title`=:title,\n                    `entry`=:entry,\n                    `excerpt`=:excerpt,\n                    `slug`=:slug,\n                    `tags`=:tags,\n                    `order`=:order,\n                    `extra`=:extra;";
     try {
         $stmt = $this->db->prepare($sql);
         $stmt->bindParam(":entry_id", $entry_id, PDO::PARAM_INT);
         $stmt->bindParam(":page_slug", $page, PDO::PARAM_INT);
         $stmt->bindParam(":title", $title, PDO::PARAM_STR);
         $stmt->bindParam(":entry", $entry, PDO::PARAM_STR);
         $stmt->bindParam(":excerpt", $excerpt, PDO::PARAM_STR);
         $stmt->bindParam(":slug", $slug, PDO::PARAM_STR);
         $stmt->bindParam(":order", $order, PDO::PARAM_INT);
         $stmt->bindParam(":tags", $tags, PDO::PARAM_STR);
         $stmt->bindParam(":extra", serialize($extra), PDO::PARAM_STR);
         $stmt->bindParam(":author", $author, PDO::PARAM_STR);
         $stmt->bindParam(":created", $created, PDO::PARAM_STR);
         $stmt->execute();
         if ($stmt->errorCode() !== '00000') {
             $err = $stmt->errorInfo();
             ECMS_Error::log_exception(new Exception($err[2]));
         }
         $stmt->closeCursor();
         return TRUE;
     } catch (Exception $e) {
         $this->_log_exception($e);
     }
 }
Exemplo n.º 3
0
<?php

//ͼƬ´óС¿ØÖƲâÊÔ
//by indraw
//2004/11/18
include 'ImageControl.class.php';
$imm = new ImageControl('test.jpg', '.');
//=============================================================================
//½«Í¼Æ¬test.jpgÉú³ÉËõÂÔͼ£¬²¢ÏÔʾ¡£
if ($imm->exist_image()) {
    echo "<p>image name : " . $imm->get_image_name() . "</p>\n";
    echo "<p>image height : " . $imm->get_image_height() . "</p>\n";
    echo "<p>image whidth : " . $imm->get_image_width() . "</p>\n";
    echo "<p>image path : " . $imm->get_image_path() . "</p>\n";
    echo "<p>image size : " . $imm->get_image_size() . "</p>\n";
    echo "<p>image dimension : " . $imm->get_image_dimension() . "</p>\n";
    echo "<p>image type : " . $imm->get_image_type() . "</p>\n";
    if ($imm->exist_thumb()) {
        echo "<p>Existent thumb : " . $imm->get_thumb_name() . "</p><br>";
    } else {
        $imm->set_back('255', '255', '255');
        $imm->set_frame('208', '208', '208');
        $imm->make_thumb("180");
        if ($imm->exist_thumb()) {
            echo "<p>Created thumb : " . $imm->get_thumb_name() . "</p><br>";
        }
    }
    echo $imm->html_thumb_image();
} else {
    echo "<p>Do not exist!</p>";
}
Exemplo n.º 4
0
 /**
  * Establishes dimensions for the image, then sends for processing
  *
  * @param array $files
  * @return string    Image path on success or FALSE on failure
  */
 public function checkIMG($files)
 {
     $img_ctrl = new ImageControl();
     if ($files['error'] == 0) {
         $img_ctrl->max_dims = array($this->img_dims['w'], $this->img_dims['h']);
         try {
             $stored = $img_ctrl->processUploadedImage($files);
             if (!$stored) {
                 return false;
             } else {
                 $img_ctrl->preview = TRUE;
                 $img_ctrl->max_dims = array(IMG_PREV_WIDTH, IMG_PREV_HEIGHT);
                 if (!$img_ctrl->processStoredImage($stored)) {
                     throw new Exception("Couldn't create image preview!");
                 }
                 $img_ctrl->preview = FALSE;
                 $img_ctrl->max_dims = array($this->img_dims['t'], $this->img_dims['t']);
                 if ($img_ctrl->processStoredImage($stored, TRUE)) {
                     return $stored;
                 } else {
                     return false;
                 }
             }
         } catch (Exception $e) {
             exit($e->getMessage());
         }
     } else {
         return false;
     }
 }