private function is_blog_present($id) { $blogshop = BlogShop::model()->findByPk($id); if ($blogshop == null) { return $blogshop; } else { return null; } }
public function __construct() { $this->table = 'blog_category'; $this->className = 'BlogCategory'; $this->module = 'psblog'; $this->multishop_context = Shop::CONTEXT_ALL; $this->edit = true; $this->delete = true; $this->view = false; $this->addRowAction('edit'); $this->addRowAction('delete'); $this->_select = ' l.`iso_code` '; $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'lang l on l.id_lang = a.id_lang '; $this->fields_list = array('id_blog_category' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 30), 'active' => array('title' => $this->l('Active'), 'active' => 'status', 'align' => 'center', 'type' => 'bool', 'orderby' => false, 'width' => 60)); if (count(Language::getLanguages(true)) > 1) { $this->fields_list['iso_code'] = array('title' => $this->l('Language'), 'width' => 20); } $this->fields_list['position'] = array('title' => $this->l('Position'), 'width' => 60); $this->fields_list['name'] = array('title' => $this->l('Category name'), 'width' => 400); BlogShop::addBlogAssoTables(); parent::__construct(); }
public static function getPostCategories($post_id, $checkContext = true, $active = true) { if ($checkContext) { $context = Context::getContext(); $id_lang = $context->language->id; } $query = 'SELECT pc.`id_blog_category`, c.`name`, c.`link_rewrite`, c.`id_lang` FROM ' . _DB_PREFIX_ . 'blog_categories pc INNER JOIN ' . _DB_PREFIX_ . 'blog_category c ON c.`id_blog_category` = pc.`id_blog_category` '; if ($checkContext) { $query .= BlogShop::addShopAssociation('blog_category', 'c'); } $query .= ' WHERE pc.`id_blog_post` = ' . (int) $post_id; if ($checkContext) { $query .= ' AND (c.id_lang = ' . intval($id_lang) . ' OR c.id_lang = 0) '; } if ($active) { $query .= ' AND c.`active` = 1'; } $query .= ' GROUP BY c.`id_blog_category` ORDER BY c.`position` ASC, c.`name` ASC'; $result = Db::getInstance()->ExecuteS($query); return $result; }
private function _postProcess() { if (Tools::isSubmit('submitPsblog')) { $pref = $_POST['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'); 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))); if ($new_values['product_page_related'] != $old_values['product_page_related']) { if ($new_values['product_page_related'] == 1) { $this->registerHook('productTab'); $this->registerHook('productTabContent'); } else { $this->unregisterHook(Hook::getIdByName('productTab')); $this->unregisterHook(Hook::getIdByName('productTabContent')); } } $this->_html .= '<div class="conf confirm">' . $this->l('Settings updated') . '</div>'; } elseif (Tools::isSubmit('submitGenerateImg')) { include_once _PS_MODULE_DIR_ . "psblog/classes/BlogPost.php"; $images = BlogPost::getAllImages(); $save_path = _PS_ROOT_DIR_ . '/' . rtrim(self::$pref['img_save_path'], '/') . "/"; foreach ($images as $img) { @unlink($save_path . 'thumb/' . $img['img_name']); @unlink($save_path . 'list/' . $img['img_name']); BlogPost::generateImageThumbs($img['id_blog_image']); } $this->_html .= '<div class="conf confirm">' . $this->l('Images regenerated') . '</div>'; } elseif (Tools::isSubmit('submitGenerateSitemap')) { include_once _PS_MODULE_DIR_ . "psblog/classes/BlogShop.php"; BlogShop::generateSitemap(); $this->_html .= '<div class="conf confirm">' . $this->l('Google sitemap regenerated') . '</div>'; } }
public function listRelated($checkContext = true, $publish = true) { if ($checkContext) { $context = Context::getContext(); $id_lang = $context->language->id; } $query = 'SELECT p.`id_blog_post`, p.`title`, p.`link_rewrite`, p.`id_lang` FROM ' . _DB_PREFIX_ . 'blog_related pr INNER JOIN ' . _DB_PREFIX_ . 'blog_post p ON p.`id_blog_post` = pr.`id_related_blog_post`'; if ($checkContext) { $query .= BlogShop::addShopAssociation('blog_post', 'p'); } $query .= ' WHERE pr.`id_blog_post` = ' . intval($this->id); if ($checkContext) { $query .= ' AND (p.id_lang = ' . intval($id_lang) . ' OR p.id_lang = 0) '; } if ($publish) { $query .= ' AND p.`status` = "published" AND p.`date_on` <= NOW()'; } $query .= ' ORDER BY p.`date_on` DESC, p.`id_blog_post` DESC'; return Db::getInstance()->ExecuteS($query); }
public function processSave() { $object = parent::processSave(); if ($object) { if (empty($this->errors)) { $save_path = rtrim($this->conf['img_save_path'], '/') . "/"; $groupList = Tools::getValue('groupBox'); $object->cleanCategories(); if (is_array($groupList) and sizeof($groupList) > 0) { $object->addCategories($groupList); } $object->cleanProducts(); if (Tools::getValue('inputAccessories')) { $productArray = explode('-', Tools::getValue('inputAccessories'), -1); $object->addProducts($productArray); } $groupRelated = Tools::getValue('groupRelated'); $object->cleanRelated(); if (is_array($groupRelated) and sizeof($groupRelated) > 0) { $object->addRelated($groupRelated); } $images_position = Tools::getValue('img_pos'); if (is_array($images_position) && count($images_position)) { $object->setImagesPosition($images_position); } if (isset($_FILES['blog_img']) && !empty($_FILES['blog_img']['tmp_name'][0])) { $j = 0; foreach ($_FILES['blog_img']['name'] as $key => $val) { if (empty($val)) { continue; } $id_img = null; try { $file['name'] = $val; $file['type'] = $_FILES['blog_img']['type'][$key]; $file['error'] = $_FILES['blog_img']['error'][$key]; $file['size'] = $_FILES['blog_img']['size'][$key]; $file['tmp_name'] = $_FILES['blog_img']['tmp_name'][$key]; //img name $curr_time = time() + $j; $ext = substr(strrchr($file['name'], '.'), 1); $img_name = $curr_time . '.' . $ext; $dest = _PS_ROOT_DIR_ . '/' . $save_path; $this->checkFile($file, $dest); $id_img = $object->addImage($img_name, 0); $this->uploadFile($file, $dest . $img_name); $object->generateImageThumbs($id_img); } catch (Exception $e) { $this->_errors[] = Tools::displayError($e->getMessage()); if (!is_null($id_img)) { $object->removeImage($id_img); } } $j++; } } BlogShop::generateSitemap(); if (Tools::getValue('blog_img_default')) { $idImg = Tools::getValue('blog_img_default'); $object->setImageDefault($idImg); } elseif ($object->getImages(true) > 0) { $object->setImageDefault(0); } } } return $object; }