Esempio n. 1
0
 public function searchFiletype($extension)
 {
     $sql = "SELECT * FROM ink_filetypes WHERE extension LIKE '%{$extension}%';";
     $row = $this->runSingleQuery($sql);
     if (!isset($row['filetypeId'])) {
         return false;
     }
     $type = new Filetype();
     $properties = array('id' => $row['filetypeId'], 'name' => $row['fileType'], 'thumbnail' => $row['thumbname'], 'description' => $row['description']);
     $type->setProperties($properties);
     return $type;
 }
Esempio n. 2
0
 /**
  * Replace the image path for the given object ID and ordinal number.
  *
  * If no object with that ID and ordinal can be found, creates a new one.
  * In that case, the $imagetype_key parameter must be non-empty.
  * @param   integer     $image_id       The object ID
  * @param   integer     $ord            The ordinal number
  * @param   string      $path           The path
  * @param   integer     $imagetype_key  The image type key
  * @param   integer     $width          The optional width, overrides automatic value
  * @param   integer     $ord            The optional height, overrides automatic value
  * @return  boolean                     True on success, false otherwise
  */
 function replace($image_id, $ord, $path, $imagetype_key = '', $width = false, $height = false)
 {
     //echo("Image::replace($image_id, $ord, $path, $imagetype_key, $width, $height): Entered<br />");
     $objImage = self::getById($image_id, $ord);
     if (!$objImage && empty($imagetype_key)) {
         //echo("Image::replace(): Image not found and empty key<br />");
         return false;
     }
     if (!$objImage) {
         $objImage = new Image($ord);
     }
     File::clean_path($path);
     $imageSize = getimagesize(ASCMS_DOCUMENT_ROOT . '/' . $path);
     if ($width === false || $height === false) {
         $width = $imageSize[0];
         $height = $imageSize[1];
         //echo("Image::replace(): Image size: $width/$height<br />");
     }
     $path_parts = pathinfo($path);
     // TODO:  Debug stuff, remove in release
     //        $auto_type = $imageSize[2];
     //        if ($auto_type !== strtoupper($path_parts['extension']))
     //echo("Image::replace(image_id $image_id, ord $ord, path $path, imagetype_key $imagetype_key, width $width, height $height): Warning: Image extension (".$path_parts['extension'].") mismatch with type ($auto_type)<br />");
     // /TODO
     if ($imagetype_key) {
         $objImage->setTypeKey($imagetype_key);
     }
     $objImage->setPath($path);
     $objImage->setFileTypeKey(Filetype::getTypeIdForExtension($path_parts['extension']));
     $objImage->setWidth($width);
     $objImage->setHeight($height);
     //echo("Image::replace(): Storing Image<br />");
     if (!$objImage->store()) {
         return false;
     }
     return $objImage->resize();
 }
Esempio n. 3
0
 /**
  * Moves an uploaded file to a specified path
  *
  * Returns true if the file name is valid, the file type matches one of
  * the accepted file types, if specified, is not too large, and can be
  * moved successfully to its target folder.
  * Missing folders are created.  If this fails, returns false.
  * Mind that the target path *MUST NOT* include ASCMS_PATH, and *SHOULD*
  * not include ASCMS_PATH_OFFSET.  The latter will be cut off, however.
  * The $target_path argument, given by reference, is fixed accordingly.
  * If the file name found in $upload_field_name is empty, returns the
  * empty string.
  * Non-positive values for $maximum_size are ignored, as are empty
  * values for $accepted_types.
  * @param   string  $upload_field_name  File input field name
  * @param   string  $target_path        Target path, relative to the
  *                                      document root, including the file
  *                                      name, by reference.
  * @param   integer $maximum_size       The optional maximum allowed file size
  * @param   string  $accepted_types     The optional allowed MIME type
  * @return  boolean                     True on success, the empty string
  *                                      if there is nothing to do, or
  *                                      false otherwise
  * @author  Reto Kohli <*****@*****.**> (Parts, fixed path handling)
  * @since   2.2.0
  */
 static function upload_file_http($upload_field_name, &$target_path, $maximum_size = 0, $accepted_types = false)
 {
     // Skip files that are not uploaded at all
     if (empty($_FILES[$upload_field_name])) {
         //DBG::log("File::upload_file_http($upload_field_name, $target_path, $maximum_size, $accepted_types): No file for index $upload_field_name<br />");
         return '';
     }
     self::path_relative_to_root($target_path);
     //DBG::log("File::upload_file_http($upload_field_name, $target_path, $maximum_size, $accepted_types): Fixed target path $target_path<br />");
     if (empty($upload_field_name) || empty($target_path)) {
         //DBG::log("File::upload_file_http($upload_field_name, $target_path, $maximum_size, $accepted_types): Missing mandatory argument<br />");
         self::$error = self::ERROR_MISSING_ARGUMENT;
         return false;
     }
     $tmp_path = $_FILES[$upload_field_name]['tmp_name'];
     $file_name = $_FILES[$upload_field_name]['name'];
     if ($accepted_types && !Filetype::matchMimetypes($file_name, $accepted_types)) {
         //DBG::log("File::upload_file_http(): Error: Found no matching MIME type for extension ($file_name)<br />");
         self::$error = self::ERROR_INVALID_FILETYPE;
         return false;
     }
     if ($maximum_size > 0 && filesize($tmp_path) > $maximum_size) {
         //DBG::log("File::upload_file_http($upload_field_name, $target_path, $maximum_size, $accepted_types): Size greater than $maximum_size<br />");
         self::$error = self::ERROR_FILESIZE_TOO_BIG;
         return false;
     }
     // Create the target folder if it doesn't exist
     if (!File::make_folder(dirname($target_path))) {
         //DBG::log("File::upload_file_http(): Failed to create folder ".dirname($target_path)." for $target_path<br />");
         self::$error = self::ERROR_CANNOT_CREATE_FOLDER;
         return false;
     }
     if (move_uploaded_file($tmp_path, ASCMS_DOCUMENT_ROOT . '/' . $target_path)) {
         //DBG::log("File::upload_file_http($upload_field_name, $target_path, $maximum_size, $accepted_types): File successfully moved to $target_path<br />");
         return true;
     }
     //DBG::log("File::upload_file_http($upload_field_name, $target_path, $maximum_size, $accepted_types): move_uploaded_file failed<br />");
     self::$error = self::ERROR_CANNOT_MOVE_FILE;
     return false;
 }
