Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This is class in develop - need some clear in functions but generating image works well, be welcome
- * improve it.
- * You need GhostScript > 9.0
- * The plugin is an extension of <var>TextObject</var>. For more details see the <i>class-textobject</i> plugin.
- *
- * @author Michal Mewald (mlodszy)
- * @package plugins
- * @subpackage media
- *
- */
- $plugin_is_filter = 9|CLASS_PLUGIN;
- $plugin_description = gettext('Provides a support for PDF, EPS, AI files.');
- $plugin_author = "Michal Mewald (based on EXTdocs Stephen Billard (sbillard))";
- $option_interface = 'EXTdocs_Options';
- if (getOption('EXTdocs_pdf_provider')) {
- addPluginType('pdf', 'EXTdocs');
- }
- if (getOption('EXTdocs_tif_provider')) {
- addPluginType('tif', 'EXTdocs');
- addPluginType('tiff', 'EXTdocs');
- }
- if (getOption('EXTdocs_eps_provider')) {
- addPluginType('eps', 'EXTdocs');
- }
- if (getOption('EXTdocs_ai_provider')) {
- addPluginType('ai', 'EXTdocs');
- }
- if (getOption('EXTdocs_rar_provider')) {
- addPluginType('rar', 'EXTdocs');
- }
- if (getOption('EXTdocs_zip_provider')) {
- addPluginType('zip', 'EXTdocs');
- }
- if (getOption('EXTdocs_psd_provider')) {
- addPluginType('psd', 'EXTdocs');
- }
- /**
- * Option class for textobjects objects
- *
- */
- class EXTdocs_Options {
- function EXTdocs_Options() {
- setOptionDefault('EXTdocs_pdf_provider', 'local');
- setOptionDefault('EXTdocs_tif_provider', 'local');
- setOptionDefault('EXTdocs_eps_provider', 'local');
- setOptionDefault('EXTdocs_ai_provider', 'local');
- setOptionDefault('EXTdocs_rar_provider', 'local');
- setOptionDefault('EXTdocs_zip_provider', 'local');
- setOptionDefault('EXTdocs_psd_provider', 'local');
- }
- /**
- * Standard option interface
- *
- * @return array
- */
- function getOptionsSupported() {
- return array( gettext('Watermark default images') => array ('key' => 'EXTdocs_watermark_default_images', 'type' => OPTION_TYPE_CHECKBOX,
- 'desc' => gettext('Check to place watermark image on default thumbnail images.')),
- gettext('PDF') => array('key' => 'EXTdocs_pdf_provider', 'type' => OPTION_TYPE_RADIO,
- 'buttons' => array( gettext('Disabled')=>'',
- gettext('GoogleDocs')=>'google',
- gettext('Zoho')=>'zoho',
- gettext('Browser default')=>'local'
- ),
- 'desc' => gettext("Choose the WEB service to use for rendering pdf documents.").
- '<p>'.sprintf(gettext('Select <em>google</em> to use the <a href="%s">GoogleDocs viewer</a>'),'http://docs.google.com/viewer').'</p>'.
- '<p>'.sprintf(gettext('Select <em>zoho</em> to use the <a href="%s">Zoho document viewer</a>'),'http://viewer.zoho.com/home.do').'</p>'.
- '<p>'.gettext('Select <em>Browser default</em> to use the your browser default application').'</p>'
- ),
- gettext('Tiff') => array('key' => 'EXTdocs_tif_provider', 'type' => OPTION_TYPE_RADIO,
- 'buttons' => array( gettext('Disabled')=>'',
- gettext('Zoho')=>'zoho',
- gettext('Browser default')=>'local'
- ),
- 'desc' => gettext("Choose the WEB service to use for rendering TIFF images.")),
- gettext('EPS') => array('key' => 'EXTdocs_eps_provider', 'type' => OPTION_TYPE_RADIO,
- 'buttons' => array( gettext('Disabled')=>'',
- gettext('GoogleDocs')=>'google',
- gettext('Browser default')=>'local'
- ),
- 'desc' => gettext("Choose the WEB service to use for rendering EPS images.")),
- gettext('AI') => array('key' => 'EXTdocs_ai_provider', 'type' => OPTION_TYPE_RADIO,
- 'buttons' => array( gettext('Disabled')=>'',
- gettext('GoogleDocs')=>'google',
- gettext('Browser default')=>'local'
- ),
- 'desc' => gettext("Choose the WEB service to use for rendering AI images.")),
- gettext('RAR') => array('key' => 'EXTdocs_rar_provider', 'type' => OPTION_TYPE_RADIO,
- 'buttons' => array( gettext('Disabled')=>'',
- gettext('GoogleDocs')=>'google',
- gettext('Browser default')=>'local'
- ),
- 'desc' => gettext("Choose the WEB service to use for rendering AI images.")),
- gettext('ZIP') => array('key' => 'EXTdocs_zip_provider', 'type' => OPTION_TYPE_RADIO,
- 'buttons' => array( gettext('Disabled')=>'',
- gettext('GoogleDocs')=>'google',
- gettext('Browser default')=>'local'
- ),
- 'desc' => gettext("Choose the WEB service to use for rendering AI images.")),
- gettext('PSD') => array('key' => 'EXTdocs_psd_provider', 'type' => OPTION_TYPE_RADIO,
- 'buttons' => array( gettext('Disabled')=>'',
- gettext('GoogleDocs')=>'google',
- gettext('Browser default')=>'local'
- ),
- 'desc' => gettext("Choose the WEB service to use for rendering AI images."))
- );
- }
- }
- require_once(dirname(__FILE__).'/class-textobject/class-textobject_core.php');
- class EXTdocs extends TextObject {
- /**
- * creates a EXTdocs (image standin)
- *
- * @param object $album the owner album
- * @param string $filename the filename of the text file
- * @return TextObject
- */
- function __construct($album, $filename, $quiet=false) {
- $this->watermark = getOption('EXTdocs_watermark');
- $this->watermarkDefault = getOption('EXTdocs_watermark_default_images');
- $this->common_instantiate($album,$filename,$quiet);
- }
- /**
- * Returns the image file name for the thumbnail image.
- *
- * @param string $path override path
- *
- * @return s
- */
- function getThumbImageFile($path=NULL) {
- global $_zp_gallery;
- if (is_null($path)) {
- $path = SERVERPATH;
- }
- if (is_null($this->objectsThumb)) {
- switch(getSuffix($this->filename)) {
- case "pdf":
- case "eps":
- case 'ai':
- case 'tif':
- case 'tiff':
- case 'zip':
- case 'rar':
- case 'psd':
- $img = '/tifDefault.png';
- break;
- }
- $imgfile = $path . '/' . THEMEFOLDER . '/' . internalToFilesystem($_zp_gallery->getCurrentTheme()) . '/images/'.$img;
- if (!file_exists($imgfile)) {
- $imgfile = $path . "/" . ZENFOLDER . '/'.PLUGIN_FOLDER .'/'. substr(basename(__FILE__), 0, -4). '/'.$img;
- return $imgfile;
- }
- }
- else {
- $imgfile = ALBUM_FOLDER_SERVERPATH.internalToFilesystem($this->album->name).'/'.$this->objectsThumb;
- return $imgfile;
- }
- }
- /**
- * Returns the content of the text file
- *
- * @param int $w optional width
- * @param int $h optional height
- * @return string
- */
- function getBody($w=NULL, $h=NULL) {
- $this->updateDimensions();
- if (is_null($w)) $w = $this->getWidth();
- if (is_null($h)) $h = $this->getHeight();
- $path_file = $this->getFullImage();
- $filename = $_SERVER['DOCUMENT_ROOT'].$path_file;
- $filename_gs = str_replace(" ", "\ ", $filename);
- $filename_md5 = $filename.".".md5_file($filename);
- $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';
- $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';
- $cmdtif = 'convert '.$filename_gs.' -quiet -quality 85 -colorspace RGB -geometry 640 '.substr($filename_gs, 0, -4).'.jpg';
- $cmdtiff = 'convert '.$filename_gs.' -quiet -quality 85 -colorspace RGB -geometry 640 '.substr($filename_gs, 0, -5).'.jpg';
- $providers = array( ''=>'<img src="'.pathurlencode($this->getThumb()).'">',
- 'google'=>'<iframe src="http://docs.google.com/viewer?url=%s&embedded=true" width="'.$w.'px" height="'.$h.'px" frameborder="0" border="none" scrolling="auto"></iframe>',
- 'zoho'=>'<iframe src="http://viewer.zoho.com/api/urlview.do?url=%s&embed=true" width="'.$w.'px" height="'.$h.'px" frameborder="0" border="none" scrolling="auto"></iframe>',
- 'local'=>'<iframe src="%s" width="'.$w.'px" height="'.$h.'px" frameborder="0" border="none" scrolling="auto"></iframe>'
- );
- switch($suffix = getSuffix($this->filename)) {
- case 'tiff':
- // Sprawdzanie sumy, generowanie pliku
- if (!file_exists($filename_md5)) {
- // Usuwamy starą sume
- foreach (glob("$filename.*") as $list_file) {
- unlink($list_file);
- }
- // Tworzymy sume
- $filename_md5_create = fopen($filename_md5, 'w') or die ("can't open file");
- fclose($filename_md5_create);
- // Tworzenie podgladu
- exec($cmdtiff, $output);
- }
- // Na wszelki wypadek
- if (!file_exists(substr($path_file, 0, -5).'.jpg')) {
- exec($cmdtiff, $output);
- }
- return '<img src="'.substr($path_file, 0, -5).'.jpg">';
- break;
- case 'pdf':
- // Sprawdzanie sumy, generowanie pliku
- if (!file_exists($filename_md5)) {
- // Usuwamy starą sume
- foreach (glob("$filename.*") as $list_file) {
- unlink($list_file);
- }
- // Tworzymy sume
- $filename_md5_create = fopen($filename_md5, 'w') or die ("can't open file");
- fclose($filename_md5_create);
- // Tworzenie podgladu
- exec($cmdpdf, $output);
- }
- // Na wszelki wypadek
- if (!file_exists(substr($path_file, 0, -4).'.jpg')) {
- exec($cmdpdf, $output);
- }
- return '<img src="'.substr($path_file, 0, -4).'.jpg">';
- break;
- case 'eps':
- // Sprawdzanie sumy, generowanie pliku
- if (!file_exists($filename_md5)) {
- // Usuwamy starą sume
- foreach (glob("$filename.*") as $list_file) {
- unlink($list_file);
- }
- // Tworzymy sume
- $filename_md5_create = fopen($filename_md5, 'w') or die ("can't open file");
- fclose($filename_md5_create);
- // Tworzenie podgladu
- exec($cmdeps, $output);
- }
- // Na wszelki wypadek
- if (!file_exists(substr($path_file, 0, -4).'.jpg')) {
- exec($cmdeps, $output);
- }
- return '<img src="'.substr($path_file, 0, -4).'.jpg">';
- break;
- case 'tif':
- // Sprawdzanie sumy, generowanie pliku
- if (!file_exists($filename_md5)) {
- // Usuwamy starą sume
- foreach (glob("$filename.*") as $list_file) {
- unlink($list_file);
- }
- // Tworzymy sume
- $filename_md5_create = fopen($filename_md5, 'w') or die ("can't open file");
- fclose($filename_md5_create);
- // Tworzenie podgladu
- exec($cmdtif, $output);
- }
- // Na wszelki wypadek
- if (!file_exists(substr($path_file, 0, -4).'.jpg')) {
- exec($cmdtif, $output);
- }
- return '<img src="'.substr($path_file, 0, -4).'.jpg">';
- break;
- case 'pps':
- case 'ai':
- case 'zip':
- case 'rar':
- case 'psd':
- $provider = 'EXTdocs_'.$suffix.'_provider';
- return sprintf($providers[getOption($provider)],html_encode($this->getFullImage(FULLWEBPATH)));
- default: // just in case we extend and are lazy...
- return '<img src="'.pathurlencode($this->getThumb()).'">';
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement