Наследование: extends ObjectModel
Пример #1
0
 public function initContent()
 {
     parent::initContent();
     Hook::exec('actionsbsingle', array('id_post' => Tools::getValue('id_post')));
     $blogcomment = new Blogcomment();
     $SmartBlogPost = new SmartBlogPost();
     $BlogCategory = new BlogCategory();
     $id_post = Tools::getValue('id_post');
     $id_lang = $this->context->language->id;
     $id_lang_defaut = Configuration::get('PS_LANG_DEFAULT');
     $post = $SmartBlogPost->getPost($id_post, $id_lang);
     $tags = $SmartBlogPost->getProductTags($id_post);
     $comment = $blogcomment->getComment($id_post);
     $countcomment = $blogcomment->getToltalComment($id_post);
     $id_cate = $post['id_category'];
     $title_category = $BlogCategory->getNameCategory($id_cate);
     // die(print_r($post));
     // die(_PS_MODULE_DIR_.'smartblog/images/'. $post['id_author'] . '/' . $post['id_post'] . '.jpg');
     if (file_exists(_PS_MODULE_DIR_ . 'smartblog/images/' . $post['id_author'] . '/' . $post['id_post'] . '.jpg')) {
         $post_img = $post['id_post'];
     } else {
         $post_img = 'no';
     }
     SmartBlogPost::postViewed($id_post);
     $this->context->smarty->assign(array('post' => $post, 'comments' => $comment, 'tags' => $tags, 'title_category' => $title_category[0]['meta_title'], 'cat_link_rewrite' => $title_category[0]['link_rewrite'], 'meta_title' => $post['meta_title'], 'post_active' => $post['active'], 'content' => htmlspecialchars_decode($post['content']), 'id_post' => $post['id_post'], 'smartshowauthorstyle' => Configuration::get('smartshowauthorstyle'), 'smartshowauthor' => Configuration::get('smartshowauthor'), 'created' => $post['created'], 'firstname' => $post['firstname'], 'lastname' => $post['lastname'], 'smartcustomcss' => Configuration::get('smartcustomcss'), 'smartshownoimg' => Configuration::get('smartshownoimg'), 'comment_status' => $post['comment_status'], 'countcomment' => $countcomment, 'post_img' => $post_img, '_report' => $this->_report, 'id_category' => $post['id_category'], 'id_author' => $post['id_author'], 'youtube' => $this->convertYoutube($post['youtube'])));
     $this->context->smarty->assign('HOOK_SMART_BLOG_POST_FOOTER', Hook::exec('displaySmartAfterPost'));
     $this->setTemplate('posts.tpl');
 }
Пример #2
0
    function prefetchBlogCat()
    {
        $cal = new BlogCategory();
        $arr = $cal->getWhere("cat_active=1");
        $cc = array();
        foreach ($arr as $c) {
            $cc[] = $c->cat_id;
        }
        echo json_encode($cc);
        die;
        ?>
[ "Amsterdam",
"London",
"Paris",
"Washington",
"New York",
"Los Angeles",
"Sydney",
"Melbourne",
"Canberra",
"Beijing",
"New Delhi",
"Kathmandu",
"Cairo",
"Cape Town",
"Kinshasa"
]<?php 
        die;
    }
Пример #3
0
 /**
  * ブログコンテンツ名を取得する
  *
  * @var int $blogContentId
  * @access public
  */
 public function getBlogContentTitle($blogContentId)
 {
     $blogCategoryModel = new BlogCategory();
     $category = $blogCategoryModel->findById($blogContentId);
     if (!empty($category)) {
         return $category['BlogCategory']['title'];
     } else {
         return '';
     }
 }
 public function initContent()
 {
     parent::initContent();
     if ($id_category = Tools::getvalue('id_category') && Tools::getvalue('id_category') != Null) {
         $this->context->smarty->assign(BlogCategory::GetMetaByCategory(Tools::getvalue('id_category')));
     }
     if ($id_post = Tools::getvalue('id_post') && Tools::getvalue('id_post') != Null) {
         $this->context->smarty->assign(SmartBlogPost::GetPostMetaByPost(Tools::getvalue('id_post')));
     }
     if (Tools::getvalue('id_category') == Null && Tools::getvalue('id_post') == Null) {
         $meta['meta_title'] = Configuration::get('smartblogmetatitle');
         $meta['meta_description'] = Configuration::get('smartblogmetadescrip');
         $meta['meta_keywords'] = Configuration::get('smartblogmetakeyword');
         $this->context->smarty->assign($meta);
     }
     if (Configuration::get('smartshowcolumn') == 0) {
         $this->context->smarty->assign(array('HOOK_LEFT_COLUMN' => Hook::exec('displaySmartBlogLeft'), 'HOOK_RIGHT_COLUMN' => Hook::exec('displaySmartBlogRight')));
     } elseif (Configuration::get('smartshowcolumn') == 1) {
         $this->context->smarty->assign(array('HOOK_LEFT_COLUMN' => Hook::exec('displaySmartBlogLeft')));
     } elseif (Configuration::get('smartshowcolumn') == 2) {
         $this->context->smarty->assign(array('HOOK_RIGHT_COLUMN' => Hook::exec('displaySmartBlogRight')));
     } elseif (Configuration::get('smartshowcolumn') == 3) {
         $this->context->smarty->assign(array());
     } else {
         $this->context->smarty->assign(array('HOOK_LEFT_COLUMN' => Hook::exec('displaySmartBlogLeft'), 'HOOK_RIGHT_COLUMN' => Hook::exec('displaySmartBlogRight')));
     }
 }
 public static function ImageDelete()
 {
     $get_blog_image = SmartBlogPost::getBlogImage();
     $get_author_image = __PS_BASE_URI__ . 'modules/smartblog/images/avatar/avatar.jpg';
     $get_cate_image = BlogCategory::getCatImage();
     $category_types = BlogImageType::GetImageAllType('category');
     $posts_types = BlogImageType::GetImageAllType('post');
     $author_types = BlogImageType::GetImageAllType('author');
     foreach ($category_types as $image_type) {
         foreach ($get_cate_image as $cat_img) {
             $dir = _PS_MODULE_DIR_ . 'smartblog/images/category/' . $cat_img['id_smart_blog_category'] . '-' . stripslashes($image_type['type_name']) . '.jpg';
             if (file_exists($dir)) {
                 unlink($dir);
             }
         }
     }
     foreach ($posts_types as $image_type) {
         foreach ($get_blog_image as $blog_img) {
             $dir = _PS_MODULE_DIR_ . 'smartblog/images/' . $blog_img['id_smart_blog_post'] . '-' . stripslashes($image_type['type_name']) . '.jpg';
             if (file_exists($dir)) {
                 unlink($dir);
             }
         }
     }
     foreach ($author_types as $image_type) {
         $dir = _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . stripslashes($image_type['type_name']) . '.jpg';
         if (file_exists($dir)) {
             unlink($dir);
         }
     }
 }
 public function LookForExistingURLSegment($URLSegment)
 {
     $existing = BlogCategory::get()->filter(array("URLSegment" => $URLSegment, 'ParentID' => $this->ParentID));
     if ($this->ID) {
         $existing = $existing->exclude("ID", $this->ID);
     }
     return $existing->count();
 }
 /**
  * returns a DataObjectSet of all the BlogCategories
  * @return {DataObjectSet}
  */
 public function getAllBlogCategories()
 {
     if (Config::inst()->get('BlogCategory', 'limit_to_holder') && $this->owner->Parent()->ClassName == 'BlogHolder') {
         return $this->owner->Parent()->BlogCategories();
     } else {
         return BlogCategory::get();
     }
 }
 /**
  * updates the fields used in the CMS
  * @see DataExtension::updateCMSFields()
  * @TODO remove the add/edit buttons from the authors gridfield
  */
 public function updateCMSFields(FieldList $fields)
 {
     // Categories tab: Show either on BlogTree or BlogHoder depending on limit settings
     $limit = Config::inst()->get('BlogCategory', 'limit_to_holder');
     if ($limit && $this->owner instanceof BlogHolder || !$limit && !$this->owner instanceof BlogHolder) {
         $categories = $limit ? $this->owner->BlogCategories() : BlogCategory::get();
         $fields->addFieldToTab('Root.Categories', GridField::create('BlogCategories', 'Blog Categories', $categories, GridFieldConfig_RecordEditor::create()));
     }
 }
 public function index($arguments)
 {
     $slug = $arguments->param('Slug');
     $blogcategory = BlogCategory::get()->filter(array('Slug' => $slug))->First();
     $this->Title = $blogcategory->Name;
     $this->BlogCategoryID = $blogcategory->ID;
     $this->Entries = $blogcategory->BlogEntries()->sort('Date DESC');
     return $this->renderWith(array('BlogEntries', 'Page'));
 }
 /**
  * Get the blog categories
  * @return ArrayList
  */
 public function getCategories()
 {
     $categories = new ArrayList();
     foreach (BlogCategory::get() as $category) {
         $data = array('Title' => $category->Title, 'Link' => $category->Parent()->Link('category/' . $category->URLSegment), 'ShowCount' => $this->ShowCount, 'Count' => $this->totalEntries($category->ID));
         $categories->push(new ArrayData($data));
     }
     return $categories;
 }
