Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Add theme missing html files by duplicating index.html to have working pages

givanz46a38ad4944f
diff --git a/admin/controller/theme/themes.php b/admin/controller/theme/themes.php
index 8ee73c7..05218aa 100755
--- a/admin/controller/theme/themes.php
+++ b/admin/controller/theme/themes.php
@@ -100,6 +100,10 @@ class Themes extends Base {
try {
// use temorary file, php cleans temporary files on request finish.
$this->themeSlug = ThemesList :: install($file['tmp_name'], $this->themeSlug, false);
+
+ if ($this->themeSlug) {
+ ThemesList :: fixIfMissingTemplates($this->themeSlug);
+ }
} catch (\Exception $e) {
$error = $e->getMessage();
$this->view->errors[] = $error;
@@ -159,6 +163,17 @@ class Themes extends Base {
}
function import() {
+ /*
+ $import = $this->request->post['import'];
+ $required_plugins = $this->request->post['required_plugins'];
+ $recommended_plugins = $this->request->post['recommended_plugins'];*/
+
+ //print_r($import);
+ //$this->processImport($import, '');
+ //print_r($required_plugins);
+ //print_r($recommended_plugins);
+
+ return;
}
function activate() {
diff --git a/system/extensions/themes.php b/system/extensions/themes.php
index afed567..21cd0c3 100755
--- a/system/extensions/themes.php
+++ b/system/extensions/themes.php
@@ -25,6 +25,7 @@ namespace Vvveb\System\Extensions;
use \Vvveb\System\Event;
use \Vvveb\System\Sites;
use function Vvveb\__;
+use function Vvveb\getDefaultTemplateList;
use Vvveb\System\Functions\Str;
class Themes extends Extensions {
@@ -86,6 +87,40 @@ class Themes extends Extensions {
return $themes;
}
+ /*
+ * Add missing templates by copying from available template
+ */
+ static function fixIfMissingTemplates($slug) {
+ //check templates in order
+ $defaultTemplate = '';
+
+ foreach (['content/page.html', 'blank.html', 'index.html'] as $page) {
+ if (file_exists(DIR_THEMES . $slug . DS . $page)) {
+ $defaultTemplate = $page;
+
+ continue;
+ }
+ }
+
+ if ($defaultTemplate) {
+ $templates = getDefaultTemplateList();
+
+ foreach ($templates as $template) {
+ $file = DIR_THEMES . $slug . DS . $template;
+
+ if (! file_exists($file)) {
+ $dir = dirname($template);
+
+ if ($dir && ! file_exists($dir)) {
+ @mkdir(DIR_THEMES . $slug . DS . $dir);
+ }
+
+ @copy(DIR_THEMES . $slug . DS . $defaultTemplate, $file);
+ }
+ }
+ }
+ }
+
static function install($extensionZipFile, $slug = false, $validate = false) {
$extension = static :: $extension;
$success = true;
diff --git a/system/functions.php b/system/functions.php
index 56e3936..4360613 100755
--- a/system/functions.php
+++ b/system/functions.php
@@ -897,6 +897,26 @@ function getThemeFolderList($theme = false) {
return $pages;
}
+function getDefaultTemplateList() {
+ return [
+ 'index.html',
+ 'index.coming-soon.html',
+ 'index.maintenance.html',
+ 'blank.html',
+ 'error404.html',
+ 'error500.html',
+ 'contact.html',
+ 'search/index.html',
+ 'content/post.html',
+ 'content/page.html',
+ 'content/index.html',
+ 'content/category.html',
+ 'product/index.html',
+ 'product/product.html',
+ 'product/category.html',
+ ];
+}
+
function getTemplateList($theme = null, $skip = []) {
$friendlyNames = [
'index' => ['name' => __('Home page'), 'description' => __('Website homepage'), 'global' => true],
@@ -1487,11 +1507,14 @@ function download($url) {
if (function_exists('curl_init')) {
$ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_FAILONERROR, true);
- curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ?? 'Vvveb ' . V_VERSION);
- $result = curl_exec($ch);
- curl_close($ch);
+
+ if ($ch) {
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_FAILONERROR, true);
+ curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ?? 'Vvveb ' . V_VERSION);
+ $result = curl_exec($ch);
+ curl_close($ch);
+ }
} else {
if (ini_get('allow_url_fopen') == '1') {
$context_options = [
@@ -1533,7 +1556,6 @@ function getUrl($url, $cache = true, $expire = 604800, $timeout = 5, $exception
curl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle);
}
$result = curl_exec($ch);
- curl_close($ch);
if ($result) {
if ($cache) {
@@ -1554,6 +1576,8 @@ function getUrl($url, $cache = true, $expire = 604800, $timeout = 5, $exception
throw new \Exception($message);
}
}
+
+ curl_close($ch);
} else {
//try with file get contents
if (ini_get('allow_url_fopen') == '1') {
@@ -1768,7 +1792,8 @@ function array2xml($array, $xml = false) {
}
if ($name) {
- $attributes[$name] = '';
+ $name = explode('=', $name);
+ $attributes[$name[0]] = trim($name[1] ?? '', '\'"');
}
}
@@ -1806,6 +1831,12 @@ function array2xml($array, $xml = false) {
return $xml->asXML();
}
+function removeJsonComments($json) {
+ $json = preg_replace('@^\s*//.*([\r\n]|\s)*|^\s*/\*([\r\n]|.)*?\*/([\r\n]|\s)*@m', '', $json);
+
+ return $json;
+}
+
function prepareJson($array) {
if (! is_array($array)) {
return;
@@ -1834,7 +1865,7 @@ function prepareJson($array) {
return $helper;
}
-function reconstructJson($array) {
+function reconstructJson(&$array, $removeAttrs = false) {
if (! is_iterable($array)) {
return;
}
@@ -1842,6 +1873,10 @@ function reconstructJson($array) {
$array = (array)$array;
foreach ($array as $key => $value) {
+ if ($removeAttrs && $key == '@attributes') {
+ continue;
+ }
+
if (substr_compare($key, 'n--', 0, 3) === 0) {
$newkey = substr($key, 3);
@@ -1858,7 +1893,7 @@ function reconstructJson($array) {
$key = '@' . substr($key, 0, -6);
}
- $helper[$key] = (is_iterable($value)) ? reconstructJson($value) : $value;
+ $helper[$key] = (is_iterable($value)) ? reconstructJson($value, $removeAttrs) : $value;
}
return $helper;