Ejemplo n.º 1
0
 public function frontend()
 {
     if (isset($_GET['debug'])) {
         if ($this->app->make('config')->get('app.debug')) {
             DB::enableQueryLog();
         }
     }
     event_trigger('mw.controller.index');
     if ($this->render_this_url == false and $this->app->url_manager->is_ajax() == false) {
         $page_url = $this->app->url_manager->string();
     } elseif ($this->render_this_url == false and $this->app->url_manager->is_ajax() == true) {
         $page_url = $this->app->url_manager->string(1);
     } else {
         $page_url = $this->render_this_url;
         $this->render_this_url = false;
     }
     if ($this->page_url != false) {
         $page_url = $this->page_url;
     }
     if (strtolower($page_url) == 'index.php') {
         $page_url = '';
     }
     if ($this->create_new_page == true and $this->page_url != false) {
         $page_url = $this->page_url;
     }
     $page = false;
     if ($page == false and !empty($this->page)) {
         $page = $this->page;
     }
     $page_url = rtrim($page_url, '/');
     $is_admin = $this->app->user_manager->is_admin();
     $page_url_orig = $page_url;
     $simply_a_file = false;
     $show_404_to_non_admin = false;
     // if this is a file path it will load it
     if (isset($_REQUEST['view'])) {
         $is_custom_view = $_REQUEST['view'];
     } else {
         $is_custom_view = $this->app->url_manager->param('view');
         if ($is_custom_view and $is_custom_view != false) {
             $is_custom_view = str_replace('..', '', $is_custom_view);
             $page_url = $this->app->url_manager->param_unset('view', $page_url);
         }
     }
     $is_editmode = $this->app->url_manager->param('editmode');
     $is_no_editmode = $this->app->url_manager->param('no_editmode');
     $is_quick_edit = $this->app->url_manager->param('mw_quick_edit');
     if ($is_quick_edit != false) {
         $page_url = $this->app->url_manager->param_unset('mw_quick_edit', $page_url);
     }
     $is_preview_template = $this->app->url_manager->param('preview_template');
     if (!$is_preview_template) {
         $is_preview_template = false;
         if ($this->return_data == false) {
             if (!defined('MW_FRONTEND')) {
                 define('MW_FRONTEND', true);
             }
         }
         if (mw()->user_manager->session_id() and $is_editmode and $is_no_editmode == false) {
             if ($is_editmode == 'n') {
                 $is_editmode = false;
                 $page_url = $this->app->url_manager->param_unset('editmode', $page_url);
                 $this->app->user_manager->session_set('back_to_editmode', true);
                 $this->app->user_manager->session_set('editmode', false);
                 return $this->app->url_manager->redirect($this->app->url_manager->site_url($page_url));
             } else {
                 $editmode_sess = $this->app->user_manager->session_get('editmode');
                 $page_url = $this->app->url_manager->param_unset('editmode', $page_url);
                 if ($is_admin == true) {
                     if ($editmode_sess == false) {
                         $this->app->user_manager->session_set('editmode', true);
                         $this->app->user_manager->session_set('back_to_editmode', false);
                         $is_editmode = false;
                     }
                     return $this->app->url_manager->redirect($this->app->url_manager->site_url($page_url));
                 } else {
                     $is_editmode = false;
                 }
             }
         }
         if (mw()->user_manager->session_id() and !$is_no_editmode) {
             $is_editmode = $this->app->user_manager->session_get('editmode');
         } else {
             $is_editmode = false;
             $page_url = $this->app->url_manager->param_unset('no_editmode', $page_url);
         }
     } else {
         $is_editmode = false;
         $page_url = $this->app->url_manager->param_unset('preview_template', $page_url);
     }
     if ($is_quick_edit == true) {
         $is_editmode = true;
     }
     $preview_module = false;
     $preview_module_template = false;
     $preview_module_id = false;
     $template_relative_layout_file_from_url = false;
     $is_preview_module = $this->app->url_manager->param('preview_module');
     if ($is_preview_module != false) {
         if ($this->app->user_manager->is_admin()) {
             $is_preview_module = module_name_decode($is_preview_module);
             if (is_module($is_preview_module)) {
                 $is_preview_module_skin = $this->app->url_manager->param('preview_module_template');
                 $preview_module_id = $this->app->url_manager->param('preview_module_id');
                 $preview_module = $is_preview_module;
                 if ($is_preview_module_skin != false) {
                     $preview_module_template = module_name_decode($is_preview_module_skin);
                     $is_editmode = false;
                 }
             }
         }
     }
     $is_layout_file = $this->app->url_manager->param('preview_layout');
     if (!$is_layout_file) {
         $is_layout_file = false;
     } else {
         $page_url = $this->app->url_manager->param_unset('preview_layout', $page_url);
     }
     if (isset($_REQUEST['content_id']) and intval($_REQUEST['content_id']) != 0) {
         $page = $this->app->content_manager->get_by_id($_REQUEST['content_id']);
     }
     if ($is_quick_edit or $is_preview_template == true or isset($_REQUEST['isolate_content_field']) or $this->create_new_page == true) {
         if (isset($_REQUEST['content_id']) and intval($_REQUEST['content_id']) != 0) {
             $page = $this->app->content_manager->get_by_id($_REQUEST['content_id']);
         } else {
             $page['id'] = 0;
             $page['content_type'] = 'page';
             if (isset($_REQUEST['content_type'])) {
                 $page['content_type'] = $this->app->database_manager->escape_string($_REQUEST['content_type']);
             }
             if (isset($_REQUEST['subtype'])) {
                 $page['subtype'] = $this->app->database_manager->escape_string($_REQUEST['subtype']);
             }
             template_var('new_content_type', $page['content_type']);
             $page['parent'] = '0';
             if (isset($_REQUEST['parent_id']) and $_REQUEST['parent_id'] != 0) {
                 $page['parent'] = intval($_REQUEST['parent_id']);
             }
             //$page['url'] = $this->app->url_manager->string();
             if (isset($is_preview_template) and $is_preview_template != false) {
                 $page['active_site_template'] = $is_preview_template;
             } else {
             }
             if (isset($is_layout_file) and $is_layout_file != false) {
                 $page['layout_file'] = $is_layout_file;
             }
             if (isset($_REQUEST['inherit_template_from']) and $_REQUEST['inherit_template_from'] != 0) {
                 $page['parent'] = intval($_REQUEST['inherit_template_from']);
                 $inherit_from = $this->app->content_manager->get_by_id($_REQUEST['inherit_template_from']);
                 //$page['parent'] =  $inherit_from ;
                 if (isset($inherit_from['layout_file']) and $inherit_from['layout_file'] == 'inherit') {
                     $inherit_from_id = $this->app->content_manager->get_inherited_parent($inherit_from['id']);
                     $inherit_from = $this->app->content_manager->get_by_id($inherit_from_id);
                 }
                 if (is_array($inherit_from) and isset($inherit_from['active_site_template'])) {
                     $page['active_site_template'] = $inherit_from['active_site_template'];
                     $is_layout_file = $page['layout_file'] = $inherit_from['layout_file'];
                 }
             }
             if (isset($_REQUEST['content_type']) and $_REQUEST['content_type'] != false) {
                 $page['content_type'] = $_REQUEST['content_type'];
             }
             if ($this->content_data != false) {
                 $page = $this->content_data;
             }
             template_var('new_page', $page);
         }
     }
     $output_cache_timeout = false;
     if (isset($is_preview_template) and $is_preview_template != false) {
         if (!defined('MW_NO_SESSION')) {
             define('MW_NO_SESSION', true);
         }
     }
     if (isset($_REQUEST['recart']) and $_REQUEST['recart'] != false) {
         event_trigger('recover_shopping_cart', $_REQUEST['recart']);
     }
     if ($output_cache_timeout != false) {
         $output_cache_id = __FUNCTION__ . crc32($_SERVER['REQUEST_URI']);
         $output_cache_group = 'content/preview';
         $output_cache_content = $this->app->cache_manager->get($output_cache_id, $output_cache_group, $output_cache_timeout);
         if ($output_cache_content != false) {
             echo $output_cache_content;
             return;
         }
     }
     $the_active_site_template = $this->app->option_manager->get('current_template', 'template');
     $date_format = $this->app->option_manager->get('date_format', 'website');
     if ($date_format == false) {
         $date_format = 'Y-m-d H:i:s';
     }
     if ($page == false or $this->create_new_page == true) {
         if (trim($page_url) == '' and $preview_module == false) {
             $page = $this->app->content_manager->homepage();
         } else {
             $found_mod = false;
             $page = $this->app->content_manager->get_by_url($page_url);
             $page_exact = $this->app->content_manager->get_by_url($page_url, true);
             $page_url_segment_1 = $this->app->url_manager->segment(0, $page_url);
             if ($preview_module != false) {
                 $page_url = $preview_module;
             }
             if ($the_active_site_template == false or $the_active_site_template == '') {
                 $the_active_site_template = 'default';
             }
             if ($page_exact == false and $found_mod == false and $this->app->modules->is_installed($page_url) and $page_url != 'settings' and $page_url != 'admin') {
                 $found_mod = true;
                 $page['id'] = 0;
                 $page['content_type'] = 'page';
                 $page['parent'] = '0';
                 $page['url'] = $this->app->url_manager->string();
                 $page['active_site_template'] = $the_active_site_template;
                 template_var('no_edit', 1);
                 $mod_params = '';
                 if ($preview_module_template != false) {
                     $mod_params = $mod_params . " template='{$preview_module_template}' ";
                 }
                 if ($preview_module_id != false) {
                     $mod_params = $mod_params . " id='{$preview_module_id}' ";
                 }
                 $found_mod = $page_url;
                 $page['content'] = '<microweber module="' . $page_url . '" ' . $mod_params . '  />';
                 //  $page['simply_a_file'] = 'clean.php';
                 $page['layout_file'] = 'clean.php';
                 template_var('content', $page['content']);
                 template_var('new_page', $page);
             }
             if ($found_mod == false) {
                 if (empty($page)) {
                     $the_new_page_file = false;
                     $page_url_segment_1 = $this->app->url_manager->segment(0, $page_url);
                     $td = templates_path() . $page_url_segment_1;
                     $td_base = $td;
                     $page_url_segment_2 = $this->app->url_manager->segment(1, $page_url);
                     $directly_to_file = false;
                     $page_url_segment_3 = $this->app->url_manager->segment(-1, $page_url);
                     $page_url_segment_1 = $the_active_site_template = $this->app->option_manager->get('current_template', 'template');
                     $td_base = templates_path() . $the_active_site_template . DS;
                     $page_url_segment_3_str = implode(DS, $page_url_segment_3);
                     if ($page_url_segment_3_str != '') {
                         $page_url_segment_3_str = rtrim($page_url_segment_3_str, DS);
                         $page_url_segment_3_str = rtrim($page_url_segment_3_str, '\\');
                         $page_url_segment_3_str_copy = $page_url_segment_3_str;
                         $is_ext = get_file_extension($page_url_segment_3_str);
                         if ($is_ext == false or $is_ext != 'php') {
                             $page_url_segment_3_str = $page_url_segment_3_str . '.php';
                         }
                         $td_f = $td_base . DS . $page_url_segment_3_str;
                         $td_fd = $td_base . DS . $page_url_segment_3_str_copy;
                         $td_fd2 = $td_base . DS . $page_url_segment_3[0];
                         if (is_file($td_f)) {
                             $the_new_page_file = $page_url_segment_3_str;
                             $simply_a_file = $directly_to_file = $td_f;
                         } else {
                             if (is_dir($td_fd)) {
                                 $td_fd_index = $td_fd . DS . 'index.php';
                                 if (is_file($td_fd_index)) {
                                     $the_new_page_file = $td_fd_index;
                                     $simply_a_file = $directly_to_file = $td_fd_index;
                                 }
                             } else {
                                 $is_ext = get_file_extension($td_fd);
                                 if ($is_ext == false or $is_ext != 'php') {
                                     $td_fd = $td_fd . '.php';
                                 }
                                 $is_ext = get_file_extension($td_fd2);
                                 if ($is_ext == false or $is_ext != 'php') {
                                     $td_fd2 = $td_fd2 . '.php';
                                 }
                                 if (is_file($td_fd)) {
                                     $the_new_page_file = $td_fd;
                                     $simply_a_file = $directly_to_file = $td_fd;
                                 } elseif (is_file($td_fd2)) {
                                     $the_new_page_file = $td_fd2;
                                     $simply_a_file = $directly_to_file = $td_fd2;
                                 } else {
                                     $td_basedef = templates_path() . 'default' . DS . $page_url_segment_3_str;
                                     if (is_file($td_basedef)) {
                                         $the_new_page_file = $td_basedef;
                                         $simply_a_file = $directly_to_file = $td_basedef;
                                     }
                                 }
                             }
                         }
                     }
                     $fname1 = 'index.php';
                     $fname2 = $page_url_segment_2 . '.php';
                     $fname3 = $page_url_segment_2;
                     $tf1 = $td . DS . $fname1;
                     $tf2 = $td . DS . $fname2;
                     $tf3 = $td . DS . $fname3;
                     if ($directly_to_file == false and is_dir($td)) {
                         if (is_file($tf1)) {
                             $simply_a_file = $tf1;
                             $the_new_page_file = $fname1;
                         }
                         if (is_file($tf2)) {
                             $simply_a_file = $tf2;
                             $the_new_page_file = $fname2;
                         }
                         if (is_file($tf3)) {
                             $simply_a_file = $tf3;
                             $the_new_page_file = $fname3;
                         }
                         if ($simply_a_file != false) {
                             $simply_a_file = str_replace('..', '', $simply_a_file);
                             $simply_a_file = normalize_path($simply_a_file, false);
                         }
                     }
                     if ($simply_a_file == false) {
                         //$page = $this->app->content_manager->homepage();
                         $page = false;
                         if (!is_array($page)) {
                             $page = array();
                             $page['id'] = 0;
                             $page['content_type'] = 'page';
                             $page['parent'] = '0';
                             $page['url'] = $this->app->url_manager->string();
                             //  $page['active_site_template'] = $page_url_segment_1;
                             $page['simply_a_file'] = 'clean.php';
                             $page['layout_file'] = 'clean.php';
                             $show_404_to_non_admin = true;
                         }
                         if (is_array($page_url_segment_3)) {
                             foreach ($page_url_segment_3 as $mvalue) {
                                 if ($found_mod == false and $this->app->modules->is_installed($mvalue)) {
                                     $found_mod = true;
                                     $page['id'] = 0;
                                     $page['content_type'] = 'page';
                                     $page['parent'] = '0';
                                     $page['url'] = $this->app->url_manager->string();
                                     $page['active_site_template'] = $page_url_segment_1;
                                     $page['content'] = '<module type="' . $mvalue . '" />';
                                     $page['simply_a_file'] = 'clean.php';
                                     $page['layout_file'] = 'clean.php';
                                     template_var('content', $page['content']);
                                     template_var('new_page', $page);
                                     $show_404_to_non_admin = false;
                                 }
                             }
                         }
                     } else {
                         if (!is_array($page)) {
                             $page = array();
                         }
                         $page['id'] = 0;
                         if (isset($page_data) and isset($page_data['id'])) {
                             //  $page['id'] = $page_data['id'];
                         }
                         $page['content_type'] = 'page';
                         $page['parent'] = '0';
                         $page['url'] = $this->app->url_manager->string();
                         $page['active_site_template'] = $page_url_segment_1;
                         $page['layout_file'] = $the_new_page_file;
                         $page['simply_a_file'] = $simply_a_file;
                         template_var('new_page', $page);
                         template_var('simply_a_file', $simply_a_file);
                     }
                 }
             }
         }
     }
     if ($page['id'] != 0) {
         // if(!isset($page['layout_file']) or $page['layout_file'] == false){
         $page = $this->app->content_manager->get_by_id($page['id']);
         // }
         if ($page['content_type'] == 'post' and isset($page['parent'])) {
             $content = $page;
             $page = $this->app->content_manager->get_by_id($page['parent']);
         } else {
             $content = $page;
         }
     } else {
         $content = $page;
     }
     if (isset($content['created_at']) and trim($content['created_at']) != '') {
         $content['created_at'] = date($date_format, strtotime($content['created_at']));
     }
     if (isset($content['updated_at']) and trim($content['updated_at']) != '') {
         $content['updated_at'] = date($date_format, strtotime($content['updated_at']));
     }
     if ($is_preview_template != false) {
         $is_preview_template = str_replace('____', DS, $is_preview_template);
         $is_preview_template = str_replace('..', '', $is_preview_template);
         $content['active_site_template'] = $is_preview_template;
     }
     if ($is_layout_file != false and $is_admin == true) {
         $is_layout_file = str_replace('____', DS, $is_layout_file);
         if ($is_layout_file == 'inherit') {
             if (isset($_REQUEST['inherit_template_from']) and intval($_REQUEST['inherit_template_from']) != 0) {
                 $inherit_layout_from_this_page = $this->app->content_manager->get_by_id($_REQUEST['inherit_template_from']);
                 if (isset($inherit_layout_from_this_page['layout_file']) and $inherit_layout_from_this_page['layout_file'] != 'inherit') {
                     $is_layout_file = $inherit_layout_from_this_page['layout_file'];
                 }
                 if (isset($inherit_layout_from_this_page['layout_file']) and $inherit_layout_from_this_page['layout_file'] != 'inherit') {
                     $is_layout_file = $inherit_layout_from_this_page['layout_file'];
                 }
             }
         }
         $content['layout_file'] = $is_layout_file;
     }
     if ($is_custom_view and $is_custom_view != false) {
         $content['custom_view'] = $is_custom_view;
     }
     if (isset($content['is_active']) and ($content['is_active'] == 'n' or $content['is_active'] == 0)) {
         if ($this->app->user_manager->is_admin() == false) {
             $page_non_active = array();
             $page_non_active['id'] = 0;
             $page_non_active['content_type'] = 'page';
             $page_non_active['parent'] = '0';
             $page_non_active['url'] = $this->app->url_manager->string();
             $page_non_active['content'] = 'This page is not published!';
             $page_non_active['simply_a_file'] = 'clean.php';
             $page_non_active['layout_file'] = 'clean.php';
             $page_non_active['page_non_active'] = true;
             template_var('content', $page_non_active['content']);
             $content = $page_non_active;
         }
     } elseif (isset($content['is_deleted']) and $content['is_deleted'] == 1) {
         if ($this->app->user_manager->is_admin() == false) {
             $page_non_active = array();
             $page_non_active['id'] = 0;
             $page_non_active['content_type'] = 'page';
             $page_non_active['parent'] = '0';
             $page_non_active['url'] = $this->app->url_manager->string();
             $page_non_active['content'] = 'This page is deleted!';
             $page_non_active['simply_a_file'] = 'clean.php';
             $page_non_active['layout_file'] = 'clean.php';
             $page_non_active['page_is_deleted'] = true;
             template_var('content', $page_non_active['content']);
             $content = $page_non_active;
         }
     }
     if (isset($content['require_login']) and $content['require_login'] == 1) {
         if ($this->app->user_manager->id() == 0) {
             $page_non_active = array();
             $page_non_active['id'] = 0;
             $page_non_active['content_type'] = 'page';
             $page_non_active['parent'] = '0';
             $page_non_active['url'] = $this->app->url_manager->string();
             $page_non_active['content'] = ' <module type="users/login" class="user-require-login-on-view" /> ';
             $page_non_active['simply_a_file'] = 'clean.php';
             $page_non_active['layout_file'] = 'clean.php';
             $page_non_active['page_require_login'] = true;
             template_var('content', $page_non_active['content']);
             $content = $page_non_active;
         }
     }
     if (!defined('IS_HOME')) {
         if (isset($content['is_home']) and $content['is_home'] == 1) {
             define('IS_HOME', true);
         }
     }
     $this->app->content_manager->define_constants($content);
     event_trigger('mw.front', $content);
     event_trigger('mw_frontend', $content);
     $render_file = $this->app->template->get_layout($content);
     $content['render_file'] = $render_file;
     if (defined('TEMPLATE_DIR')) {
         $load_template_functions = TEMPLATE_DIR . 'functions.php';
         if (is_file($load_template_functions)) {
             include_once $load_template_functions;
         }
     }
     if ($this->return_data != false) {
         return $content;
     }
     if (isset($content['original_link']) and $content['original_link'] != '') {
         $content['original_link'] = str_ireplace('{site_url}', $this->app->url_manager->site(), $content['original_link']);
         $redirect = $this->app->format->prep_url($content['original_link']);
         if ($redirect != '') {
             return $this->app->url_manager->redirect($redirect);
         }
     }
     if (!isset($page['title'])) {
         $page['title'] = 'New page';
     }
     if (!isset($content['title'])) {
         $content['title'] = 'New content';
     }
     $category = false;
     if (defined('CATEGORY_ID')) {
         $category = $this->app->category_manager->get_by_id(CATEGORY_ID);
     }
     if ($render_file) {
         $render_params = array();
         if ($show_404_to_non_admin) {
             if (!is_admin()) {
                 $load_template_404 = template_dir() . '404.php';
                 if (is_file($load_template_404)) {
                     $render_file = $load_template_404;
                 }
             }
         }
         $render_params['render_file'] = $render_file;
         $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['content'] = $content;
         $render_params['category'] = $category;
         $render_params['page'] = $page;
         $l = $this->app->template->render($render_params);
         if (is_object($l)) {
             return $l;
         }
         // used for preview from the admin wysiwyg
         if (isset($_REQUEST['isolate_content_field'])) {
             require_once MW_PATH . 'Utils' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'phpQuery.php';
             $pq = \phpQuery::newDocument($l);
             $isolated_head = pq('head')->eq(0)->html();
             $found_field = false;
             if (isset($_REQUEST['isolate_content_field'])) {
                 foreach ($pq['[field=content]'] as $elem) {
                     $isolated_el = $l = pq($elem)->htmlOuter();
                 }
             }
             $is_admin = $this->app->user_manager->is_admin();
             if ($is_admin == true and isset($isolated_el) != false) {
                 $tb = mw_includes_path() . DS . 'toolbar' . DS . 'editor_tools' . DS . 'wysiwyg' . DS . 'index.php';
                 //$layout_toolbar = file_get_contents($filename);
                 $layout_toolbar = new \Microweber\View($tb);
                 $layout_toolbar = $layout_toolbar->__toString();
                 if ($layout_toolbar != '') {
                     if (strstr($layout_toolbar, '{head}')) {
                         if ($isolated_head != false) {
                             $layout_toolbar = str_replace('{head}', $isolated_head, $layout_toolbar);
                         }
                     }
                     if (strpos($layout_toolbar, '{content}')) {
                         $l = str_replace('{content}', $l, $layout_toolbar);
                     }
                     //$layout_toolbar = mw()->parser->process($layout_toolbar, $options = array('no_apc' => 1));
                 }
             }
         }
         $modify_content = event_trigger('on_load', $content);
         if ($is_editmode == true and !defined('IN_EDIT')) {
             define('IN_EDIT', true);
         }
         if (isset($is_quick_edit) and $is_quick_edit == true and !defined('QUICK_EDIT')) {
             define('QUICK_EDIT', true);
         }
         $l = $this->app->parser->process($l, $options = false);
         if ($preview_module_id != false) {
             $_REQUEST['embed_id'] = $preview_module_id;
         }
         if (isset($_REQUEST['embed_id'])) {
             $find_embed_id = trim($_REQUEST['embed_id']);
             $l = $this->app->parser->get_by_id($find_embed_id, $l);
         }
         $apijs_loaded = $this->app->template->get_apijs_url();
         //$apijs_loaded = $this->app->template->get_apijs_url() . '?id=' . CONTENT_ID;
         $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 != '') {
                 $l = str_ireplace('</head>', $template_headers_append . '</head>', $l, $one);
             }
         }
         $template_headers_src = $this->app->template->head(true);
         $template_footer_src = $this->app->template->foot(true);
         $template_headers_src_callback = $this->app->template->head_callback($page);
         if (is_array($template_headers_src_callback) and !empty($template_headers_src_callback)) {
             foreach ($template_headers_src_callback as $template_headers_src_callback_str) {
                 if (is_string($template_headers_src_callback_str)) {
                     $template_headers_src = $template_headers_src . "\n" . $template_headers_src_callback_str;
                 }
             }
         }
         if (isset($page['created_by'])) {
             $author = $this->app->user_manager->get_by_id($page['created_by']);
             if (is_array($author) and isset($author['profile_url']) and $author['profile_url'] != false) {
                 $template_headers_src = $template_headers_src . "\n" . '<link rel="author" href="' . trim($author['profile_url']) . '" />' . "\n";
             }
         }
         if ($template_headers_src != false and is_string($template_headers_src)) {
             $l = str_ireplace('</head>', $template_headers_src . '</head>', $l, $one);
         }
         if ($template_footer_src != false and is_string($template_footer_src)) {
             $l = str_ireplace('</body>', $template_footer_src . '</body>', $l, $one);
         }
         $l = str_ireplace('<head>', '<head>' . $default_css, $l);
         if (!stristr($l, $apijs_loaded)) {
             //$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();
             $apijs_settings_script = "\r\n" . '<script src="' . $apijs_settings_loaded . '"></script>' . "\r\n";
             $apijs_settings_script .= '<script src="' . $apijs_loaded . '"></script>' . "\r\n";
             $l = str_ireplace('<head>', '<head>' . $apijs_settings_script, $l);
         }
         if (isset($content['active_site_template']) and $content['active_site_template'] == 'default' and $the_active_site_template != 'default' and $the_active_site_template != 'mw_default') {
             $content['active_site_template'] = $the_active_site_template;
         }
         if (isset($content['active_site_template']) and trim($content['active_site_template']) != '' and $content['active_site_template'] != 'default') {
             if (!defined('CONTENT_TEMPLATE')) {
                 define('CONTENT_TEMPLATE', $content['active_site_template']);
             }
             $custom_live_edit = TEMPLATES_DIR . DS . $content['active_site_template'] . DS . 'live_edit.css';
             $live_edit_css_folder = userfiles_path() . 'css' . DS . $content['active_site_template'] . DS;
             $live_edit_url_folder = userfiles_url() . 'css/' . $content['active_site_template'] . '/';
             $custom_live_edit = $live_edit_css_folder . DS . 'live_edit.css';
         } else {
             if (!defined('CONTENT_TEMPLATE')) {
                 define('CONTENT_TEMPLATE', $the_active_site_template);
             }
             //                if ($the_active_site_template == 'mw_default') {
             //                    $the_active_site_template = 'default';
             //                }
             $custom_live_edit = TEMPLATE_DIR . DS . 'live_edit.css';
             $live_edit_css_folder = userfiles_path() . 'css' . DS . $the_active_site_template . DS;
             $live_edit_url_folder = userfiles_url() . 'css/' . $the_active_site_template . '/';
             $custom_live_edit = $live_edit_css_folder . 'live_edit.css';
         }
         $custom_live_edit = normalize_path($custom_live_edit, false);
         if (is_file($custom_live_edit)) {
             $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" />';
             $l = str_ireplace('</head>', $liv_ed_css . '</head>', $l);
         }
         $liv_ed_css = $this->app->template->get_custom_css_url();
         if ($liv_ed_css != false) {
             $liv_ed_css = '<link rel="stylesheet" href="' . $liv_ed_css . '" id="mw-custom-user-css" type="text/css" />';
             $l = str_ireplace('</head>', $liv_ed_css . '</head>', $l);
         }
         $website_head_tags = $this->app->option_manager->get('website_head', 'website');
         $rep_count = 1;
         if ($website_head_tags != false) {
             $l = str_ireplace('</head>', $website_head_tags . '</head>', $l, $rep_count);
         }
         if (defined('MW_VERSION')) {
             $generator_tag = "\n" . '<meta name="generator" content="Microweber" />' . "\n";
             $l = str_ireplace('</head>', $generator_tag . '</head>', $l, $rep_count);
         }
         if ($is_editmode == true and $this->isolate_by_html_id == false and !isset($_REQUEST['isolate_content_field'])) {
             if ($is_admin == true) {
                 $tb = mw_includes_path() . DS . 'toolbar' . DS . 'toolbar.php';
                 $layout_toolbar = new \Microweber\View($tb);
                 $is_editmode_basic = false;
                 $user_data = $this->app->user_manager->get();
                 if (isset($user_data['basic_mode']) and trim($user_data['basic_mode'] == 'y')) {
                     $is_editmode_basic = true;
                 }
                 if (isset($is_editmode_basic) and $is_editmode_basic == true) {
                     $layout_toolbar->assign('basic_mode', true);
                 } else {
                     $layout_toolbar->assign('basic_mode', false);
                 }
                 event_trigger('mw.live_edit');
                 $layout_toolbar = $layout_toolbar->__toString();
                 if ($layout_toolbar != '') {
                     $layout_toolbar = $this->app->parser->process($layout_toolbar, $options = array('no_apc' => 1));
                     $c = 1;
                     $l = str_ireplace('</body>', $layout_toolbar . '</body>', $l, $c);
                 }
                 $custom_live_edit = TEMPLATES_DIR . DS . TEMPLATE_NAME . DS . 'live_edit.php';
                 $custom_live_edit = normalize_path($custom_live_edit, false);
                 if (is_file($custom_live_edit)) {
                     $layout_live_edit = new \Microweber\View($custom_live_edit);
                     $layout_live_edit = $layout_live_edit->__toString();
                     if ($layout_live_edit != '') {
                         $l = str_ireplace('</body>', $layout_live_edit . '</body>', $l, $c);
                     }
                 }
             }
         } elseif ($is_editmode == false and $is_admin == true and mw()->user_manager->session_id() and !(mw()->user_manager->session_all() == false) and mw()->user_manager->session_get('back_to_editmode')) {
             if (!isset($_REQUEST['isolate_content_field']) and !isset($_REQUEST['content_id'])) {
                 $back_to_editmode = $this->app->user_manager->session_get('back_to_editmode');
                 if ($back_to_editmode == true) {
                     $tb = mw_includes_path() . DS . 'toolbar' . DS . 'toolbar_back.php';
                     $layout_toolbar = new \Microweber\View($tb);
                     $layout_toolbar = $layout_toolbar->__toString();
                     if ($layout_toolbar != '') {
                         $layout_toolbar = $this->app->parser->process($layout_toolbar, $options = array('no_apc' => 1));
                         $c = 1;
                         $l = str_ireplace('</body>', $layout_toolbar . '</body>', $l, $c);
                     }
                 }
             }
         }
         $l = str_replace('{TEMPLATE_URL}', TEMPLATE_URL, $l);
         $l = str_replace('{THIS_TEMPLATE_URL}', THIS_TEMPLATE_URL, $l);
         $l = str_replace('{DEFAULT_TEMPLATE_URL}', DEFAULT_TEMPLATE_URL, $l);
         $l = str_replace('%7BTEMPLATE_URL%7D', TEMPLATE_URL, $l);
         $l = str_replace('%7BTHIS_TEMPLATE_URL%7D', THIS_TEMPLATE_URL, $l);
         $l = str_replace('%7BDEFAULT_TEMPLATE_URL%7D', DEFAULT_TEMPLATE_URL, $l);
         $meta = array();
         $meta['content_image'] = '';
         $meta['description'] = '';
         if (is_home()) {
             $meta['content_url'] = site_url();
         } else {
             $meta['content_url'] = $this->app->url_manager->current(1);
         }
         $meta['og_description'] = $this->app->option_manager->get('website_description', 'website');
         $meta['og_type'] = 'website';
         $meta_content_id = PAGE_ID;
         if (CONTENT_ID > 0) {
             $meta_content_id = CONTENT_ID;
         }
         if ($meta_content_id > 0) {
             $meta = $this->app->content_manager->get_by_id($meta_content_id);
             $content_image = $this->app->media_manager->get_picture($meta_content_id);
             if ($content_image) {
                 $meta['content_image'] = $content_image;
             } else {
                 $meta['content_image'] = '';
             }
             $meta['content_url'] = $this->app->content_manager->link($meta_content_id);
             $meta['og_type'] = $meta['content_type'];
             if ($meta['og_type'] != 'page' and trim($meta['subtype']) != '') {
                 $meta['og_type'] = $meta['subtype'];
             }
             if ($meta['description'] != false and trim($meta['description']) != '') {
                 $meta['description'] = $meta['description'];
             } elseif ($meta['content'] != false and trim($meta['content']) != '') {
                 $meta['description'] = str_replace("\n", ' ', $this->app->format->limit($this->app->format->clean_html(strip_tags($meta['content'])), 500));
             }
             if (isset($meta['description']) and $meta['description'] != '') {
                 $meta['og_description'] = $meta['description'];
             } else {
                 $meta['og_description'] = trim($this->app->format->limit($this->app->format->clean_html(strip_tags($meta['content'])), 500));
             }
         } else {
             $meta['title'] = $this->app->option_manager->get('website_title', 'website');
             $meta['description'] = $this->app->option_manager->get('website_description', 'website');
             $meta['content_meta_keywords'] = $this->app->option_manager->get('website_keywords', 'website');
         }
         $meta['og_site_name'] = $this->app->option_manager->get('website_title', 'website');
         if (!empty($meta)) {
             if (isset($meta['content_meta_title']) and $meta['content_meta_title'] != '') {
                 $meta['title'] = $meta['content_meta_title'];
             } elseif (isset($meta['title']) and $meta['title'] != '') {
             } else {
                 $meta['title'] = $this->app->option_manager->get('website_title', 'website');
             }
             if (isset($meta['description']) and $meta['description'] != '') {
             } else {
                 $meta['description'] = $this->app->option_manager->get('website_description', 'website');
             }
             if (isset($meta['description']) and $meta['description'] != '') {
                 $meta['content_meta_description'] = strip_tags($meta['description']);
                 unset($meta['description']);
             } elseif (isset($meta['content']) and $meta['content'] != '') {
                 $meta['content_meta_description'] = strip_tags($meta['content']);
             } elseif (isset($meta['title']) and $meta['title'] != '') {
                 $meta['content_meta_description'] = strip_tags($meta['title']);
             }
             if (isset($meta['title']) and $meta['title'] != '') {
                 $meta['content_meta_title'] = strip_tags($meta['title']);
             } elseif (isset($found_mod) and $found_mod != false) {
                 $meta['content_meta_title'] = ucwords(str_replace('/', ' ', $found_mod));
             } else {
                 $meta['content_meta_title'] = ucwords(str_replace('/', ' ', $this->app->url_manager->segment(0)));
             }
             if (isset($meta['content_meta_keywords']) and $meta['content_meta_keywords'] != '') {
             } else {
                 $meta['content_meta_keywords'] = $this->app->option_manager->get('website_keywords', 'website');
             }
             if (is_array($meta)) {
                 foreach ($meta as $key => $item) {
                     if (is_string($item)) {
                         $item = html_entity_decode($item);
                         $item = strip_tags($item);
                         $item = str_replace('&amp;zwnj;', ' ', $item);
                         $item = str_replace('"', ' ', $item);
                         $item = str_replace("'", ' ', $item);
                         $item = str_replace('>', '', $item);
                         $item = str_replace('&amp;quot;', ' ', $item);
                         $item = str_replace('quot;', ' ', $item);
                         $item = str_replace('&amp;', ' ', $item);
                         $item = str_replace('amp;', ' ', $item);
                         $item = str_replace('nbsp;', ' ', $item);
                         $item = str_replace('#039;', ' ', $item);
                         $item = str_replace('&amp;nbsp;', ' ', $item);
                         $item = str_replace('&', ' ', $item);
                         $item = str_replace(';', ' ', $item);
                         $item = str_replace('  ', ' ', $item);
                         $item = str_replace(' ', ' ', $item);
                         $l = str_replace('{' . $key . '}', $item, $l);
                     } elseif ($item == false) {
                         $l = str_replace('{' . $key . '}', '', $l);
                     }
                 }
             }
         }
         if ($page != false and empty($this->page)) {
             $this->page = $page;
         }
         $l = execute_document_ready($l);
         event_trigger('frontend');
         $is_embed = $this->app->url_manager->param('embed');
         if ($is_embed != false) {
             $this->isolate_by_html_id = $is_embed;
         }
         if ($this->isolate_by_html_id != false) {
             $id_sel = $this->isolate_by_html_id;
             $this->isolate_by_html_id = false;
             require_once MW_PATH . 'Utils' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'phpQuery.php';
             $pq = \phpQuery::newDocument($l);
             foreach ($pq['#' . $id_sel] as $elem) {
                 $l = pq($elem)->htmlOuter();
             }
         }
         if (mw()->user_manager->session_id() and !(mw()->user_manager->session_all() == false) and $is_editmode) {
             session_set('last_content_id', CONTENT_ID);
         }
         if ($output_cache_timeout != false) {
             $this->app->cache_manager->save($l, $output_cache_id, $output_cache_group);
         }
         if (isset($_REQUEST['debug'])) {
             if ($this->app->make('config')->get('app.debug')) {
                 $is_admin = $this->app->user_manager->is_admin();
                 if ($is_admin == true) {
                     include mw_includes_path() . 'debug.php';
                 }
             }
         }
         if ($show_404_to_non_admin) {
             $response = \Response::make($l);
             $response->setStatusCode(404);
             return $response;
         }
         return $l;
     } else {
         echo 'Error! Page is not found? Please login in the admin and make a page.';
         $this->app->cache_manager->clear();
         return;
     }
 }
