Пример #1
0
 public function editor_tools()
 {
     if (!defined('IN_ADMIN') and is_admin()) {
         define('IN_ADMIN', true);
     }
     if (!defined('IN_EDITOR_TOOLS')) {
         define('IN_EDITOR_TOOLS', true);
     }
     if (mw_is_installed() == true) {
         //event_trigger('mw_db_init');
         //  event_trigger('mw_cron');
     }
     $tool = $this->app->url_manager->segment(1);
     if ($tool) {
     } else {
         $tool = 'index';
     }
     $page = false;
     if (isset($_REQUEST['content_id'])) {
         if (intval($_REQUEST['content_id']) == 0) {
             $this->create_new_page = true;
             $custom_content_data_req = $_REQUEST;
             $custom_content_data = array();
             if (isset($custom_content_data_req['content_type'])) {
                 //    $custom_content_data['content_type'] = $custom_content_data_req['content_type'];
             }
             if (isset($custom_content_data_req['content_type'])) {
                 $custom_content_data['content_type'] = $custom_content_data_req['content_type'];
             }
             if (isset($custom_content_data_req['subtype'])) {
                 $custom_content_data['subtype'] = $custom_content_data_req['subtype'];
             }
             if (isset($custom_content_data_req['parent_page']) and is_numeric($custom_content_data_req['parent_page'])) {
                 $custom_content_data['parent'] = intval($custom_content_data_req['parent_page']);
             }
             if (isset($custom_content_data_req['preview_layout'])) {
                 //  $custom_content_data['preview_layout'] =($custom_content_data_req['preview_layout']);
             }
             if (!empty($custom_content_data)) {
                 $custom_content_data['id'] = 0;
                 $this->content_data = $custom_content_data;
             }
             $this->return_data = 1;
             $page = $this->frontend();
         } else {
             $page = $this->app->content_manager->get_by_id($_REQUEST['content_id']);
         }
     } elseif (isset($_SERVER['HTTP_REFERER'])) {
         $url = $_SERVER['HTTP_REFERER'];
         $url = explode('?', $url);
         $url = $url[0];
         if (trim($url) == '' or trim($url) == $this->app->url_manager->site()) {
             //$page = $this->app->content_manager->get_by_url($url);
             $page = $this->app->content_manager->homepage();
         } else {
             $page = $this->app->content_manager->get_by_url($url);
         }
     } else {
         $url = $this->app->url_manager->string();
     }
     if (!isset($page['active_site_template'])) {
         $page['active_site_template'] = 'default';
     }
     if (isset($_GET['preview_template'])) {
         $page['active_site_template'] = $_GET['preview_template'];
     }
     if (isset($_GET['content_type'])) {
         $page['content_type'] = $_GET['content_type'];
     }
     if (isset($_GET['preview_layout']) and $_GET['preview_layout'] != 'inherit') {
         $page['layout_file'] = $_GET['preview_layout'];
     }
     $this->app->content_manager->define_constants($page);
     $page['render_file'] = $this->app->template->get_layout($page);
     if (defined('TEMPLATE_DIR')) {
         $load_template_functions = TEMPLATE_DIR . 'functions.php';
         if (is_file($load_template_functions)) {
             include_once $load_template_functions;
         }
     }
     $params = $_REQUEST;
     $tool = str_replace('..', '', $tool);
     $p_index = mw_includes_path() . 'toolbar/editor_tools/index.php';
     $p_index = normalize_path($p_index, false);
     $standalone_edit = true;
     $p = mw_includes_path() . 'toolbar/editor_tools/' . $tool . '/index.php';
     $standalone_edit = false;
     if ($tool == 'plupload') {
         $standalone_edit = true;
     }
     if ($tool == 'plupload') {
         $standalone_edit = true;
     }
     if ($tool == 'imageeditor') {
         $standalone_edit = true;
     }
     if ($tool == 'rte_image_editor') {
         $standalone_edit = true;
     }
     if ($tool == 'editor_toolbar') {
         $standalone_edit = true;
     }
     if ($tool == 'wysiwyg') {
         $standalone_edit = false;
         $ed_file_from_template = TEMPLATE_DIR . 'editor.php';
         if (is_file($ed_file_from_template)) {
             $p_index = $ed_file_from_template;
         }
         if (isset($page['content_type']) and $page['content_type'] != 'post' and $page['content_type'] != 'page' and $page['content_type'] != 'product') {
             if (isset($page['subtype']) and ($page['subtype'] != 'post' and $page['subtype'] != 'product')) {
                 $standalone_edit = true;
             }
         } elseif (isset($page['content_type']) and $page['content_type'] == 'post') {
             if (isset($page['subtype']) and ($page['subtype'] != 'post' and $page['subtype'] != 'product')) {
                 $standalone_edit = true;
             }
         }
         if ($standalone_edit) {
             if (!isset($page['content'])) {
                 $page['content'] = '<div class="element"></div>';
             }
             $page['content'] = '<div class="edit" field="content" rel="content" contenteditable="true">' . $page['content'] . '</div>';
             $page['render_file'] = false;
         }
         //
         //  $page['content'] = '<div class="edit" field="content" rel="content" contenteditable="true">' . $page['content'] . '</div>';
     }
     $default_css = '';
     $apijs_settings_loaded = '';
     $apijs_loaded = '';
     $p = normalize_path($p, false);
     $l = new \Microweber\View($p_index);
     $l->params = $params;
     $layout = $l->__toString();
     $apijs_loaded = false;
     if ($layout != false) {
         //$apijs_loaded = $this->app->template->get_apijs_url() . '?id=' . CONTENT_ID;
         $apijs_loaded = $this->app->template->get_apijs_url();
         // $apijs_settings_loaded = $this->app->template->get_apijs_settings_url() . '?id=' . CONTENT_ID . '&category_id=' . CATEGORY_ID;
         $apijs_settings_loaded = $this->app->template->get_apijs_settings_url();
         // $is_admin = $this->app->user_manager->is_admin();
         $default_css = '<link rel="stylesheet" href="' . mw_includes_url() . 'default.css" type="text/css" />';
         $headers = event_trigger('site_header', TEMPLATE_NAME);
         $template_headers_append = '';
         $one = 1;
         if (is_array($headers)) {
             foreach ($headers as $modify) {
                 if ($modify != false and is_string($modify) and $modify != '') {
                     $template_headers_append = $template_headers_append . $modify;
                 }
             }
             if ($template_headers_append != false and $template_headers_append != '') {
                 $layout = str_ireplace('</head>', $template_headers_append . '</head>', $l, $one);
             }
         }
         if (function_exists('template_headers_src')) {
             $template_headers_src = template_headers_src();
             if ($template_headers_src != false and $template_headers_src != '') {
                 $layout = str_ireplace('</head>', $template_headers_src . '</head>', $l, $one);
             }
         }
         if (isset($page['active_site_template'])) {
             if ($page['active_site_template'] == '') {
                 $page['active_site_template'] = 'default';
             }
             if ($page['active_site_template'] == 'default') {
                 $active_site_template = $this->app->option_manager->get('current_template', 'template');
             } else {
                 $active_site_template = $page['active_site_template'];
                 if ($active_site_template == 'mw_default') {
                     $active_site_template = 'default';
                 }
             }
             $live_edit_css_folder = userfiles_path() . 'css' . DS . $active_site_template . DS;
             $custom_live_edit = $live_edit_css_folder . DS . 'live_edit.css';
             if (is_file($custom_live_edit)) {
                 $live_edit_url_folder = userfiles_url() . 'css/' . $active_site_template . '/';
                 $custom_live_editmtime = filemtime($custom_live_edit);
                 $liv_ed_css = '<link rel="stylesheet" href="' . $live_edit_url_folder . 'live_edit.css?version=' . $custom_live_editmtime . '" id="mw-template-settings" type="text/css" />';
                 $layout = str_ireplace('</head>', $liv_ed_css . '</head>', $l);
             }
         }
     }
     if (isset($_REQUEST['plain'])) {
         if (is_file($p)) {
             $p = new \Microweber\View($p);
             $p->params = $params;
             $layout = $p->__toString();
             echo $layout;
             return;
         }
     } elseif (is_file($p)) {
         $p = new \Microweber\View($p);
         $p->params = $params;
         $layout_tool = $p->__toString();
         $layout = str_replace('{content}', $layout_tool, $layout);
     } else {
         $layout = str_replace('{content}', 'Not found!', $layout);
     }
     $category = false;
     if (defined('CATEGORY_ID')) {
         $category = $this->app->category_manager->get_by_id(CATEGORY_ID);
     }
     //    $page['render_file'] = $render_file;
     if (!$standalone_edit) {
         if (isset($page['render_file'])) {
             event_trigger('mw.front', $page);
             $l = new \Microweber\View($page['render_file']);
             $l->page_id = PAGE_ID;
             $l->content_id = CONTENT_ID;
             $l->post_id = POST_ID;
             $l->category_id = CATEGORY_ID;
             $l->content = $page;
             $l->category = $category;
             $l->params = $params;
             $l->page = $page;
             $l->application = $this->app;
             $l = $l->__toString();
             //
             //
             //                $render_params = array();
             //                $render_params['render_file'] = $p;
             //                $render_params['page_id'] = PAGE_ID;
             //                $render_params['content_id'] = CONTENT_ID;
             //                $render_params['post_id'] = POST_ID;
             //                $render_params['category_id'] = CATEGORY_ID;
             //                $render_params['page'] = $page;
             //                $render_params['params'] = $params;
             //                $render_params['application'] = $this->app;
             //  $l = $this->app->template->render($render_params);
             if (is_object($l)) {
                 return $l;
             }
             $l = $this->app->parser->process($l, $options = false);
             //                if(isset($page['content']) and $page['content'] != false){
             //
             //                if($page['content'] == ''){
             //                    unset($page['content']);
             //                }
             //                } else {
             //                    $page['content'] = $l;
             //                }
             $editable = $this->app->parser->isolate_content_field($l, true);
             if ($editable != false) {
                 $page['content'] = $editable;
             } else {
                 if ($tool == 'wysiwyg') {
                     $err = 'no editable content region found';
                     if (isset($page['layout_file'])) {
                         $file = $page['layout_file'];
                         $file = str_replace('__', '/', $page['layout_file']);
                         $err = $err . ' in file ' . $file;
                     }
                     if (isset($page['active_site_template'])) {
                         $err = $err . ' (' . $page['active_site_template'] . ' template)';
                     }
                     return $err;
                 }
             }
         }
     }
     if (!stristr($layout, $apijs_loaded)) {
         $rep = 0;
         $default_css = $default_css . "\r\n" . '<script src="' . $apijs_settings_loaded . '"></script>' . "\r\n";
         $default_css = $default_css . "\r\n" . '<script src="' . $apijs_loaded . '"></script>' . "\r\n";
         $layout = str_ireplace('<head>', '<head>' . $default_css, $layout, $rep);
     }
     if (isset($page['content'])) {
         if ($standalone_edit) {
             if (!isset($render_file)) {
                 if (stristr($page['content'], 'field="content"') or stristr($page['content'], 'field=\'content\'')) {
                     $page['content'] = '<div class="edit" field="content" rel="content" contenteditable="true">' . $page['content'] . '</div>';
                 }
             }
         }
         $layout = str_replace('{content}', $page['content'], $layout);
     }
     $layout = mw()->template->process_meta($layout);
     $layout = $this->app->parser->process($layout, $options = false);
     $layout = execute_document_ready($layout);
     $layout = str_replace('{head}', '', $layout);
     $layout = str_replace('{content}', '', $layout);
     echo $layout;
     return;
 }
