本文整理汇总了PHP中fw_fix_path函数的典型用法代码示例。如果您正苦于以下问题:PHP fw_fix_path函数的具体用法?PHP fw_fix_path怎么用?PHP fw_fix_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fw_fix_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: download
/**
* {@inheritdoc}
* @param $args
* * destination_dir - Path to dir where the downloaded files must be placed
* * source - Path to dir or zip file
*/
public function download(array $args, array $state = array())
{
// Note: destination_dir is already validated
if (empty($args['source'])) {
return new WP_Error('no_source', __('Source not specified', 'fw'));
} elseif (!($args['source'] = fw_fix_path(realpath($args['source'])))) {
return new WP_Error('invalid_source', __('Invalid source', 'fw'));
} elseif (!($is_dir = is_dir($args['source'])) || !($is_zip = substr($args['source'], -4, 4) !== '.zip')) {
return new WP_Error('invalid_source_type', __('Invalid source type', 'fw'));
}
if ($is_dir) {
return fw_ext_backups_copy_dir_recursive($args['source'], $args['destination_dir']);
} elseif ($is_zip) {
if (!class_exists('ZipArchive')) {
return new WP_Error('zip_ext_missing', __('Zip extension missing', 'fw'));
}
$zip = new ZipArchive();
if (true === $zip->open($args['source'])) {
return new WP_Error('zip_open_fail', sprintf(__('Cannot open zip: %s', 'fw'), $args['source']));
}
$zip->extractTo($args['destination_dir']);
$zip->close();
unset($zip);
return true;
} else {
return new WP_Error('unhandled_type', __('Unhandled type', 'fw'));
}
}
开发者ID:azharijelek,项目名称:Unyson-Backups-Extension,代码行数:34,代码来源:class-fw-ext-backups-task-type-download-local.php
示例2: execute
/**
* {@inheritdoc}
* @param array $args
* * zip - file path
* * dir - where the zip file will be extract
*/
public function execute(array $args, array $state = array())
{
if (!isset($args['zip'])) {
return new WP_Error('no_zip', __('Zip file not specified', 'fw'));
} else {
$args['zip'] = fw_fix_path($args['zip']);
}
if (!isset($args['dir'])) {
return new WP_Error('no_dir', __('Destination dir not specified', 'fw'));
} else {
$args['dir'] = fw_fix_path($args['dir']);
}
if (empty($state)) {
if (!fw_ext_backups_is_dir_empty($args['dir'])) {
return new WP_Error('destination_not_empty', __('Destination dir is not empty', 'fw'));
}
$state = array('entry' => '', 'extracted_files' => 0);
}
wp_cache_flush();
FW_Cache::clear();
if (is_wp_error($extract_result = fw_ext_backups_unzip_partial($args['zip'], $args['dir'], $state['entry']))) {
return $extract_result;
} else {
if ($extract_result['finished']) {
return true;
} else {
$state['entry'] = $extract_result['last_entry'];
$state['extracted_files'] += $extract_result['extracted_files'];
return $state;
}
}
}
开发者ID:ThemeFuse,项目名称:Unyson-Backups-Extension,代码行数:38,代码来源:class-fw-ext-backups-task-type-unzip.php
示例3: get_demos
/**
* @return FW_Ext_Backups_Demo[]
*/
private function get_demos()
{
if (is_null(self::$demos)) {
$demos = array();
foreach (apply_filters('fw_ext_backups_demo_dirs', array(fw_fix_path(get_template_directory()) . '/demo-content' => get_template_directory_uri() . '/demo-content')) as $dir_path => $dir_uri) {
if (!is_dir($dir_path) || !($dirs = glob($dir_path . '/*', GLOB_ONLYDIR))) {
continue;
}
foreach (array_map('fw_fix_path', $dirs) as $demo_dir) {
$demo_dir_name = basename($demo_dir);
if (!file_exists($demo_dir . '/manifest.php')) {
continue;
}
$manifest = fw_get_variables_from_file($demo_dir . '/manifest.php', array('manifest' => array()), array('uri' => $dir_uri . '/' . $demo_dir_name));
$manifest = array_merge(array('title' => fw_id_to_title($demo_dir_name), 'screenshot' => fw_get_framework_directory_uri('/static/img/no-image.png'), 'preview_link' => '', 'extra' => array()), $manifest['manifest']);
$demo = new FW_Ext_Backups_Demo('local-' . md5($demo_dir), 'local', array('source' => $demo_dir));
$demo->set_title($manifest['title']);
$demo->set_screenshot($manifest['screenshot']);
$demo->set_preview_link($manifest['preview_link']);
$demo->set_extra($manifest['extra']);
$demos[$demo->get_id()] = $demo;
unset($demo);
}
}
self::$demos = array_merge(apply_filters('fw:ext:backups-demo:demos', array()), $demos);
}
return self::$demos;
}
开发者ID:ThemeFuse,项目名称:Unyson-Backups-Extension,代码行数:31,代码来源:class-fw-extension-backups-demo.php
示例4: fw_ext_backups_copy_dir_recursive
/**
* @param string $source_dir
* @param string $destination_dir
* @return bool|WP_Error
*/
function fw_ext_backups_copy_dir_recursive($source_dir, $destination_dir)
{
$source_dir = fw_fix_path($source_dir);
$destination_dir = fw_fix_path($destination_dir);
$dir_chmod = 0755;
if (!file_exists($destination_dir)) {
if (!mkdir($destination_dir, $dir_chmod)) {
return new WP_Error('mkdir_fail', sprintf(__('Failed to create dir: %s'), $destination_dir));
}
}
try {
foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_dir), RecursiveIteratorIterator::SELF_FIRST) as $item) {
if (in_array(basename($iterator->getSubPathName()), array('.', '..'), true)) {
continue;
// We can't use RecursiveDirectoryIterator::SKIP_DOTS, it was added in php 5.3
}
$destination_path = $destination_dir . '/' . $iterator->getSubPathName();
if ($item->isDir()) {
if (!mkdir($destination_path, $dir_chmod)) {
return new WP_Error('mk_sub_dir_fail', sprintf(__('Failed to create dir: %s'), $destination_path));
}
} else {
if (!copy($item->getPathname(), $destination_path)) {
return new WP_Error('copy_fail', sprintf(__('Failed to copy: %s'), $destination_path));
}
}
}
} catch (UnexpectedValueException $e) {
return new WP_Error('dir_copy_fail', (string) $e->getMessage());
}
return true;
}
开发者ID:azharijelek,项目名称:Unyson-Backups-Extension,代码行数:37,代码来源:helpers.php
示例5: execute
/**
* {@inheritdoc}
* @param array $args
* * uploads_dir - path to exported uploads dir (not the actual WP uploads dir! that remains untouched)
*/
public function execute(array $args, array $state = array())
{
$backups = fw_ext('backups');
if (empty($args['uploads_dir'])) {
return new WP_Error('no_uploads_dir', __('Uploads dir not specified', 'fw'));
} else {
$args['uploads_dir'] = fw_fix_path($args['uploads_dir']);
if (!file_exists($args['uploads_dir'])) {
/**
* The uploads directory was not exported, nothing to do.
*/
return true;
}
}
if (empty($state)) {
$state = array('attachment_id' => 0);
}
/**
* @var WPDB $wpdb
*/
global $wpdb;
$sql = implode(array("SELECT * FROM {$wpdb->posts}", "WHERE post_type = 'attachment' AND post_mime_type LIKE %s AND ID > %d", "ORDER BY ID", "LIMIT 7"), " \n");
$wp_uploads_dir = wp_upload_dir();
$wp_uploads_dir_length = mb_strlen($wp_uploads_dir['basedir']);
$started_time = time();
$timeout = $backups->get_timeout() - 7;
while (time() - $started_time < $timeout) {
$attachments = $wpdb->get_results($wpdb->prepare($sql, $wpdb->esc_like('image/') . '%', $state['attachment_id']), ARRAY_A);
if (empty($attachments)) {
return true;
}
foreach ($attachments as $attachment) {
if (($meta = wp_get_attachment_metadata($attachment['ID'])) && isset($meta['sizes']) && is_array($meta['sizes'])) {
$attachment_path = get_attached_file($attachment['ID']);
$filename_length = mb_strlen(basename($attachment_path));
foreach ($meta['sizes'] as $size => $sizeinfo) {
// replace wp_uploads_dir path
$file_path = $args['uploads_dir'] . mb_substr($attachment_path, $wp_uploads_dir_length);
// replace file name with resize name
$file_path = mb_substr($file_path, 0, -$filename_length) . $sizeinfo['file'];
if (file_exists($file_path)) {
@unlink($file_path);
}
}
}
if (is_array($backup_sizes = get_post_meta($attachment['ID'], '_wp_attachment_backup_sizes', true))) {
foreach ($backup_sizes as $size) {
$del_file = path_join(dirname($meta['file']), $size['file']);
@unlink(path_join($args['uploads_dir'], $del_file));
}
}
}
$state['attachment_id'] = $attachment['ID'];
}
return $state;
}
开发者ID:azharijelek,项目名称:Unyson-Backups-Extension,代码行数:61,代码来源:class-fw-ext-backups-task-type-image-sizes-remove.php
示例6: execute
/**
* {@inheritdoc}
* @param array $args
* * source_dir - everything from this directory will be added in zip
* * destination_dir - where the zip file will be created
*
* Warning!
* Zip can't be executed in steps, it will execute way too long,
* because it is impossible to update a zip file, every time you add a file to zip,
* a new temp copy of original zip is created with new modifications, it is compressed,
* and the original zip is replaced. So when the zip will grow in size,
* just adding a single file, will take a very long time.
*/
public function execute(array $args, array $state = array())
{
if (!isset($args['source_dir'])) {
return new WP_Error('no_source_dir', __('Source dir not specified', 'fw'));
} else {
$args['source_dir'] = fw_fix_path($args['source_dir']);
}
if (!isset($args['destination_dir'])) {
return new WP_Error('no_destination_dir', __('Destination dir not specified', 'fw'));
} else {
$args['destination_dir'] = fw_fix_path($args['destination_dir']);
}
if (!class_exists('ZipArchive')) {
return new WP_Error('zip_ext_missing', __('Zip extension missing', 'fw'));
}
$zip_path = $args['source_dir'] . '/' . implode('-', array('fw-backup', date('Y_m_d-H_i_s'), fw_ext('backups')->manifest->get_version())) . '.zip';
$zip = new ZipArchive();
if (false === ($zip_error_code = $zip->open($zip_path, ZipArchive::CREATE))) {
return new WP_Error('cannot_open_zip', sprintf(__('Cannot open zip (Error code: %s)', 'fw'), $zip_error_code));
}
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($args['source_dir']), RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($files as $name => $file) {
if (!$file->isDir()) {
// Skip directories (they would be added automatically)
if (($file_path = $file->getRealPath()) !== $zip_path) {
$zip->addFile($file_path, substr(fw_fix_path($file_path), strlen($args['source_dir']) + 1));
}
}
}
wp_cache_flush();
FW_Cache::clear();
// Zip archive will be created only after closing object
if (!$zip->close()) {
return new WP_Error('cannot_close_zip', __('Cannot close the zip file', 'fw'));
}
if (!rename($zip_path, $args['destination_dir'] . '/' . basename($zip_path))) {
return new WP_Error('cannot_move_zip', __('Cannot move zip in destination dir', 'fw'));
}
return true;
}
开发者ID:azharijelek,项目名称:Unyson-Backups-Extension,代码行数:53,代码来源:class-fw-ext-backups-task-type-zip.php
示例7: execute
/**
* {@inheritdoc}
* @param array $args
* * dir - source directory in which is located `database.json.txt`
* * [full] - (bool) force full or content restore. if not specified, will be detected automatically
* * [required] - (default: false) if database file must exist, else if db restore is optional
*/
public function execute(array $args, array $state = array())
{
if (!isset($args['dir'])) {
return new WP_Error('no_source_dir', __('Source dir not specified', 'fw'));
} else {
$args['dir'] = fw_fix_path($args['dir']);
}
if (!isset($args['required'])) {
$args['required'] = false;
} else {
$args['required'] = (bool) $args['required'];
}
if (empty($state)) {
if (!file_exists($args['dir'] . '/database.json.txt')) {
if ($args['required']) {
return new WP_Error('no_db_file', __('Database file not found', 'fw'));
} else {
return true;
}
}
$state = array('task' => 'cleanup', 'step' => 0, 'params' => array(), 'tables' => array(), 'full' => isset($args['full']) ? (bool) $args['full'] : null);
}
if (!class_exists('SplFileObject')) {
return new WP_Error('no_spl_file_object', __('PHP class SplFileObject is required but not available. Please contact your hosting', 'fw'));
}
if ($state['task'] === 'cleanup') {
return $this->do_cleanup($args, $state);
} elseif ($state['task'] === 'inspect') {
return $this->do_inspect($args, $state);
} elseif ($state['task'] === 'import') {
return $this->do_import($args, $state);
} elseif ($state['task'] === 'keep:options') {
return $this->do_keep_options($args, $state);
} elseif ($state['task'] === 'replace') {
return $this->do_replace($args, $state);
} else {
return new WP_Error('invalid_sub_task', sprintf(__('Invalid sub task %s', 'fw'), $state['task']));
}
return $state;
}
开发者ID:ThemeFuse,项目名称:Unyson-Backups-Extension,代码行数:47,代码来源:class-fw-ext-backups-task-type-db-restore.php
示例8: get_wp_fs_tmp_dir
private function get_wp_fs_tmp_dir()
{
return FW_WP_Filesystem::real_path_to_filesystem_path(apply_filters('fw_tmp_dir', fw_fix_path(WP_CONTENT_DIR) . '/tmp'));
}
开发者ID:puriwp,项目名称:Theme-Framework,代码行数:4,代码来源:class-fw-extension-update.php
示例9: get_path
private static function get_path()
{
if (is_null(self::$path)) {
self::$path = wp_upload_dir();
self::$path = fw_fix_path(self::$path['basedir']) . '/fw/file-cache.php';
}
return self::$path;
}
开发者ID:puriwp,项目名称:Theme-Framework,代码行数:8,代码来源:class-fw-file-cache.php
示例10: add_restore_tasks
/**
* Add restore tasks to a collection
* @param FW_Ext_Backups_Task_Collection $collection
* @param bool $full
* @param string|null $zip_path
* @param array $filesystem_args {}|{hostname: '', username: '', password: '', connection_type: ''}
* @return FW_Ext_Backups_Task_Collection
*/
public function add_restore_tasks(FW_Ext_Backups_Task_Collection $collection, $full = false, $zip_path = null, $filesystem_args = array())
{
$full = (bool) $full;
$tmp_dir = self::backups()->get_tmp_dir();
$dirs = $this->get_dirs($full);
$id_prefix = 'restore:';
if ($zip_path) {
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'unzip', 'unzip', array('zip' => $zip_path, 'dir' => $tmp_dir)));
}
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'files-restore', 'files-restore', array('source_dir' => $tmp_dir . '/f', 'destinations' => $dirs, 'filesystem_args' => $filesystem_args, 'skip_dirs' => is_multisite() && ($wp_upload_dir = wp_upload_dir()) ? array(fw_fix_path($wp_upload_dir['basedir']) . '/sites' => true) : array())));
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'db-restore', 'db-restore', array('dir' => $tmp_dir, 'full' => $full)));
if (!$full && apply_filters('fw:ext:backups:add-restore-task:image-sizes-restore', true, $collection)) {
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'image-sizes-restore', 'image-sizes-restore', array()));
}
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'tmp-dir-clean:after', 'dir-clean', array('dir' => $tmp_dir)));
/** @since 2.0.16 */
do_action('fw:ext:backups:add-restore-tasks', $collection, array('is_full' => $full, 'tmp_dir' => $tmp_dir, 'dirs' => $dirs));
return $collection;
}
开发者ID:ThemeFuse,项目名称:Unyson-Backups-Extension,代码行数:27,代码来源:class--fw-ext-backups-module-tasks.php
示例11: get_tmp_dir
private function get_tmp_dir($append = '')
{
return apply_filters('fw_tmp_dir', fw_fix_path(WP_CONTENT_DIR) . '/tmp') . $append;
}
开发者ID:northpen,项目名称:northpen,代码行数:4,代码来源:class--fw-extensions-manager.php
示例12: execute
/**
* {@inheritdoc}
* @param array $args
* * type - registered download type
* * type_args - args for registered type instance
* * destination_dir - Where must be placed the downloaded files
*/
public function execute(array $args, array $state = array())
{
if (empty($args['destination_dir'])) {
return new WP_Error('no_destination_dir', __('Destination dir not specified', 'fw'));
} elseif (!($args['destination_dir'] = fw_fix_path($args['destination_dir']))) {
return new WP_Error('invalid_destination_dir', __('Invalid destination dir', 'fw'));
}
if (empty($args['type']) || !($type = self::get_types()) || !isset($type[$args['type']])) {
return new WP_Error('invalid_type', sprintf(__('Invalid type: %s', 'fw'), $args['type']));
}
$type = $type[$args['type']];
if (empty($args['type_args'])) {
return new WP_Error('no_type_args', sprintf(__('Args not specified for type: %s', 'fw'), $type->get_type()));
}
$args['type_args'] = array_merge($args['type_args'], array('destination_dir' => $args['destination_dir']));
return $type->download($args['type_args'], $state);
}
开发者ID:ThemeFuse,项目名称:Unyson-Backups-Extension,代码行数:24,代码来源:class-fw-ext-backups-task-type-download.php
示例13: mkdir_recursive
/**
* Create wp filesystem directory recursive
* @param string $wp_filesystem_dir_path
* @return bool
*/
public static final function mkdir_recursive($wp_filesystem_dir_path)
{
/** @var WP_Filesystem_Base $wp_filesystem */
global $wp_filesystem;
if (!$wp_filesystem) {
trigger_error('Filesystem is not available', E_USER_WARNING);
return false;
}
$wp_filesystem_dir_path = fw_fix_path($wp_filesystem_dir_path);
$path = '';
$check_if_exists = true;
$firs_loop = true;
foreach (explode('/', $wp_filesystem_dir_path) as $dir_name) {
if (empty($dir_name)) {
if ($firs_loop) {
// in first loop $dir_name can be empty because it's starting with
} else {
trigger_error('Invalid path: ' . $wp_filesystem_dir_path, E_USER_WARNING);
return false;
}
}
$firs_loop = false;
$path .= '/' . $dir_name;
if ($check_if_exists) {
if ($wp_filesystem->is_dir($path)) {
// do nothing if exists
continue;
} else {
// do not check anymore, next directories sure does not exists
$check_if_exists = false;
}
}
$wp_filesystem->mkdir($path, FS_CHMOD_DIR);
}
return true;
}
开发者ID:AdsonCicilioti,项目名称:Unyson,代码行数:41,代码来源:class-fw-wp-filesystem.php
示例14: _action_update_framework
/**
* @internal
*/
public function _action_update_framework()
{
$nonce_name = '_nonce_fw_ext_update_framework';
if (!isset($_POST[$nonce_name]) || !wp_verify_nonce($_POST[$nonce_name])) {
wp_die(__('Invalid nonce.', 'fw'));
}
if (!class_exists('_FW_Ext_Update_Framework_Upgrader_Skin')) {
fw_include_file_isolated($this->get_declared_path('/includes/classes/class--fw-ext-update-framework-upgrader-skin.php'));
}
$skin = new _FW_Ext_Update_Framework_Upgrader_Skin(array('title' => __('Update Framework', 'fw')));
require_once ABSPATH . 'wp-admin/admin-header.php';
$skin->header();
$update = $this->get_framework_update(true);
do {
if ($update === false) {
$skin->error(__('Failed to get framework latest version.', 'fw'));
break;
} elseif (is_wp_error($update)) {
$skin->error($update);
break;
}
$context = $this->context;
if (!FW_WP_Filesystem::request_access($context, fw_current_url(), array($nonce_name))) {
break;
}
$this->maintenance_mode(true);
/** @var WP_Filesystem_Base $wp_filesystem */
global $wp_filesystem;
$tmp_download_dir = FW_WP_Filesystem::real_path_to_filesystem_path(fw_fix_path(WP_CONTENT_DIR) . '/cache/framework/update');
// just in case it already exists, clear everything, it may contain broken/old files
$wp_filesystem->rmdir($tmp_download_dir, true);
if (!FW_WP_Filesystem::mkdir_recursive($tmp_download_dir)) {
$skin->error(__('Cannot create directory: ' . $tmp_download_dir, 'fw'));
break;
}
$skin->feedback(__('Downloading framework...', 'fw'));
/** @var FW_Ext_Update_Service $service */
$service = $this->get_child($update['service']);
$downloaded_files_dir = $service->_download_framework($update['latest_version'], $tmp_download_dir);
if (!$downloaded_files_dir) {
$skin->error(__('Failed to download framework.', 'fw'));
break;
} elseif (is_wp_error($downloaded_files_dir)) {
$skin->error($downloaded_files_dir);
break;
}
$skin->feedback(__('Installing framework...', 'fw'));
$framework_dir = FW_WP_Filesystem::real_path_to_filesystem_path(fw_get_framework_directory());
// remove entire framework directory
$wp_filesystem->rmdir($framework_dir, true);
// move downloaded directory as new framework directory
$wp_filesystem->move($downloaded_files_dir, $framework_dir);
$skin->feedback(__('Framework updated.', 'fw'));
$wp_filesystem->delete($tmp_download_dir, true, 'd');
$skin->set_result(true);
$skin->after();
} while (false);
$this->maintenance_mode(false);
$skin->footer();
require_once ABSPATH . 'wp-admin/admin-footer.php';
}
开发者ID:outlinez,项目名称:Unyson,代码行数:64,代码来源:class-fw-extension-update.php
示例15: get_dirs
private function get_dirs($full = false)
{
$wp_upload_dir = wp_upload_dir();
$dirs = array('uploads' => fw_fix_path($wp_upload_dir['basedir']), 'plugins' => fw_fix_path(WP_PLUGIN_DIR), 'themes' => fw_fix_path(get_theme_root()));
if (is_multisite() && WPMU_PLUGIN_DIR) {
$dirs['mu-plugins'] = fw_fix_path(WPMU_PLUGIN_DIR);
}
if (!$full) {
unset($dirs['plugins']);
unset($dirs['mu-plugins']);
unset($dirs['themes']);
}
return $dirs;
}
开发者ID:azharijelek,项目名称:Unyson-Backups-Extension,代码行数:14,代码来源:class--fw-ext-backups-module-tasks.php
示例16: fw_try_make_writable
/**
* Try everything to create and make a path (file or directory) writable
* Works only within /wp-content dir, cannot make writable something outside it
* @param string $path
* @return bool
* @deprecated It's not safe to make files writable or create files as php user. Use http://codex.wordpress.org/Filesystem_API
*/
function fw_try_make_writable($path)
{
static $root_dir = null;
if ($root_dir === null) {
$root_dir = fw_fix_path(WP_CONTENT_DIR);
}
$chmod_writable_dir = 0777;
$chmod_writable_file = 0666;
do {
if (is_writable($path)) {
return true;
}
$path = fw_fix_path($path);
$rel_path = explode($root_dir, $path);
if (!empty($rel_path[0])) {
break;
}
// is not located in root dir
array_shift($rel_path);
// remove first empty element
$rel_path = implode($root_dir, $rel_path);
$rel_path_arr = explode('/', $rel_path);
array_shift($rel_path_arr);
// remove first empty element
if (empty($rel_path_arr)) {
break;
}
$file_name = '';
if (!is_dir($path)) {
if (file_exists($path)) {
// file exists, we can only try to make it writable
if (@chmod($path, $chmod_writable_file)) {
true;
} else {
break;
}
}
$file_name = array_pop($rel_path_arr);
}
if (!empty($rel_path_arr)) {
// check if parent directories exists, if not, create and make writable
$dir_path = $root_dir . '/' . implode('/', $rel_path_arr);
if (!file_exists($dir_path)) {
$created = @mkdir($dir_path, $chmod_writable_dir, true);
if (!$created) {
break;
}
}
if (!is_writable($dir_path)) {
if (@chmod($dir_path, $chmod_writable_dir)) {
true;
} else {
break;
}
}
}
if ($file_name) {
// file not exists, need to create
if (false === file_put_contents($path, '')) {
break;
}
if (is_writable($path)) {
return true;
}
if (@chmod($path, $chmod_writable_file)) {
true;
} else {
break;
}
}
return true;
} while (false);
return false;
}
开发者ID:AdsonCicilioti,项目名称:Unyson,代码行数:81,代码来源:general.php
示例17: define
/** @deprecated */
define('FW_CT_EXTENSIONS_URI', FW_CT_CUSTOM_URI . '/extensions');
}
/** @deprecated */
define('FW_PT_DIR', fw_fix_path(get_template_directory()));
/** @deprecated */
define('FW_PT_CUSTOM_DIR', FW_PT_DIR . '/framework-customizations');
/** @deprecated */
define('FW_PT_THEME_DIR', FW_PT_CUSTOM_DIR . '/theme');
/** @deprecated */
define('FW_PT_EXTENSIONS_DIR', FW_PT_CUSTOM_DIR . '/extensions');
/** @deprecated */
define('FW_PT_URI', get_template_directory_uri());
/** @deprecated */
define('FW_PT_CUSTOM_URI', FW_PT_URI . '/framework-customizations');
/** @deprecated */
define('FW_PT_THEME_URI', FW_PT_CUSTOM_URI . '/theme');
/** @deprecated */
define('FW_PT_EXTENSIONS_URI', FW_PT_CUSTOM_URI . '/extensions');
/** @deprecated */
define('FW_DIR', FW_PT_DIR . '/framework');
/** @deprecated */
define('FW_EXTENSIONS_DIR', FW_DIR . '/extensions');
/** @deprecated */
define('FW_URI', FW_PT_URI . '/framework');
/** @deprecated */
define('FW_EXTENSIONS_URI', FW_URI . '/extensions');
/** @deprecated */
define('FW_CACHE_DIR', fw_fix_path(WP_CONTENT_DIR) . '/cache/framework');
/** @deprecated */
define('FW_CACHE_URI', WP_CONTENT_URL . '/cache/framework');
开发者ID:outlinez,项目名称:Unyson,代码行数:31,代码来源:deprecated-constants.php
示例18: do_install
private function do_install(FW_Ext_Backups_Demo $demo)
{
$tmp_dir = self::backups()->get_tmp_dir();
$wp_upload_dir = wp_upload_dir();
$dirs = array('uploads' => fw_fix_path($wp_upload_dir['basedir']));
$id_prefix = 'demo:';
$collection = new FW_Ext_Backups_Task_Collection(self::$task_collection_id);
if (!self::backups()->is_disabled()) {
$collection = self::backups()->tasks()->add_backup_tasks($collection, false);
}
$collection->set_title(__('Demo Content Install', 'fw'));
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'tmp-dir-clean:before', 'dir-clean', array('dir' => $tmp_dir)));
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'demo-download', 'download', array('type' => $demo->get_source_type(), 'type_args' => $demo->get_source_args(), 'destination_dir' => $tmp_dir)));
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'files-restore', 'files-restore', array('source_dir' => $tmp_dir . '/f', 'destinations' => $dirs)));
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'db-restore', 'db-restore', array('dir' => $tmp_dir)));
$collection->add_task(new FW_Ext_Backups_Task($id_prefix . 'tmp-dir-clean:after', 'dir-clean', array('dir' => $tmp_dir)));
$this->set_active_demo(array('id' => $demo->get_id(), 'result' => null));
self::backups()->tasks()->execute_task_collection($collection);
}
开发者ID:azharijelek,项目名称:Unyson-Backups-Extension,代码行数:19,代码来源:class-fw-extension-backups-demo.php
示例19: get_next_files
/**
* @param string $root_dir
* @param array $dirs
* @param string $previous_file
* @param array $exclude_paths
* @return array|true|WP_Error ['file.txt', 'file.php', ...]
* Important: It will never return an empty array. Only: (array)files, true, WP_Error
*/
private function get_next_files($root_dir, array &$dirs, $previous_file, array $exclude_paths)
{
$rel_dir = empty($dirs) ? '' : '/' . implode('/', $dirs);
$included_hidden_names = fw_ext('backups')->get_config('included_hidden_names');
if ($paths = glob($root_dir . $rel_dir . '/{,.}[!.,!..]*', GLOB_MARK | GLOB_BRACE)) {
$files = array();
// result
$file_found = empty($previous_file);
// find previous file and return next files
$count = 0;
foreach ($paths as $path) {
$file = basename($path);
if (!$file_found) {
$file_found = $file === $previous_file;
continue;
}
if ($file[0] === '.' && !isset($included_hidden_names[$file])) {
continue;
}
if (is_dir($path)) {
if (isset($exclude_paths[fw_fix_path($path)])) {
continue;
} elseif ($files) {
// return collected files, will go inside directory on next call
return $files;
} else {
$dirs[] = $file;
return $this->get_next_files($root_dir, $dirs, '', $exclude_paths);
}
} else {
$files[] = $file;
if (++$count > $this->get_max_files_per_cycle()) {
return $files;
}
}
}
if (empty($files)) {
if ($file_found) {
// reached end of the directory
if ($dirs) {
// go a directory back
$previous_file = array_pop($dirs);
return $this->get_next_files($root_dir, $dirs, $previous_file, $exclude_paths);
} else {
// root directory end reached
return true;
}
} else {
return new WP_Error('previous_file_not_found', sprintf(__('Failed to restore dir listing from: %s', 'fw'), $root_dir . $rel_dir . '/' . $previous_file));
}
}
return $files;
} else {
// directory is empty
if ($dirs) {
// go a directory back
$previous_file = array_pop($dirs);
return $this->get_next_files($root_dir, $dirs, $previous_file, $exclude_paths);
} else {
// root directory end reached
return true;
}
}
}
开发者ID:azharijelek,项目名称:Unyson-Backups-Extension,代码行数:72,代码来源:class-fw-ext-backups-task-type-files-export.php
示例20: execute
/**
* {@inheritdoc}
* @param array $args
* * dir - source directory in which is located `database.json.txt`
* * [full] - (bool) force full or content restore. if not specified, will be detected automatically
* * [required] - (default: false) if database file must exist, else if db restore is optional
*/
public function execute(array $args, array $state = array())
{
if (!isset($args['dir'])) {
return new WP_Error('no_source_dir', __('Source dir not specified', 'fw'));
} else {
$args['dir'] = fw_fix_path($args['dir']);
}
if (!isset($args['required'])) {
$args['required'] = false;
} else {
$args['required'] = (bool) $args['required'];
}
if (empty($state)) {
if (!file_exists($args['dir'] . '/database.json.txt')) {
if ($args['required']) {
return new WP_Error('no_db_file', __('Database file not found', 'fw'));
} else {
return true;
}
}
$state = array('task' => 'cleanup', 'step' => 0, 'params' => array(), 'tables' => array(), 'full' => isset($args['full']) ? (bool) $args['full'] : null);
}
global $wpdb;
/** @var WPDB $wpdb */
if ($state['task'] === 'cleanup') {
// delete all tables with temporary prefix $this->get_tmp_table_prefix()
if ($table_names = $wpdb->get_col($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->esc_like($this->get_tmp_table_prefix()) . '%'))) {
if (!$wpdb->query('DROP TABLE ' . esc_sql($table_name = array_pop($table_names)))) {
return new WP_Error('drop_tmp_table_fail', sprintf(__('Cannot drop temporary table: %s', 'fw'), $table_name));
}
return $state;
} else {
$state['task'] = 'inspect';
$state['step'] = 0;
return $state;
}
} elseif ($state['task'] === 'inspect') {
try {
$fo = new SplFileObject($args['dir'] . '/database.json.txt');
} catch (RuntimeException $e) {
$fo = null;
return new WP_Error('cannot_open_file', __('Cannot open db file', 'fw'));
}
try {
$fo->seek($state['step']);
} catch (RuntimeException $e) {
$fo = null;
return new WP_Error('cannot_move_file_cursor', __('Cannot move cursor in db file', 'fw'));
}
$started_time = time();
$timeout = fw_ext('backups')->get_timeout() - 7;
while (time() - $started_time < $timeout) {
if ($line = $fo->current()) {
if (is_null($line = json_decode($line, true))) {
$fo = null;
return new WP_Error('line_decode_fail', sprintf(__('Failed to decode line %d from db file.', 'fw') . ' ' . fw_get_json_last_error_message(), $state['step'] + 1));
}
if ($line['type'] === 'row' && $line['data']['table'] === 'options' && isset($line['data']['row']['option_name']) && in_array($line['data']['row']['option_name'], array('siteurl', 'home'))) {
$state['params'][$line['data']['row']['option_name']] = $line['data']['row']['option_value'];
} elseif ($line['type'] === 'table' && !isset($state['tables'][$line['data']['name']])) {
$state['tables'][$line['data']['name']] = true;
} elseif ($line['type'] === 'param') {
$state['params'][$line['data']['name']] = $line['data']['value'];
}
} elseif ($line === false && !$fo->eof()) {
$fo = null;
return new WP_Error('line_read_fail', sprintf(__('Cannot read line %d from db file', 'fw'), $state['step'] + 1));
} else {
if (!isset($state['params']['siteurl']) || !isset($state['params']['home'])) {
return new WP_Error('params_not_found', __('Required params not found', 'fw'));
}
$is_full_backup = isset($state['tables']['commentmeta']) && isset($state['tables']['comments']) && isset($state['tables']['links']) && isset($state['tables']['options']) && isset($state['tables']['postmeta']) && isset($state['tables']['posts']) && isset($state['tables']['terms']) && isset($state['tables']['term_relationships']) && isset($state['tables']['term_taxonomy']) && isset($state['tables']['usermeta']) && isset($state['tables']['users']);
if (is_multisite()) {
/* @link https://codex.wordpress.org/Database_Description */
$is_full_backup = $is_full_backup && (isset($state['tables']['blogs']) && isset($state['tables']['blog_versions']) && isset($state['tables']['registration_log']) && isset($state['tables']['signups']) && isset($state['tables']['site']) && isset($state['tables']['sitemeta']));
}
if (is_null($state['full'])) {
$state['full'] = $is_full_backup;
} elseif ($state['full'] && !$is_full_backup) {
return new WP_Error('full_db_restore_impossible', __('Cannot do full db restore because backup is missing some tables', 'fw'));
}
$skip_tables = array('users' => true, 'usermeta' => true);
if (!$state['full']) {
$skip_tables = array_merge($skip_tables, array('blogs' => true, 'blog_versions' => true, 'registration_log' => true, 'signups' => true, 'site' => true, 'sitemeta' => true, 'sitecategories' => true));
}
foreach (array_keys($skip_tables) as $table_name) {
if (isset($state['tables'][$t
|
请发表评论