/** * Rename folder * @param $folder_id * @param $new_title * @throws Exception * @return array */ public function rename_folder($folder_id, $new_title) { if (substr_count($new_title, '/') > 0 or !Assets_helper::is_allowed_folder_name($new_title)) { throw new Exception(lang('invalid_folder_path')); } // swap whitespace with underscores $new_title = preg_replace('/\\s+/', '_', $new_title); $source_folder = $this->EE->assets_lib->get_folder_row_by_id($folder_id); $parent_row = $this->EE->assets_lib->get_folder_row_by_id($source_folder->parent_id); $source_path = Assets_helper::normalize_path(substr($this->get_folder_server_path($source_folder->full_path, $source_folder), 0, -1)); $base = pathinfo($source_path, PATHINFO_DIRNAME); if ($base == '.') { $base = ""; } else { $base .= "/"; } $target = $base . $new_title; if (strtolower($new_title) == strtolower($source_folder->folder_name) && $source_folder->folder_name != $new_title) { $temp_folder = $new_title . uniqid('assets'); while ($this->_source_folder_exists($base . $temp_folder)) { $temp_folder = $new_title . uniqid('assets'); } $this->_rename_source_folder($source_path, $base . $temp_folder); $this->_rename_source_folder($base . $temp_folder, $target); $source_folder->folder_name = $new_title; $this->_update_folder_info($source_folder, $parent_row); return array('success' => TRUE, 'new_name' => $new_title); } if ($this->_source_folder_exists($target)) { throw new Exception(lang('invalid_folder_path')); } if (!$this->_rename_source_folder($source_path, $target)) { throw new Exception(lang('invalid_folder_path')); } $this->EE->assets_lib->call_extension('assets_rename_folder', array($source_folder, $new_title)); $source_folder->folder_name = $new_title; $this->_update_folder_info($source_folder, $parent_row); return array('success' => TRUE, 'new_name' => $new_title); }
/** * Create EE thumbnails. * * @param $image_path * @param $upload_folder_id * @return mixed */ public static function create_ee_thumbnails($image_path, $upload_folder_id) { if (!class_exists('Assets_ee_source')) { require_once PATH_THIRD . 'assets/sources/ee/source.ee.php'; } $preferences = self::_get_EE()->filemanager->fetch_upload_dir_prefs($upload_folder_id); $preferences['file_name'] = pathinfo($image_path, PATHINFO_BASENAME); $preferences['server_path'] = Assets_ee_source::resolve_server_path(Assets_helper::normalize_path($preferences['server_path'])); // Trick Filemanager into creating the thumbnail where WE need it $preferences['server_path'] .= str_replace($preferences['server_path'], '', str_replace(pathinfo($image_path, PATHINFO_BASENAME), '', $image_path)); // On Windows machines CI's Image_lib gets all sorts of confused, so have to make sure our paths use the DIRECTORY_SEPARATOR separator if (DIRECTORY_SEPARATOR === "\\") { $preferences['server_path'] = str_replace('/', '\\', $preferences['server_path']); $image_path = str_replace('/', '\\', $image_path); } return self::_get_EE()->filemanager->create_thumb($image_path, $preferences); }
/** * Load the folder structure for data migration * * @param $path * @param $folder_structure */ private function _load_folder_structure($path, &$folder_structure) { // starting with underscore or dot gets ignored $list = glob($path . '[!_.]*', GLOB_MARK); if (is_array($list) && count($list) > 0) { foreach ($list as $item) { // parse folders and add files $item = Assets_helper::normalize_path($item); if (substr($item, -1) == '/') { // add with dropped slash and parse $folder_structure[] = substr($item, 0, -1); $this->_load_folder_structure($item, $folder_structure); } } } }
/** * Applies filedir overrides from config.php file. * @param $filedir * @return mixed */ public static function apply_filedir_overrides($filedir) { static $overrides = null; if (is_null($overrides)) { $overrides = get_instance()->config->item('upload_preferences'); } if (isset($overrides[$filedir->id])) { foreach ($overrides[$filedir->id] as $property => $value) { $filedir->{$property} = $value; } } $filedir->server_path = rtrim(Assets_helper::normalize_path($filedir->server_path), '/') . '/'; return $filedir; }