/** * Makes DB backup * db_filename - string name of result pack. Will be stored in Registry::get('config.dir.database') . $db_filename; * db_tables - array List of tables to be backuped * db_schema - bool Backup tables schema * db_data - bool Backup data from tables * @param array $params * * @return string Path to backuped DB sql/tgz file */ public static function backupDatabase($params = array()) { $default_params = array('db_tables' => array(), 'db_schema' => false, 'db_data' => false, 'db_compress' => false, 'move_progress' => true); $params = array_merge($default_params, $params); $db_filename = empty($params['db_filename']) ? 'dump_' . date('mdY') . '.sql' : fn_basename($params['db_filename']); if (!fn_mkdir(Registry::get('config.dir.backups'))) { fn_set_notification('E', __('error'), __('text_cannot_create_directory', array('[directory]' => fn_get_rel_dir(Registry::get('config.dir.backups'))))); return false; } $dump_file = Registry::get('config.dir.backups') . $db_filename; if (is_file($dump_file)) { if (!is_writable($dump_file)) { fn_set_notification('E', __('error'), __('dump_file_not_writable')); return false; } } $result = db_export_to_file($dump_file, $params['db_tables'], $params['db_schema'], $params['db_data'], true, true, $params['move_progress']); if (!empty($params['db_compress'])) { fn_set_progress('echo', __('compress_dump'), false); $ext = $params['db_compress'] == 'tgz' ? '.tgz' : '.zip'; $result = fn_compress_files($db_filename . $ext, $db_filename, dirname($dump_file)); unlink($dump_file); $dump_file .= $ext; } if ($result) { return $dump_file; } return false; }
/** * Creates PO file for specified Language * * @param string $lang_code 2-letters language code (Example: "en", "ru") * @param string $output Output destination * screen - Output countent direct to browser page * download - Force file downloading * server - upload file to the config.dir.lang_packs directory */ public static function export($lang_code, $output = 'download') { $mve_lang_variables = array(); // Translation packs should not include "Not translated" language data $allow_overlap = $lang_code == 'en' ? true : false; $default_lang = Registry::get('settings.Appearance.backend_default_language'); $langs = self::get(array('lang_code' => $lang_code)); $lang = $langs[$lang_code]; $pack_path = fn_get_cache_path(false) . 'lang_pack/'; $core_pack_path = $pack_path . 'core.po'; $mve_pack_path = $pack_path . 'editions/mve.po'; fn_rm($pack_path); fn_mkdir($pack_path); if (fn_allowed_for('MULTIVENDOR') && is_file(Registry::get('config.dir.lang_packs') . $default_lang . '/editions/mve.po')) { $mve_lang_variables = Po::getValues(Registry::get('config.dir.lang_packs') . $default_lang . '/editions/mve.po'); Po::createHeader($mve_pack_path, $lang); } Po::createHeader($core_pack_path, $lang); // Export Language values list($values) = LanguageValues::getVariables(array(), 0, $lang_code); foreach ($values as $_id => $value) { $values[$_id]['msgctxt'] = 'Languages' . \I18n_Pofile::DELIMITER . $value['name']; } $values = fn_array_value_to_key($values, 'msgctxt'); $addons_lang_vars = array(); list($addons) = fn_get_addons(array('type' => 'installed'), 0, $lang_code); foreach ($addons as $addon_id => $addon) { $addons_lang_vars = array_merge($addons_lang_vars, self::exportAddonsPo($addon_id, $pack_path . 'addons/' . $addon_id . '.po', $lang_code, $values)); } $original_values = self::getOriginalValues('Languages'); $values = array_diff_key($values, $addons_lang_vars); foreach ($values as $_id => $value) { $values[$_id]['original_value'] = isset($original_values['Languages::' . $value['name']]) ? $original_values['Languages::' . $value['name']]['msgid'] : ''; } $values = Po::convert($values, array(), $allow_overlap); list($values, $excluded) = self::excludeEditionVariables('Languages', $values, $mve_lang_variables); Po::putValues('Languages', $values, $core_pack_path); if (!empty($excluded)) { Po::putValues('Languages', $excluded, $mve_pack_path); } // Export Settings Sections $sections = Settings::instance()->getCoreSections($lang_code); $original_values = self::getOriginalValues('SettingsSections'); foreach ($sections as $_id => $value) { $sections[$_id]['original_value'] = isset($original_values['SettingsSections::' . $value['section_id']]) ? $original_values['SettingsSections::' . $value['section_id']]['msgid'] : ''; } $_sections = Po::convert($sections, array('id' => 'section_id', 'value' => 'description'), $allow_overlap); list($_sections, $excluded) = self::excludeEditionVariables('SettingsSections', $_sections, $mve_lang_variables); Po::putValues('SettingsSections', $_sections, $core_pack_path); if (!empty($excluded)) { Po::putValues('SettingsSections', $excluded, $mve_pack_path); } unset($_sections); $original_options = self::getOriginalValues('SettingsOptions'); $original_variants = self::getOriginalValues('SettingsVariants'); $original_tooltips = self::getOriginalValues('SettingsTooltips'); foreach ($sections as $section) { $options = Settings::instance()->getList($section['object_id'], 0, false, null, $lang_code); $_options = array(); $_tooltips = array(); foreach ($options['main'] as $option) { $_options[] = array('name' => $option['name'], 'value' => $option['description'], 'original_value' => isset($original_options['SettingsOptions' . \I18n_Pofile::DELIMITER . $option['name']]) ? $original_options['SettingsOptions' . \I18n_Pofile::DELIMITER . $option['name']]['msgid'] : ''); if (!empty($option['variants'])) { $_variants = array(); foreach ($option['variants'] as $variant_id => $variant) { $_variants[] = array('name' => $variant_id, 'value' => $variant, 'original_value' => isset($original_variants['SettingsVariants' . \I18n_Pofile::DELIMITER . $option['name'] . \I18n_Pofile::DELIMITER . $variant_id]) ? $original_variants['SettingsVariants' . \I18n_Pofile::DELIMITER . $option['name'] . \I18n_Pofile::DELIMITER . $variant_id]['msgid'] : ''); } $_variants = Po::convert($_variants, array(), $allow_overlap); list($_variants, $excluded) = self::excludeEditionVariables('SettingsVariants', $_variants, $mve_lang_variables); Po::putValues('SettingsVariants' . \I18n_Pofile::DELIMITER . $option['name'], $_variants, $core_pack_path); if (!empty($excluded)) { Po::putValues('SettingsVariants', $excluded, $mve_pack_path); } unset($_variants); } if (!empty($option['tooltip'])) { $_tooltips[] = array('name' => $option['name'], 'value' => $option['tooltip'], 'original_value' => isset($original_tooltips['SettingsTooltips' . \I18n_Pofile::DELIMITER . $option['name']]) ? $original_tooltips['SettingsTooltips' . \I18n_Pofile::DELIMITER . $option['name']]['msgid'] : ''); } } $_options = Po::convert($_options, array(), $allow_overlap); list($_options, $excluded) = self::excludeEditionVariables('SettingsOptions', $_options, $mve_lang_variables); Po::putValues('SettingsOptions', $_options, $core_pack_path); if (!empty($excluded)) { Po::putValues('SettingsOptions', $excluded, $mve_pack_path); } $_tooltips = Po::convert($_tooltips, array(), $allow_overlap); list($_tooltips, $excluded) = self::excludeEditionVariables('SettingsTooltips', $_tooltips, $mve_lang_variables); Po::putValues('SettingsTooltips', $_tooltips, $core_pack_path); if (!empty($excluded)) { Po::putValues('SettingsTooltips', $excluded, $mve_pack_path); } } // Export Profile fields $profile_fields = fn_get_profile_fields('ALL', array(), $lang_code); $original_values = self::getOriginalValues('ProfileFields'); $values = array(); foreach ($profile_fields as $zone => $fields) { foreach ($fields as $field_id => $field) { $values[] = array('name' => $field['field_name'], 'value' => $field['description'], 'original_value' => isset($original_values['ProfileFields::' . $field['field_name']]) ? $original_values['ProfileFields::' . $field['field_name']]['msgid'] : ''); } } $values = Po::convert($values, array(), $allow_overlap); list($values, $excluded) = self::excludeEditionVariables('ProfileFields', $values, $mve_lang_variables); Po::putValues('ProfileFields', $values, $core_pack_path); if (!empty($excluded)) { Po::putValues('ProfileFields', $excluded, $mve_pack_path); } fn_compress_files($lang_code . '.zip', './', $pack_path); $filename = $pack_path . $lang_code . '.zip'; switch ($output) { case 'server': fn_copy($filename, Registry::get('config.dir.lang_packs') . $lang_code . '.zip'); break; case 'download': fn_get_file($filename, $lang_code . '.zip'); break; } return true; }
} for ($i = 0; $i < $total_rows; $i = $i + $it) { $table_data = db_get_array("SELECT * FROM {$table} LIMIT {$i}, {$it}"); foreach ($table_data as $_tdata) { $_tdata = fn_add_slashes($_tdata, true); fwrite($fd, "INSERT INTO {$table} (`" . implode('`, `', array_keys($_tdata)) . "`) VALUES ('" . implode('\', \'', array_values($_tdata)) . "');\n"); } fn_echo(' .'); } } } fclose($fd); @chmod(DIR_DATABASE . 'backup/' . $dbdump_filename, DEFAULT_FILE_PERMISSIONS); if ($_REQUEST['dbdump_compress'] == 'Y') { fn_echo('<br />' . fn_get_lang_var('compressing_backup') . '...'); fn_compress_files($dbdump_filename . '.tgz', $dbdump_filename, dirname($dump_file)); unlink($dump_file); } fn_stop_scroller(); } // Restore if ($mode == 'restore') { if (!empty($_REQUEST['backup_files'])) { // Log database restore fn_log_event('database', 'restore'); fn_start_scroller(); foreach ($_REQUEST['backup_files'] as $file) { fn_echo('<br />' . fn_get_lang_var('restoring_from') . ': <b>' . $file . '</b><hr width="100%" />'); if (strpos($file, '.tgz') !== false) { fn_decompress_files($file, DIR_DATABASE . '/backup'); $file = substr($file, 0, strpos($file, '.tgz'));
public function backupYml() { if (file_exists($this->filepath)) { $path = fn_get_files_dir_path() . 'yml/'; $archive_path = $path . 'archives/'; fn_mkdir($archive_path); $archive_name = 'ym_' . date('dmY_His', TIME) . '.tgz'; fn_compress_files($archive_name, $this->filename . '.yml', $path); fn_rename($path . $archive_name, $archive_path . $archive_name); $archives_list = fn_get_dir_contents($archive_path, false, true); if (!empty($archives_list) && count($archives_list) > self::ARCHIVES_LIMIT) { rsort($archives_list); list(, $old_archives) = array_chunk($archives_list, self::ARCHIVES_LIMIT); foreach ($old_archives as $filename) { fn_rm($archive_path . $filename); } } } }
} return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path'] . '/' . $_REQUEST['file']); } elseif ($mode == 'decompress') { $pname = fn_te_normalize_path($_REQUEST, $section_root_dir); if (fn_te_check_path($pname, $_SESSION['active_section'])) { fn_decompress_files($pname, dirname($pname)); } return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']); } elseif ($mode == 'compress') { $pname = fn_te_normalize_path($_REQUEST, $section_root_dir); if (fn_te_check_path($pname, $_SESSION['active_section']) && file_exists($pname)) { $archive_file = $pname . '.zip'; if (file_exists($archive_file)) { fn_rm($archive_file); } fn_compress_files(fn_basename($archive_file), array(fn_basename($pname)), dirname($pname)); } return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']); } /** * Gets file/directory permissions in human-readable notation * @param string $path path to file/directory * @return string readable permissions */ function fn_te_get_permissions($path) { if (defined('IS_WINDOWS')) { return ''; } $mode = fileperms($path); $owner = array();