0, "img_width" => 200, "img_list_width" => 120, "category_active" => 1, "product_active" => 1, "related_active" => 1, "product_page_related" => 1, "product_img_format" => "medium_default", "comment_active" => 1, "comment_moderate" => 1, "comment_guest" => 1, "comment_min_time" => 20, "comment_name_min_length" => 2, "view_display_date" => 1, "view_display_popin" => 1, "list_limit_page" => 5, "list_display_date" => 1, "file_formats" => "jpg|jpeg|png|gif|JPG|JPEG|PNG|GIF", "img_save_path" => "modules/psblog/uploads/", "rss_active" => 1, "rss_display" => "excerpt", "share_active" => 1, //last posts block "img_block_width" => 60, "block_limit_items" => 5, "block_display_date" => 1, "block_display_img" => 1, "block_articles_home" => 0, //category block "block_display_subcategories" => 0, "featured_block_limit" => 5, "featured_block_home" => 0, "block_left" => array("posts" => 1, "posts_position" => 1, "categories" => 1, "categories_position" => 2, "archives" => 0, "archives_position" => 0, "featured" => 0, "featured_position" => 0, "search" => 0, "search_position" => 0, ), "block_right" => array("posts" => 0, "posts_position" => 0, "categories" => 0, "categories_position" => 0, "archives" => 1, "archives_position" => 2, "featured" => 1, "featured_position" => 1, "search" => 1, "search_position" => 3, ), "block_footer" => array("posts" => 0, "posts_position" => 0, "categories" => 0, "categories_position" => 0, "archives" => 0, "archives_position" => 0, "featured" => 0, "featured_position" => 0, "search" => 0, "search_position" => 0, ), ); public function __construct() { $this->bootstrap = true; $this->name = 'psblog'; $this->version = '2.4'; $this->module_key = "2eb7d51fcd2897494f1d594063c940cc"; $this->need_instance = 0; $this->tab = 'front_office_features'; parent::__construct(); $this->checkServerConf(); $this->author = 'APPSIDE'; $this->displayName = $this->l('Prestablog'); $this->description = $this->l('Blog module, articles, categories, comments and products related'); $this->confirmUninstall = $this->l('Are you sure you want to delete all Blog posts, Blog categories and Blog comments ?'); } public function install() { if(!parent::install() || !$this->registerHooks()) return false; if(!Configuration::updateValue('PSBLOG_CONF', base64_encode(serialize(self::$default_values)))) return false; Configuration::updateValue('PSBLOG_VERSION', $this->version); $this->createAdminTabs(); require_once(dirname(__FILE__) . '/install-sql.php'); $this->generateRewriteRules(); BlogShop::generateSitemap(); return true; } private function registerHooks(){ if($this->registerHook('leftColumn') && $this->registerHook('rightColumn') && $this->registerHook('footer') && $this->registerHook('displayHome') && $this->registerHook('displayBackOfficeHeader') && $this->registerHook('header') && $this->registerHook('actionHtaccessCreate') && $this->registerHook('displayFooterProduct')){ return true; } return false; } private function createAdminTabs() { $langs = Language::getLanguages(); $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); /**** create tab publications ****/ $tab0 = new Tab(); $tab0->class_name = "AdminBlog"; $tab0->module = "psblog"; $tab0->id_parent = 0; foreach ($langs as $l) { $tab0->name[$l['id_lang']] = $this->l('Blog'); } $tab0->save(); $blog_tab_id = $tab0->id; $tab1 = new Tab(); $tab1->class_name = "AdminBlogPosts"; $tab1->module = "psblog"; $tab1->id_parent = $blog_tab_id; foreach ($langs as $l) { $tab1->name[$l['id_lang']] = $this->l('Blog posts'); } $tab1->save(); /**** create tab categories ****/ $tab2 = new Tab(); $tab2->class_name = "AdminBlogCategories"; $tab2->module = "psblog"; $tab2->id_parent = $blog_tab_id; foreach ($langs as $l) { $tab2->name[$l['id_lang']] = $this->l('Blog categories'); } $tab2->save(); /**** create tab comments ****/ $tab3 = new Tab(); $tab3->class_name = "AdminBlogComments"; $tab3->module = "psblog"; $tab3->id_parent = $blog_tab_id; foreach ($langs as $l) { $tab3->name[$l['id_lang']] = $this->l('Blog comments'); } $tab3->save(); /**** create tab stats ****/ $tab4 = new Tab(); $tab4->class_name = "AdminBlogStats"; $tab4->module = "psblog"; $tab4->id_parent = $blog_tab_id; foreach ($langs as $l) { $tab4->name[$l['id_lang']] = $this->l('Informations'); } $tab4->save(); /**** create tab conf ****/ $tab5 = new Tab(); $tab5->class_name = "AdminBlogConf"; $tab5->module = "psblog"; $tab5->id_parent = $blog_tab_id; foreach ($langs as $l) { $tab5->name[$l['id_lang']] = $this->l('Configuration'); } $tab5->save(); /*** RIGHTS MANAGEMENT ***/ Db::getInstance()->Execute('DELETE FROM ' . _DB_PREFIX_ . 'access WHERE `id_tab` = ' . (int) $tab0->id . ' OR `id_tab` = ' . (int) $tab1->id . ' OR `id_tab` = ' . (int) $tab2->id . ' OR `id_tab` = ' . (int) $tab4->id . ' OR `id_tab` = ' . (int) $tab3->id); Db::getInstance()->Execute('DELETE FROM ' . _DB_PREFIX_ . 'module_access WHERE `id_module` = ' . (int) $this->id); $profiles = Profile::getProfiles($id_lang); if (count($profiles)) { foreach ($profiles as $p) { Db::getInstance()->Execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'access`(`id_profile`,`id_tab`,`view`,`add`,`edit`,`delete`) VALUES (' . $p['id_profile'] . ', ' . (int) $tab0->id . ',1,1,1,1)'); Db::getInstance()->Execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'access`(`id_profile`,`id_tab`,`view`,`add`,`edit`,`delete`) VALUES (' . $p['id_profile'] . ', ' . (int) $tab1->id . ',1,1,1,1)'); Db::getInstance()->Execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'access`(`id_profile`,`id_tab`,`view`,`add`,`edit`,`delete`) VALUES (' . $p['id_profile'] . ', ' . (int) $tab2->id . ',1,1,1,1)'); Db::getInstance()->Execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'access`(`id_profile`,`id_tab`,`view`,`add`,`edit`,`delete`) VALUES (' . $p['id_profile'] . ',' . (int) $tab3->id . ',1,1,1,1)'); Db::getInstance()->Execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'access`(`id_profile`,`id_tab`,`view`,`add`,`edit`,`delete`) VALUES (' . $p['id_profile'] . ',' . (int) $tab4->id . ',1,1,1,1)'); Db::getInstance()->Execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . 'access`(`id_profile`,`id_tab`,`view`,`add`,`edit`,`delete`) VALUES (' . $p['id_profile'] . ',' . (int) $tab5->id . ',1,1,1,1)'); Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'module_access(`id_profile`, `id_module`, `configure`, `view`) VALUES (' . $p['id_profile'] . ',' . (int) $this->id . ',1,1)'); } } } public static function getRewriteCode($id_lang) { $category = new BlogCategory(1, $id_lang); if (trim($category->link_rewrite) == '') { $defaultCategory = new BlogCategory(1, Configuration::get('PS_LANG_DEFAULT')); $category->link_rewrite = $defaultCategory->link_rewrite; } return $category->link_rewrite; } public static function generateRewriteRules() { if (Configuration::get('PS_REWRITING_SETTINGS')) { $rules = "\n#start_prestablog - not remove this comment \n"; $activeLanguages = Language::getLanguages(true); $default_lang_rewrite = self::getRewriteCode(Configuration::get('PS_LANG_DEFAULT')); $physical_uri = array(); foreach (ShopUrl::getShopUrls() as $shop_url) { if (in_array($shop_url->physical_uri, $physical_uri)) continue; $rewrites = array(); foreach ($activeLanguages as $l) { $lang_rewrite = self::getRewriteCode($l['id_lang']); if (trim($lang_rewrite) == '') { $lang_rewrite = $default_lang_rewrite; } if (!in_array($lang_rewrite, $rewrites)) { $rewrites[] = $lang_rewrite; $rules .= "RewriteRule ^(.*)" . $lang_rewrite . "$ " . $shop_url->physical_uri . "index.php?fc=module&module=psblog&controller=posts [QSA,L] \n"; $rules .= "RewriteRule ^(.*)" . $lang_rewrite . "/([0-9]+)\-([a-zA-Z0-9-]*) " . $shop_url->physical_uri . "index.php?fc=module&module=psblog&controller=posts&post=$2 [QSA,L] \n"; $rules .= "RewriteRule ^(.*)" . $lang_rewrite . "/category/([0-9]+)\-([a-zA-Z0-9-]*) " . $shop_url->physical_uri . "index.php?fc=module&module=psblog&controller=posts&category=$2 [QSA,L] \n"; } } $physical_uri[] = $shop_url->physical_uri; } $rules .= "#end_prestablog \n\n"; $path = _PS_ROOT_DIR_ . '/.htaccess'; if (is_writable($path)) { $existingRules = file_get_contents($path); if (strpos($existingRules, "start_prestablog")) { preg_match_all("/#start_prestablog(.*)#end_prestablog/Usi", $existingRules, $strings); if (is_array($strings) && isset($strings[0])) { $existingRules = str_replace($strings[0], "", $existingRules); } } $handle = fopen($path, 'w'); fwrite($handle, $rules . $existingRules); fclose($handle); } } } public function hookDisplayBackOfficeHeader($params){ $css = '"'; return $css; } public function hookActionHtaccessCreate($params) { $this->generateRewriteRules(); } public function uninstall() { /**** delete AdminPsblog tab ****/ $tab_id = Tab::getIdFromClassName("AdminBlog"); if ($tab_id) { $tab = new Tab($tab_id); $tab->delete(); } /**** delete AdminPsblogPosts tab ****/ $tab_id = Tab::getIdFromClassName("AdminBlogPosts"); if ($tab_id) { $tab = new Tab($tab_id); $tab->delete(); } /**** delete AdminPsblogCategory tab ****/ $tab_id = Tab::getIdFromClassName("AdminBlogCategories"); if ($tab_id) { $tab = new Tab($tab_id); $tab->delete(); } /**** delete AdminPsblogComment tab ****/ $tab_id = Tab::getIdFromClassName("AdminBlogComments"); if ($tab_id) { $tab = new Tab($tab_id); $tab->delete(); } /**** delete AdminPsblogStats tab *** */ $tab_id = Tab::getIdFromClassName("AdminBlogStats"); if ($tab_id) { $tab = new Tab($tab_id); $tab->delete(); } /**** delete AdminPsblogConf tab ****/ $tab_id = Tab::getIdFromClassName("AdminBlogConf"); if ($tab_id) { $tab = new Tab($tab_id); $tab->delete(); } if (!Configuration::deleteByName('PSBLOG_CONF') OR !parent::uninstall()) return false; Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_category`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_category_lang`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_post`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_post_lang`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_category_shop`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_post_shop`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_image`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_comment`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_category_relation`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_post_relation`"); Db::getInstance()->Execute("DROP TABLE `" . _DB_PREFIX_ . "blog_visit`"); return true; } public function hookHeader($params) { $this->context->controller->addCSS($this->_path . 'css/psblog.css', 'all'); } public function hookDisplayFooterProduct($params) { $id_product = (int) Tools::getValue('id_product'); if (!$id_product) return false; $pref = self::getPreferences(); $list = BlogPost::listPosts(true, true, null, null, false, null, $id_product, null); $img_path = rtrim($pref['img_save_path'], '/') . '/'; $this->smarty->assign(array( 'post_product_list' => $list, 'posts_img_path' => _PS_BASE_URL_ . __PS_BASE_URI__ . $img_path, ) ); return $this->display(__FILE__, 'product-footer.tpl'); } /** various product page hooks * */ public function hookExtraLeft($params) { return $this->hookProductTabContent($params); } public function hookExtra($params) { return $this->hookProductTabContent($params); } public function hookExtraRight($params) { return $this->hookProductTabContent($params); } public static function getPreferences() { if (is_null(self::$pref)) { $config = Configuration::get('PSBLOG_CONF'); $options = self::$default_values; if ($config) $options = array_merge($options, unserialize(base64_decode($config))); self::$pref = $options; } return self::$pref; } public static function getConfValue($value) { $pref = self::getPreferences(); return self::$pref[$value]; } public static function blogIsAvailable() { $context = Context::getContext(); $defaultCategory = new BlogCategory(1, $context->language->id); if (is_null(self::$blogIsAvailable)) { self::$blogIsAvailable = $defaultCategory->isAllowed(); } return self::$blogIsAvailable; } public function checkServerConf() { $pref = self::getPreferences(); $this->warning = ''; if (!is_writable(_PS_ROOT_DIR_ . '/' . $pref['img_save_path'])) { $this->warning .= _PS_ROOT_DIR_ . '/' . $pref['img_save_path'] . ' ' . $this->l('must be writable') . "
"; } if (!is_writable(_PS_ROOT_DIR_ . '/' . $pref['img_save_path'] . 'thumb/')) { $this->warning .= _PS_ROOT_DIR_ . '/' . $pref['img_save_path'] . 'thumb/ ' . $this->l('must be writable') . "
"; } if (!is_writable(_PS_ROOT_DIR_ . '/' . $pref['img_save_path'] . 'list/')) { $this->warning .= _PS_ROOT_DIR_ . '/' . $pref['img_save_path'] . 'list/ ' . $this->l('must be writable') . "
"; } } private function _postValidation() { $numericValues = array('img_width', 'img_list_width', 'list_limit_page', 'comment_min_time', 'comment_name_min_length', 'img_block_width', 'block_limit_items', 'featured_block_limit'); if (Tools::isSubmit('submitPsblog')) { $pref = Tools::getValue('pref'); foreach ($numericValues as $val) { if (trim($pref[$val]) == '' || !is_numeric($pref[$val])) { $this->_postErrors[] = $val . ' ' . $this->l(' must be a numeric value'); } } } } private function _postProcess() { if (Tools::isSubmit('submitPsblog')) { $pref = Tools::getValue('pref'); $old_values = self::getPreferences(); $checkboxes = array('category_active', 'product_active', 'comment_active', 'comment_moderate', 'comment_guest', 'list_display_date', 'view_display_date', 'related_active', 'view_display_popin', 'rewrite_active', 'product_page_related', 'rss_active', 'share_active', 'block_display_date', 'block_articles_home', 'block_display_img', 'block_display_subcategories', 'featured_block_home'); foreach ($checkboxes as $input) { if (!isset($pref[$input])) $pref[$input] = 0; } $new_values = array_merge(self::$default_values, $pref); Configuration::updateValue('PSBLOG_CONF', base64_encode(serialize($new_values))); $this->_html .= '
' . $this->l('Settings updated') . '
'; } elseif (Tools::isSubmit('submitGenerateImg')) { $images = BlogPost::getAllImages(); $save_path = _PS_ROOT_DIR_ . '/' . rtrim(self::$pref['img_save_path'], '/') . "/"; foreach ($images as $img) { @unlink($save_path . 'thumb/' . $img['img_name']); @unlink($save_path . 'list/' . $img['img_name']); BlogPost::generateImageThumbs($img['id_blog_image']); } $this->_html .= '
' . $this->l('Images regenerated') . '
'; } elseif (Tools::isSubmit('submitGenerateSitemap')) { include_once(_PS_MODULE_DIR_ . "psblog/classes/BlogShop.php"); BlogShop::generateSitemap(); $this->_html .= '
' . $this->l('Google sitemap regenerated') . '
'; } elseif (Tools::isSubmit('submitUpgrade')) { $result = Db::getInstance()->executeS('SELECT `id_hook` FROM `'._DB_PREFIX_.'hook_module` WHERE `id_module` = '.(int)$this->id); foreach ($result as $row) { $this->unregisterHook((int)$row['id_hook']); $this->unregisterExceptions((int)$row['id_hook']); } $this->registerHooks(); Configuration::updateValue('PSBLOG_VERSION', $this->version); $this->_html .= '
' . $this->l('Module have been upgraded') . '
'; } } private function _displayForm() { $values = (Tools::isSubmit('submitPsblog')) ? Tools::getValue('pref') : array_merge(self::$default_values, self::getPreferences()); $this->_html .=''; $this->_html .='

