forked from TheCodeDeli/stagebloc-local-theme-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_theme.php
113 lines (100 loc) · 3.23 KB
/
submit_theme.php
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
require_once 'config.php';
function recursiveTemplateInclude($html, $path) {
// Find all of the Includes inside of the theme
preg_match_all('#\{(Includ[^:{}"]+)(\s[^{}]+\=[^{}]*)?\}#ims', $html, $includes);
foreach ( $includes[0] as $key => $option_variable_string )
{
if ( preg_match_all('#([a-zA-Z]*)="([^"]*)"#', $option_variable_string, $options_matches) )
{
// For each include, find which file we should be putting in its place
foreach ( $options_matches[1] as $key => $option )
{
if ( strtolower($option) === 'file' )
{
$included_template = recursiveTemplateInclude(file_get_contents($path . $options_matches[2][$key]), $path);
$html = str_replace($option_variable_string, $included_template, $html);
}
}
}
}
return $html;
}
if ( isset($_COOKIE['theme']) )
{
$themeToUse = $_COOKIE['theme'];
// Get the HTML to pass along to the API
$html = file_get_contents($themePath . $themeToUse . '/theme.sbt');
if ( $themeViewsPath !== null )
{
$html = recursiveTemplateInclude($html, $themePath . $themeToUse . '/' . $themeViewsPath);
}
$postData = array(
'html' => $html,
'mobile' => filter_var($_POST['mobile'], FILTER_VALIDATE_BOOLEAN)
);
if ( $cssPath !== null ) // If this var isn't null, we'll check another folder for the CSS files
{
$css = '';
$cssFiles = scandir($themePath . $themeToUse . '/' . $cssPath);
foreach ( $cssFiles as $cssFile )
{
if ( preg_match('/\.css$/', $cssFile) )
{
$css .= file_get_contents($themePath . $themeToUse . '/' . $cssPath . $cssFile);
}
}
$postData['css'] = $css;
}
else
{
$postData['css'] = file_get_contents($themePath . $themeToUse . '/style.css');
}
if ( strpos($postData['css'], '@') === 0 )
{
$postData['css'] = ' ' . $postData['css'];
}
if ( $jsPath !== null ) // If this var isn't null, we'll check another folder for the CSS files
{
$js = '';
$jsFiles = scandir($themePath . $themeToUse . '/' . $jsPath);
foreach ( $jsFiles as $jsFile )
{
if ( preg_match('/\.js$/', $jsFile) && ! in_array($jsFile, $jsFileBlacklist) )
{
$js .= file_get_contents($themePath . $themeToUse . '/' . $jsPath . $jsFile);
}
}
$postData['js'] = $js;
}
else
{
$postData['js'] = file_get_contents($themePath . $themeToUse . '/javascript.js');
}
if ( isset($_GET['generate']) && filter_var($_GET['generate'], FILTER_VALIDATE_BOOLEAN) ): ?>
<html>
<head></head>
<body>
You can copy and paste the following text into files to have your entire theme...<br/>
<a href="index.php">Back To Theme Development</a><br/>
<textarea rows="20" cols="100" readonly><?php echo htmlspecialchars($postData['html']); ?></textarea><br/>
<textarea rows="20" cols="100" readonly><?php echo htmlspecialchars($postData['css']); ?></textarea><br/>
<textarea rows="20" cols="100" readonly><?php echo htmlspecialchars($postData['js']); ?></textarea>
</body>
</html>
<?php else:
try
{
$stagebloc->post('theme/edit', $postData);
}
catch ( Services_StageBloc_Invalid_Http_Response_Code_Exception $e )
{
die('Error: ' . $e->getHttpBody());
}
exit(header('Location: index.php')); // Redirect back to the editor
endif;
}
else
{
die('No theme cookie set! Try switching themes to a different one and then back.');
}