Skip to content

Commit 46a38ad

Browse files
committed
Add theme missing html files by duplicating index.html to have working pages
1 parent aa0b7e7 commit 46a38ad

File tree

3 files changed

+94
-9
lines changed

3 files changed

+94
-9
lines changed

admin/controller/theme/themes.php

+15
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ function upload() {
100100
try {
101101
// use temorary file, php cleans temporary files on request finish.
102102
$this->themeSlug = ThemesList :: install($file['tmp_name'], $this->themeSlug, false);
103+
104+
if ($this->themeSlug) {
105+
ThemesList :: fixIfMissingTemplates($this->themeSlug);
106+
}
103107
} catch (\Exception $e) {
104108
$error = $e->getMessage();
105109
$this->view->errors[] = $error;
@@ -159,6 +163,17 @@ function processImport($data, $path, $type = false) {
159163
}
160164

161165
function import() {
166+
/*
167+
$import = $this->request->post['import'];
168+
$required_plugins = $this->request->post['required_plugins'];
169+
$recommended_plugins = $this->request->post['recommended_plugins'];*/
170+
171+
//print_r($import);
172+
//$this->processImport($import, '');
173+
//print_r($required_plugins);
174+
//print_r($recommended_plugins);
175+
176+
return;
162177
}
163178

164179
function activate() {

system/extensions/themes.php

+35
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use \Vvveb\System\Event;
2626
use \Vvveb\System\Sites;
2727
use function Vvveb\__;
28+
use function Vvveb\getDefaultTemplateList;
2829
use Vvveb\System\Functions\Str;
2930

3031
class Themes extends Extensions {
@@ -86,6 +87,40 @@ static function getList($path = '') {
8687
return $themes;
8788
}
8889

90+
/*
91+
* Add missing templates by copying from available template
92+
*/
93+
static function fixIfMissingTemplates($slug) {
94+
//check templates in order
95+
$defaultTemplate = '';
96+
97+
foreach (['content/page.html', 'blank.html', 'index.html'] as $page) {
98+
if (file_exists(DIR_THEMES . $slug . DS . $page)) {
99+
$defaultTemplate = $page;
100+
101+
continue;
102+
}
103+
}
104+
105+
if ($defaultTemplate) {
106+
$templates = getDefaultTemplateList();
107+
108+
foreach ($templates as $template) {
109+
$file = DIR_THEMES . $slug . DS . $template;
110+
111+
if (! file_exists($file)) {
112+
$dir = dirname($template);
113+
114+
if ($dir && ! file_exists($dir)) {
115+
@mkdir(DIR_THEMES . $slug . DS . $dir);
116+
}
117+
118+
@copy(DIR_THEMES . $slug . DS . $defaultTemplate, $file);
119+
}
120+
}
121+
}
122+
}
123+
89124
static function install($extensionZipFile, $slug = false, $validate = false) {
90125
$extension = static :: $extension;
91126
$success = true;

system/functions.php

+44-9
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,26 @@ function getThemeFolderList($theme = false) {
897897
return $pages;
898898
}
899899

900+
function getDefaultTemplateList() {
901+
return [
902+
'index.html',
903+
'index.coming-soon.html',
904+
'index.maintenance.html',
905+
'blank.html',
906+
'error404.html',
907+
'error500.html',
908+
'contact.html',
909+
'search/index.html',
910+
'content/post.html',
911+
'content/page.html',
912+
'content/index.html',
913+
'content/category.html',
914+
'product/index.html',
915+
'product/product.html',
916+
'product/category.html',
917+
];
918+
}
919+
900920
function getTemplateList($theme = null, $skip = []) {
901921
$friendlyNames = [
902922
'index' => ['name' => __('Home page'), 'description' => __('Website homepage'), 'global' => true],
@@ -1487,11 +1507,14 @@ function download($url) {
14871507

14881508
if (function_exists('curl_init')) {
14891509
$ch = curl_init($url);
1490-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1491-
curl_setopt($ch, CURLOPT_FAILONERROR, true);
1492-
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ?? 'Vvveb ' . V_VERSION);
1493-
$result = curl_exec($ch);
1494-
curl_close($ch);
1510+
1511+
if ($ch) {
1512+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1513+
curl_setopt($ch, CURLOPT_FAILONERROR, true);
1514+
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ?? 'Vvveb ' . V_VERSION);
1515+
$result = curl_exec($ch);
1516+
curl_close($ch);
1517+
}
14951518
} else {
14961519
if (ini_get('allow_url_fopen') == '1') {
14971520
$context_options = [
@@ -1533,7 +1556,6 @@ function getUrl($url, $cache = true, $expire = 604800, $timeout = 5, $exception
15331556
curl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle);
15341557
}
15351558
$result = curl_exec($ch);
1536-
curl_close($ch);
15371559

15381560
if ($result) {
15391561
if ($cache) {
@@ -1554,6 +1576,8 @@ function getUrl($url, $cache = true, $expire = 604800, $timeout = 5, $exception
15541576
throw new \Exception($message);
15551577
}
15561578
}
1579+
1580+
curl_close($ch);
15571581
} else {
15581582
//try with file get contents
15591583
if (ini_get('allow_url_fopen') == '1') {
@@ -1768,7 +1792,8 @@ function array2xml($array, $xml = false) {
17681792
}
17691793

17701794
if ($name) {
1771-
$attributes[$name] = '';
1795+
$name = explode('=', $name);
1796+
$attributes[$name[0]] = trim($name[1] ?? '', '\'"');
17721797
}
17731798
}
17741799

@@ -1806,6 +1831,12 @@ function array2xml($array, $xml = false) {
18061831
return $xml->asXML();
18071832
}
18081833

1834+
function removeJsonComments($json) {
1835+
$json = preg_replace('@^\s*//.*([\r\n]|\s)*|^\s*/\*([\r\n]|.)*?\*/([\r\n]|\s)*@m', '', $json);
1836+
1837+
return $json;
1838+
}
1839+
18091840
function prepareJson($array) {
18101841
if (! is_array($array)) {
18111842
return;
@@ -1834,14 +1865,18 @@ function prepareJson($array) {
18341865
return $helper;
18351866
}
18361867

1837-
function reconstructJson($array) {
1868+
function reconstructJson(&$array, $removeAttrs = false) {
18381869
if (! is_iterable($array)) {
18391870
return;
18401871
}
18411872
$helper = [];
18421873
$array = (array)$array;
18431874

18441875
foreach ($array as $key => $value) {
1876+
if ($removeAttrs && $key == '@attributes') {
1877+
continue;
1878+
}
1879+
18451880
if (substr_compare($key, 'n--', 0, 3) === 0) {
18461881
$newkey = substr($key, 3);
18471882

@@ -1858,7 +1893,7 @@ function reconstructJson($array) {
18581893
$key = '@' . substr($key, 0, -6);
18591894
}
18601895

1861-
$helper[$key] = (is_iterable($value)) ? reconstructJson($value) : $value;
1896+
$helper[$key] = (is_iterable($value)) ? reconstructJson($value, $removeAttrs) : $value;
18621897
}
18631898

18641899
return $helper;

0 commit comments

Comments
 (0)