content\controllers\Edit::index PHP Метод

index() публичный Метод

public index ( $params )
    function index($params)
    {
        if (is_admin() == false) {
            return;
        }
        if (isset($params['content_type']) and $params['content_type'] == 'category') {
            print load_module('categories/edit_category', $params);
            return;
        }
        $data = false;
        $just_saved = false;
        $is_new_content = false;
        $is_current = false;
        $is_live_edit = false;
        if (!isset($is_quick)) {
            $is_quick = false;
        }
        //	if (isset($params['is_shop'])) {
        //            if (trim($params['is_shop']) == 'y') {
        //				$params['is_shop'] = 1;
        //			} else if (trim($params['is_shop']) == 'n') {
        //				$params['is_shop'] = 0;
        //			}
        //        }
        if (isset($params['live_edit'])) {
            $is_live_edit = $params['live_edit'];
        } elseif (isset($params['from_live_edit'])) {
            $is_live_edit = $params['from_live_edit'];
        }
        if (isset($params['quick_edit'])) {
            $is_quick = $params['quick_edit'];
        }
        if ($is_live_edit == true) {
            $is_quick = false;
        }
        if (isset($params['just-saved'])) {
            $just_saved = $params['just-saved'];
        }
        if (isset($params['is-current'])) {
            $is_current = $params['is-current'];
        }
        if (isset($params['page-id'])) {
            $data = $this->app->content_manager->get_by_id(intval($params["page-id"]));
        }
        if (isset($params['content-id'])) {
            $data = $this->app->content_manager->get_by_id(intval($params["content-id"]));
        }
        $recommended_parent = false;
        if (isset($params['recommended_parent']) and $params['recommended_parent'] != false) {
            $recommended_parent = $params['recommended_parent'];
        } elseif (isset($params['parent']) and $params['parent'] != false) {
            $recommended_parent = $params['parent'];
        }
        // dd($params);
        $categories_active_ids = false;
        $title_placeholder = false;
        if (isset($params['category']) and $params['category'] != false) {
            $categories_active_ids = $params['category'];
        } elseif (isset($params['selected-category-id']) and $params['selected-category-id'] != false) {
            $categories_active_ids = $params['selected-category-id'];
        }
        /* FILLING UP EMPTY CONTENT WITH DATA */
        if ($data == false or empty($data)) {
            $is_new_content = true;
            $data = $this->empty_data;
            if (isset($params['content_type'])) {
                $data['content_type'] = $params['content_type'];
            }
            if (isset($params['subtype'])) {
                $data['subtype'] = $params['subtype'];
                if ($data['subtype'] == 'post') {
                    $data['content_type'] = 'post';
                }
            }
            if (isset($data['content_type']) and $data['content_type'] == 'post' and $data['subtype'] == 'static') {
                $data['subtype'] = 'post';
            } else {
                if (isset($data['content_type']) and $data['content_type'] == 'product' and $data['subtype'] == 'static') {
                    $data['content_type'] = 'product';
                    $data['subtype'] = 'product';
                }
            }
        }
        if (isset($params['add-to-menu'])) {
            $data['add_to_menu'] = $params["add-to-menu"];
        }
        /* END OF FILLING UP EMPTY CONTENT  */
        /* SETTING PARENT AND ACTIVE CATEGORY */
        $forced_parent = false;
        if (intval($data['id']) == 0 and intval($data['parent']) == 0 and isset($params['parent-category-id']) and $params['parent-category-id'] != 0 and !isset($params['parent-page-id'])) {
            $cat_page = get_page_for_category($params['parent-category-id']);
            if (is_array($cat_page) and isset($cat_page['id'])) {
                $forced_parent = $params['parent-page-id'] = $cat_page['id'];
            }
        }
        if (intval($data['id']) == 0 and intval($data['parent']) == 0 and isset($params['parent-page-id'])) {
            $data['parent'] = $params['parent-page-id'];
            if (isset($params['content_type']) and $params['content_type'] == 'product') {
                $parent_content = $this->app->content_manager->get_by_id($params['parent-page-id']);
                // if(!isset($parent_content['is_shop']) or $parent_content['is_shop'] != 1){
                // $data['parent'] = 0;
                // }
            }
            if (isset($params['parent-category-id']) and $params['parent-category-id'] != 0) {
                $categories_active_ids = $params['parent-category-id'];
            }
        } else {
            if (intval($data['id']) != 0) {
                $categories = $this->app->category_manager->get_for_content($data['id']);
                if (is_array($categories)) {
                    $c = array();
                    foreach ($categories as $category) {
                        $c[] = $category['id'];
                    }
                    $categories_active_ids = implode(',', $c);
                }
            }
        }
        /* END OF SETTING PARENT AND ACTIVE CATEGORY  */
        if ($recommended_parent != false and $data['parent'] == 0) {
            $data['parent'] = $recommended_parent;
        }
        /* SETTING PARENT AND CREATING DEFAULT BLOG OR SHOP IF THEY DONT EXIST */
        if ($recommended_parent != false and intval($data['id']) == 0) {
            if (isset($data['subtype']) and $data['subtype'] == 'post') {
                if (isset($data['is_shop']) and $data['is_shop'] == 0) {
                    $parent_content = $this->app->content_manager->get_by_id($recommended_parent);
                    if (isset($parent_content['is_shop']) and $parent_content['is_shop'] == 1) {
                        $parent_content_params = array();
                        $parent_content_params['subtype'] = 'dynamic';
                        $parent_content_params['content_type'] = 'page';
                        $parent_content_params['limit'] = 1;
                        $parent_content_params['one'] = 1;
                        $parent_content_params['fields'] = 'id';
                        $parent_content_params['order_by'] = 'posted_at desc, updated_at desc';
                        $parent_content_params['is_shop'] = 0;
                        $parent_content = $this->app->content_manager->get($parent_content_params);
                        if (isset($parent_content['id']) and $parent_content['id'] != 0) {
                            $data['parent'] = $recommended_parent = $parent_content['id'];
                            $categories_active_ids = false;
                        }
                    }
                }
            } elseif (isset($data['subtype']) and $data['subtype'] == 'product') {
                if (isset($data['is_shop']) and $data['is_shop'] == 0) {
                    $parent_content = $this->app->content_manager->get_by_id($recommended_parent);
                    if (isset($parent_content['is_shop']) and $parent_content['is_shop'] == 0) {
                        $parent_content_params = array();
                        $parent_content_params['subtype'] = 'dynamic';
                        $parent_content_params['content_type'] = 'page';
                        $parent_content_params['limit'] = 1;
                        $parent_content_params['one'] = 1;
                        $parent_content_params['is_shop'] = 1;
                        $parent_content_params['fields'] = 'id';
                        $parent_content_params['order_by'] = 'posted_at desc, updated_at desc';
                        $parent_content = $this->app->content_manager->get($parent_content_params);
                        if (isset($parent_content['id']) and $parent_content['id'] != 0) {
                            $data['parent'] = $recommended_parent = $parent_content['id'];
                            $categories_active_ids = false;
                        }
                    }
                }
            }
        }
        if ($recommended_parent == false and intval($data['id']) == 0 and intval($data['parent']) == 0) {
            $parent_content_params = array();
            $parent_content_params['subtype'] = 'dynamic';
            $parent_content_params['content_type'] = 'page';
            $parent_content_params['limit'] = 1;
            $parent_content_params['one'] = 1;
            $parent_content_params['parent'] = 0;
            $parent_content_params['fields'] = 'id';
            $parent_content_params['order_by'] = 'posted_at desc, updated_at desc';
            if (isset($params['subtype']) and $params['subtype'] == 'post') {
                $parent_content_params['is_shop'] = 0;
                $parent_content_params['is_home'] = 0;
                $parent_content = $this->app->content_manager->get($parent_content_params);
                if (!isset($parent_content['id'])) {
                    unset($parent_content_params['parent']);
                    $parent_content = $this->app->content_manager->get($parent_content_params);
                }
                if (isset($parent_content['id'])) {
                    $data['parent'] = $parent_content['id'];
                } else {
                    $this->app->content_manager_helpers->create_default_content('blog');
                    $parent_content_params['no_cache'] = true;
                    $parent_content = $this->app->content_manager->get($parent_content_params);
                }
            } elseif (isset($params['subtype']) and $params['content_type'] == 'product') {
                $parent_content_params['is_shop'] = 1;
                $parent_content = $this->app->content_manager->get($parent_content_params);
                if (isset($parent_content['id'])) {
                    $data['parent'] = $parent_content['id'];
                } else {
                    $this->app->content_manager_helpers->create_default_content('shop');
                    $parent_content_params['no_cache'] = true;
                    $parent_content = $this->app->content_manager->get($parent_content_params);
                }
            }
            if (isset($parent_content) and isset($parent_content['id'])) {
                $data['parent'] = $parent_content['id'];
            }
        } elseif ($forced_parent == false and (intval($data['id']) == 0 and intval($data['parent']) != 0) and isset($data['subtype']) and $data['content_type'] == 'product') {
            //if we are adding product in a page that is not a shop
            $parent_shop_check = $this->app->content_manager->get_by_id($data['parent']);
            if (!isset($parent_shop_check['is_shop']) or $parent_shop_check['is_shop'] != 1) {
                $parent_content_shop = $this->app->content_manager->get('content_type=page&order_by=updated_at desc&one=true&is_shop=0');
                if (isset($parent_content_shop['id'])) {
                    $data['parent'] = $parent_content_shop['id'];
                }
            }
        } elseif ($forced_parent == false and (intval($data['id']) == 0 and intval($data['parent']) != 0) and isset($data['subtype']) and $data['subtype'] == 'post') {
            $parent_shop_check = $this->app->content_manager->get_by_id($data['parent']);
            if (!isset($parent_shop_check['content_type']) or $parent_shop_check['content_type'] != 'page') {
                $parent_content_shop = $this->app->content_manager->get('order_by=updated_at desc&one=true&content_type=page&subtype=dynamic&is_shop=1');
                if (isset($parent_content_shop['id'])) {
                    $data['parent'] = $parent_content_shop['id'];
                }
            }
        }
        /* END OF SETTING PARENT AND CREATING DEFAULT BLOG OR SHOP IF THEY DONT EXIST */
        $module_id = $params['id'];
        $post_list_view = $this->views_dir . 'edit.php';
        $this->app->event_manager->trigger('module.content.edit.main', $data);
        //d($params);
        //d($data['content_type']);
        //d($data);
        $view = new View($post_list_view);
        $view->assign('params', $params);
        $view->assign('module_id', $module_id);
        $view->assign('just_saved', $just_saved);
        $view->assign('is_new_content', $is_new_content);
        $view->assign('is_current', $is_current);
        $view->assign('is_live_edit', $is_live_edit);
        $view->assign('recommended_parent', $recommended_parent);
        $view->assign('categories_active_ids', $categories_active_ids);
        $view->assign('title_placeholder', $title_placeholder);
        $view->assign('rand', rand());
        $view->assign('data', $data);
        $view->assign('is_quick', $is_quick);
        return $view->display();
    }

