Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Show absolute urls for post and product links for correct links on multi site

givanzb3b58bbf9b06
diff --git a/admin/controller/content/edit.php b/admin/controller/content/edit.php
index 6529067..59a272e 100644
--- a/admin/controller/content/edit.php
+++ b/admin/controller/content/edit.php
@@ -29,11 +29,13 @@ use function Vvveb\model;
use function Vvveb\sanitizeHTML;
use function Vvveb\slugify;
use Vvveb\Sql\categorySQL;
+use Vvveb\Sql\SiteSQL;
use Vvveb\System\CacheManager;
use Vvveb\System\Core\View;
use Vvveb\System\Event;
use Vvveb\System\Images;
use Vvveb\System\Sites;
+use Vvveb\System\User\Admin;
use Vvveb\System\Validator;
class Edit extends Base {
@@ -45,25 +47,58 @@ class Edit extends Base {
use TaxonomiesTrait, AutocompleteTrait;
+ function sites($selectedSites = []) {
+ $sites = new SiteSQL();
+
+ $options = [];
+
+ if (Admin::hasCapability('edit_other_sites')) {
+ unset($options['site_id']);
+ } else {
+ $options['site_id'] = Admin :: siteAccess();
+ }
+
+ $results = $sites->getAll(
+ $options + [
+ 'start' => 0,
+ 'limit' => 100,
+ ]
+ )['sites'] ?? [];
+
+ if ($results && $selectedSites) {
+ foreach ($results as &$site) {
+ $site['selected'] = in_array($site['site_id'], $selectedSites);
+ }
+ }
+
+ return $results;
+ }
+
function getThemeFolder() {
- return DIR_THEMES . DS . Sites::getTheme() ?? 'default';
+ return DIR_THEMES . Sites::getTheme() ?? 'default';
}
function index() {
$view = $this->view;
- $admin_path = \Vvveb\adminPath();
- $postOptions = [];
- $post = [];
- $post_id = $this->request->get[$this->object . '_id'] ?? $this->request->post[$this->object . '_id'] ?? false;
+ $admin_path = \Vvveb\adminPath();
+ $postOptions = [];
+ $post = [];
+ $post_id = $this->request->get[$this->object . '_id'] ?? $this->request->post[$this->object . '_id'] ?? false;
- $controllerPath = $admin_path . 'index.php?module=media/media';
- $view->scanUrl = "$controllerPath&action=scan";
- $view->uploadUrl = "$controllerPath&action=upload";
- $theme = Sites::getTheme() ?? 'default';
- $view->themeCss = PUBLIC_PATH . "themes/$theme/css/admin-post-editor.css";
+ $controllerPath = $admin_path . 'index.php?module=media/media';
+ $view->scanUrl = "$controllerPath&action=scan";
+ $view->uploadUrl = "$controllerPath&action=upload";
+ $theme = Sites::getTheme() ?? 'default';
+ $view->themeCss = PUBLIC_PATH . "themes/$theme/css/admin-post-editor.css";
//$view->themeCss = PUBLIC_PATH . "themes/$theme/css/style.css";
+ $viewCapability = 'view_other_posts';
+
+ if ($this->object == 'product') {
+ $viewCapability = 'view_other_products';
+ }
+
if ($post_id) {
$postOptions[$this->object . '_id'] = (int)$post_id;
} else {
@@ -81,6 +116,13 @@ class Edit extends Base {
$postOptions['type'] = $this->type;
$options = $postOptions + $this->global;
+
+ if (Admin::hasCapability($viewCapability)) {
+ unset($options['admin_id']);
+ } else {
+ $options['admin_id'] = $this->global['admin_id'];
+ }
+
//get all languages
//unset($options['language_id']);
$post = $posts->get($options);
@@ -128,13 +170,18 @@ class Edit extends Base {
$revisions = model($this->object . '_content_revision');
}
+ //get site host for current selected site to use for absolute url
+ $url = ['host' => $this->global['host']];
+
+ $revisionsUrl = \Vvveb\url(['module' => "$controller/revisions", 'object' => $this->object, 'type' => $this->type, $this->object . '_id' => $post_id]);
+
if (isset($post[$this->object . '_content'])) {
foreach ($post[$this->object . '_content'] as &$content) {
if (! isset($post['url'])) {
- $post['url'] = \Vvveb\url($route, ['slug'=> $content['slug']]);
+ $post['url'] = \Vvveb\url($route, ['slug'=> $content['slug']] + $url);
if (! $post['url']) {
- $post['url'] = \Vvveb\url($altRoute, ['slug'=> $content['slug']]);
+ $post['url'] = \Vvveb\url($altRoute, ['slug'=> $content['slug']] + $url);
}
}
$language = [];
@@ -148,17 +195,22 @@ class Edit extends Base {
$language = ['language' => $code];
}
- $content['url'] = \Vvveb\url($route, $content + $language);
+ $content['url'] = \Vvveb\url($route, $content + $language + $url);
$content['revision_count'] = 0;
if (! $content['url']) {
- $content['url'] = \Vvveb\url($altRoute, $content + $language);
+ $content['url'] = \Vvveb\url($altRoute, $content + $language + $url);
}
if ($revisions) {
$revision = $revisions->getAll([$this->object . '_id' => $post_id, 'language_id' => $content['language_id']]);
if ($revision) {
+ foreach ($revision['revision'] as &$rev) {
+ $rev['preview-url'] = $content['url'] . '?revision=preview&created_at=' . $rev['created_at'];
+ $rev['compare-url'] = $revisionsUrl . '&created_at=' . $rev['created_at'];
+ }
+
$content['revision_count'] = $revision['count'];
$content['revision'] = $revision['revision'];
}
@@ -173,7 +225,7 @@ class Edit extends Base {
$themeFolder = $this->getThemeFolder();
if (isset($post['url'])) {
- $design_url = $admin_path . \Vvveb\url(['module' => 'editor/editor', 'url' => $post['url'], 'template' => $template], false, false);
+ $design_url = \Vvveb\url(['module' => 'editor/editor', 'url' => $post['url'], 'template' => $template, 'host' => $this->global['host'] . $admin_path], false, false);
$post['design_url'] = $design_url;
}
@@ -189,18 +241,31 @@ class Edit extends Base {
$view->taxonomies = $this->taxonomies($post[$this->object . '_id'] ?? false);
}
+ $sites = $post[$this->object . '_to_site'] ?? [];
+
+ if ($sites) {
+ $sites = array_keys($sites);
+ } else {
+ if (! $post_id) {
+ $sites[] = $this->global['site_id'];
+ }
+ }
+
+ $view->sitesList = $this->sites($sites);
+
list($post, $post_id) = Event :: trigger(__CLASS__,__FUNCTION__, $post, $post_id);
- $object = $this->object;
- $view->$object = $post;
- $view->status = ['publish' => 'Publish', 'draft' => 'Draft', 'pending' => 'Pending', 'private' => 'Private', 'password' => 'Password'];
- $view->templates = \Vvveb\getTemplateList(false, ['email']);
+ $object = $this->object;
+ $view->$object = $post;
+ $view->status = ['publish' => 'Publish', 'draft' => 'Draft', 'pending' => 'Pending', 'private' => 'Private', 'password' => 'Password'];
+ $view->templates = \Vvveb\getTemplateList(false, ['email']);
//$validator = new Validator([$this->object]);
//$view->validatorJson = $validator->getJSON();
- $view->type = __($this->type);
- $view->type_name = $type_name;
- $view->posts_list_url = \Vvveb\url(['module' => $this->list, 'type' => $this->type]);
- $view->revisions_url = \Vvveb\url(['module' => "$controller/revisions", 'object' => $this->object, 'type' => $this->type, $this->object . '_id' => $post_id]);
+ $view->type = __($this->type);
+ $view->type_name = $type_name;
+ $view->posts_list_url = \Vvveb\url(['module' => $this->list, 'type' => $this->type]);
+ $view->revisions_url = $revisionsUrl;
+ $view->oEmbedProxyUrl = $admin_path . 'index.php?module=editor/editor&action=oEmbedProxy';
}
private function addCategory($taxonomy_id, $name) {
@@ -215,6 +280,10 @@ class Edit extends Base {
return $category_id = $cat['taxonomy_item'];
}
+ function add() {
+ $this->save();
+ }
+
function save() {
$view = view :: getInstance();
$post_id = $this->request->get[$this->object . '_id'] ?? $this->request->post[$this->object . '_id'] ?? false;
@@ -270,13 +339,28 @@ class Edit extends Base {
}
}
- $post = $post + $this->global;
+ $site_id = $this->request->post['site'] ?? []; //[$this->global['site_id']];
- $new = false;
+ $post = $post + $this->global;
+ $new = false;
if ($post_id) {
- $post[$this->object . '_id'] = (int)$post_id;
- $result = $posts->edit([$this->object => $post, $this->object . '_id' => $post_id] + $this->global);
+ /*
+ $viewCapability = 'edit_other_posts';
+
+ if ($this->object == 'product') {
+ $viewCapability = 'edit_other_products';
+ }
+
+ if (Admin::hasCapability($viewCapability)) {
+ unset($postOptions['admin_id']);
+ } else {
+ $postOptions['admin_id'] = $this->global['admin_id'];
+ }
+ */
+
+ $post[$this->object . '_id'] = (int)$post_id;
+ $result = $posts->edit([$this->object => $post, $this->object . '_id' => $post_id, 'site_id' => $site_id] + $this->global);
if ($result >= 0) {
$this->view->success['get'] = ucfirst($this->type) . ' ' . __('saved') . '!';
@@ -309,16 +393,17 @@ class Edit extends Base {
unset($post['updated_at'], $post[$this->object . '_id']);
}
- $return = $posts->add([$this->object => $post] + $this->global);
- $id = $return[$this->object] ?? false;
+ $return = $posts->add([$this->object => $post, 'site_id' => $site_id] + $this->global);
+ $id = $return[$this->object] ?? false;
if (! $id) {
$view->errors = [$posts->error];
} else {
CacheManager::delete($this->object);
$this->request->get[$this->object . '_id'] = $id;
- $post_id = $id;
- $new = true;
+
+ $post_id = $id;
+ $new = true;
$message = ucfirst($this->type) . ' ' . __('saved') . '!';
$view->success['get'] = $message;
diff --git a/admin/controller/content/posts.php b/admin/controller/content/posts.php
index 2fce788..4a492bb 100755
--- a/admin/controller/content/posts.php
+++ b/admin/controller/content/posts.php
@@ -74,6 +74,8 @@ class Posts extends Base {
$archives = $this->posts->getArchives($options);
+ $return = [];
+
$df = false;
if (class_exists('\IntlDateFormatter')) {
@@ -81,6 +83,32 @@ class Posts extends Base {
$df = new \IntlDateFormatter(\Vvveb\getLanguage(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, NULL, NULL, 'MMMM');
}
+ foreach ($archives['archives'] as $index => &$archive) {
+ if (isset($archive['month'])) {
+ $monthNum = $archive['month'];
+ //$dateObj = \DateTime::createFromFormat('!m', $monthNum);
+ //$monthName = $dateObj->format('F');
+
+ $archive['month_text'] = $monthNum;
+
+ if ($df) {
+ $archive['month_text'] = ucfirst(datefmt_format($df, $dt));
+ $dt->setDate(0, $archive['month'], 0);
+ } else {
+ $archive['month_text'] = date('F',mktime(0,0,0,$monthNum,1,$archive['year']));
+ }
+ }
+
+ $name =
+ (isset($archive['day']) ? $archive['day'] . ' ' : '') .
+ (isset($archive['month']) ? $archive['month_text'] . ' ' : '') .
+ (isset($archive['year']) ? $archive['year'] . ' ' : '');
+
+ $archive['month'] = sprintf('%02d', $archive['month']);
+
+ $return[$archive['year'] . '/' . $archive['month']] = $name;
+ }
+/*
$return = [];
if (isset($archives['archives'])) {
@@ -104,7 +132,7 @@ class Posts extends Base {
$return[$archive['year'] . '/' . $archive['month']] = $name;
}
}
-
+*/
return $return;
}
@@ -113,7 +141,7 @@ class Posts extends Base {
$this->posts = new postSQL();
$this->type = $this->request->get['type'] ?? 'post';
- $this->filter = $this->request->get['filter'] ?? [];
+ $this->filter = array_filter($this->request->get['filter'] ?? []);
$options = [
'type' => $this->type,
@@ -155,10 +183,10 @@ class Posts extends Base {
$post['url'] = \Vvveb\url($url);
$post['edit-url'] = $post['url'];
- $post['admin-url'] = \Vvveb\url(['module' => 'content/posts']) . '&filter[admin_id_text]=' . $post['username'] . ' &filter[admin_id]=' . $post['admin_id'];
+ $post['admin-url'] = \Vvveb\url(['module' => 'content/posts']) . '&filter[admin_id_text]=' . $post['username'] . ' &filter[admin_id]=' . $post['admin_id'];
$post['delete-url'] = \Vvveb\url(['module' => 'content/posts', 'action' => 'delete'] + $url + ['post_id[]' => $post['post_id']]);
- $post['view-url'] = \Vvveb\url("content/{$this->type}/index", $post);
- $post['design-url'] = $admin_path . \Vvveb\url(['module' => 'editor/editor', 'url' => $post['view-url'], 'template' => $template], false, false);
+ $post['view-url'] = \Vvveb\url("content/{$this->type}/index", $post + $url + ['host' => $this->global['host']]);
+ $post['design-url'] = \Vvveb\url(['module' => 'editor/editor', 'url' => $post['view-url'], 'template' => $template, 'host' => $this->global['host'] . $admin_path], false, false);
}
}
diff --git a/admin/controller/content/tag.php b/admin/controller/content/tag.php
index f8bfaea..5b6b136 100755
--- a/admin/controller/content/tag.php
+++ b/admin/controller/content/tag.php
@@ -68,6 +68,7 @@ class Tag extends Base {
] + $this->global;
unset($options['user_id']);
+ $view->status = [0 => __('Disabled'), 1 => __('Enabled')];
$view->tag = $tags->getCategoryBySlug($options);
$view->tag['image_url'] = Images::image($view->tag['image'], 'tag', 'thumb');
}
diff --git a/admin/controller/product/product.php b/admin/controller/product/product.php
index 3902c30..19f9d39 100755
--- a/admin/controller/product/product.php
+++ b/admin/controller/product/product.php
@@ -174,8 +174,9 @@ class Product extends Edit {
$view->product['manufacturer_id'] = (($view->product['manufacturer_id'] ?? 0) ? $view->product['manufacturer_id'] : '');
$view->product['vendor_id'] = (($view->product['vendor_id'] ?? 0) ? $view->product['vendor_id'] : '');
+ $view->product['status'] = $view->product['status'] ?? 1;
$data['subtract'] = [1 => __('Yes'), 0 => __('No')]; //Subtract stock options
- $data['status'] = [0 => __('Disabled'), 1 => __('Enabled')]; //Subtract stock options
+ $data['status'] = [0 => __('Disabled'), 1 => __('Enabled')];
$view->set($data);
}
}
diff --git a/admin/controller/product/products.php b/admin/controller/product/products.php
index bb39aeb..21a0cfe 100755
--- a/admin/controller/product/products.php
+++ b/admin/controller/product/products.php
@@ -71,7 +71,7 @@ class Products extends Base {
$view = View :: getInstance();
$products = new ProductSQL();
- $this->filter = $this->request->get['filter'] ?? [];
+ $this->filter = array_filter($this->request->get['filter'] ?? []);
$options = [
'type' => $this->type,
@@ -107,9 +107,9 @@ class Products extends Base {
$product['url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
$product['edit-url'] = url(['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']]);
$product['delete-url'] = url(['module' => 'product/products', 'action' => 'delete', 'product_id[]' => $product['product_id'], 'type' => $product['type']]);
- $product['view-url'] = url('product/product/index', $product);
+ $product['view-url'] = url('product/product/index', $product + ['host' => $this->global['host']]);
$admin_path = \Vvveb\config('admin.path', 'admin') . '/';
- $product['design-url'] = '/' . $admin_path . url(['module' => 'editor/editor', 'url' => $product['view-url'], 'template' => $template], false, false);
+ $product['design-url'] = url(['module' => 'editor/editor', 'url' => $product['view-url'], 'template' => $template, 'host' => $this->global['host'] . $admin_path], false, false);
}
}