public function renderForm()
 {
     $this->initFormToolbar();
     if (!$this->loadObject(true)) {
         return;
     }
     $obj = $this->loadObject(true);
     $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';
     }
     $obj->tags = SimpleBlogTag::getPostTags($obj->id);
     $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;
     $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);
     $this->fields_form[0]['form'] = array('legend' => array('title' => $this->l('SimpleBlog Post'), 'image' => '../img/admin/tab-categories.gif'), 'input' => array(array('type' => 'text', 'label' => $this->l('Title:'), 'name' => 'meta_title', 'required' => true, 'lang' => true, 'id' => 'name', 'class' => 'copyNiceUrl'), array('type' => 'textarea', 'label' => $this->l('Description:'), 'name' => 'short_content', 'lang' => true, 'rows' => 5, 'cols' => 40, 'autoload_rte' => true), array('type' => 'textarea', 'label' => $this->l('Content:'), 'name' => 'content', 'lang' => true, 'rows' => 15, 'cols' => 40, 'autoload_rte' => true), array('type' => 'select', 'label' => $this->l('Category:'), 'name' => 'id_simpleblog_category', 'required' => true, 'options' => array('id' => 'id', 'query' => SimpleBlogCategory::getCategories($this->context->language->id), 'name' => 'name')), array('type' => 'text', 'label' => $this->l('Tags:'), 'desc' => $this->l('separate by comma for eg. ipod, apple, something'), 'name' => 'tags', 'display_tags' => true, 'required' => false, 'lang' => true), array('type' => 'text', 'label' => $this->l('Author:'), 'name' => 'author'), array('type' => 'radio', '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' => 'radio', '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('For logged customers only?'), 'name' => 'logged', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'logged_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'logged_off', 'value' => 0, 'label' => $this->l('No'))))), 'submit' => array('title' => $this->l('Save and stay'), 'class' => 'button', 'stay' => true));
     $this->fields_form[1]['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));
     $this->fields_form[2]['form'] = array('legend' => array('title' => $this->l('SimpleBlog SEO'), 'image' => '../img/admin/tab-categories.gif'), 'input' => array(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));
     if (Shop::isFeatureActive()) {
         $this->fields_form[3]['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 function __construct($id_simpleblog_category = null, $id_lang = null, $id_shop = null)
 {
     parent::__construct($id_simpleblog_category, $id_lang, $id_shop);
     if (file_exists(_PS_MODULE_DIR_ . 'ph_simpleblog/covers_cat/' . $this->id_simpleblog_category . '.' . $this->cover)) {
         $this->image = _MODULE_DIR_ . 'ph_simpleblog/covers_cat/' . $this->id_simpleblog_category . '.' . $this->cover;
     }
     if ($this->id) {
         $tags = SimpleBlogTag::getPostTags((int) $this->id);
         $this->tags = $tags;
         if (isset($tags) && isset($tags[$id_lang])) {
             $this->tags_list = $tags[$id_lang];
         }
     }
 }
Exemple #3
0
 public function getTags($id_lang)
 {
     if (is_null($this->tags)) {
         $this->tags = SimpleBlogTag::getPostTags($this->id);
     }
     if (!($this->tags && key_exists($id_lang, $this->tags))) {
         return '';
     }
     $result = '';
     foreach ($this->tags[$id_lang] as $tag_name) {
         $result .= $tag_name . ', ';
     }
     return rtrim($result, ', ');
 }
 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();
 }