Jump to content

Recommended Posts

mrhaba blog modülü için bu hatayı almaktayım yeni bir ekleme yapmak istediğimde 
n modules/advanceblog/controllers/admin/AdminBlogCategories.php (line 19) 

klasör içerisinde 19.satırda bir türlü yapamadım satır içeriği altta. burada nasıl bir yol izlemem gerekir acaba

<?php
/**
* Advance Blog
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @author    FMM Modules
* @copyright Copyright 2017 © fmemodules All right reserved
* @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
* @category  FMM Modules
* @package   advanceblog
*/

class AdminBlogPostsController extends ModuleAdminController
{
    public function __construct()
    {
        $this->table = 'fme_blog_posts';
        $this->className = 'BlogPosts';
        $this->identifier = 'id_post';
        $this->lang = true;
        $this->deleted = false;
        $this->colorOnBackground = false;
        $this->bootstrap = true;

        parent::__construct();

        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
        $this->context = Context::getContext();
        $this->fields_list = array(
            'id_post' => array(
                'title'     => '#',
                'width' => 25
            ),
            'post_title' => array(
                'title'     => $this->l('Title'),
                'width' => 'auto'
            ),
            'active' => array(
                'title' => $this->l('Active'),
                'width' => 70,
                'active' => 'status',
                'type' => 'bool',
                'align' => 'center',
                'orderby' => false
            ),
            'enable_comments' => array(
                'title' => $this->l('Enable Comments'),
                'width' => 70,
                'active' => 'enable_comments',
                'type' => 'bool',
                'align' => 'center',
                'orderby' => false
            ),
            'publication_time' => array(
                'title' => $this->l('Published On'),
                'width' => 70,
                'type' => 'datetime',
                'orderby' => false
            )
        );
    }

    public function renderList()
    {
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $dashboard_link = $this->context->link->getAdminLink('AdminModules').'&configure='.$this->module->name.'&tab_module='.$this->module->tab.'&module_name='.$this->module->name;
        $this->tpl_list_vars['dashboard_link'] = $dashboard_link;
        $this->context->smarty->assign('currentMenuTab', 'posts');
        $this->context->smarty->assign('subMenuTab', 'posts_view');
        return parent::renderList();
    }

