/** * @param array $infos assoc array of data from images table */ function __construct($infos) { global $conf; $this->id = $infos['id']; $ext = get_extension($infos['path']); if (in_array($ext, $conf['picture_ext'])) { $this->rel_path = $infos['path']; $this->flags |= self::IS_ORIGINAL; } elseif (!empty($infos['representative_ext'])) { $this->rel_path = original_to_representative($infos['path'], $infos['representative_ext']); } else { $ext = strtolower($ext); $this->rel_path = trigger_change('get_mimetype_location', get_themeconf('mime_icon_dir') . $ext . '.png', $ext); $this->flags |= self::IS_MIMETYPE; if (($size = @getimagesize(PHPWG_ROOT_PATH . $this->rel_path)) === false) { $this->rel_path = 'themes/default/icon/mimetypes/unknown.png'; $size = getimagesize(PHPWG_ROOT_PATH . $this->rel_path); } $this->size = array($size[0], $size[1]); } if (!$this->size) { if (isset($infos['width']) && isset($infos['height'])) { $width = $infos['width']; $height = $infos['height']; $this->rotation = intval($infos['rotation']) % 4; // 1 or 5 => 90 clockwise // 3 or 7 => 270 clockwise if ($this->rotation % 2) { $width = $infos['height']; $height = $infos['width']; } $this->size = array($width, $height); } elseif (!array_key_exists('width', $infos)) { $this->flags |= self::DIM_NOT_GIVEN; } } }
/** * Get all metadata of a file. * * @param array $infos - (path[, representative_ext]) * @return array - includes data provided in $infos */ function get_sync_metadata($infos) { global $conf; $file = PHPWG_ROOT_PATH . $infos['path']; $fs = @filesize($file); if ($fs === false) { return false; } $infos['filesize'] = floor($fs / 1024); if (isset($infos['representative_ext'])) { $file = original_to_representative($file, $infos['representative_ext']); } if ($image_size = @getimagesize($file)) { $infos['width'] = $image_size[0]; $infos['height'] = $image_size[1]; } if ($conf['use_exif']) { $exif = get_sync_exif_data($file); $infos = array_merge($infos, $exif); } if ($conf['use_iptc']) { $iptc = get_sync_iptc_data($file); $infos = array_merge($infos, $iptc); } return $infos; }
do_error(401, 'Access denied'); } include_once PHPWG_ROOT_PATH . 'include/functions_picture.inc.php'; $file = ''; switch ($_GET['part']) { case 'e': if (!$user['enabled_high']) { $deriv = new DerivativeImage(IMG_XXLARGE, new SrcImage($element_info)); if (!$deriv->same_as_source()) { do_error(401, 'Access denied e'); } } $file = get_element_path($element_info); break; case 'r': $file = original_to_representative(get_element_path($element_info), $element_info['representative_ext']); break; case 'f': $file = original_to_format(get_element_path($element_info), $format['ext']); $element_info['file'] = get_filename_wo_extension($element_info['file']) . '.' . $format['ext']; break; } if (empty($file)) { do_error(404, 'Requested file not found'); } if ($_GET['part'] == 'e') { pwg_log($_GET['id'], 'high'); } else { if ($_GET['part'] == 'e') { pwg_log($_GET['id'], 'other'); } else {
/** * Deletes derivatives of a particular element * * @param array $infos ('path'[, 'representative_ext']) * @param 'all'|int $type */ function delete_element_derivatives($infos, $type = 'all') { $path = $infos['path']; if (!empty($infos['representative_ext'])) { $path = original_to_representative($path, $infos['representative_ext']); } if (substr_compare($path, '../', 0, 3) == 0) { $path = substr($path, 3); } $dot = strrpos($path, '.'); if ($type == 'all') { $pattern = '-*'; } else { $pattern = '-' . derivative_to_url($type) . '*'; } $path = substr_replace($path, $pattern, $dot, 0); if (($glob = glob(PHPWG_ROOT_PATH . PWG_DERIVATIVE_DIR . $path)) !== false) { foreach ($glob as $file) { @unlink($file); } } }
function upload_file_pdf($representative_ext, $file_path) { global $logger, $conf; $logger->info(__FUNCTION__ . ', $file_path = ' . $file_path . ', $representative_ext = ' . $representative_ext); if (isset($representative_ext)) { return $representative_ext; } if (pwg_image::get_library() != 'ext_imagick') { return $representative_ext; } if (!in_array(strtolower(get_extension($file_path)), array('pdf'))) { return $representative_ext; } $ext = conf_get_param('pdf_representative_ext', 'jpg'); $jpg_quality = conf_get_param('pdf_jpg_quality', 90); // move the uploaded file to pwg_representative sub-directory $representative_file_path = original_to_representative($file_path, $ext); prepare_directory(dirname($representative_file_path)); $exec = $conf['ext_imagick_dir'] . 'convert'; if ('jpg' == $ext) { $exec .= ' -quality ' . $jpg_quality; } $exec .= ' "' . realpath($file_path) . '"[0]'; $exec .= ' "' . $representative_file_path . '"'; $exec .= ' 2>&1'; @exec($exec, $returnarray); // Return the extension (if successful) or false (if failed) if (file_exists($representative_file_path)) { $representative_ext = $ext; } return $representative_ext; }