first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
drwxr-xr-x 4 30094 users 4 Oct 6 10:16 .
drwxr-xr-x 9 30094 users 16 Oct 6 10:16 ..
drwxr-xr-x 2 30094 users 6 Oct 6 10:16 admin
drwxr-xr-x 2 30094 users 9 Oct 6 10:16 front

View File

@@ -0,0 +1,6 @@
drwxr-xr-x 2 30094 users 6 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 4 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 33073 Aug 31 2021 AdminJXBlogCategories.php
-rw-r--r-- 1 30094 users 26016 Aug 31 2021 AdminJXBlogImages.php
-rw-r--r-- 1 30094 users 3927 Aug 31 2021 AdminJXBlogMainSettings.php
-rw-r--r-- 1 30094 users 16150 Aug 31 2021 AdminJXBlogPosts.php

View File

@@ -0,0 +1,723 @@
<?php
/**
* 2017-2019 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2019 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class AdminJXBlogCategoriesController extends ModuleAdminController
{
public $_category = null;
protected $position_identifier = 'id_jxblog_category_to_move';
public $imageManager;
public $breadCrumbs = array();
protected $helper;
public function __construct()
{
$this->table = 'jxblog_category';
$this->list_id = $this->table;
$this->identifier = 'id_jxblog_category';
$this->className = 'JXBlogCategory';
$this->module = $this;
$this->lang = true;
$this->bootstrap = true;
$this->languages = Language::getLanguages(false);
$this->default_language = Configuration::get('PS_LANG_DEFAULT');
$this->context = Context::getContext();
$this->translator = Context::getContext()->getTranslator();
if (Shop::isFeatureActive()) {
Shop::addTableAssociation($this->table, array('type' => 'shop'));
}
$id_category = (int)Tools::getValue('id_jxblog_category');
if (!$id_category && !Tools::getIsset('add'.$this->table)) {
$id_category = 2;
}
$this->_category = new JXBlogCategory($id_category);
$this->_join = 'LEFT JOIN '._DB_PREFIX_.$this->table.'_shop jxs ON a.id_jxblog_category=jxs.id_jxblog_category && jxs.id_shop IN('.implode(',', Shop::getContextListShopID()).')';
$this->_filter = 'AND a.`id_parent_category` = '.$id_category.' AND a.id_jxblog_category > 2';
$this->_select = 'jxs.id_shop';
$this->_defaultOrderBy = 'a.position';
$this->_defaultOrderWay = 'ASC';
$this->_default_pagination = 10;
$this->_pagination = array(10, 20, 50, 100);
$this->_orderBy = Tools::getValue($this->table.'Orderby');
$this->_orderWay = Tools::getValue($this->table.'Orderway');
$this->orderBy = 'position';
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?')
)
);
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
$this->_group = 'GROUP BY a.id_jxblog_category';
}
$this->fields_list = array(
'id_jxblog_category' => array(
'title' => $this->l('ID Category'),
'width' => 100,
'type' => 'text',
'search' => true,
'orderby' => true
),
'name' => array(
'title' => $this->l('Name'),
'width' => 440,
'type' => 'text',
'search' => true,
'orderby' => true,
'lang' => true
),
'position' => array(
'title' => $this->l('Position'),
'filter_key' => 'a!position',
'position' => 'position',
'align' => 'center'
),
'active' => array(
'title' => $this->l('Displayed'),
'active' => 'status',
'type' => 'bool',
'class' => 'fixed-width-xs',
'align' => 'center',
'ajax' => true,
'orderby' => false
)
);
parent::__construct();
$this->imageManager = new JXBlogImageManager($this->module);
if (!$this->module->active) {
Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome'));
}
}
public function setMedia($isNewTheme = false)
{
$this->context->controller->addCss($this->module->modulePath.'views/css/jxblog_admin.css');
parent::setMedia($isNewTheme);
}
public function init()
{
parent::init();
}
public function renderView()
{
return $this->renderList();
}
public function initToolbar()
{
// add button "New" to each categories listing
if ($this->display == 'view') {
$this->toolbar_btn['new'] = array(
'href' => self::$currentIndex . '&add' . $this->table . '&id_parent=' . (int) Tools::getValue('id_jxblog_category') . '&token=' . $this->token,
'desc' => $this->l('Add New'),
);
}
parent::initToolbar();
// add different back buttons to each category listing
if (!$this->lite_display
&& isset($this->toolbar_btn['back']['href'])
&& !empty($this->_category)
&& $this->_category->id_parent_category
&& $this->_category->id_parent_category != 2
) {
$this->toolbar_btn['back']['href'] .= '&viewjxblog_category&id_jxblog_category=' . (int) $this->_category->id_parent_category;
}
}
public function renderList()
{
$this->addRowAction('view');
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->helper = new HelperBlog();
// create categories breadcrumb
$this->helper->buildBreadCrumbs($this->_category->id_jxblog_category);
$categories_tree = $this->helper->getBreadCrumbs();
// add edit link to breadcrumb
if (!empty($categories_tree)) {
$link = Context::getContext()->link;
foreach ($categories_tree as $k => $tree) {
$categories_tree[$k]['edit_link'] = $link->getAdminLink('AdminJXBlogCategories', true) . '&id_jxblog_category=' . (int) $tree['id_jxblog_category'] . '&updatejxblog_category';
}
}
$this->tpl_list_vars['categories_tree'] = $categories_tree;
$this->tpl_list_vars['categories_tree_current_id'] = $this->_category->id;
return parent::renderList();
}
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
parent::getList($id_lang);
// add view button to category if it has children
if ($this->_list && count($this->_list)) {
foreach ($this->_list as $item) {
if (!JXBlogCategory::getChildrenCategories($item['id_jxblog_category'])) {
$this->addRowActionSkipList('view', array($item['id_jxblog_category']));
}
}
}
}
public function initContent()
{
if ($this->errors) {
$this->content = $this->renderForm();
$this->context->smarty->assign('content', $this->content);
} elseif (Tools::getIsset('delete'.$this->table)) {
$this->content = $this->confirmDeleteForm();
parent::initContent();
} else {
parent::initContent();
}
}
/**
* Confirm delete form. Used to determine what to do with the category data(posts, children categories)
* when you delete the category
*
* @return string
*/
public function confirmDeleteForm()
{
$availableCategories = JXBlogCategory::getAllCategoriesWithInfo();
$options = array();
foreach ($availableCategories as $key => $category) {
if ($category['id_jxblog_category'] > 1 &&$category['id_jxblog_category'] != Tools::getValue('id_jxblog_category')) {
$options[$key]['id'] = $category['id_jxblog_category'];
$options[$key]['type'] = $category['name'];
}
}
$this->fields_form = array(
'legend' => array(
'title' => $this->l('What do you want to do with products and categories that are related to the category?')
),
'input' => array(
array(
'type' => 'hidden',
'name' => 'id_jxblog_category',
'value' => Tools::getValue('id_jxblog_category')
),
array(
'type' => 'radio',
'name' => 'deleteAction',
'label' => '',
'col' => 12,
'values' => array(
array(
'id' => 'deleteAction',
'value' => 1,
'label' => $this->l('Remove the category and all children categories and leave their posts without main category')
),
array(
'id' => 'deleteAction',
'value' => 2,
'label' => $this->l('Remove the category and all children categories and all their posts')
),
array(
'id' => 'deleteAction',
'value' => 3,
'label' => $this->l('Remove the category and only its posts but leave children categories')
),
array(
'id' => 'deleteAction',
'value' => 4,
'label' => $this->l('Select new main category from the list below')
)
)
),
array(
'type' => 'select',
'name' => 'newDefaultCategory',
'label' => '',
'col' => 12,
'options' => array(
'query' => $options,
'id' => 'id',
'name' => 'type'
)
)
),
'buttons' => array(
array(
'title' => $this->l('Delete'),
'class' => 'button pull-right btn btn-danger',
'name' => 'confirmDelete',
'type' => 'submit'
)
)
);
$this->fields_value['deleteAction'] = 1;
$this->submit_action = 'confirmDelete';
return parent::renderForm();
}
public function renderForm()
{
$categoriesTree = $this->helper->buildTree();
$id_category = Tools::getValue('id_jxblog_category');
$unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP'));
$guest = new Group(Configuration::get('PS_GUEST_GROUP'));
$default = new Group(Configuration::get('PS_CUSTOMER_GROUP'));
$unidentified_group_information = sprintf($this->l('%s - All people without a valid customer account.'), '<b>'.$unidentified->name[$this->context->language->id].'</b>');
$guest_group_information = sprintf($this->l('%s - Customer who placed an order with the guest checkout.'), '<b>'.$guest->name[$this->context->language->id].'</b>');
$default_group_information = sprintf($this->l('%s - All people who have created an account on this site.'), '<b>'.$default->name[$this->context->language->id].'</b>');
$image = false;
$thumb = false;
if (Tools::getIsset('id_jxblog_category') && Tools::getValue('id_jxblog_category')) {
if (file_exists($this->module->modulePath.'img/c/'.Tools::getValue('id_jxblog_category').'.jpg')) {
$image = '<img class="imgm img-thumbnail" src="'.$this->module->_link.'img/c/'.Tools::getValue('id_jxblog_category').'.jpg" width="300" />';
}
if (file_exists($this->module->modulePath.'img/ct/'.Tools::getValue('id_jxblog_category').'.jpg')) {
$thumb = '<img class="imgm img-thumbnail" src="'.$this->module->_link.'img/ct/'.Tools::getValue('id_jxblog_category').'.jpg" width="150" />';
}
}
$selected_categories = array();
if (Tools::getIsset('id_parent') && Tools::getValue('id_parent')) {
$selected_categories[] = Tools::getValue('id_parent');
} elseif ($this->_category->id_parent_category) {
$selected_categories[] = $this->_category->id_parent_category;
} else {
$selected_categories[] = 2;
}
$this->fields_form = array(
'input' => array(
array(
'type' => 'text',
'class' => 'copy2friendlyUrl',
'hint' => $this->l('Invalid characters: <>;=#{}'),
'label' => $this->l('Name'),
'name' => 'name',
'required' => true,
'desc' => $this->l('Enter the blog category name'),
'lang' => true,
'col' => 3
),
array(
'type' => 'text',
'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.'),
'label' => $this->l('Friendly URL'),
'name' => 'link_rewrite',
'required' => true,
'desc' => $this->l('Enter the blog category friendly URL. Will be used as a link to the category in the "Friendly URL" mode'),
'lang' => true,
'col' => 3
),
array(
'type' => 'categories',
'label' => $this->l('Parent category'),
'name' => 'id_parent_category',
'tree' => array(
'id' => 'blog-categories-tree',
'selected_categories' => $selected_categories,
'disabled_categories' => (!Tools::isSubmit('add' . $this->table) && !Tools::isSubmit('submitAdd' . $this->table)) ? array($id_category) : null,
'root_category' => 1,
'set_data' => $categoriesTree,
'use_search' => true,
'use_checkbox' => false
),
),
array(
'type' => 'textarea',
'label' => $this->l('Short description'),
'name' => 'short_description',
'desc' => $this->l('Enter the category short description'),
'lang' => true,
'col' => 6,
'autoload_rte' => true
),
array(
'type' => 'textarea',
'label' => $this->l('Full description'),
'name' => 'description',
'desc' => $this->l('Enter the category full description'),
'lang' => true,
'col' => 6,
'autoload_rte' => true
),
array(
'type' => 'text',
'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.'),
'label' => $this->l('Meta Keywords'),
'name' => 'meta_keyword',
'desc' => $this->l('Enter Your Category Meta Keywords. Separated by comma(,) '),
'lang' => true,
'col' => 6
),
array(
'type' => 'textarea',
'label' => $this->l('Meta Description'),
'name' => 'meta_description',
'desc' => $this->l('Enter the category meta description'),
'lang' => true,
'col' => 6,
'autoload_rte' => false
),
array(
'type' => 'file',
'label' => $this->l('Image'),
'name' => 'image',
'value' => true,
'display_image' => false,
'image' => $image,
'desc' => $this->l('Only .jpg images are allowed')
),
array(
'type' => 'file',
'label' => $this->l('Image thumbnail'),
'name' => 'thumbnail',
'value' => true,
'display_image' => false,
'image' => $thumb,
'desc' => $this->l('Only .jpg images are allowed')
),
array(
'type' => 'group',
'label' => $this->l('Group access'),
'name' => 'groupBox',
'values' => Group::getGroups(Context::getContext()->language->id),
'info_introduction' => $this->l('You now have three default customer groups.'),
'unidentified' => $unidentified_group_information,
'guest' => $guest_group_information,
'customer' => $default_group_information,
'hint' => $this->l('Mark all of the customer groups which you would like to have access to this category.')
),
array(
'type' => 'text',
'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.'),
'label' => $this->l('Badge'),
'name' => 'badge',
'desc' => $this->l('Enter the badge which will unify the category on the list'),
'lang' => true,
'col' => 6
),
array(
'type' => 'switch',
'label' => $this->l('Status'),
'name' => 'active',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled'),
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled'),
)
)
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button pull-right btn btn-default'
)
);
$this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
if (Shop::isFeatureActive()) {
$this->fields_form['input'][] = array(
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso'
);
}
$category_groups_ids = array();
if ($id_category) {
$category = new JXBlogCategory($id_category);
$category_groups_ids = $category->getGroups();
}
$groups = Group::getGroups($this->context->language->id);
if (!count($category_groups_ids)) {
$preselected = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP'));
$category_groups_ids = array_merge($category_groups_ids, $preselected);
}
foreach ($groups as $group) {
$this->fields_value['groupBox_'.$group['id_group']] = Tools::getValue('groupBox_'.$group['id_group'], (in_array($group['id_group'], $category_groups_ids)));
}
if (!($JXBlogCategory = $this->loadObject(true))) {
return;
}
return parent::renderForm();
}
public function validateRules($class_name = false)
{
parent::validateRules();
}
public function postProcess()
{
$this->helper = new HelperBlog();
if (Tools::isSubmit('submitAddjxblog_category') && !Tools::getIsset('confirmDelete')) {
$this->validateRules();
if (count($this->errors)) {
return false;
}
$id_category = (int)Tools::getValue('id_jxblog_category');
if (!$id_category) {
$category = new JXBlogCategory();
} else {
$category = new JXBlogCategory($id_category);
}
if (!$id_category) {
$category->date_add = date('y-m-d H:i:s');
$category->position = (int)$category->getNewPosition(Tools::getValue('id_parent_category'));
} else {
$category->date_upd = date('y-m-d H:i:s');
if ($category->id_parent_category != Tools::getValue('id_parent_category')) {
$category->position = $category->getNewPosition(Tools::getValue('id_parent_category'));
}
}
if (!$parent = Tools::getValue('id_parent_category')) {
$category->id_parent_category = $category->id_parent_category ? $category->id_parent_category : 0;
} else {
$category->id_parent_category = (int)$parent;
}
$category->active = Tools::getValue('active');
foreach ($this->languages as $lang) {
$category->name[$lang['id_lang']] = Tools::getValue('name_'.$lang['id_lang']);
$category->link_rewrite[$lang['id_lang']] = Tools::getValue('link_rewrite_'.$lang['id_lang']);
if (!$category->link_rewrite[$lang['id_lang']]) {
$category->link_rewrite[$lang['id_lang']] = Tools::getValue(
'link_rewrite_'.$this->default_language
);
}
if (!$category->link_rewrite[$lang['id_lang']]) {
$category->link_rewrite[$lang['id_lang']] = Tools::getValue(
'link_rewrite_'.$this->default_language
);
}
if ($category->checkCategoryNameExistence(
$category->id,
$category->name[$lang['id_lang']],
$lang['id_lang']
)
) {
$this->errors[] = sprintf(
$this->l('The category with such name already exists!. Name: %s, Language: %s'),
$category->name[$lang['id_lang']],
$lang['iso_code']
);
}
if ($category->checkFriendlyUrlNameExistence(
$category->id,
$category->link_rewrite[$lang['id_lang']],
$lang['id_lang']
)
) {
$this->errors[] = sprintf(
$this->l('The category with such Friendly Url already exists!. Name: %s, Language: %s'),
$category->link_rewrite[$lang['id_lang']],
$lang['iso_code']
);
}
$category->description[$lang['id_lang']] = Tools::getValue('description_'.$lang['id_lang']);
$category->short_description[$lang['id_lang']] = Tools::getValue('short_description_'.$lang['id_lang']);
$category->meta_keyword[$lang['id_lang']] = Tools::getValue('meta_keyword_'.$lang['id_lang']);
$category->meta_description[$lang['id_lang']] = Tools::getValue('meta_description_'.$lang['id_lang']);
$category->badge[$lang['id_lang']] = Tools::getValue('badge_'.$lang['id_lang']);
}
if ($this->errors) {
return false;
}
if (!$category->save()) {
$this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
}
// upload category images after successful saving
$imageManger = new JXBlogImageManager($this->module);
if (!Tools::isEmpty(Tools::getValue('image')) && Tools::getValue('image')) {
if ($error = $imageManger->uploadImage($category->id, $_FILES['image'], 'category')) {
$this->errors[] = $error;
}
}
if (!Tools::isEmpty(Tools::getValue('thumbnail')) && Tools::getValue('thumbnail')) {
if ($error = $imageManger->uploadImage($category->id, $_FILES['thumbnail'], 'category_thumb')) {
$this->errors[] = $error;
}
}
// redirect to the categories list page if no errors occurred
if (!$this->errors) {
if (Tools::getIsset('id_parent_category') && Tools::getValue('id_parent_category') > 2) {
//redirent to the parent category listing and avoid wrong redirection if parent category is one of the default
Tools::redirectAdmin($this->context->link->getAdminLink('AdminJXBlogCategories').'&conf=4&id_jxblog_category='.Tools::getValue('id_parent_category').'&view'.$this->table);
}
// redirect to default category listing
Tools::redirectAdmin($this->context->link->getAdminLink('AdminJXBlogCategories').'&conf=4');
}
} elseif (Tools::isSubmit('confirmDelete') && $id_jxblog_category = Tools::getValue('id_jxblog_category')) {
$post = new JXBlogPost();
$category = new JXBlogCategory($id_jxblog_category);
switch (Tools::getValue('deleteAction')) {
case 1:
$this->removeCategoryWithChildrenAction($this->helper->buildTree($id_jxblog_category));
$post->resetDefaultCategory($id_jxblog_category);
break;
case 2:
$this->removeCategoryWithChildrenAction($this->helper->buildTree($id_jxblog_category), 'remove');
$posts = $post->getPostsByDefaultCategory($id_jxblog_category);
if ($posts) {
foreach ($posts as $post) {
$post = new JXBlogPost($post['id_jxblog_post']);
$post->delete();
}
}
break;
case 3:
// remove category's posts
$posts = $post->getPostsByDefaultCategory($id_jxblog_category);
if ($posts) {
foreach ($posts as $post) {
$post = new JXBlogPost($post['id_jxblog_post']);
$post->delete();
}
}
$childrenCategories = JXBlogCategory::getChildrenCategories($id_jxblog_category);
// set all related categories to the home category
if ($childrenCategories) {
foreach ($childrenCategories as $childrenCategory) {
$chCategory = new JXBlogCategory($childrenCategory['id_category']);
$chCategory->id_parent_category = 2;
$chCategory->position = $chCategory->getNewPosition();
$chCategory->update();
}
}
break;
case 4:
$post->resetDefaultCategory($id_jxblog_category, Tools::getValue('newDefaultCategory'));
$childrenCategories = JXBlogCategory::getChildrenCategories($id_jxblog_category);
if ($childrenCategories) {
foreach ($childrenCategories as $childrenCategory) {
$chCategory = new JXBlogCategory($childrenCategory['id_category']);
$chCategory->id_parent_category = Tools::getValue('newDefaultCategory');
$chCategory->position = $chCategory->getNewPosition();
$chCategory->update();
}
}
break;
}
$category->delete();
if (!$this->errors) {
if (Tools::getValue('deleteAction') == 4 && Tools::getValue('newDefaultCategory')) {
//redirent to the parent category listing and avoid wrong redirection if parent category is one of the default
Tools::redirectAdmin($this->context->link->getAdminLink('AdminJXBlogCategories').'&conf=1&id_jxblog_category='.Tools::getValue('newDefaultCategory').'&view'.$this->table);
}
// redirect to default category listing
Tools::redirectAdmin($this->context->link->getAdminLink('AdminJXBlogCategories').'&conf=1');
}
} elseif (!Tools::getIsset('delete'.$this->table)) {
parent::postProcess();
}
}
public function ajaxProcessStatusjxblogCategory()
{
if (!$id_category = (int)Tools::getValue('id_jxblog_category')) {
die(json_encode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status'))));
} else {
$category = new JXBlogCategory((int)$id_category);
if (Validate::isLoadedObject($category)) {
$category->active = $category->active == 1 ? 0 : 1;
$category->save() ?
die(json_encode(array('success' => true, 'text' => $this->l('The status has been updated successfully')))) :
die(json_encode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status'))));
}
}
}
public function ajaxProcessUpdatePositions()
{
$id_category_to_move = (int)Tools::getValue('id');
$way = (int)Tools::getValue('way');
$positions = Tools::getValue('jxblog_category');
if (is_array($positions)) {
foreach ($positions as $key => $value) {
$pos = explode('_', $value);
if (isset($pos[2]) && $pos[2] == $id_category_to_move) {
$position = $key;
break;
}
}
}
$category = new JXBlogCategory($id_category_to_move);
if (Validate::isLoadedObject($category)) {
if (isset($position) && $category->updatePosition($way, $position)) {
die(true);
} else {
die('{"hasError" : true, errors : "Cannot update categories position"}');
}
} else {
die('{"hasError" : true, "errors" : "This category cannot be loaded"}');
}
}
/**
* Remove category and manage related data depending on the selected action
*
* @param $list
* @param string $action
*
* @return bool
*/
private function removeCategoryWithChildrenAction($list, $action = 'reset')
{
$result = true;
$post = new JXBlogPost();
if (is_array($list) && count($list)) {
foreach ($list as $item) {
if (isset($item['children']) && is_array($item['children'])) {
$this->removeCategoryWithChildrenAction($item['children'], $action);
}
$category = new JXBlogCategory($item['id_category']);
// if we want to delete children categories but want to save all post that are related we need to set posts to default category
if ($action == 'reset') {
$result &= $post->resetDefaultCategory($category->id_jxblog_category);
//if we want to remove categories with related posts
} elseif ($action == 'remove') {
$posts = $post->getPostsByDefaultCategory($category->id_jxblog_category);
if ($posts) {
foreach ($posts as $post) {
$post = new JXBlogPost($post['id_jxblog_post']);
$result &= $post->delete();
}
}
}
$result &= $category->delete();
}
}
return $result;
}
}

View File

@@ -0,0 +1,626 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class AdminJXBlogImagesController extends ModuleAdminController
{
public $translator;
public $imageTypes;
public $imageManager;
public function __construct()
{
$this->translator = Context::getContext()->getTranslator();
$this->table = 'jxblog_image';
$this->list_id = $this->table;
$this->identifier = 'id_jxblog_image';
$this->className = 'JXBlogImage';
$this->module = $this;
$this->lang = false;
$this->bootstrap = true;
$this->context = Context::getContext();
$this->_defaultOrderBy = 'id_jxblog_image';
$this->_defaultOrderWay = 'DESC';
$this->_default_pagination = 10;
$this->_pagination = array(10, 20, 50, 100);
$this->_orderBy = Tools::getValue($this->table.'Orderby');
$this->_orderWay = Tools::getValue($this->table.'Orderway');
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?')
)
);
$this->fields_list = array(
'id_jxblog_image' => array(
'title' => $this->l('ID Image'),
'width' => 100,
'type' => 'text',
'search' => true,
'orderby' => true
),
'name' => array(
'title' => $this->l('Name'),
'width' => 440,
'type' => 'text',
'search' => true,
'orderby' => true,
'lang' => true
),
'width' => array(
'title' => $this->l('Width'),
'width' => 150,
'type' => 'text',
'search' => true,
'orderby' => true,
'lang' => true
),
'height' => array(
'title' => $this->l('Height'),
'width' => 150,
'type' => 'text',
'search' => true,
'orderby' => true,
'lang' => true
),
'category' => array(
'title' => $this->l('Categories'),
'active' => 'category',
'type' => 'bool',
'class' => 'fixed-width-xs',
'align' => 'center',
'ajax' => true,
'orderby' => false
),
'category_thumb' => array(
'title' => $this->l('Categories Thumbnails'),
'active' => 'category_thumb',
'type' => 'bool',
'class' => 'fixed-width-xs',
'align' => 'center',
'ajax' => true,
'orderby' => false
),
'post' => array(
'title' => $this->l('Posts'),
'active' => 'post',
'type' => 'bool',
'class' => 'fixed-width-xs',
'align' => 'center',
'ajax' => true,
'orderby' => false
),
'post_thumb' => array(
'title' => $this->l('Posts Thumbnails'),
'active' => 'post_thumb',
'type' => 'bool',
'class' => 'fixed-width-xs',
'align' => 'center',
'ajax' => true,
'orderby' => false
),
'user' => array(
'title' => $this->l('Users'),
'active' => 'user',
'type' => 'bool',
'class' => 'fixed-width-xs',
'align' => 'center',
'ajax' => true,
'orderby' => false
)
);
$this->languages = Language::getLanguages(false);
$this->default_language = Configuration::get('PS_LANG_DEFAULT');
parent::__construct();
$this->imageManager = new JXBlogImageManager($this->module);
if (!$this->module->active) {
Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome'));
}
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function initContent()
{
$this->content = '';
if (Tools::isSubmit('updateDefaultImages')) {
$this->updateDefaultImages();
$this->regenerateImages('default');
}
if (Tools::isSubmit('regenerateImages')) {
$this->regenerateImages(Tools::getValue('regenerate_type'));
}
if (Tools::getIsset('ajax') && Tools::getValue('ajax')) {
$action = str_replace($this->table, '', Tools::getValue('action'));
$id_image_type = Tools::getValue('id_jxblog_image');
if (!$id_image_type || !$action) {
die(json_encode(array('success' => false, 'error' => true, 'text' => $this->l('Failed to update the status'))));
}
$this->ajaxUpdate($action, $id_image_type);
} else {
if ($this->display == 'edit' || $this->display == 'add') {
$this->content .= $this->renderForm();
} else {
$this->content .= $this->renderList();
$this->content .= $this->renderRegenerateForm();
$this->content .= $this->renderDefaultImagesForm();
}
$this->context->smarty->assign(
array(
'content' => $this->content,
'url_post' => self::$currentIndex.'&token='.$this->token,
'show_page_header_toolbar' => $this->show_page_header_toolbar,
'page_header_toolbar_title' => $this->page_header_toolbar_title,
'page_header_toolbar_btn' => $this->page_header_toolbar_btn
)
);
}
}
public function renderForm()
{
$this->fields_form = array(
'input' => array(
array(
'type' => 'text',
'hint' => $this->l('Letters, underscores and hyphens only (e.g. "small_custom", "post_medium", "large", "thickbox_extra-large").'),
'label' => $this->l('Name'),
'name' => 'name',
'required' => true,
'desc' => $this->l('Enter the image type name'),
'col' => 3
),
array(
'type' => 'text',
'label' => $this->l('Width'),
'hint' => $this->l('Maximum image width in pixels.'),
'name' => 'width',
'required' => true,
'desc' => $this->l('Enter the image type width'),
'col' => 3,
'suffix' => $this->l('px')
),
array(
'type' => 'text',
'label' => $this->l('Height'),
'hint' => $this->l('Maximum image height in pixels.'),
'name' => 'height',
'required' => true,
'desc' => $this->l('Enter the image type height'),
'col' => 3,
'suffix' => $this->l('px')
),
array(
'type' => 'switch',
'label' => $this->l('Categories'),
'hint' => $this->l('This type will be used for Blog categories images.'),
'name' => 'category',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'switch',
'label' => $this->l('Categories Thumbnails'),
'hint' => $this->l('This type will be used for Blog categories thumbnails images.'),
'name' => 'category_thumb',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'switch',
'label' => $this->l('Posts'),
'hint' => $this->l('This type will be used for Blog posts images.'),
'name' => 'post',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'switch',
'label' => $this->l('Posts Thumbnails'),
'hint' => $this->l('This type will be used for Blog posts thumbnails.'),
'name' => 'post_thumb',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'switch',
'label' => $this->l('Blog users'),
'hint' => $this->l('This type will be used for not registered Blog users.'),
'name' => 'user',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button pull-right btn btn-default'
)
);
return parent::renderForm();
}
public function renderDefaultImagesForm()
{
$defaultImages = $this->getDefaultImages();
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Default images')
),
'input' => array(
array(
'type' => 'multilingual_image',
'name' => 'image_default',
'label' => $this->l('Default image'),
'hint' => $this->l('Upload default image.'),
'folder' => false,
'images' => $defaultImages['image_default']
),
array(
'type' => 'multilingual_image',
'name' => 'image_category',
'label' => $this->l('Categories default image'),
'hint' => $this->l('Upload default image for categories.'),
'folder' => 'c',
'images' => $defaultImages['image_category']
),
array(
'type' => 'multilingual_image',
'name' => 'image_category_thumb',
'label' => $this->l('Categories thumbnails default image'),
'hint' => $this->l('Upload default image for categories thumbnails.'),
'folder' => 'ct',
'images' => $defaultImages['image_category_thumb']
),
array(
'type' => 'multilingual_image',
'name' => 'image_post',
'label' => $this->l('Posts default image'),
'hint' => $this->l('Upload default image for posts.'),
'folder' => 'p',
'images' => $defaultImages['image_post']
),
array(
'type' => 'multilingual_image',
'name' => 'image_post_thumb',
'label' => $this->l('Posts thumbnail default image'),
'hint' => $this->l('Upload default image for posts thumbnails.'),
'folder' => 'pt',
'images' => $defaultImages['image_post_thumb']
),
array(
'type' => 'multilingual_image',
'name' => 'image_user',
'label' => $this->l('Users default image'),
'hint' => $this->l('Upload default image for users.'),
'folder' => 'u',
'images' => $defaultImages['image_user']
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button pull-right btn btn-default',
'name' => 'updateDefaultImages',
'id' => ''
)
);
// add extra fields from related modules
$extraFields = array_values(Hook::exec('displayJxblogImageManagerExtra', array(), null, true));
if ($extraFields) {
foreach ($extraFields[0] as $filed) {
$this->fields_form['input'][] = $filed;
}
}
return parent::renderForm();
}
public function renderRegenerateForm()
{
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Regenerate images')
),
'input' => array(
array(
'type' => 'select',
'name' => 'regenerate_type',
'label' => $this->l('Select images type to regenerate'),
'desc' => $this->l('All images will regenerated. All old images will be lost.'),
'options' => array(
'query' => array(
array(
'id' => 'all',
'type' => $this->l('All')
),
array(
'id' => 'category',
'type' => $this->l('Categories')
),
array(
'id' => 'category_thumb',
'type' => $this->l('Categories thumbnails')
),
array(
'id' => 'post',
'type' => $this->l('Posts')
),
array(
'id' => 'post_thumb',
'type' => $this->l('Posts thumbnails')
),
array(
'id' => 'user',
'type' => $this->l('Users')
)
),
'id' => 'id',
'name' => 'type'
)
)
),
'submit' => array(
'title' => $this->l('Regenerate'),
'class' => 'button pull-right btn btn-default',
'id' => 'regenerate-images',
'name' => 'regenerateImages'
)
);
return parent::renderForm();
}
public function validateRules($class_name = false)
{
// check if this image type name is not already used
if (!Tools::isEmpty(Tools::getValue('name')) && JXBlogImage::checkIfNameExists(Tools::getValue('name'), Tools::getValue('id_jxblog_image'))) {
$this->errors[] = $this->l('The image type with this name already exists, you can\'t use the same name more than once.');
}
parent::validateRules();
}
public function postProcess()
{
$id_jxblog_image = Tools::getValue('id_jxblog_image');
if (!Tools::isSubmit('updateDefaultImages') && !Tools::isSubmit('regenerateImages') && Tools::isSubmit('submitAddjxblog_image')) {
// remove all old images related to current image type in order to delete images if they are no more related to this type after saving
if ($this->module->imagesAutoRegenerate && $id_jxblog_image && !$this->imageManager->removeImageTypeImages($id_jxblog_image)) {
$this->errors[] = $this->lang('Fail to remove old images', array(), 'Modules.JXBlog.Admin');
}
$this->validateRules(false);
if (count($this->errors)) {
parent::postProcess();
return false;
}
if ($id_jxblog_image = Tools::getValue('id_jxblog_image')) {
$blogimage = new JXBlogImage($id_jxblog_image);
} else {
$blogimage = new JXBlogImage();
}
$blogimage->name = Tools::getValue('name');
$blogimage->width = Tools::getValue('width');
$blogimage->height = Tools::getValue('height');
$blogimage->category = Tools::getValue('category');
$blogimage->category_thumb = Tools::getValue('category_thumb');
$blogimage->post = Tools::getValue('post');
$blogimage->post_thumb = Tools::getValue('post_thumb');
$blogimage->user = Tools::getValue('user');
if (!$blogimage->save()) {
$this->errors[] = $this->lang('An error occurred during object regeneration', array(), 'Modules.JXBlog.Admin');
} else {
$result = true;
// check if images auto regeneration option is enabled
if ($this->module->imagesAutoRegenerate) {
foreach (array_keys($this->module->imageTypes) as $imageType) {
if ($imageType == 'default' || ($imageType != 'default' && $blogimage->$imageType)) {
$result &= $this->imageManager->regenerateTypeImages($imageType, false, $blogimage->name);
}
}
}
if (!$result) {
$this->errors[] = $this->lang('An error occurred during images regeneration', array(), 'Modules.JXBlog.Admin');
} else {
Tools::redirectAdmin($this->context->link->getAdminLink('AdminJXBlogImages').'&conf=4');
}
}
} elseif (!Tools::isSubmit('updateDefaultImages') && !Tools::isSubmit('regenerateImages')) {
parent::postProcess();
}
}
/**
* Update status for image content type
*
* @param $action
* @param $id_image_type
*/
public function ajaxUpdate($action, $id_image_type)
{
$image = new JXBlogImage((int)$id_image_type);
if (Validate::isLoadedObject($image)) {
$image->$action = $image->$action == 1 ? 0 : 1;
if ($image->save()) {
// check if images auto regeneration option is enabled
if ($this->module->imagesAutoRegenerate) {
if ($image->$action) {
if (!$this->imageManager->regenerateTypeImages($action, false, $image->name)) {
die(json_encode(
array(
'success' => false,
'text' => $this->l('The status has been updated successfully but images were not generated properly. Please, regenerate it manually.')
)
));
}
} else {
if (!$this->imageManager->removeImageTypeImages($image->id, $action)) {
die(json_encode(
array(
'success' => false,
'text' => $this->l('The status has been updated successfully but images were not removed properly. Please, regenerate it manually.')
)
));
}
}
}
die(json_encode(
array(
'success' => true,
'text' => $this->l('The status has been updated successfully')
)
));
} else {
die(json_encode(
array(
'success' => false,
'error' => true,
'text' => $this->l('Failed to update the status')
)
));
}
}
}
public function updateDefaultImages()
{
$errors = array();
foreach ($this->module->imageTypes as $key => $type) {
foreach ($this->languages as $language) {
if (Tools::getValue('image_'.$key.'_'.$language['id_lang'])) {
if ($error = $this->imageManager->uploadImage($language['iso_code'], $_FILES['image_'.$key.'_'.$language['id_lang']], $key)) {
$errors[] = $error;
}
}
}
}
Hook::exec('actionUpdateJxblogImages', array('values' => Tools::getAllValues(), 'images' => $_FILES));
if (count($errors)) {
$this->errors[] = $errors;
}
$this->confirmations[] = $this->l('Everything is cool!');
}
public function getDefaultImages()
{
$defaultImages = array();
foreach ($this->module->imageTypes as $key => $type) {
foreach ($this->languages as $language) {
$defaultImages['image_'.$key][$language['id_lang']] = false;
if ($key == 'default') {
if (file_exists($this->module->modulePath.'img/'.$language['iso_code'].'.jpg')) {
$defaultImages['image_'.$key][$language['id_lang']] = $this->module->_link.'img/'.$language['iso_code'].'.jpg';
}
} else {
if (file_exists($this->module->modulePath.'img/'.$type[0].$language['iso_code'].'.jpg')) {
$defaultImages['image_'.$key][$language['id_lang']] = $this->module->_link.'img/'.$type[0].$language['iso_code'].'.jpg';
}
}
}
}
return $defaultImages;
}
/**
* Launch images regeneration
*
* @param $type
*/
public function regenerateImages($type)
{
$result = true;
if ($type == 'all') {
$result &= $this->imageManager->regenerateTypeImages('default');
$result &= $this->imageManager->regenerateTypeImages('category');
$result &= $this->imageManager->regenerateTypeImages('category_thumb');
$result &= $this->imageManager->regenerateTypeImages('post');
$result &= $this->imageManager->regenerateTypeImages('post_thumb');
$result &= $this->imageManager->regenerateTypeImages('user');
} else {
$result &= $this->imageManager->regenerateTypeImages($type);
}
if (!$result) {
$this->errors[] = $this->l('An error occurred during the images regeneration');
} else {
$this->confirmations[] = $this->l('All images are regenerated successfully');
}
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class AdminJXBlogMainSettingsController extends AdminController
{
public function __construct()
{
$this->bootstrap = true;
parent::__construct();
$this->fields_options = array(
'general' => array(
'title' => $this->l('Comments settings '),
'fields' => array(
'JXBLOG_IMAGES_AUTO_REGENERATION' => array(
'title' => $this->l('Image regeneration'),
'desc' => $this->l('Regenerate images automatically after each changing?'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
'default' => '0'
),
'JXBLOG_DISPLAY_BLOG_PAGE' => array(
'title' => $this->l('Display Blog main page'),
'desc' => $this->l(
'Display Blog main page with all blog content listed instead of Blog category page'
),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
'default' => '0'
),
'JXBLOG_DISPLAY_PRODUCTS_ON_BLOG_PAGE' => array(
'title' => $this->l('Display Products on Blog main page'),
'desc' => $this->l('Display products on Blog main page after all blog content listed'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
'default' => '0'
),
'JXBLOG_DISPLAY_POST_AUTHOR' => array(
'title' => $this->l('Display author'),
'desc' => $this->l('Display an author of the post on the front-end?'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
'default' => '0'
),
'JXBLOG_DISPLAY_POST_VIEWS' => array(
'title' => $this->l('Display views'),
'desc' => $this->l('Display on the front-end how many times the post has been viewed?'),
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool',
'default' => '0'
),
'JXBLOG_POSTS_PER_PAGE' => array(
'title' => $this->l('Items per page'),
'desc' => $this->l('How many items will be displayed in listings on the front page?'),
'validation' => 'isInt',
'type' => 'text',
'default' => '6'
)
),
'submit' => array(
'title' => $this->l('Save')
)
)
);
}
}

View File

@@ -0,0 +1,402 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class AdminJXBlogPostsController extends ModuleAdminController
{
public $categories = false;
protected $helper;
public function __construct()
{
$this->table = 'jxblog_post';
$this->list_id = $this->table;
$this->identifier = 'id_jxblog_post';
$this->className = 'JXBlogPost';
$this->module = $this;
$this->lang = true;
$this->bootstrap = true;
$this->languages = Language::getLanguages(false);
$this->default_language = Configuration::get('PS_LANG_DEFAULT');
$this->context = Context::getContext();
$this->_defaultOrderBy = 'a.id_jxblog_post';
$this->_defaultOrderWay = 'ASC';
$this->_default_pagination = 10;
$this->_pagination = array(10, 20, 50, 100);
$this->_orderBy = Tools::getValue($this->table.'Orderby');
$this->_orderWay = Tools::getValue($this->table.'Orderway');
$this->imageDir = '../modules/jxblog/img/p/';
$this->translator = Context::getContext()->getTranslator();
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?')
)
);
$this->fields_list = array(
'id_jxblog_post' => array(
'title' => $this->l('ID Post'),
'width' => 50,
'type' => 'text',
'search' => true,
'orderby' => true
),
'image' => array(
'title' => $this->l('Image'),
'image' => $this->imageDir,
'width' => 150,
'align' => 'center',
'orderby' => false,
'filter' => false,
'search' => false
),
'name' => array(
'title' => $this->l('Name'),
'width' => 300,
'type' => 'text',
'search' => true,
'orderby' => true,
'lang' => true,
'filter_key' => 'b!name'
),
'category_name' => array(
'title' => $this->l('Default category'),
'width' => 300,
'type' => 'text',
'search' => true,
'orderby' => true,
'lang' => true,
'filter_key' => 'cl!name'
),
'employee_last_name' => array(
'title' => $this->l('Author'),
'width' => 300,
'type' => 'text',
'search' => true,
'orderby' => true,
'lang' => true,
'filter_key' => 'e!firstname'
),
'views' => array(
'title' => $this->l('Views'),
'type' => 'text',
'search' => true,
'orderby' => true,
'lang' => true
),
'date_add' => array(
'title' => $this->l('Date added'),
'width' => 100,
'type' => 'datetime',
'search' => true,
'orderby' => true
),
'date_start' => array(
'title' => $this->l('Posted date'),
'width' => 100,
'type' => 'datetime',
'search' => true,
'orderby' => true
),
'active' => array(
'title' => $this->l('Active'),
'active' => 'status',
'type' => 'bool',
'class' => 'fixed-width-xs',
'align' => 'center',
'ajax' => true,
'orderby' => false
)
);
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'jxblog_category_lang` cl ON(a.`id_jxblog_category_default` = cl.`id_jxblog_category` AND cl.`id_lang` = '.$this->context->language->id.')';
$this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'employee` e ON(a.`author` = e.`id_employee`)';
$this->_select = 'cl.`name` as `category_name`, CONCAT(e.`lastname`," ",e.`firstname`) as `employee_last_name`';
parent::__construct();
if (!$this->module->active) {
Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome'));
}
$this->helper = new HelperBlog();
}
public function setMedia($isNewTheme = false)
{
$this->context->controller->addJquery();
$this->context->controller->addJqueryUI('ui.widget');
$this->context->controller->addJqueryPlugin(array('tagify'));
$this->context->controller->addJs($this->module->modulePath.'views/js/jxblog_admin.js');
$this->context->controller->addCss($this->module->modulePath.'views/css/jxblog_admin.css');
parent::setMedia($isNewTheme);
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function initContent()
{
if (!$this->categories = JXBlogCategory::getAllCategoriesWithInfo()) {
return $this->errors[] = $this->l('There are no categories in the blog. To create a post you need to create at least one category before.');
}
return parent::initContent();
}
public function renderForm()
{
$categoriesTree = $this->helper->buildTree();
$image = false;
$thumb = false;
if (Tools::getIsset('id_jxblog_post') && $id_jxblog_post = Tools::getValue('id_jxblog_post')) {
if (file_exists($this->module->modulePath.'img/p/'.$id_jxblog_post.'.jpg')) {
$image = '<img class="imgm img-thumbnail" src="'.$this->module->_link.'img/p/'.$id_jxblog_post.'.jpg" width="300" />';
}
}
if (isset($id_jxblog_post)) {
if (file_exists($this->module->modulePath.'img/pt/'.$id_jxblog_post.'.jpg')) {
$thumb = '<img class="imgm img-thumbnail" src="'.$this->module->_link.'img/pt/'.$id_jxblog_post.'.jpg" width="300" />';
}
}
if (Tools::getIsset('id_jxblog_post') && $id_jxblog_post = Tools::getValue('id_jxblog_post')) {
$post = new JXBlogPost($id_jxblog_post);
}
$defaultList = array();
foreach ($this->categories as $key => $category) {
if ($category['id_jxblog_category'] > 1) {
$defaultList[$key]['id'] = $category['id_jxblog_category'];
$defaultList[$key]['name'] = $category['name'];
}
}
$this->fields_form = array(
'input' => array(
array(
'type' => 'text',
'required' => true,
'class' => 'copy2friendlyUrl',
'label' => $this->l('Post name'),
'hint' => $this->l('Invalid characters: &lt;&gt;;=#{}'),
'desc' => $this->l('Enter the blog post name'),
'name' => 'name',
'lang' => true,
'col' => 4
),
array(
'type' => 'text',
'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.'),
'label' => $this->l('Friendly URL'),
'name' => 'link_rewrite',
'required' => true,
'desc' => $this->l('Enter the blog post friendly URL. Will be used as a link to the post in the "Friendly URL" mode'),
'lang' => true,
'col' => 3
),
array(
'type' => 'textarea',
'label' => $this->l('Short description'),
'name' => 'short_description',
'desc' => $this->l('Enter the post short description'),
'lang' => true,
'col' => 6,
'autoload_rte' => true
),
array(
'type' => 'textarea',
'label' => $this->l('Full description'),
'name' => 'description',
'desc' => $this->l('Enter the post full description'),
'lang' => true,
'col' => 6,
'autoload_rte' => true
),
array(
'type' => 'text',
'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.'),
'label' => $this->l('Meta Keywords'),
'name' => 'meta_keyword',
'desc' => $this->l('Enter Your Post Meta Keywords. Separated by comma(,)'),
'lang' => true,
'col' => 6
),
array(
'type' => 'textarea',
'label' => $this->l('Meta Description'),
'name' => 'meta_description',
'desc' => $this->l('Enter the post meta description'),
'lang' => true,
'col' => 6,
'autoload_rte' => false
),
array(
'type' => 'file',
'label' => $this->l('Post image'),
'name' => 'image',
'display_image' => true,
'image' => $image ? $image : false,
'desc' => $this->l('Only .jpg images are allowed')
),
array(
'type' => 'file',
'label' => $this->l('Post thumb'),
'name' => 'thumbnail',
'display_image' => true,
'image' => $thumb ? $thumb : false,
'desc' => $this->l('Only .jpg images are allowed')
),
array(
'type' => 'switch',
'label' => $this->l('Status'),
'name' => 'active',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'select',
'label' => $this->l('Default category'),
'name' => 'id_jxblog_category_default',
'required' => true,
'options' => array(
'query' => $defaultList,
'id' => 'id',
'name' => 'name'
)
),
array(
'type' => 'categories',
'label' => $this->l('Associated categories'),
'name' => 'jxcategoryBox',
'tree' => array(
'id' => 'blog-categories-tree',
'selected_categories' => isset($post) ? $post->getAssociatedCategories() : array(),
'root_category' => 1,
'set_data' => $categoriesTree,
'use_search' => true,
'use_checkbox' => true
)
),
array(
'type' => 'tags',
'name' => 'tags',
'label' => $this->l('Post tags'),
'lang' => true,
'hint' => $this->l('To add "tags," click in the field, write something, and then press "Enter."').'&nbsp;'.$this->l('Forbidden characters:').' <>;=#{}'
),
array(
'type' => 'datetime',
'name' => 'date_start',
'label' => $this->l('Publishing date'),
'desc' => $this->l('Set the date if you want to delay the article publishing.')
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button pull-right btn btn-default'
)
);
$extraData = array_values(Hook::exec('displayJxblogPostExtra', array('post' => isset($post) ? $post : false), null, true));
// add all necessary data from related modules
if ($extraData) {
foreach ($extraData as $extra) {
$extraFields = $extra['fields'];
$extraValues = $extra['values'];
foreach ($extraFields as $filed) {
$this->fields_form['input'][] = $filed;
}
foreach ($extraValues as $key => $filed) {
$this->fields_value[$key] = $filed;
}
}
}
$this->fields_value['tags'] = isset($post) ? $post->getAdminPostTags() : false;
if (!($JXBlogPost = $this->loadObject(true))) {
return;
}
return parent::renderForm();
}
public function ajaxProcessSearchPosts()
{
$excludeIds = array();
$exclude = explode(',', Tools::getValue('excludeIds'));
foreach ($exclude as $item) {
if ($item) {
$excludeIds[] = $item;
}
}
$posts = JXBlogPost::searchPostsLive(Tools::getValue('q'), $this->context->language->id, Tools::getValue('limit'), $excludeIds);
if ($posts) {
die(implode("\n", $posts));
}
}
public function ajaxProcessStatusjxblogPost()
{
if (!$id_post = (int)Tools::getValue('id_jxblog_post')) {
die(json_encode(
array(
'success' => false,
'error' => true,
'text' => $this->l('Failed to update the status')
)
));
} else {
$post = new JXBlogPost((int)$id_post);
if (Validate::isLoadedObject($post)) {
$post->active = $post->active == 1 ? 0 : 1;
$post->save() ?
die(json_encode(
array(
'success' => true,
'text' => $this->l('The status has been updated successfully')
)
)) :
die(json_encode(
array(
'success' => false,
'error' => true,
'text' => $this->l('Failed to update the status')
)
));
}
}
}
}

View File

@@ -0,0 +1,9 @@
drwxr-xr-x 2 30094 users 9 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 4 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 2666 Aug 31 2021 author.php
-rw-r--r-- 1 30094 users 2778 Aug 31 2021 blog.php
-rw-r--r-- 1 30094 users 2331 Aug 31 2021 categories.php
-rw-r--r-- 1 30094 users 3697 Aug 31 2021 category.php
-rw-r--r-- 1 30094 users 2903 Aug 31 2021 post.php
-rw-r--r-- 1 30094 users 4849 Aug 31 2021 search.php
-rw-r--r-- 1 30094 users 2598 Aug 31 2021 tag.php

View File

@@ -0,0 +1,79 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class JxblogAuthorModuleFrontController extends ModuleFrontController
{
public $pagename = 'author';
public $author;
public $page = 1;
public $itemPerPage = 6;
public function __construct()
{
if (Tools::getIsset('page') && $page = Tools::getValue('page')) {
$this->page = $page;
}
parent::__construct();
$this->itemPerPage = Configuration::get('JXBLOG_POSTS_PER_PAGE');
$this->author = new Employee(Tools::getValue('author'));
}
public function initContent()
{
parent::initContent();
$pagination = false;
$posts = false;
if ($this->author) {
$posts = JXBlogPost::getPostsByAuthor($this->author->id, $this->context->language->id, $this->page, $this->itemPerPage);
$pagination = $this->module->buildPagination(
'apagination',
JXBlogPost::countPostsByAuthor($this->author->id),
$this->page,
$this->itemPerPage,
$this->author->id,
''
);
}
$this->context->smarty->assign(
array(
'author' => $this->author,
'posts' => $posts,
'pagination' => $pagination,
'displayViews' => Configuration::get('JXBLOG_DISPLAY_POST_VIEWS'),
'displayAuthor' => Configuration::get('JXBLOG_DISPLAY_POST_AUTHOR')
)
);
$this->setTemplate('module:jxblog/views/templates/front/author.tpl');
}
public function getBreadcrumbLinks()
{
$link = new Link();
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array('title' => $this->module->translator('all_categories'), 'url' => $link->getModuleLink('jxblog', 'categories'));
$breadcrumb['links'][] = array('title' => $this->author->firstname.' '.$this->author->lastname, 'url' => $link->getModuleLink('jxblog', 'author', array('author' => $this->author->id)));
return $breadcrumb;
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class JxblogBlogModuleFrontController extends ModuleFrontController
{
public $pagename = 'blog';
public $itemPerPage = 1;
public $page = 1;
public function __construct()
{
// if this page is terned off redirect to default page
if (!Configuration::get('JXBLOG_DISPLAY_BLOG_PAGE')) {
$link = new Link();
Tools::redirect($link->getModuleLink('jxblog', 'categories'));
}
if (Tools::getIsset('page') && $page = Tools::getValue('page')) {
$this->page = $page;
}
parent::__construct();
$this->itemPerPage = Configuration::get('JXBLOG_POSTS_PER_PAGE');
}
public function initContent()
{
parent::initContent();
$pagination = false;
$categories = JXBlogCategory::getAllFrontCategories(
2,
$this->context->language->id,
$this->context->shop->id,
$this->context->customer->id_default_group,
1,
1000
);
$posts = JXBlogPost::getAllPosts($this->context->language->id, $this->context->shop->id, $this->context->customer->id_default_group, $this->page, $this->itemPerPage);
if ($posts) {
$pagination = $this->module->buildPagination(
'bpagination',
JXBlogPost::countAllPosts(
2,
$this->context->shop->id,
$this->context->customer->id_default_group
),
$this->page,
$this->itemPerPage
);
}
$this->context->smarty->assign(
array(
'categories' => $categories,
'posts' => $posts,
'pagination' => $pagination
)
);
$this->setTemplate('module:jxblog/views/templates/front/blog.tpl');
}
public function getBreadcrumbLinks()
{
$link = new Link();
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array('title' => $this->module->translator('blog'), 'url' => $link->getModuleLink('jxblog', 'blog'));
return $breadcrumb;
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class JxblogCategoriesModuleFrontController extends ModuleFrontController
{
public $pagename = 'categories';
public $itemPerPage = 6;
public $page = 1;
public function __construct()
{
if (Tools::getIsset('page') && $page = Tools::getValue('page')) {
$this->page = $page;
}
parent::__construct();
$this->itemPerPage = Configuration::get('JXBLOG_POSTS_PER_PAGE');
}
public function initContent()
{
parent::initContent();
$pagination = false;
$categories = JXBlogCategory::getAllFrontCategories(
2,
$this->context->language->id,
$this->context->shop->id,
$this->context->customer->id_default_group,
$this->page,
$this->itemPerPage
);
if ($categories) {
$pagination = $this->module->buildPagination(
'cpagination',
JXBlogCategory::countFrontCategories(
2,
$this->context->shop->id,
$this->context->customer->id_default_group
),
$this->page,
$this->itemPerPage
);
}
$this->context->smarty->assign(
array(
'categories' => $categories,
'pagination' => $pagination
)
);
$this->setTemplate('module:jxblog/views/templates/front/categories.tpl');
}
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array('title' => $this->module->translator('all_categories'), 'url' => '');
return $breadcrumb;
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class JxblogCategoryModuleFrontController extends ModuleFrontController
{
public $pagename = 'category';
public $category;
public $page = 1;
public $itemPerPage = 6;
public $helper;
public function __construct()
{
if (Tools::getIsset('page') && $page = Tools::getValue('page')) {
$this->page = $page;
}
parent::__construct();
$this->itemPerPage = Configuration::get('JXBLOG_POSTS_PER_PAGE');
$this->category = new JXBlogCategory(Tools::getValue('id_jxblog_category'), $this->context->language->id);
$this->helper = new HelperBlog();
$this->helper->buildBreadCrumbs($this->category->id_jxblog_category, 2);
}
public function initContent()
{
parent::initContent();
$pagination = false;
$posts = false;
$category = JXBlogCategory::getCategory($this->category->id, $this->context->language->id, $this->context->shop->id, $this->context->customer->id_default_group)[0];
$subCategories = JXBlogCategory::getSubCategories(
$this->category->id,
$this->context->language->id,
$this->context->shop->id,
$this->context->customer->id_default_group
);
if ($category) {
$posts = JXBlogPost::getPostsByCategory($this->category->id, $this->context->language->id, $this->page, $this->itemPerPage);
$pagination = $this->module->buildPagination(
'pagination',
JXBlogPost::countPostsByCategory($this->category->id),
$this->page,
$this->itemPerPage,
$this->category->id,
$this->category->link_rewrite
);
}
$this->context->smarty->assign(
array(
'category' => $category,
'sub_categories' => $subCategories,
'posts' => $posts,
'pagination' => $pagination,
'displayViews' => Configuration::get('JXBLOG_DISPLAY_POST_VIEWS'),
'displayAuthor' => Configuration::get('JXBLOG_DISPLAY_POST_AUTHOR')
)
);
$this->setTemplate('module:jxblog/views/templates/front/category.tpl');
}
public function getBreadcrumbLinks()
{
$link = new Link();
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array('title' => $this->module->translator('all_categories'), 'url' => $link->getModuleLink('jxblog', 'categories'));
foreach ($this->helper->getBreadCrumbs() as $item) {
// exclude home and root categories
$breadcrumb['links'][] = array(
'title' => $item['name'],
'url' => $link->getModuleLink(
'jxblog',
'category',
array(
'id_jxblog_category' => $item['id_jxblog_category'],
'rewrite' => $item['link_rewrite']
)
)
);
}
return $breadcrumb;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class JxblogPostModuleFrontController extends ModuleFrontController
{
public $pagename = 'jxblogpost';
public $post;
protected $helper;
public function __construct()
{
$this->helper = new HelperBlog();
parent::__construct();
$this->post = new JXBlogPost(Tools::getValue('id_jxblog_post'), $this->context->language->id);
$this->helper->buildBreadCrumbs($this->post->id_jxblog_category_default, 2);
}
public function initContent()
{
parent::initContent();
JXBlogPost::postViewed($this->post->id);
$post = JXBlogPost::getPost($this->post->id, $this->context->language->id, $this->context->shop->id, $this->context->customer->id_default_group);
if ($post) {
$post = $post[0];
}
$this->context->smarty->assign(
array(
'post' => $post,
'tags' => JXBlogPost::getPostTags($this->post->id, $this->context->language->id),
'displayViews' => Configuration::get('JXBLOG_DISPLAY_POST_VIEWS'),
'displayAuthor' => Configuration::get('JXBLOG_DISPLAY_POST_AUTHOR')
)
);
$this->setTemplate('module:jxblog/views/templates/front/post.tpl');
}
public function getBreadcrumbLinks()
{
$link = new Link();
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array('title' => $this->module->translator('all_categories'), 'url' => $link->getModuleLink('jxblog', 'categories'));
foreach ($this->helper->getBreadCrumbs() as $item) {
// exclude home and root categories
$breadcrumb['links'][] = array(
'title' => $item['name'],
'url' => $link->getModuleLink(
'jxblog',
'category',
array(
'id_jxblog_category' => $item['id_jxblog_category'],
'rewrite' => $item['link_rewrite']
)
)
);
}
$breadcrumb['links'][] = array('title' => $this->post->name, 'url' => $link->getModuleLink('jxblog', 'post', array('id_jxblog_post' => $this->post->id, 'rewrite' => $this->post->link_rewrite)));
return $breadcrumb;
}
}

View File

@@ -0,0 +1,138 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class JxblogSearchModuleFrontController extends ModuleFrontController
{
public $pagename = 'search';
public $query;
public $category;
public $page = 1;
public $itemPerPage = 6;
public function __construct()
{
if (Tools::getIsset('page') && $page = Tools::getValue('page')) {
$this->page = $page;
}
parent::__construct();
$this->itemPerPage = Configuration::get('JXBLOG_POSTS_PER_PAGE');
$this->query = Tools::getValue('blog_search_query');
$this->category = Tools::getValue('search_blog_categories');
}
public function initContent()
{
$query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
if (Tools::getValue('ajax')) {
$this->getAjaxSearch($query);
} else {
parent::initContent();
$pagination = false;
$posts = false;
if ($this->query) {
$posts = JXBlogPost::search(
$this->query,
$this->category,
$this->context->language->id,
$this->context->shop->id,
$this->context->customer->id_default_group,
$this->page,
$this->itemPerPage
);
$pagination = $this->module->buildPagination(
'spagination',
JXBlogPost::countPostsBySearch(
$this->query,
$this->category,
$this->context->language->id,
$this->context->shop->id,
$this->context->customer->id_default_group
),
$this->page,
$this->itemPerPage,
'',
''
);
$currentCategoryName = '';
if ($this->category) {
$currentCategory = new JXBlogCategory($this->category, $this->context->language->id);
$currentCategoryName = $currentCategory->name;
}
}
$this->context->smarty->assign(
array(
'blog_search_query' => $this->query,
'posts' => $posts,
'pagination' => $pagination,
'active_blog_category' => $currentCategoryName,
'displayViews' => Configuration::get('JXBLOG_DISPLAY_POST_VIEWS'),
'displayAuthor' => Configuration::get('JXBLOG_DISPLAY_POST_AUTHOR')
)
);
$this->setTemplate('module:jxblog/views/templates/front/search.tpl');
}
}
public function getBreadcrumbLinks()
{
$link = new Link();
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array('title' => $this->module->translator('all_categories'), 'url' => $link->getModuleLink('jxblog', 'categories'));
return $breadcrumb;
}
protected function getAjaxSearch($query)
{
$id_category = (int)Tools::getValue('category');
$posts = JXBlogPost::search(
$query,
$id_category,
$this->context->language->id,
$this->context->shop->id,
$this->context->customer->id_default_group,
1,
1000
);
$output = array();
if (count($posts)) {
$jxsearch = new Jxsearch();
$link = new Link();
foreach ($posts as $post) {
$this->context->smarty->assign('post', array(
'info' => $post,
'url' => $link->getModuleLink('jxblog', 'post', array('id_jxblog_post' => $post['id_jxblog_post'], 'rewrite' => $post['link_rewrite'])),
));
$output[] = $jxsearch->display($jxsearch->getLocalPath(), '/views/templates/hook/_items/row-blog.tpl');
}
}
if (!count($output)) {
die(json_encode(array('empty' => $this->l('No post found'))));
}
$total = count($output);
die(json_encode(array('result' => $output, 'total' => $total)));
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* 2017-2018 Zemez
*
* JX Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the General Public License (GPL 2.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/GPL-2.0
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade the module to newer
* versions in the future.
*
* @author Zemez (Alexander Grosul)
* @copyright 2017-2018 Zemez
* @license http://opensource.org/licenses/GPL-2.0 General Public License (GPL 2.0)
*/
class JxblogTagModuleFrontController extends ModuleFrontController
{
public $pagename = 'tag';
public $tag;
public $page = 1;
public $itemPerPage = 6;
public function __construct()
{
if (Tools::getIsset('page') && $page = Tools::getValue('page')) {
$this->page = $page;
}
parent::__construct();
$this->itemPerPage = Configuration::get('JXBLOG_POSTS_PER_PAGE');
$this->tag = new JXBlogTag(Tools::getValue('id_jxblog_tag'));
}
public function initContent()
{
parent::initContent();
$pagination = false;
$posts = false;
if ($this->tag) {
$posts = JXBlogPost::getPostsByTag($this->tag->id, $this->context->language->id, $this->page, $this->itemPerPage);
$pagination = $this->module->buildPagination(
'tpagination',
JXBlogPost::countPostsByTag($this->tag->id),
$this->page,
$this->itemPerPage,
$this->tag->id,
''
);
}
$this->context->smarty->assign(
array(
'tag' => $this->tag,
'posts' => $posts,
'pagination' => $pagination,
'displayViews' => Configuration::get('JXBLOG_DISPLAY_POST_VIEWS'),
'displayAuthor' => Configuration::get('JXBLOG_DISPLAY_POST_AUTHOR')
)
);
$this->setTemplate('module:jxblog/views/templates/front/tag.tpl');
}
public function getBreadcrumbLinks()
{
$link = new Link();
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array('title' => $this->module->translator('all_categories'), 'url' => $link->getModuleLink('jxblog', 'categories'));
$breadcrumb['links'][] = array('title' => $this->tag->tag, 'url' => $link->getModuleLink('jxblog', 'tag', array('id_jxblog_tag' => $this->tag->id)));
return $breadcrumb;
}
}