Usage Example

Пример #1
0
 function index($params)
 {
     if (isset($params['manage_categories'])) {
         print load_module('categories/manage', $params);
         return;
     }
     if (isset($params['is_shop']) and $params['is_shop'] == 'y') {
         $params['is_shop'] = 1;
     } else {
         if (isset($params['is_shop']) and $params['is_shop'] == 'n') {
             $params['is_shop'] = 0;
         }
     }
     $no_page_edit = false;
     $posts_mod = array();
     // $posts_mod['type'] = 'content/admin_posts_list';
     if (isset($params['data-page-id'])) {
         $posts_mod['page-id'] = $params['data-page-id'];
     }
     if (isset($params['no_page_edit'])) {
         $no_page_edit = $params['no_page_edit'];
     }
     if (isset($params['keyword'])) {
         $posts_mod['search_by_keyword'] = $params['keyword'];
     }
     if (isset($params['content_type']) and $params['content_type'] != false) {
         $posts_mod['content_type'] = $params['content_type'];
     }
     if (isset($params['subtype']) and $params['subtype'] != false) {
         $posts_mod['subtype'] = $params['subtype'];
     }
     if (isset($params['is_shop']) and $params['is_shop'] == 1) {
         $posts_mod['content_type'] = 'product';
     } else {
         if (isset($params['is_shop']) and $params['is_shop'] == 0) {
             $posts_mod['subtype'] = 'post';
         }
     }
     if (isset($params['content_type']) and $params['content_type'] == 'product') {
         $posts_mod['content_type'] = 'product';
         // $posts_mod['content_type'] = 'post';
     }
     if (isset($params['content_type']) and $params['content_type'] == 'post') {
         if (!isset($params['subtype']) or $params['subtype'] == false) {
             //	$posts_mod['subtype'] = 'post';
         }
     }
     if (isset($params['content_type_filter']) and $params['content_type_filter'] != '') {
         $posts_mod['content_type'] = $params['content_type_filter'];
     }
     if (isset($params['subtype_filter']) and $params['subtype_filter'] != '') {
         $posts_mod['subtype'] = $params['subtype_filter'];
     }
     if (!isset($params['category-id']) and isset($params['page-id']) and $params['page-id'] != 'global') {
         $check_if_exist = $this->provider->get_by_id($params['page-id']);
         if (is_array($check_if_exist)) {
             if (isset($check_if_exist['is_shop']) and trim($check_if_exist['is_shop']) == 1) {
                 //  $posts_mod['subtype'] = 'product';
             }
         }
     }
     $page_info = false;
     if (isset($params['page-id'])) {
         if ($params['page-id'] == 'global') {
             if (isset($params['is_shop']) and $params['is_shop'] == 1) {
                 $page_info = $this->provider->get('limit=1&one=1&content_type=page&is_shop=0');
             }
         } else {
             $page_info = $this->provider->get_by_id($params['page-id']);
             if (isset($page_info['is_shop']) and trim($page_info['is_shop']) == 1) {
                 //  $posts_mod['subtype'] = 'product';
             }
         }
     }
     if (isset($params['category-id']) and $params['category-id'] != 'global') {
         $check_if_exist = $this->category_provider->get_page($params['category-id']);
         if (is_array($check_if_exist)) {
             $page_info = $check_if_exist;
             if (isset($check_if_exist['is_shop']) and trim($check_if_exist['is_shop']) == 1) {
                 $posts_mod['content_type'] = 'product';
             } else {
                 // $posts_mod['subtype'] = $check_if_exist['subtype'];
             }
         }
     }
     $posts_mod['paging_param'] = 'pg';
     $posts_mod['orderby'] = 'position desc';
     if (isset($posts_mod['page-id'])) {
         $posts_mod['parent'] = $posts_mod['page-id'];
     }
     if (isset($params['pg'])) {
         $posts_mod['pg'] = $params['pg'];
     }
     if (isset($params['data-category-id'])) {
         $posts_mod['category'] = $params['data-category-id'];
     } else {
         if (isset($params['parent-category-id'])) {
             $posts_mod['category'] = $params['parent-category-id'];
         } elseif (isset($params['category-id'])) {
             $posts_mod['category'] = $params['category-id'];
         }
     }
     if (isset($params[$posts_mod['paging_param']])) {
         $posts_mod['page'] = $params[$posts_mod['paging_param']];
     }
     $keyword = false;
     if (isset($posts_mod['search_by_keyword'])) {
         $keyword = strip_tags($posts_mod['search_by_keyword']);
     }
     if (isset($params['parent-page-id'])) {
         $posts_mod['parent'] = intval($params['parent-page-id']);
     }
     $data = $this->provider->get($posts_mod);
     if (empty($data) and isset($posts_mod['page'])) {
         if (isset($posts_mod['paging_param'])) {
             $posts_mod[$posts_mod['paging_param']] = 1;
         }
         unset($posts_mod['page']);
         $data = $this->provider->get($posts_mod);
     }
     $post_params_paging = $posts_mod;
     $post_params_paging['page_count'] = true;
     $pages = $this->provider->get($post_params_paging);
     $this->event_manager->trigger('module.content.manager', $posts_mod);
     $post_toolbar_view = $this->views_dir . 'toolbar.php';
     $toolbar = new View($post_toolbar_view);
     $toolbar->assign('page_info', $page_info);
     $toolbar->assign('keyword', $keyword);
     $toolbar->assign('params', $params);
     $post_list_view = $this->views_dir . 'manager.php';
     if ($no_page_edit == false) {
         if ($data == false) {
             if (isset($posts_mod['category-id']) and isset($page_info['content_type']) and $page_info['content_type'] == 'page' and $page_info['subtype'] != 'static') {
                 if (isset($posts_mod['category-id']) and $posts_mod['category-id'] != 0) {
                 } else {
                     $manager = new Edit();
                     return $manager->index($params);
                 }
             } elseif (isset($page_info['content_type']) and $page_info['content_type'] == 'page' and isset($page_info['subtype']) and isset($page_info['id'])) {
                 if ($page_info['subtype'] != 'dynamic') {
                     $manager = new Edit();
                     return $manager->index($params);
                 }
             }
         }
     }
     $view = new View($post_list_view);
     $view->assign('params', $params);
     $view->assign('page_info', $page_info);
     $view->assign('toolbar', $toolbar);
     $view->assign('data', $data);
     $view->assign('pages', $pages);
     $view->assign('keyword', $keyword);
     $view->assign('post_params', $posts_mod);
     $view->assign('paging_param', $posts_mod['paging_param']);
     return $view->display();
 }