Example #1
0
 public static function getToltalByCategory($id_lang, $id_category, $limit_start, $limit)
 {
     $result = array();
     $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post_lang pl INNER JOIN 
             ' . _DB_PREFIX_ . 'smart_blog_post p ON pl.id_smart_blog_post=p.id_smart_blog_post INNER JOIN
             ' . _DB_PREFIX_ . 'smart_blog_post_category pc ON p.id_smart_blog_post=pc.id_smart_blog_post
             WHERE pl.id_lang=' . $id_lang . ' and p.active = 1 AND pc.id_smart_blog_category = ' . $id_category . '
             ORDER BY p.id_smart_blog_post DESC LIMIT ' . $limit_start . ',' . $limit;
     if (!($posts = Db::getInstance()->executeS($sql))) {
         return false;
     }
     $context = Context::getContext();
     $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]['name'] = $post['name'];
         $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'];
         $post_format = $post['post_type'];
         $result[$i]['post_format'] = $post_format;
         if (isset(smartblog::$post_meta_fields[$post_format]) && !empty(smartblog::$post_meta_fields[$post_format])) {
             $importMetadata = array();
             foreach (smartblog::$post_meta_fields[$post_format] as $meta) {
                 $meta_key = "{$post_format}-{$meta['name']}";
                 $id_lang = null;
                 if (isset($meta['lang']) && $meta['lang']) {
                     $id_lang = $context->language->id;
                 }
                 $importMetadata[$meta_key] = BlogPostMeta::get((int) $post['id_smart_blog_post'], $meta_key, false, $id_lang);
             }
             $result[$i]['post_format_data'] = $importMetadata;
         }
         $i++;
     }
     return $result;
 }
 private function updateMetaFields($object)
 {
     if (isset($this->post_format_fields[$object->post_type]) && !empty($this->post_format_fields[$object->post_type])) {
         $fieldgroup = $object->post_type;
         foreach ($this->post_format_fields[$object->post_type] as $field) {
             if (isset($field['lang']) && $field['lang']) {
                 $languages = Language::getLanguages();
                 foreach ($languages as $language) {
                     $fieldname = "{$fieldgroup}-{$field['name']}_{$language['id_lang']}";
                     if (Tools::isSubmit($fieldname)) {
                         BlogPostMeta::updateValue($object->id, $fieldname, pSQL(Tools::getValue($fieldname)));
                     }
                 }
             } else {
                 if (Tools::isSubmit("{$fieldgroup}-{$field['name']}")) {
                     BlogPostMeta::updateValue($object->id, "{$fieldgroup}-{$field['name']}", pSQL(Tools::getValue("{$fieldgroup}-{$field['name']}")));
                 }
             }
         }
     }
     //BlogPostMeta::updateValue()
 }
Example #3
0
 public static function getArchiveResult($month = null, $year = null)
 {
     $BlogCategory = '';
     $month = pSQL($month);
     $year = pSQL($year);
     $result = array();
     $id_lang = (int) Context::getContext()->language->id;
     if ($month != '' and $month != NULL and $year != '' and $year != NULL) {
         $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post s INNER JOIN ' . _DB_PREFIX_ . 'smart_blog_post_lang sl ON s.id_smart_blog_post = sl.id_smart_blog_post
              and sl.id_lang = ' . $id_lang . ' INNER JOIN ' . _DB_PREFIX_ . 'smart_blog_post_shop ps ON ps.id_smart_blog_post = s.id_smart_blog_post AND ps.id_shop = ' . (int) Context::getContext()->shop->id . '
         where s.active = 1 and MONTH(s.created) = ' . $month . ' AND YEAR(s.created) = ' . $year . ' ORDER BY s.id_smart_blog_post DESC';
     } elseif ($month == '' and $month == NULL and $year != '' and $year != NULL) {
         $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post s INNER JOIN ' . _DB_PREFIX_ . 'smart_blog_post_lang sl ON s.id_smart_blog_post = sl.id_smart_blog_post
              and sl.id_lang = ' . $id_lang . ' INNER JOIN ' . _DB_PREFIX_ . 'smart_blog_post_shop ps ON ps.id_smart_blog_post = s.id_smart_blog_post AND ps.id_shop = ' . (int) Context::getContext()->shop->id . '
        where s.active = 1 AND YEAR(s.created) = ' . $year . ' ORDER BY s.id_smart_blog_post DESC';
     } elseif ($month != '' and $month != NULL and $year == '' and $year == NULL) {
         $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post s INNER JOIN ' . _DB_PREFIX_ . 'smart_blog_post_lang sl ON s.id_smart_blog_post = sl.id_smart_blog_post
              and sl.id_lang = ' . $id_lang . ' INNER JOIN ' . _DB_PREFIX_ . 'smart_blog_post_shop ps ON ps.id_smart_blog_post = s.id_smart_blog_post AND ps.id_shop = ' . (int) Context::getContext()->shop->id . '
        where s.active = 1 AND   MONTH(s.created) = ' . $month . '  ORDER BY s.id_smart_blog_post DESC';
     } else {
         $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post s INNER JOIN ' . _DB_PREFIX_ . 'smart_blog_post_lang sl ON s.id_smart_blog_post = sl.id_smart_blog_post
              and sl.id_lang = ' . $id_lang . ' INNER JOIN ' . _DB_PREFIX_ . 'smart_blog_post_shop ps ON ps.id_smart_blog_post = s.id_smart_blog_post AND ps.id_shop = ' . (int) Context::getContext()->shop->id . '
         where s.active = 1 ORDER BY s.id_smart_blog_post DESC';
     }
     if (!($posts = Db::getInstance()->executeS($sql))) {
         return false;
     }
     $BlogCategory = new BlogCategory();
     $i = 0;
     foreach ($posts as $post) {
         $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'] = $post['created'];
         $post_format = $post['post_type'];
         $result[$i]['post_format'] = $post_format;
         if (isset(smartblog::$post_meta_fields[$post_format]) && !empty(smartblog::$post_meta_fields[$post_format])) {
             $importMetadata = array();
             foreach (smartblog::$post_meta_fields[$post_format] as $meta) {
                 $meta_key = "{$post_format}-{$meta['name']}";
                 $id_lang = null;
                 if (isset($meta['lang']) && $meta['lang']) {
                     $id_lang = Context::getContext()->language->id;
                 }
                 $importMetadata[$meta_key] = BlogPostMeta::get((int) $post['id_smart_blog_post'], $meta_key, false, $id_lang);
             }
             $result[$i]['post_format_data'] = $importMetadata;
         }
         $i++;
     }
     return $result;
 }