' . $this->l('General') . '

'; $this->_html .= '
'; $this->_html .= '

' . $this->l('List settings') . '

px
'; $this->_html .= '
'; $this->_html .= '

' . $this->l('View settings') . '

px
'; $this->_html .= '

' . $this->l('Related products settings') . '

'; $formats = ImageType::getImagesTypes(); $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '

' . $this->l('Comments settings') . '

' . $this->l('seconds') . '
' . $this->l('characters') . '
'; $this->_html .= '
'; $this->_html .= '

' . $this->l('RSS settings') . '

'; $this->_html .= '
'; $this->_html .= '

' . $this->l('Block last posts settings') . '

  ' . $this->l('instead of column') . '
px
'; $this->_html .= '

' . $this->l('Prestablog categories block settings') . '

'; $this->_html .= '

' . $this->l('Prestablog featured block settings') . '

  ' . $this->l('instead of column') . '
'; $blocks = array('block_left' => 'Left column','block_right' => 'Right column','block_footer' => 'Footer'); foreach ($blocks as $key => $legend) { $this->_html .= '

' . $legend . '

'; $this->_html .= '
    ' . $this->l('Position') . '
'; $this->_html .= '
    ' . $this->l('Position') . '
'; $this->_html .= '
    ' . $this->l('Position') . '
