'; $new_config_file = $dir.'/config/database.inc.php'; if (!($fp = @fopen($new_config_file, 'w')) or !@fwrite($fp, $file_content) or !@fclose($fp)) { array_push($page['errors'], l10n('Unable to write new local directory.')); return; } @chmod($new_config_file, 0755); } // config_local.inc.php $file = PHPWG_ROOT_PATH.'include/config_local.inc.php'; if (is_readable($file)) { copy($file, $dir.'/config/config.inc.php'); @chmod($file, 0755); } // languages $language_dir = opendir(PHPWG_ROOT_PATH.'language'); while ($file = readdir($language_dir)) { $path = PHPWG_ROOT_PATH.'language/'.$file; if (!is_link($path) and is_dir($path) and is_readable($path.'/local.lang.php')) { $content = file_get_contents($path.'/local.lang.php'); $langdef = explode('.',$file); if (count($langdef)>1) { $content = utf8_encode($content); } $filename = $dir.'/language/'.$langdef[0].'.lang.php'; $fp = @fopen($filename, 'w'); @fwrite($fp, $content); @fclose($fp); @chmod($filename, 0755); } } closedir($language_dir); // template-common/local-layout.css $file = PHPWG_ROOT_PATH.'template-common/local-layout.css'; if (is_readable($file)) { copy($file, $dir.'/css/rules.css'); @chmod($file, 0755); } // template/xxx/local-layout.css $known_templates = array( 'yoga' => 'default', 'floPure' => 'Pure_default', 'floOs' => 'OS_default', 'gally' => 'gally-default', 'simple' => 'simple', ); foreach ($known_templates as $old_tpl => $new_tpl) { $file = PHPWG_ROOT_PATH.'template/'.$old_tpl.'/local-layout.css'; if (is_readable($file)) { copy($file, $dir.'/css/'.$new_tpl.'-rules.css'); @chmod($file, 0755); } } } function autoupdate_save_template_dir() { global $page, $conf; $path = $conf['local_data_dir'].'/autoupdate'; if (@mkgetdir($path) and ($zip = tempnam($path, 'zip')) and ($archive = new pclZip($zip)) and ($v_list = $archive->add(PHPWG_ROOT_PATH.'template', PCLZIP_OPT_REMOVE_PATH, PHPWG_ROOT_PATH)) and is_array($v_list) and !empty($v_list)) { $http_headers = array( 'Content-Length: '.@filesize($zip), 'Content-Type: application/zip', 'Content-Disposition: attachment; filename="template.zip";', 'Content-Transfer-Encoding: binary', ); foreach ($http_headers as $header) { header($header); } @readfile($zip); autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); exit(); } else { array_push($page['errors'], l10n('Unable to send template directory.')); } } function autoupdate_dump_database() { global $page, $conf, $cfgBase; if (version_compare(PHPWG_VERSION, '2.1', '<')) { $conf['db_base'] = $cfgBase; } include(AUTOUPDATE_PATH.'include/mysqldump.php'); $path = $conf['local_data_dir'].'/autoupdate'; if (@mkgetdir($path) and ($backupFile = tempnam($path, 'sql')) and ($dumper = new MySQLDump($conf['db_base'],$backupFile,false,false))) { foreach (get_defined_constants() as $constant => $value) { if (preg_match('/_TABLE$/', $constant)) { $dumper->getTableStructure($value); if ($constant == 'HISTORY_TABLE' and !isset($_POST['includeHistory'])) { continue; } $dumper->getTableData($value); } } } if (@filesize($backupFile)) { $http_headers = array( 'Content-Length: '.@filesize($backupFile), 'Content-Type: text/x-sql', 'Content-Disposition: attachment; filename="database.sql";', 'Content-Transfer-Encoding: binary', ); foreach ($http_headers as $header) { header($header); } @readfile($backupFile); autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); exit(); } else { array_push($page['errors'], l10n('Unable to dump database.')); } } function autoupdate_upgrade_to($upgrade_to, &$step) { global $page, $conf, $template; if (!version_compare($_POST['upgrade_to'], PHPWG_VERSION, '>')) { redirect(get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php')); } if ($step == 2) { preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches); $code = $matches[1].'.x_to_'.$_POST['upgrade_to']; $dl_code = str_replace(array('.', '_'), '', $code); $remove_path = $code; $obsolete_list = 'obsolete.list'; } else { $code = $_POST['upgrade_to']; $dl_code = $code; $remove_path = version_compare($code, '2.0.8', '>=') ? 'piwigo' : 'piwigo-'.$code; $obsolete_list = PHPWG_ROOT_PATH.'install/obsolete.list'; if (version_compare(PHPWG_VERSION, '2.1', '<')) { move_local_files(PHPWG_ROOT_PATH.'local'); } } if (empty($page['errors'])) { $path = $conf['local_data_dir'].'/autoupdate'; $filename = $path.'/'.$code.'.zip'; @mkgetdir($path); $chunk_num = 0; $end = false; $zip = @fopen($filename, 'w'); while (!$end) { $chunk_num++; if (@fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.$dl_code.'&chunk_num='.$chunk_num, $result) and $input = @unserialize($result)) { if (0 == $input['remaining']) { $end = true; } @fwrite($zip, base64_decode($input['data'])); } else { $end = true; } } @fclose($zip); if (@filesize($filename)) { $zip = new PclZip($filename); if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, PCLZIP_OPT_REMOVE_PATH, $remove_path, PCLZIP_OPT_SET_CHMOD, 0755, PCLZIP_OPT_REPLACE_NEWER)) { //Check if all files were extracted $error = ''; foreach($result as $extract) { if (!in_array($extract['status'], array('ok', 'filtered', 'already_a_directory'))) { // Try to change chmod and extract if (@chmod(PHPWG_ROOT_PATH.$extract['filename'], 0777) and ($res = $zip->extract(PCLZIP_OPT_BY_NAME, $remove_path.'/'.$extract['filename'], PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, PCLZIP_OPT_REMOVE_PATH, $remove_path, PCLZIP_OPT_SET_CHMOD, 0755, PCLZIP_OPT_REPLACE_NEWER)) and isset($res[0]['status']) and $res[0]['status'] == 'ok') { continue; } else { $error .= $extract['filename'].': '.$extract['status']."\n"; } } } if (empty($error)) { process_obsolete_list($obsolete_list); autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); invalidate_user_cache(true); $template->delete_compiled_templates(); if ($step == 2) { array_push($page['infos'], sprintf(l10n('autoupdate_success'), $upgrade_to)); $step = -1; } else { redirect(PHPWG_ROOT_PATH.'upgrade.php?now='); } } else { file_put_contents($conf['local_data_dir'].'/autoupdate/log_error.txt', $error); $relative_path = trim(str_replace(dirname(dirname(dirname(dirname(__FILE__)))), '', $conf['local_data_dir']), '/\\'); array_push($page['errors'], sprintf(l10n('autoupdate_extract_fail'), PHPWG_ROOT_PATH.$relative_path.'/autoupdate/log_error.txt')); } } else { autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); array_push($page['errors'], l10n('autoupdate_fail')); } } else { array_push($page['errors'], l10n('Piwigo cannot retrieve upgrade file from server')); } } } if (!function_exists('is_webmaster')) { function is_webmaster($user_status = '') { return is_autorize_status(ACCESS_WEBMASTER, $user_status); } } define('AU_DEFAULT_INDEX', file_get_contents(AUTOUPDATE_PATH.'index.php')); ?>