if (!@chmod($_POST['current_directory'] . $_POST['item_name'], octdec($_POST['item_new_permissions']))) { $error_code = '3'; } } break; case 3: # Paste if (isset($_POST['directory_where_the_files_are_received']) && isset($_POST['item_names']) && isset($_POST['move_or_copy'])) { $_POST['current_directory'] = mb_convert_encoding($_POST['current_directory'], $settings['filesystem_encoding'], 'UTF-8'); $item_names = explode('|', $_POST['item_names']); if ($_POST['move_or_copy'] == 'm') { foreach ($item_names as $item_name) { $item_name = mb_convert_encoding($item_name, $settings['filesystem_encoding'], 'UTF-8'); $item = mb_convert_encoding($_POST['directory_where_the_files_are_received'], $settings['filesystem_encoding'], 'UTF-8') . $item_name; if (@filetype($item) == 'dir') { if (!move_directory($item, $_POST['current_directory'])) { $error_code = '3'; } } else { if (!@rename($item, $_POST['current_directory'] . $item_name)) { $error_code = '4'; } } } } else { foreach ($item_names as $item_name) { $item_name = mb_convert_encoding($item_name, $settings['filesystem_encoding'], 'UTF-8'); $item = mb_convert_encoding($_POST['directory_where_the_files_are_received'], $settings['filesystem_encoding'], 'UTF-8') . $item_name; if (@filetype($item) == 'dir') { if (!copy_directory($item, $_POST['current_directory'])) { $error_code = '5';
function download_template_repo(&$output, $template, $childpath = false) { # Creating the zip directory for the download $zip_file = tempnam('/tmp', 'REPODL'); $zip_resource = fopen($zip_file, "w"); # Logging $output[] = ' - Starting download of template repo "' . $template . '"<br />'; # Loading the master branch from github $repo_url = 'https://github.com/nuQuery-Templates/' . $template . '/archive/master.zip'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $repo_url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_FILE, $zip_resource); $success = curl_exec($ch); curl_close($ch); # Error downloading if (!$success) { $output[] = ' - Error downloading repo : ' . curl_error($ch) . '<br />'; return false; } else { # Logging $output[] = ' - Download complete, unzipping.<br />'; # Extracting the zip $zip = new ZipArchive(); $save_path = __DIR__ . '/_installed/'; mkdir($save_path); if ($zip->open($zip_file) != "true") { $output[] = ' - Unable to open the Zip File'; return false; } $zip->extractTo($save_path); $zip->close(); # Removing zip unlink($zip_file); # Moving directories into root if ($childpath !== false) { move_directory($save_path . $template . '-master/', $childpath . '/'); remove_directory($save_path . $template . '-master'); } else { rename($save_path . $template . '-master', __DIR__ . '/' . $template); } # Removing install directory remove_directory($save_path); # Logging $output[] = ' - Install of template "' . $template . '" complete.<br />'; } # Success return true; }