/** * Scan * * Extract an module with all his dependency * * @access public * @author blair Jersyer * @copyright 2015 * @param string $module_namespace * @since 3.0.1 * @return void */ static function extract($module_namespace) { $module = self::get($module_namespace); if ($module) { get_instance()->load->library('zip'); get_instance()->load->helper('security'); $module_temp_folder_name = do_hash($module_namespace); $module_installed_dir = MODULESPATH . $module_namespace . '/'; // creating temp folder $temp_folder = APPPATH . 'temp' . '/' . $module_temp_folder_name; if (!is_dir($temp_folder)) { mkdir($temp_folder); } // check manifest if (is_file($manifest = $module_installed_dir . 'manifest.json')) { $manifest_content = file_get_contents($manifest); $manifest_array = json_decode($manifest_content); //var_dump( $manifest_content ); // manifest is valid if (is_array($manifest_array)) { //var_dump( $manifest_array ); // moving manifest file to temp folder foreach (array('models', 'libraries', 'language', 'config') as $reserved_folder) { foreach ($manifest_array as $file) { //var_dump( $path_id_separator = APPPATH . $reserved_folder ); if (strstr($file, $path_id_separator = APPPATH . $reserved_folder)) { // we found a a file $path_splited = explode($path_id_separator, $file); //var_dump( $path_splited ); SimpleFileManager::file_copy(APPPATH . $reserved_folder . $path_splited[1], $temp_folder . '/' . $reserved_folder . $path_splited[1]); } } } } $assets_path = PUBLICPATH . 'modules' . '/' . $module_namespace; // Copy Assets to if (is_dir($assets_path)) { // create assets folder if (!is_dir($temp_folder . '/' . 'assets')) { mkdir($temp_folder . '/' . 'assets'); } SimpleFileManager::copy($assets_path, $temp_folder . '/' . 'assets'); } } // move module file to temp folder SimpleFileManager::copy($module_installed_dir, $temp_folder); $FCPATH = str_replace('/', '\\', FCPATH); // read temp folder and download it get_instance()->zip->read_dir($FCPATH . 'application\\temp\\' . $module_temp_folder_name . '\\', FALSE, $FCPATH . 'application\\temp\\' . $module_temp_folder_name . '\\'); // delete temp folder SimpleFileManager::drop($temp_folder); get_instance()->zip->download($module_namespace); } }
function install($stage, $zipball = null) { $tendoo_zip = APPPATH . 'temp/tendoo-cms.zip'; if ($stage === 1 && $zipball != null) { // for downloading $tendoo_cms_zip = $this->curl->security(false)->get('https://codeload.github.com/Blair2004/tendoo-cms/legacy.zip/' . $zipball); if (!empty($tendoo_cms_zip)) { file_put_contents($tendoo_zip, $tendoo_cms_zip); return array('code' => 'archive-downloaded'); } return array('code' => 'error-occured'); } elseif ($stage === 2) { // for uncompressing if (is_file($tendoo_zip)) { // if zip exists $zip = new ZipArchive(); $tendoo = $zip->open($tendoo_zip); if ($tendoo) { if (is_dir(APPPATH . 'temp/core')) { SimpleFileManager::drop(APPPATH . 'temp/core'); // if any update failed, we drop temp/core before } mkdir(APPPATH . 'temp/core'); $zip->extractTo(APPPATH . 'temp/core'); $zip->close(); unlink($tendoo_zip); // removing zip file } return array('code' => 'archive-uncompressed'); } } elseif ($stage === 3) { // updating itself if (is_dir(APPPATH . 'temp/core')) { // looping internal dir $dir = opendir(APPPATH . 'temp/core'); while (false !== ($file = readdir($dir))) { if (!in_array($file, array('.', '..'))) { // skiping up directory SimpleFileManager::extractor(APPPATH . 'temp/core/' . $file, FCPATH); break; // first folder is tendoo main folder (we think, since branch name can change) } } SimpleFileManager::drop(APPPATH . 'temp/core'); // dropping core update folder return array('code' => 'update-done'); } } return array('code' => 'error-occured'); }