本文整理汇总了PHP中BackWPup_Job::generate_filename方法的典型用法代码示例。如果您正苦于以下问题:PHP BackWPup_Job::generate_filename方法的具体用法?PHP BackWPup_Job::generate_filename怎么用?PHP BackWPup_Job::generate_filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackWPup_Job
的用法示例。
在下文中一共展示了BackWPup_Job::generate_filename方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: job_run
public function job_run(BackWPup_Job $job_object)
{
global $wpdb;
$job_object->substeps_todo = 1;
$job_object->log(sprintf(__('%d. Trying to generate a file with installed widget names …', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']));
//build filename
if (empty($job_object->temp['widgetlistfile'])) {
$job_object->temp['widgetlistfile'] = $job_object->generate_filename($job_object->job['widgetlistfile'], 'sql') . $job_object->job['widgetlistfilecompression'];
}
$handle = fopen($job_object->temp['widgetlistfile'], 'w');
if ($handle) {
$query = "SELECT * FROM {$wpdb->options} WHERE option_name LIKE 'widget_%'";
$rows = $wpdb->get_results($query);
$header = '';
foreach ($rows as $row) {
$header .= "INSERT INTO {$wpdb->options} (option_name, option_value, autoload) VALUES" . "('" . esc_sql($row->option_name) . "', '" . esc_sql($row->option_value) . "', '" . esc_sql($row->autoload) . "')" . "ON DUPLICATE KEY UPDATE option_value = '" . esc_sql($row->option_value) . "';\n";
}
$query = "SELECT * FROM {$wpdb->options} WHERE option_name = 'sidebars_widgets'";
$rows = $wpdb->get_results($query);
foreach ($rows as $row) {
$header .= "INSERT INTO {$wpdb->options} (option_name, option_value, autoload) VALUES" . "('" . esc_sql($row->option_name) . "', '" . esc_sql($row->option_value) . "', '" . esc_sql($row->autoload) . "')" . "ON DUPLICATE KEY UPDATE option_value = '" . esc_sql($row->option_value) . "';\n";
}
fwrite($handle, $header);
fclose($handle);
} else {
$job_object->log(__('Can not open target file for writing.', 'backwpup'), E_USER_ERROR);
return FALSE;
}
if ($job_object->temp['widgetlistfile']) {
$job_object->additional_files_to_backup[] = $job_object->temp['widgetlistfile'];
$job_object->log(sprintf(__('Added widget list file "%1$s" with %2$s to backup file list.', 'backwpup'), $job_object->temp['widgetlistfile'], size_format($job_object->temp['widgetlistfile']), 2));
}
$job_object->substeps_done = 1;
return TRUE;
}
示例2: job_run
/**
* @param $job_object
* @return bool
*/
public function job_run(BackWPup_Job $job_object)
{
global $wpdb, $post, $wp_query;
$wxr_version = '1.2';
if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY']) {
$job_object->log(sprintf(__('%d. Trying to create a WordPress export to XML file …', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']));
$job_object->steps_data[$job_object->step_working]['wpexportfile'] = BackWPup::get_plugin_data('TEMP') . $job_object->generate_filename($job_object->job['wpexportfile'], 'xml', TRUE);
$job_object->steps_data[$job_object->step_working]['substep'] = 'header';
$job_object->steps_data[$job_object->step_working]['post_ids'] = array();
$job_object->substeps_todo = 10;
$job_object->substeps_done = 0;
}
add_filter('wxr_export_skip_postmeta', array($this, 'wxr_filter_postmeta'), 10, 2);
if ($job_object->steps_data[$job_object->step_working]['substep'] == 'header') {
if ('all' != $job_object->job['wpexportcontent'] && post_type_exists($job_object->job['wpexportcontent'])) {
$ptype = get_post_type_object($job_object->job['wpexportcontent']);
if (!$ptype->can_export) {
$job_object->log(sprintf(__('WP Export: Post type “%s” does not allow export.', 'backwpup'), $job_object->job['wpexportcontent']), E_USER_ERROR);
return FALSE;
}
$where = $wpdb->prepare("{$wpdb->posts}.post_type = %s", $job_object->job['wpexportcontent']);
} else {
$post_types = get_post_types(array('can_export' => true));
$esses = array_fill(0, count($post_types), '%s');
$where = $wpdb->prepare("{$wpdb->posts}.post_type IN (" . implode(',', $esses) . ')', $post_types);
$job_object->job['wpexportcontent'] = 'all';
}
$where .= " AND {$wpdb->posts}.post_status != 'auto-draft'";
// grab a snapshot of post IDs, just in case it changes during the export
$job_object->steps_data[$job_object->step_working]['post_ids'] = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE {$where}");
$job_object->substeps_todo = $job_object->substeps_todo + count($job_object->steps_data[$job_object->step_working]['post_ids']);
$header = '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
$header .= "<!-- This is a WordPress eXtended RSS file generated by the WordPress plugin BackWPup as an export of your site. -->\n";
$header .= "<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->\n";
$header .= "<!-- You may use this file to transfer that content from one site to another. -->\n";
$header .= "<!-- This file is not intended to serve as a complete backup of your site. -->\n\n";
$header .= "<!-- To import this information into a WordPress site follow these steps: -->\n";
$header .= "<!-- 1. Log in to that site as an administrator. -->\n";
$header .= "<!-- 2. Go to Tools: Import in the WordPress admin panel. -->\n";
$header .= "<!-- 3. Install the \"WordPress\" importer from the list. -->\n";
$header .= "<!-- 4. Activate & Run Importer. -->\n";
$header .= "<!-- 5. Upload this file using the form provided on that page. -->\n";
$header .= "<!-- 6. You will first be asked to map the authors in this export file to users -->\n";
$header .= "<!-- on the site. For each author, you may choose to map to an -->\n";
$header .= "<!-- existing user on the site or to create a new user. -->\n";
$header .= "<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->\n";
$header .= "<!-- contained in this file into your site. -->\n\n";
$header .= "<!-- generator=\"WordPress/" . get_bloginfo_rss('version') . "\" created=\"" . date('Y-m-d H:i') . "\" -->\n";
$header .= "<rss version=\"2.0\" xmlns:excerpt=\"http://wordpress.org/export/{$wxr_version}/excerpt/\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:wp=\"http://wordpress.org/export/{$wxr_version}/\">\n";
$header .= "<channel>\n";
$header .= "\t<title>" . get_bloginfo_rss('name') . "</title>\n";
$header .= "\t<link>" . get_bloginfo_rss('url') . "</link>\n";
$header .= "\t<description>" . get_bloginfo_rss('description') . "</description>\n";
$header .= "\t<pubDate>" . date('D, d M Y H:i:s +0000') . "</pubDate>\n";
$header .= "\t<language>" . get_bloginfo_rss('language') . "</language>\n";
$header .= "\t<wp:wxr_version>" . $wxr_version . "</wp:wxr_version>\n";
$header .= "\t<wp:base_site_url>" . $this->wxr_site_url() . "</wp:base_site_url>\n";
$header .= "\t<wp:base_blog_url>" . get_bloginfo_rss('url') . "</wp:base_blog_url>\n";
$written = file_put_contents($job_object->steps_data[$job_object->step_working]['wpexportfile'], $header, FILE_APPEND);
if ($written === FALSE) {
$job_object->log(__('WP Export file could not written.', 'backwpup'), E_USER_ERROR);
return FALSE;
}
unset($header);
$job_object->steps_data[$job_object->step_working]['substep'] = 'authors';
$job_object->substeps_done++;
$job_object->update_working_data();
$job_object->do_restart_time();
}
if ($job_object->steps_data[$job_object->step_working]['substep'] == 'authors') {
$written = file_put_contents($job_object->steps_data[$job_object->step_working]['wpexportfile'], $this->wxr_authors_list(), FILE_APPEND);
if ($written === FALSE) {
$job_object->log(__('WP Export file could not written.', 'backwpup'), E_USER_ERROR);
return FALSE;
}
$job_object->steps_data[$job_object->step_working]['substep'] = 'cats';
$job_object->substeps_done++;
$job_object->update_working_data();
$job_object->do_restart_time();
}
if ($job_object->steps_data[$job_object->step_working]['substep'] == 'cats') {
if ('all' == $job_object->job['wpexportcontent']) {
$cats = array();
$categories = (array) get_categories(array('get' => 'all'));
// put categories in order with no child going before its parent
while ($cat = array_shift($categories)) {
if ($cat->parent == 0 || isset($cats[$cat->parent])) {
$cats[$cat->term_id] = $cat;
} else {
$categories[] = $cat;
}
}
$cats_xml = '';
foreach ($cats as $c) {
$parent_slug = $c->parent ? $cats[$c->parent]->slug : '';
$cats_xml .= "\t<wp:category><wp:term_id>" . $c->term_id . "</wp:term_id><wp:category_nicename>" . $c->slug . "</wp:category_nicename><wp:category_parent>" . $parent_slug . "</wp:category_parent>" . $this->wxr_cat_name($c) . $this->wxr_category_description($c) . "</wp:category>\n";
//.........这里部分代码省略.........
示例3: job_run
/**
* Dumps the Database
*
* @param $job_object BackWPup_Job
*
* @return bool
*/
public function job_run(BackWPup_Job $job_object)
{
$job_object->substeps_todo = 1;
if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY']) {
$job_object->log(sprintf(__('%d. Try to backup database …', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']));
}
//build filename
if (empty($job_object->steps_data[$job_object->step_working]['dbdumpfile'])) {
$job_object->steps_data[$job_object->step_working]['dbdumpfile'] = $job_object->generate_filename($job_object->job['dbdumpfile'], 'sql') . $job_object->job['dbdumpfilecompression'];
}
try {
//Connect to Database
$sql_dump = new BackWPup_MySQLDump(array('dumpfile' => BackWPup::get_plugin_data('TEMP') . $job_object->steps_data[$job_object->step_working]['dbdumpfile']));
if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY']) {
$job_object->log(sprintf(__('Connected to database %1$s on %2$s', 'backwpup'), DB_NAME, DB_HOST));
}
//Exclude Tables
foreach ($sql_dump->tables_to_dump as $key => $table) {
if (in_array($table, $job_object->job['dbdumpexclude'], true)) {
unset($sql_dump->tables_to_dump[$key]);
}
}
//set steps must done
$job_object->substeps_todo = count($sql_dump->tables_to_dump);
if ($job_object->substeps_todo == 0) {
$job_object->log(__('No tables to backup.', 'backwpup'), E_USER_WARNING);
unset($sql_dump);
return TRUE;
}
//dump head
if (!isset($job_object->steps_data[$job_object->step_working]['is_head'])) {
$sql_dump->dump_head(TRUE);
$job_object->steps_data[$job_object->step_working]['is_head'] = TRUE;
}
//dump tables
$i = 0;
foreach ($sql_dump->tables_to_dump as $table) {
if ($i < $job_object->substeps_done) {
$i++;
continue;
}
if (empty($job_object->steps_data[$job_object->step_working]['tables'][$table])) {
$num_records = $sql_dump->dump_table_head($table);
$job_object->steps_data[$job_object->step_working]['tables'][$table] = array('start' => 0, 'length' => 1000);
if ($job_object->is_debug()) {
$job_object->log(sprintf(__('Backup database table "%s" with "%s" records', 'backwpup'), $table, $num_records));
}
}
$while = true;
while ($while) {
$dump_start_time = microtime(TRUE);
$done_records = $sql_dump->dump_table($table, $job_object->steps_data[$job_object->step_working]['tables'][$table]['start'], $job_object->steps_data[$job_object->step_working]['tables'][$table]['length']);
$dump_time = microtime(TRUE) - $dump_start_time;
if (empty($dump_time)) {
$dump_time = 0.01;
}
if ($done_records < $job_object->steps_data[$job_object->step_working]['tables'][$table]['length']) {
//that is the last chunk
$while = FALSE;
}
$job_object->steps_data[$job_object->step_working]['tables'][$table]['start'] = $job_object->steps_data[$job_object->step_working]['tables'][$table]['start'] + $done_records;
// dump time per record and set next length
$length = ceil($done_records / $dump_time * $job_object->get_restart_time());
if ($length > 25000 || 0 >= $job_object->get_restart_time()) {
$length = 25000;
}
if ($length < 1000) {
$length = 1000;
}
$job_object->steps_data[$job_object->step_working]['tables'][$table]['length'] = $length;
$job_object->do_restart_time();
}
$sql_dump->dump_table_footer($table);
$job_object->substeps_done++;
$i++;
$job_object->update_working_data();
}
//dump footer
$sql_dump->dump_footer();
unset($sql_dump);
} catch (Exception $e) {
$job_object->log($e->getMessage(), E_USER_ERROR, $e->getFile(), $e->getLine());
unset($sql_dump);
return FALSE;
}
$filesize = filesize(BackWPup::get_plugin_data('TEMP') . $job_object->steps_data[$job_object->step_working]['dbdumpfile']);
if (!is_file(BackWPup::get_plugin_data('TEMP') . $job_object->steps_data[$job_object->step_working]['dbdumpfile']) || $filesize < 1) {
$job_object->log(__('MySQL backup file not created', 'backwpup'), E_USER_ERROR);
return FALSE;
} else {
$job_object->additional_files_to_backup[] = BackWPup::get_plugin_data('TEMP') . $job_object->steps_data[$job_object->step_working]['dbdumpfile'];
$job_object->log(sprintf(__('Added database dump "%1$s" with %2$s to backup file list', 'backwpup'), $job_object->steps_data[$job_object->step_working]['dbdumpfile'], size_format($filesize, 2)));
}
//.........这里部分代码省略.........
示例4: job_run
/**
* @param $job_object
* @return bool
*/
public function job_run(BackWPup_Job $job_object)
{
$job_object->substeps_todo = 1;
$job_object->log(sprintf(__('%d. Trying to generate a file with installed plugin names …', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']));
//build filename
if (empty($job_object->temp['pluginlistfile'])) {
$job_object->temp['pluginlistfile'] = $job_object->generate_filename($job_object->job['pluginlistfile'], 'txt') . $job_object->job['pluginlistfilecompression'];
}
if ($job_object->job['pluginlistfilecompression'] == '.gz') {
$handle = fopen('compress.zlib://' . BackWPup::get_plugin_data('TEMP') . $job_object->temp['pluginlistfile'], 'w');
} elseif ($job_object->job['pluginlistfilecompression'] == '.bz2') {
$handle = fopen('compress.bzip2://' . BackWPup::get_plugin_data('TEMP') . $job_object->temp['pluginlistfile'], 'w');
} else {
$handle = fopen(BackWPup::get_plugin_data('TEMP') . $job_object->temp['pluginlistfile'], 'w');
}
if ($handle) {
//open file
$header = "------------------------------------------------------------" . PHP_EOL;
$header .= " Plugin list generated with BackWPup version: " . BackWPup::get_plugin_data('Version') . PHP_EOL;
$header .= " " . translate(BackWPup::get_plugin_data('pluginuri'), 'backwpup') . PHP_EOL;
$header .= " Blog Name: " . get_bloginfo('name') . PHP_EOL;
$header .= " Blog URL: " . get_bloginfo('url') . PHP_EOL;
$header .= " Generated on: " . date('Y-m-d H:i.s', current_time('timestamp')) . PHP_EOL;
$header .= "------------------------------------------------------------" . PHP_EOL . PHP_EOL;
fwrite($handle, $header);
//get Plugins
if (!function_exists('get_plugins')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugins = get_plugins();
$plugins_active = get_option('active_plugins');
//write it to file
fwrite($handle, PHP_EOL . __('All plugin information:', 'backwpup') . PHP_EOL . '------------------------------' . PHP_EOL);
foreach ($plugins as $plugin) {
fwrite($handle, $plugin['Name'] . ' (v.' . $plugin['Version'] . ') ' . html_entity_decode(sprintf(__('from %s', 'backwpup'), $plugin['Author']), ENT_QUOTES) . PHP_EOL . "\t" . $plugin['PluginURI'] . PHP_EOL);
}
fwrite($handle, PHP_EOL . __('Active plugins:', 'backwpup') . PHP_EOL . '------------------------------' . PHP_EOL);
foreach ($plugins as $key => $plugin) {
if (in_array($key, $plugins_active)) {
fwrite($handle, $plugin['Name'] . PHP_EOL);
}
}
fwrite($handle, PHP_EOL . __('Inactive plugins:', 'backwpup') . PHP_EOL . '------------------------------' . PHP_EOL);
foreach ($plugins as $key => $plugin) {
if (!in_array($key, $plugins_active)) {
fwrite($handle, $plugin['Name'] . PHP_EOL);
}
}
fclose($handle);
} else {
$job_object->log(__('Can not open target file for writing.', 'backwpup'), E_USER_ERROR);
return FALSE;
}
//add file to backup files
if (is_readable(BackWPup::get_plugin_data('TEMP') . $job_object->temp['pluginlistfile'])) {
$job_object->additional_files_to_backup[] = BackWPup::get_plugin_data('TEMP') . $job_object->temp['pluginlistfile'];
$job_object->log(sprintf(__('Added plugin list file "%1$s" with %2$s to backup file list.', 'backwpup'), $job_object->temp['pluginlistfile'], size_format(filesize(BackWPup::get_plugin_data('TEMP') . $job_object->temp['pluginlistfile']), 2)));
}
$job_object->substeps_done = 1;
return TRUE;
}