Microweber\Utils\Import::save_content_item PHP Метод

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

public save_content_item ( $content )
    public function save_content_item($content)
    {
        if (!isset($content['title']) or $content['title'] == false) {
            return;
        }
        $orig = $content;
        $this->app->media_manager->download_remote_images = true;
        if (isset($content['content_type']) and $content['content_type'] == 'category') {
            unset($content['content_type']);
            if (isset($content['title']) and is_string($content['title'])) {
                $category_set_item = $content['title'];
                $category_set_item = trim($category_set_item);
                $possible_slug = $this->app->url_manager->slug($category_set_item);
                $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&url=' . $possible_slug);
                if (!isset($cat_item['id'])) {
                    $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&title=' . $category_set_item);
                }
                if (!isset($cat_item['id'])) {
                    $new = $content;
                    $new['rel_type'] = 'content';
                    $new['title'] = $category_set_item;
                    // parent_category_title
                    $new_cat = $this->app->category_manager->save($new);
                    $cat_item = $this->app->category_manager->get_by_id($new_cat);
                }
                if (isset($cat_item['id'])) {
                    if (isset($content['parent'])) {
                        unset($content['parent']);
                    }
                    $new = $content;
                    $new['id'] = $cat_item['id'];
                    //  \Log::info(print_r($new, true));
                    //  dd($new);
                    return $this->app->category_manager->save($new);
                }
            }
            //return save_category($content);
        } else {
            // make categories
            if (isset($content['categories']) and is_string($content['categories'])) {
                $category_sets = explode(',', $content['categories']);
                $cats_ids = array();
                foreach ($category_sets as $category_set) {
                    if (is_string($category_set)) {
                        $category_set_items = explode('/', $category_set);
                        $nest_level = 0;
                        $prev_parent_cat = 0;
                        foreach ($category_set_items as $category_set_item) {
                            $category_set_item = trim($category_set_item);
                            if ($category_set_item == false) {
                                //  dd($category_set_items,$category_set,$content);
                            }
                            if ($category_set_item != false) {
                                $possible_slug = $this->app->url_manager->slug($category_set_item);
                                // \Log::info('------'.print_r($category_set_item, true));
                                $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&url=' . $possible_slug);
                                // \Log::info('000000----'.print_r($cat_item, true));
                                if (!isset($cat_item['id'])) {
                                    //    \Log::info('111000000----'.print_r($cat_item, true));
                                    $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&title=' . $category_set_item);
                                }
                                //  $cat_item = $this->app->category_manager->get('no_cache=true&single=true&rel_type=content&title=' . $category_set_item);
                                // dd($category_set_items,$category_set_item);
                                //if (!isset($cat_item['id'])) {
                                $new = array();
                                if (isset($cat_item['id'])) {
                                    $new['id'] = $cat_item['id'];
                                }
                                $new['rel_type'] = 'content';
                                $new['title'] = $category_set_item;
                                if (isset($content['parent']) and $nest_level == 0) {
                                    $new['parent_page'] = $content['parent'];
                                }
                                if ($nest_level > 0 and $prev_parent_cat) {
                                    $new['parent_id'] = $prev_parent_cat;
                                }
                                // d($category_set_items);
                                //   \Log::info(print_r($new, true));
                                $new_cat = $this->app->category_manager->save($new);
                                //    \Log::info(print_r($new_cat, true));
                                $cat_item = $this->app->category_manager->get_by_id($new_cat);
                                //  }
                                if (isset($cat_item['id'])) {
                                    $prev_parent_cat = $cat_item['id'];
                                    $cats_ids[] = $cat_item['id'];
                                }
                                ++$nest_level;
                            }
                        }
                    }
                }
                if (!empty($cats_ids)) {
                    // \Log::info(print_r($orig, true));
                    $content['categories'] = $cats_ids;
                }
            }
            // dd($content);
            if (isset($content['images']) and is_string($content['images'])) {
                $content['images'] = explode(',', $content['images']);
                $content['images'] = array_unique($content['images']);
            }
            $is_saved = get_content('no_cache=true&one=true&title=' . $content['title']);
            if (isset($content['description']) and (!isset($content['content']) or $content['content'] == false)) {
                //$content['content'] = $content['description'];
            }
            if (isset($content['parent'])) {
                $par = get_content_by_id($content['parent']);
                if ($par != false) {
                    if (isset($par['is_shop']) and $par['is_shop'] == 1) {
                        $content['content_type'] = 'product';
                        $content['subtype'] = 'product';
                    }
                }
            }
            if (!isset($content['content_type'])) {
                $content['content_type'] = 'post';
            }
            if (!isset($content['subtype'])) {
                $content['subtype'] = 'post';
            }
            // $content['subtype'] = 'post';
            $content['is_active'] = 1;
            if (isset($content['debug'])) {
                unset($content['debug']);
            }
            //  $content['debug'] = 'y';
            $content['download_remote_images'] = true;
            if ($is_saved != false) {
                $content['id'] = $is_saved['id'];
                if (!isset($content['content_type'])) {
                    $content['content_type'] = $is_saved['content_type'];
                    $content['subtype'] = $is_saved['subtype'];
                }
            }
            //            \Log::info('----------------   ================   ----------------');
            //            \Log::info('----------------   SAVING CONTENT   ----------------');
            //            \Log::info('----------------   ================   ----------------');
            //
            //
            //
            //
            //            \Log::info(print_r($content, true));
            return save_content($content);
        }
    }