Attached Files |
universal_mime_detection.patch [^] (2,055 bytes) 2010-05-23 07:08
[Show Content]
Index: kernel/globals.php
===================================================================
--- kernel/globals.php (revision 13571)
+++ kernel/globals.php (working copy)
@@ -739,4 +739,44 @@
return $res;
}
+ }
+
+ function get_mime_type($file)
+ {
+ $ret = '';
+
+ if (function_exists('finfo_open') && function_exists('finfo_file')) {
+ $mime_magic_resource = finfo_open(FILEINFO_MIME);
+
+ if ($mime_magic_resource) {
+ $ret = finfo_file($mime_magic_resource, $file);
+ finfo_close($mime_magic_resource);
+ }
+ }
+ elseif (function_exists('mime_content_type')) {
+ $ret = mime_content_type($file);
+ }
+
+ if (!$ret) {
+ // use file extension to mime type mapping array
+ $file_extension = mb_strtolower( pathinfo($file, PATHINFO_EXTENSION) );
+
+ $mapping = '(xls:application/excel)(hqx:application/macbinhex40)(doc,dot,wrd:application/msword)(pdf:application/pdf)
+ (pgp:application/pgp)(ps,eps,ai:application/postscript)(ppt:application/powerpoint)(rtf:application/rtf)
+ (tgz,gtar:application/x-gtar)(gz:application/x-gzip)(php,php3:application/x-httpd-php)(js:application/x-javascript)
+ (ppd,psd:application/x-photoshop)(swf,swc,rf:application/x-shockwave-flash)(tar:application/x-tar)(zip:application/zip)
+ (mid,midi,kar:audio/midi)(mp2,mp3,mpga:audio/mpeg)(ra:audio/x-realaudio)(wav:audio/wav)(bmp:image/bitmap)(bmp:image/bitmap)
+ (gif:image/gif)(iff:image/iff)(jb2:image/jb2)(jpg,jpe,jpeg:image/jpeg)(jpx:image/jpx)(png:image/png)(tif,tiff:image/tiff)
+ (wbmp:image/vnd.wap.wbmp)(xbm:image/xbm)(css:text/css)(txt:text/plain)(htm,html:text/html)(xml:text/xml)
+ (mpg,mpe,mpeg:video/mpeg)(qt,mov:video/quicktime)(avi:video/x-ms-video)(eml:message/rfc822)';
+
+ if (preg_match('/[\(,]'.$file_extension.'[,]{0,1}.*?:(.*?)\)/s', $mapping, $regs)) {
+ $ret = $regs[1];
+ }
+ else {
+ $ret = 'application/octet-stream';
+ }
+ }
+
+ return $ret;
}
\ No newline at end of file
universal_mime_detection_core_520.patch [^] (8,093 bytes) 2011-10-04 03:38
[Show Content]
Index: kernel/db/db_event_handler.php
===================================================================
--- kernel/db/db_event_handler.php (revision 14610)
+++ kernel/db/db_event_handler.php (working copy)
@@ -2969,10 +2969,8 @@
exit;
}
- $type = mime_content_type($path);
-
header('Content-Length: ' . filesize($path));
- header('Content-Type: ' . $type);
+ header('Content-Type: ' . kUtil::mimeContentType($path));
header('Content-Disposition: inline; filename="' . $file . '"');
readfile($path);
Index: kernel/globals.php
===================================================================
--- kernel/globals.php (revision 14609)
+++ kernel/globals.php (working copy)
@@ -581,6 +581,65 @@
return false;
}
+
+ /**
+ * Returns mime type corresponding to given file
+ * @param string $file
+ * @return string
+ * @access public
+ */
+ public static function mimeContentType($file)
+ {
+ $ret = '';
+
+ if ( function_exists('finfo_open') && function_exists('finfo_file') ) {
+ $mime_magic_resource = finfo_open(FILEINFO_MIME_TYPE);
+
+ if ( $mime_magic_resource ) {
+ $ret = finfo_file($mime_magic_resource, $file);
+ finfo_close($mime_magic_resource);
+ }
+ }
+ elseif ( function_exists('mime_content_type') ) {
+ $ret = mime_content_type($file);
+ }
+
+ return $ret ? $ret : self::mimeContentTypeByExtension($file);
+ }
+
+ /**
+ * Detects mime type of the file purely based on it's extension
+ *
+ * @param string $file
+ * @return string
+ * @access public
+ */
+ public static function mimeContentTypeByExtension($file)
+ {
+ $file_extension = mb_strtolower( pathinfo($file, PATHINFO_EXTENSION) );
+
+ $mapping = '(xls:application/excel)(hqx:application/macbinhex40)(doc,dot,wrd:application/msword)(pdf:application/pdf)
+ (pgp:application/pgp)(ps,eps,ai:application/postscript)(ppt:application/powerpoint)(rtf:application/rtf)
+ (tgz,gtar:application/x-gtar)(gz:application/x-gzip)(php,php3:application/x-httpd-php)(js:application/x-javascript)
+ (ppd,psd:application/x-photoshop)(swf,swc,rf:application/x-shockwave-flash)(tar:application/x-tar)(zip:application/zip)
+ (mid,midi,kar:audio/midi)(mp2,mp3,mpga:audio/mpeg)(ra:audio/x-realaudio)(wav:audio/wav)(bmp:image/bitmap)(bmp:image/bitmap)
+ (gif:image/gif)(iff:image/iff)(jb2:image/jb2)(jpg,jpe,jpeg:image/jpeg)(jpx:image/jpx)(png:image/png)(tif,tiff:image/tiff)
+ (wbmp:image/vnd.wap.wbmp)(xbm:image/xbm)(css:text/css)(txt:text/plain)(htm,html:text/html)(xml:text/xml)
+ (mpg,mpe,mpeg:video/mpeg)(qt,mov:video/quicktime)(avi:video/x-ms-video)(eml:message/rfc822)
+ (sxw:application/vnd.sun.xml.writer)(sxc:application/vnd.sun.xml.calc)(sxi:application/vnd.sun.xml.impress)
+ (sxd:application/vnd.sun.xml.draw)(sxm:application/vnd.sun.xml.math)
+ (odt:application/vnd.oasis.opendocument.text)(oth:application/vnd.oasis.opendocument.text-web)
+ (odm:application/vnd.oasis.opendocument.text-master)(odg:application/vnd.oasis.opendocument.graphics)
+ (odp:application/vnd.oasis.opendocument.presentation)(ods:application/vnd.oasis.opendocument.spreadsheet)
+ (odc:application/vnd.oasis.opendocument.chart)(odf:application/vnd.oasis.opendocument.formula)
+ (odi:application/vnd.oasis.opendocument.image)';
+
+ if ( preg_match('/[\(,]' . $file_extension . '[,]{0,1}.*?:(.*?)\)/s', $mapping, $regs) ) {
+ return $regs[1];
+ }
+
+ return 'application/octet-stream';
+ }
}
/**
Index: kernel/utility/email_send.php
===================================================================
--- kernel/utility/email_send.php (revision 14590)
+++ kernel/utility/email_send.php (working copy)
@@ -891,26 +891,11 @@
*/
function guessContentType($filename, &$content_type, &$encoding)
{
- $file_extension = mb_strtolower( $this->GetFilenameExtension($filename) );
+ $content_type = kUtil::mimeContentTypeByExtension($filename);
- $mapping = '(xls:application/excel)(hqx:application/macbinhex40)(doc,dot,wrd:application/msword)(pdf:application/pdf)
- (pgp:application/pgp)(ps,eps,ai:application/postscript)(ppt:application/powerpoint)(rtf:application/rtf)
- (tgz,gtar:application/x-gtar)(gz:application/x-gzip)(php,php3:application/x-httpd-php)(js:application/x-javascript)
- (ppd,psd:application/x-photoshop)(swf,swc,rf:application/x-shockwave-flash)(tar:application/x-tar)(zip:application/zip)
- (mid,midi,kar:audio/midi)(mp2,mp3,mpga:audio/mpeg)(ra:audio/x-realaudio)(wav:audio/wav)(bmp:image/bitmap)(bmp:image/bitmap)
- (gif:image/gif)(iff:image/iff)(jb2:image/jb2)(jpg,jpe,jpeg:image/jpeg)(jpx:image/jpx)(png:image/png)(tif,tiff:image/tiff)
- (wbmp:image/vnd.wap.wbmp)(xbm:image/xbm)(css:text/css)(txt:text/plain)(htm,html:text/html)(xml:text/xml)
- (mpg,mpe,mpeg:video/mpeg)(qt,mov:video/quicktime)(avi:video/x-ms-video)(eml:message/rfc822)';
-
- if (preg_match('/[\(,]'.$file_extension.'[,]{0,1}.*?:(.*?)\)/s', $mapping, $regs)) {
- if ($file_extension == 'eml') {
- $encoding = '7bit';
- }
- $content_type = $regs[1];
+ if ( mb_strtolower($this->GetFilenameExtension($filename)) == 'eml' ) {
+ $encoding = '7bit';
}
- else {
- $content_type = 'application/octet-stream';
- }
}
/**
@@ -1737,25 +1722,31 @@
*
* @param string $text
* @param bool $multiple
- * @param bool $allowOnlyDomain
- * @return string
+ * @param bool $allow_only_domain
+ * @return Array|bool
+ * @access public
*/
- function ExtractRecipientEmail($text, $multiple = false, $allowOnlyDomain = false) {
- if ($allowOnlyDomain) {
- $pattern = '/(('.REGEX_EMAIL_USER.'@)?'.REGEX_EMAIL_DOMAIN.')/i';
- } else {
- $pattern = '/('.REGEX_EMAIL_USER.'@'.REGEX_EMAIL_DOMAIN.')/i';
+ public function ExtractRecipientEmail($text, $multiple = false, $allow_only_domain = false)
+ {
+ if ( $allow_only_domain ) {
+ $pattern = '/((' . REGEX_EMAIL_USER . '@)?' . REGEX_EMAIL_DOMAIN . ')/i';
}
- if ($multiple) {
- if (preg_match_all($pattern, $text, $findemail) >= 1) {
- return $findemail[1];
- } else {
+ else {
+ $pattern = '/(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')/i';
+ }
+ if ( $multiple ) {
+ if ( preg_match_all($pattern, $text, $found_emails) >= 1 ) {
+ return $found_emails[1];
+ }
+ else {
return false;
}
- } else {
- if (preg_match($pattern, $text, $findemail) == 1) {
- return $findemail[1];
- } else {
+ }
+ else {
+ if ( preg_match($pattern, $text, $found_emails) == 1 ) {
+ return $found_emails[1];
+ }
+ else {
return false;
}
}
Index: units/helpers/file_helper.php
===================================================================
--- units/helpers/file_helper.php (revision 14590)
+++ units/helpers/file_helper.php (working copy)
@@ -221,12 +221,15 @@
* @param string $prefix
* @param string $field_name
* @param Array $virtual_fields
+ * @param bool $is_image
+ * @return void
+ * @access protected
*/
- function _createCustomFields($prefix, $field_name, &$virtual_fields, $is_image)
+ protected function _createCustomFields($prefix, $field_name, &$virtual_fields, $is_image = false)
{
$virtual_fields['Delete' . $field_name] = Array ('type' => 'int', 'default' => 0);
- if ($is_image) {
+ if ( $is_image ) {
$virtual_fields[$field_name . 'Alt'] = Array ('type' => 'string', 'default' => '');
}
}
@@ -238,11 +241,9 @@
*/
function DownloadFile($filename)
{
- $content_type = function_exists('mime_content_type') ? mime_content_type($filename) : 'application/octet-stream';
-
- header('Content-type: '.$content_type);
- header('Content-Disposition: attachment; filename="'.basename($filename).'"');
- header('Content-Length: '.filesize($filename));
+ header('Content-type: ' . kUtil::mimeContentType($filename));
+ header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
+ header('Content-Length: ' . filesize($filename));
readfile($filename);
flush();
}
universal_mime_detection_modules_520.patch [^] (2,335 bytes) 2011-10-04 03:38
[Show Content]
Index: in-commerce/units/downloads/download_helper.php
===================================================================
--- in-commerce/units/downloads/download_helper.php (revision 14590)
+++ in-commerce/units/downloads/download_helper.php (working copy)
@@ -42,12 +42,10 @@
function DoSendFile($file_info)
{
- $content_type = function_exists('mime_content_type') ? mime_content_type($file_info['real_path']) : $file_info['MIMEType'];
+ header('Content-type: ' . kUtil::mimeContentType($file_info['real_path']));
+ header('Content-Disposition: attachment; filename="' . $file_info['FilePath'] . '"');
+ header('Content-Length: ' . filesize($file_info['real_path']));
- header('Content-type: '.$content_type);
- header('Content-Disposition: attachment; filename="'.$file_info['FilePath'].'"');
- header('Content-Length: '.filesize($file_info['real_path']));
-
$file_info['download_start'] = adodb_mktime();
readfile($file_info['real_path']);
flush();
Index: in-commerce/units/orders/orders_event_handler.php
===================================================================
--- in-commerce/units/orders/orders_event_handler.php (revision 14594)
+++ in-commerce/units/orders/orders_event_handler.php (working copy)
@@ -1308,7 +1308,7 @@
protected function OnBeforeClone(&$event)
{
parent::OnBeforeClone($event);
-
+
$object =& $event->getObject();
if (substr($event->Special, 0, 9) == 'recurring') {
@@ -3460,16 +3460,15 @@
ini_set('max_execution_time', '0');
$object =& $event->getObject();
- $file = $object->GetDBField('ShippingTracking').'.pdf';
- $full_path = USPS_LABEL_FOLDER.$file;
+ $file = $object->GetDBField('ShippingTracking') . '.pdf';
+ $full_path = USPS_LABEL_FOLDER . $file;
- if (!file_exists($full_path) || !is_file($full_path)) {
- return ;
+ if ( !file_exists($full_path) || !is_file($full_path) ) {
+ return;
}
- $mime = function_exists('mime_content_type') ? mime_content_type($full_path) : 'application/download';
- header('Content-type: '.$mime);
- header('Content-Disposition: attachment; filename="'.$file.'"');
+ header('Content-type: ' . kUtil::mimeContentType($full_path));
+ header('Content-Disposition: attachment; filename="' . $file . '"');
readfile($full_path);
}
}
\ No newline at end of file
|