• Resolved thirzah

    (@thirzah)


    Hello

    I’m not sure how useful this is going to be, but I hit a couple of problems when running the import, so thought I’d share my (hatchet job) fixes. You can probably improve on them ??

    First: Query Parameters
    When a file has a query parameter (e.g. “pic.jpg?w=150&h=23″) the file extension is not picked up.

    Solution: in function handle_import_media_file, after the commented out section

    // this security check is pointless. 
    
    ...
    
    /**/

    I added

    // thirzah. strip query params from file names
    if (strpos($file,"?", 0)>0) {
       $file=substr($file,0,strpos($file,"?", 0));
    }

    Second issue: embedded/inline images

    I wanted to import the base64 data. remove_dot_segments was removing double slashes from the data, so that had to be turned off. And then the data had to be turned into a file ready for import. So to sum up:

    1. Find function “import_images”

    2. Find these lines:

    // intersect base path and src, or just clean up junk
    $imgpath = $this->remove_dot_segments($imgpath);

    3. replace them with

    // intersect base path and src, or just clean up junk
    // thirzah says: please don't muck with base64 stuff
    if (!(strpos($imgpath,"data:image",0)>0)) $imgpath = $this->remove_dot_segments($imgpath);

    4. Find function “handle_import_media_file”

    5. (as per the query string fix, above) find the commented out section that starts/ends

    // this security check is pointless.
    
    ...
    
    /**/

    6. beneath it, add:

    // thirzah says: handle inline data:image stuff (urgh)
    if (strpos($file,"data:image",0)>0) {
    
    list($type, $data) = explode(';', $file);
    $ftype = substr($type,-3,3);
    list(, $data)      = explode(',', $data);
    $data = str_replace(' ', '+', $data);
    $data = str_replace('-', '+', $data);
    $data = str_replace('_', '/', $data);
    
    $data = base64_decode($data);
    
    $file = $uploads['path'] . '/' . uniqid() . '.' . $ftype;
    $success = file_put_contents($file, $data);
    print $success ? $file : '<br/>Unable to save the file.';
    
    }

    https://www.ads-software.com/plugins/import-html-pages/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘couple of image tweaks’ is closed to new replies.