public static function generateSitemap() { require_once _PS_MODULE_DIR_ . 'psblog/classes/BlogCategory.php'; require_once _PS_MODULE_DIR_ . 'psblog/classes/BlogPost.php'; $filename = _PS_MODULE_DIR_ . 'psblog/sitemap-blog.xml'; if (!is_writable($filename)) { return FALSE; } $sql = 'SELECT s.id_shop, su.domain, su.domain_ssl, CONCAT(su.physical_uri, su.virtual_uri) as uri FROM ' . _DB_PREFIX_ . 'shop s INNER JOIN ' . _DB_PREFIX_ . 'shop_url su ON s.id_shop = su.id_shop AND su.main = 1 WHERE s.active = 1 AND s.deleted = 0 AND su.active = 1'; if (!($result = Db::getInstance()->executeS($sql))) { return false; } $xml = simplexml_load_file($filename); unset($xml->url); $sxe = new SimpleXMLElement($xml->asXML()); foreach ($result as $row) { $shopContext = Context::getContext()->cloneContext(); $shopContext->shop = new Shop($row['id_shop']); $languages = Language::getLanguages(true, $row['id_shop']); foreach ($languages as $l) { $shopContext->language->id_lang = $l['id_lang']; $shopContext->language->iso_code = $l['iso_code']; $url = $sxe->addChild('url'); $listlink = BlogPost::linkList(null, $shopContext); $listlink = str_replace('&', '&', $listlink); $url->addChild('loc', $listlink); $url->addChild('priority', '0.7'); $url->addChild('changefreq', 'weekly'); } unset($shopContext->language); $shopPosts = BlogPost::listPosts($shopContext, true); foreach ($shopPosts as $post) { $postlink = BlogPost::linkPost($post['id_blog_post'], $post['link_rewrite'], $post['id_lang'], $shopContext); $postlink = str_replace('&', '&', $postlink); $url = $sxe->addChild('url'); $url->addChild('loc', $postlink); $url->addChild('priority', '0.6'); $url->addChild('changefreq', 'monthly'); } $shopCategories = BlogCategory::listCategories($shopContext, true); foreach ($shopCategories as $cat) { $catlink = BlogCategory::linkCategory($cat['id_blog_category'], $cat['link_rewrite'], $cat['id_lang'], null, $shopContext); $catlink = str_replace('&', '&', $catlink); $url = $sxe->addChild('url'); $url->addChild('loc', $catlink); $url->addChild('priority', '0.6'); $url->addChild('changefreq', 'monthly'); } $sxe->asXML($filename); } }
public function hookLeftColumn($params) { if (!$this->checkServerConf()) { return false; } require_once _PS_MODULE_DIR_ . "psblog/psblog.php"; require_once _PS_MODULE_DIR_ . "psblog/classes/BlogCategory.php"; $pref = array_merge(Psblog::getPreferences(), self::getPreferences()); $list = BlogCategory::listCategories(true, true); if ($list) { $i = 0; foreach ($list as $val) { $list[$i]['link'] = BlogCategory::linkCategory($val['id_blog_category'], $val['link_rewrite'], $val['id_lang']); $i++; } } $this->smarty->assign(array('post_categories' => $list, 'post_conf' => $pref)); return $this->display(__FILE__, 'blockcategories.tpl'); }
public function displayPost() { $id_lang = $this->context->language->id; $id_shop = $this->context->shop->id; if (is_null($this->id_post) || !is_numeric($this->id_post)) { return $this->displayList(); } $post = new BlogPost($this->id_post); if ($post->status == 'published' && $post->isAssociatedToShop($id_shop)) { //comment submit if (Tools::isSubmit('submitMessage') && $this->conf['comment_active'] && $post->allow_comments) { $comment = new BlogComment(); try { $message = trim(strip_tags(Tools::getValue('blog_comment'))); $comment->id_blog_post = $this->id_post; $comment->customer_name = pSQL(Tools::getValue('customer_name')); if ($message == '' || strlen($comment->customer_name) < (int) $this->conf['comment_name_min_length']) { throw new Exception('error_input'); } if (!Validate::isMessage($message) || !Validate::isGenericName($comment->customer_name)) { throw new Exception('error_input_invalid'); } $comment->content = $message; $id_customer = (int) $this->context->customer->id; $id_guest = (int) $this->context->cookie->id_guest; if (!$this->conf['comment_guest'] && empty($id_customer)) { throw new Exception('error_guest'); } //get last comment from customer $customerComment = BlogComment::getByCustomer($this->id_post, $id_customer, true, $id_guest); $comment->id_customer = $id_customer; $comment->id_guest = $id_guest; $comment->id_lang = $id_lang; $comment->id_shop = $id_shop; if ($customerComment['content'] == $comment->content) { throw new Exception('error_already'); } if ($customerComment && strtotime($customerComment['date_add']) + (int) $this->conf['comment_min_time'] > time()) { throw new Exception('error_delay'); } $comment->active = $this->conf['comment_moderate'] ? 0 : 1; $comment->save(); $this->context->smarty->assign('psblog_confirmation', true); } catch (Exception $e) { $comment->content = Tools::getValue('blog_comment'); $comment->customer_name = Tools::getValue('customer_name'); $this->context->smarty->assign('psblog_error', $e->getMessage()); $this->context->smarty->assign('comment', $comment); } } /* * * view article ** */ $images = $post->getImages(false); $categories = $post->listCategories(true); $products = $post->getProducts(true); $related = $post->listRelated(true, true); if (is_array($related) && count($related) > 0) { $i = 0; foreach ($related as $val) { $related[$i]['link'] = BlogPost::linkPost($val['id_blog_post'], $val['link_rewrite'], $val['id_lang']); $i++; } } if (is_array($products) && count($products) > 0) { $i = 0; foreach ($products as $p) { $product = new Product($p['id_product'], false, $id_lang); $products[$i]['link'] = $this->context->link->getProductLink($product); $products[$i]['imageLink'] = $this->context->link->getImageLink($p['link_rewrite'], $p['id_product'] . '-' . $p['id_image'], $this->conf['product_img_format']); $i++; } } /* SEO metas */ $curr_meta_title = $this->context->smarty->getTemplateVars('meta_title'); $this->context->smarty->assign(array('meta_title' => $curr_meta_title . ' - ' . $post->title, 'meta_description' => $post->meta_description, 'meta_keywords' => $post->meta_keywords)); if ($this->conf['view_display_popin'] == 1) { $this->addjqueryPlugin('fancybox'); $this->addJS($this->module->getPathUri() . 'js/popin.js'); } if ($categories) { $i = 0; foreach ($categories as $cat) { $categories[$i]['link'] = BlogCategory::linkCategory($cat['id_blog_category'], $cat['link_rewrite'], $cat['id_lang']); $i++; } } $comments = $post->getComments(); $this->context->smarty->assign(array('post_images' => $images, 'post_products' => $products, 'post_related' => $related, 'post_categories' => $categories, 'post_comments' => $comments)); } else { $post->status = 'suspended'; } $this->context->smarty->assign('post', $post); $this->setTemplate('view.tpl'); }