'; $this->_html .= '
    ' . $this->l('Position') . '
'; $this->_html .= '
    ' . $this->l('Position') . '
'; $this->_html .= '
'; } $this->_html .= '
'; $this->_html .= '

' . $this->l('Tools') . '

' . $this->l('Useful if you change the images sizes') . '

'; if (self::isInstalled('gsitemap')) { $this->_html .= '

  ' . _PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/psblog/sitemap-blog.xml

'; } $current_version = Configuration::get('PSBLOG_VERSION'); if($current_version < $this->version){ $this->_html .= '

'; } $this->_html .= '

' . $this->l('If url rewriting doesn\'t works, check that this above lines exist in your current .htaccess file, if no, add it manually on top of your .htaccess file') . ':

'; $default_lang_rewrite = self::getRewriteCode(Configuration::get('PS_LANG_DEFAULT')); $physical_uri = array(); foreach (ShopUrl::getShopUrls() as $shop_url) { if (in_array($shop_url->physical_uri, $physical_uri)) continue; $activeLanguages = Language::getLanguages(true); $rewrites = array(); foreach ($activeLanguages as $l) { $lang_rewrite = self::getRewriteCode($l['id_lang']); if (trim($lang_rewrite) == '') { $lang_rewrite = $default_lang_rewrite; } if (!in_array($lang_rewrite, $rewrites)) { $rewrites[] = $lang_rewrite; $this->_html .= "RewriteRule ^(.*)" . $lang_rewrite . "$ " . $shop_url->physical_uri . "index.php?fc=module&module=psblog&controller=posts [QSA,L]
"; $this->_html .= "RewriteRule ^(.*)" . $lang_rewrite . "/([0-9]+)\-([a-zA-Z0-9-]*) " . $shop_url->physical_uri . "index.php?fc=module&module=psblog&controller=posts&post=$2 [QSA,L]
"; $this->_html .= "RewriteRule ^(.*)" . $lang_rewrite . "/category/([0-9]+)\-([a-zA-Z0-9-]*) " . $shop_url->physical_uri . "index.php?fc=module&module=psblog&controller=posts&category=$2 [QSA,L]
"; $this->_html .= "
"; $physical_uri[] = $shop_url->physical_uri; } } } $this->_html .= '

