public function renderForm() { $this->initFormToolbar(); if (!$this->loadObject(true)) { return; } $obj = $this->loadObject(true); /** POST IMAGES **/ $cover = false; $featured = false; if (isset($obj->id)) { $this->display = 'edit'; $cover = ImageManager::thumbnail(_PS_MODULE_DIR_ . 'ph_simpleblog/covers/' . $obj->id . '.' . $obj->cover, 'ph_simpleblog_' . $obj->id . '.' . $obj->cover, 350, $obj->cover, false); $featured = ImageManager::thumbnail(_PS_MODULE_DIR_ . 'ph_simpleblog/featured/' . $obj->id . '.' . $obj->featured, 'ph_simpleblog_featured_' . $obj->id . '.' . $obj->featured, 350, $obj->featured, false); } else { $this->display = 'add'; } $this->fields_value = array('cover' => $cover ? $cover : false, 'cover_size' => $cover ? filesize(_PS_MODULE_DIR_ . 'ph_simpleblog/covers/' . $obj->id . '.' . $obj->cover) / 1000 : false, 'featured' => $featured ? $featured : false, 'featured_size' => $featured ? filesize(_PS_MODULE_DIR_ . 'ph_simpleblog/featured/' . $obj->id . '.' . $obj->featured) / 1000 : false); /** POST TAGS **/ $obj->tags = SimpleBlogTag::getPostTags($obj->id); /** GLOBAL $ **/ $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'); $this->tpl_form_vars['languages'] = $this->_languages; $this->tpl_form_vars['simpleblogpost'] = $obj; $this->tpl_form_vars['is_16'] = $this->is_16; /** POST ACCESS **/ if (isset($obj->id) && $obj->access) { $groupAccess = unserialize($obj->access); foreach ($groupAccess as $groupAccessID => $value) { $groupBox = 'groupBox_' . $groupAccessID; $this->fields_value[$groupBox] = $value; } } else { $groups = Group::getGroups($this->context->language->id); $preselected = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP')); foreach ($groups as $group) { $this->fields_value['groupBox_' . $group['id_group']] = in_array($group['id_group'], $preselected); } } /** Default publication date for new posts **/ if (!isset($obj->id)) { $this->fields_value['date_add'] = date('Y-m-d H:i:s'); } $available_categories = SimpleBlogCategory::getCategories($this->context->language->id, true, false); foreach ($available_categories as &$category) { if ($category['is_child']) { $category['name'] = ' ' . $category['name']; } } $i = 0; $this->fields_form[$i]['form'] = array('legend' => array('title' => $this->l('SimpleBlog Post'), 'icon' => 'icon-folder-close'), 'input' => array(array('type' => 'select', 'label' => $this->l('Post type:'), 'name' => 'id_simpleblog_post_type', 'required' => true, 'options' => array('id' => 'id_simpleblog_post_type', 'query' => SimpleBlogPostType::getAll(), 'name' => 'name')), array('type' => 'select', 'label' => $this->l('Category:'), 'name' => 'id_simpleblog_category', 'required' => true, 'options' => array('id' => 'id', 'query' => $available_categories, 'name' => 'name')), array('type' => 'text', 'label' => $this->l('Author:'), 'name' => 'author'), array('type' => 'text', 'label' => $this->l('Title:'), 'name' => 'title', 'required' => true, 'lang' => true, 'id' => 'name', 'class' => 'copyNiceUrl'), array('type' => 'textarea', 'label' => $this->l('Short content:'), 'name' => 'short_content', 'lang' => true, 'rows' => 5, 'cols' => 40, 'autoload_rte' => true), array('type' => 'textarea', 'label' => $this->l('Full post content:'), 'name' => 'content', 'lang' => true, 'rows' => 15, 'cols' => 40, 'autoload_rte' => true), array('type' => 'tags', 'label' => $this->l('Tags:'), 'desc' => $this->l('separate by comma for eg. ipod, apple, something'), 'name' => 'tags', 'required' => false, 'lang' => true), array('type' => 'switch', 'label' => $this->l('Featured?'), 'name' => 'is_featured', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'is_featured_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'is_featured_off', 'value' => 0, 'label' => $this->l('No')))), array('type' => 'switch', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'radio', 'label' => $this->l('Allow comments?'), 'name' => 'allow_comments', 'required' => false, 'class' => 't', 'values' => array(array('id' => 'allow_comments_1', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'allow_comments_2', 'value' => 2, 'label' => $this->l('No')), array('id' => 'allow_comments_3', 'value' => 3, 'label' => $this->l('Use global setting'))))), 'submit' => array('title' => $this->l('Save and stay'), 'class' => 'button', 'stay' => true)); $i++; if (isset($obj->id)) { $this->addjQueryPlugin(array('thickbox', 'ajaxfileupload')); // Get images $images = SimpleBlogPostImage::getAllById($obj->id); foreach ($images as $k => $image) { $images[$k] = new SimpleBlogPostImage($image['id_simpleblog_post_image']); } $image_uploader = new HelperImageUploader('file'); $image_uploader->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminSimpleBlogPosts') . '&ajax=1&id_simpleblog_post=' . (int) $obj->id . '&action=addPostImages'); $this->tpl_form_vars['images'] = $images; $this->tpl_form_vars['image_uploader'] = $image_uploader->render(); $this->fields_form[$i]['form'] = array('legend' => array('title' => $this->l('Post type options'), 'icon' => 'icon-folder-close'), 'input' => array(array('type' => 'text', 'label' => $this->l('External URL:'), 'name' => 'external_url', 'form_group_class' => 'simpleblog-post-type simpleblog-post-type-' . SimpleBlogPostType::getIdBySlug('url'), 'lang' => true), array('type' => 'textarea', 'label' => $this->l('Video embed code:'), 'name' => 'video_code', 'lang' => true, 'form_group_class' => 'simpleblog-post-type simpleblog-post-type-' . SimpleBlogPostType::getIdBySlug('video'), 'desc' => $this->l('Remember to "Allow iframes on HTML fields" in Preferences -> General')), array('type' => 'file', 'multiple' => true, 'ajax' => true, 'name' => 'post_images', 'label' => $this->l('Add images to gallery'), 'required' => false, 'lang' => false, 'form_group_class' => 'simpleblog-post-type simpleblog-post-type-' . SimpleBlogPostType::getIdBySlug('gallery'))), 'submit' => array('title' => $this->l('Save and stay'), 'class' => 'button', 'stay' => true)); $i++; } else { $this->fields_form[$i]['form'] = array('legend' => array('title' => $this->l('Post type options'), 'icon' => 'icon-folder-close'), 'description' => $this->l('Specific post type options will be available after saving post')); $i++; } $this->fields_form[$i]['form'] = array('legend' => array('title' => $this->l('Post Images'), 'image' => $this->is_16 ? null : '../img/t/AdminImages.gif', 'icon' => 'icon-picture'), 'input' => array(array('type' => 'file', 'label' => $this->l('Post cover:'), 'display_image' => true, 'name' => 'cover', 'desc' => $this->l('Upload a image from your computer.')), array('type' => 'file', 'label' => $this->l('Post featured image:'), 'display_image' => true, 'name' => 'featured', 'desc' => $this->l('Upload a image from your computer. Featured image will be displayed only if you want on the single post page.'))), 'submit' => array('title' => $this->l('Save and stay'), 'class' => 'button', 'stay' => true)); $i++; $available_products = self::getSimpleProducts($this->context->language->id); foreach ($available_products as &$available_related_product) { if (empty($available_related_product['product_name'])) { if (isset($available_related_product['name']) && !empty($available_related_product['name'])) { $available_related_product['product_name'] = $available_related_product['name']; } } } $this->fields_form[$i]['form'] = array('legend' => array('title' => $this->l('Related products')), 'input' => array(array('type' => 'select', 'label' => $this->l('Product:'), 'name' => 'id_product[]', 'id' => 'select_product', 'multiple' => true, 'required' => false, 'options' => array('id' => 'id_product', 'query' => $available_products, 'name' => 'product_name'))), 'submit' => array('title' => $this->l('Save and stay'), 'class' => 'button', 'stay' => true)); $i++; $this->fields_value['id_product[]'] = explode(',', $obj->id_product); $this->fields_form[$i]['form'] = array('legend' => array('title' => $this->l('SEO'), 'icon' => 'icon-folder-close'), 'input' => array(array('type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'lang' => true), array('type' => 'text', 'label' => $this->l('Meta description:'), 'name' => 'meta_description', 'lang' => true), array('type' => 'text', 'label' => $this->l('Meta keywords:'), 'name' => 'meta_keywords', 'lang' => true), array('type' => 'text', 'label' => $this->l('Friendly URL:'), 'name' => 'link_rewrite', 'required' => true, 'lang' => true)), 'submit' => array('title' => $this->l('Save and stay'), 'class' => 'button', 'stay' => true)); $i++; $unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP')); $guest = new Group(Configuration::get('PS_GUEST_GROUP')); $default = new Group(Configuration::get('PS_CUSTOMER_GROUP')); $unidentified_group_information = sprintf($this->l('%s - All people without a valid customer account.'), '<b>' . $unidentified->name[$this->context->language->id] . '</b>'); $guest_group_information = sprintf($this->l('%s - Customer who placed an order with the guest checkout.'), '<b>' . $guest->name[$this->context->language->id] . '</b>'); $default_group_information = sprintf($this->l('%s - All people who have created an account on this site.'), '<b>' . $default->name[$this->context->language->id] . '</b>'); $this->fields_form[$i]['form'] = array('legend' => array('title' => $this->l('Availability')), 'input' => array(array('type' => 'datetime', 'label' => $this->l('Publication date:'), 'name' => 'date_add', 'desc' => $this->l('Remember to set correctly your timezone in Simple Blog -> Settings. Current timezone:') . ' ' . Configuration::get('PH_BLOG_TIMEZONE') . ', ' . $this->l('current time with this setting:') . ' ' . SimpleBlogHelper::now(Configuration::get('PH_BLOG_TIMEZONE')), 'required' => true), array('type' => 'group', 'label' => $this->l('Group access'), 'name' => 'groupBox', 'values' => Group::getGroups(Context::getContext()->language->id), 'info_introduction' => $this->l('You now have three default customer groups.'), 'unidentified' => $unidentified_group_information, 'guest' => $guest_group_information, 'customer' => $default_group_information, 'hint' => $this->l('Mark all of the customer groups which you would like to have access to this category.'))), 'submit' => array('title' => $this->l('Save and stay'), 'class' => 'button', 'stay' => true)); $i++; if (Shop::isFeatureActive()) { $this->fields_form[$i]['form'] = array('legend' => array('title' => $this->l('Shop association:')), 'input' => array(array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso'))); } $this->multiple_fieldsets = true; return parent::renderForm(); }
public static function getPosts($id_lang, $limit = 10, $id_simpleblog_category = null, $page = null, $active = true, $orderby = false, $orderway = false, $exclude = null, $featured = false, $author = false, $id_shop = null, $filter = false, $selected = array(), $check_access = true) { $context = Context::getContext(); $start = $limit * ($page == 0 ? 0 : $page - 1); $sql = new DbQuery(); $sql->select('*'); $sql->from('simpleblog_post', 'sbp'); if ($id_lang) { $sql->innerJoin('simpleblog_post_lang', 'l', 'sbp.id_simpleblog_post = l.id_simpleblog_post AND l.id_lang = ' . (int) $id_lang); } if (!$id_shop) { $id_shop = $context->shop->id; } $sql->innerJoin('simpleblog_post_shop', 'sbps', 'sbp.id_simpleblog_post = sbps.id_simpleblog_post AND sbps.id_shop = ' . (int) $id_shop); if ($active) { $sql->where('sbp.active = 1'); } if (isset($id_simpleblog_category) && (int) $id_simpleblog_category > 0) { $childrens = SimpleBlogCategory::getChildrens((int) $id_simpleblog_category); if ($childrens && sizeof($childrens)) { $child_categories = array((int) $id_simpleblog_category); foreach ($childrens as $child) { $child_categories[] = $child['id_simpleblog_category']; } $sql->where('sbp.id_simpleblog_category IN (' . join(',', $child_categories) . ')'); } else { $sql->where('sbp.id_simpleblog_category = ' . (int) $id_simpleblog_category); } } if ($exclude) { $sql->where('sbp.id_simpleblog_post != ' . (int) $exclude); } if ($featured) { $sql->where('sbp.is_featured = 1'); } if ($author && Configuration::get('PH_BLOG_POST_BY_AUTHOR')) { $sql->where('sbp.author = \'' . pSQL($author) . '\''); } if ($filter) { $sql->where('sbp.id_simpleblog_post ' . $filter . ' (' . join(',', $selected) . ')'); } $sql->where('sbp.date_add <= \'' . SimpleBlogHelper::now(Configuration::get('PH_BLOG_TIMEZONE')) . '\''); if (!$orderby) { $orderby = 'sbp.date_add'; } if (!$orderway) { $orderway = 'DESC'; } $sql->orderBy($orderby . ' ' . $orderway); $sql->limit($limit, $start); $result = Db::getInstance()->executeS($sql); if (sizeof($result) && $check_access == true) { $result = self::checkAccess($result); } if (sizeof($result)) { foreach ($result as &$row) { $category_rewrite = SimpleBlogCategory::getRewriteByCategory($row['id_simpleblog_category'], $id_lang); $category_obj = new SimpleBlogCategory($row['id_simpleblog_category'], $id_lang); $category_url = SimpleBlogCategory::getLink($category_obj->link_rewrite, $id_lang); if (file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/covers/' . $row['id_simpleblog_post'] . '.' . $row['cover'])) { $row['banner'] = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $row['id_simpleblog_post'] . '.' . $row['cover']; $row['banner_thumb'] = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $row['id_simpleblog_post'] . '-thumb.' . $row['cover']; $row['banner_wide'] = _MODULE_DIR_ . 'ph_simpleblog/covers/' . $row['id_simpleblog_post'] . '-wide.' . $row['cover']; } if (file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/featured/' . $row['id_simpleblog_post'] . '.' . $row['featured'])) { $row['featured'] = _MODULE_DIR_ . 'ph_simpleblog/featured/' . $row['id_simpleblog_post'] . '.' . $row['featured']; } $row['url'] = self::getLink($row['link_rewrite'], $category_obj->link_rewrite, $id_lang); $row['category'] = $category_obj->name; $row['category_rewrite'] = $category_obj->link_rewrite; $row['category_url'] = $category_url; $tags = SimpleBlogTag::getPostTags($row['id_simpleblog_post']); $row['tags'] = isset($tags[$id_lang]) && sizeof($tags[$id_lang] > 0) ? $tags[$id_lang] : false; $row['post_type'] = SimpleBlogPostType::getSlugById($row['id_simpleblog_post_type']); if ($row['post_type'] == 'gallery') { $row['gallery'] = SimpleBlogPostImage::getAllById($row['id_simpleblog_post']); } } } else { return; } return $result; }