Advertisement
mlodszy

Untitled

May 23rd, 2013
5,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.45 KB | None | 0 0
  1. <?php
  2. /**
  3.  * This is class in develop - need some clear in functions but generating image works well, be welcome
  4.  * improve it.
  5.  * You need GhostScript > 9.0
  6.  * The plugin is an extension of <var>TextObject</var>. For more details see the <i>class-textobject</i> plugin.
  7.  *
  8.  * @author Michal Mewald (mlodszy)
  9.  * @package plugins
  10.  * @subpackage media
  11.  *
  12.  */
  13.  
  14. $plugin_is_filter = 9|CLASS_PLUGIN;
  15. $plugin_description = gettext('Provides a support for PDF, EPS, AI files.');
  16. $plugin_author = "Michal Mewald (based on EXTdocs Stephen Billard (sbillard))";
  17.  
  18.  
  19. $option_interface = 'EXTdocs_Options';
  20.  
  21. if (getOption('EXTdocs_pdf_provider')) {
  22.     addPluginType('pdf', 'EXTdocs');
  23. }
  24. if (getOption('EXTdocs_tif_provider')) {
  25.     addPluginType('tif', 'EXTdocs');
  26.     addPluginType('tiff', 'EXTdocs');
  27. }
  28. if (getOption('EXTdocs_eps_provider')) {
  29.     addPluginType('eps', 'EXTdocs');
  30. }
  31. if (getOption('EXTdocs_ai_provider')) {
  32.     addPluginType('ai', 'EXTdocs');
  33. }
  34. if (getOption('EXTdocs_rar_provider')) {
  35.     addPluginType('rar', 'EXTdocs');
  36. }
  37. if (getOption('EXTdocs_zip_provider')) {
  38.     addPluginType('zip', 'EXTdocs');
  39. }
  40. if (getOption('EXTdocs_psd_provider')) {
  41.     addPluginType('psd', 'EXTdocs');
  42. }
  43.  
  44.  
  45. /**
  46.  * Option class for textobjects objects
  47.  *
  48.  */
  49. class EXTdocs_Options {
  50.  
  51.     function EXTdocs_Options() {
  52.         setOptionDefault('EXTdocs_pdf_provider', 'local');
  53.         setOptionDefault('EXTdocs_tif_provider', 'local');
  54.         setOptionDefault('EXTdocs_eps_provider', 'local');
  55.         setOptionDefault('EXTdocs_ai_provider', 'local');
  56.         setOptionDefault('EXTdocs_rar_provider', 'local');
  57.         setOptionDefault('EXTdocs_zip_provider', 'local');
  58.         setOptionDefault('EXTdocs_psd_provider', 'local');
  59.     }
  60.  
  61.     /**
  62.      * Standard option interface
  63.      *
  64.      * @return array
  65.      */
  66.     function getOptionsSupported() {
  67.         return array(   gettext('Watermark default images') => array ('key' => 'EXTdocs_watermark_default_images', 'type' => OPTION_TYPE_CHECKBOX,
  68.                                                                     'desc' => gettext('Check to place watermark image on default thumbnail images.')),
  69.                                     gettext('PDF') => array('key' => 'EXTdocs_pdf_provider', 'type' => OPTION_TYPE_RADIO,
  70.                                                                     'buttons' => array( gettext('Disabled')=>'',
  71.                                                                                                             gettext('GoogleDocs')=>'google',
  72.                                                                                                             gettext('Zoho')=>'zoho',
  73.                                                                                                             gettext('Browser default')=>'local'
  74.                                                                                                             ),
  75.                                                                     'desc' => gettext("Choose the WEB service to use for rendering pdf documents.").
  76.                                                                                                                 '<p>'.sprintf(gettext('Select <em>google</em> to use the <a href="%s">GoogleDocs viewer</a>'),'http://docs.google.com/viewer').'</p>'.
  77.                                                                                                                 '<p>'.sprintf(gettext('Select <em>zoho</em> to use the <a href="%s">Zoho document viewer</a>'),'http://viewer.zoho.com/home.do').'</p>'.
  78.                                                                                                                 '<p>'.gettext('Select <em>Browser default</em> to use the your browser default application').'</p>'
  79.                                                                                             ),
  80.                                     gettext('Tiff') => array('key' => 'EXTdocs_tif_provider', 'type' => OPTION_TYPE_RADIO,
  81.                                                                     'buttons' => array( gettext('Disabled')=>'',
  82.                                                                                                             gettext('Zoho')=>'zoho',
  83.                                                                                                             gettext('Browser default')=>'local'
  84.                                                                                                             ),
  85.                                                                     'desc' => gettext("Choose the WEB service to use for rendering TIFF images.")),
  86.                                     gettext('EPS')  =>  array('key' =>  'EXTdocs_eps_provider', 'type'  => OPTION_TYPE_RADIO,
  87.                                                                     'buttons' => array( gettext('Disabled')=>'',
  88.                                                                                                             gettext('GoogleDocs')=>'google',
  89.                                                                                                             gettext('Browser default')=>'local'
  90.                                                                                                             ),
  91.                                                                     'desc' => gettext("Choose the WEB service to use for rendering EPS images.")),
  92.                                     gettext('AI')   =>  array('key' =>  'EXTdocs_ai_provider', 'type'   => OPTION_TYPE_RADIO,
  93.                                                                     'buttons' => array( gettext('Disabled')=>'',
  94.                                                                                                             gettext('GoogleDocs')=>'google',
  95.                                                                                                             gettext('Browser default')=>'local'
  96.                                                                                                             ),
  97.                                                                     'desc' => gettext("Choose the WEB service to use for rendering AI images.")),
  98.                                     gettext('RAR')  =>  array('key' =>  'EXTdocs_rar_provider', 'type'  => OPTION_TYPE_RADIO,
  99.                                                                     'buttons' => array( gettext('Disabled')=>'',
  100.                                                                                                             gettext('GoogleDocs')=>'google',
  101.                                                                                                             gettext('Browser default')=>'local'
  102.                                                                                                             ),
  103.                                                                     'desc' => gettext("Choose the WEB service to use for rendering AI images.")),
  104.                                     gettext('ZIP')  =>  array('key' =>  'EXTdocs_zip_provider', 'type'  => OPTION_TYPE_RADIO,
  105.                                                                     'buttons' => array( gettext('Disabled')=>'',
  106.                                                                                                             gettext('GoogleDocs')=>'google',
  107.                                                                                                             gettext('Browser default')=>'local'
  108.                                                                                                             ),
  109.                                                                     'desc' => gettext("Choose the WEB service to use for rendering AI images.")),
  110.                                     gettext('PSD')  =>  array('key' =>  'EXTdocs_psd_provider', 'type'  => OPTION_TYPE_RADIO,
  111.                                                                     'buttons' => array( gettext('Disabled')=>'',
  112.                                                                                                             gettext('GoogleDocs')=>'google',
  113.                                                                                                             gettext('Browser default')=>'local'
  114.                                                                                                             ),
  115.                                                                     'desc' => gettext("Choose the WEB service to use for rendering AI images."))
  116.                     );
  117.     }
  118.  
  119. }
  120.  
  121. require_once(dirname(__FILE__).'/class-textobject/class-textobject_core.php');
  122.  
  123. class EXTdocs extends TextObject {
  124.  
  125.     /**
  126.      * creates a EXTdocs (image standin)
  127.      *
  128.      * @param object $album the owner album
  129.      * @param string $filename the filename of the text file
  130.      * @return TextObject
  131.      */
  132.     function __construct($album, $filename, $quiet=false) {
  133.  
  134.         $this->watermark = getOption('EXTdocs_watermark');
  135.         $this->watermarkDefault = getOption('EXTdocs_watermark_default_images');
  136.  
  137.         $this->common_instantiate($album,$filename,$quiet);
  138.  
  139.     }
  140.  
  141.     /**
  142.      * Returns the image file name for the thumbnail image.
  143.      *
  144.      * @param string $path override path
  145.      *
  146.      * @return s
  147.      */
  148.     function getThumbImageFile($path=NULL) {
  149.         global $_zp_gallery;
  150.         if (is_null($path)) {
  151.             $path = SERVERPATH;
  152.         }
  153.         if (is_null($this->objectsThumb)) {
  154.             switch(getSuffix($this->filename)) {
  155.                 case "pdf":
  156.                 case "eps":
  157.                 case 'ai':
  158.                 case 'tif':
  159.                 case 'tiff':
  160.                 case 'zip':
  161.                 case 'rar':
  162.                 case 'psd':
  163.                     $img = '/tifDefault.png';
  164.                     break;
  165.             }
  166.  
  167.             $imgfile = $path . '/' . THEMEFOLDER . '/' . internalToFilesystem($_zp_gallery->getCurrentTheme()) . '/images/'.$img;
  168.             if (!file_exists($imgfile)) {
  169.                 $imgfile = $path . "/" . ZENFOLDER . '/'.PLUGIN_FOLDER .'/'. substr(basename(__FILE__), 0, -4). '/'.$img;
  170.                 return $imgfile;
  171.             }
  172.         }
  173.  
  174.         else {
  175.             $imgfile = ALBUM_FOLDER_SERVERPATH.internalToFilesystem($this->album->name).'/'.$this->objectsThumb;
  176.             return $imgfile;
  177.             }
  178.  
  179.     }
  180.  
  181.     /**
  182.      * Returns the content of the text file
  183.      *
  184.      * @param int $w optional width
  185.      * @param int $h optional height
  186.      * @return string
  187.      */
  188.     function getBody($w=NULL, $h=NULL) {
  189.         $this->updateDimensions();
  190.         if (is_null($w)) $w = $this->getWidth();
  191.         if (is_null($h)) $h = $this->getHeight();
  192.  
  193.         $path_file = $this->getFullImage();
  194.         $filename = $_SERVER['DOCUMENT_ROOT'].$path_file;
  195.         $filename_gs = str_replace(" ", "\ ", $filename);
  196.         $filename_md5 = $filename.".".md5_file($filename);
  197.  
  198.         $cmdpdf = 'gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -dJPEGQ=85 -sDEVICE=jpeg -dTextAlphaBits=4 -sOutputFile='.substr($filename_gs, 0, -4).'.jpg '.$filename_gs.' 2>/dev/null';
  199.         $cmdeps = 'gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -dJPEGQ=85 -dEPSCrop -dEPSFitPage -sDEVICE=jpeg -dTextAlphaBits=4 -sOutputFile='.substr($filename_gs, 0, -4).'.jpg '.$filename_gs.' 2>/dev/null';
  200.         $cmdtif = 'convert '.$filename_gs.' -quiet -quality 85 -colorspace RGB -geometry 640 '.substr($filename_gs, 0, -4).'.jpg';
  201.         $cmdtiff = 'convert '.$filename_gs.' -quiet -quality 85 -colorspace RGB -geometry 640 '.substr($filename_gs, 0, -5).'.jpg';
  202.  
  203.         $providers = array( ''=>'<img src="'.pathurlencode($this->getThumb()).'">',
  204.                                                 'google'=>'<iframe src="http://docs.google.com/viewer?url=%s&amp;embedded=true" width="'.$w.'px" height="'.$h.'px" frameborder="0" border="none" scrolling="auto"></iframe>',
  205.                                                 'zoho'=>'<iframe src="http://viewer.zoho.com/api/urlview.do?url=%s&amp;embed=true" width="'.$w.'px" height="'.$h.'px" frameborder="0" border="none" scrolling="auto"></iframe>',
  206.                                                 'local'=>'<iframe src="%s" width="'.$w.'px" height="'.$h.'px" frameborder="0" border="none" scrolling="auto"></iframe>'
  207.                                             );
  208.         switch($suffix = getSuffix($this->filename)) {
  209.             case 'tiff':
  210.                 // Sprawdzanie sumy, generowanie pliku
  211.                 if (!file_exists($filename_md5)) {
  212.                     // Usuwamy starą sume
  213.                     foreach (glob("$filename.*") as $list_file) {
  214.                         unlink($list_file);
  215.                     }
  216.                     // Tworzymy sume
  217.                     $filename_md5_create = fopen($filename_md5, 'w') or die ("can't open file");
  218.                     fclose($filename_md5_create);
  219.                     // Tworzenie podgladu
  220.                     exec($cmdtiff, $output);
  221.                     }
  222.                 // Na wszelki wypadek
  223.                 if (!file_exists(substr($path_file, 0, -5).'.jpg')) {
  224.                     exec($cmdtiff, $output);
  225.                 }
  226.                 return '<img src="'.substr($path_file, 0, -5).'.jpg">';
  227.                 break;
  228.             case 'pdf':
  229.                 // Sprawdzanie sumy, generowanie pliku
  230.                 if (!file_exists($filename_md5)) {
  231.                     // Usuwamy starą sume
  232.                     foreach (glob("$filename.*") as $list_file) {
  233.                         unlink($list_file);
  234.                     }
  235.                     // Tworzymy sume
  236.                     $filename_md5_create = fopen($filename_md5, 'w') or die ("can't open file");
  237.                     fclose($filename_md5_create);
  238.             // Tworzenie podgladu
  239.                     exec($cmdpdf, $output);
  240.                     }
  241.                 // Na wszelki wypadek
  242.                 if (!file_exists(substr($path_file, 0, -4).'.jpg')) {
  243.                     exec($cmdpdf, $output);
  244.                 }
  245.  
  246.                 return '<img src="'.substr($path_file, 0, -4).'.jpg">';
  247.                 break;
  248.             case 'eps':
  249.                 // Sprawdzanie sumy, generowanie pliku
  250.                 if (!file_exists($filename_md5)) {
  251.                     // Usuwamy starą sume
  252.                     foreach (glob("$filename.*") as $list_file) {
  253.                         unlink($list_file);
  254.                     }
  255.                     // Tworzymy sume
  256.                     $filename_md5_create = fopen($filename_md5, 'w') or die ("can't open file");
  257.                     fclose($filename_md5_create);
  258.             // Tworzenie podgladu
  259.                     exec($cmdeps, $output);
  260.                     }
  261.                 // Na wszelki wypadek
  262.                 if (!file_exists(substr($path_file, 0, -4).'.jpg')) {
  263.                     exec($cmdeps, $output);
  264.                 }
  265.                 return '<img src="'.substr($path_file, 0, -4).'.jpg">';
  266.                 break;
  267.             case 'tif':
  268.                 // Sprawdzanie sumy, generowanie pliku
  269.                 if (!file_exists($filename_md5)) {
  270.                     // Usuwamy starą sume
  271.                     foreach (glob("$filename.*") as $list_file) {
  272.                         unlink($list_file);
  273.                     }
  274.                     // Tworzymy sume
  275.                     $filename_md5_create = fopen($filename_md5, 'w') or die ("can't open file");
  276.                     fclose($filename_md5_create);
  277.             // Tworzenie podgladu
  278.                     exec($cmdtif, $output);
  279.                     }
  280.                 // Na wszelki wypadek
  281.                 if (!file_exists(substr($path_file, 0, -4).'.jpg')) {
  282.                     exec($cmdtif, $output);
  283.                 }
  284.                 return '<img src="'.substr($path_file, 0, -4).'.jpg">';
  285.                 break;
  286.             case 'pps':
  287.             case 'ai':
  288.             case 'zip':
  289.             case 'rar':
  290.             case 'psd':
  291.                 $provider = 'EXTdocs_'.$suffix.'_provider';
  292.                 return sprintf($providers[getOption($provider)],html_encode($this->getFullImage(FULLWEBPATH)));
  293.             default: // just in case we extend and are lazy...
  294.                 return '<img src="'.pathurlencode($this->getThumb()).'">';
  295.         }
  296.     }
  297.  
  298.  
  299. }
  300.  
  301. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement