3 require_once 'Pman.php';
5 class Pman_Cms_PageThumb extends Pman
7 function get($id = '', $opts = array())
9 $cms_page = DB_DataObject::factory('cms_page');
10 $cms_page->autoJoin();
12 $file_broken = realpath('Pman/templates/images/file-broken.png');
14 if(empty($id) || !$cms_page->get($id)){
15 $this->serve($file_broken);
18 if ($cms_page->page_type_id_name == 'element') {
19 $cms_page = $cms_page->parent();
22 if(empty($cms_page->page_type_id_name) || $cms_page->page_type_id_name != 'page') {
23 $this->serve($file_broken);
25 $ff = HTML_FlexyFramework::get();
26 $opts = isset($ff->Pman_Cms) ? $ff->Pman_Cms : array();
28 if (!isset($opts['basePHP'])) {
29 $this->serve($file_broken);
32 $basePHP = $opts['basePHP'];
35 $pl = $cms_page->page_link;
36 if (is_array($opts['basePHP'])) {
37 foreach($opts['basePHP'] as $k=>$v) {
38 if ($k == substr($pl,0, strlen($k))) {
39 $pl = substr($pl, strlen($k)+1);
46 $this->serve($file_broken);
62 $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
64 $url = $protocol . $_SERVER['HTTP_HOST'] . $this->rootURL .'/'. $basePHP . $pl;
66 $file = $cms_page->getStoreName();
68 if(file_exists($file) && strtotime($cms_page->updated) < filemtime($file)){
72 require_once 'System.php';
74 $conv = System::which('wkhtmltoimage');
77 $this->jerr("missing wkhtmltoimage");
80 $xvfb = System::which('xvfb-run');
83 $this->jerr("missing xvfb-run");
86 $cmd = $xvfb . ' --auto-servernum ' . $conv .
87 ' --width 300 --height 300 --zoom 0.3 --disable-smart-width --enable-javascript --javascript-delay 1000 ' .
88 escapeshellarg($url) . ' ' .escapeshellarg($file);
92 if(!file_exists($file)){
93 $this->serve($file_broken);
102 function serve($file)
104 $this->sessionState(0);
106 require_once 'File/Convert.php';
108 $fc = new File_Convert($file, 'image/png');
110 $fc->convert('image/png');
112 $fc->serve('inline');