first commit
This commit is contained in:
365
modules/leoblog/classes/LeoblogOwlCarousel.php
Normal file
365
modules/leoblog/classes/LeoblogOwlCarousel.php
Normal file
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
if (!class_exists('LeoblogOwlCarousel')) {
|
||||
|
||||
class LeoblogOwlCarousel
|
||||
{
|
||||
const MODULE_NAME = 'leotempcp';
|
||||
|
||||
public static function l($string, $specific = false, $name = '')
|
||||
{
|
||||
if (empty($name)) {
|
||||
# validate module
|
||||
$name = self::MODULE_NAME;
|
||||
}
|
||||
return Translate::getModuleTranslation($name, $string, ($specific) ? $specific : $name);
|
||||
}
|
||||
const ENABLE = '1';
|
||||
const DISABLE = '0';
|
||||
|
||||
public static function getEnableOptions()
|
||||
{
|
||||
return array(array(
|
||||
'id' => 'active_on',
|
||||
'value' => self::ENABLE,
|
||||
'label' => self::l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => self::DISABLE,
|
||||
'label' => self::l('Disabled')
|
||||
));
|
||||
}
|
||||
const CAROUSEL_BOOTSTRAP = 'carousel_bootstrap';
|
||||
const CAROUSEL_OWL = 'carousel_owl';
|
||||
|
||||
public static function getCaroulseOptions()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'value' => self::CAROUSEL_BOOTSTRAP,
|
||||
'name' => self::l('Bootstrap'),
|
||||
),
|
||||
array(
|
||||
'value' => self::CAROUSEL_OWL,
|
||||
'name' => self::l('Own Carousel'),
|
||||
),
|
||||
);
|
||||
}
|
||||
const TRANSITIONSTYLE_FADE = 'fade';
|
||||
const TRANSITIONSTYLE_BACKSLIDE = 'backSlide';
|
||||
const TRANSITIONSTYLE_GODOWN = 'goDown';
|
||||
const TRANSITIONSTYLE_FADEUP = 'fadeUp';
|
||||
|
||||
public static function getTransitionStyleOptions()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'value' => self::TRANSITIONSTYLE_FADE,
|
||||
'name' => self::l('Fade'),
|
||||
),
|
||||
array(
|
||||
'value' => self::TRANSITIONSTYLE_BACKSLIDE,
|
||||
'name' => self::l('Back Slide'),
|
||||
),
|
||||
array(
|
||||
'value' => self::TRANSITIONSTYLE_GODOWN,
|
||||
'name' => self::l('Go Down'),
|
||||
),
|
||||
array(
|
||||
'value' => self::TRANSITIONSTYLE_FADEUP,
|
||||
'name' => self::l('Fade Up'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare owl carousel inputs of form in Backend
|
||||
*/
|
||||
public function getOwlCarouselAdminFormOptions()
|
||||
{
|
||||
return array(
|
||||
# config for Owl Carousel - BEGIN
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Items Per Row'),
|
||||
'name' => 'owl_items',
|
||||
'default' => 3,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'fixed-width-xl digits',
|
||||
'desc' => $this->l('This variable allows you to set the maximum amount of items displayed at a time with the widest browser width'),
|
||||
'required' => true,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Number of rows'),
|
||||
'name' => 'owl_rows',
|
||||
'default' => 1,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'fixed-width-xl digits',
|
||||
'required' => true,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Auto Play'),
|
||||
'name' => 'owl_autoPlay',
|
||||
'default' => 8000,
|
||||
'desc' => $this->l('Enter Time(miniseconds) to play carousel. Value 0 to stop.'),
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'fixed-width-xl digits',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Stop On Hover'),
|
||||
'name' => 'owl_stopOnHover',
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'values' => self::getEnableOptions(),
|
||||
'desc' => $this->l('Stop "Auto Play" on mouse hover.'),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Auto Height'),
|
||||
'name' => 'owl_autoHeight',
|
||||
'default' => self::DISABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'values' => self::getEnableOptions(),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Reponsive'),
|
||||
'name' => 'owl_responsive',
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'values' => self::getEnableOptions(),
|
||||
),
|
||||
/*
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Transition Style', array(), 'Modules.LeoBlog.Admin'),
|
||||
'name' => 'owl_transitionStyle',
|
||||
'default' => LeomanagewidgetsOwlCarousel::TRANSITIONSTYLE_FADE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-' . self::CAROUSEL_OWL,
|
||||
'options' => array(
|
||||
'query' => LeomanagewidgetsOwlCarousel::getTransitionStyleOptions(),
|
||||
'id' => 'value',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
*/
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Mouse Drag'),
|
||||
'name' => 'owl_mouseDrag',
|
||||
'desc' => $this->l('Turn off/on mouse events.'),
|
||||
'values' => self::getEnableOptions(),
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Touch Drag'),
|
||||
'name' => 'owl_touchDrag',
|
||||
'desc' => $this->l('Turn off/on touch events.'),
|
||||
'values' => self::getEnableOptions(),
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Navigation'),
|
||||
'name' => 'owl_navigation',
|
||||
'desc' => $this->l('Display "next" and "prev" buttons.'),
|
||||
'values' => self::getEnableOptions(),
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_slideSpeed',
|
||||
'label' => $this->l('Slide Speed'),
|
||||
'desc' => $this->l('Slide speed in milliseconds. Time to next/drag/tough each item. Ex 200.'),
|
||||
'default' => '200',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'fixed-width-xl digits',
|
||||
),
|
||||
array(
|
||||
'type' => 'html',
|
||||
'name' => 'noname',
|
||||
'html_content' => '<div class="space"><strong>'.$this->l('Items for Screens').'</strong><hr/></div>',
|
||||
'default' => 'novalue',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_itemsDesktop',
|
||||
'label' => $this->l('Items Desktop (~1199)'),
|
||||
'desc' => $this->l('This allows you to preset the number of slides visible with ItemsDesktop (1199). Value 0 to disable. (Ex 4).'),
|
||||
'default' => '0',
|
||||
'form_group_class' => 'required carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'digits',
|
||||
//'required' => 'true',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_itemsDesktopSmall',
|
||||
'label' => $this->l('Items Desktop Small (~979)'),
|
||||
'desc' => $this->l('This allows you to preset the number of slides visible with itemsDesktopSmall (979px). Value 0 to disable. (Ex 3).'),
|
||||
'default' => '0',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'digits',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_itemsTablet',
|
||||
'label' => $this->l('Items Tablet (~768)'),
|
||||
'desc' => $this->l('This allows you to preset the number of slides visible with itemsTablet (768). Value 0 to disable. (Ex 2).'),
|
||||
'default' => '0',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'digits',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_itemsTabletSmall',
|
||||
'label' => $this->l('Items Tablet Small (~640)'),
|
||||
'desc' => $this->l('This allows you to preset the number of slides visible with itemsTabletSmall (640). Value 0 to disable. (Ex 2).'),
|
||||
'default' => '0',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'digits',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_itemsMobile',
|
||||
'label' => $this->l('Items Mobile (~479)'),
|
||||
'desc' => $this->l('This allows you to preset the number of slides visible with itemsmobile (360). Value 0 to disable. (Ex 1).'),
|
||||
'default' => '0',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'digits',
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_itemsCustom',
|
||||
'label' => $this->l('Items Custom'),
|
||||
//'desc' => $this->l('(Advance User) Example: [[0, 2], [400, 4], [700, 6], [1000, 8], [1200, 10], [1600, 16]]. The format is [x,y] whereby x=browser width and y=number of slides displayed. Value 0 to disable.'),
|
||||
'desc' => $this->l('(Advance User) Example: [[320, 1], [360, 1], [480, 2], [568, 2], [600, 2], [640, 2], [768, 3], [900, 3], [960, 3], [1024, 4]]. The format is [x,y] whereby x=browser width and y=number of slides displayed. Override all above Items. Value 0 to disable.'),
|
||||
'default' => '0',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'owl_items_custom',
|
||||
),
|
||||
array(
|
||||
'type' => 'html',
|
||||
'name' => 'noname',
|
||||
'html_content' => '<div class="space"><strong>'.$this->l('Effect').'</strong><hr/></div>',
|
||||
'default' => 'novalue',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Lazy Load'),
|
||||
'name' => 'owl_lazyLoad',
|
||||
'default' => self::DISABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'values' => self::getEnableOptions(),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Lazy Effect'),
|
||||
'name' => 'owl_lazyEffect',
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'values' => self::getEnableOptions(),
|
||||
'desc' => $this->l('Default is fadeIn on 400ms speed.'),
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Lazy Follow'),
|
||||
'name' => 'owl_lazyFollow',
|
||||
'is_bool' => true,
|
||||
'desc' => $this->l('When pagination used, it skips loading the images from pages that got skipped. It only loads the images that get displayed in viewport. If set to false, all images get loaded when pagination used. It is a sub setting of the lazy load function.'),
|
||||
'values' => self::getEnableOptions(),
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'html',
|
||||
'name' => 'noname',
|
||||
'html_content' => '<div class="space"><strong>'.$this->l('Pagination').'</strong><hr/></div>',
|
||||
'default' => 'novalue',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Pagination'),
|
||||
'name' => 'owl_pagination',
|
||||
'values' => self::getEnableOptions(),
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Show Pagination Numbers'),
|
||||
'name' => 'owl_paginationNumbers',
|
||||
'values' => self::getEnableOptions(),
|
||||
'default' => self::DISABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_paginationSpeed',
|
||||
'label' => $this->l('Pagination Speed'),
|
||||
'desc' => $this->l('Enter Time(miniseconds) to next/prev page. Ex 800.'),
|
||||
'default' => '800',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'digits',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Rewind Nav'),
|
||||
'name' => 'owl_rewindNav',
|
||||
'is_bool' => true,
|
||||
'desc' => $this->l('Slide to first page. Use "Rewind Speed" to change animation speed.'),
|
||||
'values' => self::getEnableOptions(),
|
||||
'default' => self::ENABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'owl_rewindSpeed',
|
||||
'label' => $this->l('Rewind Speed'),
|
||||
'desc' => $this->l('Enter Time(miniseconds) to back first page. "Rewind Nav" must be enable. Ex 1000'),
|
||||
'default' => '1000',
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
'class' => 'digits',
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Scroll Per Page'),
|
||||
'name' => 'owl_scrollPerPage',
|
||||
'is_bool' => true,
|
||||
'desc' => $this->l('Scroll per page not per item. This affect next/prev buttons and mouse/touch dragging. Use "Slide Speed" to change animation speed.'),
|
||||
'values' => self::getEnableOptions(),
|
||||
'default' => self::DISABLE,
|
||||
'form_group_class' => 'carousel_type_sub carousel_type-'.self::CAROUSEL_OWL,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
588
modules/leoblog/classes/blog.php
Normal file
588
modules/leoblog/classes/blog.php
Normal file
@@ -0,0 +1,588 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
class LeoBlogBlog extends ObjectModel
|
||||
{
|
||||
/** @var string Name */
|
||||
public $meta_title;
|
||||
public $subtitle;
|
||||
public $meta_description;
|
||||
public $meta_keywords;
|
||||
public $content;
|
||||
public $description;
|
||||
public $video_code;
|
||||
public $image = '';
|
||||
public $thumb = '';
|
||||
public $link_rewrite;
|
||||
public $id_leoblogcat;
|
||||
public $position;
|
||||
public $indexation;
|
||||
public $active;
|
||||
public $id_leoblog_blog;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
public $hits = 0;
|
||||
public $id_employee;
|
||||
public $tags;
|
||||
public $favorite;
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
//DONGND:: add author name
|
||||
public $author_name;
|
||||
|
||||
public static $definition = array(
|
||||
'table' => 'leoblog_blog',
|
||||
'primary' => 'id_leoblog_blog',
|
||||
'multilang' => true,
|
||||
'fields' => array(
|
||||
'id_leoblogcat' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'image' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName'),
|
||||
'position' => array('type' => self::TYPE_INT),
|
||||
'id_employee' => array('type' => self::TYPE_INT),
|
||||
'indexation' => array('type' => self::TYPE_BOOL),
|
||||
'favorite' => array('type' => self::TYPE_BOOL),
|
||||
'active' => array('type' => self::TYPE_BOOL),
|
||||
'image' => array('type' => self::TYPE_STRING, 'lang' => false),
|
||||
'thumb' => array('type' => self::TYPE_STRING, 'lang' => false),
|
||||
'hits' => array('type' => self::TYPE_INT),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'video_code' => array('type' => self::TYPE_HTML, 'validate' => 'isString', 'required' => false),
|
||||
'author_name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255),
|
||||
# Lang fields
|
||||
'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
|
||||
'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
|
||||
'tags' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
|
||||
'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 128),
|
||||
'subtitle' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
|
||||
'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128),
|
||||
'content' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 3999999999999),
|
||||
'description' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 3999999999999),
|
||||
),
|
||||
);
|
||||
protected $webserviceParameters = array(
|
||||
'objectNodeName' => 'content',
|
||||
'objectsNodeName' => 'content_management_system',
|
||||
);
|
||||
public static function findByRewrite($parrams)
|
||||
{
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
$id = 0;
|
||||
if (isset($parrams['link_rewrite']) && $parrams['link_rewrite']) {
|
||||
$sql = 'SELECT bl.id_leoblog_blog FROM '._DB_PREFIX_.'leoblog_blog_lang bl';
|
||||
$sql .= ' INNER JOIN '._DB_PREFIX_.'leoblog_blog_shop bs on bl.id_leoblog_blog=bs.id_leoblog_blog AND id_shop='.$id_shop;
|
||||
//$sql .= ' WHERE id_lang = ' . $id_lang ." AND link_rewrite = '".$parrams['link_rewrite']."'";
|
||||
$sql .= " AND link_rewrite = '".pSQL($parrams['link_rewrite'])."'";
|
||||
if ($row = Db::getInstance()->getRow($sql)) {
|
||||
$id = $row['id_leoblog_blog'];
|
||||
}
|
||||
}
|
||||
return new LeoBlogBlog($id, $id_lang);
|
||||
}
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
$this->position = self::getLastPosition((int)$this->id_leoblogcat);
|
||||
|
||||
$id_shop = LeoBlogHelper::getIDShop();
|
||||
$res = parent::add($autodate, $null_values);
|
||||
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'leoblog_blog_shop` (`id_shop`, `id_leoblog_blog`)
|
||||
VALUES('.(int)$id_shop.', '.(int)$this->id.')';
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
$this->cleanPositions($this->id_leoblogcat);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function update($null_values = false)
|
||||
{
|
||||
if (parent::update($null_values)) {
|
||||
return $this->cleanPositions($this->id_leoblogcat);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateField($id, $fields)
|
||||
{
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'leoblog_blog` SET ';
|
||||
$last_key = current(array_keys($fields));
|
||||
foreach ($fields as $field => $value) {
|
||||
$sql .= "`".bqSql($field)."` = '".pSQL($value)."'";
|
||||
if ($field != $last_key) {
|
||||
# validate module
|
||||
$sql .= ',';
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' WHERE `id_leoblog_blog`='.(int)$id;
|
||||
return Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (parent::delete()) {
|
||||
# BLOG_SHOP
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.'leoblog_blog_shop` '
|
||||
.'WHERE `id_leoblog_blog` IN ('.(int)$this->id.')';
|
||||
Db::getInstance()->execute($sql);
|
||||
|
||||
//delete comment
|
||||
$result_comment = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT `id_comment` as id FROM `'._DB_PREFIX_.'leoblog_comment` WHERE `id_leoblog_blog` = '.(int)$this->id.'');
|
||||
foreach ($result_comment as $value) {
|
||||
$comment = new LeoBlogComment($value['id']);
|
||||
$comment->delete();
|
||||
}
|
||||
|
||||
return $this->cleanPositions($this->id_leoblogcat);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array $condition ( default array )
|
||||
* @param Boolean $is_active ( default false )
|
||||
*/
|
||||
public static function getListBlogs($id_category, $id_lang, $page_number, $nb_products, $order_by, $order_way, $condition = array(), $is_active = false, $id_shop = null)
|
||||
{
|
||||
# module validation
|
||||
!is_null($nb_products) ? true : $nb_products = 10;
|
||||
!is_null($page_number) ? true : $page_number = 0;
|
||||
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
if (empty($id_lang)) {
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
if ($page_number < 1) {
|
||||
$page_number = 1;
|
||||
}
|
||||
if ($nb_products < 1) {
|
||||
$nb_products = 10;
|
||||
}
|
||||
if (empty($order_by) || $order_by == 'position') {
|
||||
$order_by = 'date_add';
|
||||
}
|
||||
if (empty($order_way)) {
|
||||
$order_way = 'DESC';
|
||||
}
|
||||
if ($order_by == 'id_leoblog_blog' || $order_by == 'date_add' || $order_by == 'date_upd') {
|
||||
$order_by_prefix = 'c';
|
||||
} else if ($order_by == 'title') {
|
||||
$order_by_prefix = 'c';
|
||||
}
|
||||
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
if (strpos($order_by, '.') > 0) {
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by_prefix = $order_by[0];
|
||||
$order_by = $order_by[1];
|
||||
}
|
||||
|
||||
$where = '';
|
||||
|
||||
if ($id_category) {
|
||||
# validate module
|
||||
$where .= ' AND c.id_leoblogcat='.(int)$id_category;
|
||||
}
|
||||
if ($id_shop) {
|
||||
# validate module
|
||||
$where .= ' AND s.id_shop='.(int)$id_shop;
|
||||
}
|
||||
if (isset($condition['favorite'])) {
|
||||
$where .= ' AND c.favorite='.(int)$condition['favorite'];
|
||||
}
|
||||
if (isset($condition['search'])) {
|
||||
$where .= ' AND blc.`meta_keywords` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR blc.`content_text` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR blc.`meta_description` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`meta_title` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`subtitle` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`tags` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`meta_keywords` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`meta_description` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`content` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`description` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
';
|
||||
}
|
||||
if (isset($condition['type'])) {
|
||||
switch ($condition['type']) {
|
||||
case 'author':
|
||||
if (isset($condition['id_employee'])) {
|
||||
$where .= ' AND id_employee='.(int)$condition['id_employee'].' AND (author_name = "" OR author_name is null)';
|
||||
} else {
|
||||
$where .= ' AND author_name LIKE "%'.pSQL($condition['author_name']).'%"';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tag':
|
||||
$tmp = explode(',', $condition['tag']);
|
||||
|
||||
if (!empty($tmp) && count($tmp) > 1) {
|
||||
$t = array();
|
||||
foreach ($tmp as $tag) {
|
||||
# validate module
|
||||
$t[] = 'l.tags LIKE "%'.pSQL(trim($tag)).'%"';
|
||||
}
|
||||
$where .= ' AND ('.implode(' OR ', $t).') ';
|
||||
} else {
|
||||
# validate module
|
||||
$where .= ' AND l.tags LIKE "%'.pSQL($condition['tag']).'%"';
|
||||
}
|
||||
break;
|
||||
case 'samecat':
|
||||
$where .= ' AND c.id_leoblog_blog!='.(int)$condition['id_leoblog_blog'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_active) {
|
||||
# validate module
|
||||
$where .= ' AND c.active=1';
|
||||
}
|
||||
$query = '
|
||||
SELECT c.*, l.*, l.meta_title as title, blc.link_rewrite as category_link_rewrite , blc.title as category_title
|
||||
FROM '._DB_PREFIX_.'leoblog_blog c
|
||||
LEFT JOIN '._DB_PREFIX_.'leoblog_blog_lang l ON (c.id_leoblog_blog = l.id_leoblog_blog) and l.id_lang='.(int)$id_lang
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblog_blog_shop s ON (c.id_leoblog_blog = s.id_leoblog_blog) and s.id_shop='.(int)$id_shop
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblogcat bc ON bc.id_leoblogcat = c.id_leoblogcat '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblogcat_lang blc ON blc.id_leoblogcat=bc.id_leoblogcat and blc.id_lang='.(int)$id_lang
|
||||
.' '.Shop::addSqlAssociation('blog', 'c').'
|
||||
WHERE l.id_lang = '.(int)$id_lang.$where.'
|
||||
GROUP BY c.id_leoblog_blog
|
||||
';
|
||||
|
||||
$order_way = Validate::isOrderWay($order_way) ? Tools::strtoupper($order_way) : 'ASC'; // $order_way Validate::isOrderWay()
|
||||
$query .= 'ORDER BY '.(isset($order_by_prefix) ? '`'.pSQL($order_by_prefix).'`.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way)
|
||||
.' LIMIT '.(int)(($page_number - 1) * $nb_products).', '.(int)$nb_products;
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array $condition ( default array )
|
||||
* @param Boolean $is_active ( default false )
|
||||
*/
|
||||
public static function countBlogs($id_category, $id_lang, $condition = array(), $is_active = false, $id_shop = null)
|
||||
{
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
$where = '';
|
||||
if ($id_category) {
|
||||
# validate module
|
||||
$where .= ' AND c.id_leoblogcat='.(int)$id_category;
|
||||
}
|
||||
if ($is_active) {
|
||||
# validate module
|
||||
$where .= ' AND c.active=1';
|
||||
}
|
||||
if ($id_shop) {
|
||||
# validate module
|
||||
$where .= ' AND s.id_shop='.(int)$id_shop;
|
||||
}
|
||||
if (isset($condition['favorite'])) {
|
||||
$where .= ' AND c.favorite='.(int)$condition['favorite'];
|
||||
}
|
||||
if (isset($condition['search'])) {
|
||||
$where .= ' AND blc.`meta_keywords` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR blc.`content_text` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR blc.`meta_description` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`meta_title` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`subtitle` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`tags` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`meta_keywords` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`meta_description` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`content` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
OR l.`description` LIKE \'%' . pSQL($condition['search']) . '%\'
|
||||
';
|
||||
}
|
||||
if (isset($condition['type'])) {
|
||||
switch ($condition['type']) {
|
||||
case 'author':
|
||||
if (isset($condition['id_employee'])) {
|
||||
$where .= ' AND id_employee='.(int)$condition['id_employee'].' AND (author_name = "" OR author_name is null)';
|
||||
} else {
|
||||
$where .= ' AND author_name LIKE "%'.pSQL($condition['author_name']).'%"';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'tag':
|
||||
$tmp = explode(',', $condition['tag']);
|
||||
|
||||
if (!empty($tmp) && count($tmp) > 1) {
|
||||
$t = array();
|
||||
foreach ($tmp as $tag) {
|
||||
# validate module
|
||||
$t[] = 'l.tags LIKE "%'.pSQL(trim($tag)).'%"';
|
||||
}
|
||||
$where .= ' AND '.implode(' OR ', $t).' ';
|
||||
} else {
|
||||
# validate module
|
||||
$where .= ' AND l.tags LIKE "%'.pSQL($condition['tag']).'%"';
|
||||
}
|
||||
break;
|
||||
case 'samecat':
|
||||
$where .= ' AND c.id_leoblog_blog!='.(int)$condition['id_leoblog_blog'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$query = '
|
||||
SELECT c.id_leoblog_blog
|
||||
FROM '._DB_PREFIX_.'leoblog_blog c
|
||||
LEFT JOIN '._DB_PREFIX_.'leoblog_blog_lang l ON (c.id_leoblog_blog = l.id_leoblog_blog) and l.id_lang='.(int)$id_lang
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblog_blog_shop s ON (c.id_leoblog_blog = s.id_leoblog_blog) '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblogcat bc ON bc.id_leoblogcat = c.id_leoblogcat '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblogcat_lang blc ON blc.id_leoblogcat=bc.id_leoblogcat and blc.id_lang='.(int)$id_lang
|
||||
.'
|
||||
WHERE l.id_lang = '.(int)$id_lang.$where.'
|
||||
GROUP BY c.id_leoblog_blog
|
||||
';
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
return count($data);
|
||||
}
|
||||
|
||||
public static function listblog($id_lang = null, $id_block = false, $active = true, $id_shop = null)
|
||||
{
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
if (empty($id_lang)) {
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT c.id_leoblog_blog, l.meta_title
|
||||
FROM '._DB_PREFIX_.'blog c
|
||||
JOIN '._DB_PREFIX_.'blog_lang l ON (c.id_leoblog_blog = l.id_leoblog_blog)
|
||||
JOIN '._DB_PREFIX_.'leoblog_blog_lang s ON (c.id_leoblog_blog = s.id_leoblog_blog)
|
||||
'.Shop::addSqlAssociation('blog', 'c').'
|
||||
'.(($id_block) ? 'JOIN '._DB_PREFIX_.'block_blog b ON (c.id_leoblog_blog = b.id_leoblog_blog)' : '').'
|
||||
WHERE s.id_shop = '.(int)$id_shop.' AND l.id_lang = '.(int)$id_lang.(($id_block) ? ' AND b.id_block = '.(int)$id_block : '').($active ? ' AND c.`active` = 1 ' : '').'
|
||||
GROUP BY c.id_leoblog_blog
|
||||
ORDER BY c.`position`');
|
||||
}
|
||||
|
||||
public function updatePosition($way, $position)
|
||||
{
|
||||
$sql = 'SELECT cp.`id_leoblog_blog`, cp.`position`, cp.`id_leoblogcat`
|
||||
FROM `'._DB_PREFIX_.'blog` cp
|
||||
WHERE cp.`id_leoblogcat` = '.(int)$this->id_leoblogcat.'
|
||||
ORDER BY cp.`position` ASC';
|
||||
if (!$res = Db::getInstance()->executeS($sql)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($res as $blog) {
|
||||
if ((int)$blog['id_leoblog_blog'] == (int)$this->id) {
|
||||
$moved_blog = $blog;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($moved_blog) || !isset($position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// < and > statements rather than BETWEEN operator
|
||||
// since BETWEEN is treated differently according to databases
|
||||
return (Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'blog`
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way ? '> '.(int)$moved_blog['position'].' AND `position` <= '.(int)$position : '< '.(int)$moved_blog['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_leoblogcat`='.(int)$moved_blog['id_leoblogcat']) && Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'blog`
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_leoblog_blog` = '.(int)$moved_blog['id_leoblog_blog'].'
|
||||
AND `id_leoblogcat`='.(int)$moved_blog['id_leoblogcat']));
|
||||
}
|
||||
|
||||
public static function cleanPositions($id_category)
|
||||
{
|
||||
$sql = '
|
||||
SELECT `id_leoblog_blog`
|
||||
FROM `'._DB_PREFIX_.'leoblog_blog`
|
||||
WHERE `id_leoblogcat` = '.(int)$id_category.'
|
||||
ORDER BY `position`';
|
||||
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
|
||||
for ($i = 0, $total = count($result); $i < $total; ++$i) {
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'leoblog_blog`
|
||||
SET `position` = '.(int)$i.'
|
||||
WHERE `id_leoblogcat` = '.(int)$id_category.'
|
||||
AND `id_leoblog_blog` = '.(int)$result[$i]['id_leoblog_blog'];
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getLastPosition($id_category)
|
||||
{
|
||||
$sql = '
|
||||
SELECT MAX(position) + 1
|
||||
FROM `'._DB_PREFIX_.'leoblog_blog`
|
||||
WHERE `id_leoblogcat` = '.(int)$id_category;
|
||||
|
||||
return (Db::getInstance()->getValue($sql));
|
||||
}
|
||||
|
||||
public static function getblogPages($id_lang = null, $id_leoblogcat = null, $active = true, $id_shop = null)
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('*');
|
||||
$sql->from('blog', 'c');
|
||||
if ($id_lang) {
|
||||
$sql->innerJoin('blog_lang', 'l', 'c.id_leoblog_blog = l.id_leoblog_blog AND l.id_lang = '.(int)$id_lang);
|
||||
}
|
||||
|
||||
if ($id_shop) {
|
||||
$sql->innerJoin('blog_shop', 'cs', 'c.id_leoblog_blog = cs.id_leoblog_blog AND cs.id_shop = '.(int)$id_shop);
|
||||
}
|
||||
|
||||
if ($active) {
|
||||
$sql->where('c.active = 1');
|
||||
}
|
||||
|
||||
if ($id_leoblogcat) {
|
||||
$sql->where('c.id_leoblogcat = '.(int)$id_leoblogcat);
|
||||
}
|
||||
|
||||
$sql->orderBy('position');
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public static function getUrlRewriteInformations($id_leoblog_blog)
|
||||
{
|
||||
$sql = 'SELECT l.`id_lang`, c.`link_rewrite`
|
||||
FROM `'._DB_PREFIX_.'leoblog_blog_lang` AS c
|
||||
LEFT JOIN `'._DB_PREFIX_.'lang` AS l ON c.`id_lang` = l.`id_lang`
|
||||
WHERE c.`id_leoblog_blog` = '.(int)$id_leoblog_blog.'
|
||||
AND l.`active` = 1';
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is build for module ApPageBuilder, most logic query Sqlis clone from function getListBlog.
|
||||
* @param Int $id_category ( default '' )
|
||||
* @param Int $nb_blog ( default 10 )
|
||||
* @param Array $condition ( default array )
|
||||
* @param Boolean $is_active ( default false )
|
||||
*/
|
||||
public static function getListBlogsForApPageBuilder($id_category, $id_lang, $nb_blog, $order_by, $order_way, $condition, $is_active, $id_shop = null)
|
||||
{
|
||||
# module validation
|
||||
!is_null($nb_blog) ? true : $nb_blog = 10;
|
||||
is_array($condition) ? true : $condition = array();
|
||||
!is_null($is_active) ? true : $is_active = false;
|
||||
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
if (empty($id_lang)) {
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
if ($nb_blog < 1) {
|
||||
$nb_blog = 10;
|
||||
}
|
||||
if (empty($order_by) || $order_by == 'position') {
|
||||
$order_by = 'date_add';
|
||||
}
|
||||
if (empty($order_way)) {
|
||||
$order_way = 'DESC';
|
||||
}
|
||||
if ($order_by == 'id_leoblog_blog' || $order_by == 'date_add' || $order_by == 'date_upd') {
|
||||
$order_by_prefix = 'c';
|
||||
} else if ($order_by == 'title') {
|
||||
$order_by_prefix = 'c';
|
||||
}
|
||||
// if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
|
||||
// die(Tools::displayError());
|
||||
// }
|
||||
if (strpos($order_by, '.') > 0) {
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by_prefix = $order_by[0];
|
||||
$order_by = $order_by[1];
|
||||
}
|
||||
$where = '';
|
||||
if ($id_category) {
|
||||
$id_category = implode(', ', array_map('intval', explode(',', $id_category)));
|
||||
$where .= ' AND c.id_leoblogcat IN('.$id_category.')';
|
||||
}
|
||||
if ($id_shop) {
|
||||
$where .= ' AND s.id_shop='.(int)$id_shop;
|
||||
}
|
||||
if (isset($condition['type'])) {
|
||||
switch ($condition['type']) {
|
||||
case 'author':
|
||||
$where .= ' AND id_employee='.(int)$condition['id_employee'];
|
||||
break;
|
||||
case 'tag':
|
||||
$tmp = explode(',', $condition['tag']);
|
||||
if (!empty($tmp) && count($tmp) > 1) {
|
||||
$t = array(); # validate module
|
||||
foreach ($tmp as $tag) {
|
||||
$t[] = 'l.tags LIKE "%'.pSQL(trim($tag)).'%"';
|
||||
}
|
||||
$where .= ' AND '.implode(' OR ', $t).' ';
|
||||
} else {
|
||||
$where .= ' AND l.tags LIKE "%'.pSQL($condition['tag']).'%"';
|
||||
}
|
||||
break;
|
||||
case 'samecat':
|
||||
$where .= ' AND c.id_leoblog_blog!='.(int)$condition['id_leoblog_blog'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($is_active) {
|
||||
$where .= ' AND c.active=1';
|
||||
}
|
||||
$query = '
|
||||
SELECT c.*, l.*, l.meta_title as title, blc.link_rewrite as category_link_rewrite , blc.title as category_title
|
||||
FROM '._DB_PREFIX_.'leoblog_blog c
|
||||
LEFT JOIN '._DB_PREFIX_.'leoblog_blog_lang l ON (c.id_leoblog_blog = l.id_leoblog_blog) and l.id_lang='.(int)$id_lang
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblog_blog_shop s ON (c.id_leoblog_blog = s.id_leoblog_blog) '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblogcat bc ON bc.id_leoblogcat = c.id_leoblogcat '
|
||||
.' LEFT JOIN '._DB_PREFIX_.'leoblogcat_lang blc ON blc.id_leoblogcat=bc.id_leoblogcat and blc.id_lang='.(int)$id_lang
|
||||
.' '.Shop::addSqlAssociation('blog', 'c').'
|
||||
WHERE l.id_lang = '.(int)$id_lang.$where.'
|
||||
GROUP BY c.id_leoblog_blog ';
|
||||
|
||||
if ($order_way == 'random') {
|
||||
$query .= 'ORDER BY rand() LIMIT 0, '.(int)$nb_blog;
|
||||
} else {
|
||||
$order_way = Validate::isOrderWay($order_way) ? Tools::strtoupper($order_way) : 'ASC'; // $order_way Validate::isOrderWay()
|
||||
$query .= 'ORDER BY '.(isset($order_by_prefix) ? '`'.pSQL($order_by_prefix).'`.' : '')
|
||||
.'`'.bqSQL($order_by).'` '.pSQL($order_way).' LIMIT 0, '.(int)$nb_blog;
|
||||
}
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
67
modules/leoblog/classes/captcha.php
Normal file
67
modules/leoblog/classes/captcha.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!class_exists('LeoCaptcha')) {
|
||||
|
||||
class LeoCaptcha
|
||||
{
|
||||
protected $code;
|
||||
protected $width = 35;
|
||||
protected $height = 150;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->code = Tools::substr(sha1(mt_rand()), 17, 6);
|
||||
}
|
||||
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function showImage()
|
||||
{
|
||||
$image = imagecreatetruecolor($this->height, $this->width);
|
||||
|
||||
$width = imagesx($image);
|
||||
$height = imagesy($image);
|
||||
|
||||
$black = imagecolorallocate($image, 0, 0, 0);
|
||||
$white = imagecolorallocate($image, 255, 255, 255);
|
||||
$red = imagecolorallocatealpha($image, 255, 033, 0, 75);
|
||||
$green = imagecolorallocatealpha($image, 33, 255, 0, 75);
|
||||
$blue = imagecolorallocatealpha($image, 0, 22, 255, 75);
|
||||
|
||||
imagefilledrectangle($image, 0, 0, $width, $height, $white);
|
||||
|
||||
imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
|
||||
imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
|
||||
imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
|
||||
|
||||
imagefilledrectangle($image, 0, 0, $width, 0, $black);
|
||||
imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
|
||||
imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
|
||||
imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
|
||||
|
||||
imagestring($image, 10, (($width - (Tools::strlen($this->code) * 9)) / 2), (($height - 15) / 2), $this->code, $black); # validate module
|
||||
|
||||
header('Content-type: image/jpeg');
|
||||
|
||||
imagejpeg($image);
|
||||
|
||||
imagedestroy($image);
|
||||
}
|
||||
}
|
||||
}
|
||||
152
modules/leoblog/classes/comment.php
Normal file
152
modules/leoblog/classes/comment.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class LeoBlogComment extends ObjectModel
|
||||
{
|
||||
/** @var string Name */
|
||||
public $user;
|
||||
public $comment;
|
||||
public $active;
|
||||
public $id_leoblog_blog;
|
||||
public $date_add;
|
||||
public $email;
|
||||
public $id_shop;
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'leoblog_comment',
|
||||
'primary' => 'id_comment',
|
||||
'fields' => array(
|
||||
'id_leoblog_blog' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'user' => array('type' => self::TYPE_STRING, 'required' => false),
|
||||
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128, 'required' => true),
|
||||
'comment' => array('type' => self::TYPE_STRING, 'required' => true),
|
||||
'active' => array('type' => self::TYPE_BOOL),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => false)
|
||||
),
|
||||
);
|
||||
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
// $this->position = self::getLastPosition((int)$this->id_leoblogcat);
|
||||
$this->id_shop = LeoBlogHelper::getIDShop();
|
||||
return parent::add($autodate, $null_values);
|
||||
}
|
||||
|
||||
public static function countComments($id_leoblog_blog = 0, $is_active = false, $id_shop = null)
|
||||
{
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
$query = ' SELECT count(id_comment) as total FROM '._DB_PREFIX_.'leoblog_comment WHERE 1=1 ';
|
||||
|
||||
if ($id_leoblog_blog > 0) {
|
||||
# validate module
|
||||
$query .= ' AND id_leoblog_blog='.(int)$id_leoblog_blog;
|
||||
}
|
||||
if ($is_active) {
|
||||
# validate module
|
||||
$query .= ' AND active=1 ';
|
||||
}
|
||||
if ($id_shop) {
|
||||
$query .= ' AND id_shop='.(int)$id_shop;
|
||||
}
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
return $data[0]['total'];
|
||||
}
|
||||
|
||||
public static function getComments($id_leoblog_blog, $limit, $id_lang, $order = null, $by = null, $id_shop = null)
|
||||
{
|
||||
# validate module
|
||||
!is_null($limit) ? true : $limit = 10;
|
||||
unset($id_leoblog_blog);
|
||||
unset($order);
|
||||
unset($by);
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
$query = ' SELECT c.*, b.meta_title FROM '._DB_PREFIX_.'leoblog_comment c';
|
||||
$query .= ' LEFT JOIN '._DB_PREFIX_.'leoblog_blog_lang b ON c.id_leoblog_blog=b.id_leoblog_blog AND b.id_lang='.(int)$id_lang;
|
||||
$query .= ' WHERE 1=1 AND id_shop='.(int)$id_shop;
|
||||
$query .= ' LIMIT '.(int)$limit;
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getList($id_leoblog_blog, $id_lang, $page_number = 0, $nb_products = 10, $order_by = null, $order_way = null, $id_shop = null)
|
||||
{
|
||||
if (!$id_shop) {
|
||||
$context = Context::getContext();
|
||||
$id_shop = $context->shop->id;
|
||||
}
|
||||
|
||||
if (empty($id_lang)) {
|
||||
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
||||
}
|
||||
|
||||
if ($page_number < 1) {
|
||||
$page_number = 1;
|
||||
}
|
||||
|
||||
if ($nb_products < 1) {
|
||||
$nb_products = 10;
|
||||
}
|
||||
if (empty($order_by) || $order_by == 'position') {
|
||||
$order_by = 'date_add';
|
||||
}
|
||||
if (empty($order_way)) {
|
||||
$order_way = 'DESC';
|
||||
}
|
||||
if ($order_by == 'id_leoblog_blog' || $order_by == 'date_add' || $order_by == 'date_upd') {
|
||||
$order_by_prefix = 'c';
|
||||
} else if ($order_by == 'title') {
|
||||
$order_by_prefix = 'c';
|
||||
}
|
||||
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
if (strpos($order_by, '.') > 0) {
|
||||
$order_by = explode('.', $order_by);
|
||||
$order_by_prefix = $order_by[0];
|
||||
$order_by = $order_by[1];
|
||||
}
|
||||
|
||||
$query = ' SELECT c.* FROM '._DB_PREFIX_.'leoblog_comment c';
|
||||
$query .= ' WHERE 1=1 AND id_shop='.(int)$id_shop;
|
||||
|
||||
$query .= ' AND active=1 AND id_leoblog_blog='.(int)$id_leoblog_blog;
|
||||
|
||||
$order_way = Validate::isOrderWay($order_way) ? Tools::strtoupper($order_way) : 'ASC'; // $order_way Validate::isOrderWay()
|
||||
$query .= ' ORDER BY '.(isset($order_by_prefix) ? '`'.pSQL($order_by_prefix).'`.' : '').'`'.bqSQL($order_by).'` '.pSQL($order_way)
|
||||
.' LIMIT '.(int)(($page_number - 1) * $nb_products).', '.(int)$nb_products; # validate module
|
||||
|
||||
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
84
modules/leoblog/classes/config.php
Normal file
84
modules/leoblog/classes/config.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
class LeoBlogConfig
|
||||
{
|
||||
public $params;
|
||||
public $cat_image_dir = '';
|
||||
/** @var int id_lang current language in for, while */
|
||||
public $cur_id_lang = '';
|
||||
/** @var int id_lang current language in for, while */
|
||||
public $cur_prefix_rewrite = '';
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
static $instance;
|
||||
if (!$instance) {
|
||||
# validate module
|
||||
$instance = new LeoBlogConfig();
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
//get data for template
|
||||
if (Configuration::get(Tools::strtoupper(_LEO_BLOG_PREFIX_.'template_current')) == 'default' || Tools::getValue('bloglayout') == 'default') {
|
||||
$data = self::getConfigValue('cfg_global');
|
||||
} else {
|
||||
$data = self::getConfigValue('cfg_global_'.Configuration::get(Tools::strtoupper(_LEO_BLOG_PREFIX_.'template_current')));
|
||||
}
|
||||
if ($data && $tmp = Tools::jsonDecode($data, true)) {
|
||||
include_once(_PS_MODULE_DIR_.'leoblog/libs/Helper.php');
|
||||
$tmp['social_code'] = LeoBlogHelper::correctDeCodeData($tmp['social_code']);
|
||||
$this->params = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
public function mergeParams($params)
|
||||
{
|
||||
# validate module
|
||||
unset($params);
|
||||
}
|
||||
|
||||
public function setVar($key, $value)
|
||||
{
|
||||
$this->params[$key] = $value;
|
||||
}
|
||||
|
||||
public function get($name, $value = '')
|
||||
{
|
||||
if (isset($this->params[$name])) {
|
||||
# validate module
|
||||
return $this->params[$name];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function getConfigName($name)
|
||||
{
|
||||
return Tools::strtoupper(_LEO_BLOG_PREFIX_.$name);
|
||||
}
|
||||
|
||||
public static function updateConfigValue($name, $value = '')
|
||||
{
|
||||
Configuration::updateValue(self::getConfigName($name), $value, true);
|
||||
}
|
||||
|
||||
public static function getConfigValue($name)
|
||||
{
|
||||
return Configuration::get(self::getConfigName($name));
|
||||
}
|
||||
}
|
||||
36
modules/leoblog/classes/index.php
Normal file
36
modules/leoblog/classes/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2012 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.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/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2012 PrestaShop SA
|
||||
* @version Release: $Revision: 13573 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
540
modules/leoblog/classes/leoblogcat.php
Normal file
540
modules/leoblog/classes/leoblogcat.php
Normal file
@@ -0,0 +1,540 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
# module validation
|
||||
exit;
|
||||
}
|
||||
|
||||
class Leoblogcat extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
public $id_leoblogcat;
|
||||
public $image;
|
||||
public $icon_class;
|
||||
public $id_parent = 1;
|
||||
public $is_group = 0;
|
||||
public $width;
|
||||
public $submenu_width;
|
||||
public $colum_width;
|
||||
public $submenu_colum_width;
|
||||
public $item;
|
||||
public $colums = 1;
|
||||
public $type;
|
||||
public $is_content = 0;
|
||||
public $show_title = 1;
|
||||
public $type_submenu;
|
||||
public $level_depth;
|
||||
public $active = 1;
|
||||
public $position;
|
||||
public $show_sub;
|
||||
public $url;
|
||||
public $target;
|
||||
public $privacy;
|
||||
public $position_type;
|
||||
public $menu_class;
|
||||
public $content;
|
||||
public $submenu_content;
|
||||
public $level;
|
||||
public $left;
|
||||
public $right;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
# Lang
|
||||
public $title;
|
||||
public $description;
|
||||
public $content_text;
|
||||
public $submenu_content_text;
|
||||
public $submenu_catids;
|
||||
public $is_cattree = 1;
|
||||
public $template;
|
||||
public $meta_keywords;
|
||||
public $meta_description;
|
||||
private $shop_url;
|
||||
public $link_rewrite;
|
||||
private $megaConfig = array();
|
||||
private $_editStringCol = '';
|
||||
private $_isLiveEdit = true;
|
||||
private $_module = null;
|
||||
public $id_shop = '';
|
||||
public $select_data = array();
|
||||
public $randkey;
|
||||
|
||||
public function setModule($module)
|
||||
{
|
||||
$this->_module = $module;
|
||||
}
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'leoblogcat',
|
||||
'primary' => 'id_leoblogcat',
|
||||
'multilang' => true,
|
||||
'fields' => array(
|
||||
'image' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName'),
|
||||
'id_parent' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
|
||||
'level_depth' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
|
||||
'show_title' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
|
||||
'position' => array('type' => self::TYPE_INT),
|
||||
'privacy' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'size' => 6),
|
||||
'template' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'size' => 200),
|
||||
'menu_class' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'size' => 25),
|
||||
'icon_class' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'size' => 125),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
# Lang fields
|
||||
'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),
|
||||
'content_text' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString', 'required' => false),
|
||||
'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255, 'required' => false),
|
||||
'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255, 'required' => false),
|
||||
'link_rewrite' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128),
|
||||
'randkey' => array('type' => self::TYPE_STRING, 'lang' => false, 'size' => 255),
|
||||
),
|
||||
);
|
||||
|
||||
public static function findByRewrite($parrams)
|
||||
{
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
$id = 0;
|
||||
if (isset($parrams['link_rewrite']) && $parrams['link_rewrite']) {
|
||||
$sql = 'SELECT cl.id_leoblogcat FROM '._DB_PREFIX_.'leoblogcat_lang cl';
|
||||
$sql .= ' INNER JOIN '._DB_PREFIX_.'leoblogcat_shop cs on cl.id_leoblogcat=cs.id_leoblogcat AND id_shop='.$id_shop;
|
||||
$sql .= ' INNER JOIN '._DB_PREFIX_.'leoblogcat cc on cl.id_leoblogcat=cc.id_leoblogcat AND cl.id_leoblogcat != cc.id_parent'; # FIX : PARENT IS NOT THIS CATEGORY
|
||||
//$sql .= ' WHERE id_lang = ' . $id_lang ." AND link_rewrite = '".$parrams['link_rewrite']."'";
|
||||
$sql .= " AND link_rewrite = '".pSQL($parrams['link_rewrite'])."'";
|
||||
|
||||
if ($row = Db::getInstance()->getRow($sql)) {
|
||||
$id = $row['id_leoblogcat'];
|
||||
}
|
||||
}
|
||||
return new Leoblogcat($id, $id_lang);
|
||||
}
|
||||
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
$this->position = self::getLastPosition((int)$this->id_parent);
|
||||
$this->level_depth = $this->calcLevelDepth();
|
||||
$id_shop = LeoBlogHelper::getIDShop();
|
||||
$res = parent::add($autodate, $null_values);
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'leoblogcat_shop` (`id_shop`, `id_leoblogcat`)
|
||||
VALUES('.(int)$id_shop.', '.(int)$this->id.')';
|
||||
$res &= Db::getInstance()->execute($sql);
|
||||
$this->cleanPositions($this->id_parent);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function update($null_values = false)
|
||||
{
|
||||
$this->level_depth = $this->calcLevelDepth();
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
protected function recursiveDelete(&$to_delete, $id_leoblogcat)
|
||||
{
|
||||
if (!is_array($to_delete) || !$id_leoblogcat) {
|
||||
die(Tools::displayError());
|
||||
}
|
||||
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_leoblogcat`
|
||||
FROM `'._DB_PREFIX_.'leoblogcat`
|
||||
WHERE `id_parent` = '.(int)$id_leoblogcat);
|
||||
foreach ($result as $row) {
|
||||
$to_delete[] = (int)$row['id_leoblogcat'];
|
||||
$this->recursiveDelete($to_delete, (int)$row['id_leoblogcat']);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if ($this->id == 1) {
|
||||
return false;
|
||||
}
|
||||
$this->clearCache();
|
||||
|
||||
// Get children categories
|
||||
$to_delete = array((int)$this->id);
|
||||
$this->recursiveDelete($to_delete, (int)$this->id);
|
||||
$to_delete = array_unique($to_delete);
|
||||
|
||||
// Delete CMS Category and its child from database
|
||||
$list = count($to_delete) > 1 ? implode(',', array_map('intval', $to_delete)) : (int)$this->id;
|
||||
//delete blog
|
||||
//get all blog from category ID
|
||||
//$where = '`id_leoblogcat` IN (' . $list . ')';
|
||||
$result_blog = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT `id_leoblog_blog` as id FROM `'._DB_PREFIX_.'leoblog_blog` WHERE `id_leoblogcat` IN ('.pSQL($list).')');
|
||||
foreach ($result_blog as $value) {
|
||||
$blog = new LeoBlogBlog($value['id']);
|
||||
$blog->delete();
|
||||
}
|
||||
|
||||
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'leoblogcat` WHERE `id_leoblogcat` IN ('.pSQL($list).')');
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'leoblogcat_shop` WHERE `id_leoblogcat` IN ('.pSQL($list).')');
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'leoblogcat_lang` WHERE `id_leoblogcat` IN ('.pSQL($list).')');
|
||||
leoblogcat::cleanPositions($this->id_parent);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function countCats()
|
||||
{
|
||||
$row = Db::getInstance()->executeS('SELECT COUNT(id_leoblogcat) as total FROM `'._DB_PREFIX_.'leoblogcat` WHERE id_leoblogcat!=1 AND 1=1');
|
||||
return $row[0]['total'];
|
||||
}
|
||||
|
||||
public function deleteSelection($menus)
|
||||
{
|
||||
$return = 1;
|
||||
foreach ($menus as $id_leoblogcat) {
|
||||
$obj_menu = new Leoblogcat($id_leoblogcat);
|
||||
$return &= $obj_menu->delete();
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function calcLevelDepth()
|
||||
{
|
||||
$parentleoblogcat = new Leoblogcat($this->id_parent);
|
||||
if (!$parentleoblogcat) {
|
||||
die('parent Menu does not exist');
|
||||
}
|
||||
return $parentleoblogcat->level_depth + 1;
|
||||
}
|
||||
|
||||
public function updatePosition($way, $position)
|
||||
{
|
||||
$sql = 'SELECT cp.`id_leoblogcat`, cp.`position`, cp.`id_parent`
|
||||
FROM `'._DB_PREFIX_.'leoblogcat` cp
|
||||
WHERE cp.`id_parent` = '.(int)$this->id_parent.'
|
||||
ORDER BY cp.`position` ASC';
|
||||
!$res = Db::getInstance()->executeS($sql);
|
||||
if ($res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($res as $menu) {
|
||||
if ((int)$menu['id_leoblogcat'] == (int)$this->id) {
|
||||
$moved_menu = $menu;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($moved_menu) || !isset($position)) {
|
||||
return false;
|
||||
}
|
||||
// < and > statements rather than BETWEEN operator
|
||||
// since BETWEEN is treated differently according to databases
|
||||
return (Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'leoblogcat`
|
||||
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||
WHERE `position`
|
||||
'.($way ? '> '.(int)$moved_menu['position'].' AND `position` <= '.(int)$position : '< '.(int)$moved_menu['position'].' AND `position` >= '.(int)$position).'
|
||||
AND `id_parent`='.(int)$moved_menu['id_parent']) && Db::getInstance()->execute('
|
||||
UPDATE `'._DB_PREFIX_.'leoblogcat`
|
||||
SET `position` = '.(int)$position.'
|
||||
WHERE `id_parent` = '.(int)$moved_menu['id_parent'].'
|
||||
AND `id_leoblogcat`='.(int)$moved_menu['id_leoblogcat']));
|
||||
}
|
||||
|
||||
public static function cleanPositions($id_parent)
|
||||
{
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT `id_leoblogcat`
|
||||
FROM `'._DB_PREFIX_.'leoblogcat`
|
||||
WHERE `id_parent` = '.(int)$id_parent.'
|
||||
ORDER BY `position`');
|
||||
$sizeof = count($result);
|
||||
for ($i = 0; $i < $sizeof; ++$i) {
|
||||
$sql = '
|
||||
UPDATE `'._DB_PREFIX_.'leoblogcat`
|
||||
SET `position` = '.(int)$i.'
|
||||
WHERE `id_parent` = '.(int)$id_parent.'
|
||||
AND `id_leoblogcat` = '.(int)$result[$i]['id_leoblogcat'];
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getLastPosition($id_parent)
|
||||
{
|
||||
return (Db::getInstance()->getValue('SELECT MAX(position)+1 FROM `'._DB_PREFIX_.'leoblogcat` WHERE `id_parent` = '.(int)$id_parent));
|
||||
}
|
||||
|
||||
public function getInfo($id_leoblogcat, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
if (!$id_lang) {
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
if (!$id_shop) {
|
||||
$id_shop = Context::getContext()->shop->id;
|
||||
}
|
||||
$sql = 'SELECT m.*, md.title, md.description, md.content_text
|
||||
FROM '._DB_PREFIX_.'megamenu m
|
||||
LEFT JOIN '._DB_PREFIX_.'leoblogcat_lang md ON m.id_leoblogcat = md.id_leoblogcat AND md.id_lang = '.(int)$id_lang
|
||||
.' JOIN '._DB_PREFIX_.'leoblogcat_shop bs ON m.id_leoblogcat = bs.id_leoblogcat AND bs.id_shop = '.(int)($id_shop);
|
||||
$sql .= ' WHERE m.id_leoblogcat='.(int)$id_leoblogcat;
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public function getChild($id_leoblogcat = null, $id_lang = null, $id_shop = null, $active = false)
|
||||
{
|
||||
if (!$id_lang) {
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
if (!$id_shop) {
|
||||
$id_shop = Context::getContext()->shop->id;
|
||||
}
|
||||
|
||||
$sql = ' SELECT m.*, md.*
|
||||
FROM '._DB_PREFIX_.'leoblogcat m
|
||||
LEFT JOIN '._DB_PREFIX_.'leoblogcat_lang md ON m.id_leoblogcat = md.id_leoblogcat AND md.id_lang = '.(int)$id_lang
|
||||
.' JOIN '._DB_PREFIX_.'leoblogcat_shop bs ON m.id_leoblogcat = bs.id_leoblogcat AND bs.id_shop = '.(int)($id_shop);
|
||||
if ($active) {
|
||||
$sql .= ' WHERE m.`active`=1 ';
|
||||
}
|
||||
|
||||
if ($id_leoblogcat != null) {
|
||||
# validate module
|
||||
$sql .= ' WHERE id_parent='.(int)$id_leoblogcat;
|
||||
}
|
||||
$sql .= ' ORDER BY `position` ';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public function getAllChild($id_leoblogcat = null, $id_lang = null, $id_shop = null, $active = false)
|
||||
{
|
||||
if (!$id_lang) {
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
if (!$id_shop) {
|
||||
$id_shop = Context::getContext()->shop->id;
|
||||
}
|
||||
|
||||
$sql = ' SELECT m.id_leoblogcat AS id_category, m.id_parent, md.title AS name
|
||||
FROM '._DB_PREFIX_.'leoblogcat m
|
||||
LEFT JOIN '._DB_PREFIX_.'leoblogcat_lang md ON m.id_leoblogcat = md.id_leoblogcat AND md.id_lang = '.(int)$id_lang
|
||||
.' JOIN '._DB_PREFIX_.'leoblogcat_shop bs ON m.id_leoblogcat = bs.id_leoblogcat AND bs.id_shop = '.(int)($id_shop);
|
||||
if ($active) {
|
||||
$sql .= ' WHERE m.`active`=1 ';
|
||||
}
|
||||
|
||||
if ($id_leoblogcat != null) {
|
||||
# validate module
|
||||
$sql .= ' WHERE id_parent='.(int)$id_leoblogcat;
|
||||
}
|
||||
$sql .= ' ORDER BY `position` ';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
public function hasChild($id)
|
||||
{
|
||||
return isset($this->children[$id]);
|
||||
}
|
||||
|
||||
public function getNodes($id)
|
||||
{
|
||||
return $this->children[$id];
|
||||
}
|
||||
|
||||
public function getTree($id = null)
|
||||
{
|
||||
$childs = $this->getChild($id);
|
||||
|
||||
foreach ($childs as $child) {
|
||||
# validate module
|
||||
$this->children[$child['id_parent']][] = $child;
|
||||
}
|
||||
$parent = 1;
|
||||
$output = $this->genTree($parent, 1);
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getDropdown($id, $selected = 1)
|
||||
{
|
||||
$this->children = array();
|
||||
$childs = $this->getChild($id);
|
||||
foreach ($childs as $child) {
|
||||
# validate module
|
||||
$this->children[$child['id_parent']][] = $child;
|
||||
}
|
||||
$output = array(array('id' => '1', 'title' => 'Root', 'selected' => ''));
|
||||
$output = $this->genOption(1, 1, $selected, $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $level (default 0 )
|
||||
* @param type $output ( default array )
|
||||
* @param type $output
|
||||
*/
|
||||
public function genOption($parent, $level, $selected, $output)
|
||||
{
|
||||
# module validation
|
||||
!is_null($level) ? $level : $level = 0;
|
||||
is_array($output) ? true : $output = array();
|
||||
|
||||
if ($this->hasChild($parent)) {
|
||||
$data = $this->getNodes($parent);
|
||||
foreach ($data as $menu) {
|
||||
//$select = $selected == $menu['id_leoblogcat'] ? 'selected="selected"' : "";
|
||||
$output[] = array('id' => $menu['id_leoblogcat'], 'title' => str_repeat('-', $level).' '.$menu['title'].' (ID:'.$menu['id_leoblogcat'].')', 'selected' => $selected);
|
||||
if ($menu['id_leoblogcat'] != $parent) {
|
||||
$output = $this->genOption($menu['id_leoblogcat'], $level + 1, $selected, $output);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function genTree($parent, $level)
|
||||
{
|
||||
if ($this->hasChild($parent)) {
|
||||
$data = $this->getNodes($parent);
|
||||
$t = $level == 1 ? ' sortable' : '';
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'parent' => $parent,
|
||||
'level' => $level,
|
||||
't' => $t,
|
||||
'data' => $data,
|
||||
'param_id_leoblogcat' => Tools::getValue('id_leoblogcat'),
|
||||
'model_leoblogcat' => $this,
|
||||
));
|
||||
return Context::getContext()->smarty->fetch($this->getTemplatePath().'genTree.tpl');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getTemplatePath()
|
||||
{
|
||||
return _PS_MODULE_DIR_ . 'leoblog/views/templates/admin/';
|
||||
}
|
||||
|
||||
public function genTreeForApPageBuilder($parent, $level, $select = array())
|
||||
{
|
||||
if ($this->hasChild($parent)) {
|
||||
$data = $this->getNodes($parent);
|
||||
|
||||
Context::getContext()->smarty->assign(array(
|
||||
'parent' => $parent,
|
||||
'level' => $level,
|
||||
'data' => $data,
|
||||
'select' => $select,
|
||||
'model_leoblogcat' => $this,
|
||||
));
|
||||
return Context::getContext()->smarty->fetch($this->getTemplatePath().'genTreeForApPageBuilder.tpl');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getTreeForApPageBuilder($select = array(), $id = null)
|
||||
{
|
||||
$childs = $this->getChild($id);
|
||||
foreach ($childs as $child) {
|
||||
$this->children[$child['id_parent']][] = $child;
|
||||
}
|
||||
$parent = 1;
|
||||
$output = $this->genTreeForApPageBuilder($parent, 1, $select);
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getFrontEndTree($id, $helper)
|
||||
{
|
||||
$child_active = 0;
|
||||
$childs = $this->getChild(null);
|
||||
foreach ($childs as $child) {
|
||||
# validate module
|
||||
$this->children[$child['id_parent']][] = $child;
|
||||
if ($child['id_parent'] != 1 && $child['active']) {
|
||||
$child_active++;
|
||||
}
|
||||
}
|
||||
|
||||
$parent = $id;
|
||||
$output = $this->genFontEndTree($parent, 1, $helper, $child_active);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function genFontEndTree($parent, $level, $helper, $child_active)
|
||||
{
|
||||
if ($this->hasChild($parent)) {
|
||||
$data = $this->getNodes($parent);
|
||||
$t = $level == 1 ? ' tree dhtml' : ' collapse';
|
||||
$id_sub = '';
|
||||
if ($level != 1) {
|
||||
$id_sub = 'sub_'.$parent;
|
||||
$output = '<ul id="'.$id_sub.'" class="level'.$level.$t.' ">';
|
||||
} else {
|
||||
$output = '<ul class="level'.$level.$t.' ">';
|
||||
}
|
||||
foreach ($data as $menu) {
|
||||
if (isset($menu['active']) && $menu['active']) {
|
||||
$params = array(
|
||||
'rewrite' => $menu['link_rewrite'],
|
||||
'id' => $menu['id_leoblogcat']
|
||||
);
|
||||
|
||||
$category_link = $helper->getBlogCatLink($params);
|
||||
|
||||
$cls = Tools::getValue('id_leoblogcat') == $menu['id_leoblogcat'] ? 'selected' : '';
|
||||
$output .= '<li id="list_'.$menu['id_leoblogcat'].'" class="'.$cls.' '.$menu['menu_class'].'"><a href="'.$category_link.'" title="'.$menu['title'].'">';
|
||||
if ($menu['icon_class']) {
|
||||
$output .= '<i class="'.$menu['icon_class'].'"></i>';
|
||||
}
|
||||
$output .= '<span>'.$menu['title'].'</span></a> ';
|
||||
|
||||
if ($menu['id_leoblogcat'] != $parent) {
|
||||
# validate module
|
||||
if ($this->hasChild($menu['id_leoblogcat']) && $child_active) {
|
||||
$output .= '<div class="navbar-toggler collapse-icons" data-toggle="collapse" data-target="#sub_'.$menu['id_leoblogcat'].'">
|
||||
<i class="material-icons add">add</i>
|
||||
<i class="material-icons remove">remove</i>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$output .= $this->genFontEndTree($menu['id_leoblogcat'], $level + 1, $helper, $child_active);
|
||||
}
|
||||
$output .= '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '</ul>';
|
||||
return $output;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function autoCreateKey()
|
||||
{
|
||||
$sql = 'SELECT '.self::$definition['primary'].' FROM '._DB_PREFIX_.bqSQL(self::$definition['table']).
|
||||
' WHERE randkey IS NULL OR randkey = ""';
|
||||
|
||||
$rows = Db::getInstance()->executes($sql);
|
||||
foreach ($rows as $row) {
|
||||
$mod_group = new Leoblogcat((int)$row[self::$definition['primary']]);
|
||||
include_once(_PS_MODULE_DIR_.'leoblog/libs/Helper.php');
|
||||
$mod_group->randkey = LeoBlogHelper::genKey();
|
||||
try {
|
||||
# Try caught to remove validate
|
||||
$mod_group->update();
|
||||
} catch (Exception $exc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
131
modules/leoblog/classes/link.php
Normal file
131
modules/leoblog/classes/link.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 Leotheme
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Content Management
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* @author leotheme <leotheme@gmail.com>
|
||||
* @copyright 2007-2015 Leotheme
|
||||
* @license http://leotheme.com - prestashop template provider
|
||||
*/
|
||||
|
||||
class LeoBlogLink extends Link
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a link to a module
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $module Module name
|
||||
* @param string $process Action name
|
||||
* @param int $id_lang
|
||||
* @return string
|
||||
* Get link of ROOT_BLOG "Show All"
|
||||
*/
|
||||
public function getLink($route_id, $controller = 'default', array $params = array(), $ssl = null, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
# validate module
|
||||
unset($controller);
|
||||
if (!$id_lang) {
|
||||
$id_lang = Context::getContext()->language->id;
|
||||
}
|
||||
$url = $this->getBaseLink($id_shop, $ssl).$this->getLangLink($id_lang, null, $id_shop);
|
||||
return $url.Dispatcher::getInstance()->createUrl($route_id, $id_lang, $params, $this->allow, '', $id_shop);
|
||||
}
|
||||
|
||||
public function getLeoblogLink($id_object, $controller, $params = array())
|
||||
{
|
||||
return $this->getLink($id_object, $controller, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pagination link
|
||||
*
|
||||
* @param string $type Controller name
|
||||
* @param int $id_object
|
||||
* @param boolean $nb Show nb element per page attribute
|
||||
* @param boolean $sort Show sort attribute
|
||||
* @param boolean $pagination Show page number attribute
|
||||
* @param boolean $array If false return an url, if true return an array
|
||||
*/
|
||||
public function getLeoPaginationLink($type, $id_object, $controller, $params, $nb = false, $sort = false, $pagination = false, $array = true)
|
||||
{
|
||||
// If no parameter $type, try to get it by using the controller name
|
||||
if (!$type && !$id_object) {
|
||||
$method_name = 'get'.Dispatcher::getInstance()->getController().'Link';
|
||||
if (method_exists($this, $method_name) && Tools::getIsset(Tools::getValue('id_'.Dispatcher::getInstance()->getController()))) {
|
||||
$type = Dispatcher::getInstance()->getController();
|
||||
$id_object = Tools::getValue('id_'.$type);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type && $id_object) {
|
||||
$url = $this->{'get'.$type.'Link'}($id_object, $controller, $params);
|
||||
} else {
|
||||
if (isset(Context::getContext()->controller->php_self)) {
|
||||
$name = Context::getContext()->controller->php_self;
|
||||
} else {
|
||||
$name = Dispatcher::getInstance()->getController();
|
||||
}
|
||||
$url = $this->getPageLink($name);
|
||||
}
|
||||
|
||||
$vars = array();
|
||||
$vars_nb = array('n', 'search_query');
|
||||
$vars_sort = array('orderby', 'orderway');
|
||||
$vars_pagination = array('p');
|
||||
|
||||
$get = array();
|
||||
$get['isolang'] = Tools::getValue('isolang');
|
||||
$get['id_lang'] = Tools::getValue('id_lang');
|
||||
$get['id'] = Tools::getValue('id');
|
||||
$get['fc'] = Tools::getValue('fc');
|
||||
$get['module'] = Tools::getValue('module');
|
||||
$get['controller'] = Tools::getValue('controller');
|
||||
|
||||
foreach ($get as $k => $value) {
|
||||
if ($k != 'id_'.$type && $k != 'controller') {
|
||||
if (Configuration::get('PS_REWRITING_SETTINGS') && ($k == 'isolang' || $k == 'id_lang')) {
|
||||
continue;
|
||||
}
|
||||
$if_nb = (!$nb || ($nb && !in_array($k, $vars_nb)));
|
||||
$if_sort = (!$sort || ($sort && !in_array($k, $vars_sort)));
|
||||
$if_pagination = (!$pagination || ($pagination && !in_array($k, $vars_pagination)));
|
||||
if ($if_nb && $if_sort && $if_pagination) {
|
||||
if (!is_array($value)) {
|
||||
$vars[urlencode($k)] = $value;
|
||||
} else {
|
||||
foreach (explode('&', http_build_query(array($k => $value), '', '&')) as $val) {
|
||||
$data = explode('=', $val);
|
||||
$vars[urldecode($data[0])] = $data[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$array) {
|
||||
if (count($vars)) {
|
||||
return $url.(($this->allow == 1 || $url == $this->url) ? '?' : '&').http_build_query($vars, '', '&');
|
||||
} else {
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
$vars['requestUrl'] = $url;
|
||||
|
||||
if ($type && $id_object) {
|
||||
$vars['id_'.$type] = (is_object($id_object) ? (int)$id_object->id : (int)$id_object);
|
||||
}
|
||||
|
||||
if (!$this->allow == 1) {
|
||||
$vars['controller'] = Dispatcher::getInstance()->getController();
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user