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)){
-
- $roo->jdata(array(
- 'file' => $file,
- 'url' => $url,
- 'base64' => base64_encode(file_get_contents($file))
- ));
+ if(file_exists($file) && strtotime($cms_page->updated) < filemtime($file)){
+ $this->serve($file);
}
+
require_once 'System.php';
$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 .
' --width 300 --height 300 --zoom 0.3 --disable-smart-width --enable-javascript --javascript-delay 1000 ' .
escapeshellarg($url) . ' ' .escapeshellarg($file);
- ///echo $cmd;exit;
exec($cmd);
if(!file_exists($file)){
- $roo->jerr('Fail to make preview image');
+ $this->serve($file_broken);
}
- $roo->jdata(array(
- 'file' => $file,
- 'url' => $url,
- 'base64' => base64_encode(file_get_contents($file))
- ));
+ $this->serve($file);
exit;
- /*
- require_once 'Pman/Cms/Preview.php';
-
- $p = new Pman_Cms_Preview();
- // set up the basic params..
- $p->rootURL = $roo->rootURL;
- $p->baseURL = $roo->rootURL . '/'. $opts['basePHP'] ;
- $p->loadPage('Site'); // loads any blocks from site.
- $p->loadPage('Site/*'); // loads any blocks from site.
- $p->loadPage('Home'); // loads any blocks from site.
-
- $p->page = $p->loadPage($this->page_link);
+ }
+
+ function serve($file)
+ {
+ $this->sessionState(0);
+ require_once 'File/Convert.php';
- $fo = &PEAR::getStaticProperty('HTML_Template_Flexy', 'options');
+ $fc = new File_Convert($file, 'image/png');
- $fo['templateDir'] = $opts['templateDir'];
- $fo['forceCompile'] = true;
- if (isset($opts['url_rewrite'])) {
- $fo['url_rewrite'] = $opts['url_rewrite'];
- }
+ $fc->convert('image/png');
+ $fc->serve('inline');
- $p->output();
exit;
- */
-
-
-
}
}
\ No newline at end of file