3 require_once 'Pman.php';
5 class Pman_Cms_PageThumb extends Pman
9 $this->jerr('Invalid Page');
10 $cms_page = DB_DataObject::factory('cms_page');
11 $cms_page->autoJoin();
13 if(empty($id) || !$cms_page->get($id)){
14 $this->jerr('Invalid Page');
15 // header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
16 // urlencode("no images for that item: " . htmlspecialchars($id)));
19 if ($cms_page->page_type_id_name == 'element') {
20 $cms_page = $cms_page->parent();
23 if($cms_page->page_type_id_name != 'page'){
24 $this->jerr('Can not handle this type');
27 $opts = HTML_FlexyFramework::get()->Pman_Cms;
29 if (!isset($opts['basePHP'])) {
30 $this->jerr(" Pman_Cms[basePHP] is not set ");
33 $basePHP = $opts['basePHP'];
36 $pl = $cms_page->page_link;
37 if (is_array($opts['basePHP'])) {
38 foreach($opts['basePHP'] as $k=>$v) {
39 if ($k == substr($pl,0, strlen($k))) {
40 $pl = substr($pl, strlen($k)+1);
47 $this->jerr(" page link does not match any configured site.");
63 $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
65 $url = $protocol . $_SERVER['HTTP_HOST'] . $this->rootURL .'/'. $basePHP . $pl;
67 $file = $cms_page->getStoreName();
69 if(file_exists($file) && strtotime($cms_page->updated) < filemtime($file)){
73 require_once 'System.php';
75 $conv = System::which('wkhtmltoimage');
78 $this->jerr("missing wkhtmltoimage");
81 $xvfb = System::which('xvfb-run');
84 $this->jerr("missing xvfb-run");
87 $cmd = $xvfb . ' --auto-servernum ' . $conv .
88 ' --width 300 --height 300 --zoom 0.3 --disable-smart-width --enable-javascript --javascript-delay 1000 ' .
89 escapeshellarg($url) . ' ' .escapeshellarg($file);
93 if(!file_exists($file)){
94 $this->jerr('Fail to make preview image');
103 function serve($file)
105 $this->sessionState(0);
107 require_once 'File/Convert.php';
109 $fc = new File_Convert($file, 'image/png');
111 $fc->convert('image/png', $this->size);
113 $fc->serve('inline');