Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Site path support for using multi site within subfolders in addition to subdomains

givanz51fc2ce4083f
diff --git a/admin/controller/content/edit.php b/admin/controller/content/edit.php
index 23be38a..8db8b7f 100644
--- a/admin/controller/content/edit.php
+++ b/admin/controller/content/edit.php
@@ -226,7 +226,11 @@ class Edit extends Base {
}
//get site host for current selected site to use for absolute url
- $url = ['host' => $this->global['host']];
+ $url = ['host' => $this->global['host'], 'path' => $this->global['path'] ? '/' . $this->global['path'] : null];
+
+ if ($this->type != $this->object) {
+ $url['type'] = $this->type;
+ }
$revisionsUrl = \Vvveb\url(['module' => "$controller/revisions", 'object' => $this->object, 'type' => $this->type, $this->object . '_id' => $post_id]);
$name = '';
diff --git a/admin/controller/editor/editor.php b/admin/controller/editor/editor.php
index c6876b3..b18b0f4 100755
--- a/admin/controller/editor/editor.php
+++ b/admin/controller/editor/editor.php
@@ -93,7 +93,16 @@ class Editor extends Base {
$pages = $list + Cache::getInstance()->cache(APP, 'template-list-' . $theme,
function () use ($theme) {
- return \Vvveb\getTemplateList($theme);
+ $templates = \Vvveb\getTemplateList($theme);
+ //add a prefix for templates like 404 to avoid showing them first
+ foreach ($templates as $key => $template) {
+ if (is_numeric($key) || is_numeric($key[0])) {
+ unset($templates[$key]);
+ $templates["t-$key"] = $template;
+ }
+ }
+
+ return $templates;
}, 604800);
list($pages) = Event::trigger(__CLASS__, __FUNCTION__, $pages);
@@ -102,7 +111,7 @@ class Editor extends Base {
}
private function clearTemplateListCache($theme = null) {
- return Cache::getInstance()->delete(APP, 'template-list-' . $theme);
+ return Cache::getInstance()->delete(APP, 'template-list-' . sanitizeFileName($theme));
}
private function loadEditorData() {
@@ -149,12 +158,12 @@ class Editor extends Base {
if (file_exists($themeFolder . $vvvebJs)) {
$assets['js']['vvvebjs'] = $view->themeBaseUrl . $vvvebJs;
}
-
+
list($assets) =
Event::trigger(__CLASS__, __FUNCTION__, $assets);
-
+
foreach ($assets as $type => $files) {
- $name = 'theme' . ucfirst($type);//themeSections
+ $name = 'theme' . ucfirst($type); //themeSections
$view->$name = $files;
}
}
@@ -181,8 +190,14 @@ class Editor extends Base {
if (! isset($post['slug']) || ! isset($post['name'])) {
continue;
}
+
$slug = htmlspecialchars($post['slug']);
- $url = url('content/page/index',['slug' => $slug, 'post_id' => $post['post_id']]);
+ $params = ['slug' => $slug, 'post_id' => $post['post_id']];
+ if ($this->global['path']) {
+ $params['path'] = '/' . $this->global['path'];
+ }
+
+ $url = url('content/page/index', $params);
$posts["$slug-page"] = [
'name' => "$slug-page",
@@ -203,7 +218,7 @@ class Editor extends Base {
function index() {
$theme = $this->getTheme();
- $themeParam = ($theme ? '&theme=' . $theme : '');
+ $themeParam = (isset($this->request->get['theme']) ? '&theme=' . $theme : '');
$view = View::getInstance();
$view->themeBaseUrl = PUBLIC_PATH . 'themes/' . $theme . '/';
$view->themeName = $theme;
@@ -226,14 +241,15 @@ class Editor extends Base {
$this->loadThemeAssets();
$urlParams = '';
//if admin host is different than site host (for multi site install) use full url including host
- if ($_SERVER['HTTP_HOST'] !== $this->global['site_url']) {
+ $host = $_SERVER['HTTP_HOST'] . ($this->global['path'] ? '/' . $this->global['path'] : '');
+ if ($host !== $this->global['site_url']) {
//$urlPrefix = '//' . $this->global['site_url'];
$urlParams = '&site_id=' . $this->global['site_id'];
}
- $this->pages($theme, $urlParams);
+ $this->pages(isset($this->request->get['theme']) ? $theme : false, $urlParams);
- $homeUrl = V_SUBDIR_INSTALL ?: '/';
+ $homeUrl = (V_SUBDIR_INSTALL ?: '') . '/' . ($this->global['path'] ? $this->global['path'] : '');
$url = sanitizeFileName($this->request->get['url'] ?? $homeUrl, false);
$name = $this->request->get['name'] ?? '';
$template = $this->request->get['template'] ?? ''; //\Vvveb\getUrlTemplate($url) ?? 'index.html';
@@ -245,11 +261,11 @@ class Editor extends Base {
$site_name = '';
if ($url == $homeUrl && ! $template) {
$site = Sites :: getSiteData($this->global['site_id']);
- $template = $site['template'] ?: 'index.html';
+ $template = ($site['template'][$this->global['language_id']] ?? $site['template'][0] ?? '') ?: 'index.html';
$site_name = $site['name'];
}
- $file = $template;
+ $file = $template;
//check if url and template is relative
if (strpos($url, '//') !== false && strpos($template, '..') !== false) {
@@ -307,7 +323,7 @@ class Editor extends Base {
if ($route && isset($route['module'])) {
switch ($route['module']) {
case 'product/product/index':
- $className = 'product';
+ $className = 'product';
if (isset($route['product_id'])) {
$current_page['product_id'] = $route['product_id'];
@@ -325,7 +341,7 @@ class Editor extends Base {
case 'content/post/index':
case 'content/page/index':
- $className = 'page';
+ $className = 'page';
if (isset($route['post_id'])) {
$current_page['post_id'] = $route['post_id'];
@@ -374,7 +390,7 @@ class Editor extends Base {
$current_page += [
'name' => $key,
'file' => $file,
- 'url' => $url . ($theme ? '?theme=' . $theme : '') . $urlParams,
+ 'url' => $url . (isset($this->request->get['theme']) ? '?theme=' . $theme : '') . $urlParams,
'title' => $name,
'folder' => '',
'className' => $className,
@@ -686,7 +702,7 @@ class Editor extends Base {
}
}
- $this->clearTemplateListCache(sanitizeFileName($this->request->get['theme'] ?? false));
+ $this->clearTemplateListCache($this->request->get['theme'] ?? false);
$this->response->setType('json');
$this->response->output($message);
}
@@ -706,7 +722,7 @@ class Editor extends Base {
$theme = $this->getTheme();
$url = '';
- $file = sanitizeFileName(str_replace('.html', '', $file)) . '.html';
+ $file = slugify(sanitizeFileName(str_replace('.html', '', $file))) . '.html';
$folder = trim(sanitizeFileName($folder), '/');
$startTemplateUrl = sanitizeFileName($startTemplateUrl);
@@ -720,6 +736,11 @@ class Editor extends Base {
$default = $templateType == 'global' ? "content/$type.html" : "content/$slug.html";
$default = sanitizeFileName($default);
$template = $templateType == 'global' && isset($startTemplateUrl) ? $startTemplateUrl : $default;
+
+ if ($templateType != 'global' ) {
+ $file = $template;
+ }
+
$post = new PostSQL();
$result = $post->add([
'post' => [
@@ -750,6 +771,11 @@ class Editor extends Base {
$default = sanitizeFileName($default);
$template = $templateType == 'global' && isset($startTemplateUrl) ? $startTemplateUrl : $default;
$price = $this->request->post['price'] ?? 0;
+
+ if ($templateType != 'global' ) {
+ $file = $template;
+ }
+
$product = new ProductSQL();
$result = $product->add([
'product' => [
@@ -801,11 +827,10 @@ class Editor extends Base {
if ($startTemplateUrl) {
$startTemplate = $themeFolder . DS . $startTemplateUrl;
-
if (file_exists($startTemplate)) {
if (! ($html = @file_get_contents($startTemplate))) {
$text .= sprintf(__('%s is not readable!'), $startTemplate);
- }
+ }
} else {
$text .= sprintf(__('%s does not exist!'), $startTemplate);
}
@@ -918,6 +943,8 @@ class Editor extends Base {
}
if (CacheManager::clearCompiledFiles('app', $this->global['site_id'], $theme)) {
+ $this->clearTemplateListCache($this->request->get['theme'] ?? false);
+
$pageCache = new PageCache();
$uri = preg_replace('/\?.+/', '', $uri);
$path = $pageCache->uri($uri);
diff --git a/admin/controller/product/products.php b/admin/controller/product/products.php
index 0545d81..dd69373 100755
--- a/admin/controller/product/products.php
+++ b/admin/controller/product/products.php
@@ -157,6 +157,13 @@ class Products extends Listing {
$options += $this->filter;
+ if (isset($this->request->get['filter']['site_id'])) {
+ if ($this->request->get['filter']['site_id']) {
+ //$options['site_id'] = $this->filter['site_id'];
+ } else {
+ unset($options['site_id']);
+ }
+ }
$results = $products->getAll($options);
$defaultTemplate = "product/{$this->type}.html";
@@ -186,14 +193,14 @@ class Products extends Listing {
$product['edit-url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
$product['delete-url'] = url(['module' => 'product/products', 'action' => 'delete'] + $url); // + ['product_id[]' => $product['product_id']]);
$product['duplicate-url'] = url(['module' => 'product/products', 'action' => 'duplicate'] + $url); // + ['product_id' => $product['product_id']]);
- $product['view-url'] = url('product/product/index', $product + $url + ['host' => $this->global['host']]);
+ $product['view-url'] = url('product/product/index', $product + $url + ['host' => $this->global['host'], 'path' => $this->global['path'] ? '/' . $this->global['path'] : null]);
$relativeUrl = url('product/product/index', $product + $url);
$product['design-url'] = url(['module' => 'editor/editor', 'name' => urlencode($product['name'] ?? ''), 'url' => $relativeUrl, 'template' => $template], false);
}
}
$view->set($results);
- $view->status = [0 => 'Disabled', 1 => 'Enabled'];
+ $view->status = [0 => __('Disabled'), 1 => __('Enabled')];
$view->filter = $this->filter;
$view->type = $this->type;
$view->limit = $options['limit'];
diff --git a/system/core/frontcontroller.php b/system/core/frontcontroller.php
index 09332ae..74f1fbb 100644
--- a/system/core/frontcontroller.php
+++ b/system/core/frontcontroller.php
@@ -92,7 +92,11 @@ class FrontController {
$controller = 'Vvveb\Controller\Error' . $statusCode;
//http_response_code($statusCode);
$view = View::getInstance();
- $view->set($message);
+ if (is_array($message)) {
+ $view->set($message);
+ } else {
+ $view->message = $message;
+ }
self :: call($controller, 'index', $file);
PageCache::getInstance()->cleanUp();
die();
@@ -299,7 +303,7 @@ class FrontController {
return $_GET['module'] ?? '';
}
- static public function dispatch() {
+ static public function dispatch(&$site = []) {
$module = $_GET['module'] ?? $_POST['module'] ?? null;
$action = $_GET['action'] ?? $_POST['action'] ?? null;
$_REQUEST = array_merge($_GET, $_REQUEST);
@@ -312,17 +316,16 @@ class FrontController {
*/
//remove GET parameters to allow correct matching,
- $uri = $_SERVER['REQUEST_URI'] ?? '';
-
- if (V_SUBDIR_INSTALL) {
- $uri = substr($uri, strlen(V_SUBDIR_INSTALL));
- //$uri = str_replace(V_SUBDIR_INSTALL, '', $uri);
- }
-
+ $uri = SITE_URI ?? $_SERVER['REQUEST_URI'] ?? '/';
$uri = preg_replace('/\?.*$/', '', $uri);
+
$route = false;
+ $routesSiteId = null;
+ if (isset($site['route'])) {
+ $routesSiteId = $site['site_id'];
+ };
- if (! $module && (APP != 'admin' && APP != 'install' && (Routes::init(APP) && $route = Routes::match($uri)))) {
+ if (! $module && (APP != 'admin' && APP != 'install' && (Routes::init(APP, $routesSiteId) && $route = Routes::match($uri)))) {
$_GET = array_merge($route, $_GET);
} else {
$module = $module ?? ((APP == 'install' || APP == 'admin') ? 'index' : false);
diff --git a/system/core/startup.php b/system/core/startup.php
index 7190aa1..16ecc3c 100755
--- a/system/core/startup.php
+++ b/system/core/startup.php
@@ -374,6 +374,8 @@ function start() {
//start session
//Session :: getInstance();
$site_id = false;
+ $path = $_SERVER['REQUEST_URI'] ?? '/';
+
if (isset($_GET['site_id'])) {
//check if admin user to allow site id override for editor
if ($admin = \Vvveb\System\User\Admin :: current()) {
@@ -381,22 +383,25 @@ function start() {
}
}
- $site = Sites :: getSiteData($site_id);
-
+ $site = Sites :: getSiteData($site_id, $path);
if ($site) {
define('SITE_URL', $site['host']);
define('SITE_ID', $site['site_id'] ?? 1);
+ define('SITE_URI', $site['uri'] ?? '');
+ define('SITE_PATH', $site['path'] ?? '');
//load plugins first for APP
if (APP != 'admin') {
Plugins :: loadPlugins(SITE_ID);
}
- FrontController::dispatch();
+ FrontController::dispatch($site);
} else {
define('SITE_URL', $_SERVER['HTTP_HOST'] ?? 'localhost');
define('SITE_ID', 1);
+ define('SITE_URI', '');
+ define('SITE_PATH', '');
FrontController::notFound(false, 'Website not found!');
}
}
diff --git a/system/functions.php b/system/functions.php
index d3955f0..f4f20fd 100755
--- a/system/functions.php
+++ b/system/functions.php
@@ -1723,7 +1723,9 @@ function download($url) {
curl_close($ch);
}
- if ($httpcode != 200) return;
+ if ($httpcode != 200) {
+ return;
+ }
}
} else {
if (ini_get('allow_url_fopen') == '1') {
@@ -1798,12 +1800,14 @@ function getUrl($url, $cache = true, $expire = 604800, $timeout = 5, $exception
$streamVerboseHandle = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle);
}
-
+
$result = curl_exec($ch);
if ($result) {
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if ($httpcode != 200) return;
+ if ($httpcode != 200) {
+ return;
+ }
if ($cache) {
$cacheDriver->set('url', $cacheKey, $result);