Пример #2
0
 public function index($input = null)
 {
     if (!is_array($input) || empty($input)) {
         $input = Input::all();
     }
     $allowed_configs = array('database', 'microweber');
     $is_installed = mw_is_installed();
     if ($is_installed) {
         return 'Microweber is already installed!';
     }
     $view = MW_PATH . 'Views/install.php';
     $connection = Config::get('database.connections');
     $this->install_log("Preparing to install");
     if (isset($input['make_install'])) {
         if (!isset($input['db_pass'])) {
             $input['db_pass'] = '';
         }
         if (!isset($input['table_prefix'])) {
             $input['table_prefix'] = '';
         }
         $errors = array();
         if (!isset($input['db_host'])) {
             $errors[] = 'Parameter "db_host" is required';
         } else {
             $input['db_host'] = trim($input['db_host']);
         }
         if (!isset($input['db_name'])) {
             $errors[] = 'Parameter "db_name" is required';
         } else {
             $input['db_name'] = trim($input['db_name']);
         }
         if (!isset($input['db_user'])) {
             $errors[] = 'Parameter "db_user" is required';
         }
         if (!isset($input['admin_email'])) {
             $errors[] = 'Parameter "admin_email" is required';
         }
         if (!isset($input['admin_password'])) {
             $errors[] = 'Parameter "admin_password" is required';
         }
         if (!isset($input['admin_username'])) {
             $errors[] = 'Parameter "admin_username" is required';
         }
         if (!empty($errors)) {
             return implode("\n", $errors);
         }
         if (isset($input['db_driver'])) {
             $dbDriver = $input['db_driver'];
         } else {
             $dbDriver = 'mysql';
         }
         Config::set("database.default", $dbDriver);
         if ($dbDriver == 'sqlite') {
             if (isset($input['db_name_sqlite'])) {
                 $input['db_name'] = $input['db_name_sqlite'];
             }
             Config::set("database.connections.{$dbDriver}.database", $input['db_name']);
             if (!file_exists($input['db_name'])) {
                 touch($input['db_name']);
             }
         }
         Config::set("database.connections.{$dbDriver}.host", $input['db_host']);
         Config::set("database.connections.{$dbDriver}.username", $input['db_user']);
         Config::set("database.connections.{$dbDriver}.password", $input['db_pass']);
         Config::set("database.connections.{$dbDriver}.database", $input['db_name']);
         Config::set("database.connections.{$dbDriver}.prefix", $input['table_prefix']);
         if (isset($input['default_template']) and $input['default_template'] != false) {
             Config::set('microweber.install_default_template', $input['default_template']);
         }
         if (isset($input['with_default_content']) and $input['with_default_content'] != false) {
             Config::set('microweber.install_default_template_content', 1);
         }
         if (Config::get('app.key') == 'YourSecretKey!!!') {
             if (!$this->app->runningInConsole()) {
                 $_SERVER['argv'] = array();
             }
             Artisan::call('key:generate');
         }
         $this->install_log("Saving config");
         Config::save($allowed_configs);
         Cache::flush();
         $install_finished = false;
         try {
             DB::connection($dbDriver)->getDatabaseName();
         } catch (\PDOException $e) {
             return 'Error: ' . $e->getMessage() . "\n";
         } catch (\Exception $e) {
             return 'Error: ' . $e->getMessage() . "\n";
         }
         if (function_exists('set_time_limit')) {
             @set_time_limit(0);
         }
         $this->install_log("Setting up database");
         $installer = new Install\DbInstaller();
         $installer->run();
         $installer = new Install\WebserverInstaller();
         $installer->run();
         $this->install_log("Setting up template");
         $installer = new Install\TemplateInstaller();
         $installer->run();
         $this->install_log("Setting up default options");
         $installer = new Install\DefaultOptionsInstaller();
         $installer->run();
         Config::set('microweber.is_installed', 1);
         if (isset($input['admin_password']) && strlen($input['admin_password'])) {
             $this->install_log("Adding admin user");
             $adminUser = new \User();
             $adminUser->username = $input['admin_username'];
             $adminUser->email = $input['admin_email'];
             $adminUser->password = $input['admin_password'];
             $adminUser->is_admin = 1;
             $adminUser->is_active = 1;
             $adminUser->save();
             Config::set('microweber.has_admin', 1);
         }
         $this->install_log("Saving ready config");
         Config::save($allowed_configs);
         $this->install_log("done");
         return 'done';
     }
     $layout = new View($view);
     $defaultDbEngine = Config::get('database.default');
     if (extension_loaded('pdo_sqlite')) {
         // $defaultDbEngine = 'sqlite';
     }
     $dbEngines = Config::get('database.connections');
     foreach ($dbEngines as $driver => $v) {
         if (!extension_loaded("pdo_{$driver}")) {
             unset($dbEngines[$driver]);
         }
     }
     $viewData = ['config' => $dbEngines[$defaultDbEngine], 'dbDefaultEngine' => $defaultDbEngine, 'dbEngines' => array_keys($dbEngines), 'dbEngineNames' => ['mysql' => 'MySQL', 'sqlite' => 'SQLite', 'sqlsrv' => 'Microsoft SQL Server', 'pgsql' => 'PostgreSQL']];
     $domain = false;
     if (isset($_SERVER['HTTP_HOST'])) {
         $domain = $_SERVER['HTTP_HOST'];
         $domain = str_replace('www.', '', $domain);
         $domain = str_replace('.', '_', $domain);
         $domain = str_replace('-', '_', $domain);
         $domain = substr($domain, 0, 10);
     }
     if (!$viewData['config']['prefix'] and $domain) {
         $viewData['config']['prefix'] = $domain . '_';
     }
     if (extension_loaded('pdo_sqlite') and $domain) {
         $sqlite_path = normalize_path(storage_path() . DS . $domain . '.sqlite', false);
         $viewData['config']['db_name_sqlite'] = $sqlite_path;
     }
     $layout->set($viewData);
     $is_installed = mw_is_installed();
     if ($is_installed) {
         App::abort(403, 'Unauthorized action. Microweber is already installed.');
     }
     $layout->assign('done', $is_installed);
     $layout = $layout->__toString();
     return $layout;
 }
Пример #3
0
 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;
                     }
                 }
             }
         }
     }
     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->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->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();
 }
Пример #4
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();
 }