Esempio n. 4
0
     $edited_Filetype = new Filetype();
     // Check permission:
     $current_User->check_perm('options', 'edit', true);
     // load data from request
     if ($edited_Filetype->load_from_Request()) {
         // We could load data from form without errors:
         // Insert in DB:
         $edited_Filetype->dbinsert();
         $Messages->add(T_('New file type created.'), 'success');
         // What next?
         param('submit', 'string', true);
         if ($submit == T_('Record, then Create Similar')) {
             $action = 'new';
         } elseif ($submit == T_('Record, then Create New')) {
             $action = 'new';
             $edited_Filetype = new Filetype();
         } else {
             $action = 'list';
             // Redirect so that a reload doesn't write to the DB twice:
             header_redirect('?ctrl=filetypes', 303);
             // Will EXIT
             // We have EXITed already at this point!!
         }
     }
     break;
 case 'update':
     // Edit file type form...:
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('filetype');
     // Check permission:
     $current_User->check_perm('options', 'edit', true);
Esempio n. 5
0
 /**
  * Initialize the arrays of extensions and mime types on request
  *
  * The arrays look like this:
  *  $arrExtensions2Mimetypes = array(
  *    Extension => array(
  *      'id'        => ID,
  *      'text_id'   => Text ID,
  *      'name'      => Name,
  *      'extension' => Extension,
  *      'mimetype' => array(
  *        MIME Type,
  *        ... more ...
  *      ),
  *    ),
  *    ... more ...
  *  );
  *
  *  $arrMimetypes2Extensions = array(
  *    MIME Type => array(
  *      'id'        => ID,
  *      'text_id'   => Text ID,
  *      'name'      => Name,
  *      'mimetype' => MIME Type,
  *      'extension' => array(
  *        Extension,
  *        ... more ...
  *      ),
  *    ),
  *    ... more ...
  *  );
  * @author  Reto Kohli <*****@*****.**>
  * @return  boolean             True on success, false otherwise
  * @static
  */
 static function init()
 {
     global $objDatabase;
     $arrSqlName = Text::getSqlSnippets('`filetype`.`text_name_id`', FRONTEND_LANG_ID, 0, self::TEXT_NAME);
     $query = "\n            SELECT `filetype`.`id`,\n                   `filetype`.`extension`, `filetype`.`mimetype`" . $arrSqlName['field'] . "\n              FROM " . DBPREFIX . "core_filetype AS `filetype`" . $arrSqlName['join'] . "\n             ORDER BY `filetype`.`ord` ASC";
     $objResult = $objDatabase->Execute($query);
     if (!$objResult) {
         return self::errorHandler();
     }
     self::$arrExtensions2Mimetypes = array();
     while (!$objResult->EOF) {
         $id = $objResult->fields['id'];
         $text_id = $objResult->fields[$arrSqlName['id']];
         $strName = $objResult->fields[$arrSqlName['text']];
         if ($strName === null) {
             $objText = Text::getById($id, 0);
             if ($objText) {
                 $strName = $objText->getText();
             }
         }
         if (empty(self::$arrExtensions2Mimetypes[$objResult->fields['extension']])) {
             self::$arrExtensions2Mimetypes[$objResult->fields['extension']] = array('id' => $id, 'text_id' => $text_id, 'name' => $strName, 'extension' => $objResult->fields['extension']);
         }
         self::$arrExtensions2Mimetypes[$objResult->fields['extension']]['mimetype'][] = $objResult->fields['mimetype'];
         if (empty(self::$arrMimetypes2Extensions[$objResult->fields['mimetype']])) {
             self::$arrMimetypes2Extensions[$objResult->fields['mimetype']] = array('id' => $id, 'text_id' => $text_id, 'name' => $strName, 'mimetype' => $objResult->fields['mimetype']);
         }
         self::$arrMimetypes2Extensions[$objResult->fields['mimetype']]['extension'][] = $objResult->fields['extension'];
         $objResult->MoveNext();
     }
     return true;
 }
Esempio n. 6
0
 /**
  * Get icon for this file.
  *
  * Looks at the file's extension.
  *
  * @uses get_icon()
  * @return string img tag
  */
 function get_icon()
 {
     if ($this->is_dir()) {
         // Directory icon:
         $icon = 'folder';
     } elseif (isset($this->Filetype->icon) && $this->Filetype->icon) {
         // Return icon for known type of the file
         return $this->Filetype->get_icon();
     } else {
         // Icon for unknown file type:
         $icon = 'file_unknown';
     }
     // Return Icon for a directory or unknown type file:
     return get_icon($icon, 'imgtag', array('alt' => $this->get_ext(), 'title' => $this->get_type()));
 }