public function index()
 {
     $is_installed = mw_is_installed();
     if (!$is_installed) {
         if (!$is_installed) {
             $installer = new InstallController();
             return $installer->index();
         }
     } else {
         if (defined('MW_VERSION')) {
             $config_version = Config::get('microweber.version');
             if ($config_version != MW_VERSION) {
                 $this->app->update->post_update(MW_VERSION);
             }
         }
     }
     if (!defined('MW_BACKEND')) {
         define('MW_BACKEND', true);
     }
     //create_mw_default_options();
     mw()->content_manager->define_constants();
     if (defined('TEMPLATE_DIR')) {
         $load_template_functions = TEMPLATE_DIR . 'functions.php';
         if (is_file($load_template_functions)) {
             include_once $load_template_functions;
         }
     }
     event_trigger('mw.admin');
     event_trigger('mw_backend');
     $view = modules_path() . 'admin/';
     $hasNoAdmin = User::where('is_admin', 1)->limit(1)->count();
     if (!$hasNoAdmin) {
         $this->hasNoAdmin();
     }
     $view .= (!$hasNoAdmin ? 'create' : 'index') . '.php';
     $layout = new View($view);
     $layout = $layout->__toString();
     $layout = mw()->parser->process($layout);
     event_trigger('on_load');
     $layout = execute_document_ready($layout);
     event_trigger('mw.admin.header');
     $apijs_loaded = mw()->template->get_apijs_url();
     $apijs_settings_loaded = mw()->template->get_apijs_settings_url();
     $default_css = '<link rel="stylesheet" href="' . mw_includes_url() . 'default.css" type="text/css" />';
     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);
     }
     $template_headers_src = mw()->template->admin_head(true);
     if ($template_headers_src != false and $template_headers_src != '') {
         $layout = str_ireplace('</head>', $template_headers_src . '</head>', $layout, $one);
     }
     return $layout;
 }
Exemple #2
0
function load_all_functions_files_for_modules($options = false)
{
    $is_installed = mw_is_installed();
    if (!$is_installed) {
        return;
    }
    $modules = mw()->modules->get('ui=any&installed=1&limit=99999');
    $files = array();
    if (!empty($modules)) {
        foreach ($modules as $module) {
            if (isset($module['module'])) {
                $is_function = normalize_path(modules_path() . $module['module'] . DS . 'functions.php', false);
                if (is_file($is_function)) {
                    include_once $is_function;
                    $files[] = $is_function;
                }
            }
        }
        return $files;
    }
}
 public function checkout($data)
 {
     return $this->app->checkout_manager->checkout($data);
     $exec_return = false;
     $sid = mw()->user_manager->session_id();
     $sess_order_id = mw()->user_manager->session_get('order_id');
     $cart = array();
     $cart_table = $this->tables['cart'];
     $table_orders = $this->tables['cart_orders'];
     $cart['session_id'] = $sid;
     $cart['order_completed'] = 0;
     $cart['limit'] = 1;
     $mw_process_payment = true;
     $mw_process_payment_success = false;
     $mw_process_payment_failed = false;
     if (isset($_REQUEST['mw_payment_success'])) {
         $mw_process_payment = false;
         $mw_process_payment_success = true;
         $exec_return = true;
     } elseif (isset($_REQUEST['mw_payment_failure'])) {
         $mw_process_payment_failed = true;
         $exec_return = true;
     }
     $cart_table_real = $this->app->database_manager->real_table_name($cart_table);
     $order_table_real = $this->app->database_manager->real_table_name($table_orders);
     if ($exec_return == true) {
         if (isset($_REQUEST['return_to'])) {
             $return_to = urldecode($_REQUEST['return_to']);
             $append = '?';
             if (strstr($return_to, '?')) {
                 $append = '&';
             }
             if ($mw_process_payment_success == true) {
                 $return_to = $return_to . $append . 'mw_payment_success=1';
             } elseif ($mw_process_payment_failed == true) {
                 $return_to = $return_to . $append . 'mw_payment_failure=1';
             }
             return $this->app->url_manager->redirect($return_to);
         }
     }
     $additional_fields = false;
     if (isset($data['for']) and isset($data['for_id'])) {
         $additional_fields = $this->app->fields_manager->get($data['for'], $data['for_id'], 1);
     }
     $seach_address_keys = array('country', 'city', 'address', 'state', 'zip');
     $addr_found_from_search_in_post = false;
     if (isset($data) and is_array($data)) {
         foreach ($data as $k => $v) {
             if (is_array($v)) {
                 foreach ($seach_address_keys as $item) {
                     $case1 = ucfirst($item);
                     if (!isset($data[$item]) and (isset($v[$item]) or isset($v[$case1]))) {
                         $data[$item] = $v[$item];
                         if ($addr_found_from_search_in_post == false) {
                             unset($data[$k]);
                         }
                         $addr_found_from_search_in_post = 1;
                     }
                 }
             }
         }
     }
     $save_custom_fields_for_order = array();
     if (is_array($additional_fields) and !empty($additional_fields)) {
         foreach ($additional_fields as $cf) {
             if (isset($data) and is_array($data)) {
                 foreach ($data as $k => $item) {
                     $key1 = str_replace('_', ' ', $cf['name']);
                     $key2 = str_replace('_', ' ', $k);
                     if ($key1 == $key2) {
                         $save_custom_fields_for_order[$key1] = $this->app->format->clean_html($item);
                     }
                 }
             }
         }
     }
     $checkout_errors = array();
     $check_cart = $this->get_cart($cart);
     if (!is_array($check_cart)) {
         $checkout_errors['cart_empty'] = 'Your cart is empty';
     } else {
         if (!isset($data['payment_gw']) and $mw_process_payment == true) {
             $data['payment_gw'] = 'none';
         } else {
             if ($mw_process_payment == true) {
                 $gw_check = $this->payment_options('payment_gw_' . $data['payment_gw']);
                 if (is_array($gw_check[0])) {
                     $gateway = $gw_check[0];
                 } else {
                     $checkout_errors['payment_gw'] = 'No such payment gateway is activated';
                 }
             }
         }
         $shipping_country = false;
         $shipping_cost_max = false;
         $shipping_cost = false;
         $shipping_cost_above = false;
         if (mw()->user_manager->session_get('shipping_country')) {
             $shipping_country = mw()->user_manager->session_get('shipping_country');
         }
         if (mw()->user_manager->session_get('shipping_cost_max')) {
             $shipping_cost_max = mw()->user_manager->session_get('shipping_cost_max');
         }
         if (mw()->user_manager->session_get('shipping_cost')) {
             $shipping_cost = mw()->user_manager->session_get('shipping_cost');
         }
         if (mw()->user_manager->session_get('shipping_cost_above')) {
             $shipping_cost_above = mw()->user_manager->session_get('shipping_cost_above');
         }
         //post any of those on the form
         $flds_from_data = array('first_name', 'last_name', 'email', 'country', 'city', 'state', 'zip', 'address', 'address2', 'payment_email', 'payment_name', 'payment_country', 'payment_address', 'payment_city', 'payment_state', 'payment_zip', 'phone', 'promo_code', 'payment_gw');
         if (!isset($data['email']) or $data['email'] == '') {
             $checkout_errors['email'] = 'Email is required';
         }
         if (!isset($data['first_name']) or $data['first_name'] == '') {
             $checkout_errors['first_name'] = 'First name is required';
         }
         if (!isset($data['last_name']) or $data['last_name'] == '') {
             $checkout_errors['last_name'] = 'Last name is required';
         }
         if (isset($data['payment_gw']) and $data['payment_gw'] != '') {
             $data['payment_gw'] = str_replace('..', '', $data['payment_gw']);
         }
         $custom_order_id = $this->app->option_manager->get('custom_order_id', 'shop');
         $posted_fields = array();
         $place_order = array();
         $place_order['id'] = false;
         $return_url_after = '';
         if ($this->app->url_manager->is_ajax()) {
             $place_order['url'] = $this->app->url_manager->current(true);
             $return_url_after = '&return_to=' . urlencode($_SERVER['HTTP_REFERER']);
         } elseif (isset($_SERVER['HTTP_REFERER'])) {
             $place_order['url'] = $_SERVER['HTTP_REFERER'];
             $return_url_after = '&return_to=' . urlencode($_SERVER['HTTP_REFERER']);
         } else {
             $place_order['url'] = $this->app->url_manager->current();
         }
         $place_order['session_id'] = $sid;
         $place_order['order_completed'] = 0;
         $items_count = 0;
         foreach ($flds_from_data as $value) {
             if (isset($data[$value]) and $data[$value] != false) {
                 $place_order[$value] = $data[$value];
                 $posted_fields[$value] = $data[$value];
             }
         }
         $amount = $this->cart_total();
         $tax = $this->app->cart_manager->get_tax();
         if (!empty($checkout_errors)) {
             return array('error' => $checkout_errors);
         }
         $place_order['amount'] = $amount;
         $place_order['allow_html'] = true;
         $place_order['currency'] = $this->app->option_manager->get('currency', 'payments');
         if (isset($data['shipping_gw'])) {
             $place_order['shipping_service'] = $data['shipping_gw'];
         }
         $place_order['shipping'] = $shipping_cost;
         if ($tax != 0) {
             $place_order['taxes_amount'] = $tax;
         }
         $items_count = $this->cart_sum(false);
         $place_order['items_count'] = $items_count;
         $cart_checksum = md5($sid . serialize($check_cart) . uniqid());
         $place_order['payment_verify_token'] = $cart_checksum;
         define('FORCE_SAVE', $table_orders);
         if (isset($save_custom_fields_for_order) and !empty($save_custom_fields_for_order)) {
             $place_order['custom_fields_data'] = $this->app->format->array_to_base64($save_custom_fields_for_order);
         }
         if (!isset($place_order['shipping']) or $place_order['shipping'] == false) {
             $place_order['shipping'] = 0;
         }
         $temp_order = $this->app->database_manager->save($table_orders, $place_order);
         if ($temp_order != false) {
             $place_order['id'] = $temp_order;
         } else {
             $place_order['id'] = 0;
         }
         if ($custom_order_id != false) {
             foreach ($place_order as $key => $value) {
                 $custom_order_id = str_ireplace('{' . $key . '}', $value, $custom_order_id);
             }
             $custom_order_id = str_ireplace('{YYYYMMDD}', date('Ymd'), $custom_order_id);
             $custom_order_id = str_ireplace('{date}', date('Y-m-d'), $custom_order_id);
         }
         if ($custom_order_id != false) {
             $place_order['item_name'] = 'Order id:' . ' ' . $custom_order_id;
             $place_order['order_id'] = $custom_order_id;
         } else {
             $place_order['item_name'] = 'Order id:' . ' ' . $place_order['id'];
         }
         if ($mw_process_payment == true) {
             $shop_dir = module_dir('shop');
             $shop_dir = $shop_dir . DS . 'payments' . DS . 'gateways' . DS;
             if ($data['payment_gw'] != 'none') {
                 $gw_process = modules_path() . $data['payment_gw'] . '_process.php';
                 if (!is_file($gw_process)) {
                     $gw_process = normalize_path(modules_path() . $data['payment_gw'] . DS . 'process.php', false);
                 }
                 $mw_return_url = $this->app->url_manager->api_link('checkout') . '?mw_payment_success=1&order_id=' . $place_order['id'] . '&payment_gw=' . $data['payment_gw'] . '&payment_verify_token=' . $place_order['payment_verify_token'] . '&order_id=' . $place_order['id'] . $return_url_after;
                 $mw_cancel_url = $this->app->url_manager->api_link('checkout') . '?mw_payment_failure=1&order_id=' . $place_order['id'] . '&payment_gw=' . $data['payment_gw'] . '&payment_verify_token=' . $place_order['payment_verify_token'] . '&order_id=' . $place_order['id'] . $return_url_after;
                 $mw_ipn_url = $this->app->url_manager->api_link('checkout_ipn') . '?payment_gw=' . $data['payment_gw'] . '&order_id=' . $place_order['id'] . '&payment_verify_token=' . $place_order['payment_verify_token'] . $return_url_after;
                 //                    $place_order['success_url'] = $mw_return_url;
                 //                    $place_order['cancel_url'] = $mw_cancel_url;
                 //                    $place_order['notify_url'] = $mw_ipn_url;
                 if (is_file($gw_process)) {
                     require_once $gw_process;
                 } else {
                     $checkout_errors['payment_gw'] = 'Payment gateway\'s process file not found.';
                 }
             } else {
                 $place_order['order_completed'] = 1;
                 $place_order['is_paid'] = 0;
                 $place_order['success'] = 'Your order has been placed successfully!';
             }
             $place_order['order_status'] = 'pending';
             if (!empty($checkout_errors)) {
                 return array('error' => $checkout_errors);
             }
             $ord = $this->place_order($place_order);
             $place_order['id'] = $ord;
         }
         if (isset($place_order) and !empty($place_order)) {
             if (!isset($place_order['success'])) {
                 $place_order['success'] = 'Your order has been placed successfully!';
             }
             $return = $place_order;
             if (isset($place_order['redirect'])) {
                 $return['redirect'] = $place_order['redirect'];
             }
             return $return;
         }
     }
     if (!empty($checkout_errors)) {
         return array('error' => $checkout_errors);
     }
 }
