Example #1
0
function templates_path()
{
    static $folder;
    if (!$folder) {
        $folder = userfiles_path() . MW_TEMPLATES_FOLDER_NAME . DIRECTORY_SEPARATOR;
    }
    return $folder;
}
Example #2
0
 public function run()
 {
     $removed = 0;
     $value = mw()->cache_manager->get('create_batch', $this->cache_group);
     if (isset($value['total']) and $value['total'] > 0) {
         if (isset($value['remaining']) and $value['remaining'] > 0) {
             $batch = mw()->media_manager->get_all('limit=30000');
             if ($batch) {
                 foreach ($batch as $k => $v) {
                     if (isset($v['id']) and isset($v['filename']) and $v['filename'] != false) {
                         $process = false;
                         if (stristr($v['filename'], '{SITE_URL}')) {
                             $process = true;
                         } else {
                             if (stristr($v['filename'], site_url())) {
                                 $process = true;
                             }
                         }
                         if ($process) {
                             $v['filename'] = str_ireplace('{SITE_URL}', '', $v['filename']);
                             $v['filename'] = str_ireplace(site_url(), '', $v['filename']);
                             $is_file = false;
                             $file1 = normalize_path(public_path() . DS . $v['filename'], false);
                             $file2 = normalize_path(base_path() . DS . $v['filename'], false);
                             $file3 = normalize_path(media_base_path() . DS . $v['filename'], false);
                             $file4 = normalize_path(userfiles_path() . DS . $v['filename'], false);
                             if (is_file($file1)) {
                                 $is_file = true;
                             } elseif (is_file($file2)) {
                                 $is_file = true;
                             } elseif (is_file($file3)) {
                                 $is_file = true;
                             } elseif (is_file($file4)) {
                                 $is_file = true;
                             }
                             if ($is_file == false) {
                                 mw()->media_manager->delete($v['id']);
                                 $removed++;
                             }
                         }
                     }
                 }
             }
         }
     }
     mw()->cache_manager->delete($this->cache_group);
     $resp = array('success' => "Removed " . $removed . ' items');
     return $resp;
 }
Example #3
0
 public function export_to_excel($params)
 {
     //this function is experimental
     set_time_limit(0);
     $adm = $this->app->user_manager->is_admin();
     if ($adm == false) {
         return array('error' => 'Error: not logged in as admin.' . __FILE__ . __LINE__);
     }
     if (!isset($params['id'])) {
         return array('error' => 'Please specify list id! By posting field id=the list id ');
     } else {
         $lid = intval($params['id']);
         $data = get_form_entires('limit=100000&list_id=' . $lid);
         $surl = $this->app->url_manager->site();
         $csv_output = '';
         if (is_array($data)) {
             $csv_output = 'id,';
             $csv_output .= 'created_at,';
             $csv_output .= 'user_ip,';
             foreach ($data as $item) {
                 if (isset($item['custom_fields'])) {
                     foreach ($item['custom_fields'] as $k => $v) {
                         $csv_output .= $this->app->format->no_dashes($k) . ",";
                         $csv_output .= "\t";
                     }
                 }
             }
             $csv_output .= "\n";
             foreach ($data as $item) {
                 if (isset($item['custom_fields'])) {
                     $csv_output .= $item['id'] . ",";
                     $csv_output .= "\t";
                     $csv_output .= $item['created_at'] . ",";
                     $csv_output .= "\t";
                     $csv_output .= $item['user_ip'] . ",";
                     $csv_output .= "\t";
                     foreach ($item['custom_fields'] as $item1 => $val) {
                         $output_val = $val;
                         $output_val = str_replace('{SITE_URL}', $surl, $output_val);
                         $csv_output .= $output_val . ",";
                         $csv_output .= "\t";
                     }
                     $csv_output .= "\n";
                 }
             }
         }
         $filename = 'export' . "_" . date("Y-m-d_H-i", time()) . uniqid() . '.csv';
         $filename_path = userfiles_path() . 'export' . DS . 'forms' . DS;
         $filename_path_index = userfiles_path() . 'export' . DS . 'forms' . DS . 'index.php';
         if (!is_dir($filename_path)) {
             mkdir_recursive($filename_path);
             if (!is_file($filename_path_index)) {
                 @touch($filename_path_index);
             }
         }
         $filename_path_full = $filename_path . $filename;
         file_put_contents($filename_path_full, $csv_output);
         $download = $this->app->url_manager->link_to_file($filename_path_full);
         return array('success' => 'Your file has been exported!', 'download' => $download);
     }
 }
Example #4
0
only_admin_access();
/**
 * Simple file browser
 *
 * Gets all files from dir and output them in a template
 *
 * @package		modules
 * @subpackage	files
 * @category	modules
 */
