/** * Defines all constants that are needed to parse the page layout * * It accepts array or $content that must have $content['id'] set * * @example * <code> * Define constants for some page * $ref_page = $this->get_by_id(1); * $this->define_constants($ref_page); * print PAGE_ID; * print POST_ID; * print CATEGORY_ID; * print MAIN_PAGE_ID; * print DEFAULT_TEMPLATE_DIR; * print DEFAULT_TEMPLATE_URL; * </code> * * @package Content * @subpackage Advanced * @const PAGE_ID Defines the current page id * @const POST_ID Defines the current post id * @const CATEGORY_ID Defines the current category id if any * @const ACTIVE_PAGE_ID Same as PAGE_ID * @const CONTENT_ID current post or page id * @const MAIN_PAGE_ID the parent page id * @const DEFAULT_TEMPLATE_DIR the directory of the site's default template * @const DEFAULT_TEMPLATE_URL the url of the site's default template * * * * @param array|bool $content * @option integer "id" [description] * @option string "content_type" [description] * @return void */ public function define_constants($content = false) { if ($content == false) { if (isset($_SERVER['HTTP_REFERER'])) { $ref_page = $_SERVER['HTTP_REFERER']; if ($ref_page != '') { $ref_page = $this->get_by_url($ref_page); if ($ref_page != false and !empty($ref_page)) { $content = $ref_page; } } } } $page = false; if (is_array($content)) { if (!isset($content['active_site_template']) and isset($content['id']) and $content['id'] != 0) { $content = $this->get_by_id($content['id']); $page = $content; } else { if (isset($content['id']) and $content['id'] == 0) { $page = $content; } else { if (isset($content['active_site_template'])) { $page = $content; } } } if ($page == false) { $page = $content; } } if (is_array($page)) { if (isset($page['content_type']) and ($page['content_type'] == "post" or $page['content_type'] != "page")) { if (isset($page['id']) and $page['id'] != 0) { $content = $page; $current_categorys = $this->app->category_manager->get_for_content($page['id']); if (!empty($current_categorys)) { $current_category = end($current_categorys); if (defined('CATEGORY_ID') == false and isset($current_category['id'])) { define('CATEGORY_ID', $current_category['id']); } } $page = $this->get_by_id($page['parent']); if (defined('POST_ID') == false) { define('POST_ID', $content['id']); } if ($page['content_type'] == "product") { if (defined('PRODUCT_ID') == false) { define('PRODUCT_ID', $content['id']); } } } } else { $content = $page; if (defined('POST_ID') == false) { define('POST_ID', false); } } if (defined('ACTIVE_PAGE_ID') == false) { if (!isset($page['id'])) { $page['id'] = 0; } define('ACTIVE_PAGE_ID', $page['id']); } if (!defined('CATEGORY_ID')) { //define('CATEGORY_ID', $current_category['id']); } if (defined('CATEGORY_ID') == false) { $cat_url = $this->app->url_manager->param('category', $skip_ajax = true); if ($cat_url != false) { define('CATEGORY_ID', intval($cat_url)); } } if (!defined('CATEGORY_ID')) { define('CATEGORY_ID', false); } if (defined('CONTENT_ID') == false and isset($content['id'])) { define('CONTENT_ID', $content['id']); } if (defined('PAGE_ID') == false and isset($content['id'])) { define('PAGE_ID', $page['id']); } if (isset($page['parent'])) { $parent_page_check_if_inherited = $this->get_by_id($page['parent']); if (isset($parent_page_check_if_inherited["layout_file"]) and $parent_page_check_if_inherited["layout_file"] == 'inherit') { $inherit_from_id = $this->get_inherited_parent($parent_page_check_if_inherited["id"]); if (defined('MAIN_PAGE_ID') == false) { define('MAIN_PAGE_ID', $inherit_from_id); } } //$root_parent = $this->get_inherited_parent($page['parent']); // $this->get_inherited_parent($page['id']); // if ($par_page != false) { // $par_page = $this->get_by_id($page['parent']); // } if (defined('ROOT_PAGE_ID') == false) { $root_page = $this->get_parents($page['id']); if (!empty($root_page) and isset($root_page[0])) { $root_page[0] = end($root_page); } else { $root_page[0] = $page['parent']; } define('ROOT_PAGE_ID', $root_page[0]); } if (defined('MAIN_PAGE_ID') == false) { if ($page['parent'] == 0) { define('MAIN_PAGE_ID', $page['id']); } else { define('MAIN_PAGE_ID', $page['parent']); } } if (defined('PARENT_PAGE_ID') == false) { define('PARENT_PAGE_ID', $page['parent']); } } } if (defined('ACTIVE_PAGE_ID') == false) { define('ACTIVE_PAGE_ID', false); } if (defined('CATEGORY_ID') == false) { define('CATEGORY_ID', false); } if (defined('CONTENT_ID') == false) { define('CONTENT_ID', false); } if (defined('POST_ID') == false) { define('POST_ID', false); } if (defined('PAGE_ID') == false) { define('PAGE_ID', false); } if (defined('MAIN_PAGE_ID') == false) { define('MAIN_PAGE_ID', false); } if (isset($page) and isset($page['active_site_template']) and $page['active_site_template'] != '' and strtolower($page['active_site_template']) != 'inherit' and strtolower($page['active_site_template']) != 'default') { $the_active_site_template = $page['active_site_template']; } else { if (isset($page) and isset($page['active_site_template']) and $page['active_site_template'] != '' and strtolower($page['active_site_template']) != 'default') { $the_active_site_template = $page['active_site_template']; } else { if (isset($content) and isset($content['active_site_template']) and $content['active_site_template'] != '' and strtolower($content['active_site_template']) != 'default') { $the_active_site_template = $content['active_site_template']; } else { $the_active_site_template = $this->app->option_manager->get('current_template', 'template'); // } } } if (isset($content['parent']) and $content['parent'] != 0 and isset($content['layout_file']) and $content['layout_file'] == 'inherit') { $inh = $this->get_inherited_parent($content['id']); if ($inh != false) { $inh_parent = $this->get_by_id($inh); if (isset($inh_parent['active_site_template']) and $inh_parent['active_site_template'] != '' and strtolower($inh_parent['active_site_template']) != 'default') { $the_active_site_template = $inh_parent['active_site_template']; } else { if (isset($inh_parent['active_site_template']) and $inh_parent['active_site_template'] != '' and strtolower($inh_parent['active_site_template']) == 'default') { $the_active_site_template = $this->app->option_manager->get('current_template', 'template'); } else { if (isset($inh_parent['active_site_template']) and $inh_parent['active_site_template'] == '') { $the_active_site_template = $this->app->option_manager->get('current_template', 'template'); } } } } } if (isset($the_active_site_template) and $the_active_site_template != 'default' and $the_active_site_template == 'mw_default') { $the_active_site_template = 'default'; } if ($the_active_site_template == false) { $the_active_site_template = 'default'; } if (defined('THIS_TEMPLATE_DIR') == false and $the_active_site_template != false) { define('THIS_TEMPLATE_DIR', templates_path() . $the_active_site_template . DS); } if (defined('THIS_TEMPLATE_FOLDER_NAME') == false and $the_active_site_template != false) { define('THIS_TEMPLATE_FOLDER_NAME', $the_active_site_template); } $the_active_site_template_dir = normalize_path(templates_path() . $the_active_site_template . DS); if (defined('DEFAULT_TEMPLATE_DIR') == false) { define('DEFAULT_TEMPLATE_DIR', templates_path() . 'default' . DS); } if (defined('DEFAULT_TEMPLATE_URL') == false) { define('DEFAULT_TEMPLATE_URL', templates_url() . '/default/'); } if (trim($the_active_site_template) != 'default') { if (!strstr($the_active_site_template, DEFAULT_TEMPLATE_DIR)) { $use_default_layouts = $the_active_site_template_dir . 'use_default_layouts.php'; if (is_file($use_default_layouts)) { if (isset($page['layout_file'])) { $template_view = DEFAULT_TEMPLATE_DIR . $page['layout_file']; } else { $template_view = DEFAULT_TEMPLATE_DIR; } if (isset($page)) { if (!isset($page['layout_file']) or (isset($page['layout_file']) and $page['layout_file'] == 'inherit' or $page['layout_file'] == '')) { $par_page = $this->get_inherited_parent($page['id']); if ($par_page != false) { $par_page = $this->get_by_id($par_page); } if (isset($par_page['layout_file'])) { $the_active_site_template = $par_page['active_site_template']; $page['layout_file'] = $par_page['layout_file']; $page['active_site_template'] = $par_page['active_site_template']; $template_view = templates_path() . $page['active_site_template'] . DS . $page['layout_file']; } } } if (is_file($template_view) == true) { if (defined('THIS_TEMPLATE_DIR') == false) { define('THIS_TEMPLATE_DIR', templates_path() . $the_active_site_template . DS); } if (defined('THIS_TEMPLATE_URL') == false) { $the_template_url = templates_url() . '/' . $the_active_site_template; $the_template_url = $the_template_url . '/'; if (defined('THIS_TEMPLATE_URL') == false) { define("THIS_TEMPLATE_URL", $the_template_url); } if (defined('TEMPLATE_URL') == false) { define("TEMPLATE_URL", $the_template_url); } } $the_active_site_template = 'default'; $the_active_site_template_dir = DEFAULT_TEMPLATE_DIR; } } } } if (defined('ACTIVE_TEMPLATE_DIR') == false) { define('ACTIVE_TEMPLATE_DIR', $the_active_site_template_dir); } if (defined('THIS_TEMPLATE_DIR') == false) { define('THIS_TEMPLATE_DIR', $the_active_site_template_dir); } if (defined('THIS_TEMPLATE_URL') == false) { $the_template_url = templates_url() . '/' . $the_active_site_template; $the_template_url = $the_template_url . '/'; if (defined('THIS_TEMPLATE_URL') == false) { define("THIS_TEMPLATE_URL", $the_template_url); } } if (defined('TEMPLATE_NAME') == false) { define('TEMPLATE_NAME', $the_active_site_template); } if (defined('TEMPLATE_DIR') == false) { define('TEMPLATE_DIR', $the_active_site_template_dir); } if (defined('ACTIVE_SITE_TEMPLATE') == false) { define('ACTIVE_SITE_TEMPLATE', $the_active_site_template); } if (defined('TEMPLATES_DIR') == false) { define('TEMPLATES_DIR', templates_path()); } $the_template_url = templates_url() . $the_active_site_template; $the_template_url = $the_template_url . '/'; if (defined('TEMPLATE_URL') == false) { define("TEMPLATE_URL", $the_template_url); } if (defined('LAYOUTS_DIR') == false) { $layouts_dir = TEMPLATE_DIR . 'layouts/'; define("LAYOUTS_DIR", $layouts_dir); } else { $layouts_dir = LAYOUTS_DIR; } if (defined('LAYOUTS_URL') == false) { $layouts_url = reduce_double_slashes($this->app->url_manager->link_to_file($layouts_dir) . '/'); define("LAYOUTS_URL", $layouts_url); } return true; }
function template_save_css($params) { $is_admin = $this->app->user_manager->is_admin(); if ($is_admin == false) { return false; } if (is_string($params)) { $params = parse_params($params); } $ref_page = false; if (!isset($params['active_site_template'])) { if (!isset($params['content_id'])) { if (isset($_SERVER['HTTP_REFERER'])) { $ref_page_url = $_SERVER['HTTP_REFERER']; if ($ref_page_url != '') { $ref_page_url_rel = str_ireplace(site_url(), '', $ref_page_url); if ($ref_page_url_rel == '') { $ref_page1 = $this->app->content_manager->homepage(); } else { $ref_page1 = $this->app->content_manager->get_by_url($ref_page_url, true); } if (isset($ref_page1['id'])) { $ref_page = $this->app->content_manager->get_by_id(intval($ref_page1['id'])); } } } } else { $ref_page = $this->app->content_manager->get_by_id(intval($params['content_id'])); } if (isset($ref_page['id']) and isset($ref_page['content_type']) and $ref_page['content_type'] != 'page') { $ref_page_parent = $this->app->content_manager->get_by_id(intval($ref_page['id'])); if (isset($ref_page_partent['parent']) and intval($ref_page_partent['parent']) != 0) { $ref_page = $this->app->content_manager->get_by_id(intval($ref_page_partent['id'])); } else { $ref_page_parents = $this->app->content_manager->get_parents(intval($ref_page['id'])); if (!empty($ref_page_parents)) { $ref_page_parent = array_pop($ref_page_parents); $ref_page = $this->app->content_manager->get_by_id($ref_page_parent); } } } } else { $ref_page = $params; } if (!is_array($ref_page) or empty($ref_page)) { return false; } $pd = $ref_page; if ($is_admin == true and is_array($pd)) { $save_page = $pd; if (isset($save_page["layout_file"]) and $save_page["layout_file"] == 'inherit') { $inherit_from_id = $this->app->content_manager->get_inherited_parent($save_page["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'])) { $save_page['active_site_template'] = $inherit_from['active_site_template']; $save_page['layout_file'] = $inherit_from['layout_file']; } } $template = false; if (!isset($save_page['active_site_template']) or $save_page['active_site_template'] == '') { $template = 'default'; } else { if (isset($save_page['active_site_template'])) { $template = $save_page['active_site_template']; } } if ($template == 'default') { $site_template_settings = $this->app->option_manager->get('current_template', 'template'); if ($site_template_settings != false and $site_template_settings != 'default') { $template = $site_template_settings; } } $final_file_blocks = array(); if ($template != false) { if (isset($_POST['save_template_settings'])) { $json = json_encode($_POST); $option = array(); $option['option_value'] = $json; $option['option_key'] = 'template_settings'; $option['option_group'] = 'template_' . $template; save_option($option); } $template_folder = templates_path() . $template . DS; $template_url = templates_url() . $template . '/'; $this_template_url = THIS_TEMPLATE_URL; $template_folder = userfiles_path() . 'css' . DS . $template . DS; if (!is_dir($template_folder)) { mkdir_recursive($template_folder); } $live_edit_css = $template_folder . 'live_edit.css'; $fcont = ''; if (is_file($live_edit_css)) { $fcont = file_get_contents($live_edit_css); } $css_cont = $fcont; $css_cont_new = $css_cont; //@import on top $sort_params = array(); $sort_params2 = array(); foreach ($params as $item) { if (isset($item['selector']) and trim($item['selector']) == '@import' and isset($item["value"])) { if ($item['value'] != 'reset') { $sort_params[] = $item; } } else { $sort_params2[] = $item; } } $params = array_merge($sort_params, $sort_params2); foreach ($params as $item) { $curr = ""; if (!isset($item["css"]) and isset($item["property"]) and isset($item['value'])) { if ($item['value'] == 'reset') { $item["css"] = 'reset'; } else { if (isset($item['selector']) and trim($item['selector']) == '@import' and isset($item["value"])) { $props = explode(',', $item['property']); foreach ($props as $prop) { $curr .= $prop . " " . $item['value'] . ";"; } } else { $props = explode(',', $item['property']); $curr = ""; foreach ($props as $prop) { if (isset($item["value"]) and trim($item["value"]) != '') { $curr .= $prop . ":" . $item['value'] . ";"; } } } if ($curr != '') { $item["css"] = $curr; } } } if (isset($item['selector']) and trim($item['selector']) != '' and isset($item["css"])) { $item["selector"] = str_ireplace('.element-current', '', $item["selector"]); $item["selector"] = str_ireplace('.mwfx', '', $item["selector"]); $item["selector"] = str_ireplace('.mw_image_resizer', '', $item["selector"]); $item["selector"] = str_ireplace('.ui-resizable', '', $item["selector"]); $item["selector"] = str_ireplace('.ui-draggable', '', $item["selector"]); $item["css"] = str_ireplace('background:url(;', '', $item["css"]); $item["css"] = str_ireplace('background:;', '', $item["css"]); $item["css"] = str_ireplace('background-image:url(;', '', $item["css"]); $item["css"] = str_ireplace('background-image: url("");', 'background-image: none;', $item["css"]); $sel = trim($item['selector']); $css = trim($item["css"]); if (trim($sel) != '' and strlen($sel) > 2 and strlen($css) > 2) { $delim = "\n /* {$sel} */ \n"; //$item["css"] = str_ireplace($this_template_url, '', $item["css"]); //$item["css"] = str_ireplace($template_url, '', $item["css"]); $item["css"] = str_ireplace('http://', '//', $item["css"]); $item["css"] = str_ireplace('https://', '//', $item["css"]); $is_existing = explode($delim, $css_cont_new); if (!empty($is_existing)) { $srings = $this->app->format->string_between($css_cont_new, $delim, $delim); if ($srings != false) { $css_cont_new = str_ireplace($srings, '', $css_cont_new); $css_cont_new = str_ireplace($delim, '', $css_cont_new); } } if (trim($item["css"]) != 'reset' and trim($item["css"]) != 'reset;') { $css_cont_new .= $delim; if (isset($sel) and trim($sel) == '@import') { $css_cont_new .= $sel . ' ' . $item["css"] . ' '; } else { $css_cont_new .= $sel . ' { ' . $item["css"] . ' }'; } $css_cont_new .= $delim; } } } } $resp = array(); $resp['url'] = $this->app->url_manager->link_to_file($live_edit_css); if ($css_cont_new != '' and $css_cont != $css_cont_new) { file_put_contents($live_edit_css, $css_cont_new); // print $css_cont_new; } $resp['content'] = $css_cont_new; return $resp; } } }
</tr> <tr> <td>userfiles_folder</td> <td><?php print modules_url(); ?> </td> </tr> <tr> <td>site_url</td> <td><?php print site_url(); ?> </td> </tr> <tr> <td>templates_path</td> <td><?php print templates_path(); ?> </td> </tr> <tr> <td>templates_url</td> <td><?php print templates_url(); ?> </td> </tr> </table>
</tr> <tr> <td>userfiles_folder</td> <td><?php echo modules_url(); ?> </td> </tr> <tr> <td>site_url</td> <td><?php echo site_url(); ?> </td> </tr> <tr> <td>templates_path</td> <td><?php echo templates_path(); ?> </td> </tr> <tr> <td>templates_url</td> <td><?php echo templates_url(); ?> </td> </tr> </table>