update
This commit is contained in:
@@ -49,7 +49,8 @@ class Projectproblog extends Module
|
||||
return parent::install()
|
||||
&& $this->installSql()
|
||||
&& $this->installTabs()
|
||||
&& $this->registerHook('moduleRoutes');
|
||||
&& $this->registerHook('moduleRoutes')
|
||||
&& $this->registerHook('displayHome');
|
||||
}
|
||||
|
||||
protected function createImgDir()
|
||||
@@ -195,6 +196,8 @@ class Projectproblog extends Module
|
||||
|
||||
public function hookModuleRoutes()
|
||||
{
|
||||
$this->ensureDisplayHomeHookRegistration();
|
||||
|
||||
return [
|
||||
'module-projectproblog-list' => [
|
||||
'controller' => 'list',
|
||||
@@ -236,6 +239,21 @@ class Projectproblog extends Module
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Zapewnia podpiecie hooka displayHome takze dla istniejacych instalacji.
|
||||
*/
|
||||
protected function ensureDisplayHomeHookRegistration()
|
||||
{
|
||||
$idHook = (int) Hook::getIdByName('displayHome');
|
||||
if ($idHook <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->isRegisteredInHook('displayHome')) {
|
||||
$this->registerHook('displayHome');
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* HELPERS — generowanie linków */
|
||||
/* ------------------------------------------------------------------ */
|
||||
@@ -266,4 +284,43 @@ class Projectproblog extends Module
|
||||
$idLang
|
||||
);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* HOMEPAGE HOOK */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
public function hookDisplayHome()
|
||||
{
|
||||
$idLang = (int) $this->context->language->id;
|
||||
$posts = BlogPost::getLatest($idLang, 3);
|
||||
|
||||
if (empty($posts)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$base = $this->context->link->getBaseLink();
|
||||
foreach ($posts as &$post) {
|
||||
$post['thumbnail_url'] = $post['thumbnail']
|
||||
? $base . 'modules/projectproblog/views/img/posts/' . $post['thumbnail']
|
||||
: null;
|
||||
$post['url'] = self::getPostUrl($post['link_rewrite'], $idLang);
|
||||
}
|
||||
unset($post);
|
||||
|
||||
if (isset($this->context->controller)) {
|
||||
$this->context->controller->registerStylesheet(
|
||||
'module-projectproblog-blog',
|
||||
'modules/projectproblog/views/css/blog.css',
|
||||
['media' => 'all', 'priority' => 200]
|
||||
);
|
||||
}
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'blog_home_title' => $this->l('Najnowsze na blogu'),
|
||||
'blog_home_posts' => $posts,
|
||||
'blog_url' => self::getBlogUrl($idLang),
|
||||
]);
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/hook/home.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user