// Explore the files via a web interface.
$script = $config['url'];
// the name of this script
$path = media_base_path();
// the path the script should access
$path_restirct = userfiles_path();
// the path the script should access
if (isset($params['path']) and trim($params['path']) != '' and trim($params['path']) != 'false') {
    $path = $params['path'];
    // the path the script should access
}
$path = str_replace('./', '', $path);
$path = str_replace('..', '', $path);
$path = urldecode($path);
$path = str_replace($path_restirct, '', $path);
//$data = rglob($path);
$params_get_files = array();
$params_get_files['directory'] = $path_restirct . $path;
if (isset($params['search'])) {
    $params_get_files['search'] = $params['search'];
}
Example #5
0
$target_path = media_base_path() . DS;
$target_path = media_base_path() . DS . $host_dir . DS . 'uploaded' . DS;
$target_path = normalize_path($target_path, 0);
$path_restirct = userfiles_path();
// the path the script should access
if (isset($_REQUEST['path']) and trim($_REQUEST['path']) != '' and trim($_REQUEST['path']) != 'false') {
    $path = urldecode($_REQUEST['path']);
    $path = html_entity_decode($path);
    $path = htmlspecialchars_decode($path, ENT_NOQUOTES);
    //$path = urldecode($path);
    $path = str_replace('%2F', '/', $path);
    //$path = str_replace('%25252F','/',$path);
    $path = normalize_path($path, 0);
    $path = str_replace('..', '', $path);
    $path = str_replace($path_restirct, '', $path);
    $target_path = userfiles_path() . DS . $path;
    $target_path = normalize_path($target_path, 1);
}
$targetDir = $target_path;
if (!is_dir($targetDir)) {
    mkdir_recursive($targetDir);
}
//$targetDir = 'uploads';
$cleanupTargetDir = true;
// Remove old files
$maxFileAge = 5 * 3600;
// Temp file age in seconds
// 5 minutes execution time
@set_time_limit(5 * 60);
// Uncomment this one to fake upload time
// usleep(5000);
Example #6
0
 public function delete_media_file($params)
 {
     only_admin_access();
     $target_path = media_base_path() . 'uploaded' . DS;
     $target_path = normalize_path($target_path, 0);
     $path_restirct = userfiles_path();
     $fn_remove_path = $_REQUEST["path"];
     $resp = array();
     if ($fn_remove_path != false and is_array($fn_remove_path)) {
         foreach ($fn_remove_path as $key => $value) {
             $fn_remove = $this->app->url_manager->to_path($value);
             if (isset($fn_remove) and trim($fn_remove) != '' and trim($fn_remove) != 'false') {
                 $path = urldecode($fn_remove);
                 $path = normalize_path($path, 0);
                 $path = str_replace('..', '', $path);
                 $path = str_replace($path_restirct, '', $path);
                 $target_path = userfiles_path() . DS . $path;
                 $target_path = normalize_path($target_path, false);
                 if (stristr($target_path, media_base_path())) {
                     if (is_dir($target_path)) {
                         mw('Microweber\\Utils\\Files')->rmdir($target_path, false);
                         $resp = array('success' => 'Directory ' . $target_path . ' is deleted');
                     } else {
                         if (is_file($target_path)) {
                             unlink($target_path);
                             $resp = array('success' => 'File ' . basename($target_path) . ' is deleted');
                         } else {
                             $resp = array('error' => 'Not valid file or folder ' . $target_path . ' ');
                         }
                     }
                 } else {
                     $resp = array('error' => 'Not allowed to delete on ' . $target_path . ' ');
                 }
             }
         }
     }
     return $resp;
 }
