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) { require_once _PS_MODULE_DIR_ . "psblog/psblog.php"; require_once _PS_MODULE_DIR_ . "psblog/classes/BlogPost.php"; if (isset($_GET['search']) && trim($_GET['search']) != '') { $search = $_GET['search']; $search_nb = BlogPost::searchPosts($search, true, true, true); $this->smarty->assign('search_query', $search); $this->smarty->assign('search_query_nb', $search_nb); } $this->smarty->assign('ENT_QUOTES', ENT_QUOTES); $this->smarty->assign('linkPosts', BlogPost::linkList()); return $this->display(__FILE__, 'blocksearch.tpl'); }
private function calculHookCommon($params) { $pref = array_merge(Psblog::getPreferences(), self::getPreferences()); $img_path = rtrim($pref['img_save_path'], '/') . '/'; $list = BlogPost::listPosts(true, true, 0, intval($pref['block_limit_items'])); if ($list) { $i = 0; foreach ($list as $val) { $list[$i]['link'] = BlogPost::linkPost($val['id_blog_post'], $val['link_rewrite'], $val['id_lang']); $i++; } } $this->smarty->assign(array('last_post_list' => $list, 'blog_conf' => $pref, 'linkPosts' => BlogPost::linkList(), 'img_path' => _PS_BASE_URL_ . __PS_BASE_URI__ . $img_path, 'posts_rss_url' => BlogPost::linkRss())); return true; }
public function displayList() { $id_lang = $this->context->language->id; $id_shop = $this->context->shop->id; $limit_per_page = intval($this->conf['list_limit_page']); $current_page = isset($_GET['p']) && is_numeric($_GET['p']) ? intval($_GET['p']) : 1; $start = ($current_page - 1) * $limit_per_page; $category = null; if (!is_null($this->id_category) && is_numeric($this->id_category)) { $category = new BlogCategory(intval($this->id_category)); $category_lang = $category->id_lang; if ($category_lang != 0 && $category_lang != $id_lang || !$category->isAssociatedToShop($id_shop)) { $category->active = 0; } } if ($category && $category->active) { $nb_articles = $category->nbPosts(true, true); // first page if page not exists $max_page = ceil($nb_articles / $limit_per_page); if ($max_page < $current_page) { $current_page = 1; $start = 0; } $list = $category->getPosts(true, true, $start, intval($this->conf['list_limit_page'])); /* Metas */ $curr_meta_title = $this->context->smarty->getTemplateVars('meta_title'); $this->context->smarty->assign(array('meta_title' => $curr_meta_title . ' - ' . $category->name, 'meta_description' => $category->meta_description, 'meta_keywords' => $category->meta_keywords)); $categoryLink = BlogCategory::linkCategory($category->id, $category->link_rewrite, $category->id_lang); $paginationLink = BlogCategory::linkCategory($category->id, $category->link_rewrite, $category->id_lang, ''); $this->context->smarty->assign(array('categoryLink' => $categoryLink, 'post_category' => $category, 'paginationLink' => $paginationLink)); } elseif ($category && $category->active == 0) { $this->context->smarty->assign('post_category', false); $this->context->smarty->assign('notfound', true); } else { if (isset($_GET['search']) && $_GET['search'] != '') { //search articles $search_query = $_GET['search']; $nb_articles = BlogPost::searchPosts($search_query, true, true, true); $list = BlogPost::searchPosts($search_query, true, true, false, $start, $limit_per_page); $this->context->smarty->assign('search_query_nb', $nb_articles); $this->context->smarty->assign('search_query', $search_query); $paginationLink = BlogPost::linkList('', null, $search_query); $this->context->smarty->assign('paginationLink', $paginationLink); } else { $paginationLink = BlogPost::linkList(''); /* * * ALL ARTICLES ** */ $nb_articles = BlogPost::listPosts(true, true, null, null, true, null, null, null); $list = BlogPost::listPosts(true, true, $start, $limit_per_page, false, null, null, null); $this->context->smarty->assign('paginationLink', $paginationLink); } } if (isset($list) && is_array($list) && count($list)) { /** pagination * */ $nb_pages = ceil($nb_articles / $limit_per_page); $next = $current_page > 1 ? true : false; //articles plus recents $back = $current_page >= 1 && $current_page < $nb_pages ? true : false; //articles precedents $i = 0; foreach ($list as $val) { $list[$i]['link'] = BlogPost::linkPost($val['id_blog_post'], $val['link_rewrite'], $val['id_lang']); $categories = BlogCategory::getPostCategories($val['id_blog_post'], true, true); if ($categories) { $j = 0; foreach ($categories as $cat) { $categories[$j]['link'] = BlogCategory::linkCategory($cat['id_blog_category'], $cat['link_rewrite'], $cat['id_lang']); $j++; } } $list[$i]['categories'] = $categories; $i++; } $this->context->smarty->assign(array('post_list' => $list, 'next' => $next, 'back' => $back, 'curr_page' => $current_page)); } $this->setTemplate('list.tpl'); }