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('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 .= '