    public function renderForm()
    {
        $back = Tools::safeOutput(Tools::getValue('back', ''));
        if (empty($back)) {
            $back = self::$currentIndex.'&token='.$this->token;
        }

        $this->toolbar_btn['save-and-stay'] = array(
            'href' => '#',
            'desc' => $this->l('Save and Stay')
        );
        $this->fields_form['submit'] = array(
            'title' => $this->l('   Save   '),
            'class' => 'button btn btn-default'
        );

        $this->context->smarty->assign('mode', $this->display);

        $iso = $this->context->language->iso_code;
        $iso_lang = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en');
        $id_lang_default = Configuration::get('PS_LANG_DEFAULT');
        $theme_dir = _THEME_CSS_DIR_;
        $path = dirname($_SERVER['PHP_SELF']);
        $js_path = _PS_JS_DIR_;
        $ps_version = _PS_VERSION_;
        $this->context->smarty->assign(array(
            'iso_lang' => $iso_lang,
            'theme_dir' => $theme_dir,
            'path' => $path,
            'ps_version' => $ps_version,
            'js_path' => $js_path,
            'id_lang_default' => $id_lang_default,
            ));
        $header_html = $this->context->smarty->fetch(_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/tiny_script.tpl');

        $protocol = (Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode()) ? 'https://' : 'http://';
        $this->context->smarty->assign('protocol', $protocol);
        $categories = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/categories.tpl';
        $authors = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/authors.tpl';
        $publish = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/publish.tpl';
        $tags = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/tags.tpl';
        $comments = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/comments.tpl';
        $shops = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/blog_shops.tpl';
        $related = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/related.tpl';
        $products = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/products.tpl';
        $informations = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/informations.tpl';
        $images = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/images.tpl';
        $videos = _PS_MODULE_DIR_.'advanceblog/views/templates/admin/blog_posts/video.tpl';
        $noscriptPath = __PS_BASE_URI__.'modules/advanceblog/views/css/jquery.fileupload-ui-noscript.css';
        $obj_model = new BlogPosts();
        //Get the selected ProductIDs
        $selected_shops = array();
        $id = (int)Tools::getValue('id_post');
        if ($id > 0) {
            $this->context->smarty->assign('id_post', $id);
            $this->context->smarty->assign('selectedPIDS', $obj_model->getProductsAttached($id));
            $attachproducts = array();
            $attachproducts = $obj_model->getProductsAll($id);
            if (!empty($attachproducts) && is_array($attachproducts)) {
                foreach ($attachproducts as &$product) {
                    $product = new Product((int)$product['id_product'], true, (int)$this->context->language->id);
                    $product->id_product_attribute = (int)Product::getDefaultAttribute($product->id) > 0 ? (int)Product::getDefaultAttribute($product->id) : 0;
                    $_cover = ((int)$product->id_product_attribute > 0) ? Product::getCombinationImageById((int)$product->id_product_attribute, $this->context->language->id) : Product::getCover($product->id);
                    if (!is_array($_cover)) {
                        $_cover = Product::getCover($product->id);
                    }
                    $product->id_image = $_cover['id_image'];
                }
            }
            $this->context->smarty->assign('attachproducts', $attachproducts);
            $selected_shops = $obj_model->getPostShops($id);
        } else {
            $this->context->smarty->assign('selectedPIDS', 0);
        }

        // video
        $postData = $obj_model->getPostDetails($id);
        $force_ssl = (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE'));
        $this->context->smarty->assign(array('base_dir' => _PS_BASE_URL_.__PS_BASE_URI__,
            'base_dir_ssl' => _PS_BASE_URL_SSL_.__PS_BASE_URI__,
            'force_ssl' => $force_ssl));
        $this->context->smarty->assign('postData', $postData);

        $languages = Language::getLanguages();
        $currencies = Currency::getCurrencies();
        $shop_selected_id = $this->context->shop->id;
        $blog_cats = $obj_model->getAllCategories($shop_selected_id);
        $blog_auths = $this->getAllAuthors();
        $exblog_cats = $obj_model->getPostCategories($id);
        $exblog_auth = $this->getAuth($id);
        $shops_tree = '';
        if (Shop::isFeatureActive()) {
            if (Tools::version_compare(_PS_VERSION_, '1.6', '<')) {
                $helper = new Helper();
                $shops_tree = $helper->renderShopList();
            } else {
                $helper = new HelperTreeShops('blog_cat_shop');
                $helper->setSelectedShops($selected_shops);
                $shops_tree = $helper->render();
            }
        }

        $blog_posts = $obj_model->getAllPosts($id);
        $exblog_posts = $obj_model->getRelatedPosts($id);

        $exImages = $obj_model->getPostImages($id);
        $exVideos = $obj_model->getPostVideos($id);
        $this->context->smarty->assign('exImages', $exImages);
        $this->context->smarty->assign('exVideos', $exVideos);
        $current_object = $this->loadObject(true);
        $helper_obj = new BlogPostsHelper();
        $this->context->smarty->assign('hooks', $helper_obj->hooksDDL());
        $this->context->smarty->assign('noscriptpath', $noscriptPath);
        $this->context->smarty->assign('default_img', Tools::getShopProtocol().$_SERVER['HTTP_HOST']._PS_IMG_.'uploads'.SEPARATOR.'prod_thumb.jpg');
        $this->context->smarty->assign('imgpath', $this->context->link->getAdminLink('AdminBlogPosts').'&action=addimage');
        $this->context->smarty->assign('video_action', $this->context->link->getAdminLink('AdminBlogPosts').'&id_post='.(int)Tools::getValue('id_post'));
        $this->context->smarty->assign('swfpath', Tools::getShopProtocol().$_SERVER['HTTP_HOST']._MODULE_DIR_.'advanceblog/views'.SEPARATOR.'js'.SEPARATOR.'uploader'.SEPARATOR.'plupload.flash.swf');
        $this->context->smarty->assign('path_jw_swf', Tools::getShopProtocol().$_SERVER['HTTP_HOST']._MODULE_DIR_.'advanceblog/views'.SEPARATOR.'js'.SEPARATOR.'mediaelement-flash-video.swf');
        $this->context->smarty->assign('xappath', Tools::getShopProtocol().$_SERVER['HTTP_HOST']._MODULE_DIR_.'advanceblog/views'.SEPARATOR.'js'.SEPARATOR.'uploader'.SEPARATOR.'plupload.silverlight.xap');
        $this->context->smarty->assign('img_path', Tools::getShopProtocol().$_SERVER['HTTP_HOST']._MODULE_DIR_.'advanceblog/views'.SEPARATOR.'img'.SEPARATOR.'');
        $this->context->smarty->assign('uploaded_img', Tools::getShopProtocol().$_SERVER['HTTP_HOST']._PS_IMG_.'uploads'.SEPARATOR.'thumbnails'.SEPARATOR);
        $this->context->smarty->assign('libpath', $this->context->link->getAdminLink('AdminBlogPosts').'&action=getproducts');
        $this->context->smarty->assign('img_dir_path', Tools::getShopProtocol().$_SERVER['HTTP_HOST']._PS_IMG_);
        $this->context->smarty->assign('seprator', SEPARATOR);
        $dashboard_link = $this->context->link->getAdminLink('AdminModules').'&configure='.$this->module->name.'&tab_module='.$this->module->tab.'&module_name='.$this->module->name;
        $this->context->smarty->assign('currentMenuTab', 'posts');
        $this->context->smarty->assign(array('header_html' => $header_html,
                'id_post' => (int)$id,
                'dashboard_link' => $dashboard_link,
                'show_toolbar' => true,
                'toolbar_btn' => $this->toolbar_btn,
                'toolbar_scroll' => $this->toolbar_scroll,
                'title' => array($this->l('Advance Blog')),
                'languages' => $languages,
                'currencies' => $currencies,
                'currentToken' => $this->token,
                'currentIndex' => self::$currentIndex,
                'currentObject' => $current_object,
                'currentTab' => $this,
                'blogCats' => $blog_cats,
                'blog_auths' => $blog_auths,
                'exBlogCats' => $exblog_cats,
                'exblog_auth' => $exblog_auth,
                'shops_tree' => $shops_tree,
                'blogPosts' => $blog_posts,
                'exBlogPosts' => $exblog_posts,
                'informations' => $informations,
                'categories' => $categories,
                'authors' => $authors,
                'publish' => $publish,
                'tags' => $tags,
                'comments' => $comments,
                'shops' => $shops,
                'related' => $related,
                'images' => $images,
                'products' => $products,
                'video' => $videos,
                'ps_version' => _PS_VERSION_,
                'employee_lang' => $this->context->employee->id_lang,
                'id_employee' => $this->context->employee->id,
                'id_lang_default' => Configuration::get('PS_LANG_DEFAULT'),
                'module_path' => __PS_BASE_URI__.'modules/advanceblog/views/',
                'defaultCurrency' => Configuration::get('PS_CURRENCY_DEFAULT'),
                'admin_url' => $this->context->link->getAdminLink('AdminBlogPosts'),
                'post_rewrite' => BlogPosts::getPostRewrite($id, $this->context->employee->id_lang)));
        $url = $this->context->link->getAdminLink('AdminBlogPosts', true);
        $this->context->smarty->assign('action_url', $url.'&action=getSearchProducts&forceJson=1&disableCombination=1&exclude_packs=0&excludeVirtuals=0&limit=20');
        $this->context->smarty->assign('action_url_addauthor', $url.'&action=addauthor');
        return parent::renderForm();
    }

    public function init()
    {
        parent::init();
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $id_lang = (int)Context::getContext()->language->id;
            if (Tools::getValue('post_title_'.$id_lang) == '') {
                $this->errors[] = $this->l('Post Title for default language can\'t be empty');
            }

            if (Tools::getValue('link_rewrite_'.$id_lang) == '') {
                $this->errors[] = $this->l('Permalink for default language can\'t be empty');
            }
        }
    }

    public function postProcess()
    {
        parent::postProcess();
        $id = (int)Tools::getValue('id_post');
        $action = Tools::getValue('action');

        if ($action == 'addimage') {
            $obj_file = new ImageManager();
            $img_real_name = $_FILES['file']['name'];
            $real_img_array = explode('.', $img_real_name);
            $real_img_only_name = $real_img_array[0];
            $real_img_ext = $real_img_array[1];
            move_uploaded_file($_FILES['file']['tmp_name'], _PS_IMG_DIR_.'uploads/'.$img_real_name);
            $obj_file->resize(_PS_IMG_DIR_.'uploads/'.$_FILES['file']['name'], _PS_IMG_DIR_.'uploads/thumbnails/'.$real_img_only_name.'.'.$real_img_ext, 200, 200);
            die('{"jsonrpc" : "2.0", "filename" : "'.$_FILES['file']['name'].'", "result" : null, "id" : "id"}');
        }


        // ajax add video file
        if ($action == 'addVideos') {
            $video = $_FILES['file'];
            $result = array(
                'jsonrpc' => '2.0',
                'id' => '',
                'filename' => '',
                'videoPath' => '',
                'type' => null,
                'result' => null,
                'errors' => null
            );
            $supported_formats = array('mp4', 'webm', 'ogv');
            $extension = Tools::strtolower(pathinfo($video['name'], PATHINFO_EXTENSION));
            if ($video['error']) {
                $result = array(
                                'jsonrpc' => '2.0',
                                'id' => '',
                                'filename' => $video['name'],
                                'videoPath' => null,
                                'result' => null,
                                'type' => 'video/'.$extension,
                                'errors' => Tools::displayError($video['error'])
                            );
            } elseif (!in_array($extension, $supported_formats)) {
                $result = array(
                                'jsonrpc' => '2.0',
                                'id' => '',
                                'filename' => $video['name'],
                                'videoPath' => null,
                                'type' => 'video/'.$extension,
                                'result' => null,
                                'errors' => sprintf(Tools::displayError('Invalid video format.').'%s', $video['name'])
                            );
            } else {
                $blog_path = _PS_IMG_DIR_.'blog';
                if (!file_exists($blog_path)) {
                    @mkdir($blog_path, 0777, true);
                }
                if (!file_exists($blog_path.'/temp')) {
                    @mkdir($blog_path.'/temp', 0777, true);
                }
                if (!file_exists($blog_path.'/temp/'.$id)) {
                    @mkdir($blog_path.'/temp/'.$id, 0777, true);
                }
                $blog_path .= '/temp';
                $imgRealName = $video['name'];
                $videoPath = 'blog/temp/'.(int)$id.'/'.$imgRealName;

                if (file_exists(_PS_IMG_DIR_.$videoPath)) {
                    $result = array(
                        'jsonrpc' => '2.0',
                        'id' => '',
                        'filename' => $video['name'],
                        'videoPath' => __PS_BASE_URI__.'img/'.$videoPath,
                        'type' => 'video/'.$extension,
                        'result' => null,
                        'errors' => sprintf(Tools::displayError('File %s already exists.'), $video['name'])
                    );
                } else {
                    $moved = move_uploaded_file($video['tmp_name'], $blog_path.'/'.$id.'/'.$imgRealName);
                    if (!$moved) {
                        $result = array(
                                    'jsonrpc' => '2.0',
                                    'id' => '',
                                    'filename' => $video['name'],
                                    'videoPath' => null,
                                    'type' => 'video/'.$extension,
                                    'result' => null,
                                    'errors' => sprintf(Tools::displayError('Error uploading video file.').'%s', $video['name'])
                                );
                    } else {
                        $fields = array(
                            'id_video' => (int)Tools::getValue('id_video'),
                            'id_post' => (int)$id,
                            'video_path' => $videoPath
                        );
                        if ($id_video = BlogPosts::saveVideoData($fields)) {
                            $result = array(
                                'jsonrpc' => '2.0',
                                'id' => $id_video,
                                'filename' => $video['name'],
                                'videoPath' => __PS_BASE_URI__.'img/'.$videoPath,
                                'type' => 'video/'.$extension,
                                'result' => null,
                                'errors' => null
                            );
                        }
                    }
                }
            }
            die(json_encode($result));
        }

        // ajax delete video file
        if ($action == 'deleteVideos' && Tools::getIsset('id_video') && Tools::getIsset('id_post')) {
            $id_video = (int)Tools::getValue('id_video');
            $id_post = (int)Tools::getValue('id_post');
            $result = array('success' => null, 'errors' => null);
            $video = BlogPosts::getVideoDetails($id_video, $id_post);

            if (isset($video) && $video) {
                if (!file_exists(_PS_IMG_DIR_.$video['video_path'])) {
                    $result = array('success' => false, 'errors' => Tools::displayError('Video file does not exists on storage media.'));
                } else {
                    if (!BlogPosts::deleteVideoById($id_video, $id_post)) {
                        $result = array('success' => false, 'errors' => Tools::displayError('File deletion error.'));
                    } else {
                        unlink(_PS_IMG_DIR_.$video['video_path']);
                        $result = array('success' => true, 'errors' => null);
                    }
                }
            }
            die(json_encode($result));
        }
        $obj_model = new BlogPosts();
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            if ($id == 0) {
                $id = $obj_model->getLastId();
            }
        }
        if (Tools::isSubmit('submitAddfme_blog_posts') || Tools::isSubmit('submitAddfme_blog_postsAndStay')) {
            Db::getInstance()->execute('DELETE
            FROM `'._DB_PREFIX_.'fme_blog_products`
            WHERE `id_post` = '.(int)$id);
            $pids = Tools::getValue('pids');
            if (!empty($pids)) {
                foreach ($pids as $product_id) {
                    Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'fme_blog_products`
                    (id_post, id_product) VALUES ('.(int)$id.', '.(int)$product_id.')');
                }
            }
        }
        $catids = Tools::getValue('catIds');
        if (!empty($catids)) {
            Db::getInstance()->execute('DELETE
              FROM `'._DB_PREFIX_.'fme_blog_post_cat`
              WHERE `id_post` = '.(int)$id);

            foreach ($catids as $cats_id) {
                BlogPosts::associateCategory($id, $cats_id);
            }
        }
        $authid=Tools::getValue('author');
        if ($authid != 0) {
            Db::getInstance()->delete('fme_blog_post_auth', 'id_post='.(int)$id);
            Db::getInstance()->insert('fme_blog_post_auth', array(
                'id_post' => (int)$id,
                'id_auth' => (int)$authid,
            ));
        }

        $post_ids = Tools::getValue('postIds');
        if (!empty($post_ids)) {
            Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'fme_blog_post_related`
                WHERE `id_post` = '.(int)$id);

            foreach ($post_ids as $related_id) {
                Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'fme_blog_post_related`
                    (id_post, related_post_id) VALUES ("'.(int)$id.'", "'.(int)$related_id.'")');
            }
        }

        if (Tools::isSubmit('enable_comments'.$this->table) && Tools::getIsset('id_post')) {
            if (Validate::isLoadedObject($post = new BlogPosts((int)Tools::getValue('id_post')))) {
                $post->enable_comments = !$post->enable_comments;
                if (!$post->update()) {
                    $this->errors[] = $this->l('Error:Comment Status not update.');
                } else {
                    $this->confirmations[] = $this->l('Comment status updated successfully.');
                }
            }
        }

        if (Tools::isSubmit('submitAddfme_blog_posts') || Tools::isSubmit('submitAddfme_blog_postsAndStay')) {
            // processing images data
            $media = Tools::getValue('media');
            if (!empty($media)) {
                Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'fme_blog_images`
                    WHERE `id_post` = '.(int)$id);

                $media_array = Tools::getValue('media');
                //Insert new data
                foreach ($media_array as $value) {
                    if (!empty($value['exclude'])) {
                        $active = 0;
                    } else {
                        $active = 1;
                    }

                    if (!empty($value['featured'])) {
                        $featured = 1;
                    } else {
                        $featured = 0;
                    }

                    if (!empty($value['img_name'])) {
                        Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'fme_blog_images` (
                            id_post,
                            id_file,
                            img_name,
                            img_thumb,
                            img_link,
                            img_label,
                            img_path,
                            active,
                            featured,
                            img_sort_order
                            )
                        VALUES
                        (
                            "'.(int)$id.'",
                            "'.(int)$value['id_file'].'",
                            "'.pSQL($value['img_name']).'",
                            "'.pSQL($value['img_thumb']).'",
                            "'.pSQL($value['link']).'",
                            "'.pSQL($value['title']).'",
                            "'.pSQL($value['img_path']).'",
                            "'.(int)$active.'",
                            "'.(int)$featured.'",
                            "'.(int)$value['position'].'"
                            )
                        ');
                    }
                }
            } elseif (empty($media)) {
                Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'fme_blog_images`
                    WHERE `id_post` = '.(int)$id);
            }

            // processing videos data
            $videos = Tools::getValue('video');
            if (isset($videos) && $videos) {
                //Insert new data
                foreach ($videos as $id_video => $video) {
                    if (!empty($video['title'])) {
                        Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'fme_blog_videos`
                            set video_label = "'.pSQL($video['title']).'"
                            WHERE id_video = '.(int)$id_video.'
                            AND id_post = '.(int)$id);
                    }
                }
            }

            // shop association
            $shops = Tools::getValue('checkBoxShopAsso_fme_blog_posts');
            if ($shops) {
                $id_blogpost = explode('&', $this->redirect_after);
                $ids = explode('=', $id_blogpost[1]);
                foreach ($shops as $shop) {
                    $all = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'fme_blog_posts_shop`');
                    foreach ($all as $rec) {
                        if ($rec['id_post'] == (int)$ids[1] && $rec['id_shop'] == (int)$shop) {
                            Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'fme_blog_posts_shop`
                            WHERE id_post = '.(int)$rec['id_post']);
                        }
                    }
                    Db::getInstance()->execute('
                    INSERT INTO `'._DB_PREFIX_.'fme_blog_posts_shop` (id_post, id_shop)
                    VALUES ("'.(int)$ids[1].'", "'.(int)$shop.'")');
                }
            } else {
                $id_blogpost = explode('&', $this->redirect_after);
                if (isset($id_blogpost) && isset($id_blogpost[1])) {
                    $ids = explode('=', $id_blogpost[1]);
                    $shop_default = $this->context->shop->id;

                    Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'fme_blog_posts_shop`
                        WHERE id_post = '.(int)$ids[1]);
                    Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'fme_blog_posts_shop` (id_post, id_shop)
                        VALUES ("'.(int)$ids[1].'", "'.(int)$shop_default.'")');
                }
            }
        }
        ////for ajax search products
        if ($action == 'getSearchProducts') {
            $this->getSearchProducts();
            die();
        }
                ////for ajax adding authors
        if ($action == 'addauthor') {
            $this->addAuthor();
            die(json_encode($this->getLatestAddAuth()));
        }
    }

    public function addAuthor()
    {
        $auth_name= Tools::getValue('author_name');
        Db::getInstance()->insert('fme_blog_authors', array(
            'name'      => pSQL($auth_name),
        ));
    }

    public function getLatestAddAuth()
    {
        $sql = new DbQuery();
        $sql->select('*');
        $sql->from('fme_blog_authors', 'ba');
        $sql->orderby('ba.id_author desc');
        return Db::getInstance()->getRow($sql);
    }

    public function getAllAuthors()
    {
        $sql = new DbQuery();
        $sql->select('*');
        $sql->from('fme_blog_authors', 'ba');
        $sql->orderby('ba.id_author desc');
        return Db::getInstance()->executeS($sql);
    }

    public function getAuth($id)
    {
        $sql = new DbQuery();
        $sql->select('ba.id_auth');
        $sql->from('fme_blog_post_auth', 'ba');
        $sql->where('ba.id_post='.(int)$id);
        return Db::getInstance()->getValue($sql);
    }
    
    protected function getSearchProducts()
    {
        $query = Tools::getValue('q', false);
        if (!$query || $query == '' || Tools::strlen($query) < 1) {
            die(json_encode($this->l('Found Nothing.')));
        }

        /*
         * In the SQL request the "q" param is used entirely to match result in database.
         * In this way if string:"(ref : #ref_pattern#)" is displayed on the return list,
         * they are no return values just because string:"(ref : #ref_pattern#)"
         * is not write in the name field of the product.
         * So the ref pattern will be cut for the search request.
         */
        if ($pos = strpos($query, ' (ref:')) {
            $query = Tools::substr($query, 0, $pos);
        }

        $excludeIds = Tools::getValue('excludeIds', false);
        if ($excludeIds && $excludeIds != 'NaN') {
            $excludeIds = implode(',', array_map('intval', explode(',', $excludeIds)));
        } else {
            $excludeIds = '';
        }

        // Excluding downloadable products from packs because download from pack is not supported
        $forceJson = Tools::getValue('forceJson', false);
        $disableCombination = Tools::getValue('disableCombination', false);
        $excludeVirtuals = (bool)Tools::getValue('excludeVirtuals', true);
        $exclude_packs = (bool)Tools::getValue('exclude_packs', true);

        $context = Context::getContext();

        $sql = 'SELECT p.`id_product`, pl.`link_rewrite`, p.`reference`, pl.`name`, image_shop.`id_image` id_image, il.`legend`, p.`cache_default_attribute`
                FROM `'._DB_PREFIX_.'product` p
                '.Shop::addSqlAssociation('product', 'p').'
                LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product = p.id_product AND pl.id_lang = '.(int)$context->language->id.Shop::addSqlRestrictionOnLang('pl').')
                LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop
                    ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.')
                LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$context->language->id.')
                WHERE (pl.name LIKE \'%'.pSQL($query).'%\' OR p.reference LIKE \'%'.pSQL($query).'%\')'.
                (!empty($excludeIds) ? ' AND p.id_product NOT IN ('.$excludeIds.') ' : ' ').
                ($excludeVirtuals ? 'AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'product_download` pd WHERE (pd.id_product = p.id_product))' : '').
                ($exclude_packs ? 'AND (p.cache_is_pack IS NULL OR p.cache_is_pack = 0)' : '').
                ' GROUP BY p.id_product';

        $items = Db::getInstance()->executeS($sql);
        if ($items && ($disableCombination ||$excludeIds)) {
            $results = array();
            foreach ($items as $item) {
                if (!$forceJson) {
                    $item['name'] = str_replace('|', '&#124;', $item['name']);
                    $results[] = trim($item['name']).(!empty($item['reference']) ? ' (ref: '.$item['reference'].')' : '').'|'.(int)$item['id_product'];
                } else {
                    $cover = Product::getCover($item['id_product']);
                    $results[] = array(
                        'id' => $item['id_product'],
                        'name' => $item['name'].(!empty($item['reference']) ? ' (ref: '.$item['reference'].')' : ''),
                        'ref' => (!empty($item['reference']) ? $item['reference'] : ''),
                        'image' => str_replace('http://', Tools::getShopProtocol(), $context->link->getImageLink($item['link_rewrite'], (($item['id_image'])?$item['id_image']:$cover['id_image']), $this->getFormatedName('home'))),
                    );
                }
            }

            if (!$forceJson) {
                echo implode("\n", $results);
            } else {
                echo json_encode($results);
            }
        } elseif ($items) {
            // packs
            $results = array();
            foreach ($items as $item) {
                // check if product have combination
                if (Combination::isFeatureActive() && $item['cache_default_attribute']) {
                    $sql = 'SELECT pa.`id_product_attribute`, pa.`reference`, ag.`id_attribute_group`, pai.`id_image`, agl.`name` AS group_name, al.`name` AS attribute_name,
                                a.`id_attribute`
                            FROM `'._DB_PREFIX_.'product_attribute` pa
                            '.Shop::addSqlAssociation('product_attribute', 'pa').'
                            LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
                            LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
                            LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
                            LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$context->language->id.')
                            LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$context->language->id.')
                            LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` pai ON pai.`id_product_attribute` = pa.`id_product_attribute`
                            WHERE pa.`id_product` = '.(int)$item['id_product'].'
                            GROUP BY pa.`id_product_attribute`, ag.`id_attribute_group`
                            ORDER BY pa.`id_product_attribute`';

                    $combinations = Db::getInstance()->executeS($sql);
                    if (!empty($combinations)) {
                        foreach ($combinations as $combination) {
                            $cover = Product::getCover($item['id_product']);
                            $results[$combination['id_product_attribute']]['id'] = $item['id_product'];
                            $results[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute'];
                            !empty($results[$combination['id_product_attribute']]['name']) ? $results[$combination['id_product_attribute']]['name'] .= ' '.$combination['group_name'].'-'.$combination['attribute_name']
                            : $results[$combination['id_product_attribute']]['name'] = $item['name'].' '.$combination['group_name'].'-'.$combination['attribute_name'];
                            if (!empty($combination['reference'])) {
                                $results[$combination['id_product_attribute']]['ref'] = $combination['reference'];
                            } else {
                                $results[$combination['id_product_attribute']]['ref'] = !empty($item['reference']) ? $item['reference'] : '';
                            }
                            if (empty($results[$combination['id_product_attribute']]['image'])) {
                                $results[$combination['id_product_attribute']]['image'] = str_replace('http://', Tools::getShopProtocol(), $context->link->getImageLink($item['link_rewrite'], (($combination['id_image'])?$combination['id_image']:$cover['id_image']), $this->getFormatedName('home')));
                            }
                        }
                    } else {
                        $results[] = array(
                            'id' => $item['id_product'],
                            'name' => $item['name'],
                            'ref' => (!empty($item['reference']) ? $item['reference'] : ''),
                            'image' => str_replace('http://', Tools::getShopProtocol(), $context->link->getImageLink($item['link_rewrite'], $item['id_image'], $this->getFormatedName('home'))),
                        );
                    }
                } else {
                    $results[] = array(
                        'id' => $item['id_product'],
                        'name' => $item['name'],
                        'ref' => (!empty($item['reference']) ? $item['reference'] : ''),
                        'image' => str_replace('http://', Tools::getShopProtocol(), $context->link->getImageLink($item['link_rewrite'], $item['id_image'], $this->getFormatedName('home'))),
                    );
                }
            }
            echo json_encode(array_values($results));
        } else {
            echo json_encode(array());
        }
    }
    