Пример #11
0
    public static function generateSitemap()
    {
        require_once _PS_MODULE_DIR_ . 'psblog/classes/BlogCategory.php';
        require_once _PS_MODULE_DIR_ . 'psblog/classes/BlogPost.php';
        $filename = _PS_MODULE_DIR_ . 'psblog/sitemap-blog.xml';
        if (!is_writable($filename)) {
            return FALSE;
        }
        $sql = 'SELECT s.id_shop, su.domain, su.domain_ssl, CONCAT(su.physical_uri, su.virtual_uri) as uri
				FROM ' . _DB_PREFIX_ . 'shop s
				INNER JOIN ' . _DB_PREFIX_ . 'shop_url su ON s.id_shop = su.id_shop AND su.main = 1
				WHERE s.active = 1 AND s.deleted = 0 AND su.active = 1';
        if (!($result = Db::getInstance()->executeS($sql))) {
            return false;
        }
        $xml = simplexml_load_file($filename);
        unset($xml->url);
        $sxe = new SimpleXMLElement($xml->asXML());
        foreach ($result as $row) {
            $shopContext = Context::getContext()->cloneContext();
            $shopContext->shop = new Shop($row['id_shop']);
            $languages = Language::getLanguages(true, $row['id_shop']);
            foreach ($languages as $l) {
                $shopContext->language->id_lang = $l['id_lang'];
                $shopContext->language->iso_code = $l['iso_code'];
                $url = $sxe->addChild('url');
                $listlink = BlogPost::linkList(null, $shopContext);
                $listlink = str_replace('&', '&amp;', $listlink);
                $url->addChild('loc', $listlink);
                $url->addChild('priority', '0.7');
                $url->addChild('changefreq', 'weekly');
            }
            unset($shopContext->language);
            $shopPosts = BlogPost::listPosts($shopContext, true);
            foreach ($shopPosts as $post) {
                $postlink = BlogPost::linkPost($post['id_blog_post'], $post['link_rewrite'], $post['id_lang'], $shopContext);
                $postlink = str_replace('&', '&amp;', $postlink);
                $url = $sxe->addChild('url');
                $url->addChild('loc', $postlink);
                $url->addChild('priority', '0.6');
                $url->addChild('changefreq', 'monthly');
            }
            $shopCategories = BlogCategory::listCategories($shopContext, true);
            foreach ($shopCategories as $cat) {
                $catlink = BlogCategory::linkCategory($cat['id_blog_category'], $cat['link_rewrite'], $cat['id_lang'], null, $shopContext);
                $catlink = str_replace('&', '&amp;', $catlink);
                $url = $sxe->addChild('url');
                $url->addChild('loc', $catlink);
                $url->addChild('priority', '0.6');
                $url->addChild('changefreq', 'monthly');
            }
            $sxe->asXML($filename);
        }
    }
Пример #12
0
 public function hookLeftColumn($params)
 {
     if (Module::isInstalled('smartblog') != 1) {
         $this->smarty->assign(array('smartmodname' => $this->name));
         return $this->display(__FILE__, 'views/templates/front/install_required.tpl');
     } else {
         if (!$this->isCached('smartblogcategories.tpl', $this->getCacheId())) {
             $view_data = array();
             $id_lang = $this->context->language->id;
             $BlogCategory = new BlogCategory();
             $categories = $BlogCategory->getCategory(1, $id_lang);
             $i = 0;
             foreach ($categories as $category) {
                 $categories[$i]['count'] = $BlogCategory->getPostByCategory($category['id_smart_blog_category']);
                 $i++;
             }
             $this->smarty->assign(array('categories' => $categories));
         }
         return $this->display(__FILE__, 'views/templates/front/smartblogcategories.tpl', $this->getCacheId());
     }
 }
