class Pman_Cms_PageThumb extends Pman
{
- function get($id)
+ function get($id = '', $opts = array())
{
$cms_page = DB_DataObject::factory('cms_page');
$cms_page->autoJoin();
+ $file_broken = realpath('Pman/templates/images/file-broken.png');
+
if(empty($id) || !$cms_page->get($id)){
- $this->jerr('Invalid Page');
-// header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
-// urlencode("no images for that item: " . htmlspecialchars($id)));
+ $this->serve($file_broken);
}
if ($cms_page->page_type_id_name == 'element') {
$cms_page = $cms_page->parent();
}
- if($cms_page->page_type_id_name == 'page'){
- $this->jerr('Can not handle this type');
+ if($cms_page->page_type_id_name != 'page'){
+ $this->serve($file_broken);
}
$opts = HTML_FlexyFramework::get()->Pman_Cms;
if (!isset($opts['basePHP'])) {
- $this->jerr(" Pman_Cms[basePHP] is not set ");
+ $this->serve($file_broken);
}
$basePHP = $opts['basePHP'];
$strip = 0;
- $pl = $this->page_link;
+ $pl = $cms_page->page_link;
if (is_array($opts['basePHP'])) {
foreach($opts['basePHP'] as $k=>$v) {
if ($k == substr($pl,0, strlen($k))) {
}
}
if (!$matched) {
- $this->jerr(" page link does not match any configured site.");
+ $this->serve($file_broken);
}
}
$file = $cms_page->getStoreName();
- if(file_exists($file) && strtotime($this->updated) < filemtime($file)){
+ if(file_exists($file) && strtotime($cms_page->updated) < filemtime($file)){
$this->serve($file);
}
$conv = System::which('wkhtmltoimage');
if (!$conv) {
- $roo->jerr("missing wkhtmltoimage");
+ $this->jerr("missing wkhtmltoimage");
}
$xvfb = System::which('xvfb-run');
if (!$xvfb) {
- $roo->jerr("missing xvfb-run");
+ $this->jerr("missing xvfb-run");
}
$cmd = $xvfb . ' --auto-servernum ' . $conv .
exec($cmd);
if(!file_exists($file)){
- $roo->jerr('Fail to make preview image');
+ $this->serve($file_broken);
}
$this->serve($file);
exit;
}
+
+ function serve($file)
+ {
+ $this->sessionState(0);
+
+ require_once 'File/Convert.php';
+
+ $fc = new File_Convert($file, 'image/png');
+
+ $fc->convert('image/png');
+
+ $fc->serve('inline');
+
+ exit;
+
+ }
}
\ No newline at end of file