Exemple #4
0
 public function get_modules_from_current_site_template()
 {
     if (!defined('ACTIVE_TEMPLATE_DIR')) {
         $this->app->content_manager->define_constants();
     }
     $dir_name = ACTIVE_TEMPLATE_DIR . 'modules' . DS;
     if (is_dir($dir_name)) {
         $configs = array();
         $glob_patern = '*config.php';
         $dir = rglob($glob_patern, 0, $dir_name);
         $replace_root = normalize_path($dir_name);
         $def_icon = modules_path() . 'default.png';
         if (!empty($dir)) {
             foreach ($dir as $module) {
                 $module_dir = dirname($module);
                 $module_dir = normalize_path($module_dir);
                 $config = array();
                 include $module;
                 $module_name = str_replace($replace_root, '', $module_dir);
                 $module_name = rtrim($module_name, '\\');
                 $module_name = rtrim($module_name, '/');
                 $config['module'] = $module_name;
                 $config['module'] = rtrim($config['module'], '\\');
                 $config['module'] = rtrim($config['module'], '/');
                 $try_icon = $module_dir . $module_name . '.png';
                 if (is_file($try_icon)) {
                     $config['icon'] = $this->app->url_manager->link_to_file($try_icon);
                 } else {
                     $config['icon'] = $this->app->url_manager->link_to_file($def_icon);
                 }
                 $configs[] = $config;
             }
         }
         return $configs;
     }
 }
Exemple #5
0
    print $mod_obj_str;
    ?>
 = {}

    </script>

<?php 
}
?>

<ul class="modules-list list-<?php 
print $mod_obj_str;
?>
">
    <?php 
$def_icon = modules_path() . 'default.png';
$def_icon = mw()->url_manager->link_to_file($def_icon);
?>
    <?php 
