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; }
public function save_content($data, $delete_the_cache = true) { if (is_string($data)) { $data = parse_params($data); } $mw_global_content_memory = array(); $adm = $this->app->user_manager->is_admin(); $table = $this->tables['content']; $table_data = $this->tables['content_data']; $checks = mw_var('FORCE_SAVE_CONTENT'); $orig_data = $data; $stop = false; if ($stop == true) { return array('error' => 'You are not logged in as admin to save content!'); } $cats_modified = false; if (!empty($data)) { if (!isset($data['id'])) { $data['id'] = 0; } if ($data['id'] == 0 and !isset($data['is_active'])) { $data['is_active'] = 1; } $this->app->event_manager->trigger('content.before.save', $data); if (intval($data['id']) == 0) { if (isset($data['subtype']) and $data['subtype'] == 'post' and !isset($data['content_type'])) { $data['subtype'] = 'post'; $data['content_type'] = 'post'; } if (!isset($data['subtype'])) { $data['subtype'] = 'post'; } if (!isset($data['content_type'])) { $data['content_type'] = 'post'; } } } if (isset($data['content_url']) and !isset($data['url'])) { $data['url'] = $data['content_url']; } if (!isset($data['parent']) and isset($data['content_parent'])) { $data['parent'] = $data['content_parent']; } if (isset($data['is_active'])) { if ($data['is_active'] === 'y') { $data['is_active'] = 1; } elseif ($data['is_active'] === 'n') { $data['is_active'] = 0; } } $data_to_save = $data; if (!isset($data['title']) and isset($data['content_title'])) { $data['title'] = $data['content_title']; } if (isset($data['title'])) { if ($data['title'] == '<br>' or $data['title'] == '<br />' or $data['title'] == '<br/>') { $data['title'] = ''; } $data['title'] = htmlspecialchars($data['title'], ENT_QUOTES, "UTF-8"); $data_to_save['title'] = $data['title']; } if (!isset($data['url']) and intval($data['id']) != 0) { $q = $this->get_by_id($data_to_save['id']); $thetitle = $q['title']; $q = $q['url']; $theurl = $q; } else { if (isset($data['url'])) { $theurl = $data['url']; } else { $theurl = $data['title']; } $thetitle = $data['title']; } if (isset($data['id']) and intval($data['id']) == 0) { if (!isset($data['is_deleted']) or $data['is_deleted'] == '') { $data_to_save['is_deleted'] = 0; } else { $data_to_save['is_deleted'] = $data['is_deleted']; } if (!isset($data['title']) or $data['title'] == '') { $data['title'] = "New page"; if (isset($data['content_type']) and $data['content_type'] != 'page') { $data['title'] = "New " . $data['content_type']; if (isset($data['subtype']) and $data['subtype'] != 'page' and $data['subtype'] != 'post' and $data['subtype'] != 'static' and $data['subtype'] != 'dynamic') { $data['title'] = "New " . $data['subtype']; } } $data_to_save['title'] = $data['title']; } } if (isset($data['url']) == false or $data['url'] == '') { if (isset($data['title']) != false and intval($data['id']) == 0) { $data['url'] = $this->app->url_manager->slug($data['title']); if ($data['url'] == '') { $data['url'] = date("Y-M-d-His"); } } } $url_changed = false; if (isset($data['url']) != false and is_string($data['url'])) { $search_weird_chars = array('%E2%80%99', '%E2%80%99', '%E2%80%98', '%E2%80%9C', '%E2%80%9D'); $str = $data['url']; $good[] = 9; #tab $good[] = 10; #nl $good[] = 13; #cr for ($a = 32; $a < 127; $a++) { $good[] = $a; } $newstr = ''; $len = strlen($str); for ($b = 0; $b < $len + 1; $b++) { if (isset($str[$b]) and in_array(ord($str[$b]), $good)) { $newstr .= $str[$b]; } } $newstr = str_replace('--', '-', $newstr); $newstr = str_replace('--', '-', $newstr); if ($newstr == '-' or $newstr == '--') { $newstr = 'post-' . date('YmdHis'); } $data['url'] = $newstr; $url_changed = true; $data_to_save['url'] = $data['url']; } if (isset($data['category']) or isset($data['categories'])) { $cats_modified = true; } $table_cats = $this->tables['categories']; if (isset($data_to_save['title']) and $data_to_save['title'] != '' and (!isset($data['url']) or trim($data['url']) == '')) { $data['url'] = $this->app->url_manager->slug($data_to_save['title']); } if (isset($data['url']) and $data['url'] != false) { if (trim($data['url']) == '') { $data['url'] = $this->app->url_manager->slug($data['title']); } $data['url'] = $this->app->database_manager->escape_string($data['url']); $date123 = date("YmdHis"); $get = array(); $get['url'] = $data['url']; $get['single'] = true; $q = $this->get($get); if (!empty($q)) { if ($data['id'] != $q['id']) { $data['url'] = $data['url'] . '-' . $date123; $data_to_save['url'] = $data['url']; } } if (isset($data_to_save['url']) and strval($data_to_save['url']) == '' and isset($data_to_save['quick_save']) == false) { $data_to_save['url'] = $data_to_save['url'] . '-' . $date123; } if (isset($data_to_save['title']) and strval($data_to_save['title']) == '' and isset($data_to_save['quick_save']) == false) { $data_to_save['title'] = 'post-' . $date123; } if (isset($data_to_save['url']) and strval($data_to_save['url']) == '' and isset($data_to_save['quick_save']) == false) { $data_to_save['url'] = strtolower(reduce_double_slashes($data['url'])); } } if (isset($data_to_save['url']) and is_string($data_to_save['url'])) { if ($data_to_save['url'] == '') { $data_to_save['url'] = date("Y-M-d-His"); } $data_to_save['url'] = str_replace(site_url(), '', $data_to_save['url']); } if (isset($data['created_at'])) { $data_to_save['created_at'] = $data['created_at']; } if (isset($data['updated_at'])) { $data_to_save['updated_at'] = $data['updated_at']; } $data_to_save_options = array(); if (isset($data_to_save['is_home']) and $data_to_save['is_home'] == 'y') { $data_to_save['is_home'] = 1; } elseif (isset($data_to_save['is_home']) and $data_to_save['is_home'] == 'n') { $data_to_save['is_home'] = 0; } if (isset($data_to_save['is_shop']) and $data_to_save['is_shop'] === 'y') { $data_to_save['is_shop'] = 1; } elseif (isset($data_to_save['is_shop']) and $data_to_save['is_shop'] === 'n') { $data_to_save['is_shop'] = 0; } if (isset($data_to_save['require_login']) and $data_to_save['require_login'] === 'y') { $data_to_save['require_login'] = 1; } elseif (isset($data_to_save['require_login']) and $data_to_save['require_login'] === 'n') { $data_to_save['require_login'] = 0; } if (isset($data_to_save['is_home']) and $data_to_save['is_home'] == 1) { if ($adm == true) { $q = Content::where('is_home', 1)->update(array('is_home' => 0)); } else { $data_to_save['is_home'] = 0; } } if (isset($data_to_save['content_type']) and strval($data_to_save['content_type']) == 'post') { if (isset($data_to_save['subtype']) and strval($data_to_save['subtype']) == 'static') { $data_to_save['subtype'] = 'post'; } else { if (isset($data_to_save['subtype']) and strval($data_to_save['subtype']) == 'dynamic') { $data_to_save['subtype'] = 'post'; } } } if (isset($data_to_save['subtype']) and strval($data_to_save['subtype']) == 'dynamic') { $check_ex = false; if (isset($data_to_save['subtype_value']) and trim($data_to_save['subtype_value']) != '' and intval($data_to_save['subtype_value']) > 0) { $check_ex = $this->app->category_manager->get_by_id(intval($data_to_save['subtype_value'])); } if ($check_ex == false) { if (isset($data_to_save['id']) and intval(trim($data_to_save['id'])) > 0) { $test2 = $this->app->category_manager->get('data_type=category&rel_type=content&rel_id=' . intval($data_to_save['id'])); if (isset($test2[0])) { $check_ex = $test2[0]; $data_to_save['subtype_value'] = $test2[0]['id']; } } unset($data_to_save['subtype_value']); } } $par_page = false; if (isset($data_to_save['content_type']) and strval($data_to_save['content_type']) == 'post') { if (isset($data_to_save['parent']) and intval($data_to_save['parent']) > 0) { $par_page = $this->get_by_id($data_to_save['parent']); } if (is_array($par_page)) { $change_to_dynamic = true; if (isset($data_to_save['is_home']) and $data_to_save['is_home'] == 1) { $change_to_dynamic = false; } if ($change_to_dynamic == true and $par_page['subtype'] == 'static') { $par_page_new = array(); $par_page_new['id'] = $par_page['id']; $par_page_new['subtype'] = 'dynamic'; $par_page_new = $this->app->database_manager->save($table, $par_page_new); $cats_modified = true; } if (!isset($data_to_save['categories'])) { $data_to_save['categories'] = ''; } if (is_string($data_to_save['categories']) and isset($par_page['subtype_value']) and intval($par_page['subtype_value']) != 0) { $data_to_save['categories'] = $data_to_save['categories'] . ', ' . intval($par_page['subtype_value']); } } $c1 = false; if (isset($data_to_save['category']) and !isset($data_to_save['categories'])) { $data_to_save['categories'] = $data_to_save['category']; } if (isset($data_to_save['categories']) and $par_page == false) { if (is_string($data_to_save['categories'])) { $c1 = explode(',', $data_to_save['categories']); if (is_array($c1)) { foreach ($c1 as $item) { $item = intval($item); if ($item > 0) { $cont_cat = $this->get('limit=1&content_type=page&subtype_value=' . $item); if (isset($cont_cat[0]) and is_array($cont_cat[0])) { $cont_cat = $cont_cat[0]; if (isset($cont_cat["subtype_value"]) and intval($cont_cat["subtype_value"]) > 0) { $data_to_save['parent'] = $cont_cat["id"]; break; } } } } } } } } if (isset($data_to_save['content'])) { if (trim($data_to_save['content']) == '' or $data_to_save['content'] == false) { $data_to_save['content'] = null; } else { if (isset($data['download_remote_images']) and $data['download_remote_images'] != false and $adm == true) { $site_url = $this->app->url_manager->site(); $images = mw()->parser->query($data_to_save['content'], 'img'); $to_download = array(); $to_replace = array(); $possible_sources = array(); if (isset($data['insert_content_image']) and $data['insert_content_image'] != false and isset($data['content'])) { $data['content'] = "<img src='{$data['insert_content_image']}' /> " . $data['content']; } if (!empty($images)) { foreach ($images as $image) { $srcs = array(); preg_match('/src="([^"]*)"/i', $image, $srcs); if (!empty($srcs) and isset($srcs[1]) and $srcs[1] != false) { $possible_sources[] = $srcs[1]; } } } if (!empty($possible_sources)) { foreach ($possible_sources as $image_src) { if (!stristr($image_src, $site_url)) { $to_replace[] = $image_src; $image_src = strtok($image_src, '?'); $ext = get_file_extension($image_src); switch (strtolower($ext)) { case 'jpg': case 'jpeg': case 'png': case 'gif': case 'svg': $to_download[] = $image_src; break; default: break; } } } } if (!empty($to_download)) { $to_download = array_unique($to_download); if (!empty($to_download)) { foreach ($to_download as $src) { $dl_dir = media_base_path() . 'downloaded' . DS; if (!is_dir($dl_dir)) { mkdir_recursive($dl_dir); } $dl_file = $dl_dir . md5($src) . basename($src); if (!is_file($dl_file)) { $is_dl = $this->app->url_manager->download($src, false, $dl_file); } if (is_file($dl_file)) { $url_local = dir2url($dl_file); $data_to_save['content'] = str_ireplace($src, $url_local, $data_to_save['content']); } } } } } $data_to_save['content'] = mw()->parser->make_tags($data_to_save['content']); } } if (!isset($data_to_save['updated_at'])) { $data_to_save['updated_at'] = date("Y-m-d H:i:s"); } if (isset($data_to_save['id']) and intval($data_to_save['id']) == 0 or !isset($data_to_save['id'])) { if (!isset($data_to_save['position']) or intval($data_to_save['position']) == 0) { $pos_params = array(); $pos_params['table'] = 'content'; if (isset($data_to_save['content_type']) and strval($data_to_save['content_type']) == 'page') { $pos_params['content_type'] = $data_to_save['content_type']; $pos_params['min'] = 'position'; } else { $pos_params['max'] = 'position'; } $get_max_pos = mw()->database_manager->get($pos_params); if (is_null($get_max_pos)) { $data_to_save['position'] = 1; } else { if (is_int($get_max_pos) or is_string($get_max_pos)) { if (isset($data_to_save['content_type']) and strval($data_to_save['content_type']) == 'page') { $data_to_save['position'] = intval($get_max_pos) - 1; } else { $data_to_save['position'] = intval($get_max_pos) + 1; } } } } $data_to_save['posted_at'] = $data_to_save['updated_at']; } $cats_modified = true; if (isset($data_to_save['url']) and $data_to_save['url'] == $this->app->url_manager->site()) { unset($data_to_save['url']); } $data_to_save['allow_html'] = true; $this->no_cache = true; //clean some fields if (isset($data_to_save['custom_field_type']) and isset($data_to_save['value'])) { unset($data_to_save['custom_field_type']); unset($data_to_save['value']); } if (isset($data_to_save['custom_field_help_text'])) { unset($data_to_save['custom_field_help_text']); unset($data_to_save['custom_field_help_text']); } if (isset($data_to_save['custom_field_is_active'])) { unset($data_to_save['custom_field_is_active']); } if (isset($data_to_save['name'])) { unset($data_to_save['name']); } if (isset($data_to_save['values'])) { unset($data_to_save['values']); } if (isset($data_to_save['value'])) { unset($data_to_save['value']); } if (isset($data_to_save['title'])) { $url_changed = true; } $data_to_save['table'] = $table; $data_fields = array(); if (!empty($orig_data)) { $data_str = 'data_'; $data_str_l = strlen($data_str); foreach ($orig_data as $k => $v) { if (is_string($k)) { if (strlen($k) > $data_str_l) { $rest = substr($k, 0, $data_str_l); $left = substr($k, $data_str_l, strlen($k)); if ($rest == $data_str) { if (!isset($data_to_save['data_fields'])) { $data_to_save['data_fields'] = array(); } $data_to_save['data_fields'][$left] = $v; } } } } } if (isset($data_to_save['parent']) and $data_to_save['parent'] != 0) { if (isset($data_to_save['id']) and $data_to_save['id'] != 0) { if ($data_to_save['parent'] == $data_to_save['id']) { $data_to_save['parent'] = 0; } } } $save = $this->app->database->extended_save($table, $data_to_save); $id = $save; if (isset($data_to_save['parent']) and $data_to_save['parent'] != 0) { $upd_posted = array(); $upd_posted['posted_at'] = $data_to_save['updated_at']; $upd_posted['id'] = $data_to_save['parent']; $save_posted = $this->app->database_manager->save($table, $upd_posted); } $after_save = $data_to_save; $after_save['id'] = $id; $this->app->event_manager->trigger('content.after.save', $after_save); $this->app->cache_manager->delete('content/' . $save); $this->app->cache_manager->delete('content_fields/global'); if ($url_changed != false) { $this->app->cache_manager->delete('menus'); $this->app->cache_manager->delete('categories'); } if (!isset($data_to_save['images']) and isset($data_to_save['pictures'])) { $data_to_save['images'] = $data_to_save['pictures']; } if (isset($data_to_save['images']) and is_string($data_to_save['images'])) { $data_to_save['images'] = explode(',', $data_to_save['images']); } if (isset($data_to_save['images']) and is_array($data_to_save['images']) and !empty($data_to_save['images'])) { $images_to_save = $data_to_save['images']; foreach ($images_to_save as $image_to_save) { if (is_string($image_to_save)) { $image_to_save = trim($image_to_save); if ($image_to_save != '') { $save_media = array(); $save_media['content_id'] = $id; $save_media['filename'] = $image_to_save; $check = $this->app->media_manager->get($save_media); $save_media['media_type'] = 'picture'; if ($check == false) { $this->app->media_manager->save($save_media); } } } elseif (is_array($image_to_save) and !empty($image_to_save)) { $save_media = $image_to_save; $save_media['content_id'] = $id; $this->app->media_manager->save($save_media); } } } if (isset($data_to_save['add_content_to_menu']) and is_array($data_to_save['add_content_to_menu'])) { foreach ($data_to_save['add_content_to_menu'] as $menu_id) { $ids_to_save = $save; $this->add_content_to_menu($ids_to_save, $menu_id); } } $custom_field_table = $this->tables['custom_fields']; $custom_field_table = mw()->database_manager->real_table_name($custom_field_table); $sid = mw()->user_manager->session_id(); $media_table = $this->tables['media']; $media_table = mw()->database_manager->real_table_name($media_table); if ($sid != false and $sid != '' and $id != false) { $clean = " UPDATE {$custom_field_table} SET\n rel_type =\"content\" ,\n rel_id =\"{$id}\"\n WHERE\n\n (rel_id=0 OR rel_id IS NULL OR rel_id =\"0\")\n AND rel_type =\"content\"\n\t "; $this->app->database_manager->q($clean); $clean = " UPDATE {$media_table} SET\n rel_id =\"{$id}\"\n WHERE\n session_id =\"{$sid}\"\n AND rel_type =\"content\" AND (rel_id=0 OR rel_id IS NULL)\n "; $this->app->database_manager->q($clean); } $this->app->cache_manager->delete('custom_fields'); $this->app->cache_manager->delete('custom_fields_values'); $this->app->cache_manager->delete('media/global'); if (isset($data_to_save['parent']) and intval($data_to_save['parent']) != 0) { $this->app->cache_manager->delete('content' . DIRECTORY_SEPARATOR . intval($data_to_save['parent'])); } if (isset($data_to_save['id']) and intval($data_to_save['id']) != 0) { $this->app->cache_manager->delete('content' . DIRECTORY_SEPARATOR . intval($data_to_save['id'])); } $this->app->cache_manager->delete('content' . DIRECTORY_SEPARATOR . 'global'); $this->app->cache_manager->delete('content' . DIRECTORY_SEPARATOR . '0'); $this->app->cache_manager->delete('content_fields/global'); $this->app->cache_manager->delete('content'); $this->app->cache_manager->delete('categories/global'); $this->app->cache_manager->delete('categories_items/global'); if ($cats_modified != false) { if (isset($c1) and is_array($c1)) { foreach ($c1 as $item) { $item = intval($item); if ($item > 0) { $this->app->cache_manager->delete('categories/' . $item); } } } } event_trigger('mw_save_content', $save); return $id; }
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; }
<?php 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'])) {
function extended_save_images($params) { if ($this->extended_save_has_permission()) { event_trigger('mw.database.extended_save_images', $params); $data_to_save = $params; if (isset($data_to_save['images'])) { $data_fields = $data_to_save['images']; if (is_array($data_fields) and !empty($data_fields)) { foreach ($data_fields as $k => $v) { if (isset($v['filename'])) { $save_cat_item = array(); $save_cat_item['rel_type'] = $data_to_save['table']; $save_cat_item['rel_id'] = $data_to_save['id']; if (isset($data_to_save['download_remote_images']) and $data_to_save['download_remote_images'] != false) { $is_url = false; if (filter_var($v['filename'], FILTER_VALIDATE_URL)) { if (!stristr($v['filename'], site_url())) { $image_src = $v['filename']; $to_download = false; $image_src = strtok($image_src, '?'); $ext = get_file_extension($image_src); switch (strtolower($ext)) { case 'jpg': case 'jpeg': case 'png': case 'gif': case 'svg': $to_download = $image_src; break; default: break; } if ($to_download != false) { $output_fn = 'ext_save' . crc32($to_download) . '.' . $ext; $relative = 'downloaded' . DS . $save_cat_item['rel_type'] . DS . $save_cat_item['rel_id'] . DS; $output = media_base_path() . $relative; $output_relative = media_base_url() . str_replace(DS, '/', $relative); $output = normalize_path($output, true); if (!is_dir($output)) { mkdir_recursive($output); } $output_file = $output . $output_fn; if (!is_file($output_file)) { $download = new \Microweber\Utils\Http(); $download->set_url($image_src); $download->download($output_file); } $v['filename'] = $output_relative . $output_fn; $v['filename'] = str_replace(site_url(), '{SITE_URL}', $v['filename']); } } } } $save_cat_item["filename"] = $v['filename']; $check = $this->app->media_manager->get($save_cat_item); if ($check == false) { if (isset($v['position'])) { $save_cat_item["position"] = $v['position']; } $save = $this->app->media_manager->save($save_cat_item); } } } } } } }
* * Copyright 2009, Moxiecode Systems AB * Released under GPL License. * * License: http://www.plupload.com/license * Contributing: http://www.plupload.com/contributing */ // HTTP headers for no cache etc header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); // Settings $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);
public function thumbnails_path() { return media_base_path() . 'thumbnail' . DS; }
$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); } if (defined('MW_PATH') and is_dir(MW_PATH) and !is_writable(MW_PATH)) { $check_pass = false; $must_be = MW_PATH; $server_check_errors['MW_PATH'] = _e("The directory " . MW_PATH . " must be writable", true); } ?> <?php if ($check_pass == false) { ?> <?php if (!empty($server_check_errors)) { ?> <h3> <?php
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'); } elseif (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; }
public function download_remote_images_from_text($text) { $site_url = $this->app->url_manager->site(); $images = $this->app->parser->query($text, 'img'); $to_download = array(); $to_replace = array(); $possible_sources = array(); if (!empty($images)) { foreach ($images as $image) { $srcs = array(); preg_match('/src="([^"]*)"/i', $image, $srcs); if (!empty($srcs) and isset($srcs[1]) and $srcs[1] != false) { $possible_sources[] = $srcs[1]; } } } if (!empty($possible_sources)) { foreach ($possible_sources as $image_src) { if (!stristr($image_src, $site_url)) { $to_replace[] = $image_src; $image_src = strtok($image_src, '?'); $ext = get_file_extension($image_src); switch (strtolower($ext)) { case 'jpg': case 'jpeg': case 'png': case 'gif': case 'svg': $to_download[] = $image_src; break; default: break; } } } } if (!empty($to_download)) { $to_download = array_unique($to_download); if (!empty($to_download)) { foreach ($to_download as $src) { $dl_dir = media_base_path() . 'downloaded' . DS; if (!is_dir($dl_dir)) { mkdir_recursive($dl_dir); } $dl_file = $dl_dir . md5($src) . basename($src); if (!is_file($dl_file)) { $is_dl = $this->app->url_manager->download($src, false, $dl_file); } if (is_file($dl_file)) { $url_local = dir2url($dl_file); $text = str_ireplace($src, $url_local, $text); } } } } return $text; }
$server_check_errors['MW_USERFILES'] = _e('The directory ' . MW_USERFILES . ' 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 (function_exists('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); } ?> <?php if ($check_pass == false) { ?> <?php if (!empty($server_check_errors)) { ?> <h3> <?php _e('Server check'); ?> </h3> <h4> <?php