Пример #13
0
 public static function getToltalByCategory($id_lang, $id_category, $limit_start, $limit, $where = '')
 {
     $result = array();
     $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post_lang pl, ' . _DB_PREFIX_ . 'smart_blog_post p 
             WHERE pl.id_lang=' . $id_lang . ' and p.active = 1 AND pl.id_smart_blog_post=p.id_smart_blog_post AND p.id_category = ' . $id_category;
     if ($where) {
         $sql .= ' AND ' . $where;
     }
     $sql .= ' ORDER BY p.id_smart_blog_post DESC LIMIT ' . $limit_start . ',' . $limit;
     if (!($posts = Db::getInstance()->executeS($sql))) {
         return false;
     }
     $i = 0;
     $BlogCategory = new BlogCategory();
     foreach ($posts as $post) {
         $result[$i]['id_post'] = $post['id_smart_blog_post'];
         $result[$i]['viewed'] = $post['viewed'];
         $result[$i]['meta_title'] = $post['meta_title'];
         $result[$i]['meta_description'] = $post['meta_description'];
         $result[$i]['short_description'] = $post['short_description'];
         $result[$i]['content'] = $post['content'];
         $result[$i]['meta_keyword'] = $post['meta_keyword'];
         $result[$i]['id_category'] = $post['id_category'];
         $result[$i]['link_rewrite'] = $post['link_rewrite'];
         $result[$i]['cat_link_rewrite'] = $BlogCategory->getCatLinkRewrite($post['id_category']);
         $employee = new Employee($post['id_author']);
         $result[$i]['lastname'] = $employee->lastname;
         $result[$i]['firstname'] = $employee->firstname;
         if (file_exists(_PS_MODULE_DIR_ . 'smartblog/images/' . $post['id_smart_blog_post'] . '.jpg')) {
             $image = $post['id_smart_blog_post'];
             $result[$i]['post_img'] = $image;
         } else {
             $result[$i]['post_img'] = 'no';
         }
         $result[$i]['created'] = $post['created'];
         $i++;
     }
     return $result;
 }
 public function search(array $data, BlogSearchForm $form, SS_HTTPRequest $request)
 {
     $link = $this->getBlog()->Link();
     //if we have keyword and category
     if (isset($data['Category']) && isset($data['Keyword']) && $data['Category'] && $data['Keyword']) {
         $link = $this->getBlog()->Link("?keyword={$data['Keyword']}&category={$data['Category']}");
     } elseif (isset($data['Category']) && $data['Category']) {
         $link = BlogCategory::get_by_id('BlogCategory', $data['Category'])->getLink();
     } elseif (isset($data['Keyword']) && $data['Keyword']) {
         $link = $this->getBlog()->Link("?keyword={$data['Keyword']}");
     }
     return Controller::curr()->redirect($link);
 }
 public function hookdisplaySmartAfterPost($params)
 {
     if (Module::isInstalled('smartblog') != 1) {
         $this->smarty->assign(array('smartmodname' => $this->name));
         return $this->display(__FILE__, 'views/templates/front/install_required.tpl');
     } else {
         if (!$this->isCached('smartblogrelatedposts.tpl', $this->getCacheId())) {
             $id_cat = BlogCategory::getCategoryNameByPost(Tools::getvalue('id_post'));
             $id_lang = $this->context->language->id;
             $posts = SmartBlogPost::getRelatedPosts($id_lang, $id_cat, Tools::getvalue('id_post'));
             $this->smarty->assign(array('posts' => $posts));
         }
         return $this->display(__FILE__, 'views/templates/front/smartblogrelatedposts.tpl', $this->getCacheId());
     }
 }
Пример #16
0
 public function getFeaturedBlogPost()
 {
     $category = $this->getCategory();
     $tag = $this->getTag();
     $archive = $this->getArchive();
     if ($category) {
         $category = BlogCategory::get()->filter("URLSegment", $category)->first();
         return $category->BlogPosts()->filter("FeaturedPost", true)->first();
     }
     if ($tag) {
         $tag = BlogTag::get()->filter("URLSegment", $tag)->first();
         return $tag->BlogPosts()->filter("FeaturedPost", true)->first();
     }
     if ($archive) {
         return $this->owner->getArchivedBlogPosts($archive["Year"], $archive["Month"], $archive["Day"])->filter("FeaturedPost", true)->first();
     }
     return BlogPost::get()->filter("FeaturedPost", true)->first();
 }
Пример #17
0
 /**
  * カテゴリのURLを取得する
  * [注意] リンク関数でラップする前提の為、ベースURLは考慮されない
  * 
  * @param string $blogCategoyId
  * @return void
  */
 function getCategoryUrl($blogCategoryId)
 {
     if (!isset($this->BlogCategory)) {
         $this->BlogCategory =& ClassRegistry::init('BlogCategory', 'Model');
     }
     $categoryPath = $this->BlogCategory->getPath($blogCategoryId);
     $blogContentId = $categoryPath[0]['BlogCategory']['blog_content_id'];
     $this->_setBlogContent($blogContentId);
     $blogContentName = $this->blogContent['name'];
     $path = array('category');
     if ($categoryPath) {
         foreach ($categoryPath as $category) {
             $path[] = $category['BlogCategory']['name'];
         }
     }
     $url = Router::url(am(array('admin' => false, 'plugin' => '', 'controller' => $blogContentName, 'action' => 'archives'), $path));
     $baseUrl = preg_replace('/\\/$/', '', baseUrl());
     return preg_replace('/^' . preg_quote($baseUrl, '/') . '/', '', $url);
 }
Пример #18
0
 public function hookLeftColumn($params)
 {
     if (!$this->checkServerConf()) {
         return false;
     }
     require_once _PS_MODULE_DIR_ . "psblog/psblog.php";
     require_once _PS_MODULE_DIR_ . "psblog/classes/BlogCategory.php";
     $pref = array_merge(Psblog::getPreferences(), self::getPreferences());
     $list = BlogCategory::listCategories(true, true);
     if ($list) {
         $i = 0;
         foreach ($list as $val) {
             $list[$i]['link'] = BlogCategory::linkCategory($val['id_blog_category'], $val['link_rewrite'], $val['id_lang']);
             $i++;
         }
     }
     $this->smarty->assign(array('post_categories' => $list, 'post_conf' => $pref));
     return $this->display(__FILE__, 'blockcategories.tpl');
 }
Пример #19
0
 /**
  * カテゴリ一覧へのURLを取得する
  *
  * [注意] リンク関数でラップする前提の為、ベースURLは考慮されない
  *
  * @param string $blogCategoyId ブログカテゴリID
  * @param array $options オプション(初期値 : array())
  *	`named` : URLの名前付きパラメーター
  * @return string カテゴリ一覧へのURL
  */
 public function getCategoryUrl($blogCategoryId, $options = array())
 {
     $options = array_merge(array('named' => array()), $options);
     extract($options);
     if (!isset($this->BlogCategory)) {
         $this->BlogCategory = ClassRegistry::init('Blog.BlogCategory');
     }
     $categoryPath = $this->BlogCategory->getPath($blogCategoryId);
     $blogContentId = $categoryPath[0]['BlogCategory']['blog_content_id'];
     $this->setContent($blogContentId);
     $path = array('category');
     if ($categoryPath) {
         foreach ($categoryPath as $category) {
             $path[] = urldecode($category['BlogCategory']['name']);
         }
     }
     if ($named) {
         $path = array_merge($path, $named);
     }
     $url = Router::url($this->request->params['Content']['url'] . 'archives/' . implode('/', $path));
     $baseUrl = preg_replace('/\\/$/', '', BC_BASE_URL);
     return preg_replace('/^' . preg_quote($baseUrl, '/') . '/', '', $url);
 }
 /**
  * @return ArrayList of {@link BlogCategoryCloud_Category}
  */
 public function Categories()
 {
     $result = new ArrayList();
     $cats = BlogCategory::get();
     $entries = BlogEntry::get();
     if ($this->holderId) {
         $cats = $cats->filter('ParentID', $this->holderId);
         $entries = $entries->filter('ParentID', $this->holderId);
     }
     $totalEntryCount = $entries->count();
     // TODO Not possible in a single query due to SS3 ORM
     $aggregateQuery = clone $cats->dataQuery()->query();
     $aggregateQuery->addLeftJoin('BlogEntry_BlogCategories', '"BlogEntry_BlogCategories"."BlogCategoryID" = "BlogCategory"."ID"');
     $aggregateQuery->addLeftJoin('BlogEntry', '"BlogEntry_BlogCategories"."BlogEntryID" = "BlogEntry"."ID"');
     $aggregateQuery->setSelect(array('"BlogCategory"."ID"'));
     $aggregateQuery->selectField('COUNT("BlogEntry"."ID")', 'BlogEntryCount');
     $aggregateQuery->setGroupBy(array('"BlogCategory"."ID"'));
     $aggregateResults = array();
     $maxEntryCount = 0;
     foreach ($aggregateQuery->execute() as $v) {
         $aggregateResults[$v['ID']] = $v;
         if ($v['BlogEntryCount'] > $maxEntryCount) {
             $maxEntryCount = $v['BlogEntryCount'];
         }
     }
     foreach ($cats as $cat) {
         $result->push(BlogCategoryCloud_Category::create($cat, $aggregateResults[$cat->ID]['BlogEntryCount'], $totalEntryCount, $maxEntryCount));
     }
     // Sort in-memory since it might be related to dynamic values like frequency
     // TODO Convert frequency calc to subselect and do sorting in SQL
     if ($this->limit) {
         $result = $result->sort($this->limitSortBy);
         $result = $result->limit($this->limit);
     }
     $result = $result->sort($this->sort);
     return $result;
 }
