public static function simpleMap(SimpleBlogPost $blogPost, array $properties) { if (array_key_exists('blog_id', $properties)) { $blogPost->setId((int) $properties['blog_id']); } if (array_key_exists('date', $properties)) { $formattedDate = $properties['date']; $date = self::createDateTime($formattedDate); if ($date) { $blogPost->setDate($date); } } if (array_key_exists('content', $properties)) { $blogPost->setContent($properties['content']); } if (array_key_exists('created_by', $properties)) { $blogPost->setCreatedBy($properties['created_by']); } if (array_key_exists('description', $properties)) { $blogPost->setDescription($properties['description']); } if (array_key_exists('modified_by', $properties)) { $blogPost->setModifiedBy($properties['modified_by']); } if (array_key_exists('restaurant_id', $properties)) { $blogPost->setRestaurantId($properties['restaurant_id']); } }
public function delete() { if ((int) $this->id === 0) { return false; } return SimpleBlogPost::deleteCover($this) && SimpleBlogPost::deleteFeatured($this) && parent::delete(); }
public function initContent() { $this->context->controller->addJqueryPlugin('cooki-plugin'); $sidebar = Configuration::get('PH_BLOG_LAYOUT'); if ($sidebar == 'left_sidebar') { $this->display_column_left = true; $this->display_column_right = false; } elseif ($sidebar == 'right_sidebar') { $this->display_column_left = false; $this->display_column_right = true; } elseif ($sidebar == 'full_width') { $this->display_column_left = false; $this->display_column_right = false; } else { $this->display_column_left = true; $this->display_column_right = true; } parent::initContent(); $id_lang = Context::getContext()->language->id; $SimpleBlogPost = SimpleBlogPost::getByRewrite($this->simpleblog_post_rewrite, $id_lang); $logged = isset(Context::getContext()->customer) && Context::getContext()->customer->isLogged() ? true : false; if (Validate::isLoadedObject($SimpleBlogPost) && $SimpleBlogPost->logged && !$logged || Validate::isLoadedObject($SimpleBlogPost) && !$SimpleBlogPost->active) { Tools::redirect('index.php?controller=404'); } $this->context->smarty->assign('meta_title', $SimpleBlogPost->meta_title); if (!empty($SimpleBlogPost->meta_description)) { $this->context->smarty->assign('meta_description', $SimpleBlogPost->meta_description); } if (!empty($SimpleBlogPost->meta_keywords)) { $this->context->smarty->assign('meta_keywords', $SimpleBlogPost->meta_keywords); } if (!Validate::isLoadedObject($SimpleBlogPost)) { $SimpleBlogPost = SimpleBlogPost::getByRewrite($this->simpleblog_post_rewrite, false); if (Validate::isLoadedObject($SimpleBlogPost)) { $SimpleBlogPost = new SimpleBlogPost($SimpleBlogPost->id, $id_lang); header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . SimpleBlogPost::getLink($SimpleBlogPost->link_rewrite, $SimpleBlogPost->category_rewrite)); } else { Tools::redirect('index.php?controller=404'); } } $SimpleBlogPost->increaseViewsNb(); $this->context->smarty->assign('post', $SimpleBlogPost); $this->context->smarty->assign('is_16', (bool) (version_compare(_PS_VERSION_, '1.6.0', '>=') === true)); $this->setTemplate('single.tpl'); }
public function initContent() { $this->multiple_fieldsets = true; if (Tools::isSubmit('regenerateThumbnails')) { SimpleBlogPost::regenerateThumbnails(); Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=9'); } $this->context->smarty->assign(array('content' => $this->content, 'url_post' => self::$currentIndex . '&token=' . $this->token)); parent::initContent(); }
public function preparePosts($nb = 4, $cat = null) { $featured = false; if ($cat == 9999) { $cat = 0; $featured = true; } if (!Module::isInstalled('ph_simpleblog') || !Module::isEnabled('ph_simpleblog')) { return false; } if (!isset($nb) || !isset($cat)) { return false; } require_once _PS_MODULE_DIR_ . 'ph_simpleblog/models/SimpleBlogPost.php'; $id_lang = $this->context->language->id; $posts = SimpleBlogPost::getPosts($id_lang, $nb, $cat, null, true, 'sbp.date_add', 'DESC', null, $featured); return $posts; }
public function deleteCover($id) { $object = new SimpleBlogPost($id, Context::getContext()->language->id); $tmp_location = _PS_TMP_IMG_DIR_ . 'ph_simpleblog_' . $object->id . '.' . $object->cover; if (file_exists($tmp_location)) { @unlink($tmp_location); } $orig_location = _PS_MODULE_DIR_ . 'ph_simpleblog/covers/' . $object->id . '.' . $object->cover; $thumb = _PS_MODULE_DIR_ . 'ph_simpleblog/covers/' . $object->id . '-thumb.' . $object->cover; $thumbWide = _PS_MODULE_DIR_ . 'ph_simpleblog/covers/' . $object->id . '-wide.' . $object->cover; if (file_exists($orig_location)) { @unlink($orig_location); } if (file_exists($thumb)) { @unlink($thumb); } if (file_exists($thumbWide)) { @unlink($thumbWide); } $object->cover = NULL; $object->update(); Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminSimpleBlogPosts') . '&conf=7'); }
public function initContent() { $this->multiple_fieldsets = true; if (Tools::isSubmit('regenerateThumbnails')) { SimpleBlogPost::regenerateThumbnails(); Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getValue('token') . '&conf=9'); } if (Tools::isSubmit('submitExportSettings')) { header("Content-type: text/plain"); header("Content-Disposition: attachment; filename=ph_simpleblog_configuration_" . date('d-m-Y') . ".txt"); $configs = array(); foreach ($this->fields_options as $category_data) { if (!isset($category_data['fields'])) { continue; } $fields = $category_data['fields']; foreach ($fields as $field => $values) { if ($values['type'] == 'textLang') { $configs[$field] = self::getValueForLangs($field); } else { $configs[$field] = Configuration::get($field); } } } echo serialize($configs); exit; } $this->context->smarty->assign(array('content' => $this->content, 'url_post' => self::$currentIndex . '&token=' . $this->token)); parent::initContent(); }
<?php include dirname(__FILE__) . '/../../config/config.inc.php'; include dirname(__FILE__) . '/../../init.php'; $status = 'success'; $message = ''; include_once dirname(__FILE__) . '/ph_simpleblog.php'; include_once dirname(__FILE__) . '/models/SimpleBlogPost.php'; $action = Tools::getValue('action'); switch ($action) { case 'addRating': $simpleblog_post_id = Tools::getValue('simpleblog_post_id'); $reply = SimpleBlogPost::changeRating('up', (int) $simpleblog_post_id); $message = $reply[0]["likes"]; break; case 'removeRating': $simpleblog_post_id = Tools::getValue('simpleblog_post_id'); $reply = SimpleBlogPost::changeRating('down', (int) $simpleblog_post_id); $message = $reply[0]["likes"]; break; default: $status = 'error'; $message = 'Unknown parameters!'; break; } $response = new stdClass(); $response->status = $status; $response->message = $message; $response->action = $action; echo json_encode($response);
public function hookDisplaySimpleBlogPosts($params) { return; $id_lang = $this->context->language->id; $posts = SimpleBlogPost::getPosts($id_lang, 5); $this->smarty->assign('posts', $posts); return $this->display(__FILE__, 'home.tpl'); }
private static function isValidStatus($status) { return in_array($status, SimpleBlogPost::allStatuses()); }
public function initContent() { $id_lang = Context::getContext()->language->id; parent::initContent(); $this->context->smarty->assign('is_16', (bool) (version_compare(_PS_VERSION_, '1.6.0', '>=') === true)); $gridType = Configuration::get('PH_BLOG_COLUMNS'); $gridColumns = Configuration::get('PH_BLOG_GRID_COLUMNS'); $blogLayout = Configuration::get('PH_BLOG_LIST_LAYOUT'); $gridHtmlCols = ''; if ($blogLayout == 'full') { $gridHtmlCols = 'ph_col'; } $this->context->smarty->assign(array('categories' => SimpleBlogCategory::getCategories($id_lang), 'latest_posts' => SimpleBlogPost::getPosts($id_lang, 5), 'blogMainTitle' => Configuration::get('PH_BLOG_MAIN_TITLE', $id_lang), 'grid' => Configuration::get('PH_BLOG_COLUMNS'), 'columns' => $gridColumns, 'gridHtmlCols' => $gridHtmlCols, 'blogLayout' => $blogLayout, 'module_dir' => _MODULE_DIR_ . 'ph_simpleblog/', 'tpl_path' => _PS_MODULE_DIR_ . 'ph_simpleblog/views/templates/front/', 'gallery_dir' => _MODULE_DIR_ . 'ph_simpleblog/galleries/')); $page = Tools::getValue('p', 0); // How many posts? $this->posts_per_page = Configuration::get('PH_BLOG_POSTS_PER_PAGE'); // Is blog category, author or something else? $this->context->smarty->assign('is_category', false); $this->context->smarty->assign('is_search', false); // Category things if ($this->sb_category != '') { $this->context->smarty->assign('is_category', true); $SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, $id_lang); // Category not found so now we looking for categories in same rewrite but other languages and if we found then we redirect 301 if (!Validate::isLoadedObject($SimpleBlogCategory)) { $SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, false); if (Validate::isLoadedObject($SimpleBlogCategory)) { $SimpleBlogCategory = new SimpleBlogCategory($SimpleBlogCategory->id, $id_lang); header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . SimpleBlogCategory::getLink($SimpleBlogCategory->link_rewrite)); } else { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); Tools::redirect($this->context->link->getPageLink('404')); } } if ($SimpleBlogCategory->id_parent > 0) { $parent = new SimpleBlogCategory($SimpleBlogCategory->id_parent, $id_lang); $this->context->smarty->assign('parent_category', $parent); } // @todo: More flexible if ($SimpleBlogCategory->meta_title != '') { $meta_title = $SimpleBlogCategory->meta_title; } else { $meta_title = $SimpleBlogCategory->name . ' - ' . $this->module->l('Blog'); } if (!empty($SimpleBlogCategory->meta_description)) { $this->context->smarty->assign('meta_description', $SimpleBlogCategory->meta_description); } if (!empty($SimpleBlogCategory->meta_keywords)) { $this->context->smarty->assign('meta_keywords', $SimpleBlogCategory->meta_keywords); } if ($page > 1) { $meta_title .= ' (' . $page . ')'; } $this->context->smarty->assign('meta_title', $meta_title); $posts = SimpleBlogPost::getPosts($id_lang, $this->posts_per_page, $SimpleBlogCategory->id, $page); $this->assignPagination($this->posts_per_page, sizeof(SimpleBlogPost::getPosts($id_lang, null, $SimpleBlogCategory->id))); $this->context->smarty->assign('blogCategory', $SimpleBlogCategory); $this->context->smarty->assign('posts', $posts); $this->context->smarty->assign('category_rewrite', $SimpleBlogCategory->link_rewrite); //$this->setTemplate('list-category.tpl'); } elseif ($this->is_search) { // @todo: complete refactoring "authors" to 2.0.0 // Posts by author $this->context->smarty->assign('is_search', true); // echo SimpleBlogPost::getSearchLink('author', 'kpodemski', $id_lang); // @todo: meta titles, blog title, specific layout switch ($this->simpleblog_search) { case 'author': break; case 'tag': break; } $this->context->smarty->assign('meta_title', $this->l('Posts by', 'list') . ' ' . $this->simpleblog_author . ' - ' . $this->l('Blog', 'list')); $posts = SimpleBlogPost::findPosts($this->simpleblog_search, $this->simpleblog_keyword, $id_lang, $this->posts_per_page, $page); $this->assignPagination($this->posts_per_page, sizeof(SimpleBlogPost::findPosts($this->simpleblog_search, $this->simpleblog_keyword, $id_lang))); $this->context->smarty->assign('posts', $posts); } else { // Home things $posts = SimpleBlogPost::getPosts($id_lang, $this->posts_per_page, null, $page); $this->assignPagination($this->posts_per_page, sizeof(SimpleBlogPost::getPosts($id_lang, null))); // @todo: More flexible $meta_title = Configuration::get('PH_BLOG_MAIN_TITLE', Context::getContext()->language->id) ? Configuration::get('PH_BLOG_MAIN_TITLE', Context::getContext()->language->id) : Configuration::get('PS_SHOP_NAME') . ' - Blog'; $meta_description = Configuration::get('PH_BLOG_MAIN_META_DESCRIPTION', Context::getContext()->language->id) ? Configuration::get('PH_BLOG_MAIN_META_DESCRIPTION', Context::getContext()->language->id) : ''; if ($page > 1) { $meta_title .= ' (' . $page . ')'; } $this->context->smarty->assign('meta_title', $meta_title); $this->context->smarty->assign('meta_description', $meta_description); $this->context->smarty->assign('posts', $posts); } $this->setTemplate('list.tpl'); }
private function getParams(SimpleBlogPost $blogPost) { $params = array(':blog_id' => $blogPost->getId(), ':status' => $blogPost->getStatus(), ':date' => self::formatDateTime($blogPost->getDate()), ':content' => $blogPost->getContent(), ':description' => $blogPost->getDescription(), ':created_by' => $blogPost->getCreatedBy(), ':modified_by' => $blogPost->getModifiedBy(), ':restaurant_id' => $blogPost->getRestaurantId()); // if ($flightBooking->getId()) { // // unset created date, this one is never updated // unset($params[':created_on']); // } return $params; }
public function initContent() { $this->context->controller->addJqueryPlugin('cooki-plugin'); $this->context->controller->addJqueryPlugin('cookie-plugin'); $this->context->controller->addjqueryPlugin('fancybox'); $this->context->controller->addCSS(array(_THEME_CSS_DIR_ . 'category.css' => 'all', _THEME_CSS_DIR_ . 'product_list.css' => 'all')); parent::initContent(); $this->SimpleBlogPost->increaseViewsNb(); /** Support for SmartShortcode module from CodeCanyon **/ if (file_exists(_PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php')) { require_once _PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php'; } if (Module::isEnabled('smartshortcode')) { $smartshortcode = new SmartShortCode(); $this->SimpleBlogPost->content = $smartshortcode->parse($this->SimpleBlogPost->content); } $this->context->smarty->assign('post', $this->SimpleBlogPost); $this->context->smarty->assign('is_16', version_compare(_PS_VERSION_, '1.6.0', '>=') === true ? true : false); $this->context->smarty->assign('gallery_dir', _MODULE_DIR_ . 'ph_simpleblog/galleries/'); // Comments if ($this->SimpleBlogPost->allow_comments == 1) { $allow_comments = true; } elseif ($this->SimpleBlogPost->allow_comments == 2) { $allow_comments = false; } elseif ($this->SimpleBlogPost->allow_comments == 3) { $allow_comments = Configuration::get('PH_BLOG_COMMENT_ALLOW'); } else { $allow_comments = false; } $this->context->smarty->assign('allow_comments', $allow_comments); if ($allow_comments) { $comments = SimpleBlogComment::getComments($this->SimpleBlogPost->id_simpleblog_post); $this->context->smarty->assign('comments', $comments); } if (Configuration::get('PH_BLOG_DISPLAY_RELATED')) { $related_products = SimpleBlogPost::getRelatedProducts($this->SimpleBlogPost->id_product); $this->context->smarty->assign('related_products', $related_products); } $this->setTemplate('single.tpl'); }
public function initContent() { $sidebar = Configuration::get('PH_BLOG_LAYOUT'); if ($sidebar == 'left_sidebar') { $this->display_column_left = true; $this->display_column_right = false; } elseif ($sidebar == 'right_sidebar') { $this->display_column_left = false; $this->display_column_right = true; } elseif ($sidebar == 'full_width') { $this->display_column_left = false; $this->display_column_right = false; } else { $this->display_column_left = true; $this->display_column_right = true; } $id_lang = Context::getContext()->language->id; parent::initContent(); $this->context->smarty->assign('is_16', (bool) (version_compare(_PS_VERSION_, '1.6.0', '>=') === true)); $gridType = Configuration::get('PH_BLOG_COLUMNS'); $gridColumns = Configuration::get('PH_BLOG_GRID_COLUMNS'); $blogLayout = Configuration::get('PH_BLOG_LIST_LAYOUT'); $gridHtmlCols = ''; $mainTemplate = ''; // First attempts to support 1.6 if ($gridType == 'prestashop') { $gridHtmlCols = 'ph_col ph_col_' . $gridColumns; } elseif ($gridType == 'bootstrap') { $mainTemplate = '-bootstrap'; } if ($blogLayout == 'full') { $gridHtmlCols = 'ph_col'; } $this->context->smarty->assign(array('categories' => SimpleBlogCategory::getCategories($id_lang), 'latest_posts' => SimpleBlogPost::getPosts($id_lang, 5), 'blogMainTitle' => Configuration::get('PH_BLOG_MAIN_TITLE', $id_lang), 'columns' => $gridColumns, 'grid' => Configuration::get('PH_BLOG_COLUMNS'), 'gridHtmlCols' => $gridHtmlCols, 'module_dir' => _MODULE_DIR_ . 'ph_simpleblog/', 'blogLayout' => $blogLayout)); $page = Tools::getValue('p', 0); // How many posts? $this->posts_per_page = Configuration::get('PH_BLOG_POSTS_PER_PAGE'); // Is blog category, author or something else? $this->context->smarty->assign('is_category', false); $this->context->smarty->assign('is_search', false); // Category things if ($this->sb_category != '') { $this->context->smarty->assign('is_category', true); $SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, $id_lang); // Category not found so now we looking for categories in same rewrite but other languages and if we found then we redirect 301 if (!Validate::isLoadedObject($SimpleBlogCategory)) { $SimpleBlogCategory = SimpleBlogCategory::getByRewrite($this->sb_category, false); if (Validate::isLoadedObject($SimpleBlogCategory)) { $SimpleBlogCategory = new SimpleBlogCategory($SimpleBlogCategory->id, $id_lang); header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . SimpleBlogCategory::getLink($SimpleBlogCategory->link_rewrite)); } } // @todo: More flexible if ($SimpleBlogCategory->meta_title != '') { $meta_title = $SimpleBlogCategory->meta_title; } else { $meta_title = $SimpleBlogCategory->name . ' - Blog'; } if (!empty($SimpleBlogCategory->meta_description)) { $this->context->smarty->assign('meta_description', $SimpleBlogCategory->meta_description); } if (!empty($SimpleBlogCategory->meta_keywords)) { $this->context->smarty->assign('meta_keywords', $SimpleBlogCategory->meta_keywords); } if ($page > 1) { $meta_title .= ' (' . $page . ')'; } $this->context->smarty->assign('meta_title', $meta_title); $posts = SimpleBlogPost::getPosts($id_lang, $this->posts_per_page, $SimpleBlogCategory->id, $page); $this->assignPagination($this->posts_per_page, sizeof(SimpleBlogPost::getPosts($id_lang, null, $SimpleBlogCategory->id))); $this->context->smarty->assign('blogCategory', $SimpleBlogCategory); $this->context->smarty->assign('posts', $posts); $this->context->smarty->assign('category_rewrite', $SimpleBlogCategory->link_rewrite); //$this->setTemplate('list-category.tpl'); } elseif ($this->is_search) { $this->context->smarty->assign('is_search', true); // echo SimpleBlogPost::getSearchLink('author', 'kpodemski', $id_lang); // @todo: meta titles, blog title, specific layout switch ($this->simpleblog_search) { case 'author': break; case 'tag': break; } $this->context->smarty->assign('meta_title', $this->l('Posts by') . ' ' . $this->simpleblog_author . ' - Blog'); $posts = SimpleBlogPost::findPosts($this->simpleblog_search, $this->simpleblog_keyword, $id_lang, $this->posts_per_page, $page); $this->assignPagination($this->posts_per_page, sizeof(SimpleBlogPost::findPosts($this->simpleblog_search, $this->simpleblog_keyword, $id_lang))); $this->context->smarty->assign('posts', $posts); } else { $posts = SimpleBlogPost::getPosts($id_lang, $this->posts_per_page, null, $page); $this->assignPagination($this->posts_per_page, sizeof(SimpleBlogPost::getPosts($id_lang))); // @todo: More flexible $meta_title = Configuration::get('PS_SHOP_NAME') . ' - Blog'; if ($page > 1) { $meta_title .= ' (' . $page . ')'; } $this->context->smarty->assign('meta_title', $meta_title); $this->context->smarty->assign('posts', $posts); } $this->setTemplate('list' . $mainTemplate . '.tpl'); }
public function preparePosts($nb = 6, $from = null) { $featured = false; $order_by = 'sbp.date_add'; if ($from == 'featured') { $from = null; $featured = true; } elseif ($from == 'recent') { $from = null; } elseif ($from == 'viewed') { $from = null; $order_by = 'sbp.views'; } elseif ($from == 'liked') { $from = null; $order_by = 'sbp.likes'; } else { $from = (int) $from; } if (!Module::isInstalled('ph_simpleblog') || !Module::isEnabled('ph_simpleblog')) { return false; } require_once _PS_MODULE_DIR_ . 'ph_simpleblog/models/SimpleBlogPost.php'; $id_lang = $this->context->language->id; $posts = SimpleBlogPost::getPosts($id_lang, (int) $nb, $from, null, true, $order_by, 'DESC', null, (bool) $featured); return $posts; }
/** Front end */ public function _prepareRelatedPosts() { if (!isset($this->context->controller->php_self) || $this->context->controller->php_self != 'product') { return false; } $id_product = Tools::getValue('id_product', 0); $related_posts = array(); $relatedPosts = SimpleBlogRelatedPost::getByProductId((int) $id_product); if (sizeof($relatedPosts) < 1) { return false; } foreach ($relatedPosts as $key => $post) { $related_posts[] = $post['id_simpleblog_post']; } return SimpleBlogPost::getPosts($this->context->language->id, 999, null, null, true, false, false, null, false, false, null, 'IN', $related_posts); }
<?php include dirname(__FILE__) . '/../../config/config.inc.php'; include dirname(__FILE__) . '/../../init.php'; $status = 'success'; $message = ''; include_once dirname(__FILE__) . '/ph_simpleblog.php'; include_once dirname(__FILE__) . '/models/SimpleBlogPost.php'; $action = Tools::getValue('action'); switch ($action) { case 'addRating': $id_simpleblog_post = Tools::getValue('id_simpleblog_post'); $reply = SimpleBlogPost::changeRating('up', (int) $id_simpleblog_post); $message = $reply[0]["likes"]; break; case 'removeRating': $id_simpleblog_post = Tools::getValue('id_simpleblog_post'); $reply = SimpleBlogPost::changeRating('down', (int) $id_simpleblog_post); $message = $reply[0]["likes"]; break; default: $status = 'error'; $message = 'Unknown parameters!'; break; } $response = new stdClass(); $response->status = $status; $response->message = $message; $response->action = $action; echo json_encode($response);