    public function getFormatedName($name)
    {
        $theme_name = Context::getContext()->shop->theme_name;
        $name_without_theme_name = str_replace(array('_'.$theme_name, $theme_name.'_'), '', $name);
        //check if the theme name is already in $name if yes only return $name
        if (strstr($name, $theme_name) && ImageType::getByNameNType($name, 'products')) {
            return $name;
        } elseif (ImageType::getByNameNType($name_without_theme_name.'_'.$theme_name, 'products')) {
            return $name_without_theme_name.'_'.$theme_name;
        } elseif (ImageType::getByNameNType($theme_name.'_'.$name_without_theme_name, 'products')) {
            return $theme_name.'_'.$name_without_theme_name;
        } else {
            return $name_without_theme_name.'_default';
        }
    }

    public function setMedia()
    {
        parent::setMedia();
        $this->addJqueryUI(array('ui.widget', 'ui.datepicker'));
        $this->addJqueryPlugin(array('tagify', 'fancybox'));
        //Add CSS
        $this->addCSS(__PS_BASE_URI__.'modules/advanceblog/views/css/jquery-ui-1.9.2.custom.css', 'screen');
        $this->addCSS(__PS_BASE_URI__.'modules/advanceblog/views/css/fmmblog.css', 'screen');
        $this->addCSS(__PS_BASE_URI__.'modules/advanceblog/views/css/fme_page.css', 'screen');
        $this->addCSS(__PS_BASE_URI__.'modules/advanceblog/views/css/fme_table_jui.css', 'screen');
        $this->addCSS(__PS_BASE_URI__.'modules/advanceblog/views/css/ColVis.css', 'screen');
        $this->addCSS(__PS_BASE_URI__.'modules/advanceblog/views/css/mediaelementplayer.min.css', 'screen');

        //Add JS
        $this->addJS(__PS_BASE_URI__.'modules/advanceblog/views/js/jquery.accordion.js');
        $this->addJS(__PS_BASE_URI__.'modules/advanceblog/views/js/jquery.cookie.min.js');
        $this->addJS(__PS_BASE_URI__.'modules/advanceblog/views/js/uploader/plupload.full.js');
        $this->addJS(__PS_BASE_URI__.'modules/advanceblog/views/js/jquery.dataTables.js');
        $this->addJS(__PS_BASE_URI__.'modules/advanceblog/views/js/ColVis.js');
        $this->addJS(__PS_BASE_URI__.'modules/advanceblog/views/js/jquery.word-and-character-counter.js');
        $this->addJs(__PS_BASE_URI__.'modules/advanceblog/views/js/mediaelement-and-player.min.js');
    }
}

 

Share this post


Link to post
Share on other sites

Merhaba,

Büyük İhtimalle ;

> ] } gibi Parametlerden Birisi Kapalı Ve Senin Eklediğin Kod Bu Döngünün İçersine Giriyor. Kodu eklediğin kısmı incelermisin, bu bahsettiğim syntaxlar var mı?

 

Teşekkürler

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More