Пример #21
0
 /**
  * カテゴリ一覧へのURLを取得する
  * 
  * [注意] リンク関数でラップする前提の為、ベースURLは考慮されない
  *
  * @param string $blogCategoyId ブログカテゴリID
  * @param array $options オプション(初期値 : array())
  *	`named` : URLの名前付きパラメーター
  * @return string カテゴリ一覧へのURL
  */
 public function getCategoryUrl($blogCategoryId, $options = array())
 {
     $options = array_merge(array('named' => array()), $options);
     extract($options);
     if (!isset($this->BlogCategory)) {
         $this->BlogCategory = ClassRegistry::init('BlogCategory', 'Model');
     }
     $categoryPath = $this->BlogCategory->getPath($blogCategoryId);
     $blogContentId = $categoryPath[0]['BlogCategory']['blog_content_id'];
     $this->setContent($blogContentId);
     $blogContentName = $this->blogContent['name'];
     $path = array('category');
     if ($categoryPath) {
         foreach ($categoryPath as $category) {
             $path[] = urldecode($category['BlogCategory']['name']);
         }
     }
     if ($named) {
         $path = array_merge($path, $named);
     }
     $url = Router::url(am(array('admin' => false, 'plugin' => '', 'controller' => $blogContentName, 'action' => 'archives'), $path));
     $baseUrl = preg_replace('/\\/$/', '', BC_BASE_URL);
     return preg_replace('/^' . preg_quote($baseUrl, '/') . '/', '', $url);
 }
 public function postProcess()
 {
     if (Tools::isSubmit('deletesmart_blog_category') && Tools::getValue('id_smart_blog_category') != '') {
         $id_lang = (int) Context::getContext()->language->id;
         $catpost = (int) SmartBlogPost::getToltalByCategory($id_lang, Tools::getValue('id_smart_blog_category'));
         if ((int) $catpost != 0) {
             $this->errors[] = Tools::displayError('You need to delete all posts associate with this category .');
         } else {
             $BlogCategory = new BlogCategory((int) Tools::getValue('id_smart_blog_category'));
             if (!$BlogCategory->delete()) {
                 $this->errors[] = Tools::displayError('An error occurred while deleting the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 Hook::exec('actionsbdeletecat', array('BlogCategory' => $BlogCategory));
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
             }
         }
     } elseif (Tools::isSubmit('submitAddsmart_blog_category')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         if (!($id_smart_blog_category = (int) Tools::getValue('id_smart_blog_category'))) {
             $BlogCategory = new BlogCategory();
             $languages = Language::getLanguages(false);
             foreach ($languages as $language) {
                 $title = str_replace('"', '', htmlspecialchars_decode(html_entity_decode(Tools::getValue('meta_title_' . $language['id_lang']))));
                 $BlogCategory->meta_title[$language['id_lang']] = $title;
                 $BlogCategory->meta_keyword[$language['id_lang']] = Tools::getValue('meta_keyword_' . $language['id_lang']);
                 $BlogCategory->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
                 $BlogCategory->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']);
                 if (Tools::getValue('link_rewrite_' . $language['id_lang']) == '' && Tools::getValue('link_rewrite_' . $language['id_lang']) == null) {
                     $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('meta_title_' . $language['id_lang']));
                 } else {
                     $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('link_rewrite_' . $language['id_lang']));
                 }
             }
             $BlogCategory->id_parent = Tools::getValue('id_parent');
             $BlogCategory->position = Tools::getValue('position');
             $BlogCategory->desc_limit = Tools::getValue('desc_limit');
             $BlogCategory->active = Tools::getValue('active');
             $BlogCategory->created = Date('y-m-d H:i:s');
             $BlogCategory->modified = Date('y-m-d H:i:s');
             if (!$BlogCategory->save()) {
                 $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
             } else {
                 Hook::exec('actionsbnewcat', array('BlogCategory' => $BlogCategory));
                 $this->processImageCategory($_FILES, $BlogCategory->id);
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
             }
         } elseif ($id_smart_blog_category = Tools::getValue('id_smart_blog_category')) {
             $BlogCategory = new BlogCategory($id_smart_blog_category);
             $languages = Language::getLanguages(false);
             foreach ($languages as $language) {
                 $title = str_replace('"', '', htmlspecialchars_decode(html_entity_decode(Tools::getValue('meta_title_' . $language['id_lang']))));
                 $BlogCategory->meta_title[$language['id_lang']] = $title;
                 $BlogCategory->meta_keyword[$language['id_lang']] = Tools::getValue('meta_keyword_' . $language['id_lang']);
                 $BlogCategory->meta_description[$language['id_lang']] = Tools::getValue('meta_description_' . $language['id_lang']);
                 $BlogCategory->description[$language['id_lang']] = Tools::getValue('description_' . $language['id_lang']);
                 $BlogCategory->link_rewrite[$language['id_lang']] = str_replace(array(' ', ':', '\\', '/', '#', '!', '*', '.', '?'), '-', Tools::getValue('link_rewrite_' . $language['id_lang']));
             }
             $BlogCategory->id_parent = Tools::getValue('id_parent');
             $BlogCategory->position = Tools::getValue('position');
             $BlogCategory->desc_limit = Tools::getValue('desc_limit');
             $BlogCategory->active = Tools::getValue('active');
             $BlogCategory->modified = Date('y-m-d H:i:s');
             if (!$BlogCategory->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 Hook::exec('actionsbupdatecat', array('BlogCategory' => $BlogCategory));
             }
             $this->processImageCategory($_FILES, $BlogCategory->id_smart_blog_category);
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
         }
     } elseif (Tools::isSubmit('statussmart_blog_category') && Tools::getValue($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Hook::exec('actionsbtogglecat', array('SmartBlogCat' => $this->object));
                     $identifier = (int) $object->id_parent ? '&id_smart_blog_category=' . (int) $object->id_parent : '';
                     Tools::redirectAdmin($this->context->link->getAdminLink('AdminBlogCategory'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('smart_blog_categoryOrderby') && Tools::isSubmit('smart_blog_categoryOrderway')) {
         $this->_defaultOrderBy = Tools::getValue('smart_blog_categoryOrderby');
         $this->_defaultOrderWay = Tools::getValue('smart_blog_categoryOrderway');
     }
 }
 public function renderForm()
 {
     $this->post_format_fields = smartblog::$post_meta_fields;
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $shops = false;
     if (Shop::isFeatureActive()) {
         $shops = Shop::getShops();
     }
     if ($shops) {
         foreach ($shops as $key => $shop) {
             if (!$obj->isAssociatedToShop($shop['id_shop'])) {
                 unset($shops[$key]);
             }
         }
     }
     $languages = Language::getLanguages(false);
     //Added From Old
     /*         * ************* featured image ****************** */
     $featured_image = _MODULE_SMARTBLOG_DIR_ . $obj->id . '.jpg';
     $image_url = ImageManager::thumbnail($featured_image, $this->table . '_' . pSQL(Tools::getvalue('id_smart_blog_post')) . '.jpg', 200, 'jpg', true, true);
     $image_size = file_exists($featured_image) ? filesize($featured_image) / 1000 : false;
     /*         * ************* featured image ****************** */
     // image gallary
     $id_smart_blog_post = (int) Tools::getValue('id_smart_blog_post');
     $images = SmartBlogGallaryImage::getImages($this->context->language->id, $id_smart_blog_post);
     foreach ($images as $k => $image) {
         $images[$k] = new SmartBlogGallaryImage($image['id_smart_blog_gallary_images']);
     }
     //start sdsimage type
     $image_uploader = new HelperImageUploader('file');
     $image_uploader->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminSmartBlogAjax') . '&ajax=1&id_smart_blog_post=' . (int) Tools::getvalue('id_smart_blog_post') . '&action=addGallaryImage');
     // test code
     $root = BlogCategory::getRootCategory();
     $default_category = $root['id_smart_blog_category'];
     if (!Tools::isSubmit('id_smart_blog_post')) {
         $selected_cat = BlogCategory::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language);
     } else {
         if (Tools::isSubmit('categoryBox')) {
             $selected_cat = BlogCategory::getCategoryInformations(Tools::getValue('categoryBox', array($default_category)), $this->default_form_language);
         } else {
             $selected_cat = BlogCategory::getPostCategoriesFull((int) Tools::getValue('id_smart_blog_post'), $this->default_form_language);
         }
     }
     $categories = array();
     foreach ($selected_cat as $key => $category) {
         $categories[] = $key;
     }
     $tree = new SmartBlogHelperTreeCategories('smartblog-associated-categories-tree', 'Associated categories');
     $tree->setTemplate('tree_associated_categories.tpl')->setHeaderTemplate('tree_associated_header.tpl')->setRootCategory((int) $root['id_category'])->setUseCheckBox(true)->setUseSearch(false)->setSelectedCategories($categories);
     // end test code
     $temp_employees = Employee::getEmployees();
     $employees = array();
     foreach ($temp_employees as $employee) {
         $employee['fullname'] = $employee['firstname'] . ' ' . $employee['lastname'];
         $employee['id_select'] = $employee['id_employee'];
         $employees[] = $employee;
     }
     $this->fields_form = array('legend' => array('title' => $this->l('Blog Post')), 'input' => array(array('type' => 'text', 'label' => $this->l('Blog Title'), 'name' => 'meta_title', 'id' => 'name', 'class' => 'copyMeta2friendlyURL', 'size' => 60, 'required' => true, 'desc' => $this->l('Enter Your Blog Post Title'), 'lang' => true), array('type' => 'select', 'label' => $this->l('Author'), 'name' => 'id_author', 'options' => array('query' => $employees, 'id' => 'id_select', 'name' => 'fullname')), array('type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'content', 'lang' => true, 'rows' => 10, 'cols' => 62, 'class' => 'rte', 'autoload_rte' => true, 'desc' => $this->l('Enter Your Post Description')), array('type' => 'file', 'label' => $this->l('Featured Image:'), 'name' => 'image', 'display_image' => true, 'image' => $image_url ? $image_url : false, 'size' => $image_size, 'delete_url' => self::$currentIndex . '&' . $this->identifier . '=' . pSQL(Tools::getvalue('id_smart_blog_post')) . '&token=' . $this->token . '&deleteImage=1', 'hint' => $this->l('Upload a feature image from your computer.')), array('type' => 'html', 'label' => $this->l('Blog Categories'), 'name' => 'id_category_big', 'required' => true, 'html_content' => $tree->render(), 'desc' => $this->l('Select Your Parent Category')), array('type' => 'text', 'label' => $this->l('Meta Keyword'), 'name' => 'meta_keyword', 'lang' => true, 'size' => 60, 'required' => false, 'desc' => $this->l('Enter Your Post Meta Keyword. Separated by comma(,)')), array('type' => 'textarea', 'label' => $this->l('Short Description'), 'name' => 'short_description', 'rows' => 10, 'cols' => 62, 'lang' => true, 'required' => true, 'desc' => $this->l('Enter Your Post Short Description')), array('type' => 'textarea', 'label' => $this->l('Meta Description'), 'name' => 'meta_description', 'rows' => 10, 'cols' => 62, 'lang' => true, 'required' => false, 'desc' => $this->l('Enter Your Post Meta Description')), array('type' => 'text', 'label' => $this->l('Link Rewrite'), 'name' => 'link_rewrite', 'size' => 60, 'lang' => true, 'required' => false, 'desc' => $this->l('Enetr Your Post Slug. Use In SEO Friendly URL')), array('type' => 'tags', 'label' => $this->l('Tag'), 'name' => 'tags', 'size' => 60, 'lang' => true, 'required' => false, 'hint' => array($this->l('To add "tags" click in the field, write something, and then press "Enter."'), $this->l('Invalid characters:') . ' &lt;&gt;;=#{}')), array('type' => 'switch', 'label' => $this->l('Comment Status'), 'name' => 'comment_status', 'required' => false, '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'))), 'desc' => $this->l('You Can Enable or Disable Your Comments')), array('label' => $this->l('Published Date'), 'name' => 'created', 'title' => $this->l('Published date'), 'type' => 'datetime'), array('type' => 'associations', 'label' => $this->l('Related Product(s)'), 'name' => 'associations', 'size' => 60, 'lang' => true, 'required' => false), array('type' => 'switch', 'label' => $this->l('Status'), 'name' => 'active', 'required' => false, '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' => 'switch', 'label' => $this->l('Is Featured?'), 'name' => 'is_featured', 'required' => false, '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'))))), 'gallary' => array('images' => array('count' => count($images), 'max_image_size' => $this->max_image_size / 1024 / 1024, 'table' => $this->table, 'images' => $images, 'id_smart_blog_post' => (int) Tools::getValue('id_smart_blog_post'), 'object' => $this->object, 'image_uploader' => $image_uploader->render())));
     $this->fields_form['input'][] = array('type' => 'radio', 'label' => $this->l('Post Format'), 'name' => 'post_type', 'required' => true, 'values' => array(array('id' => 'post_type_default', 'value' => '', 'label' => '<i class="icon-home"></i> ' . $this->l('None')), array('id' => 'post_type_gallery', 'value' => 'gallery', 'label' => '<i class="icon-picture"></i> ' . $this->l('Gallery')), array('id' => 'post_type_audio', 'value' => 'audio', 'label' => '<i class="icon-music"></i> ' . $this->l('Audio')), array('id' => 'post_type_video', 'value' => 'video', 'label' => '<i class="icon-film"></i> ' . $this->l('Video')), array('id' => 'post_type_quote', 'value' => 'quote', 'label' => '<i class="icon-quote-left"></i> ' . $this->l('Quote')), array('id' => 'post_type_link', 'value' => 'link', 'label' => '<i class="icon-link"></i> ' . $this->l('Link'))));
     $this->fields_form['input'][] = array('type' => 'html', 'label' => $this->l('Post Format Fields'), 'name' => 'post_format_fields', 'html_content' => $this->AdminMetaFields(), 'desc' => $this->l('Set exclusive fields for the post format'));
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso');
     }
     if (!($SmartBlogPost = $this->loadObject(true))) {
         return;
     }
     $this->fields_form['submit'] = array('title' => $this->l('Save'));
     $image = ImageManager::thumbnail(_MODULE_SMARTBLOG_DIR_ . $SmartBlogPost->id_smart_blog_post . '.jpg', $this->table . '_' . (int) $SmartBlogPost->id_smart_blog_post . '.' . $this->imageType, 350, $this->imageType, true);
     $this->fields_value = array('image' => $image ? $image : false, 'size' => $image ? filesize(_MODULE_SMARTBLOG_DIR_ . $SmartBlogPost->id_smart_blog_post . '.jpg') / 1000 : false);
     if (Tools::getvalue('id_smart_blog_post') != '' && Tools::getvalue('id_smart_blog_post') != NULL) {
         foreach (Language::getLanguages(false) as $lang) {
             $this->fields_value['tags'][(int) $lang['id_lang']] = SmartBlogPost::getProductTagsBylang((int) Tools::getvalue('id_smart_blog_post'), (int) $lang['id_lang']);
         }
     }
     $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
     // related product using Accessories block
     $accessories = SmartBlogPost::getAccessoriesLight($this->context->language->id, $SmartBlogPost->id_smart_blog_post);
     if ($post_accessories = Tools::getValue('inputAccessories')) {
         $post_accessories_tab = explode('-', $post_accessories);
         foreach ($post_accessories_tab as $accessory_id) {
             if (!$this->haveThisAccessory($accessory_id, $accessories) && ($accessory = Product::getAccessoryById($accessory_id))) {
                 $accessories[] = $accessory;
             }
         }
     }
     $this->tpl_form_vars['accessories'] = $accessories;
     /* image gallary */
     $this->tpl_form_vars['images'] = $images;
     $this->tpl_form_vars['image_uploader'] = $image_uploader->render();
     $this->tpl_form_vars['max_image_size'] = $this->max_image_size / 1024 / 1024;
     $this->tpl_form_vars['languages'] = $languages;
     $this->tpl_form_vars['iso_lang'] = $languages[0]['iso_code'];
     $this->tpl_form_vars['imageType'] = 'home-small';
     $this->tpl_form_vars['id_smart_blog_post'] = (int) Tools::getValue('id_smart_blog_post');
     $this->tpl_form_vars['default_language'] = (int) Configuration::get('PS_LANG_DEFAULT');
     $this->tpl_form_vars['table'] = $this->table;
     $this->tpl_form_vars['token'] = Tools::getAdminTokenLite('AdminBlogPost');
     $this->tpl_form_vars['gallary_path'] = _MODULE_DIR_ . 'smartblog/gallary/';
     // $this->tpl_form_vars['token_book'] = Tools::getAdminTokenLite('AdminBook');
     return parent::renderForm();
 }
Пример #24
0
 public function renderForm()
 {
     $img_desc = '';
     $img_desc .= $this->l('Upload a Feature Image from your computer.<br/>N.B : Only jpg image is allowed');
     if (Tools::getvalue('id_smart_blog_post') != '' && Tools::getvalue('id_smart_blog_post') != NULL) {
         $img_desc .= '<br/><img style="height:auto;width:300px;clear:both;border:1px solid black;" alt="" src="' . __PS_BASE_URI__ . 'modules/smartblog/images/' . Tools::getvalue('id_smart_blog_post') . '.jpg" /><br />';
     }
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $image = _MODULE_SMARTBLOG_DIR_ . $obj->id . '.jpg';
     $image_url = ImageManager::thumbnail($image, $this->table . '_' . Tools::getvalue('id_smart_blog_post') . '.jpg', 200, 'jpg', true, true);
     $image_size = file_exists($image) ? filesize($image) / 1000 : false;
     $this->fields_form = array('legend' => array('title' => $this->l('Blog Post')), 'input' => array(array('type' => 'hidden', 'name' => 'post_type', 'default_value' => 0), array('type' => 'text', 'label' => $this->l('Blog Title'), 'name' => 'meta_title', 'id' => 'name', 'class' => 'copyMeta2friendlyURL', 'size' => 60, 'required' => true, 'desc' => $this->l('Enter Your Blog Post Title'), 'lang' => true), array('type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'content', 'lang' => true, 'rows' => 10, 'cols' => 62, 'class' => 'rte', 'autoload_rte' => true, 'required' => true, 'hint' => array($this->l('Enter Your Post Description'), $this->l('Invalid characters:') . ' <>;=#{}')), array('type' => 'file', 'label' => $this->l('Feature Image:'), 'name' => 'image', 'display_image' => true, 'image' => $image_url ? $image_url : false, 'size' => $image_size, 'delete_url' => self::$currentIndex . '&' . $this->identifier . '=' . Tools::getvalue('id_smart_blog_post') . '&token=' . $this->token . '&deleteImage=1', 'hint' => $this->l('Upload a feature image from your computer.')), array('type' => 'select', 'label' => $this->l('Blog Category'), 'name' => 'id_category', 'options' => array('query' => BlogCategory::getCategory(), 'id' => 'id_smart_blog_category', 'name' => 'meta_title'), 'desc' => $this->l('Select Your Parent Category')), array('type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => array($this->l('To add "tags" click in the field, write something, and then press "Enter."'), $this->l('Invalid characters:') . ' &lt;&gt;;=#{}')), array('type' => 'textarea', 'label' => $this->l('Short Description'), 'name' => 'short_description', 'rows' => 10, 'cols' => 62, 'lang' => true, 'required' => true, 'hint' => array($this->l('Enter Your Post Short Description'))), array('type' => 'textarea', 'label' => $this->l('Meta Description'), 'name' => 'meta_description', 'rows' => 10, 'cols' => 62, 'lang' => true, 'required' => false, 'desc' => $this->l('Enter Your Post Meta Description')), array('type' => 'text', 'label' => $this->l('Link Rewrite'), 'name' => 'link_rewrite', 'size' => 60, 'lang' => true, 'required' => false, 'hint' => $this->l('Only letters and the hyphen (-) character are allowed.')), array('type' => 'tags', 'label' => $this->l('Tag'), 'name' => 'tags', 'size' => 60, 'lang' => true, 'required' => false, 'hint' => array($this->l('To add "tags" click in the field, write something, and then press "Enter."'), $this->l('Invalid characters:') . ' &lt;&gt;;=#{}')), array('type' => 'radio', 'label' => $this->l('Comment Status'), 'name' => 'comment_status', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('You Can Enable or Disable Your Comments')), array('type' => 'radio', 'label' => $this->l('Status'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'radio', 'label' => $this->l('Is Featured?'), 'name' => 'is_featured', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'is_featured', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'is_featured', 'value' => 0, 'label' => $this->l('Disabled'))))), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'));
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso');
     }
     if (!($SmartBlogPost = $this->loadObject(true))) {
         return;
     }
     $this->fields_form['submit'] = array('title' => $this->l('Save   '), 'class' => 'button');
     $image = ImageManager::thumbnail(_MODULE_SMARTBLOG_DIR_ . $SmartBlogPost->id_smart_blog_post . '.jpg', $this->table . '_' . (int) $SmartBlogPost->id_smart_blog_post . '.' . $this->imageType, 350, $this->imageType, true);
     $this->fields_value = array('image' => $image ? $image : false, 'size' => $image ? filesize(_MODULE_SMARTBLOG_DIR_ . $SmartBlogPost->id_smart_blog_post . '.jpg') / 1000 : false);
     if (Tools::getvalue('id_smart_blog_post') != '' && Tools::getvalue('id_smart_blog_post') != NULL) {
         foreach (Language::getLanguages(false) as $lang) {
             $this->fields_value['tags'][(int) $lang['id_lang']] = SmartBlogPost::getProductTagsBylang((int) Tools::getvalue('id_smart_blog_post'), (int) $lang['id_lang']);
         }
     }
     $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
     return parent::renderForm();
 }
Пример #25
0
 /**
  * {@inheritdoc}
  */
 public function getCMSFields()
 {
     Requirements::css(BLOGGER_DIR . '/css/cms.css');
     Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
     $self =& $this;
     $this->beforeUpdateCMSFields(function ($fields) use($self) {
         $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image'));
         $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
         /**
          * @var FieldList $fields
          */
         $fields->insertAfter($uploadField, 'Content');
         $summary = HtmlEditorField::create('Summary', false);
         $summary->setRows(5);
         $summary->setDescription(_t('BlogPost.SUMMARY_DESCRIPTION', 'If no summary is specified the first 30 words will be used.'));
         $summaryHolder = ToggleCompositeField::create('CustomSummary', _t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'), array($summary));
         $summaryHolder->setHeadingLevel(4);
         $summaryHolder->addExtraClass('custom-summary');
         $fields->insertAfter($summaryHolder, 'FeaturedImage');
         $fields->push(HiddenField::create('MenuTitle'));
         $urlSegment = $fields->dataFieldByName('URLSegment');
         $urlSegment->setURLPrefix($self->Parent()->RelativeLink());
         $fields->removeFieldsFromTab('Root.Main', array('MenuTitle', 'URLSegment'));
         $authorField = ListboxField::create('Authors', _t('BlogPost.Authors', 'Authors'), $self->getCandidateAuthors()->map()->toArray())->setMultiple(true);
         $authorNames = TextField::create('AuthorNames', _t('BlogPost.AdditionalCredits', 'Additional Credits'), null, 1024)->setDescription(_t('BlogPost.AdditionalCredits_Description', 'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.'));
         if (!$self->canEditAuthors()) {
             $authorField = $authorField->performDisabledTransformation();
             $authorNames = $authorNames->performDisabledTransformation();
         }
         $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
         $publishDate->getDateField()->setConfig('showcalendar', true);
         if (!$self->PublishDate) {
             $publishDate->setDescription(_t('BlogPost.PublishDate_Description', 'Will be set to "now" if published without a value.'));
         }
         // Get categories and tags
         $parent = $self->Parent();
         $categories = $parent instanceof Blog ? $parent->Categories() : BlogCategory::get();
         $tags = $parent instanceof Blog ? $parent->Tags() : BlogTag::get();
         $options = BlogAdminSidebar::create($publishDate, $urlSegment, TagField::create('Categories', _t('BlogPost.Categories', 'Categories'), $categories, $self->Categories())->setCanCreate($self->canCreateCategories())->setShouldLazyLoad(true), TagField::create('Tags', _t('BlogPost.Tags', 'Tags'), $tags, $self->Tags())->setCanCreate($self->canCreateTags())->setShouldLazyLoad(true), $authorField, $authorNames)->setTitle('Post Options');
         $options->setName('blog-admin-sidebar');
         $fields->insertBefore($options, 'Root');
     });
     $fields = parent::getCMSFields();
     $fields->fieldByName('Root')->setTemplate('TabSet_holder');
     return $fields;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     BlogCategory::where('parent_id', '=', $id)->delete();
     $cat = BlogCategory::find($id);
     if ($cat) {
         $cat->delete();
     }
     return array('status' => 'OK');
 }
 public function getData()
 {
     if (!isset($this->_data)) {
         $shop = $this->getShop();
         $lang = $this->getLang();
         $root_category = (int) $this->getRootCategory();
         if ($this->_full_tree) {
             $this->setData(BlogCategory::getNestedCategories($root_category, $lang, false, null, $this->useShopRestriction()));
             $this->setDataSearch(BlogCategory::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction()));
         } elseif ($this->_children_only) {
             if (empty($root_category)) {
                 $root_category = BlogCategory::getRootCategory();
                 $root_category = $root_category['id_smart_blog_category'];
             }
             $categories = array();
             $categories[$root_category] = BlogCategory::getChildren($root_category, $lang, false, $shop->id);
             $children = $this->fillTree($categories, $root_category);
             $this->setData($children);
         } else {
             if (empty($root_category)) {
                 $root_category = BlogCategory::getRootCategory();
                 $root_category = $root_category['id_smart_blog_category'];
             }
             $new_selected_categories = array();
             $selected_categories = $this->getSelectedCategories();
             $categories[$root_category] = BlogCategory::getChildren($root_category, $lang, false);
             foreach ($selected_categories as $selected_category) {
                 $category = new BlogCategory($selected_category, $lang, $shop->id);
                 $new_selected_categories[] = $selected_category;
                 $parents = $category->getParentsCategories($lang);
                 foreach ($parents as $value) {
                     $new_selected_categories[] = $value['id_category'];
                 }
             }
             $new_selected_categories = array_unique($new_selected_categories);
             foreach ($new_selected_categories as $selected_category) {
                 $current_category = BlogCategory::getChildren($selected_category, $lang, false, $shop->id);
                 if (!empty($current_category)) {
                     $categories[$selected_category] = $current_category;
                 }
             }
             $tree = BlogCategory::getCategoryInformations(array($root_category), $lang);
             $children = $this->fillTree($categories, $root_category);
             if (!empty($children)) {
                 $tree[$root_category]['children'] = $children;
             }
             $this->setData($tree);
             $this->setDataSearch(BlogCategory::getAllCategoriesName($root_category, $lang, false, null, $this->useShopRestriction()));
         }
     }
     return $this->_data;
 }
Пример #28
0
 public static function SmartBlogSearchPost($keyword = NULL, $id_lang = NULL5)
 {
     if ($keyword == NULL) {
         return false;
     }
     if ($id_lang == NULL) {
         $id_lang = (int) Context::getContext()->language->id;
     }
     $keyword = pSQL($keyword);
     $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post_lang pl, ' . _DB_PREFIX_ . 'smart_blog_post p 
             WHERE pl.id_lang=' . pSQL($id_lang) . '  AND p.active = 1 
             AND pl.id_smart_blog_post=p.id_smart_blog_post AND
             (pl.meta_title LIKE \'%' . $keyword . '%\' OR
              pl.meta_keyword LIKE \'%' . $keyword . '%\' OR
              pl.meta_description LIKE \'%' . $keyword . '%\' OR
              pl.content LIKE \'%' . $keyword . '%\') ORDER BY p.id_smart_blog_post DESC';
     if (!($posts = Db::getInstance()->executeS($sql))) {
         return false;
     }
     $BlogCategory = new BlogCategory();
     $i = 0;
     $result = array();
     foreach ($posts as $post) {
         $result[$i]['post_format'] = $post['post_type'];
         $result[$i]['id_post'] = $post['id_smart_blog_post'];
         $result[$i]['viewed'] = $post['viewed'];
         $result[$i]['is_featured'] = $post['is_featured'];
         $result[$i]['meta_title'] = $post['meta_title'];
         $result[$i]['short_description'] = $post['short_description'];
         $result[$i]['meta_description'] = $post['meta_description'];
         $result[$i]['content'] = $post['content'];
         $result[$i]['meta_keyword'] = $post['meta_keyword'];
         $result[$i]['id_category'] = $post['id_category'];
         $result[$i]['link_rewrite'] = $post['link_rewrite'];
         $result[$i]['cat_name'] = $BlogCategory->getCatName($post['id_category']);
         $result[$i]['cat_link_rewrite'] = $BlogCategory->getCatLinkRewrite($post['id_category']);
         $employee = new Employee($post['id_author']);
         $result[$i]['lastname'] = $employee->lastname;
         $result[$i]['firstname'] = $employee->firstname;
         if (file_exists(_PS_MODULE_DIR_ . 'smartblog/images/' . $post['id_smart_blog_post'] . '.jpg')) {
             $image = $post['id_smart_blog_post'];
             $result[$i]['post_img'] = $image;
         } else {
             $result[$i]['post_img'] = 'no';
         }
         $result[$i]['created'] = Smartblog::displayDate($post['created']);
         $i++;
     }
     return $result;
 }
Пример #29
0
 public function smartblogcategoriesHookLeftColumn($params)
 {
     if (!$this->isCached('plugins/smartblogcategories.tpl')) {
         $view_data = array();
         $id_lang = $this->context->language->id;
         $BlogCategory = new BlogCategory();
         $categories = $BlogCategory->getCategory(1, $id_lang);
         $i = 0;
         foreach ($categories as $category) {
             $categories[$i]['count'] = $BlogCategory->getPostByCategory($category['id_smart_blog_category']);
             $i++;
         }
         $protocol_link = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://';
         $protocol_content = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
         $smartbloglink = new SmartBlogLink($protocol_link, $protocol_content);
         $this->smarty->assign(array('smartbloglink' => $smartbloglink, 'categories' => $categories));
     }
     return $this->display(__FILE__, 'views/templates/front/plugins/smartblogcategories.tpl');
 }
Пример #30
0
 public function renderForm()
 {
     $img_desc = '';
     $img_desc .= $this->l('Upload a Feature Image from your computer.<br/>N.B : Only jpg image is allowed');
     if (Tools::getvalue('id_smart_blog_post') != '' && Tools::getvalue('id_smart_blog_post') != NULL) {
         $img_desc .= '<br/><img style="height:auto;width:300px;clear:both;border:1px solid black;" alt="" src="' . __PS_BASE_URI__ . 'modules/smartblog/images/' . Tools::getvalue('id_smart_blog_post') . '.jpg" /><br />';
     }
     $this->fields_form = array('legend' => array('title' => $this->l('Blog Post')), 'input' => array(array('type' => 'hidden', 'name' => 'post_type', 'default_value' => 0), array('type' => 'text', 'label' => $this->l('Blog Title'), 'name' => 'meta_title', 'size' => 60, 'required' => true, 'desc' => $this->l('Enter Your Blog Post Title'), 'lang' => true), array('type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'content', 'lang' => true, 'rows' => 10, 'cols' => 62, 'class' => 'rte', 'autoload_rte' => true, 'required' => true, 'desc' => $this->l('Enter Your Post Description')), array('type' => 'file', 'label' => $this->l('Feature Image:'), 'name' => 'image', 'display_image' => false, 'desc' => $img_desc), array('type' => 'select', 'label' => $this->l('Blog Category'), 'name' => 'id_category', 'options' => array('query' => BlogCategory::getCategory(), 'id' => 'id_smart_blog_category', 'name' => 'meta_title'), 'desc' => $this->l('Select Your Parent Category')), array('type' => 'text', 'label' => $this->l('Meta Keyword'), 'name' => 'meta_keyword', 'lang' => true, 'size' => 60, 'required' => false, 'desc' => $this->l('Enter Your Post Meta Keyword. Separated by comma(,)')), array('type' => 'textarea', 'label' => $this->l('Short Description'), 'name' => 'short_description', 'rows' => 10, 'cols' => 62, 'lang' => true, 'required' => true, 'desc' => $this->l('Enter Your Post Short Description')), array('type' => 'textarea', 'label' => $this->l('Meta Description'), 'name' => 'meta_description', 'rows' => 10, 'cols' => 62, 'lang' => true, 'required' => false, 'desc' => $this->l('Enter Your Post Meta Description')), array('type' => 'text', 'label' => $this->l('Link Rewrite'), 'name' => 'link_rewrite', 'size' => 60, 'lang' => true, 'required' => false, 'desc' => $this->l('Enetr Your Post Slug. Use In SEO Friendly URL')), array('type' => 'text', 'label' => $this->l('Tag'), 'name' => 'tags', 'size' => 60, 'lang' => true, 'required' => false, 'desc' => $this->l('Enter Your Post Meta Tag. Separated by comma(,)')), array('type' => 'radio', 'label' => $this->l('Comment Status'), 'name' => 'comment_status', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('You Can Enable or Disable Your Comments')), array('type' => 'radio', 'label' => $this->l('Status'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'radio', 'label' => $this->l('Is Featured?'), 'name' => 'is_featured', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'is_featured', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'is_featured', 'value' => 0, 'label' => $this->l('Disabled'))))), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'));
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso');
     }
     if (!($SmartBlogPost = $this->loadObject(true))) {
         return;
     }
     $this->fields_form['submit'] = array('title' => $this->l('Save   '), 'class' => 'button');
     $image = ImageManager::thumbnail(_MODULE_SMARTBLOG_DIR_ . $SmartBlogPost->id_smart_blog_post . '.jpg', $this->table . '_' . (int) $SmartBlogPost->id_smart_blog_post . '.' . $this->imageType, 350, $this->imageType, true);
     $this->fields_value = array('image' => $image ? $image : false, 'size' => $image ? filesize(_MODULE_SMARTBLOG_DIR_ . $SmartBlogPost->id_smart_blog_post . '.jpg') / 1000 : false);
     if (Tools::getvalue('id_smart_blog_post') != '' && Tools::getvalue('id_smart_blog_post') != NULL) {
         foreach (Language::getLanguages(false) as $lang) {
             $this->fields_value['tags'][(int) $lang['id_lang']] = SmartBlogPost::getProductTagsBylang((int) Tools::getvalue('id_smart_blog_post'), (int) $lang['id_lang']);
         }
     }
     return parent::renderForm();
 }