public function __construct(Replace $replace, DatabaseManager $dbm)
 {
     $this->errors = new \WP_Error();
     $this->backup_dir = get_temp_dir();
     $this->replace = $replace;
     $this->dbm = $dbm;
 }
 /**
  * Save some CSV data to a file, and create a quasi-$_FILES entry for it.
  * @param string $data
  * @return string|array
  */
 private function save_data_file($data)
 {
     $test_filename = get_temp_dir() . '/test_' . uniqid() . '.csv';
     file_put_contents($test_filename, $data);
     $uploaded = array('type' => 'text/csv', 'file' => $test_filename);
     return $uploaded;
 }
Beispiel #3
0
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $this->initCmd();
     if (is_null($this->cmd)) {
         return false;
     }
     $absPath = $fileview->toTmpFile($path);
     $tmpDir = get_temp_dir();
     $defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ';
     $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
     $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
     $export = 'export HOME=/' . $tmpDir;
     shell_exec($export . "\n" . $exec);
     //create imagick object from pdf
     try {
         $pdf = new \imagick($absPath . '.pdf' . '[0]');
         $pdf->setImageFormat('jpg');
     } catch (\Exception $e) {
         unlink($absPath);
         unlink($absPath . '.pdf');
         \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromData($pdf);
     unlink($absPath);
     unlink($absPath . '.pdf');
     return $image->valid() ? $image : false;
 }
Beispiel #4
0
function jb_doPostFacebook($status_msg)
{
    $username = get_option('facebook-account-username');
    $password = get_option('facebook-account-password');
    $firstname = get_option('facebook-account-firstname');
    $cookiejar = get_temp_dir() . $firstname . "-" . sha1(mt_rand()) . "-cookiejar.txt";
    $fp = fopen($cookiejar, "w+") or die("<BR><B>Unable to open cookie file {$cookiejar} for write!<BR>");
    fclose($fp);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&amp;next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'email=' . urlencode($username) . '&pass='******'&login=Login');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
    curl_exec($ch);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
    $page = curl_exec($ch);
    curl_setopt($ch, CURLOPT_POST, 1);
    preg_match('/name="post_form_id" value="(.*)" \\/>' . ucfirst($firstname) . '/', $page, $form_id);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'post_form_id=' . $form_id[1] . '&status=' . urlencode($status_msg) . '&update=Update');
    curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
    curl_exec($ch);
    unlink($cookiejar);
    // Delete cookiefile
}
Beispiel #5
0
 /**
  * {@inheritDoc}
  */
 public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
 {
     $this->initCmd();
     if (is_null($this->cmd)) {
         return false;
     }
     $absPath = $fileview->toTmpFile($path);
     $tmpDir = get_temp_dir();
     $defaultParameters = ' -env:UserInstallation=file://' . escapeshellarg($tmpDir . '/owncloud-' . \OC_Util::getInstanceId() . '/') . ' --headless --nologo --nofirststartwizard --invisible --norestore --convert-to pdf --outdir ';
     $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters);
     $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath);
     shell_exec($exec);
     //create imagick object from pdf
     $pdfPreview = null;
     try {
         list($dirname, , , $filename) = array_values(pathinfo($absPath));
         $pdfPreview = $dirname . '/' . $filename . '.pdf';
         $pdf = new \imagick($pdfPreview . '[0]');
         $pdf->setImageFormat('jpg');
     } catch (\Exception $e) {
         unlink($absPath);
         unlink($pdfPreview);
         \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
         return false;
     }
     $image = new \OC_Image();
     $image->loadFromData($pdf);
     unlink($absPath);
     unlink($pdfPreview);
     return $image->valid() ? $image : false;
 }
