public function render($params = array())
 {
     $render_file = $params['render_file'];
     $l = new \Microweber\View($render_file);
     $l->page_id = $params['page_id'];
     $l->content_id = $params['content_id'];
     $l->post_id = $params['post_id'];
     // $l->category_id = $params['category_id'];
     if (isset($params['content'])) {
         $l->content = $params['content'];
     }
     if (isset($params['category_id'])) {
         $l->category_id = $params['category_id'];
     }
     if (isset($params['category'])) {
         $l->category = $params['category'];
     }
     // $l->category = $params['category'];
     $l->page = $params['page'];
     $l->application = $this->app;
     if (!empty($params)) {
         foreach ($params as $k => $v) {
             $l->assign($k, $v);
         }
     }
     $l = $l->__toString();
     return $l;
 }
Example #2
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;
     }
 }
Example #3
0
 /**
  * make_field.
  *
  * @desc        make_field
  *
  * @category    forms
  *
  * @author      Microweber
  *
  * @link        http://microweber.com
  *
  * @param string $field_type
  * @param string $field_id
  * @param array  $settings
  */
 public function make($field_id = 0, $field_type = 'text', $settings = false)
 {
     if (is_array($field_id)) {
         if (!empty($field_id)) {
             $data = $field_id;
         }
     } else {
         if ($field_id != 0) {
             $data = $this->get_by_id($id = $field_id);
         }
     }
     if (isset($data['settings']) or isset($_REQUEST['settings']) and trim($_REQUEST['settings']) == 'y') {
         $settings = true;
     }
     if (isset($data['copy_from'])) {
         $copy_from = intval($data['copy_from']);
         if (is_admin() == true) {
             $table_custom_field = $this->table;
             $form_data = $this->app->database_manager->get_by_id($table_custom_field, $id = $copy_from);
             if (is_array($form_data)) {
                 $field_type = $form_data['type'];
                 $data['id'] = 0;
                 if (isset($data['save_on_copy'])) {
                     $cp = $form_data;
                     $cp['id'] = 0;
                     $cp['copy_of_field'] = $copy_from;
                     if (isset($data['rel_type'])) {
                         $cp['rel_type'] = $data['rel_type'];
                     }
                     if (isset($data['rel_id'])) {
                         $cp['rel_id'] = $data['rel_id'];
                     }
                     $this->save($cp);
                     $data = $cp;
                 } else {
                     $data = $form_data;
                 }
             }
         }
     } elseif (isset($data['field_id'])) {
         $data = $this->get_by_id($id = $data['field_id']);
     }
     if (isset($data['type'])) {
         $field_type = $data['type'];
     }
     if (!isset($data['custom_field_required'])) {
         $data['custom_field_required'] = 'n';
     }
     if (isset($data['type'])) {
         $field_type = $data['type'];
     }
     if (isset($data['field_type'])) {
         $field_type = $data['field_type'];
     }
     if (isset($data['field_values']) and !isset($data['value'])) {
         $data['values'] = $data['field_values'];
     }
     $data['type'] = $field_type;
     if (isset($data['options']) and is_string($data['options'])) {
         $data['options'] = $this->_decode_options($data['options']);
     }
     $data = $this->app->url_manager->replace_site_url_back($data);
     $dir = mw_includes_path();
     $dir = $dir . DS . 'custom_fields' . DS;
     $field_type = str_replace('..', '', $field_type);
     $load_from_theme = false;
     if (defined('ACTIVE_TEMPLATE_DIR')) {
         $custom_fields_from_theme = ACTIVE_TEMPLATE_DIR . 'modules' . DS . 'custom_fields' . DS;
         if (is_dir($custom_fields_from_theme)) {
             if ($settings == true or isset($data['settings'])) {
                 $file = $custom_fields_from_theme . $field_type . '_settings.php';
             } else {
                 $file = $custom_fields_from_theme . $field_type . '.php';
             }
             if (is_file($file)) {
                 $load_from_theme = true;
             }
         }
     }
     if ($load_from_theme == false) {
         if ($settings == true or isset($data['settings'])) {
             $file = $dir . $field_type . '_settings.php';
         } else {
             $file = $dir . $field_type . '.php';
         }
     }
     if (!is_file($file)) {
         $field_type = 'text';
         if ($settings == true or isset($data['settings'])) {
             $file = $dir . $field_type . '_settings.php';
         } else {
             $file = $dir . $field_type . '.php';
         }
     }
     $file = normalize_path($file, false);
     if (is_file($file)) {
         $l = new \Microweber\View($file);
         //
         $l->assign('settings', $settings);
         if (isset($data['params'])) {
             $l->assign('params', $data['params']);
         } else {
             $l->assign('params', false);
         }
         //  $l->settings = $settings;
         if (isset($data) and !empty($data)) {
             $l->data = $data;
         } else {
             $l->data = array();
         }
         $l->assign('data', $data);
         $layout = $l->__toString();
         return $layout;
     }
 }