OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



Has anyone see an issue with OMP and uploads of CSS files?

Are you responsible for making OMP work -- installing, upgrading, migrating or troubleshooting? Do you think you've found a bug? Post in this forum.

Moderators: jmacgreg, michael, asmecher

Forum rules
What to do if you have a technical problem with OMP:

1. Search the forum. You can do this from the Advanced Search Page or from our Google Custom Search, which will search the entire PKP site. If you are encountering an error, we especially recommend searching the forum for said error.

2. Check the FAQ to see if your question or error has already been resolved.

3. Post a question, but please, only after trying the above two solutions. If it's a workflow or usability question you should probably post to the OMP Discussion subforum; if you have a development question, try the OMP Development subforum.

Has anyone see an issue with OMP and uploads of CSS files?

Postby bdgregg » Mon Jun 17, 2013 1:10 pm

Just out of curiosity, has anyone had an issue with uploading a stylesheet to OMP 1.0? I suspect that the attached image is related to mime types but for a lack to where to start troubleshooting this at, does anyone have a hint? The system is running Oracle Enterprise Linux 6.4 (RHEL 6.4 equiv.) with all current patches. File permissions are all set correctly and there are no comments in the start of the CSS file.

Hints?

Thanks in advance.
Attachments
ompstyles.css.txt
Style Sheet
(6.64 KiB) Downloaded 59 times
OMP - CSS upload fail.jpg
OMP - CSS upload fail.jpg (122.19 KiB) Viewed 2091 times
bdgregg
 
Posts: 117
Joined: Wed Sep 15, 2004 8:21 am
Location: University of Pittsburgh

Re: Has anyone see an issue with OMP and uploads of CSS file

Postby asmecher » Mon Jun 17, 2013 2:03 pm

Hi Brian,

The front-end is different, but the back-end tools that identify MIME types in OMP are just the same as used in OJS and OCS. There's a post describing these at http://pkp.sfu.ca/support/forum/viewtopic.php?f=3&t=2892#p10396. The first thing to do is identify which of the 3 methods OJS is using (based on which your server supports), and then debug the specific response it's getting from that detection method.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8345
Joined: Wed Aug 10, 2005 12:56 pm

Re: Has anyone see an issue with OMP and uploads of CSS file

Postby bdgregg » Thu Jun 20, 2013 1:57 pm

Alec,

I've reviewed the link you've sent me and I've tried going over a few things on the server. It seems to be a bug with PHP https://bugs.php.net/bug.php?id=53035&edit=1 as even running via command line returns "text/x-c" instead of the expected "text/css". And just to be clear I'm running Oracle Enterprise Linux (OEL) 6.4 64-bit (a variant of RHEL/CENTOS) with all the current patches applied to the system.

PHP Version:
Code: Select all
#  php -v
PHP 5.3.3 (cli) (built: Feb 22 2013 13:05:52)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies


Using the command line version of 'file' I get the following, however the included script below reports that php is using the mime_content_type function. I've attached the file ompstyle.css as well.

Code: Select all
# file --mime ompstyle.css
ompstyle.css: text/x-c; charset=us-ascii



Script:
Code: Select all
<?php

$mytype = my_mime_content_type("ompstyle.css");
print "Type: $mytype<br>\n";


        /**
         * @see http://ca.php.net/manual/en/function.mime_content_type.php
         */
        function my_mime_content_type($filename) {
                if (function_exists('mime_content_type')) {
                        $result = mime_content_type($filename);
                        // mime_content_type appears to return a charset
                        // (erroneously?) in recent versions of PHP5
                        if (($i = strpos($result, ';')) !== false) {
                                $result = trim(substr($result, 0, $i));
                        }
                        print "Using Function:mime_content_type<br>\n";
                        return $result;
                } elseif (function_exists('finfo_open')) {
                        $fi =& Registry::get('fileInfo', true, null);
                        if ($fi === null) {
                                $fi = finfo_open(FILEINFO_MIME, Config::getVar('finfo', 'mime_database_path'));
                        }
                        if ($fi !== false) {
                                print "Using Function:finfo_open<br>\n";
                                return strtok(finfo_file($fi, $filename), ' ;');
                        }
                }

                // Fall back on an external "file" tool
                $f = escapeshellarg($filename);
                $result = trim(`file --brief --mime $f`);
                // Make sure we just return the mime type.
                if (($i = strpos($result, ';')) !== false) {
                        print "Using Function:file<br>\n";
                        $result = trim(substr($result, 0, $i));
                }
                return $result;
        }

?>


Output:
Code: Select all
# php mimeinfo2.php
Using Function:mime_content_type<br>
Type: text/x-c<br>



Thoughts?
bdgregg
 
Posts: 117
Joined: Wed Sep 15, 2004 8:21 am
Location: University of Pittsburgh

Re: Has anyone see an issue with OMP and uploads of CSS file

Postby asmecher » Thu Jun 20, 2013 2:10 pm

Hi Brian,

The "file" command-line tool isn't part of PHP, it's a standard *NIX tool. You may need to update your MIME magic file, which is the database that tool uses to identify files based on their content.

