X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FImages.php;h=10c92f198cc46559e778b089e4c44591d0d4ebc7;hp=21731b9124e3a17940291d9d52b2fb0429cf2764;hb=0240d255376ca95b458e45be50e071ffd6a0e759;hpb=dc87fea31701f7f43c6afab936f29c1c6de63add diff --git a/DataObjects/Images.php b/DataObjects/Images.php index 21731b91..10c92f19 100644 --- a/DataObjects/Images.php +++ b/DataObjects/Images.php @@ -131,7 +131,9 @@ class Pman_Core_DataObjects_Images extends DB_DataObject } } - $this->getNumberOfPages($file); + if($this->mimetype == 'application/pdf'){ + $this->no_of_pages = $this->getPdfPages($file); + } $this->filesize = filesize($file); $this->created = date('Y-m-d H:i:s'); @@ -183,6 +185,7 @@ class Pman_Core_DataObjects_Images extends DB_DataObject { $opts = HTML_FlexyFramework::get()->Pman; $fn = preg_replace('/[^a-z0-9\.]+/i', '_', $this->filename); + print_r($opts);exit; return implode( '/', array( $opts['storedir'], '_images_', date('Y/m', strtotime($this->created)), $this->id . '-'. $fn )); @@ -767,6 +770,10 @@ class Pman_Core_DataObjects_Images extends DB_DataObject $this->filesize = filesize($f); + if($this->mimetype == 'application/pdf'){ + $this->no_of_pages = $this->getPdfPages($f); + } + $this->update($o); return true; @@ -792,50 +799,34 @@ class Pman_Core_DataObjects_Images extends DB_DataObject return $base64; } - function getNumberOfPages() + function getPdfPages($file) { - $ret = false; - require_once 'System.php'; - $file = $this->getStoreName(); - - if(!file_exists($file)){ - return false; + $page = 0; + + $pdfinfo = System::which('pdfinfo'); + + if (!file_exists($file) || empty($pdfinfo)) { + return $page; } - - switch ($this->mimetype) { - - case 'application/pdf' : - - $pdftk = System::which('pdftk'); - - if (empty($pdftk)) { - return false; - } - - $cmd = "{$pdftk} {$file} dump_data"; - - $info = `$cmd`; - - $infos = explode("\n", $info); + + $cmd = "{$pdfinfo} {$file}"; - foreach ($infos as $i){ - - if(!preg_match('/^NumberOfPages: ([0-9]+)/', $i, $matches)){ - continue; - } - - $ret = (empty($matches[1])) ? false : $matches[1]; - break; - } - - break; - default : - break; + $ret = `$cmd`; + + $info = explode("\n", $ret); + + foreach ($info as $i){ + + if(!preg_match('/^Pages:[\s]*([0-9]+)/', $i, $matches)){ + continue; + } + + $page = (empty($matches[1])) ? 0 : $matches[1]; } - return $ret; + return $page; } }