'; $this->_html .= '

' . $this->l('To declare blog sitemap xml, add this line at the end of your robots.txt file') . ':

Sitemap ' . _PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/psblog/sitemap-blog.xml

'; $this->_html .= '
'; } public static function getRewriteConf() { self::getPreferences(); return self::$pref['rewrite_active']; } public function getContent() { $this->checkServerConf(); if ($this->warning != '') { $this->_html .= '
' . $this->warning . '
'; } $this->_html .= '

' . $this->l('Prestablog settings') . '

'; $this->_html .= '

' . $this->l('If you want to add articles, you must go to the Blog tab on the navigation menu') . '

'; $this->_postValidation(); if (!isset($this->_postErrors) || !sizeof($this->_postErrors)) { $this->_postProcess(); } else { foreach ($this->_postErrors AS $err) $this->_html .= '
' . $err . '
'; } $this->_displayForm(); return $this->_html; } public function hookRightColumn($params) { return $this->getBlocks('block_right', $params); } public function hookLeftColumn($params) { return $this->getBlocks('block_left', $params); } public function hookFooter($params) { return $this->getBlocks('block_footer', $params); } protected function getBlocks($block_type, $params) { if (self::$blogIsAvailable) return ''; $pref = self::getPreferences(); $output = ''; $blocks = array( array('name' => 'search', 'order' => $pref[$block_type]['search_position'], 'active' => (int) $pref[$block_type]['search'], 'call' => 'blockSearch'), array('name' => 'categories', 'order' => $pref[$block_type]['categories_position'], 'active' => (int) $pref[$block_type]['categories'], 'call' => 'blockCategories'), array('name' => 'posts', 'order' => $pref[$block_type]['posts_position'], 'active' => (int) $pref[$block_type]['posts'], 'call' => 'blockLastPosts'), array('name' => 'archives', 'order' => $pref[$block_type]['archives_position'], 'active' => (int) $pref[$block_type]['archives'], 'call' => 'blockArchives'), array('name' => 'featured', 'order' => $pref[$block_type]['featured_position'], 'active' => (int) $pref[$block_type]['featured'], 'call' => 'blockFeatured')); $hookBlocks = array(); foreach ($blocks as $b) if ($b['active']) $hookBlocks[] = $b; $orders = array(); foreach ($hookBlocks as $key => $b) $orders[$key] = $b['order']; array_multisort($orders, SORT_ASC, $hookBlocks); $this->smarty->assign('block_type', $block_type); foreach ($hookBlocks as $b) { $output .= call_user_func(array($this, $b['call']), $params, $block_type, $this, $b['order']); } return $output; } public function hookDisplayHome($params) { $pref = self::getPreferences(); $is_home = Tools::getValue('controller') == 'index' ? true : false; $img_path = rtrim($pref['img_save_path'], '/') . '/'; $list = BlogPost::listPosts(true, true, 0, intval($pref['block_limit_items']),false,2); $this->smarty->assign(array('posts_list' => $list, 'posts_conf' => $pref, 'linkPosts' => BlogCategory::linkCategory(2), 'posts_title' => $this->l('Our News'), 'posts_img_path' => _PS_BASE_URL_ . __PS_BASE_URI__ . $img_path, 'posts_rss_url' => BlogPost::linkRss())); return $this->display(__FILE__, 'blockpostshome.tpl'); } public function hookDisplayHomeNextBlog($params){ $pref = self::getPreferences(); $is_home = Tools::getValue('controller') == 'index' ? true : false; $img_path = rtrim($pref['img_save_path'], '/') . '/'; $list = BlogPost::listPosts(true, true, 0, intval($pref['block_limit_items']),false,3); $this->smarty->assign(array('posts_list' => $list, 'posts_conf' => $pref, 'linkPosts' =>BlogCategory::linkCategory(3), 'posts_title' => $this->l('Our dossier and advice'), 'posts_img_path' => _PS_BASE_URL_ . __PS_BASE_URI__ . $img_path, 'posts_rss_url' => BlogPost::linkRss())); return $this->display(__FILE__, 'blocklastpostshome.tpl'); } protected function blockLastPosts($params, $block_type, $pos = null) { $pref = self::getPreferences(); $is_home = Tools::getValue('controller') == 'index' ? true : false; $img_path = rtrim($pref['img_save_path'], '/') . '/'; $list = BlogPost::listPosts(true, true, 0, intval($pref['block_limit_items'])); $this->smarty->assign(array('posts_list' => $list, 'posts_conf' => $pref, 'linkPosts' => BlogPost::linkList(), 'posts_title' => $this->l('Last blog articles'), 'posts_img_path' => _PS_BASE_URL_ . __PS_BASE_URI__ . $img_path, 'posts_rss_url' => BlogPost::linkRss())); if ($is_home && $pref['block_articles_home'] == 1 && ($block_type == 'block_left' || $block_type == 'block_right')) { return ''; } elseif ($is_home && $pref['block_articles_home'] == 1 && $block_type == 'home') { return $this->display(__FILE__, 'blockpostshome.tpl'); } elseif ($block_type == 'block_footer') { return $this->display(__FILE__, 'blockposts_footer.tpl'); } else { return $this->display(__FILE__, 'blockposts.tpl'); } } protected function blockCategories($params, $block_type, $pos = null) { if (!$this->getConfValue('category_active')) return ''; $pref = self::getPreferences(); $list = BlogCategory::listCategories(true, true, true, false, array(1,2)); if (Tools::getValue('controller') == "posts" && Tools::getIsset('category')) { $current_category_id = (int) Tools::getValue('category'); $category = new BlogCategory($current_category_id, $this->context->language->id); if (!is_null($category->id_blog_category_parent) && !empty($category->id_blog_category_parent)) { $current_category_id = $category->id_blog_category_parent; } $this->smarty->assign('blog_category', $current_category_id); } $this->smarty->assign(array('post_categories' => $list, 'blog_conf' => $pref)); if ($block_type == 'block_footer') { return $this->display(__FILE__, 'blockcategories_footer.tpl'); } else { // last change to put private sales on right column of blog $id_post = (int) Tools::getValue('post'); if($id_post){ $post = new BlogPost($id_post,$this->context->language->id); $sales = $post->getSalesPosts(true, true); $this->context->smarty->assign(array( 'sales' => $sales, 'link_img' => 'modules/privatesales/img/', 'link_mod_img' => _PS_MODULE_DIR_.'modules/privatesales/img/', 'title_sale' => $this->l('Ventes en relation') )); } else{ $sales = SaleCore::getSales('current', 0, true, false, true, 'rand'); if($sales){ $this->context->smarty->assign(array( 'sales' => $sales, 'link_img' => 'modules/privatesales/img/', 'link_mod_img' => _PS_MODULE_DIR_.'modules/privatesales/img/' )); } } return $this->display(__FILE__, 'blockcategories.tpl'); } } protected function blockSearch($params, $block_type, $pos = null) { $pref = self::getPreferences(); if (Tools::getValue('search') != '') { $search = Tools::getValue('search'); $search_nb = BlogPost::searchPosts($search, true, true, true); $this->smarty->assign('search_query', $search); $this->smarty->assign('search_query_nb', $search_nb); } $rewrite = (Configuration::get('PS_REWRITING_SETTINGS')) ? true : false; $this->smarty->assign('rewrite', $rewrite); $this->smarty->assign('ENT_QUOTES', ENT_QUOTES); $this->smarty->assign('linkPosts', BlogPost::linkList()); return $this->display(__FILE__, 'blocksearch.tpl'); } protected function blockFeatured($params, $block_type, $pos = null) { $pref = self::getPreferences(); $is_home = Tools::getValue('controller') == 'index' ? true : false; $img_path = rtrim($pref['img_save_path'], '/') . '/'; $category = new BlogCategory(2, $this->context->language->id); $list = $category->getPosts(true, true, 0, intval($pref['featured_block_limit'])); $this->smarty->assign(array('posts_list' => $list, 'posts_conf' => $pref, 'posts_title' => $category->name, 'linkPosts' => BlogPost::linkList(), 'posts_img_path' => _PS_BASE_URL_ . __PS_BASE_URI__ . $img_path, 'posts_rss_url' => BlogPost::linkRss())); if ($is_home && $pref['featured_block_home'] == 1 && ($block_type == 'block_left' || $block_type == 'block_right')) { return ''; } elseif ($is_home && $pref['featured_block_home'] == 1 && $block_type == 'home') { return $this->display(__FILE__, 'blockpostshome.tpl'); } elseif ($block_type == 'block_footer') { return $this->display(__FILE__, 'blockposts_footer.tpl'); } else { return $this->display(__FILE__, 'blockposts.tpl'); } } protected function blockArchives($params, $block_type, $pos = null) { $pref = self::getPreferences(); $archives = BlogPost::getArchives(); $langMonths = array( 1 => $this->l('January'), 2 => $this->l('February'), 3 => $this->l('March'), 4 => $this->l('April'), 5 => $this->l('May'), 6 => $this->l('June'), 7 => $this->l('July'), 8 => $this->l('August'), 9 => $this->l('September'), 10 => $this->l('October'), 11 => $this->l('November'), 12 => $this->l('December')); $list = array(); foreach ($archives as $val) { if (!array_key_exists('year', $val) || !array_key_exists('month', $val)) continue; $year = $val['year']; $month = isset($langMonths[$val['month']]) ? $langMonths[$val['month']] : null; if (is_null($month) || is_null($year)) continue; if (isset($list[$year])) $list[$year]['nb'] += (int) $val['nb']; else $list[$year]['nb'] = (int) $val['nb']; if ($year == date('Y')) { $list[$year]['months'][$val['month']]['name'] = $month; $list[$year]['months'][$val['month']]['nb'] = $val['nb']; } } $linkPosts = (Configuration::get('PS_REWRITING_SETTINGS')) ? BlogPost::linkList() . '?' : BlogPost::linkList() . '&'; $this->smarty->assign(array('blog_archives' => $list, 'blog_conf' => $pref, 'posts_rss_url' => BlogPost::linkRss())); $this->smarty->assign('linkPosts', $linkPosts); return $this->display(__FILE__, 'blockarchives.tpl'); } public static function getBlogConfigurationLink(){ $context = Context::getContext(); $tokenModules = Tools::getAdminToken('AdminModules' . (int) (Tab::getIdFromClassName('AdminModules')) . (int) $context->employee->id); $blog_conf = 'index.php?controller=AdminModules&configure=psblog&module_name=psblog&token=' . $tokenModules; return $blog_conf; } }