(There's a chance that the PHP code isn't falling back on the "file" tool if one of the other approaches are available -- it's possible that either mime_content_type or fileinfo are also generating the wrong result.)

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8345
Joined: Wed Aug 10, 2005 12:56 pm

Re: Has anyone see an issue with OMP and uploads of CSS file

Postby bdgregg » Tue Jul 16, 2013 11:03 am

All,

After fighting with the server to determine exactly which method was/was not working I've made the following changes:

1.) Modify the /etc/magic file to include the following (thanks to: http://stackoverflow.com/questions/1249 ... t-text-css):
Code: Select all
0        search/4096    ={
>&0      search/512     =transition-    CSS3
!:mime   text/css

0        search/4096    ={
>&0      search/512     =background:    CSS
!:mime   text/css

0        search/4096    ={
>&0      search/512     =color:         CSS
!:mime   text/css


2.) Modify the omp/lib/pkp/classes/core/String.inc.php file:
Code: Select all
--- String.inc.php.orig 2013-07-16 07:56:30.577252490 -0400
+++ String.inc.php      2013-07-16 07:54:14.939255301 -0400
@@ -366,23 +366,23 @@
         * @see http://ca.php.net/manual/en/function.mime_content_type.php
         */
        function mime_content_type($filename) {
-               if (function_exists('mime_content_type')) {
-                       $result = mime_content_type($filename);
-                       // mime_content_type appears to return a charset
-                       // (erroneously?) in recent versions of PHP5
-                       if (($i = strpos($result, ';')) !== false) {
-                               $result = trim(substr($result, 0, $i));
-                       }
-                       return $result;
-               } elseif (function_exists('finfo_open')) {
-                       $fi =& Registry::get('fileInfo', true, null);
-                       if ($fi === null) {
-                               $fi = finfo_open(FILEINFO_MIME, Config::getVar('finfo', 'mime_database_path'));
-                       }
-                       if ($fi !== false) {
-                               return strtok(finfo_file($fi, $filename), ' ;');
-                       }
-               }
+               #if (function_exists('mime_content_type')) {
+               #       $result = mime_content_type($filename);
+               #       // mime_content_type appears to return a charset
+               #       // (erroneously?) in recent versions of PHP5
+               #       if (($i = strpos($result, ';')) !== false) {
+               #               $result = trim(substr($result, 0, $i));
+               #       }
+               #       return $result;
+               #} elseif (function_exists('finfo_open')) {
+               #       $fi =& Registry::get('fileInfo', true, null);
+               #       if ($fi === null) {
+               #               $fi = finfo_open(FILEINFO_MIME, Config::getVar('finfo', 'mime_database_path'));
+               #       }
+               #       if ($fi !== false) {
+               #               return strtok(finfo_file($fi, $filename), ' ;');
+               #       }
+               #}

                // Fall back on an external "file" tool
                $f = escapeshellarg($filename);


This forces the use of the use of the external command 'file' tool which uses the /etc/magic file to determine the mime type of the file. An alternate was to modify and recompile the /usr/share/misc/magic.mgc file which would be at risk for replacement when a 'yum update' was applied.

This has solved the issue for us as for what ever reason the mime_content_type function always returned 'text/x-c' which was incorrect and caused the software to issue an error and not allow uploading of our custom CSS file.

I hope that this helps someone else as this took a while to track down. In light of this, I feel it would be a welcomed change to allow in the PKP configuration for all OMP/OJS/OCS software the ability to chose which method to use to determine the mime type instead of first checking on the possibly failing/deprecated mime_content_type function.

Thanks,
Brian Gregg.
bdgregg
 
Posts: 117
Joined: Wed Sep 15, 2004 8:21 am
Location: University of Pittsburgh

Re: Has anyone see an issue with OMP and uploads of CSS file

Postby asmecher » Tue Jul 16, 2013 12:22 pm

Hi Brian,

Thanks for all the detail. FYI, since mime_content_type has long been removed and we're dropping PHP4 support, I've committed the change to remove mime_content_type calls. (See http://pkp.sfu.ca/bugzilla/show_bug.cgi?id=8299.)

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 8345
Joined: Wed Aug 10, 2005 12:56 pm

Re: Has anyone see an issue with OMP and uploads of CSS file

Postby JasonNugent » Fri Sep 06, 2013 9:44 am

Hi folks,

Ultimately, the problem here is that there is no accepted mime type for CSS files. There are content types for giving a browser some sort of hint (e.g. type="text/css"), but CSS files are ascii text and tools that examine the contents looking for identifying strings are probably not going to find anything. I just went through this a bit with some recent work on the modifications being made to HTML galleys in OJS.

Brian, your solution will work in your case, because your CSS contains those strings, but unfortunately something more general will be needed. The OJS galley code now examines the file genre which is specified when it is uploaded and corrects the stored mime type just before the file is sent to a browser. This check is performed every time it is viewed. It's not ideal, but it ensures that the MIME type is set correctly. We'll probably need something similar for OMP.

Regards,
Jason
JasonNugent
Site Admin
 
Posts: 849
Joined: Tue Jan 10, 2006 6:20 am


Return to OMP Technical Support

Who is online

Users browsing this forum: No registered users and 1 guest