if (isset($dynamic_layouts) and is_array($dynamic_layouts)) {
    ?>
        <?php 
    foreach ($dynamic_layouts as $dynamic_layout) {
        ?>
            <?php 
        if (isset($dynamic_layout['template_dir']) and isset($dynamic_layout['layout_file'])) {
            ?>
                <li data-module-name="layout"
                    template="<?php 
            print $dynamic_layout['template_dir'];
            ?>
<?php

only_admin_access();
$is_shop = false;
if (isset($params['is_shop'])) {
    $is_shop = $params['is_shop'];
}
$dir_name = normalize_path(modules_path());
$posts_mod = $dir_name . 'posts' . DS . 'admin_live_edit_tab1.php';
$set_content_type_mod = 'page';
if (isset($params['global']) and $params['global'] != false) {
    $set_content_type_mod_1 = get_option('data-content-type', $params['id']);
    if ($set_content_type_mod_1 != false and $set_content_type_mod_1 != '') {
        $set_content_type_mod = $set_content_type_mod_1;
    }
}
$add_post_q = '';
if (isset($params['id'])) {
    $add_post_q .= ' module-id="' . $params['id'] . '" ';
}
if (isset($params['content-id'])) {
    $add_post_q .= ' data-content-id=' . $params['content-id'];
}
if (isset($params['related'])) {
    $add_post_q .= ' related=' . $params['related'];
}
$parent_page = false;
$is_global = false;
if (isset($params['global'])) {
    $add_post_q .= ' global=' . $params['global'];
    $is_global = true;
Exemple #7
0
function get_all_functions_files_for_modules($options = false)
{
    if (mw_is_installed() == false) {
        return false;
    }
    $args = func_get_args();
    $function_cache_id = '';
    $function_cache_id = serialize($options);
    $cache_id = $function_cache_id = __FUNCTION__ . crc32($function_cache_id);
    $cache_group = 'modules/global';
    $cache_content = mw()->cache_manager->get($cache_id, $cache_group);
    if ($cache_content != false) {
        return $cache_content;
    }
    if (isset($options['glob'])) {
        $glob_patern = $options['glob'];
    } else {
        $glob_patern = '*functions.php';
    }
    if (isset($options['dir_name'])) {
        $dir_name = $options['dir_name'];
    } else {
        $dir_name = normalize_path(modules_path());
    }
    $installed = mw()->modules->get('ui=any&installed=1');
    $configs = false;
    if (is_array($installed) and !empty($installed)) {
        $configs = array();
        foreach ($installed as $module) {
            if (isset($module['module'])) {
                $file = normalize_path($dir_name . $module['module'] . DS . 'functions.php', false);
                if (is_file($file)) {
                    $configs[] = $file;
                }
            }
        }
    }
    mw()->cache_manager->save($configs, $function_cache_id, $cache_group);
    return $configs;
}
Exemple #8
0
<table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td>modules_url</td>
    <td><?php 
echo modules_url();
?>
</td>
  </tr>
  <tr>
    <td>modules_path</td>
    <td><?php 
echo modules_path();
?>
</td>
  </tr>
  <tr>
    <td>userfiles_path</td>
    <td><?php 
echo userfiles_path();
?>
</td>
  </tr>
  <tr>
    <td>userfiles_folder</td>
    <td><?php 
echo modules_url();
?>
</td>
  </tr>
  <tr>
    <td>site_url</td>
Exemple #9
0
 public function load($module_name, $attrs = array())
 {
     $is_element = false;
     $custom_view = false;
     if (isset($attrs['view'])) {
         $custom_view = $attrs['view'];
         $custom_view = trim($custom_view);
         $custom_view = str_replace('\\', '/', $custom_view);
         $attrs['view'] = $custom_view = str_replace('..', '', $custom_view);
     }
     if ($custom_view != false and strtolower($custom_view) == 'admin') {
         if ($this->app->user_manager->is_admin() == false) {
             mw_error('Not logged in as admin');
         }
     }
     $module_name = trim($module_name);
     $module_name = str_replace('\\', '/', $module_name);
     $module_name = str_replace('..', '', $module_name);
     // prevent hack of the directory
     $module_name = reduce_double_slashes($module_name);
     $module_namei = $module_name;
     if (strstr($module_name, 'admin')) {
         $module_namei = str_ireplace('\\admin', '', $module_namei);
         $module_namei = str_ireplace('/admin', '', $module_namei);
     }
     //$module_namei = str_ireplace($search, $replace, $subject)e
     $uninstall_lock = $this->app->modules->get('one=1&ui=any&module=' . $module_namei);
     if (isset($uninstall_lock["installed"]) and $uninstall_lock["installed"] != '' and intval($uninstall_lock["installed"]) != 1) {
         return '';
     }
     if (!defined('ACTIVE_TEMPLATE_DIR')) {
         $this->app->content_manager->define_constants();
     }
     $module_in_template_dir = ACTIVE_TEMPLATE_DIR . 'modules/' . $module_name . '';
     $module_in_template_dir = normalize_path($module_in_template_dir, 1);
     $module_in_template_file = ACTIVE_TEMPLATE_DIR . 'modules/' . $module_name . '.php';
     $module_in_template_file = normalize_path($module_in_template_file, false);
     $try_file1 = false;
     $mod_d = $module_in_template_dir;
     $mod_d1 = normalize_path($mod_d, 1);
     $try_file1zz = $mod_d1 . 'index.php';
     $in_dir = false;
     if ($custom_view == true) {
         $try_file1zz = $mod_d1 . trim($custom_view) . '.php';
     } else {
         $try_file1zz = $mod_d1 . 'index.php';
     }
     if (is_dir($module_in_template_dir) and is_file($try_file1zz)) {
         $try_file1 = $try_file1zz;
         $in_dir = true;
     } elseif (is_file($module_in_template_file)) {
         $try_file1 = $module_in_template_file;
         $in_dir = false;
     } else {
         $module_in_default_dir = modules_path() . $module_name . '';
         $module_in_default_dir = normalize_path($module_in_default_dir, 1);
         // d($module_in_default_dir);
         $module_in_default_file = modules_path() . $module_name . '.php';
         $module_in_default_file_custom_view = modules_path() . $module_name . '_' . $custom_view . '.php';
         $element_in_default_file = elements_path() . $module_name . '.php';
         $element_in_default_file = normalize_path($element_in_default_file, false);
         //
         $module_in_default_file = normalize_path($module_in_default_file, false);
         if (is_file($module_in_default_file)) {
             $in_dir = false;
             if ($custom_view == true and is_file($module_in_default_file_custom_view)) {
                 $try_file1 = $module_in_default_file_custom_view;
             } else {
                 $try_file1 = $module_in_default_file;
             }
         } else {
             if (is_dir($module_in_default_dir)) {
                 $in_dir = true;
                 $mod_d1 = normalize_path($module_in_default_dir, 1);
                 if ($custom_view == true) {
                     $try_file1 = $mod_d1 . trim($custom_view) . '.php';
                 } else {
                     $try_file1 = $mod_d1 . 'index.php';
                 }
             } elseif (is_file($element_in_default_file)) {
                 $in_dir = false;
                 $is_element = true;
                 $try_file1 = $element_in_default_file;
             }
         }
     }
     //
     if (isset($try_file1) != false and $try_file1 != false and is_file($try_file1)) {
         if (isset($attrs) and is_array($attrs) and !empty($attrs)) {
             $attrs2 = array();
             foreach ($attrs as $attrs_k => $attrs_v) {
                 $attrs_k2 = substr($attrs_k, 0, 5);
                 if (strtolower($attrs_k2) == 'data-') {
                     $attrs_k21 = substr($attrs_k, 5);
                     $attrs2[$attrs_k21] = $attrs_v;
                 } elseif (!isset($attrs['data-' . $attrs_k])) {
                     $attrs2['data-' . $attrs_k] = $attrs_v;
                 }
                 $attrs2[$attrs_k] = $attrs_v;
             }
             $attrs = $attrs2;
         }
         $config['path_to_module'] = $config['mp'] = $config['path'] = normalize_path(dirname($try_file1) . '/', true);
         $config['the_module'] = $module_name;
         $config['module'] = $module_name;
         $module_name_dir = dirname($module_name);
         $config['module_name'] = $module_name_dir;
         $config['module_name_url_safe'] = $this->module_name_encode($module_name);
         $find_base_url = $this->app->url_manager->current(1);
         if ($pos = strpos($find_base_url, ':' . $module_name) or $pos = strpos($find_base_url, ':' . $config['module_name_url_safe'])) {
             $find_base_url = substr($find_base_url, 0, $pos) . ':' . $config['module_name_url_safe'];
         }
         $config['url'] = $find_base_url;
         $config['url_main'] = $config['url_base'] = strtok($find_base_url, '?');
         if ($in_dir != false) {
             $mod_api = str_replace('/admin', '', $module_name);
         } else {
             $mod_api = str_replace('/admin', '', $module_name_dir);
         }
         $config['module_api'] = $this->app->url_manager->site('api/' . $mod_api);
         $config['module_view'] = $this->app->url_manager->site('module/' . $module_name);
         $config['ns'] = str_replace('/', '\\', $module_name);
         $config['module_class'] = $this->module_css_class($module_name);
         $config['url_to_module'] = $this->app->url_manager->link_to_file($config['path_to_module']);
         if (isset($attrs['id'])) {
             $attrs['id'] = str_replace('__MODULE_CLASS_NAME__', $config['module_class'], $attrs['id']);
             $template = false;
         }
         //$config['url_to_module'] = rtrim($config['url_to_module'], '///');
         $lic = $this->app->modules->license($module_name);
         //  $lic = 'valid';
         if ($lic != false) {
             $config['license'] = $lic;
         }
         if (isset($attrs['module-id']) and $attrs['module-id'] != false) {
             $attrs['id'] = $attrs['module-id'];
         }
         if (!isset($attrs['id'])) {
             global $mw_mod_counter;
             $mw_mod_counter++;
             //  $seg_clean = $this->app->url_manager->segment(0);
             $seg_clean = $this->app->url_manager->segment(0, url_current());
             if (defined('IS_HOME')) {
                 $seg_clean = '';
             }
             $seg_clean = str_replace('%20', '-', $seg_clean);
             $seg_clean = str_replace(' ', '-', $seg_clean);
             $seg_clean = str_replace('.', '', $seg_clean);
             $attrs1 = crc32(serialize($attrs) . $seg_clean . $mw_mod_counter);
             $attrs1 = str_replace('%20', '-', $attrs1);
             $attrs1 = str_replace(' ', '-', $attrs1);
             $attrs['id'] = $config['module_class'] . '-' . $attrs1;
         }
         if (isset($attrs['id']) and strstr($attrs['id'], '__MODULE_CLASS_NAME__')) {
             $attrs['id'] = str_replace('__MODULE_CLASS_NAME__', $config['module_class'], $attrs['id']);
             //$attrs['id'] = ('__MODULE_CLASS__' . '-' . $attrs1);
         }
         $l1 = new \Microweber\View($try_file1);
         $l1->config = $config;
         $l1->app = $this->app;
         if (!isset($attrs['module'])) {
             $attrs['module'] = $module_name;
         }
         if (!isset($attrs['parent-module'])) {
             $attrs['parent-module'] = $module_name;
         }
         if (!isset($attrs['parent-module-id'])) {
             $attrs['parent-module-id'] = $attrs['id'];
         }
         //            $mw_restore_get = mw_var('mw_restore_get');
         //            if ($mw_restore_get != false and is_array($mw_restore_get)) {
         //                $l1->_GET = $mw_restore_get;
         //                $_GET = $mw_restore_get;
         //            }
         if (defined('MW_MODULE_ONDROP')) {
             if (!isset($attrs['ondrop'])) {
                 $attrs['ondrop'] = true;
             }
         }
         $l1->params = $attrs;
         if ($config) {
             $this->current_module = $config;
         }
         if ($attrs) {
             $this->current_module_params = $attrs;
         }
         if (isset($attrs['view']) && trim($attrs['view']) == 'empty') {
             $module_file = EMPTY_MOD_STR;
         } elseif (isset($attrs['view']) && trim($attrs['view']) == 'admin') {
             $module_file = $l1->__toString();
         } else {
             if (isset($attrs['display']) && trim($attrs['display']) == 'custom') {
                 $module_file = $l1->__get_vars();
                 return $module_file;
             } else {
                 if (isset($attrs['format']) && trim($attrs['format']) == 'json') {
                     $module_file = $l1->__get_vars();
                     header("Content-type: application/json");
                     exit(json_encode($module_file));
                 } else {
                     $module_file = $l1->__toString();
                 }
             }
         }
         //	$l1 = null;
         unset($l1);
         if ($lic != false and isset($lic["error"]) and $lic["error"] == 'no_license_found') {
             $lic_l1_try_file1 = MW_ADMIN_VIEWS_DIR . 'activate_license.php';
             $lic_l1 = new \Microweber\View($lic_l1_try_file1);
             $lic_l1->config = $config;
             $lic_l1->params = $attrs;
             $lic_l1e_file = $lic_l1->__toString();
             unset($lic_l1);
             $module_file = $lic_l1e_file . $module_file;
         }
         // $mw_loaded_mod_memory[$function_cache_id] = $module_file;
         return $module_file;
     } else {
         //define($cache_content, FALSE);
         // $mw_loaded_mod_memory[$function_cache_id] = false;
         return false;
     }
 }
Exemple #10
0
 public function get_custom_css()
 {
     if (!defined('MW_NO_SESSION')) {
         define("MW_NO_SESSION", 1);
     }
     ob_start();
     event_trigger('mw.template.print_custom_css_includes');
     $fonts_file = modules_path() . 'editor' . DS . 'fonts' . DS . 'stylesheet.php';
     if (is_file($fonts_file)) {
         include $fonts_file;
     }
     $custom_css = get_option("custom_css", "template");
     if (is_string($custom_css)) {
         print $custom_css;
     }
     event_trigger('mw.template.print_custom_css');
     $output = ob_get_contents();
     ob_end_clean();
     $l = $output;
     $compile_assets = \Config::get('microweber.compile_assets');
     if ($compile_assets and defined('MW_VERSION')) {
         $userfiles_dir = userfiles_path();
         $userfiles_cache_dir = normalize_path($userfiles_dir . 'cache' . DS);
         $userfiles_cache_filename = $userfiles_cache_dir . 'custom_css.' . md5(site_url()) . '.' . MW_VERSION . '.css';
         if (!is_file($userfiles_cache_filename)) {
             if (!is_dir($userfiles_cache_dir)) {
                 mkdir_recursive($userfiles_cache_dir);
             }
             if (is_dir($userfiles_cache_dir)) {
                 @file_put_contents($userfiles_cache_filename, $l);
             }
         } else {
             $fmd5 = md5_file($userfiles_cache_filename);
             $fmd = md5($l);
             if ($fmd5 != $fmd) {
                 @file_put_contents($userfiles_cache_filename, $l);
             }
         }
     }
     return $output;
 }
 public function scan($options = false)
 {
     $options = parse_params($options);
     if (!isset($options['path'])) {
         if (isset($options['site_template']) and strtolower($options['site_template']) != 'default' and trim($options['site_template']) != '') {
             $tmpl = trim($options['site_template']);
             $check_dir = templates_path() . '' . $tmpl;
             if (is_dir($check_dir)) {
                 $the_active_site_template = $tmpl;
             } else {
                 $the_active_site_template = $this->app->option_manager->get('current_template', 'template');
             }
         } elseif (isset($options['site_template']) and strtolower($options['site_template']) == 'mw_default') {
             $options['site_template'] = 'default';
             $tmpl = trim($options['site_template']);
             $check_dir = templates_path() . '' . $tmpl;
             if (is_dir($check_dir)) {
                 $the_active_site_template = $tmpl;
             } else {
                 $the_active_site_template = $this->app->option_manager->get('current_template', 'template');
             }
         } else {
             $the_active_site_template = $this->app->option_manager->get('current_template', 'template');
         }
         if ($the_active_site_template == '' or $the_active_site_template == 'mw_default') {
             $the_active_site_template = 'default';
         }
         $path = normalize_path(templates_path() . $the_active_site_template);
     } else {
         $path = $options['path'];
     }
     if (isset($the_active_site_template) and trim($the_active_site_template) != 'default') {
         if (defined('DEFAULT_TEMPLATE_DIR') and (!isset($path) or $path == false or !strstr($path, DEFAULT_TEMPLATE_DIR))) {
             $use_default_layouts = $path . 'use_default_layouts.php';
             if (is_file($use_default_layouts)) {
                 $path = DEFAULT_TEMPLATE_DIR;
             }
         }
     }
     if (!isset($path) or $path == false) {
         return;
     }
     if (!isset($options['no_cache'])) {
         $args = func_get_args();
         $function_cache_id = '';
         foreach ($args as $k => $v) {
             $function_cache_id = $function_cache_id . serialize($k) . serialize($v);
         }
         $cache_id = $function_cache_id = __FUNCTION__ . crc32($path . $function_cache_id);
         $cache_group = 'templates';
         $cache_content = $this->app->cache_manager->get($cache_id, $cache_group);
         if ($cache_content != false) {
             return $cache_content;
         }
     }
     $glob_patern = "*.php";
     $template_dirs = array();
     if (isset($options['get_dynamic_layouts'])) {
         $possible_dir = TEMPLATE_DIR . 'modules' . DS . 'layout' . DS;
         if (is_dir($possible_dir)) {
             $template_dirs[] = $possible_dir;
             $dir2 = rglob($possible_dir . '*.php', 0);
             if (!empty($dir2)) {
                 foreach ($dir2 as $dir_glob) {
                     $dir[] = $dir_glob;
                 }
             }
         }
     }
     if (!isset($options['get_dynamic_layouts'])) {
         if (!isset($options['filename'])) {
             $dir = rglob($glob_patern, 0, $path);
         } else {
             $dir = array();
             $dir[] = $options['filename'];
         }
     } else {
     }
     $configs = array();
     if (!empty($dir)) {
         foreach ($dir as $filename) {
             $skip = false;
             if (!isset($options['get_dynamic_layouts'])) {
                 if (!isset($options['for_modules'])) {
                     if (strstr($filename, 'modules' . DS)) {
                         $skip = true;
                     }
                 } else {
                     if (!strstr($filename, 'modules' . DS)) {
                         $skip = true;
                     }
                 }
             }
             if ($skip == false and is_file($filename)) {
                 $fin = file_get_contents($filename);
                 $here_dir = dirname($filename) . DS;
                 $to_return_temp = array();
                 if (preg_match('/type:.+/', $fin, $regs)) {
                     $result = $regs[0];
                     $result = str_ireplace('type:', '', $result);
                     $to_return_temp['type'] = trim($result);
                     $to_return_temp['directory'] = $here_dir;
                     if (strstr($here_dir, templates_path())) {
                         $templ_dir = str_replace(templates_path(), '', $here_dir);
                         if ($templ_dir != '') {
                             $templ_dir = explode(DS, $templ_dir);
                             if (isset($templ_dir[0])) {
                                 $to_return_temp['template_dir'] = $templ_dir[0];
                             }
                         }
                     }
                     if (strstr($here_dir, modules_path())) {
                         $templ_dir1 = str_replace(modules_path(), '', $here_dir);
                         $templ_dir1 = str_ireplace('templates', '', $templ_dir1);
                         $templ_dir1 = str_ireplace('\\', '/', $templ_dir1);
                         $templ_dir1 = str_ireplace('//', '/', $templ_dir1);
                         $to_return_temp['module_directory'] = $templ_dir1;
                     }
                     if (strtolower($to_return_temp['type']) == 'layout') {
                         $to_return_temp['directory'] = $here_dir;
                         if (preg_match('/is_shop:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('is_shop:', '', $result);
                             $to_return_temp['is_shop'] = trim($result);
                         }
                         if (preg_match('/name:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('name:', '', $result);
                             $to_return_temp['name'] = trim($result);
                         }
                         if (preg_match('/is_default:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('is_default:', '', $result);
                             $to_return_temp['is_default'] = trim($result);
                         }
                         if (preg_match('/position:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('position:', '', $result);
                             $to_return_temp['position'] = intval($result);
                         } else {
                             $to_return_temp['position'] = 99999;
                         }
                         if (preg_match('/version:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('version:', '', $result);
                             $to_return_temp['version'] = trim($result);
                         }
                         if (preg_match('/visible:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('visible:', '', $result);
                             $to_return_temp['visible'] = trim($result);
                         }
                         if (preg_match('/icon:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('icon:', '', $result);
                             $to_return_temp['icon'] = trim($result);
                             $possible = $here_dir . $to_return_temp['icon'];
                             if (is_file($possible)) {
                                 $to_return_temp['icon'] = $this->app->url_manager->link_to_file($possible);
                             } else {
                                 unset($to_return_temp['icon']);
                             }
                         }
                         if (preg_match('/image:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('image:', '', $result);
                             $to_return_temp['image'] = trim($result);
                             $possible = $here_dir . $to_return_temp['image'];
                             if (is_file($possible)) {
                                 $to_return_temp['image'] = $this->app->url_manager->link_to_file($possible);
                             } else {
                                 unset($to_return_temp['image']);
                             }
                         }
                         if (preg_match('/description:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('description:', '', $result);
                             $to_return_temp['description'] = trim($result);
                         }
                         if (preg_match('/content_type:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('content_type:', '', $result);
                             $to_return_temp['content_type'] = trim($result);
                         }
                         if (preg_match('/tag:.+/', $fin, $regs)) {
                             $result = $regs[0];
                             $result = str_ireplace('tag:', '', $result);
                             $to_return_temp['tag'] = trim($result);
                         }
                         $layout_file = str_replace($path, '', $filename);
                         if (isset($template_dirs) and !empty($template_dirs)) {
                             foreach ($template_dirs as $template_dir) {
                                 $layout_file = str_replace($template_dir, '', $layout_file);
                             }
                         }
                         $layout_file = str_replace(DS, '/', $layout_file);
                         $to_return_temp['layout_file'] = $layout_file;
                         $to_return_temp['filename'] = $filename;
                         $screen = str_ireplace('.php', '.png', $filename);
                         $screen_jpg = str_ireplace('.php', '.jpg', $filename);
                         if (is_file($screen_jpg)) {
                             $to_return_temp['screenshot_file'] = $screen_jpg;
                         } else {
                             if (is_file($screen)) {
                                 $to_return_temp['screenshot_file'] = $screen;
                             }
                         }
                         if (isset($to_return_temp['screenshot_file'])) {
                             $to_return_temp['screenshot'] = $this->app->url_manager->link_to_file($to_return_temp['screenshot_file']);
                         }
                         $configs[] = $to_return_temp;
                     }
                 }
             }
         }
         if (!empty($configs)) {
             $sorted_by_pos = array();
             $sorted_by_pos_items = array();
             $pos = 9999;
             foreach ($configs as $item) {
                 if (isset($item['position'])) {
                     $sorted_by_pos_items[$item['position']][] = $item;
                 } else {
                     $sorted_by_pos[$pos] = $item;
                 }
                 $pos++;
             }
             if (!empty($sorted_by_pos_items)) {
                 ksort($sorted_by_pos_items);
                 foreach ($sorted_by_pos_items as $configs) {
                     $pos = 0;
                     foreach ($configs as $item) {
                         $sorted_by_pos[] = $item;
                         $pos++;
                     }
                 }
             }
             if (!empty($sorted_by_pos)) {
                 $configs = $sorted_by_pos;
             }
             if (!isset($options['no_cache'])) {
                 $this->app->cache_manager->save($configs, $function_cache_id, $cache_group);
             }
             return $configs;
         }
     }
 }
Exemple #12
0
function mw_includes_path()
{
    static $folder;
    if (!$folder) {
        $folder = modules_path() . MW_SYSTEM_MODULE_FOLDER . '/';
    }
    return $folder;
}
Exemple #13
0
 public function get_custom_css()
 {
     ob_start();
     event_trigger('mw.template.print_custom_css_includes');
     $fonts_file = modules_path() . 'editor' . DS . 'fonts' . DS . 'stylesheet.php';
     if (is_file($fonts_file)) {
         include $fonts_file;
     }
     $custom_css = get_option("custom_css", "template");
     if (is_string($custom_css)) {
         print $custom_css;
     }
     event_trigger('mw.template.print_custom_css');
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
 /**
  * Return the path to the layout file that will render the page
  *
  */
 public function get_layout($page = array())
 {
     $function_cache_id = '';
     if (is_array($page)) {
         ksort($page);
     }
     $function_cache_id = $function_cache_id . serialize($page);
     $cache_id = __FUNCTION__ . crc32($function_cache_id);
     $cache_group = 'content/global';
     if (!defined('ACTIVE_TEMPLATE_DIR')) {
         if (isset($page['id'])) {
             $this->app->content_manager->define_constants($page);
         }
     }
     $cache_content = false;
     //  $cache_content = $this->app->cache_manager->get($cache_id, $cache_group);
     if ($cache_content != false) {
         // return $cache_content;
     }
     $override = $this->app->event_manager->trigger('mw.front.get_layout', $page);
     $render_file = false;
     $look_for_post = false;
     $template_view_set_inner = false;
     $fallback_render_internal_file = false;
     $site_template_settings = $this->app->option_manager->get('current_template', 'template');
     if (!isset($page['active_site_template'])) {
         $page['active_site_template'] = 'default';
     } elseif (isset($page['active_site_template']) and $page['active_site_template'] == '') {
         $page['active_site_template'] = $site_template_settings;
     }
     if ($page['active_site_template'] and ($page['active_site_template'] == 'default' or $page['active_site_template'] == 'mw_default')) {
         if ($site_template_settings != 'default' and $page['active_site_template'] == 'mw_default') {
             $page['active_site_template'] = 'default';
             $site_template_settings = 'default';
         }
         if ($site_template_settings != false) {
             $site_template_settings = str_replace('..', '', $site_template_settings);
             $site_template_settings_dir = TEMPLATES_DIR . $site_template_settings . DS;
             if (is_dir($site_template_settings_dir) != false) {
                 $page['active_site_template'] = $site_template_settings;
             }
         }
     }
     if (isset($page['content_type'])) {
         $page['content_type'] = str_replace('..', '', $page['content_type']);
     }
     if (isset($page['subtype'])) {
         $page['subtype'] = str_replace('..', '', $page['subtype']);
     }
     if (isset($page['layout_file'])) {
         $page['layout_file'] = str_replace('..', '', $page['layout_file']);
     }
     if (isset($page['active_site_template'])) {
         $page['active_site_template'] = str_replace('..', '', $page['active_site_template']);
     }
     if (is_array($override)) {
         foreach ($override as $resp) {
             if (isset($resp['render_file']) and $resp['render_file'] != false) {
                 $render_file = $resp['render_file'];
             } elseif (is_array($resp) and !empty($resp)) {
                 $page = array_merge($page, $resp);
             }
         }
     }
     if ($render_file == false) {
         if (isset($page['active_site_template']) and isset($page['layout_file'])) {
             $page['layout_file'] = str_replace('___', DS, $page['layout_file']);
             $page['layout_file'] = str_replace('__', DS, $page['layout_file']);
             $page['layout_file'] = str_replace('..', '', $page['layout_file']);
             $template_d = $page['active_site_template'];
             if ($template_d == 'mw_default') {
                 $template_d = 'default';
             }
             $render_file_temp = normalize_path(TEMPLATES_DIR . $template_d . DS . $page['layout_file'], false);
             $render_use_default = normalize_path(TEMPLATES_DIR . $template_d . DS . 'use_default_layouts.php', false);
             $render_file_module_temp = modules_path() . DS . $page['layout_file'];
             $render_file_module_temp = normalize_path($render_file_module_temp, false);
             if (is_file($render_file_temp)) {
                 $render_file = $render_file_temp;
             } elseif (is_file($render_file_module_temp)) {
                 $render_file = $render_file_module_temp;
             } elseif (is_file($render_use_default)) {
                 $render_file_temp = DEFAULT_TEMPLATE_DIR . $page['layout_file'];
                 if (is_file($render_file_temp)) {
                     $render_file = $render_file_temp;
                 }
             }
         }
     }
     if ($render_file == false and isset($page['content_type']) and isset($page['parent']) and $page['content_type'] != 'page') {
         $get_layout_from_parent = false;
         $par = $this->app->content_manager->get_by_id($page['parent']);
         if (isset($par['layout_file']) and $par['layout_file'] != '' and $par['layout_file'] != 'inherit') {
             $get_layout_from_parent = $par;
         } elseif (isset($par['is_home']) and isset($par['active_site_template']) and (!isset($par['layout_file']) or $par['layout_file'] == '') and $par['is_home'] == 'y') {
             $par['layout_file'] = 'index.php';
             $get_layout_from_parent = $par;
         } else {
             $inh = $this->app->content_manager->get_inherited_parent($page['parent']);
             if ($inh != false) {
                 $par = $this->app->content_manager->get_by_id($inh);
                 if (isset($par['active_site_template']) and isset($par['layout_file']) and $par['layout_file'] != '') {
                     $get_layout_from_parent = $par;
                 } else {
                     if (isset($par['active_site_template']) and isset($par['is_home']) and $par['is_home'] == 'y' and (!isset($par['layout_file']) or $par['layout_file'] == '')) {
                         $par['layout_file'] = 'index.php';
                         $get_layout_from_parent = $par;
                     }
                 }
             }
         }
         if (isset($get_layout_from_parent['layout_file'])) {
             if (!isset($get_layout_from_parent['active_site_template'])) {
                 $get_layout_from_parent['active_site_template'] = 'default';
             }
             if ($get_layout_from_parent['active_site_template'] == 'default') {
                 $get_layout_from_parent['active_site_template'] = $site_template_settings;
             }
             if ($get_layout_from_parent['active_site_template'] == 'mw_default') {
                 $get_layout_from_parent['active_site_template'] = 'default';
             }
             $get_layout_from_parent['layout_file'] = str_replace('___', DS, $get_layout_from_parent['layout_file']);
             $get_layout_from_parent['layout_file'] = str_replace('..', '', $get_layout_from_parent['layout_file']);
             $render_file_temp = TEMPLATES_DIR . $get_layout_from_parent['active_site_template'] . DS . $get_layout_from_parent['layout_file'];
             $render_use_default = TEMPLATES_DIR . $get_layout_from_parent['active_site_template'] . DS . 'use_default_layouts.php';
             $render_file_temp = normalize_path($render_file_temp, false);
             $render_use_default = normalize_path($render_use_default, false);
             $render_file_module_temp = modules_path() . DS . $get_layout_from_parent['layout_file'];
             $render_file_module_temp = normalize_path($render_file_module_temp, false);
             //if (!isset($page['content_type']) or $page['content_type'] == 'page') {
             if (is_file($render_file_temp)) {
                 $render_file = $render_file_temp;
             } elseif (is_file($render_use_default)) {
                 $render_file_temp = DEFAULT_TEMPLATE_DIR . $get_layout_from_parent['layout_file'];
                 if (is_file($render_file_temp)) {
                     $render_file = $render_file_temp;
                 }
             } elseif (is_file($render_file_module_temp)) {
                 $render_file = $render_file_module_temp;
             }
         }
     }
     if ($render_file == false and !isset($page['active_site_template']) and isset($page['layout_file'])) {
         $test_file = str_replace('___', DS, $page['layout_file']);
         $test_file = str_replace('..', '', $test_file);
         $render_file_temp = $test_file;
         $render_file_temp = normalize_path($render_file_temp, false);
         if (is_file($render_file_temp)) {
             $render_file = $render_file_temp;
         }
     }
     if ($render_file == false and isset($page['active_site_template']) and isset($page['active_site_template']) and isset($page['layout_file']) and $page['layout_file'] != 'inherit' and $page['layout_file'] != '') {
         $test_file = str_replace('___', DS, $page['layout_file']);
         $test_file = str_replace('..', '', $test_file);
         $render_file_temp = TEMPLATES_DIR . $page['active_site_template'] . DS . $test_file;
         $render_file_module_temp = modules_path() . DS . $test_file;
         $render_file_module_temp = normalize_path($render_file_module_temp, false);
         if (is_file($render_file_temp)) {
             $render_file = $render_file_temp;
         } elseif (is_file($render_file_module_temp)) {
             $render_file = $render_file_module_temp;
         }
     }
     if ($render_file == false and isset($page['id']) and intval($page['id']) == 0) {
         $url_file = $this->app->url_manager->string(1, 1);
         $test_file = str_replace('___', DS, $url_file);
         $render_file_temp = ACTIVE_TEMPLATE_DIR . DS . $test_file . '.php';
         $render_file_temp2 = ACTIVE_TEMPLATE_DIR . DS . $url_file . '.php';
         if (is_file($render_file_temp)) {
             $render_file = $render_file_temp;
         } elseif (is_file($render_file_temp2)) {
             $render_file = $render_file_temp2;
         }
     }
     if (isset($page['active_site_template']) and $page['active_site_template'] == 'default') {
         $page['active_site_template'] = $site_template_settings;
     }
     if (isset($page['active_site_template']) and $page['active_site_template'] != 'default' and $page['active_site_template'] == 'mw_default') {
         $page['active_site_template'] = 'default';
     }
     if ($render_file == false and isset($page['id']) and isset($page['active_site_template']) and isset($page['layout_file']) and $page['layout_file'] != 'inherit') {
         $render_file_temp = TEMPLATES_DIR . $page['active_site_template'] . DS . $page['layout_file'];
         $render_file_temp = normalize_path($render_file_temp, false);
         if (is_file($render_file_temp)) {
             $render_file = $render_file_temp;
         } else {
             $render_file_temp = DEFAULT_TEMPLATE_DIR . $page['layout_file'];
             if (is_file($render_file_temp)) {
                 $render_file = $render_file_temp;
             }
         }
     }
     if ($render_file == false and isset($page['id']) and isset($page['active_site_template']) and (!isset($page['layout_file']) or isset($page['layout_file']) and $page['layout_file'] == 'inherit' or $page['layout_file'] == false)) {
         $inherit_from = $this->app->content_manager->get_parents($page['id']);
         $found = 0;
         if ($inherit_from == false) {
             if (isset($page['parent']) and $page['parent'] != false) {
                 $par_test = $this->app->content_manager->get_by_id($page['parent']);
                 if (is_array($par_test)) {
                     $inherit_from = array();
                     if (isset($page['layout_file']) and $page['layout_file'] != 'inherit') {
                         $inherit_from[] = $page['parent'];
                     } else {
                         $inh = $this->app->content_manager->get_inherited_parent($page['parent']);
                         $inherit_from[] = $inh;
                     }
                 }
             }
         }
         if (!empty($inherit_from)) {
             foreach ($inherit_from as $value) {
                 if ($found == 0 and $value != $page['id']) {
                     $par_c = $this->app->content_manager->get_by_id($value);
                     if (isset($par_c['id']) and isset($par_c['active_site_template']) and isset($par_c['layout_file']) and $par_c['layout_file'] != 'inherit') {
                         $page['layout_file'] = $par_c['layout_file'];
                         $page['layout_file'] = str_replace('__', DS, $page['layout_file']);
                         $page['active_site_template'] = $par_c['active_site_template'];
                         $page['active_site_template'] = str_replace('..', '', $page['active_site_template']);
                         if ($page['active_site_template'] == 'default') {
                             $page['active_site_template'] = $site_template_settings;
                         }
                         if ($page['active_site_template'] != 'default' and $page['active_site_template'] == 'mw_default') {
                             $page['active_site_template'] = 'default';
                         }
                         $render_file_temp = TEMPLATES_DIR . $page['active_site_template'] . DS . $page['layout_file'];
                         $render_file_temp = normalize_path($render_file_temp, false);
                         $render_file_module_temp = modules_path() . DS . $page['layout_file'];
                         $render_file_module_temp = normalize_path($render_file_module_temp, false);
                         if (is_file($render_file_temp)) {
                             $render_file = $render_file_temp;
                         } elseif (is_file($render_file_module_temp)) {
                             $render_file = $render_file_module_temp;
                         } else {
                             $render_file_temp = DEFAULT_TEMPLATE_DIR . $page['layout_file'];
                             if (is_file($render_file_temp)) {
                                 $fallback_render_internal_file = $render_file_temp;
                             }
                         }
                         $found = 1;
                     }
                 }
             }
         }
     }
     if ($render_file != false and (isset($page['content_type']) and $page['content_type'] != 'page')) {
         $f1 = $render_file;
         $f2 = $render_file;
         $stringA = $f1;
         $stringB = "_inner";
         $length = strlen($stringA);
         $temp1 = substr($stringA, 0, $length - 4);
         $temp2 = substr($stringA, $length - 4, $length);
         $f1 = $temp1 . $stringB . $temp2;
         $f1 = normalize_path($f1, false);
         if (is_file($f1)) {
             $render_file = $f1;
         } else {
             $stringA = $f2;
             $stringB = '_' . $page['content_type'];
             $length = strlen($stringA);
             $temp1 = substr($stringA, 0, $length - 4);
             $temp2 = substr($stringA, $length - 4, $length);
             $f3 = $temp1 . $stringB . $temp2;
             $f3 = normalize_path($f3, false);
             if (is_file($f3)) {
                 $render_file = $f3;
             } else {
                 $found_subtype_layout = false;
                 if (isset($page['subtype'])) {
                     $stringA = $f2;
                     $stringB = '_' . $page['subtype'];
                     $length = strlen($stringA);
                     $temp1 = substr($stringA, 0, $length - 4);
                     $temp2 = substr($stringA, $length - 4, $length);
                     $f3 = $temp1 . $stringB . $temp2;
                     $f3 = normalize_path($f3, false);
                     if (is_file($f3)) {
                         $found_subtype_layout = true;
                         $render_file = $f3;
                     }
                 }
                 $check_inner = dirname($render_file);
                 if ($found_subtype_layout == false and is_dir($check_inner)) {
                     if (isset($page['subtype'])) {
                         $stringA = $check_inner;
                         $stringB = $page['subtype'] . '.php';
                         $length = strlen($stringA);
                         $f3 = $stringA . DS . $stringB;
                         $f3 = normalize_path($f3, false);
                         if (is_file($f3)) {
                             $found_subtype_layout = true;
                             $render_file = $f3;
                         }
                     }
                     if ($found_subtype_layout == false) {
                         $in_file = $check_inner . DS . 'inner.php';
                         $in_file = normalize_path($in_file, false);
                         $in_file2 = $check_inner . DS . $page['content_type'] . '.php';
                         $in_file2 = normalize_path($in_file2, false);
                         if (is_file($in_file2)) {
                             $render_file = $in_file2;
                         } elseif (is_file($in_file)) {
                             $render_file = $in_file;
                         }
                     }
                 }
             }
         }
     }
     if ($render_file == false and isset($page['content_type']) and $page['content_type'] != false and $page['content_type'] != '') {
         $look_for_post = $page;
         if (isset($page['parent'])) {
             $par_page = false;
             $inh_par_page = $this->app->content_manager->get_inherited_parent($page['parent']);
             if ($inh_par_page != false) {
                 $par_page = $this->app->content_manager->get_by_id($inh_par_page);
             } else {
                 $par_page = $this->app->content_manager->get_by_id($page['parent']);
             }
             if (is_array($par_page)) {
                 if (isset($par_page['active_site_template']) and $par_page['active_site_template'] != false) {
                     $page['active_site_template'] = $par_page['active_site_template'];
                 }
                 if (isset($par_page['layout_file']) and $par_page['layout_file'] != false) {
                     //$page['layout_file'] = $par_page['layout_file'];
                 }
             } else {
                 $template_view_set_inner = ACTIVE_TEMPLATE_DIR . DS . 'inner.php';
                 $template_view_set_inner2 = ACTIVE_TEMPLATE_DIR . DS . 'layouts/inner.php';
             }
         } else {
             $template_view_set_inner = ACTIVE_TEMPLATE_DIR . DS . 'inner.php';
             $template_view_set_inner2 = ACTIVE_TEMPLATE_DIR . DS . 'layouts/inner.php';
         }
     }
     if ($render_file == false and isset($page['simply_a_file'])) {
         $simply_a_file2 = ACTIVE_TEMPLATE_DIR . $page['simply_a_file'];
         $simply_a_file3 = ACTIVE_TEMPLATE_DIR . 'layouts' . DS . $page['simply_a_file'];
         if ($render_file == false and is_file($simply_a_file3) == true) {
             $render_file = $simply_a_file3;
         }
         if ($render_file == false and is_file($simply_a_file2) == true) {
             $render_file = $simply_a_file2;
         }
         if ($render_file == false and is_file($page['simply_a_file']) == true) {
             $render_file = $page['simply_a_file'];
         }
     }
     if (!isset($page['active_site_template'])) {
         $page['active_site_template'] = ACTIVE_SITE_TEMPLATE;
     }
     if ($render_file == false and isset($page['active_site_template']) and trim($page['active_site_template']) != 'default') {
         $use_default_layouts = TEMPLATES_DIR . $page['active_site_template'] . DS . 'use_default_layouts.php';
         if (is_file($use_default_layouts)) {
             $page['active_site_template'] = 'default';
         }
     }
     if ($render_file == false and isset($page['content_type']) and $page['content_type'] == 'page' and isset($page['layout_file']) and trim($page['layout_file']) == 'inherit') {
         $use_index = TEMPLATE_DIR . DS . 'clean.php';
         $use_index2 = TEMPLATE_DIR . DS . 'layouts/clean.php';
         $use_index = normalize_path($use_index, false);
         $use_index2 = normalize_path($use_index2, false);
         if (is_file($use_index)) {
             $render_file = $use_index;
         } elseif (is_file($use_index2)) {
             $render_file = $use_index2;
         }
     }
     //        if ($render_file == false and isset($page['active_site_template']) and isset($page['layout_file']) and trim($page['layout_file']) == '') {
     //            $use_index = TEMPLATES_DIR . $page['active_site_template'] . DS . 'index.php';
     //            if (is_file($use_index)) {
     //                $render_file = $use_index;
     //            }
     //        }
     if ($render_file == false and isset($page['active_site_template']) and $page['active_site_template'] == 'default') {
         $page['active_site_template'] = ACTIVE_SITE_TEMPLATE;
     }
     if ($render_file == false and isset($page['active_site_template']) and isset($page['content_type']) and isset($page['layout_file'])) {
         $page['active_site_template'] = trim(str_replace('..', '', $page['active_site_template']));
         $page['layout_file'] = str_replace('__', DS, $page['layout_file']);
         $page['layout_file'] = trim(urldecode(str_replace('..', '', $page['layout_file'])));
         $page['layout_file'] = str_replace('\\', '/', $page['layout_file']);
         $render_file_test = TEMPLATES_DIR . $page['active_site_template'] . DS . $page['layout_file'];
         $render_file_test = normalize_path($render_file_test, false);
         if (is_file($render_file_test)) {
             $render_file = $render_file_test;
         }
     }
     if ($render_file == false and isset($page['active_site_template']) and isset($page['layout_file'])) {
         if (isset($page['content_type']) and $page['content_type'] == 'page') {
             $look_for_post = false;
         }
         $page['layout_file'] = str_replace('__', DS, $page['layout_file']);
         if ($look_for_post != false) {
             $f1 = $page['layout_file'];
             $stringA = $f1;
             $stringB = "_inner";
             $length = strlen($stringA);
             $temp1 = substr($stringA, 0, $length - 4);
             $temp2 = substr($stringA, $length - 4, $length);
             $f1 = $temp1 . $stringB . $temp2;
             if (strtolower($page['active_site_template']) == 'default') {
                 $template_view = ACTIVE_TEMPLATE_DIR . DS . $f1;
             } else {
                 $template_view = TEMPLATES_DIR . $page['active_site_template'] . DS . $f1;
             }
             if (is_file($template_view) == true) {
                 $render_file = $template_view;
             } else {
                 $dn = dirname($template_view);
                 $dn1 = $dn . DS;
                 $f1 = $dn1 . 'inner.php';
                 if (is_file($f1) == true) {
                     $render_file = $f1;
                 } else {
                     $dn = dirname($dn);
                     $dn1 = $dn . DS;
                     $f1 = $dn1 . 'inner.php';
                     if (is_file($f1) == true) {
                         $render_file = $f1;
                     } else {
                         $dn = dirname($dn);
                         $dn1 = $dn . DS;
                         $f1 = $dn1 . 'inner.php';
                         if (is_file($f1) == true) {
                             $render_file = $f1;
                         }
                     }
                 }
             }
         }
         if ($render_file == false) {
             if (strtolower($page['active_site_template']) == 'default') {
                 $template_view = ACTIVE_TEMPLATE_DIR . DS . $page['layout_file'];
             } else {
                 $template_view = TEMPLATES_DIR . $page['active_site_template'] . DS . $page['layout_file'];
             }
             if (is_file($template_view) == true) {
                 $render_file = $template_view;
             } else {
                 if (trim($page['active_site_template']) != 'default') {
                     $use_default_layouts = TEMPLATES_DIR . $page['active_site_template'] . DS . 'use_default_layouts.php';
                     if (is_file($use_default_layouts)) {
                         $page['active_site_template'] = 'default';
                     }
                 }
             }
         }
     }
     if ($render_file == false and (!isset($page['layout_file']) or $page['layout_file'] == false) and isset($page['url']) and $page['url'] != '') {
         $page['url'] = trim(str_replace('..', '', $page['url']));
         $template_view = ACTIVE_TEMPLATE_DIR . strtolower($page['url']) . '.php';
         if (is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     if ($render_file == false and isset($page['subtype']) and $page['subtype'] != '') {
         $page['subtype'] = trim(str_replace('..', '', $page['subtype']));
         $template_view = ACTIVE_TEMPLATE_DIR . strtolower($page['subtype']) . '.php';
         if (is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     if ($render_file == false and isset($page['content_type']) and $page['content_type'] != '') {
         $page['content_type'] = trim(str_replace('..', '', $page['content_type']));
         $template_view = ACTIVE_TEMPLATE_DIR . strtolower($page['content_type']) . '.php';
         if (is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     if (isset($page['active_site_template']) and $render_file == false and (strtolower($page['active_site_template']) == 'default' or $page['active_site_template'] == $site_template_settings)) {
         if ($render_file == false and isset($page['active_site_template']) and isset($page['id'])) {
             if (isset($look_for_post) and $look_for_post != false) {
                 if (isset($look_for_post['content_type'])) {
                     $ct = str_replace('..', '', $look_for_post['content_type']);
                     $template_view = ACTIVE_TEMPLATE_DIR . $ct . '.php';
                     if ($render_file == false and is_file($template_view) == true) {
                         $render_file = $template_view;
                     }
                 }
                 $template_view = ACTIVE_TEMPLATE_DIR . 'index_inner.php';
                 if ($render_file == false and is_file($template_view) == true) {
                     $render_file = $template_view;
                 }
                 if (isset($look_for_post['content_type']) and $look_for_post['content_type'] != 'page') {
                     $template_view = ACTIVE_TEMPLATE_DIR . 'inner.php';
                     if ($render_file == false and is_file($template_view) == true) {
                         $render_file = $template_view;
                     }
                 }
             }
         }
         //
         if ($render_file == false and isset($page['parent']) and $page['parent'] == 0) {
             if ($render_file == false and isset($page['layout_file']) and $page['layout_file'] == 'inherit') {
                 $t_dir = ACTIVE_TEMPLATE_DIR;
                 if (isset($page['active_site_template'])) {
                     $t_dir = templates_path() . DS . $page['active_site_template'] . DS;
                     $t_dir = normalize_path($t_dir, 1);
                 }
                 $template_view_cl = $t_dir . 'clean.php';
                 $template_view_cl2 = $t_dir . 'layouts/clean.php';
                 if ($render_file == false and is_file($template_view_cl) == true) {
                     $render_file = $template_view_cl;
                 }
                 if ($render_file == false and is_file($template_view_cl2) == true) {
                     $render_file = $template_view_cl2;
                 }
             }
         }
         if ($render_file == false and isset($page['layout_file']) and $page['layout_file'] != false and $page['layout_file'] != 'index.php' and $page['layout_file'] != 'inherit') {
             if ($render_file == false and isset($page['layout_file']) and $page['layout_file'] != false) {
                 $page['layout_file'] = str_replace('__', DS, $page['layout_file']);
                 $template_view = ACTIVE_TEMPLATE_DIR . DS . $page['layout_file'];
                 $template_view = normalize_path($template_view, false);
                 if (is_file($template_view) == true) {
                     $render_file = $template_view;
                 } else {
                     if (!isset($page['is_home']) or $page['is_home'] != 1) {
                         $template_view = ACTIVE_TEMPLATE_DIR . DS . 'clean.php';
                         if (is_file($template_view) == true) {
                             $render_file = $template_view;
                         }
                     }
                 }
             }
         }
         $template_view = ACTIVE_TEMPLATE_DIR . 'index.php';
         if ($render_file == false and is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     if ($render_file == false and isset($page['active_site_template'])) {
         $url_file = $this->app->url_manager->string(1, 1);
         $test_file = str_replace('___', DS, $url_file);
         $template_view = ACTIVE_TEMPLATE_DIR . $test_file . '.php';
         $template_view = normalize_path($template_view, false);
         if (is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     if ($render_file == false and $fallback_render_internal_file != false) {
         if (is_file($fallback_render_internal_file)) {
             $render_file = $fallback_render_internal_file;
         }
     }
     if ($render_file == false and isset($page['active_site_template']) and strtolower($page['active_site_template']) != 'default') {
         $template_view = ACTIVE_TEMPLATE_DIR . 'index.php';
         if (is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     if ($render_file == false and isset($page['active_site_template']) and strtolower($page['active_site_template']) != 'default') {
         $template_view = ACTIVE_TEMPLATE_DIR . 'index.html';
         if (is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     if (isset($page['active_site_template']) and $render_file == false and strtolower($page['active_site_template']) != 'default') {
         $template_view = ACTIVE_TEMPLATE_DIR . 'index.htm';
         if (is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     if ($render_file == false and $template_view_set_inner != false) {
         if (isset($template_view_set_inner2)) {
             $template_view_set_inner2 = normalize_path($template_view_set_inner2, false);
             if (is_file($template_view_set_inner2) == true) {
                 $render_file = $template_view_set_inner2;
             }
         }
         $template_view_set_inner = normalize_path($template_view_set_inner, false);
         if ($render_file == false and is_file($template_view_set_inner) == true) {
             $render_file = $template_view_set_inner;
         }
     }
     if ($render_file != false and isset($page['custom_view'])) {
         $check_custom = dirname($render_file) . DS;
         $check_custom_parent = dirname($render_file) . DS;
         $cv = trim($page['custom_view']);
         $cv = str_replace('..', '', $cv);
         $cv = str_ireplace('.php', '', $cv);
         $check_custom_f = $check_custom . $cv . '.php';
         if (is_file($check_custom_f)) {
             $render_file = $check_custom_f;
         }
     }
     if ($render_file == false and isset($page['layout_file']) and $page['layout_file'] != false) {
         $page['layout_file'] = str_replace('__', DS, $page['layout_file']);
         $template_view = ACTIVE_TEMPLATE_DIR . DS . $page['layout_file'];
         $template_view = normalize_path($template_view, false);
         if (is_file($template_view) == true) {
             $render_file = $template_view;
         }
     }
     //   $this->app->cache_manager->save($render_file, $cache_id, $cache_group);
     return $render_file;
 }
Exemple #15
0
 public function checkout_ipn($data)
 {
     if (isset($data['payment_verify_token'])) {
         $payment_verify_token = $data['payment_verify_token'];
     }
     if (!isset($data['payment_gw'])) {
         return array('error' => 'You must provide a payment gateway parameter!');
     }
     $data['payment_gw'] = str_replace('..', '', $data['payment_gw']);
     $hostname = $this->get_domain_from_str($_SERVER['REMOTE_ADDR']);
     $payment_verify_token = $this->app->database_manager->escape_string($payment_verify_token);
     $table = $this->tables['cart_orders'];
     $query = array();
     $query['payment_verify_token'] = $payment_verify_token;
     if (isset($data['order_id'])) {
         $query['id'] = intval($data['order_id']);
     } else {
         $query['transaction_id'] = '[null]';
     }
     $query['limit'] = 1;
     $query['table'] = $table;
     $query['no_cache'] = true;
     $ord_data = $this->app->database_manager->get($query);
     if (!isset($ord_data[0]) or !is_array($ord_data[0])) {
         return array('error' => 'Order is completed or expired.');
     } else {
         $ord_data = $ord_data[0];
         $ord = $ord_data['id'];
     }
     $cart_table = $this->tables['cart'];
     $table_orders = $this->tables['cart_orders'];
     $data['payment_gw'] = str_replace('..', '', $data['payment_gw']);
     $gw_process = modules_path() . $data['payment_gw'] . '_checkout_ipn.php';
     if (!is_file($gw_process)) {
         $gw_process = normalize_path(modules_path() . $data['payment_gw'] . DS . 'checkout_ipn.php', false);
     }
     $update_order = array();
     if (is_file($gw_process)) {
         include $gw_process;
     } else {
         return array('error' => 'The payment gateway is not found!');
     }
     if (!empty($update_order) and isset($update_order['order_completed']) and trim($update_order['order_completed']) == 1) {
         $update_order['id'] = $ord;
         $update_order['payment_gw'] = $data['payment_gw'];
         $ord = $this->app->database_manager->save($table_orders, $update_order);
         $this->confirm_email_send($ord);
         if (isset($update_order['is_paid']) and $update_order['is_paid'] == 1) {
             $this->update_quantities($ord);
         }
         if ($ord > 0) {
             $this->app->cache_manager->delete('cart/global');
             $this->app->cache_manager->delete('cart_orders/global');
             //return true;
         }
     }
     if (isset($data['return_to'])) {
         $return_to = urldecode($data['return_to']);
         $append = '?';
         if (strstr($return_to, '?')) {
             $append = '&';
         }
         $return_to = $return_to . $append . 'mw_payment_success=1';
         return $this->app->url_manager->redirect($return_to);
     }
     return;
 }
Exemple #16
0
<table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td>modules_url</td>
    <td><?php 
print modules_url();
?>
</td>
  </tr>
  <tr>
    <td>modules_path</td>
    <td><?php 
print modules_path();
?>
</td>
  </tr>
  <tr>
    <td>userfiles_path</td>
    <td><?php 
print userfiles_path();
?>
</td>
  </tr>
  <tr>
    <td>userfiles_folder</td>
    <td><?php 
print modules_url();
?>
</td>
  </tr>
  <tr>
    <td>site_url</td>
 private function install_from_market($item)
 {
     if (isset($item['url']) and !isset($item['download'])) {
         $item['download'] = $item['url'];
     } elseif (isset($item['download_url']) and !isset($item['download'])) {
         $item['download'] = $item['download_url'];
     }
     $download_target = false;
     if (isset($item['download']) and !isset($item['size'])) {
         $url = $item['download'];
         $download_target = $this->temp_dir . md5($url) . basename($url);
         $download_target_extract_lock = $this->temp_dir . md5($url) . basename($url) . '.unzip_lock';
         $this->_log_msg('Downloading from marketplace');
         //if (!is_file($download_target)){
         $dl = $this->http()->url($url)->download($download_target);
         //}
     } else {
         if (isset($item['download']) and isset($item['size'])) {
             $expected = intval($item['size']);
             $download_link = $item['download'];
             $ext = get_file_extension($download_link);
             if ($ext != 'zip') {
                 return;
             }
             if ($download_link != false and $expected > 0) {
                 $text = $download_link;
                 $regex = '/\\b((?:[\\w\\d]+\\:\\/\\/)?(?:[\\w\\-\\d]+\\.)+[\\w\\-\\d]+(?:\\/[\\w\\-\\d]+)*(?:\\/|\\.[\\w\\-\\d]+)?(?:\\?[\\w\\-\\d]+\\=[\\w\\-\\d]+\\&?)?(?:\\#[\\w\\-\\d]*)?)\\b/';
                 preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
                 foreach ($matches as $match) {
                     if (isset($match[0])) {
                         $url = $download_link;
                         $download_target = $this->temp_dir . basename($download_link);
                         $download_target_extract_lock = $this->temp_dir . basename($download_link) . '.unzip_lock';
                         $expectd_item_size = $item['size'];
                         if (!is_file($download_target) or filesize($download_target) != $item['size']) {
                             $dl = $this->http()->url($url)->download($download_target);
                             if ($dl == false) {
                                 if (is_file($download_target) and filesize($download_target) != $item['size']) {
                                     $fs = filesize($download_target);
                                     return array('size' => $fs, 'expected_size' => $expected, 'try_again' => "true", 'warning' => "Only " . $fs . ' bytes downloaded of total ' . $expected);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($download_target != false and is_file($download_target)) {
         $where_to_unzip = MW_ROOTPATH;
         if (isset($item['item_type'])) {
             if ($item['item_type'] == 'module') {
                 $where_to_unzip = modules_path();
             } elseif ($item['item_type'] == 'module_template') {
                 $where_to_unzip = modules_path();
             } elseif ($item['item_type'] == 'template') {
                 $where_to_unzip = templates_path();
             } elseif ($item['item_type'] == 'element') {
                 $where_to_unzip = elements_path();
             }
             if (isset($item['install_path']) and $item['install_path'] != false) {
                 if ($item['item_type'] == 'module_template') {
                     $where_to_unzip = $where_to_unzip . DS . $item['install_path'] . DS . 'templates' . DS;
                 } else {
                     $where_to_unzip = $where_to_unzip . DS . $item['install_path'];
                 }
             }
             $where_to_unzip = str_replace('..', '', $where_to_unzip);
             $where_to_unzip = normalize_path($where_to_unzip, true);
             $this->_log_msg('Unzipping in ' . $where_to_unzip);
             $unzip = new \Microweber\Utils\Unzip();
             $target_dir = $where_to_unzip;
             $result = $unzip->extract($download_target, $target_dir, $preserve_filepath = true);
             $new_composer = $target_dir . 'composer.json';
             if (is_file($new_composer)) {
                 // $this->composer_merge($new_composer);
             }
             $num_files = count($result);
             return array('files' => $result, 'location' => $where_to_unzip, 'success' => "Item is installed. {$num_files} files extracted in {$where_to_unzip}");
         }
     }
 }
 function autoloadModules($className)
 {
     $filename = modules_path() . $className . ".php";
     $filename = normalize_path($filename, false);
     if (!class_exists($className, false)) {
         if (is_file($filename)) {
             require_once $filename;
         }
     }
 }
 public function module()
 {
     if (!defined('MW_API_CALL')) {
         //      define('MW_API_CALL', true);
     }
     if (!defined('MW_NO_SESSION')) {
         $is_ajax = $this->app->url_manager->is_ajax();
         if (!mw()->user_manager->session_id() and $is_ajax == false) {
             if (!defined('MW_SESS_STARTED')) {
                 define('MW_SESS_STARTED', true);
                 // //session_start();
             }
         }
         $editmode_sess = $this->app->user_manager->session_get('editmode');
         if ($editmode_sess == true and !defined('IN_EDIT')) {
             define('IN_EDIT', true);
         }
     }
     $page = false;
     $custom_display = false;
     if (isset($_REQUEST['data-display']) and $_REQUEST['data-display'] == 'custom') {
         $custom_display = true;
     }
     if (isset($_REQUEST['data-module-name'])) {
         $_REQUEST['module'] = $_REQUEST['data-module-name'];
         $_REQUEST['data-type'] = $_REQUEST['data-module-name'];
         if (!isset($_REQUEST['id'])) {
             $_REQUEST['id'] = $this->app->url_manager->slug($_REQUEST['data-module-name'] . '-' . date('YmdHis'));
         }
     }
     if (isset($_REQUEST['data-type'])) {
         $_REQUEST['module'] = $_REQUEST['data-type'];
     }
     if (isset($_REQUEST['display']) and $_REQUEST['display'] == 'custom') {
         $custom_display = true;
     }
     if (isset($_REQUEST['view']) and $_REQUEST['view'] == 'admin') {
         $custom_display = false;
     }
     if ($custom_display == true) {
         $custom_display_id = false;
         if (isset($_REQUEST['id'])) {
             $custom_display_id = $_REQUEST['id'];
         }
         if (isset($_REQUEST['data-id'])) {
             $custom_display_id = $_REQUEST['data-id'];
         }
     }
     if (isset($_REQUEST['from_url'])) {
         $from_url = $_REQUEST['from_url'];
     } elseif (isset($_SERVER['HTTP_REFERER'])) {
         $from_url = $_SERVER['HTTP_REFERER'];
     }
     if (isset($from_url) and $from_url != false) {
         if (stristr($from_url, 'editor_tools/wysiwyg')) {
             if (!defined('IN_EDITOR_TOOLS')) {
                 define('IN_EDITOR_TOOLS', true);
             }
         }
         $url = $from_url;
         $from_url2 = str_replace('#', '/', $from_url);
         $content_id = $this->app->url_manager->param('content_id', false, $from_url2);
         if ($content_id == false) {
             $content_id = $this->app->url_manager->param('editpage', false, $from_url2);
         }
         if ($content_id == false) {
             $content_id = $this->app->url_manager->param('editpost', false, $from_url2);
         }
         if ($content_id == false) {
             $is_current = $this->app->url_manager->param('is-current', false, $from_url2);
             if ($is_current) {
                 $content_id = $this->app->url_manager->param('content-id', false, $from_url2);
             } else {
                 $content_id = $this->app->url_manager->param('mw-adm-content-id', false, $from_url2);
             }
         }
         if ($content_id == false) {
             $action_test = $this->app->url_manager->param('action', false, $from_url2);
             if ($action_test != false) {
                 $action_test = str_ireplace('editpage:', '', $action_test);
                 $action_test = str_ireplace('editpost:', '', $action_test);
                 $action_test = str_ireplace('edit:', '', $action_test);
                 $action_test = str_ireplace('showposts:', '', $action_test);
                 $action_test = intval($action_test);
                 if ($action_test != 0) {
                     $content_id = $action_test;
                     $this->app->content_manager->define_constants(array('id' => $content_id));
                 }
             }
         }
         if (strpos($url, '#')) {
             $url = substr($url, 0, strpos($url, '#'));
         }
         //$url = $_SERVER["HTTP_REFERER"];
         $url = explode('?', $url);
         $url = $url[0];
         if ($content_id != false) {
             $page = array();
             $page['id'] = $content_id;
             if ($content_id) {
                 $page = $this->app->content_manager->get_by_id($content_id);
                 $url = $page['url'];
             }
         } else {
             if (trim($url) == '' or trim($url) == $this->app->url_manager->site()) {
                 //var_dump($from_url);
                 //$page = $this->app->content_manager->get_by_url($url);
                 $page = $this->app->content_manager->homepage();
                 if (!defined('IS_HOME')) {
                     define('IS_HOME', true);
                 }
                 if (isset($from_url2)) {
                     $mw_quick_edit = $this->app->url_manager->param('mw_quick_edit', false, $from_url2);
                     if ($mw_quick_edit) {
                         $page = false;
                     }
                 }
             } else {
                 if (!stristr($url, admin_url())) {
                     $page = $this->app->content_manager->get_by_url($url);
                 } else {
                     $page = false;
                     if (!defined('PAGE_ID')) {
                         define('PAGE_ID', false);
                     }
                     if (!defined('POST_ID')) {
                         define('POST_ID', false);
                     }
                     if (!defined('CONTENT_ID')) {
                         define('CONTENT_ID', false);
                     }
                 }
             }
         }
     } else {
         $url = $this->app->url_manager->string();
     }
     if (!defined('IS_HOME')) {
         if (isset($page['is_home']) and $page['is_home'] == 'y') {
             define('IS_HOME', true);
         }
     }
     if ($page == false) {
         if (!isset($content_id)) {
             return;
         }
         $this->app->content_manager->define_constants(array('id' => $content_id));
     } else {
         $this->app->content_manager->define_constants($page);
     }
     if (defined('TEMPLATE_DIR')) {
         $load_template_functions = TEMPLATE_DIR . 'functions.php';
         if (is_file($load_template_functions)) {
             include_once $load_template_functions;
         }
     }
     if ($custom_display == true) {
         $u2 = $this->app->url_manager->site();
         $u1 = str_replace($u2, '', $url);
         $this->render_this_url = $u1;
         $this->isolate_by_html_id = $custom_display_id;
         $this->frontend();
         return;
     }
     $url_last = false;
     if (!isset($_REQUEST['module'])) {
         $url = $this->app->url_manager->string(0);
         if ($url == __FUNCTION__) {
             $url = $this->app->url_manager->string(0);
         }
         /*
                     $is_ajax = $this->app->url_manager->is_ajax();
         
                     if ($is_ajax == true) {
                     $url = $this->app->url_manager->string(true);
                     }*/
         $url = $this->app->format->replace_once('module/', '', $url);
         $url = $this->app->format->replace_once('module_api/', '', $url);
         $url = $this->app->format->replace_once('m/', '', $url);
         if (is_module($url)) {
             $_REQUEST['module'] = $url;
             $mod_from_url = $url;
         } else {
             $url1 = $url_temp = explode('/', $url);
             $url_last = array_pop($url_temp);
             $try_intil_found = false;
             $temp1 = array();
             foreach ($url_temp as $item) {
                 $temp1[] = implode('/', $url_temp);
                 $url_laset = array_pop($url_temp);
             }
             $i = 0;
             foreach ($temp1 as $item) {
                 if ($try_intil_found == false) {
                     if (is_module($item)) {
                         $url_tempx = explode('/', $url);
                         $_REQUEST['module'] = $item;
                         $url_prev = $url_last;
                         $url_last = array_pop($url_tempx);
                         $url_prev = array_pop($url_tempx);
                         // d($url_prev);
                         $mod_from_url = $item;
                         $try_intil_found = true;
                     }
                 }
                 ++$i;
             }
         }
     }
     $module_info = $this->app->url_manager->param('module_info', true);
     if ($module_info) {
         if ($_REQUEST['module']) {
             $_REQUEST['module'] = str_replace('..', '', $_REQUEST['module']);
             $try_config_file = modules_path() . '' . $_REQUEST['module'] . '_config.php';
             $try_config_file = normalize_path($try_config_file, false);
             if (is_file($try_config_file)) {
                 include $try_config_file;
                 if (!isset($config) or !is_array($config)) {
                     return false;
                 }
                 if (!isset($config['icon']) or $config['icon'] == false) {
                     $config['icon'] = modules_path() . '' . $_REQUEST['module'] . '.png';
                     $config['icon'] = $this->app->url_manager->link_to_file($config['icon']);
                 }
                 echo json_encode($config);
                 return;
             }
         }
     }
     $admin = $this->app->url_manager->param('admin', true);
     $mod_to_edit = $this->app->url_manager->param('module_to_edit', true);
     $embed = $this->app->url_manager->param('embed', true);
     $mod_iframe = false;
     if ($mod_to_edit != false) {
         $mod_to_edit = str_ireplace('_mw_slash_replace_', '/', $mod_to_edit);
         $mod_iframe = true;
     }
     //$data = $_REQUEST;
     if ($_POST) {
         $data = $_POST;
     } else {
         $url = $this->app->url_manager->segment();
         if (!empty($url)) {
             foreach ($url as $k => $v) {
                 $kv = explode(':', $v);
                 if (isset($kv[0]) and isset($kv[1])) {
                     $data[$kv[0]] = $kv[1];
                 }
             }
         }
     }
     $tags = false;
     $mod_n = false;
     if (isset($data['type']) != false) {
         if (trim($data['type']) != '') {
             $mod_n = $data['data-type'] = $data['type'];
         }
     }
     if (isset($data['data-module-name'])) {
         $mod_n = $data['data-type'] = $data['data-module-name'];
         unset($data['data-module-name']);
     }
     if (isset($data['data-type']) != false) {
         $mod_n = $data['data-type'];
     }
     if (isset($data['data-module']) != false) {
         if (trim($data['data-module']) != '') {
             $mod_n = $data['module'] = $data['data-module'];
         }
     }
     if (isset($data['module'])) {
         $mod_n = $data['data-type'] = $data['module'];
         unset($data['module']);
     }
     if (isset($data['type'])) {
         $mod_n = $data['data-type'] = $data['type'];
         unset($data['type']);
     }
     if (isset($data['data-type']) != false) {
         $data['data-type'] = rtrim($data['data-type'], '/');
         $data['data-type'] = rtrim($data['data-type'], '\\');
         $data['data-type'] = str_replace('__', '/', $data['data-type']);
     }
     if (!isset($data)) {
         $data = $_REQUEST;
     }
     if (!isset($data['module']) and isset($mod_from_url) and $mod_from_url != false) {
         $data['module'] = $mod_from_url;
     }
     if (!isset($data['id']) and isset($_REQUEST['id']) == true) {
         $data['id'] = $_REQUEST['id'];
     }
     if (isset($data['ondrop'])) {
         if (!defined('MW_MODULE_ONDROP')) {
             define('MW_MODULE_ONDROP', true);
         }
         unset($data['ondrop']);
     }
     if ($mod_n == 'layout') {
         if (isset($data['template'])) {
             $t = str_replace('..', '', $data['template']);
             $possible_layout = templates_path() . $t;
             $possible_layout = normalize_path($possible_layout, false);
             if (is_file($possible_layout)) {
                 $l = new \Microweber\View($possible_layout);
                 $layout = $l->__toString();
                 $layout = $this->app->parser->process($layout, $options = false);
                 echo $layout;
                 return;
             }
         }
     }
     $has_id = false;
     if (isset($data) and is_array($data)) {
         foreach ($data as $k => $v) {
             if ($k != 'ondrop') {
                 if ($k == 'id') {
                     $has_id = true;
                 }
                 if (is_array($v)) {
                     $v1 = $this->app->format->array_to_base64($v);
                     $tags .= "{$k}=\"{$v1}\" ";
                 } else {
                     $v = $this->app->format->clean_html($v);
                     //$v = $this->app->database_manager->escape_string($v);
                     $tags .= "{$k}=\"{$v}\" ";
                 }
             }
         }
     }
     if ($has_id == false) {
         //  $mod_n = $this->app->url_manager->slug($mod_n) . '-' . date("YmdHis");
         //  $tags .= "id=\"$mod_n\" ";
     }
     $tags = "<module {$tags} />";
     $opts = array();
     if ($_REQUEST) {
         $opts = $_REQUEST;
     }
     if (isset($_REQUEST['live_edit'])) {
         event_trigger('mw.live_edit');
     }
     $opts['admin'] = $admin;
     if ($admin == 'admin') {
         event_trigger('mw_backend');
         event_trigger('mw.admin');
     } else {
         event_trigger('mw_frontend');
         event_trigger('mw.front');
     }
     if (isset($_SERVER['HTTP_REFERER']) and $_SERVER['HTTP_REFERER'] != false) {
         $get_arr_from_ref = $_SERVER['HTTP_REFERER'];
         if (strstr($get_arr_from_ref, $this->app->url_manager->site())) {
             $get_arr_from_ref_arr = parse_url($get_arr_from_ref);
             if (isset($get_arr_from_ref_arr['query']) and $get_arr_from_ref_arr['query'] != '') {
                 $restore_get = parse_str($get_arr_from_ref_arr['query'], $get_array);
                 if (is_array($get_array)) {
                     mw_var('mw_restore_get', $get_array);
                 }
                 //
             }
         }
     }
     $res = $this->app->parser->process($tags, $opts);
     $res = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\\s*~i', '', $res);
     if ($embed != false) {
         $p_index = mw_includes_path() . 'api/index.php';
         $p_index = normalize_path($p_index, false);
         $l = new \Microweber\View($p_index);
         $layout = $l->__toString();
         $res = str_replace('{content}', $res, $layout);
     }
     $aj = $this->app->url_manager->is_ajax();
     if (isset($_REQUEST['live_edit']) and $aj == false) {
         $p_index = mw_includes_path() . DS . 'toolbar' . DS . 'editor_tools' . DS . 'module_settings' . DS . 'index.php';
         $p_index = normalize_path($p_index, false);
         $l = new \Microweber\View($p_index);
         $l->params = $data;
         $layout = $l->__toString();
         $res = str_replace('{content}', $res, $layout);
         $res = $this->app->parser->process($res, $options = false);
     }
     $res = execute_document_ready($res);
     if (!defined('MW_NO_OUTPUT')) {
         $res = $this->app->url_manager->replace_site_url_back($res);
         echo $res;
     }
     if ($url_last != __FUNCTION__) {
         if (function_exists($url_last)) {
             //
             $this->api($url_last);
         } elseif (isset($url_prev) and function_exists($url_prev)) {
             $this->api($url_last);
         } elseif (class_exists($url_last, false)) {
             $this->api($url_last);
         } elseif (isset($url_prev) and class_exists($url_prev, false)) {
             $this->api($url_prev);
         }
     }
     return;
 }
Exemple #20
0
<?php

$config = false;
if ($params['module_info']) {
    $params['module_info'] = str_replace('..', '', $params['module_info']);
    $try_config_file = modules_path() . '' . $params['module_info'] . '_config.php';
    if (is_file($try_config_file)) {
        include $try_config_file;
        if ($config['icon'] == false) {
            $config['icon'] = modules_path() . '' . $params['module_info'] . '.png';
            $config['icon'] = mw()->url_manager->link_to_file($config['icon']);
        }
    }
}
if (!empty($config)) {
    ?>

<div class="mw_iframe_header">
  <div class="mw_iframe_header_title"> <img src="<?php 
    print $config['icon'];
    ?>
" align="left" height="25"  class="mw_iframe_header_icon" /> <?php 
    print $config['name'];
    ?>
  
 
  </div>
 
 <a href="javascript:mw_delete_module_by_id('<?php 
    print $params['module_id'];
    ?>