本文整理汇总了PHP中fw_fix_path函数的典型用法代码示例。如果您正苦于以下问题:PHP fw_fix_path函数的具体用法?PHP fw_fix_path怎么用?PHP fw_fix_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fw_fix_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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'));
}
示例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;
}
示例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;
}
示例11: get_tmp_dir
private function get_tmp_dir($append = '')
{
return apply_filters('fw_tmp_dir', fw_fix_path(WP_CONTENT_DIR) . '/tmp') . $append;
}
示例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;
}
示例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';
}
示例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;
}