Example #7
0
         $is_pdo_loaded = false;
     }
 }
 if ($is_pdo_loaded == false) {
     $check_pass = false;
     $server_check_errors['pdo'] = "The PDO MYSQL PHP extension must be loaded";
 }
 if (extension_loaded('gd') && function_exists('gd_info')) {
 } else {
     $check_pass = false;
     $server_check_errors['gd'] = _e("The GD extension must be loaded in PHP", true);
 }
 if (defined('userfiles_path()') and is_dir(userfiles_path()) and !is_writable(userfiles_path())) {
     $check_pass = false;
     $must_be = userfiles_path();
     $server_check_errors['userfiles_path()'] = _e("The directory " . userfiles_path() . " must be writable", true);
 }
 if (defined('MW_CACHE_ROOT_DIR') and is_dir(MW_CACHE_ROOT_DIR) and !is_writable(MW_CACHE_ROOT_DIR)) {
     $check_pass = false;
     $must_be = MW_CACHE_ROOT_DIR;
     $server_check_errors['MW_CACHE_ROOT_DIR'] = _e("The directory " . MW_CACHE_ROOT_DIR . " must be writable", true);
 }
 if (defined('MW_CACHE_ROOT_DIR') and is_dir(MW_CACHE_ROOT_DIR) and !is_writable(MW_CACHE_ROOT_DIR)) {
     $check_pass = false;
     $must_be = MW_CACHE_ROOT_DIR;
     $server_check_errors['MW_CACHE_ROOT_DIR'] = _e("The directory " . MW_CACHE_ROOT_DIR . " must be writable", true);
 }
 if (defined('media_base_path()') and is_dir(media_base_path()) and !is_writable(media_base_path())) {
     $check_pass = false;
     $must_be = media_base_path();
     $server_check_errors['media_base_path()'] = _e("The directory " . media_base_path() . " must be writable", true);
Example #8
0
    <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>
    <td><?php 
print site_url();
?>
Example #9
0
    <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>
    <td><?php 
echo site_url();
?>
Example #10
0
 public function clear_cache()
 {
     $userfiles_dir = userfiles_path();
     $userfiles_cache_dir = normalize_path($userfiles_dir . 'cache' . DS);
     if (is_dir($userfiles_cache_dir)) {
         if (function_exists('rmdir_recursive')) {
             rmdir_recursive($userfiles_cache_dir);
         }
     }
 }
Example #11
0
 function template_save_css($params)
 {
     $is_admin = $this->app->user_manager->is_admin();
     if ($is_admin == false) {
         return false;
     }
     if (is_string($params)) {
         $params = parse_params($params);
     }
     $ref_page = false;
     if (!isset($params['active_site_template'])) {
         if (!isset($params['content_id'])) {
             if (isset($_SERVER['HTTP_REFERER'])) {
                 $ref_page_url = $_SERVER['HTTP_REFERER'];
                 if ($ref_page_url != '') {
                     $ref_page_url_rel = str_ireplace(site_url(), '', $ref_page_url);
                     if ($ref_page_url_rel == '') {
                         $ref_page1 = $this->app->content_manager->homepage();
                     } else {
                         $ref_page1 = $this->app->content_manager->get_by_url($ref_page_url, true);
                     }
                     if (isset($ref_page1['id'])) {
                         $ref_page = $this->app->content_manager->get_by_id(intval($ref_page1['id']));
                     }
                 }
             }
         } else {
             $ref_page = $this->app->content_manager->get_by_id(intval($params['content_id']));
         }
         if (isset($ref_page['id']) and isset($ref_page['content_type']) and $ref_page['content_type'] != 'page') {
             $ref_page_parent = $this->app->content_manager->get_by_id(intval($ref_page['id']));
             if (isset($ref_page_partent['parent']) and intval($ref_page_partent['parent']) != 0) {
                 $ref_page = $this->app->content_manager->get_by_id(intval($ref_page_partent['id']));
             } else {
                 $ref_page_parents = $this->app->content_manager->get_parents(intval($ref_page['id']));
                 if (!empty($ref_page_parents)) {
                     $ref_page_parent = array_pop($ref_page_parents);
                     $ref_page = $this->app->content_manager->get_by_id($ref_page_parent);
                 }
             }
         }
     } else {
         $ref_page = $params;
     }
     if (!is_array($ref_page) or empty($ref_page)) {
         return false;
     }
     $pd = $ref_page;
     if ($is_admin == true and is_array($pd)) {
         $save_page = $pd;
         if (isset($save_page["layout_file"]) and $save_page["layout_file"] == 'inherit') {
             $inherit_from_id = $this->app->content_manager->get_inherited_parent($save_page["id"]);
             $inherit_from = $this->app->content_manager->get_by_id($inherit_from_id);
             if (is_array($inherit_from) and isset($inherit_from['active_site_template'])) {
                 $save_page['active_site_template'] = $inherit_from['active_site_template'];
                 $save_page['layout_file'] = $inherit_from['layout_file'];
             }
         }
         $template = false;
         if (!isset($save_page['active_site_template']) or $save_page['active_site_template'] == '') {
             $template = 'default';
         } else {
             if (isset($save_page['active_site_template'])) {
                 $template = $save_page['active_site_template'];
             }
         }
         if ($template == 'default') {
             $site_template_settings = $this->app->option_manager->get('current_template', 'template');
             if ($site_template_settings != false and $site_template_settings != 'default') {
                 $template = $site_template_settings;
             }
         }
         $final_file_blocks = array();
         if ($template != false) {
             if (isset($_POST['save_template_settings'])) {
                 $json = json_encode($_POST);
                 $option = array();
                 $option['option_value'] = $json;
                 $option['option_key'] = 'template_settings';
                 $option['option_group'] = 'template_' . $template;
                 save_option($option);
             }
             $template_folder = templates_path() . $template . DS;
             $template_url = templates_url() . $template . '/';
             $this_template_url = THIS_TEMPLATE_URL;
             $template_folder = userfiles_path() . 'css' . DS . $template . DS;
             if (!is_dir($template_folder)) {
                 mkdir_recursive($template_folder);
             }
             $live_edit_css = $template_folder . 'live_edit.css';
             $fcont = '';
             if (is_file($live_edit_css)) {
                 $fcont = file_get_contents($live_edit_css);
             }
             $css_cont = $fcont;
             $css_cont_new = $css_cont;
             //@import on top
             $sort_params = array();
             $sort_params2 = array();
             foreach ($params as $item) {
                 if (isset($item['selector']) and trim($item['selector']) == '@import' and isset($item["value"])) {
                     if ($item['value'] != 'reset') {
                         $sort_params[] = $item;
                     }
                 } else {
                     $sort_params2[] = $item;
                 }
             }
             $params = array_merge($sort_params, $sort_params2);
             foreach ($params as $item) {
                 $curr = "";
                 if (!isset($item["css"]) and isset($item["property"]) and isset($item['value'])) {
                     if ($item['value'] == 'reset') {
                         $item["css"] = 'reset';
                     } else {
                         if (isset($item['selector']) and trim($item['selector']) == '@import' and isset($item["value"])) {
                             $props = explode(',', $item['property']);
                             foreach ($props as $prop) {
                                 $curr .= $prop . " " . $item['value'] . ";";
                             }
                         } else {
                             $props = explode(',', $item['property']);
                             $curr = "";
                             foreach ($props as $prop) {
                                 if (isset($item["value"]) and trim($item["value"]) != '') {
                                     $curr .= $prop . ":" . $item['value'] . ";";
                                 }
                             }
                         }
                         if ($curr != '') {
                             $item["css"] = $curr;
                         }
                     }
                 }
                 if (isset($item['selector']) and trim($item['selector']) != '' and isset($item["css"])) {
                     $item["selector"] = str_ireplace('.element-current', '', $item["selector"]);
                     $item["selector"] = str_ireplace('.mwfx', '', $item["selector"]);
                     $item["selector"] = str_ireplace('.mw_image_resizer', '', $item["selector"]);
                     $item["selector"] = str_ireplace('.ui-resizable', '', $item["selector"]);
                     $item["selector"] = str_ireplace('.ui-draggable', '', $item["selector"]);
                     $item["css"] = str_ireplace('background:url(;', '', $item["css"]);
                     $item["css"] = str_ireplace('background:;', '', $item["css"]);
                     $item["css"] = str_ireplace('background-image:url(;', '', $item["css"]);
                     $item["css"] = str_ireplace('background-image: url("");', 'background-image: none;', $item["css"]);
                     $sel = trim($item['selector']);
                     $css = trim($item["css"]);
                     if (trim($sel) != '' and strlen($sel) > 2 and strlen($css) > 2) {
                         $delim = "\n /* {$sel} */ \n";
                         //$item["css"] = str_ireplace($this_template_url, '', $item["css"]);
                         //$item["css"] = str_ireplace($template_url, '', $item["css"]);
                         $item["css"] = str_ireplace('http://', '//', $item["css"]);
                         $item["css"] = str_ireplace('https://', '//', $item["css"]);
                         $is_existing = explode($delim, $css_cont_new);
                         if (!empty($is_existing)) {
                             $srings = $this->app->format->string_between($css_cont_new, $delim, $delim);
                             if ($srings != false) {
                                 $css_cont_new = str_ireplace($srings, '', $css_cont_new);
                                 $css_cont_new = str_ireplace($delim, '', $css_cont_new);
                             }
                         }
                         if (trim($item["css"]) != 'reset' and trim($item["css"]) != 'reset;') {
                             $css_cont_new .= $delim;
                             if (isset($sel) and trim($sel) == '@import') {
                                 $css_cont_new .= $sel . ' ' . $item["css"] . ' ';
                             } else {
                                 $css_cont_new .= $sel . ' { ' . $item["css"] . ' }';
                             }
                             $css_cont_new .= $delim;
                         }
                     }
                 }
             }
             $resp = array();
             $resp['url'] = $this->app->url_manager->link_to_file($live_edit_css);
             if ($css_cont_new != '' and $css_cont != $css_cont_new) {
                 file_put_contents($live_edit_css, $css_cont_new);
                 //  print $css_cont_new;
             }
             $resp['content'] = $css_cont_new;
             return $resp;
         }
     }
 }
Example #12
0
 function get_import_location()
 {
     if (defined('MW_CRON_EXEC')) {
     } else {
         if (!is_admin()) {
             return false;
         }
     }
     $loc = $this->imports_folder;
     if ($loc != false) {
         return $loc;
     }
     $folder_root = false;
     if (function_exists('userfiles_path')) {
         $folder_root = userfiles_path();
     } elseif (mw_cache_path()) {
         $folder_root = normalize_path(mw_cache_path());
     }
     $here = $folder_root . "import" . DS;
     if (!is_dir($here)) {
         mkdir_recursive($here);
         $hta = $here . '.htaccess';
         if (!is_file($hta)) {
             touch($hta);
             file_put_contents($hta, 'Deny from all');
         }
     }
     $here = $folder_root . "import" . DS . get_table_prefix() . DS;
     $here2 = $this->app->option_manager->get('import_location', 'admin/import');
     if ($here2 != false and is_string($here2) and trim($here2) != 'default' and trim($here2) != '') {
         $here2 = normalize_path($here2, true);
         if (!is_dir($here2)) {
             mkdir_recursive($here2);
         }
         if (is_dir($here2)) {
             $here = $here2;
         }
     }
     if (!is_dir($here)) {
         mkdir_recursive($here);
     }
     $loc = $here;
     $this->imports_folder = $loc;
     return $here;
 }
 private function install_log($text)
 {
     $log_file = userfiles_path() . 'install_log.txt';
     if (!is_file($log_file)) {
         @touch($log_file);
     }
     if (is_file($log_file)) {
         $json = array('date' => date('H:i:s'), 'msg' => $text);
         if ($text == 'done' or $text == 'Preparing to install') {
             @file_put_contents($log_file, $text . "\n");
         } else {
             @file_put_contents($log_file, $text . "\n", FILE_APPEND);
         }
     }
 }
Example #14
0
 public function thumbnails_path()
 {
     $userfiles_dir = userfiles_path();
     $userfiles_cache_dir = normalize_path($userfiles_dir . 'cache' . DS . 'thumbnails' . DS);
     // media_base_path() . 'thumbnail' . DS;
     return $userfiles_cache_dir;
 }
Example #15
0
 public function export_orders1()
 {
     $data = get_orders('no_limit=true&order_completed=1');
     if (!$data) {
         return array('error' => 'You do not have any orders');
     }
     $csv_output = '';
     $head = reset($data);
     foreach ($head as $k => $v) {
         $csv_output .= $this->app->format->no_dashes($k) . ',';
         // $csv_output .= "\t";
     }
     $csv_output .= "\n";
     foreach ($data as $item) {
         foreach ($item as $k => $v) {
             $csv_output .= $this->app->format->no_dashes($v) . ',';
             //  $csv_output .= "\t";
         }
         $cart_items = mw()->shop_manager->order_items($item['id']);
         if (!empty($cart_items)) {
         }
         dd($cart_items);
         $csv_output .= "\n";
     }
     //dd($csv_output);
     $filename = 'orders' . '_' . date('Y-m-d_H-i', time()) . uniqid() . '.csv';
     $filename_path = userfiles_path() . 'export' . DS . 'orders' . DS;
     $filename_path_index = userfiles_path() . 'export' . DS . 'orders' . DS . 'index.php';
     if (!is_dir($filename_path)) {
         mkdir_recursive($filename_path);
     }
     if (!is_file($filename_path_index)) {
         @touch($filename_path_index);
     }
     $filename_path_full = $filename_path . $filename;
     file_put_contents($filename_path_full, $csv_output);
     $download = $this->app->url_manager->link_to_file($filename_path_full);
     return array('success' => 'Your file has been exported!', 'download' => $download);
     dd('export_orders');
 }
 public function editor_tools()
 {
     if (!defined('IN_ADMIN') and is_admin()) {
         define('IN_ADMIN', true);
     }
     if (!defined('IN_EDITOR_TOOLS')) {
         define('IN_EDITOR_TOOLS', true);
     }
     if (mw_is_installed() == true) {
         //event_trigger('mw_db_init');
         //  event_trigger('mw_cron');
     }
     $tool = $this->app->url_manager->segment(1);
     if ($tool) {
     } else {
         $tool = 'index';
     }
     $page = false;
     if (isset($_REQUEST['content_id'])) {
         if (intval($_REQUEST['content_id']) == 0) {
             $this->create_new_page = true;
             $custom_content_data_req = $_REQUEST;
             $custom_content_data = array();
             if (isset($custom_content_data_req['content_type'])) {
                 //    $custom_content_data['content_type'] = $custom_content_data_req['content_type'];
             }
             if (isset($custom_content_data_req['content_type'])) {
                 $custom_content_data['content_type'] = $custom_content_data_req['content_type'];
             }
             if (isset($custom_content_data_req['subtype'])) {
                 $custom_content_data['subtype'] = $custom_content_data_req['subtype'];
             }
             if (isset($custom_content_data_req['parent_page']) and is_numeric($custom_content_data_req['parent_page'])) {
                 $custom_content_data['parent'] = intval($custom_content_data_req['parent_page']);
             }
             if (isset($custom_content_data_req['preview_layout'])) {
                 //  $custom_content_data['preview_layout'] =($custom_content_data_req['preview_layout']);
             }
             if (!empty($custom_content_data)) {
                 $custom_content_data['id'] = 0;
                 $this->content_data = $custom_content_data;
             }
             $this->return_data = 1;
             $page = $this->frontend();
         } else {
             $page = $this->app->content_manager->get_by_id($_REQUEST['content_id']);
         }
     } elseif (isset($_SERVER['HTTP_REFERER'])) {
         $url = $_SERVER['HTTP_REFERER'];
         $url = explode('?', $url);
         $url = $url[0];
         if (trim($url) == '' or trim($url) == $this->app->url_manager->site()) {
             //$page = $this->app->content_manager->get_by_url($url);
             $page = $this->app->content_manager->homepage();
         } else {
             $page = $this->app->content_manager->get_by_url($url);
         }
     } else {
         $url = $this->app->url_manager->string();
     }
     if (!isset($page['active_site_template'])) {
         $page['active_site_template'] = 'default';
     }
     if (isset($_GET['preview_template'])) {
         $page['active_site_template'] = $_GET['preview_template'];
     }
     if (isset($_GET['content_type'])) {
         $page['content_type'] = $_GET['content_type'];
     }
     if (isset($_GET['preview_layout']) and $_GET['preview_layout'] != 'inherit') {
         $page['layout_file'] = $_GET['preview_layout'];
     }
     $this->app->content_manager->define_constants($page);
     $page['render_file'] = $this->app->template->get_layout($page);
     if (defined('TEMPLATE_DIR')) {
         $load_template_functions = TEMPLATE_DIR . 'functions.php';
         if (is_file($load_template_functions)) {
             include_once $load_template_functions;
         }
     }
     $params = $_REQUEST;
     $tool = str_replace('..', '', $tool);
     $p_index = mw_includes_path() . 'toolbar/editor_tools/index.php';
     $p_index = normalize_path($p_index, false);
     $standalone_edit = true;
     $p = mw_includes_path() . 'toolbar/editor_tools/' . $tool . '/index.php';
     $standalone_edit = false;
     if ($tool == 'plupload') {
         $standalone_edit = true;
     }
     if ($tool == 'plupload') {
         $standalone_edit = true;
     }
     if ($tool == 'imageeditor') {
         $standalone_edit = true;
     }
     if ($tool == 'rte_image_editor') {
         $standalone_edit = true;
     }
     if ($tool == 'editor_toolbar') {
         $standalone_edit = true;
     }
     if ($tool == 'wysiwyg') {
         $standalone_edit = false;
         $ed_file_from_template = TEMPLATE_DIR . 'editor.php';
         if (is_file($ed_file_from_template)) {
             $p_index = $ed_file_from_template;
         }
         if (isset($page['content_type']) and $page['content_type'] != 'post' and $page['content_type'] != 'page' and $page['content_type'] != 'product') {
             if (isset($page['subtype']) and ($page['subtype'] != 'post' and $page['subtype'] != 'product')) {
                 $standalone_edit = true;
             }
         } elseif (isset($page['content_type']) and $page['content_type'] == 'post') {
             if (isset($page['subtype']) and ($page['subtype'] != 'post' and $page['subtype'] != 'product')) {
                 $standalone_edit = true;
             }
         }
         if ($standalone_edit) {
             if (!isset($page['content'])) {
                 $page['content'] = '<div class="element"></div>';
             }
             $page['content'] = '<div class="edit" field="content" rel="content" contenteditable="true">' . $page['content'] . '</div>';
             $page['render_file'] = false;
         }
         //
         //  $page['content'] = '<div class="edit" field="content" rel="content" contenteditable="true">' . $page['content'] . '</div>';
     }
     $default_css = '';
     $apijs_settings_loaded = '';
     $apijs_loaded = '';
     $p = normalize_path($p, false);
     $l = new \Microweber\View($p_index);
     $l->params = $params;
     $layout = $l->__toString();
     $apijs_loaded = false;
     if ($layout != false) {
         //$apijs_loaded = $this->app->template->get_apijs_url() . '?id=' . CONTENT_ID;
         $apijs_loaded = $this->app->template->get_apijs_url();
         // $apijs_settings_loaded = $this->app->template->get_apijs_settings_url() . '?id=' . CONTENT_ID . '&category_id=' . CATEGORY_ID;
         $apijs_settings_loaded = $this->app->template->get_apijs_settings_url();
         // $is_admin = $this->app->user_manager->is_admin();
         $default_css = '<link rel="stylesheet" href="' . mw_includes_url() . 'default.css" type="text/css" />';
         $headers = event_trigger('site_header', TEMPLATE_NAME);
         $template_headers_append = '';
         $one = 1;
         if (is_array($headers)) {
             foreach ($headers as $modify) {
                 if ($modify != false and is_string($modify) and $modify != '') {
                     $template_headers_append = $template_headers_append . $modify;
                 }
             }
             if ($template_headers_append != false and $template_headers_append != '') {
                 $layout = str_ireplace('</head>', $template_headers_append . '</head>', $l, $one);
             }
         }
         if (function_exists('template_headers_src')) {
             $template_headers_src = template_headers_src();
             if ($template_headers_src != false and $template_headers_src != '') {
                 $layout = str_ireplace('</head>', $template_headers_src . '</head>', $l, $one);
             }
         }
         if (isset($page['active_site_template'])) {
             if ($page['active_site_template'] == '') {
                 $page['active_site_template'] = 'default';
             }
             if ($page['active_site_template'] == 'default') {
                 $active_site_template = $this->app->option_manager->get('current_template', 'template');
             } else {
                 $active_site_template = $page['active_site_template'];
                 if ($active_site_template == 'mw_default') {
                     $active_site_template = 'default';
                 }
             }
             $live_edit_css_folder = userfiles_path() . 'css' . DS . $active_site_template . DS;
             $custom_live_edit = $live_edit_css_folder . DS . 'live_edit.css';
             if (is_file($custom_live_edit)) {
                 $live_edit_url_folder = userfiles_url() . 'css/' . $active_site_template . '/';
                 $custom_live_editmtime = filemtime($custom_live_edit);
                 $liv_ed_css = '<link rel="stylesheet" href="' . $live_edit_url_folder . 'live_edit.css?version=' . $custom_live_editmtime . '" id="mw-template-settings" type="text/css" />';
                 $layout = str_ireplace('</head>', $liv_ed_css . '</head>', $l);
             }
         }
     }
     if (isset($_REQUEST['plain'])) {
         if (is_file($p)) {
             $p = new \Microweber\View($p);
             $p->params = $params;
             $layout = $p->__toString();
             echo $layout;
             return;
         }
     } elseif (is_file($p)) {
         $p = new \Microweber\View($p);
         $p->params = $params;
         $layout_tool = $p->__toString();
         $layout = str_replace('{content}', $layout_tool, $layout);
     } else {
         $layout = str_replace('{content}', 'Not found!', $layout);
     }
     $category = false;
     if (defined('CATEGORY_ID')) {
         $category = $this->app->category_manager->get_by_id(CATEGORY_ID);
     }
     //    $page['render_file'] = $render_file;
     if (!$standalone_edit) {
         if (isset($page['render_file'])) {
             event_trigger('mw.front', $page);
             $l = new \Microweber\View($page['render_file']);
             $l->page_id = PAGE_ID;
             $l->content_id = CONTENT_ID;
             $l->post_id = POST_ID;
             $l->category_id = CATEGORY_ID;
             $l->content = $page;
             $l->category = $category;
             $l->params = $params;
             $l->page = $page;
             $l->application = $this->app;
             $l = $l->__toString();
             //
             //
             //                $render_params = array();
             //                $render_params['render_file'] = $p;
             //                $render_params['page_id'] = PAGE_ID;
             //                $render_params['content_id'] = CONTENT_ID;
             //                $render_params['post_id'] = POST_ID;
             //                $render_params['category_id'] = CATEGORY_ID;
             //                $render_params['page'] = $page;
             //                $render_params['params'] = $params;
             //                $render_params['application'] = $this->app;
             //  $l = $this->app->template->render($render_params);
             if (is_object($l)) {
                 return $l;
             }
             $l = $this->app->parser->process($l, $options = false);
             //                if(isset($page['content']) and $page['content'] != false){
             //
             //                if($page['content'] == ''){
             //                    unset($page['content']);
             //                }
             //                } else {
             //                    $page['content'] = $l;
             //                }
             $editable = $this->app->parser->isolate_content_field($l, true);
             if ($editable != false) {
                 $page['content'] = $editable;
             } else {
                 if ($tool == 'wysiwyg') {
                     $err = 'no editable content region found';
                     if (isset($page['layout_file'])) {
                         $file = $page['layout_file'];
                         $file = str_replace('__', '/', $page['layout_file']);
                         $err = $err . ' in file ' . $file;
                     }
                     if (isset($page['active_site_template'])) {
                         $err = $err . ' (' . $page['active_site_template'] . ' template)';
                     }
                     return $err;
                 }
             }
         }
     }
     if (!stristr($layout, $apijs_loaded)) {
         $rep = 0;
         $default_css = $default_css . "\r\n" . '<script src="' . $apijs_settings_loaded . '"></script>' . "\r\n";
         $default_css = $default_css . "\r\n" . '<script src="' . $apijs_loaded . '"></script>' . "\r\n";
         $layout = str_ireplace('<head>', '<head>' . $default_css, $layout, $rep);
     }
     if (isset($page['content'])) {
         if ($standalone_edit) {
             if (!isset($render_file)) {
                 if (stristr($page['content'], 'field="content"') or stristr($page['content'], 'field=\'content\'')) {
                     $page['content'] = '<div class="edit" field="content" rel="content" contenteditable="true">' . $page['content'] . '</div>';
                 }
             }
         }
         $layout = str_replace('{content}', $page['content'], $layout);
     }
     $layout = mw()->template->process_meta($layout);
     $layout = $this->app->parser->process($layout, $options = false);
     $layout = execute_document_ready($layout);
     $layout = str_replace('{head}', '', $layout);
     $layout = str_replace('{content}', '', $layout);
     echo $layout;
     return;
 }
Example #17
0
 public function create_full()
 {
     if (!defined('INI_SYSTEM_CHECK_DISABLED')) {
         define('INI_SYSTEM_CHECK_DISABLED', ini_get('disable_functions'));
     }
     if (!strstr(INI_SYSTEM_CHECK_DISABLED, 'ini_set')) {
         ini_set('memory_limit', '512M');
     }
     if (!strstr(INI_SYSTEM_CHECK_DISABLED, 'set_time_limit')) {
         set_time_limit(600);
     }
     $backup_actions = array();
     $backup_actions[] = 'make_db_backup';
     $userfiles_folder = userfiles_path();
     $media_folder = media_base_path();
     $all_images = $this->app->media_manager->get_all('limit=10000');
     if (!empty($all_images)) {
         foreach ($all_images as $image) {
             if (isset($image['filename']) and $image['filename'] != false) {
                 $fn = url2dir($image['filename']);
                 if (is_file($fn)) {
                     $backup_actions[] = $fn;
                 }
             }
         }
     }
     $host = parse_url(site_url());
     $host_dir = false;
     if (isset($host['host'])) {
         $host_dir = $host['host'];
         $host_dir = str_ireplace('www.', '', $host_dir);
         $host_dir = str_ireplace('.', '-', $host_dir);
     }
     $userfiles_folder_uploaded = $media_folder . DS . $host_dir . DS . 'uploaded' . DS;
     $userfiles_folder_uploaded = $media_folder . DS . $host_dir . DS;
     $userfiles_folder_uploaded = \normalize_path($userfiles_folder_uploaded);
     $folders = \rglob($userfiles_folder_uploaded . '*', GLOB_NOSORT);
     if (!is_array($folders)) {
         $folders = array();
     }
     $cust_css_dir = $userfiles_folder . 'css' . DS;
     if (is_dir($cust_css_dir)) {
         $more_folders = \rglob($cust_css_dir . '*', GLOB_NOSORT);
         if (!empty($more_folders)) {
             $folders = array_merge($folders, $more_folders);
         }
     }
     if (!empty($folders)) {
         $text_files = array();
         foreach ($folders as $fold) {
             if (!stristr($fold, 'backup')) {
                 if (stristr($fold, '.php') or stristr($fold, '.js') or stristr($fold, '.css')) {
                     $text_files[] = $fold;
                 } else {
                     $backup_actions[] = $fold;
                 }
             }
         }
         if (!empty($text_files)) {
             $backup_actions = array_merge($text_files, $backup_actions);
         }
     }
     $cache_id = 'backup_queue';
     $cache_id_loc = 'backup_progress';
     $cache_state_id = 'backup_zip_state';
     $this->app->cache_manager->save($backup_actions, $cache_id, 'backup');
     $this->app->cache_manager->save(false, $cache_id_loc, 'backup');
     $this->app->cache_manager->save(false, $cache_state_id, 'backup');
     if (!defined('MW_NO_SESSION')) {
         define('MW_NO_SESSION', 1);
     }
     return;
 }
Example #18
0
function _mw_get_language_file_content_namespaced($namespace)
{
    if ($namespace == false) {
        return false;
    }
    global $mw_language_content_namespace;
    $namespace = trim($namespace);
    $namespace = str_replace(' ', '', $namespace);
    $namespace = str_replace('..', '', $namespace);
    $namespace = str_replace('\\', '/', $namespace);
    if (isset($mw_language_content_namespace[$namespace]) and !empty($mw_language_content_namespace[$namespace])) {
        return $mw_language_content_namespace[$namespace];
    }
    $lang = current_lang();
    $lang_file = userfiles_path() . $namespace . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . $lang . '.json';
    $lang_file = normalize_path($lang_file, false);
    $lang_file2 = userfiles_path() . 'language' . DIRECTORY_SEPARATOR . $namespace . DIRECTORY_SEPARATOR . $lang . '.json';
    $lang_file2 = normalize_path($lang_file2, false);
    $lang_file3 = userfiles_path() . $namespace . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . 'en.json';
    $lang_file3 = normalize_path($lang_file3, false);
    if (!isset($mw_language_content_namespace[$namespace])) {
        $mw_language_content_namespace[$namespace] = array();
    }
    if (is_file($lang_file2)) {
        $language_str = file_get_contents($lang_file2);
        $language = json_decode($language_str, true);
        if (isset($language) and is_array($language)) {
            foreach ($language as $k => $v) {
                if (isset($mw_language_content[$namespace][$k]) == false) {
                    $mw_language_content_namespace[$namespace][$k] = $v;
                }
            }
        }
    }
    if (is_file($lang_file)) {
        $language_str = file_get_contents($lang_file);
        $language = json_decode($language_str, true);
        if (isset($language) and is_array($language)) {
            foreach ($language as $k => $v) {
                if (isset($mw_language_content_namespace[$namespace][$k]) == false) {
                    $mw_language_content_namespace[$namespace][$k] = $v;
                }
            }
        }
    }
    if (is_file($lang_file3)) {
        $language_str = file_get_contents($lang_file3);
        $language = json_decode($language_str, true);
        if (isset($language) and is_array($language)) {
            foreach ($language as $k => $v) {
                if (isset($mw_language_content_namespace[$namespace][$k]) == false) {
                    $mw_language_content_namespace[$namespace][$k] = $v;
                }
            }
        }
    }
    return $mw_language_content_namespace[$namespace];
}