Ejemplo n.º 2
0
 private function _replace_editable_fields($layout, $no_cache = false)
 {
     if ($layout != '') {
         global $mw_replaced_edit_fields_vals;
         global $mw_parser_nest_counter_level;
         global $mw_replaced_edit_fields_vals_inner;
         $mw_parser_nest_counter_level++;
         $replaced_code_tags = array();
         if ($this->_mw_parser_passed_replaces == null) {
             $this->_mw_parser_passed_replaces = array();
         }
         $mw_found_elems = '';
         $mw_found_elems_arr = array();
         $mw_elements_array = array('orig', $layout);
         $cached = false;
         if (!isset($parser_mem_crc)) {
             $parser_mem_crc = 'parser_' . crc32($layout) . content_id();
             $parser_modules_crc = 'parser_modules' . crc32($layout) . content_id();
         }
         if (isset($this->_mw_parser_passed_replaces[$parser_mem_crc])) {
             return $this->_mw_parser_passed_replaces[$parser_mem_crc];
         }
         if (isset($mw_replaced_edit_fields_vals[$parser_mem_crc])) {
             // return false;
             return $mw_replaced_edit_fields_vals[$parser_mem_crc];
         }
         $script_pattern = "/<pre[^>]*>(.*)<\\/pre>/Uis";
         preg_match_all($script_pattern, $layout, $mw_script_matches);
         if (!empty($mw_script_matches)) {
             foreach ($mw_script_matches[0] as $key => $value) {
                 if ($value != '') {
                     $v1 = crc32($value);
                     $v1 = '<!-- mw_replace_back_this_pre_' . $v1 . ' -->';
                     $layout = str_replace($value, $v1, $layout);
                     if (!isset($replaced_code_tags[$v1])) {
                         $replaced_code_tags[$v1] = $value;
                     }
                 }
             }
         }
         $script_pattern = "/<code[^>]*>(.*)<\\/code>/Uis";
         preg_match_all($script_pattern, $layout, $mw_script_matches);
         if (!empty($mw_script_matches)) {
             foreach ($mw_script_matches[0] as $key => $value) {
                 if ($value != '') {
                     $v1 = crc32($value);
                     $v1 = '<!-- mw_replace_back_this_pre_code_' . $v1 . ' -->';
                     $layout = str_replace($value, $v1, $layout);
                     if (!isset($replaced_code_tags[$v1])) {
                         $replaced_code_tags[$v1] = $value;
                     }
                 }
             }
         }
         $ch = mw_var($parser_mem_crc);
         if ($cached != false) {
             $mw_elements_array = $cached;
         } else {
             if ($ch != false) {
                 $layout = $ch;
             } else {
                 require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'phpQuery.php';
                 $pq = \phpQuery::newDocument($layout);
                 $els = $pq['.edit'];
                 $is_editable = true;
                 foreach ($els as $elem) {
                     // iteration returns PLAIN dom nodes, NOT phpQuery objects
                     $tagName = $elem->tagName;
                     $name = pq($elem)->attr('field');
                     if (strval($name) == '') {
                         $name = pq($elem)->attr('data-field');
                     }
                     $rel = pq($elem)->attr('rel');
                     if ($rel == false) {
                         $rel = pq($elem)->attr('data-rel');
                         if ($rel == false) {
                             $rel = 'page';
                         }
                     }
                     $option_group = pq($elem)->attr('data-option_group');
                     if ($option_group == false) {
                         $option_group = 'editable_region';
                     }
                     $data_id = pq($elem)->attr('data-id');
                     if ($data_id == false) {
                         $data_id = pq($elem)->attr('rel-id');
                     }
                     if ($data_id == false) {
                         $data_id = pq($elem)->attr('rel_id');
                     }
                     if ($data_id == false) {
                         $data_id = pq($elem)->attr('data-rel-id');
                     }
                     $option_mod = pq($elem)->attr('data-module');
                     if ($option_mod == false) {
                         $option_mod = pq($elem)->attr('data-type');
                     }
                     if ($option_mod == false) {
                         $option_mod = pq($elem)->attr('type');
                     }
                     $name = trim($name);
                     $get_global = false;
                     $field = $name;
                     $use_id_as_field = $name;
                     if ($rel == 'global') {
                         $get_global = true;
                     } else {
                         $get_global = false;
                     }
                     $try_inherited = false;
                     //
                     if ($rel == 'content') {
                         if (!isset($data_id) or $data_id == false) {
                             $data_id = content_id();
                         }
                         $get_global = false;
                         $data_id = intval($data_id);
                         $data = $this->app->content_manager->get_by_id($data_id);
                     } else {
                         if ($rel == 'page') {
                             if (!isset($data_id) or $data_id == false) {
                                 $data_id = PAGE_ID;
                             }
                             if (!isset($data_id) or $data_id == false) {
                                 $data_id = content_id();
                             }
                             $data = $this->app->content_manager->get_by_id($data_id);
                             $get_global = false;
                         } else {
                             if ($rel == 'post') {
                                 $get_global = false;
                                 if (!isset($data_id) or $data_id == false) {
                                     $data_id = POST_ID;
                                 }
                                 if (!isset($data_id) or $data_id == false) {
                                     $data_id = PAGE_ID;
                                 }
                                 $data = $this->app->content_manager->get_by_id($data_id);
                             } else {
                                 if ($rel == 'inherit') {
                                     $get_global = false;
                                     if (!isset($data_id) or $data_id == false) {
                                         $data_id = PAGE_ID;
                                     }
                                     $data_inh_check = $this->app->content_manager->get_by_id($data_id);
                                     if (isset($data_inh_check['id']) and isset($data_inh_check['layout_file']) and trim($data_inh_check['layout_file']) != '' and $data_inh_check['layout_file'] != 'inherit') {
                                         $inh = $data_inh_check['id'];
                                     } else {
                                         $inh = $this->app->content_manager->get_inherited_parent($data_id);
                                     }
                                     if ($inh != false and intval($inh) != 0) {
                                         $try_inherited = true;
                                         $data_id = $inh;
                                         $rel = 'content';
                                         $data = $this->app->content_manager->get_by_id($data_id);
                                     } else {
                                         $rel = 'content';
                                         $data = $this->app->content_manager->get_page($data_id);
                                     }
                                 } else {
                                     if ($rel == 'global') {
                                         $get_global = 1;
                                         $cont_field = false;
                                     } else {
                                         if (isset($attr['post'])) {
                                             $get_global = false;
                                             $data = $this->app->content_manager->get_by_id($attr['post']);
                                             if ($data == false) {
                                                 $data = $this->app->content_manager->get_page($attr['post']);
                                             }
                                         } else {
                                             if (isset($attr['category'])) {
                                                 $get_global = false;
                                                 $data = $this->app->category_manager->get_by_id($attr['category']);
                                             } else {
                                                 if (isset($attr['global'])) {
                                                     $get_global = true;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $cf = false;
                     $field_content = false;
                     $orig_rel = $rel;
                     $this->_current_parser_rel = $rel;
                     if (!empty($this->filter)) {
                         foreach ($this->filter as $filter) {
                             if (isset($data)) {
                                 $new_data = call_user_func($filter, $data, $elem);
                                 if (is_array($new_data) and !empty($new_data)) {
                                     $data = array_merge($data, $new_data);
                                 }
                             }
                         }
                     }
                     if (isset($data[$field])) {
                         if (isset($data[$field])) {
                             $field_content = $data[$field];
                         }
                     } else {
                         if ($rel == 'page') {
                             $rel = 'content';
                         }
                         if ($rel == 'post') {
                             $rel = 'content';
                         }
                         $cont_field = false;
                         if (isset($data_id) and $data_id != 0 and trim($data_id) != '' and trim($field) != '') {
                             $cont_field = $this->app->content_manager->edit_field("rel_type={$rel}&field={$field}&rel_id={$data_id}");
                             if ($cont_field == false and $try_inherited == true) {
                                 $inh = $this->app->content_manager->get_inherited_parent($data_id);
                                 if ($inh != false and intval($inh) != 0 and $inh != $data_id) {
                                     $data_id = $inh;
                                     $cont_field2 = $this->app->content_manager->edit_field("rel_type={$rel}&field={$field}&rel_id={$inh}");
                                     if ($cont_field2 != false) {
                                         $rel = 'content';
                                         $data = $this->app->content_manager->get_by_id($inh);
                                         $cont_field = $cont_field2;
                                     }
                                 }
                             }
                         } else {
                             if (isset($data_id) and trim($data_id) != '' and $field_content == false and isset($rel) and isset($field) and trim($field) != '') {
                                 $cont_field = $this->app->content_manager->edit_field("rel_type={$rel}&field={$field}&rel_id={$data_id}");
                                 if ($cont_field != false) {
                                     $field_content = $cont_field;
                                 }
                             } else {
                                 $field_content = $cont_field = $this->app->content_manager->edit_field("rel_type={$rel}&field={$field}");
                             }
                         }
                         if ($cont_field != false) {
                             $field_content = $cont_field;
                         }
                         $mw_replaced_edit_fields_vals[$parser_mem_crc] = $field_content;
                     }
                     if ($rel == 'global') {
                         $field_content = false;
                         $get_global = 1;
                     }
                     //   $filter
                     $this->_current_parser_rel = $rel;
                     $no_edit = false;
                     if ($field_content == false) {
                         if ($get_global == true) {
                             if (isset($data_id)) {
                                 $cont_field = $this->app->content_manager->edit_field("rel_type={$rel}&field={$field}&rel_id={$data_id}");
                             }
                             if (isset($cont_field) and !empty($cont_field)) {
                                 $cont_field = $this->app->content_manager->edit_field("rel_type={$rel}&field={$field}");
                             }
                             if ($cont_field == false) {
                                 if ($option_mod != false) {
                                     $field_content = $this->app->content_manager->edit_field("rel_type={$option_group}&field={$field}");
                                 } else {
                                     $field_content = $this->app->content_manager->edit_field("rel_type={$option_group}&field={$field}");
                                 }
                             } else {
                                 $field_content = $cont_field;
                             }
                         } else {
                             if ($use_id_as_field != false) {
                                 if (isset($data[$use_id_as_field])) {
                                     $field_content = $data[$use_id_as_field];
                                 }
                             }
                             if ($field_content == false) {
                                 if (isset($data_id) and $data_id != false) {
                                     $cont_field = $this->app->content_manager->edit_field("rel_type={$orig_rel}&field={$field}&rel_id={$data_id}");
                                 } else {
                                     $cont_field = $this->app->content_manager->edit_field("rel_type={$orig_rel}&field={$field}&rel_id=" . PAGE_ID);
                                 }
                             }
                             if (isset($data[$field])) {
                                 $field_content = $data[$field];
                             } else {
                                 if (isset($cont_field) and $cont_field != false) {
                                     $field_content = $cont_field;
                                 }
                             }
                         }
                         if ($field == 'content' and template_var('content') != false) {
                             $field_content = template_var('content');
                             template_var('content', false);
                             $no_edit = template_var('no_edit');
                         }
                         if (isset($data_id) and trim($data_id) != '' and $field_content == false and isset($rel) and isset($field) and trim($field) != '') {
                             $cont_field = $this->app->content_manager->edit_field("rel_type={$rel}&field={$field}&rel_id={$data_id}");
                             if ($cont_field != false) {
                                 $field_content = $cont_field;
                             }
                         } else {
                             if ($field_content == false and isset($rel) and isset($field) and trim($field) != '') {
                                 $cont_field = $this->app->content_manager->edit_field("rel_type={$rel}&field={$field}");
                                 if ($cont_field != false) {
                                     $field_content = $cont_field;
                                 }
                             }
                         }
                     }
                     if ($field_content != false and $field_content != '' and is_string($field_content)) {
                         $parser_mem_crc2 = 'parser_field_content_' . $field . $rel . $data_id . crc32($field_content);
                         $ch2 = mw_var($parser_mem_crc);
                         if ($ch2 == false) {
                             $this->_mw_parser_passed_hashes[] = $parser_mem_crc2;
                             if (!isset($mw_replaced_edit_fields_vals[$parser_mem_crc2]) and $field_content != false and $field_content != '') {
                                 $mw_replaced_edit_fields_vals[$parser_mem_crc2] = $ch2;
                                 $parser_mem_crc3 = 'mw_replace_back_this_editable_' . $parser_mem_crc2 . '';
                                 $mw_found_elems = ',' . $parser_mem_crc2;
                                 $mw_found_elems_arr[$parser_mem_crc2] = $field_content;
                                 // $rep = pq($elem)->html();
                                 $rep = pq($elem)->html();
                                 if ($no_edit != false or isset($data) and isset($data['no_edit']) and $data['no_edit'] != false) {
                                     $is_editable = false;
                                     if ($is_editable === false) {
                                         pq($elem)->removeClass('edit');
                                     } else {
                                     }
                                     $is_editable = 1;
                                 }
                                 $mw_replaced_edit_fields_vals_inner[$parser_mem_crc3] = array('s' => $rep, 'r' => $field_content);
                             }
                         }
                         mw_var($parser_mem_crc2, 1);
                     }
                 }
                 $layout = $pq->htmlOuter();
                 $pq->__destruct();
                 $pq = null;
                 unset($pq);
                 if (!empty($mw_replaced_edit_fields_vals_inner)) {
                     $reps_arr = array();
                     $reps_arr2 = array();
                     foreach ($mw_replaced_edit_fields_vals_inner as $k => $v) {
                         $repc = 1;
                         if (isset($v['s'])) {
                             $reps_arr[] = $v['s'];
                             $reps_arr2[] = $v['r'];
                             $layout = $this->_str_replace_first($v['s'], $v['r'], $layout, $repc);
                             unset($mw_replaced_edit_fields_vals_inner[$k]);
                         }
                     }
                     // $layout = str_replace($reps_arr, $reps_arr2, $layout,$repc);
                 }
                 mw_var($parser_mem_crc, $layout);
                 if ($mw_found_elems != '') {
                     $mw_elements_array['new'] = $layout;
                     $mw_elements_array['to_replace'] = $mw_found_elems;
                     $mw_elements_array['elems'] = $mw_found_elems_arr;
                 } else {
                     $mw_elements_array['new'] = $layout;
                 }
             }
         }
     }
     if (isset($mw_elements_array) and !empty($mw_elements_array)) {
         if (isset($mw_elements_array['elems']) and isset($mw_elements_array['to_replace']) and isset($mw_elements_array['new'])) {
             $modified_layout = $mw_elements_array['new'];
             $reps = $mw_elements_array['elems'];
             $c = 1;
             foreach ($reps as $elk => $value) {
                 $elk_crc = crc32($elk);
                 $global_holder_hash = 'replaced' . $elk_crc;
                 if (!isset($mw_replaced_edit_fields_vals[$global_holder_hash])) {
                     $this->_mw_parser_passed_replaces[] = $elk_crc;
                     $mw_replaced_edit_fields_vals[$global_holder_hash] = $modified_layout;
                     if ($value != '') {
                         $val_rep = $value;
                         $val_rep = $this->_replace_editable_fields($val_rep, true);
                         $rep = 'mw_replace_back_this_editable_' . $elk . '';
                         $ct = 1;
                         //   $modified_layout = str_replace($rep, $val_rep, $modified_layout,$ct);
                         $modified_layout = $this->_str_replace_first($rep, $val_rep, $modified_layout);
                     }
                 } else {
                     $rep = 'mw_replace_back_this_editable_' . $elk . '';
                     $modified_layout = $this->_str_replace_first($rep, $value, $modified_layout);
                     // $modified_layout = str_replace($rep, $value, $modified_layout);
                 }
             }
             $layout = $modified_layout;
             $mw_replaced_edit_fields_vals[$parser_mem_crc] = $layout;
         }
         if (!empty($replaced_code_tags)) {
             foreach ($replaced_code_tags as $key => $value) {
                 if ($value != '') {
                     $layout = str_replace($key, $value, $layout);
                 }
                 unset($replaced_code_tags[$key]);
             }
         }
         if ($no_cache == false) {
             //    $this->app->cache_manager->save($layout, $parser_mem_crc, 'content_fields/global/parser');
         }
     }
     $this->_mw_parser_passed_replaces[$parser_mem_crc] = $layout;
     $mw_replaced_edit_fields_vals[$parser_mem_crc] = $layout;
     return $layout;
 }
<?php 
template_var($parse_dashboard, array());
?>

<?php 
foreach ($parse_dashboard as $value) {
    switch ($value['_TYPE']) {
        case 'GROUP':
            ?>
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            <h3 class="panel-title"><?php 
            echo $value['_LABEL'];
            ?>
</h3>
                        </div>
                        <div class="panel-body">
                            <?php 
            $this->load->view('templates/mdi_admin_dashboard_render_t', array('parse_dashboard' => $value['_CHILDREN']));
            ?>
                        </div>
                    </div>
                <?php 
            break;
        case 'MODEL':
            ?>
                    <a href="<?php 
            echo $value['_LINK'];
            ?>
" style="text-decoration: none;">
Ejemplo n.º 4
0
<?php

$this->mdi->statics_lazy('js', 'mdi/admin/admin-message.js');
?>

<?php 
template_var($type, 'info');
template_var($url, '');
template_var($title, '');
template_var($message, '');
template_var($method, 'link');
template_var($data, NULL);
?>

<div class="message container">
    <div class="alert alert-<?php 
echo $type;
?>
" role="alert">
        <strong><?php 
echo $title;
?>
</strong> <?php 
echo $message;
?>
    </div>
    <div class="text-right">
        <?php 
if ($method == 'link') {
    ?>
            <a href="<?php 
Ejemplo n.º 5
0
<?php

$is_new = template_var('new_page');
$data = array();
$data['id'] = 0;
$data['content_type'] = 'page';
$data['title'] = false;
$data['content'] = false;
$data['url'] = '';
$data['thumbnail'] = '';
$data['is_active'] = 1;
$data['is_home'] = 0;
$data['is_shop'] = 0;
$data['require_login'] = '******';
$data['subtype'] = 'static';
$data['description'] = '';
$data['active_site_template'] = '';
$data['subtype_value'] = '';
$data['parent'] = 0;
$data['layout_name'] = '';
$data['layout_file'] = '';
$data['original_link'] = '';
if ($is_new == false) {
} else {
    foreach ($is_new as $k => $v) {
        $data[$k] = $v;
    }
}
if (!isset($title_placeholder)) {
    $title_placeholder = false;
}
<?php 
template_var($parse_fields, array());
?>

<table class="table table-bordered" style="margin-bottom: 0;">
    <tbody>
    <?php 
foreach ($parse_fields as $field) {
    ?>
                <tr>
                    <?php 
    if (array_key_exists('_REQUIRED', $field) && $field['_REQUIRED']) {
        $required_text = '* ';
    } else {
        $required_text = '';
    }
    ?>
                    <td class="active text-right" style="width: 20%;">
                        <h4><?php 
    echo $required_text . $field['_LABEL'];
    ?>
</h4>
                    </td>
                    <td>
                        <?php 
    if (array_key_exists('_ERROR', $field)) {
        ?>
                            <div class="form-group has-error">
                        <?php 
    } else {