-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesignPreview.module.php
More file actions
71 lines (63 loc) · 2.79 KB
/
DesignPreview.module.php
File metadata and controls
71 lines (63 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
class DesignPreview extends NetDesign {
public function GetVersion() {
return '1.0.0';
}
function HasAdmin() {
return false;
}
function GetFriendlyName() {
return 'Design Preview';
}
public function SuppressAdminOutput(&$request) {
return true;
}
public function RegisterRoutes() {
cms_route_manager::del_static('',$this->GetName());
$route = new CmsRoute('/preview\/(?P<site_id>.*?)\/(?P<filename>.*?)((?!\.html))$/', $this->GetName(), array('action' => 'default', 'showtemplate' => 'false'));
cms_route_manager::add_static($route);
$route = new CmsRoute('/preview\/(?P<site_id>.*?)\/(?P<filename>.*?).html$/', $this->GetName(), array('action' => 'html', 'showtemplate' => 'false'));
cms_route_manager::add_static($route);
}
public function Install() {
$this->RegisterRoutes();
return false;
}
public function Uninstall() {
cms_route_manager::del_static('',$this->GetName());
return false;
}
public function Error404() {
header('Content-Type: text/plain', true, 404);
echo "404 Not Found.";
exit;
}
public function DoAction($name, $id, $params, $returnid = '') {
$cms = cmsms();
if ($name == 'default') {
$path = cms_join_path($cms->GetConfig()->offsetGet('root_path'), 'netdesign', $params['site_id'], $params['filename']);
if (!file_exists($path)) $this->Error404();
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($path);
$extension = pathinfo($path, PATHINFO_EXTENSION);
switch($extension) {
case 'css': $mime = 'text/css'; break;
case 'js': $mime = 'application/javascript'; break;
}
$this->SetContentType($mime);
readfile($path);
} else {
require_once(__DIR__ . '/vendor/autoload.php');
error_reporting(E_ALL);
ini_set('display_errors', 'on');
$html = cms_join_path($cms->GetConfig()->offsetGet('root_path'), 'netdesign', $params['site_id'], 'html', $params['filename'] . '.html');
if (!file_exists($html)) $this->Error404();
$_ = cms_join_path($cms->GetConfig()->offsetGet('root_path'), 'netdesign', $params['site_id'], 'preview', '_.php');
$php = cms_join_path($cms->GetConfig()->offsetGet('root_path'), 'netdesign', $params['site_id'], 'preview', $params['filename'] . '.php');
$dom = pQuery::parseFile($html);
if (file_exists($_)) include($_);
if (file_exists($php)) include($php);
echo $this->smarty->fetch(sprintf('string:%s', $dom->html()));
}
}
}