plugins/gallery/fetcher.php
changeset 26 023a21c8f47c
parent 25 d9f37d2ea2cf
child 27 3d8ec1f7d191
equal deleted inserted replaced
25:d9f37d2ea2cf 26:023a21c8f47c
    32   
    32   
    33   // artificial race condition for debug
    33   // artificial race condition for debug
    34   // sleep(5);
    34   // sleep(5);
    35   
    35   
    36   $type = $paths->getParam(0);
    36   $type = $paths->getParam(0);
    37   if ( !in_array($type, array('thumb', 'preview', 'full')) )
    37   if ( !in_array($type, array('thumb', 'preview', 'full', 'embed')) )
    38   {
    38   {
    39     die('Hack attempt');
    39     die('Hack attempt');
    40   }
    40   }
    41   
    41   
    42   $id = intval($paths->getParam(1));
    42   $id = intval($paths->getParam(1));
    85         case 'jpg': case 'jpeg': $mimetype = 'image/jpeg'; break;
    85         case 'jpg': case 'jpeg': $mimetype = 'image/jpeg'; break;
    86         case 'tif': case 'tiff': $mimetype = 'image/tiff'; break;
    86         case 'tif': case 'tiff': $mimetype = 'image/tiff'; break;
    87         default: $mimetype = 'application/octet-stream';
    87         default: $mimetype = 'application/octet-stream';
    88       }
    88       }
    89       break;
    89       break;
       
    90     case 'embed':
       
    91       if ( !isset($_GET['width']) || !isset($_GET['height']) )
       
    92       {
       
    93         die('Missing width or height.');
       
    94       }
       
    95       $src_filename  = ENANO_ROOT . '/files/' . $row['img_filename'];
       
    96       $dest_filename = ENANO_ROOT . '/cache/' . $row['img_filename'] . "-embed-$width-$height.$ext";
       
    97       $filename =& $dest_filename;
       
    98       $ext = get_file_extension($filename);
       
    99       
       
   100       $width = intval($_GET['width']);
       
   101       $height = intval($_GET['height']);
       
   102       if ( empty($width) || empty($height) || $width > 2048 || $height > 2048 )
       
   103       {
       
   104         die('Bad width or height');
       
   105       }
       
   106       
       
   107       if ( !file_exists($dest_filename) )
       
   108       {
       
   109         if ( !scale_image($src_filename, $dest_filename, $width, $height, false) )
       
   110         {
       
   111           die('Image scaling process failed.');
       
   112         }
       
   113       }
       
   114       
       
   115       break;
    90     default:
   116     default:
    91       die('PHP...insane...');
   117       die('PHP...insane...');
    92       break;
   118       break;
    93   }
   119   }
    94   
   120