Beispiel #6
0
 function image_assets()
 {
     // TODO: check if ziparchive is installed cms/cmsdev
     $zip = new ZipArchive();
     $ids = explode(',', $_GET['ids']);
     $name = $_GET['name'] . '.zip';
     $path = get_temp_dir() . $name;
     if ($zip->open($path, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) {
         die(json_encode(array('error' => 'Could not retrieve files.')));
     }
     foreach ($ids as $id) {
         $image = get_attached_file($id);
         if (file_exists($image)) {
             $zip->addFile($image, basename($image));
         } else {
             // die("File $filepath doesnt exit");
         }
     }
     $zip->close();
     header('Content-Type: application/zip');
     header('Content-disposition: attachment; filename=' . $name);
     header('Content-Length: ' . filesize($path));
     //TODO: alternate method to make zip file work?
     ob_clean();
     flush();
     readfile($path);
     wp_die();
 }
Beispiel #7
0
 public function setUp()
 {
     $this->baseDir = get_temp_dir() . '/oc_tmp_test';
     if (!is_dir($this->baseDir)) {
         mkdir($this->baseDir);
     }
 }
 public function export(FW_Backup_Interface_Feedback $feedback)
 {
     $db = new FW_Backup_Export_Database();
     $fs = new FW_Backup_Export_File_System();
     $zip_file = sprintf('%s/backup-full-%s.zip', get_temp_dir(), date('Y_m_d-H_i_s'));
     $tmp_file = array();
     try {
         touch($zip_file);
         $zip = new ZipArchive();
         if ($zip->open($zip_file) !== true) {
             throw new FW_Backup_Exception(__('Could not create .zip file', 'fw'));
         }
         $fs->append_zip($zip, ABSPATH, '', $feedback);
         $zip->addFile($tmp_file[] = $db->export_sql($feedback), 'database.txt');
         $feedback->set_task(__('Compressing files...', 'fw'));
         $zip->close();
     } catch (FW_Backup_Exception $exception) {
         unset($zip);
         unlink($zip_file);
     }
     array_map('unlink', $tmp_file);
     if (isset($exception)) {
         throw $exception;
     }
     return $zip_file;
 }
function ninja_forms_csv_attachment($sub_id)
{
    global $ninja_forms_processing;
    // make sure this form is supposed to attach a CSV
    if (1 == $ninja_forms_processing->get_form_setting('admin_attach_csv') and 'submit' == $ninja_forms_processing->get_action()) {
        // convert submission id to array
        $sub_ids = array($sub_id);
        // create CSV content
        $csv_content = ninja_forms_export_subs_to_csv($sub_ids, true);
        // create temporary file
        $path = tempnam(get_temp_dir(), 'Sub');
        $temp_file = fopen($path, 'r+');
        // write to temp file
        fwrite($temp_file, $csv_content);
        fclose($temp_file);
        // find the directory we will be using for the final file
        $path = pathinfo($path);
        $dir = $path['dirname'];
        $basename = $path['basename'];
        // create name for file
        $new_name = apply_filters('ninja_forms_submission_csv_name', 'ninja-forms-submission');
        // remove a file if it already exists
        if (file_exists($dir . '/' . $new_name . '.csv')) {
            unlink($dir . '/' . $new_name . '.csv');
        }
        // move file
        rename($dir . '/' . $basename, $dir . '/' . $new_name . '.csv');
        $file1 = $dir . '/' . $new_name . '.csv';
        // add new file to array of existing files
        $files = $ninja_forms_processing->get_form_setting('admin_attachments');
        array_push($files, $file1);
        $ninja_forms_processing->update_form_setting('admin_attachments', $files);
    }
}
Beispiel #10
0
 public function setUp()
 {
     $this->tmpDir = get_temp_dir() . '/filestoragecommon';
     if (!file_exists($this->tmpDir)) {
         mkdir($this->tmpDir);
     }
     $this->instance = new OC_Filestorage_CommonTest(array('datadir' => $this->tmpDir));
 }
Beispiel #11
0
 protected static function getCacheDir()
 {
     $cache_dir = get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/';
     if (!is_dir($cache_dir)) {
         mkdir($cache_dir);
     }
     return $cache_dir;
 }
 /**
  * Wrapper for Google Client cache filepath + open_basedir restriction resolution.
  */
 function _app_gcal_client_temp_dir_lookup($params)
 {
     if (!function_exists('get_temp_dir')) {
         return $params;
     }
     $params['ioFileCache_directory'] = get_temp_dir() . 'Google_Client';
     return $params;
 }
Beispiel #13
0
 protected function setUp()
 {
     parent::setUp();
     $this->baseDir = get_temp_dir() . $this->getUniqueID('/oc_tmp_test');
     if (!is_dir($this->baseDir)) {
         mkdir($this->baseDir);
     }
 }
Beispiel #14
0
 /**
  * Finds a writable tmp directory.
  *
  * @since 150329 Improving tmp directory detection.
  *
  * @throws \exception On any failure.
  *
  * @return string Writable tmp directory.
  */
 public function tmpDir()
 {
     $tmp_dir = $this->nSeps(get_temp_dir());
     if (!$tmp_dir || !@is_dir($tmp_dir) || !@is_writable($tmp_dir)) {
         throw new \exception(__('Unable to find a writable tmp directory.', 'comment-mail'));
     }
     return $tmp_dir;
     // Writable tmp directory.
 }
 /**
  * Caller should handle removal of the temp file when finished.
  *
  * @param string $ext The extension to be given to the temp file.
  *
  * @return string A temp file with the given extension.
  */
 public static function getTempFile($ext = 'png')
 {
     static $base = null;
     static $tmp;
     if (is_null($base)) {
         $base = md5(time());
         $tmp = untrailingslashit(get_temp_dir());
     }
     return $tmp . DIRECTORY_SEPARATOR . wp_unique_filename($tmp, $base . '.' . $ext);
 }
Beispiel #16
0
 /**
  * convert via openOffice hosted on the same server
  * @param string $input
  * @param string $targetFilter
  * @param string $targetExtension
  * @return string
  */
 protected static function convertLocal($input, $targetFilter, $targetExtension)
 {
     $infile = \OCP\Files::tmpFile();
     $outdir = \OCP\Files::tmpFolder();
     $cmd = Helper::findOpenOffice();
     $params = ' --headless --convert-to ' . $targetFilter . ' --outdir ' . escapeshellarg($outdir) . ' --writer ' . escapeshellarg($infile) . ' -env:UserInstallation=file://' . escapeshellarg(get_temp_dir() . '/owncloud-' . \OC_Util::getInstanceId() . '/');
     file_put_contents($infile, $input);
     shell_exec($cmd . $params);
     $output = file_get_contents($outdir . '/' . basename($infile) . '.' . $targetExtension);
     return $output;
 }
 public static function setTempPath($sFilePath = '')
 {
     $_sDir = get_temp_dir();
     $sFilePath = basename($sFilePath);
     if (empty($sFilePath)) {
         $sFilePath = time() . '.tmp';
     }
     $sFilePath = $_sDir . wp_unique_filename($_sDir, $sFilePath);
     touch($sFilePath);
     return $sFilePath;
 }
 public function fetch($storage_file, FW_Backup_Interface_Feedback $feedback)
 {
     if (!$storage_file instanceof FW_Backup_Storage_File_Local) {
         throw new FW_Backup_Exception('$backup_file should be of class FW_Backup_File_Local');
     }
     $tmp = tempnam(get_temp_dir(), 'backup');
     if (!@copy($storage_file->get_path(), $tmp)) {
         $error = error_get_last();
         throw new FW_Backup_Exception(sprintf(__('copy(%s, %s) failed with message "%s"', 'fw'), $storage_file->get_path(), $tmp, $error['message']));
     }
     return $tmp;
 }
 /**
  * Create temp file
  *
  * @since 3.1
  * @param string $filename the attachment filename
  * @param string $file the file to write
  * @return string $filename
  */
 private function create_temp_file($filename, $file)
 {
     // prepend the temp directory
     $filename = get_temp_dir() . $filename;
     // create the file
     touch($filename);
     // open the file, write file, and close it
     $handle = @fopen($filename, 'w+');
     @fwrite($handle, $file);
     @fclose($handle);
     // make sure the temp file is removed after the email is sent
     $this->temp_filename = $filename;
     register_shutdown_function(array($this, 'unlink_temp_file'));
     return $filename;
 }
Beispiel #20
0
 /**
  * add an empty folder to the archive
  * @param string path
  * @return bool
  */
 function addFolder($path)
 {
     $tmpBase = get_temp_dir() . '/';
     if (substr($path, -1, 1) != '/') {
         $path .= '/';
     }
     if ($this->fileExists($path)) {
         return false;
     }
     mkdir($tmpBase . $path);
     $result = $this->tar->addModify(array($tmpBase . $path), '', $tmpBase);
     rmdir($tmpBase . $path);
     $this->fileList = false;
     return $result;
 }
 function setUp()
 {
     add_filter('wp_image_editors', array($this, 'set_wp_image_editor'));
     $this->file = tempnam(get_temp_dir(), '') . '.png';
     copy(dirname(__FILE__) . '/images/transparent.png', $this->file);
     $this->attachment = wp_insert_attachment(array('post_title' => 'test attachment', 'post_content' => 'test content', 'post_type' => 'attachment', 'post_status' => 'publish', 'post_mime_type' => 'image/png'), $this->file);
     wp_update_attachment_metadata($this->attachment, wp_generate_attachment_metadata($this->attachment, $this->file));
     update_option('thumbnail_size_w', 100);
     update_option('thumbnail_size_h', 100);
     update_option('thumbnail_crop', true);
     update_option('medium_size_w', 200);
     update_option('medium_size_h', 200);
     update_option('large_size_w', 300);
     update_option('large_size_h', 300);
 }
function HookFormat_chooserCollection_downloadReplacedownloadfile($resource, $size, $ext)
{
    if (!supportsInputFormat($resource['file_extension'])) {
        # Do not replace files we do not support
        return false;
    }
    $baseDirectory = get_temp_dir() . '/format_chooser';
    @mkdir($baseDirectory);
    $target = $baseDirectory . '/' . getTargetFilename($resource['ref'], $ext, $size);
    $format = getImageFormat($size);
    $width = (int) $format['width'];
    $height = (int) $format['height'];
    set_time_limit(0);
    convertImage($resource, 1, -1, $target, $width, $height);
    return $target;
}
function generate_transform_preview($ref){
	global $storagedir;	
        global $imagemagick_path;
	global $imversion;

	if (!isset($imversion)){
		$imversion = get_imagemagick_version();
	}

	$tmpdir = get_temp_dir();

        // get imagemagick path
        $command = get_utility_path("im-convert");
        if ($command==false) {exit("Could not find ImageMagick 'convert' utility.");}

        $orig_ext = sql_value("select file_extension value from resource where ref = '$ref'",'');
        $originalpath= get_resource_path($ref,true,'',false,$orig_ext);

	# Since this check is in get_temp_dir() omit: if(!is_dir($storagedir."/tmp")){mkdir($storagedir."/tmp",0777);}
	if(!is_dir(get_temp_dir() . "/transform_plugin")){mkdir(get_temp_dir() . "/transform_plugin",0777);}

       if ($imversion[0]<6 || ($imversion[0] == 6 &&  $imversion[1]<7) || ($imversion[0] == 6 && $imversion[1] == 7 && $imversion[2]<5)){
                $colorspace1 = " -colorspace sRGB ";
                $colorspace2 =  " -colorspace RGB ";
        } else {
                $colorspace1 = " -colorspace RGB ";
                $colorspace2 =  " -colorspace sRGB ";
        }

        $command .= " \"$originalpath\" +matte -delete 1--1 -flatten $colorspace1 -geometry 450 $colorspace2 \"$tmpdir/transform_plugin/pre_$ref.jpg\"";
        run_command($command);


	// while we're here, clean up any old files still hanging around
	$dp = opendir(get_temp_dir() . "/transform_plugin");
	while ($file = readdir($dp)) {
		if ($file <> '.' && $file <> '..'){
			if ((filemtime(get_temp_dir() . "/transform_plugin/$file")) < (strtotime('-2 days'))) {
				unlink(get_temp_dir() . "/transform_plugin/$file");
			}
		}
	}
	closedir($dp);

        return true;
  
}
 public function export(FW_Backup_Interface_Feedback $feedback)
 {
     /**
      * @var wpdb $wpdb
      */
     global $wpdb;
     $db = new FW_Backup_Export_Database();
     $fs = new FW_Backup_Export_File_System();
     $zip_file = sprintf('%s/backup-demo-install-%s.zip', get_temp_dir(), date('Y_m_d-H_i_s'));
     $tmp_file = array();
     try {
         touch($zip_file);
         $zip = new ZipArchive();
         if ($zip->open($zip_file) !== true) {
             throw new FW_Backup_Exception(__('Could not create .zip file', 'fw'));
         }
         $upload_dir = wp_upload_dir();
         fw_set_db_extension_data($this->backup()->get_name(), 'wp_upload_dir', $upload_dir);
         $upload_dir = $upload_dir['basedir'];
         $stylesheet_dir = get_stylesheet_directory();
         $template_dir = get_template_directory();
         // Do not put auto-install directory which comes with theme into archive
         $exclude = array();
         if ($a = $this->backup()->get_auto_install_dir()) {
             $exclude[] = $a;
         }
         $fs->append_zip($zip, $template_dir, basename($template_dir) . '/', $feedback, $exclude);
         if ($stylesheet_dir != $template_dir) {
             $fs->append_zip($zip, $stylesheet_dir, basename($stylesheet_dir) . '/', $feedback, $exclude);
         }
         $fs->append_zip($zip, $upload_dir, basename($template_dir) . '/auto-install/uploads/', $feedback);
         $options_where = "WHERE option_name NOT LIKE 'fw_backup.%%' AND option_name NOT IN ('ftp_credentials', 'mailserver_url', 'mailserver_login', 'mailserver_pass', 'mailserver_port', 'admin_email')";
         $exclude_table = array($wpdb->users);
         $zip->addFile($tmp_file[] = $db->export_sql($feedback, $options_where, $exclude_table), basename($template_dir) . '/auto-install/database.txt');
         $feedback->set_task(__('Compressing files...', 'fw'));
         $zip->close();
     } catch (FW_Backup_Exception $exception) {
         unset($zip);
         unlink($zip_file);
     }
     array_map('unlink', $tmp_file);
     if (isset($exception)) {
         throw $exception;
     }
     return $zip_file;
 }
Beispiel #25
0
/**
 * Modified from Core WP.
 *
 * @since unknown
 *
 * @param unknown_type $filename
 * @param unknown_type $dir
 * @return unknown
 */
function wp_tempnam($filename = '', $dir = '')
{
    if (empty($dir)) {
        $dir = get_temp_dir();
    }
    $filename = basename($filename);
    if (empty($filename)) {
        $filename = time();
    }
    $_filename = $filename = $dir . $filename;
    $i = 0;
    while (file_exists($filename)) {
        $filename = $_filename . $i++;
    }
    touch($filename);
    return $filename;
}
function generate_transform_preview($ref)
{
    global $storagedir;
    global $imagemagick_path;
    global $imversion;
    if (!isset($imversion)) {
        $imversion = get_imagemagick_version();
    }
    $tmpdir = get_temp_dir();
    // get imagemagick path
    $command = get_utility_path("im-convert");
    if ($command == false) {
        exit("Could not find ImageMagick 'convert' utility.");
    }
    $orig_ext = sql_value("select file_extension value from resource where ref = '{$ref}'", '');
    $transformsourcepath = get_resource_path($ref, true, 'scr', false, 'jpg');
    //use screen size if available to save time
    if (!file_exists($transformsourcepath)) {
        $transformsourcepath = get_resource_path($ref, true, '', false, $orig_ext);
    }
    # Since this check is in get_temp_dir() omit: if(!is_dir($storagedir."/tmp")){mkdir($storagedir."/tmp",0777);}
    if (!is_dir(get_temp_dir() . "/transform_plugin")) {
        mkdir(get_temp_dir() . "/transform_plugin", 0777);
    }
    if ($imversion[0] < 6 || $imversion[0] == 6 && $imversion[1] < 7 || $imversion[0] == 6 && $imversion[1] == 7 && $imversion[2] < 5) {
        $colorspace1 = " -colorspace sRGB ";
        $colorspace2 = " -colorspace RGB ";
    } else {
        $colorspace1 = " -colorspace RGB ";
        $colorspace2 = " -colorspace sRGB ";
    }
    $command .= " \"{$transformsourcepath}\"[0] +matte -flatten {$colorspace1} -geometry 450 {$colorspace2} \"{$tmpdir}/transform_plugin/pre_{$ref}.jpg\"";
    run_command($command);
    // while we're here, clean up any old files still hanging around
    $dp = opendir(get_temp_dir() . "/transform_plugin");
    while ($file = readdir($dp)) {
        if ($file != '.' && $file != '..') {
            if (filemtime(get_temp_dir() . "/transform_plugin/{$file}") < strtotime('-2 days')) {
                unlink(get_temp_dir() . "/transform_plugin/{$file}");
            }
        }
    }
    closedir($dp);
    return true;
}
Beispiel #27
0
 /**
  * Test generate_filename
  * @ticket 6821
  */
 public function test_generate_filename()
 {
     // Get an editor
     $editor = wp_get_image_editor(DIR_TESTDATA . '/images/canola.jpg');
     $property = new ReflectionProperty($editor, 'size');
     $property->setAccessible(true);
     $property->setValue($editor, array('height' => 50, 'width' => 100));
     // Test with no parameters
     $this->assertEquals('canola-100x50.jpg', basename($editor->generate_filename()));
     // Test with a suffix only
     $this->assertEquals('canola-new.jpg', basename($editor->generate_filename('new')));
     // Test with a destination dir only
     $this->assertEquals(trailingslashit(realpath(get_temp_dir())), trailingslashit(realpath(dirname($editor->generate_filename(null, get_temp_dir())))));
     // Test with a suffix only
     $this->assertEquals('canola-100x50.png', basename($editor->generate_filename(null, null, 'png')));
     // Combo!
     $this->assertEquals(trailingslashit(realpath(get_temp_dir())) . 'canola-new.png', $editor->generate_filename('new', realpath(get_temp_dir()), 'png'));
 }
Beispiel #28
0
 /**
  * Class constructor.
  *
  * @since 160710 Common utils.
  */
 public function __construct()
 {
     $this->is_multisite = is_multisite();
     $this->is_main_site = !$this->is_multisite || is_main_site();
     $this->is_admin = is_admin();
     $this->is_user_admin = $this->is_admin && is_user_admin();
     $this->is_network_admin = $this->is_admin && $this->is_multisite && is_network_admin();
     $this->debug = defined('WP_DEBUG') && WP_DEBUG;
     $this->debug_edge = $this->debug && defined('WP_DEBUG_EDGE') && WP_DEBUG_EDGE;
     $this->debug_log = $this->debug && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG;
     $this->debug_display = $this->debug && defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY;
     if (!($this->salt = wp_salt())) {
         throw new Exception('Failed to acquire WP salt.');
     }
     if (!($this->tmp_dir = rtrim(get_temp_dir(), '/'))) {
         throw new Exception('Failed to acquire a writable tmp dir.');
     }
     if (!($this->site_url = site_url('/'))) {
         throw new Exception('Failed to acquire site URL.');
     } elseif (!($this->site_url_parts = parse_url($this->site_url))) {
         throw new Exception('Failed to parse site URL parts.');
     } elseif (!($this->site_url_host = $this->site_url_parts['host'] ?? '')) {
         throw new Exception('Failed to parse site URL host.');
     } elseif (!($this->site_url_root_host = implode('.', array_slice(explode('.', $this->site_url_host), -2)))) {
         throw new Exception('Failed to parse site URL root host.');
     }
     if (!($this->site_url_option = get_option('siteurl'))) {
         throw new Exception('Failed to acquire site URL option.');
     } elseif (!($this->site_url_option_parts = parse_url($this->site_url_option))) {
         throw new Exception('Failed to parse site URL option parts.');
     } elseif (!($this->site_default_scheme = $this->site_url_option_parts['scheme'] ?? '')) {
         throw new Exception('Failed to parse site URL option scheme.');
     }
     if (!($this->template_directory_url = get_template_directory_uri())) {
         throw new Exception('Failed to acquire template directory URL.');
     } elseif (!($this->template_directory_url_parts = parse_url($this->template_directory_url))) {
         throw new Exception('Failed to parse template directory URL parts.');
     }
     $this->template = get_template();
     $this->stylesheet = get_stylesheet();
     $this->is_woocommerce_active = defined('WC_VERSION');
     $this->is_woocommerce_product_vendors_active = defined('WC_PRODUCT_VENDORS_VERSION');
     $this->is_jetpack_active = defined('JETPACK__VERSION');
 }
 public function export(FW_Backup_Interface_Feedback $feedback)
 {
     $time_start = microtime(true);
     $time_end = microtime(true) + $this->seconds;
     $sleep = 0.1;
     // Do not localize task names, they are used for debugging
     $feedback->set_task('Debugging Export Layer');
     while (microtime(true) < $time_end) {
         usleep($sleep * 1000000);
         $total = $time_end - $time_start;
         $complete = microtime(true) - $time_start;
         $feedback->set_progress(min(100, number_format($complete / $total * 100)) . '% -- ' . number_format($complete, 2) . 'sec');
     }
     $feedback->set_progress('100%');
     $feedback->set_task('Debugging Export Layer Done');
     $filename = sprintf('%s/backup-debug-%s.txt', get_temp_dir(), date('Y_m_d-H_i_s'));
     file_put_contents($filename, __FILE__);
     return $filename;
 }
Beispiel #30
0
 /**
  * validates an export for a user
  * checks for existence of export_info.json and file folder
  * @param string $exportedUser the user that was exported
  * @param string $path the path to the .zip export
  * @param string $exportedBy
  */
 public function validateUserExport($exportedBy, $exportedUser, $path)
 {
     $this->assertTrue(file_exists($path));
     // Extract
     $extract = get_temp_dir() . '/oc_import_' . uniqid();
     //mkdir($extract);
     $this->tmpfiles[] = $extract;
     $zip = new ZipArchive();
     $zip->open($path);
     $zip->extractTo($extract);
     $zip->close();
     $this->assertTrue(file_exists($extract . '/export_info.json'));
     $exportInfo = file_get_contents($extract . '/export_info.json');
     $exportInfo = json_decode($exportInfo);
     $this->assertNotNull($exportInfo);
     $this->assertEquals($exportedUser, $exportInfo->exporteduser);
     $this->assertEquals($exportedBy, $exportInfo->exportedby);
     $this->assertTrue(file_exists($extract . '/' . $exportedUser . '/files'));
 }