function add_widget($fileName, $tempName)
 {
     $dest = wp_upload_dir();
     if ($fileName == null) {
         $name = $_SESSION['name'];
     }
     if ($_POST['file'] == null) {
         $zipDestination = $dest['basedir'] . $fileName;
         move_uploaded_file($tempName, $zipDestination);
         $zipDestination = str_replace('\\', '/', $zipDestination);
         //slash corection if nessary
         $_POST['file'] = $zipDestination;
         $_POST['name'] = $fileName;
         $form_fields = array('file', 'name');
     }
     if (self::connect_fs('', "POST", get_option('widgetdir'), $form_fields)) {
         $destination = get_option('widgetdir') . $fileName;
         $file = $_POST['file'];
         $unzip = unzip_file($file, $destination);
         if (is_wp_error($unzip)) {
             $_SESSION['errors'] = ' <div class="errorNotfi">' . $unzip->get_error_message() . '</div>';
         } else {
             $_SESSION['errors'] = NULL;
         }
         unlink($file);
         return TRUE;
     }
     $_SESSION['name'] = NULL;
 }
Example #2
0
 function unpack_package_zip($package, $delete_package = true)
 {
     global $wp_filesystem;
     $this->skin->feedback($this->strings['unpack_package'] . ' (' . basename($package) . ')');
     $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
     //Clean up contents of upgrade directory beforehand.
     $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
     if (!empty($upgrade_files)) {
         foreach ($upgrade_files as $file) {
             $wp_filesystem->delete($upgrade_folder . $file['name'], true);
         }
     }
     //We need a working directory
     #This is the only change from the WP core version - minimise path length
     #$working_dir = $upgrade_folder . basename($package, '.zip');
     $working_dir = $upgrade_folder . substr(md5($package), 0, 8);
     // Clean up working directory
     if ($wp_filesystem->is_dir($working_dir)) {
         $wp_filesystem->delete($working_dir, true);
     }
     // Unzip package to working directory
     $result = unzip_file($package, $working_dir);
     // Once extracted, delete the package if required.
     if ($delete_package) {
         unlink($package);
     }
     if (is_wp_error($result)) {
         $wp_filesystem->delete($working_dir, true);
         if ('incompatible_archive' == $result->get_error_code()) {
             return new WP_Error('incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data());
         }
         return $result;
     }
     return $working_dir;
 }
function get_zip_data($basename, $imgselect, $imgext, $getimage, $getdata, &$imgtempfile, &$imagename, &$data)
{
    $ret = 0;
    $zipname = IMGPATH . "/" . $basename . ".zip";
    if (file_exists($zipname)) {
        // make sure we keep the file around if people are using it actively
        touch($zipname);
        if ($getimage) {
            $imagename = "button_{$imgselect}.{$imgext}";
            $buf = unzip_file($zipname, $imagename);
            //      $buf = shell_exec("unzip -p ".$zipname." ".$imagename);
            $tmpfname = tempnam(IMGPATH, "");
            if ($file = fopen($tmpfname, "w+")) {
                fwrite($file, $buf);
                fclose($file);
                $imgtempfile = $tmpfname;
                $ret = filesize($tmpfname);
            }
        } elseif ($getdata) {
            $buf = unzip_file($zipname, READMENAME);
            //      $buf = shell_exec("unzip -p ".$zipname." ".READMENAME);
            // for each $readmetags, get the associated value and put in an array
            $data = array();
            $readmetags = array(TAGBT, TAGPC, TAGGC, TAGW, TAGH, TAGCR, TAGTH, TAGTC, TAGBC, TAGFN, TAGRPC, TAGRGC, TAGRTC, TAGQ, TAGURL, TAGIL, TAGIH, TAGIN, TAGIF, TAGIFC, TAGIT, TAGITC);
            foreach ($readmetags as $tag) {
                $tempstr = substr(strstr($buf, $tag . ": "), strlen($tag) + 2);
                $data[$tag] = substr($tempstr, 0, strpos($tempstr, "\n"));
            }
            $ret = 1;
        }
    }
    return $ret;
}
Example #4
0
 protected function _validate_form()
 {
     $url = wp_nonce_url('admin.php?page=vimeography-my-themes');
     if (false === ($creds = request_filesystem_credentials($url))) {
         // if we get here, then we don't have credentials yet,
         // but have just produced a form for the user to fill in,
         // so stop processing for now
         return true;
         // stop the normal page form from displaying
     }
     // now we have some credentials, try to get the wp_filesystem running
     if (!WP_Filesystem($creds)) {
         // our credentials were no good, ask the user for them again
         request_filesystem_credentials($url);
         return true;
     }
     if (empty($_FILES)) {
         return;
     }
     // if this fails, check_admin_referer() will automatically print a "failed" page and die.
     if (!empty($_FILES) && check_admin_referer('vimeography-install-theme', 'vimeography-theme-verification')) {
         $name = substr(wp_filter_nohtml_kses($_FILES['vimeography-theme']['name']), 0, -4);
         if ($_FILES['vimeography-theme']['type'] != 'application/zip') {
             $this->messages[] = array('type' => 'error', 'heading' => 'Ruh Roh.', 'message' => 'Make sure you are uploading the actual .zip file, not a subfolder or file.');
         } else {
             global $wp_filesystem;
             if (!unzip_file($_FILES['vimeography-theme']['tmp_name'], VIMEOGRAPHY_THEME_PATH)) {
                 $this->messages[] = array('type' => 'error', 'heading' => 'Ruh Roh.', 'message' => 'The theme could not be installed.');
             } else {
                 $this->messages[] = array('type' => 'success', 'heading' => 'Theme installed.', 'message' => 'You can now use the "' . $name . '" theme in your galleries.');
             }
         }
     }
 }
function extractFile($zip_file, $file_in_zip)
{
    global $base_tmp_upgrade_dir;
    $my_zip_dir = mk_temp_dir($base_tmp_upgrade_dir);
    unzip_file($zip_file, $file_in_zip, $my_zip_dir);
    return "{$my_zip_dir}/{$file_in_zip}";
}
 public function installFile()
 {
     $hash = md5(uniqid());
     $tmp_folder = $GLOBALS['TMP_PATH'] . "/temp_plugin_" . $hash;
     mkdir($tmp_folder);
     $file = $GLOBALS['TMP_PATH'] . "/temp_plugin_" . $hash . ".zip";
     if ($this['repository_download_url']) {
         file_put_contents($file, file_get_contents($this['repository_download_url']));
     } elseif ($_FILES['release_file']['tmp_name']) {
         move_uploaded_file($_FILES['release_file']['tmp_name'], $file);
     } else {
         return false;
     }
     unzip_file($file, $tmp_folder);
     $objects = scandir($tmp_folder);
     if (count($objects) === 3) {
         foreach ($objects as $object) {
             if ($object != "." && $object != "..") {
                 $plugin_dir = $tmp_folder . "/" . $object;
             }
         }
     } else {
         $plugin_dir = $tmp_folder;
     }
     $this->installFromDirectory($plugin_dir, $file);
     rmdirr($tmp_folder);
     unlink($file);
     $this['chdate'] = time();
     NotificationCenter::postNotification("PluginReleaseDidUpdateCode", $this);
 }
 protected function getDownloadUrl()
 {
     global $wp_filesystem;
     $this->skin->feedback('download_envato');
     $package_filename = 'js_composer.zip';
     $res = $this->fs_connect(array(WP_CONTENT_DIR));
     if (!$res) {
         return new WP_Error('no_credentials', __("Error! Can't connect to filesystem", 'js_composer'));
     }
     $username = WPBakeryVisualComposerSettings::get('envato_username');
     $api_key = WPBakeryVisualComposerSettings::get('envato_api_key');
     $purchase_code = WPBakeryVisualComposerSettings::get('js_composer_purchase_code');
     if (empty($username) || empty($api_key) || empty($purchase_code)) {
         return new WP_Error('no_credentials', __('Error! Envato username, api key and your purchase code are required for downloading updates from Envato marketplace for the Visual Composer. Visit <a href="' . admin_url('options-general.php?page=wpb_vc_settings&tab=updater') . '' . '">Settings</a> to fix.', 'js_composer'));
     }
     $json = wp_remote_get($this->envatoDownloadPurchaseUrl($username, $api_key, $purchase_code));
     $result = json_decode($json['body'], true);
     if (!isset($result['download-purchase']['download_url'])) {
         return new WP_Error('no_credentials', __('Error! Envato API error' . (isset($result['error']) ? ': ' . $result['error'] : '.'), 'js_composer'));
     }
     $result['download-purchase']['download_url'];
     $download_file = download_url($result['download-purchase']['download_url']);
     if (is_wp_error($download_file)) {
         return $download_file;
     }
     $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade_tmp/js_composer_envato_package';
     if (is_dir($upgrade_folder)) {
         $wp_filesystem->delete($upgrade_folder);
     }
     $result = unzip_file($download_file, $upgrade_folder);
     if ($result && is_file($upgrade_folder . '/' . $package_filename)) {
         return $upgrade_folder . '/' . $package_filename;
     }
     return new WP_Error('no_credentials', __('Error on unzipping package', 'js_composer'));
 }
Example #8
0
 function synved_option_item_addon_install($id, $name, $item)
 {
     $return = null;
     $type = synved_option_item_type($item);
     $target = synved_option_item_property($item, 'target');
     $folder = synved_option_item_property($item, 'folder');
     $field_name = synved_option_name_default($id);
     $path = null;
     if (file_exists($target)) {
         $path = $target;
     }
     if ($type != 'addon' || $path == null) {
         return false;
     }
     $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
     if (substr($path, -1) != DIRECTORY_SEPARATOR) {
         $path .= DIRECTORY_SEPARATOR;
     }
     if (isset($_FILES[$field_name])) {
         foreach ($_FILES[$field_name]["error"] as $key => $error) {
             if ($key == $name && $error == UPLOAD_ERR_OK) {
                 $tmp_name = $_FILES[$field_name]["tmp_name"][$key];
                 $name = $_FILES[$field_name]["name"][$key];
                 $tmpfname = wp_tempnam($name . '.zip');
                 if (move_uploaded_file($tmp_name, $tmpfname)) {
                     global $wp_filesystem;
                     $unzip_path = realpath($path);
                     $dirs = glob($path . '*', GLOB_ONLYDIR);
                     if ($wp_filesystem != null) {
                         $unzip_path = $wp_filesystem->find_folder($unzip_path);
                     }
                     wp_mkdir_p(realpath($path));
                     $return = unzip_file($tmpfname, $unzip_path);
                     if ($wp_filesystem != null) {
                         $wp_filesystem->delete($tmpfname);
                     }
                     $dirs_new = glob($path . '*', GLOB_ONLYDIR);
                     $dirs_diff = array_values(array_diff($dirs_new, $dirs));
                     $addon_path = $path;
                     if ($dirs_diff != null) {
                         $folder_path = null;
                         foreach ($dirs_diff as $dir) {
                             if (basename($dir) == $folder) {
                                 $folder_path = $dir;
                             }
                         }
                         // XXX no correct path, was unzip successful?
                         if ($folder_path == null) {
                             $folder_path = $dirs_diff[0];
                         }
                         $addon_path = $folder_path;
                     }
                     synved_option_set($id, $name, $addon_path);
                 }
             }
         }
     }
     return $return;
 }
    /**
     * This function will execute the widget frontend logic.
     * Everything you want in the widget should be output here.
     */
    private function widget_output($args, $instance)
    {
        extract($instance);
        $file_name = 'Losungen Free ' . date('Y') . '.xml';
        # determin/create content path
        $file_path = wp_upload_dir()['basedir'] . '/losung/';
        if (!is_dir($file_path)) {
            mkdir($file_path, 0777, true);
        }
        # download content if not existing
        if (!file_exists($file_path . $file_name)) {
            $archive_name = 'Losung_' . date('Y') . '_XML.zip';
            WP_Filesystem();
            file_put_contents($file_path . $archive_name, file_get_contents('http://www.brueder-unitaet.de/download/' . $archive_name));
            if (!unzip_file($file_path . $archive_name, $file_path)) {
                echo "Error, could not get Content.";
                exit;
            }
        }
        # parse xml -> get data
        $xml_data = simplexml_load_file($file_path . $file_name);
        # get day of the year
        $index = (int) date('z');
        $losung = $xml_data->Losungen[$index];
        ?>
            <p style="clear: right; padding-bottom: .8em">
                <?php 
        echo $losung->Losungstext;
        ?>
<br>
                <small style="float: right""><?php 
        echo $losung->Losungsvers;
        ?>
</small>
            </p>
            <p style="clear: right; padding-bottom: .8em;">
                <?php 
        echo $losung->Lehrtext;
        ?>
<br>
                <small style="float: right""><?php 
        echo $losung->Lehrtextvers;
        ?>
</small>
            </p>
            <p>
                <small>
                    <a href="http://herrnhuter.de" target="blank">
                        © Evangelische Brüder-Unität – Herrnhuter Brüdergemeine
                    </a>
                    Weitere Infos unter: <a target="blank" 
href="http://losung.de">www.losung.de</a>
                </small>
            </p>
        <?php 
    }
function extractFile($zip_file, $file_in_zip)
{
    global $base_tmp_upgrade_dir;
    if (empty($base_tmp_upgrade_dir)) {
        $base_tmp_upgrade_dir = $GLOBALS['sugar_config']['upload_dir'] . "upgrades/temp";
    }
    $my_zip_dir = mk_temp_dir($base_tmp_upgrade_dir);
    unzip_file($zip_file, $file_in_zip, $my_zip_dir);
    return "{$my_zip_dir}/{$file_in_zip}";
}
Example #11
0
function extractFile($zip_file, $file_in_zip)
{
    global $base_tmp_upgrade_dir;
    if (empty($base_tmp_upgrade_dir)) {
        $base_tmp_upgrade_dir = sugar_cached("upgrades/temp");
    }
    $my_zip_dir = mk_temp_dir($base_tmp_upgrade_dir);
    unzip_file($zip_file, $file_in_zip, $my_zip_dir);
    return "{$my_zip_dir}/{$file_in_zip}";
}
 public static function extractFile($zip_file, $file_in_zip)
 {
     global $base_tmp_upgrade_dir;
     if (empty($base_tmp_upgrade_dir)) {
         $base_tmp_upgrade_dir = sugar_cached("upgrades/temp");
     }
     $my_zip_dir = mk_temp_dir($base_tmp_upgrade_dir);
     register_shutdown_function('rmdir_recursive', $my_zip_dir);
     unzip_file($zip_file, $file_in_zip, $my_zip_dir);
     return "{$my_zip_dir}/{$file_in_zip}";
 }
Example #13
0
 protected function getDownloadUrl()
 {
     require_once ABSPATH . '/wp-admin/includes/file.php';
     WP_Filesystem();
     global $wp_filesystem;
     $this->skin->feedback('download_envato');
     $package_filename = 'Ultimate_VC_Addons.zip';
     $res = $this->fs_connect(array(WP_CONTENT_DIR));
     if (!$res) {
         return new WP_Error('no_credentials', __("Error! Can't connect to filesystem", 'ultimate_vc'));
     }
     $ultimate_keys = get_option('ultimate_keys');
     $username = trim($ultimate_keys['envato_username']);
     $api_key = trim($ultimate_keys['envato_api_key']);
     $purchase_code = trim($ultimate_keys['ultimate_purchase_code']);
     if (empty($username) || empty($api_key) || empty($purchase_code)) {
         return new WP_Error('no_credentials', __('Error! Envato username, api key and your purchase code are required for downloading updates from Envato marketplace for the Visual Composer.', 'ultimate_vc') . ' ' . __('Visit', 'ultimate_vc') . ' <a href="' . admin_url('options-general.php?page=wpb_vc_settings&tab=updater') . '' . '">' . __('Settings', 'ultimate_vc') . '</a> ' . _('to fix.', 'ultimate_vc'));
     }
     $json = wp_remote_get($this->envatoDownloadPurchaseUrl($username, $api_key, $purchase_code));
     $result = json_decode($json['body'], true);
     if (!isset($result['wp-download']['url'])) {
         return new WP_Error('no_credentials', __('Error! Envato API error' . (isset($result['error']) ? ': ' . $result['error'] : '.'), 'ultimate_vc'));
     }
     $download_file = download_url($result['wp-download']['url']);
     if (is_wp_error($download_file)) {
         $download_file = file_get_contents($result['wp-download']['url']);
         if (is_wp_error($download_file)) {
             return $download_file;
         }
     }
     $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade_tmp/ultimate_envato_package';
     if (is_dir($upgrade_folder)) {
         $wp_filesystem->delete($upgrade_folder);
     } else {
         mkdir($upgrade_folder, 0755);
     }
     $is_unzip = unzip_file($download_file, $upgrade_folder);
     if ($is_unzip) {
         $result = copy($result['wp-download']['url'], $upgrade_folder . '/' . $package_filename);
         if ($result) {
             return $upgrade_folder . '/' . $package_filename;
         } else {
             if (file_exists($upgrade_folder . '/Ultimate_VC_Addons') && is_dir($upgrade_folder . '/Ultimate_VC_Addons')) {
                 $this->Ultimate_Zip($upgrade_folder . '/Ultimate_VC_Addons', $upgrade_folder . '/' . $package_filename);
                 if (is_file($upgrade_folder . '/' . $package_filename)) {
                     return $upgrade_folder . '/' . $package_filename;
                 }
                 return new WP_Error('no_credentials', __('Error while zipping plugin', 'ultimate_vc'));
             }
             return new WP_Error('no_credentials', __('Error while coping zip from Remote server, allow_url_fopen is disabled on your server.', 'ultimate_vc'));
         }
     }
     return new WP_Error('no_credentials', __('Error on unzipping package', 'ultimate_vc'));
 }
Example #14
0
 function unzip($temp_file_addr, $to)
 {
     $filesystem = WP_Filesystem();
     $dounzip = unzip_file($temp_file_addr, $to);
     if (is_wp_error($dounzip)) {
         $error = $dounzip->get_error_code();
         $data = $dounzip->get_error_data($error);
         $this->error($dounzip->get_error_message());
         return false;
     }
     return true;
 }
Example #15
0
 public function edit_action($material_id = null)
 {
     $this->material = new LernmarktplatzMaterial($material_id);
     Pagelayout::setTitle($this->material->isNew() ? _("Neues Material hochladen") : _("Material bearbeiten"));
     if ($this->material['user_id'] && $this->material['user_id'] !== $GLOBALS['user']->id) {
         throw new AccessDeniedException();
     }
     if (Request::submitted("delete") && Request::isPost()) {
         $this->material->pushDataToIndexServers("delete");
         $this->material->delete();
         PageLayout::postMessage(MessageBox::success(_("Ihr Material wurde gelöscht.")));
         $this->redirect("market/overview");
     } elseif (Request::isPost()) {
         $was_new = $this->material->setData(Request::getArray("data"));
         $this->material['user_id'] = $GLOBALS['user']->id;
         $this->material['host_id'] = null;
         $this->material['license'] = "CC BY 4.0";
         if ($_FILES['file']['tmp_name']) {
             $this->material['content_type'] = $_FILES['file']['type'];
             if (in_array($this->material['content_type'], array("application/x-zip-compressed", "application/zip", "application/x-zip"))) {
                 $tmp_folder = $GLOBALS['TMP_PATH'] . "/temp_folder_" . md5(uniqid());
                 mkdir($tmp_folder);
                 unzip_file($_FILES['file']['tmp_name'], $tmp_folder);
                 $this->material['structure'] = $this->getFolderStructure($tmp_folder);
                 rmdirr($tmp_folder);
             } else {
                 $this->material['structure'] = null;
             }
             $this->material['filename'] = $_FILES['file']['name'];
             move_uploaded_file($_FILES['file']['tmp_name'], $this->material->getFilePath());
         }
         if ($_FILES['image']['tmp_name']) {
             $this->material['front_image_content_type'] = $_FILES['image']['type'];
             move_uploaded_file($_FILES['image']['tmp_name'], $this->material->getFrontImageFilePath());
         }
         if (Request::get("delete_front_image")) {
             $this->material['front_image_content_type'] = null;
         }
         $this->material->store();
         //Topics:
         $topics = Request::getArray("tags");
         foreach ($topics as $key => $topic) {
             if (!trim($topic)) {
                 unset($topics[$key]);
             }
         }
         $this->material->setTopics($topics);
         $this->material->pushDataToIndexServers();
         PageLayout::postMessage(MessageBox::success(_("Lernmaterial erfolgreich gespeichert.")));
         $this->redirect("market/details/" . $this->material->getId());
     }
 }
 public function import_seo_settings($file)
 {
     if (!empty($file)) {
         $upload_dir = wp_upload_dir();
         if (!defined('DIRECTORY_SEPARATOR')) {
             define('DIRECTORY_SEPARATOR', '/');
         }
         $p_path = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'wpseo-import' . DIRECTORY_SEPARATOR;
         if (!isset($GLOBALS['wp_filesystem']) || !is_object($GLOBALS['wp_filesystem'])) {
             WP_Filesystem();
         }
         $unzipped = unzip_file($file, $p_path);
         if (!is_wp_error($unzipped)) {
             $filename = $p_path . 'settings.ini';
             if (@is_file($filename) && is_readable($filename)) {
                 $options = parse_ini_file($filename, true);
                 if (is_array($options) && $options !== array()) {
                     $old_wpseo_version = null;
                     if (isset($options['wpseo']['version']) && $options['wpseo']['version'] !== '') {
                         $old_wpseo_version = $options['wpseo']['version'];
                     }
                     foreach ($options as $name => $optgroup) {
                         if ($name === 'wpseo_taxonomy_meta') {
                             $optgroup = json_decode(urldecode($optgroup['wpseo_taxonomy_meta']), true);
                         }
                         // Make sure that the imported options are cleaned/converted on import
                         $option_instance = WPSEO_Options::get_option_instance($name);
                         if (is_object($option_instance) && method_exists($option_instance, 'import')) {
                             $optgroup = $option_instance->import($optgroup, $old_wpseo_version, $options);
                         }
                     }
                     return true;
                 } else {
                     throw new Exception(__('Settings could not be imported:', 'wordpress-seo'));
                 }
                 unset($options, $name, $optgroup);
             } else {
                 throw new Exception(__('Settings could not be imported:', 'wordpress-seo'));
             }
             @unlink($filename);
             @unlink($p_path);
         } else {
             throw new Exception(__('Settings could not be imported:', 'wordpress-seo') . ' ' . sprintf(__('Unzipping failed with error "%s".', 'wordpress-seo'), $unzipped->get_error_message()));
         }
         unset($zip, $unzipped);
         @unlink($file);
     } else {
         throw new Exception(__('Settings could not be imported:', 'wordpress-seo') . ' ' . __('Upload failed.', 'wordpress-seo'));
     }
     return false;
 }
function importThemeForm(){
	if($_FILES){
		WP_Filesystem();
		move_uploaded_file($_FILES["template"]["tmp_name"], THEME_CACHE_DIR."/" . $_FILES["template"]["name"]);
		$nfile = THEME_CACHE_DIR."/" . $_FILES["template"]["name"];
		$folder = THEME_CACHE_DIR.'/'.str_replace('.zip', '', $_FILES["template"]["name"]);
		$unzipit = unzip_file($nfile, $folder);
		$files = WonderWorksHelper::getUTX($folder);
		if($files){
			foreach($files as $file){
				importTemplate($folder.DS.$file,$folder);
			}
		}	
	} else { 
?>
<h2><?php _e('Import a Template','ultimatum');?></h2>
<p></p>
<form action="" method="post"  enctype="multipart/form-data">
		<table class="widefat ult-tables">
			<tbody>
				<tr>
					<th><?php _e('File','ultimatum');?> :</th>
					<td><input type="file" name="template" /></td>
				</tr>
 				<tr class="alternate">
 					<th colspan="2"><?php _e('Options','ultimatum');?></th></tr>
 				<tr>
					<th><?php _e('Template Name','ultimatum');?> :</th>
					<td><input type="text" name="template_name" /><br />
					<?php _e('If you wish to have the imported template with a different name than its original type the name you desire','ultimatum');?></td>
				</tr>
				<tr>
					<th><?php _e('Import Assignments','ultimatum');?> :</th>
					<td>
						<select name="assigners">
						<option value="donot"><?php _e('Do not import layout assignments','ultimatum');?></option>
						<option value="assign"><?php _e('Import layout assignments','ultimatum');?></option>
						</select>
					<br />
					<?php _e('The imported template may have assignmets to post types categories etc. If you want those assignments to be imported set this option so.','ultimatum');?></td>
				</tr>
			</tbody>
		</table>
		<p><input type="submit" value="<?php _e('Import','ultimatum');?>" class="button button-primary"/></p>
</form>

<?php
	}
}
function imagegallery_process_zip_file($file)
{
    global $CFG, $USER, $gallery;
    $tmpdir = random_string(6);
    $fullpath = make_upload_directory($tmpdir);
    $origpath = dirname($file->path);
    if (!unzip_file($file->path, $fullpath)) {
        error(get_string("unzipfileserror", "error"));
    }
    $images = imagegallery_search_images($fullpath);
    if (!empty($images)) {
        foreach ($images as $image) {
            $newpath = $origpath . '/' . basename($image);
            // If file already exists, just skip it.
            if (@file_exists($newpath)) {
                continue;
            }
            $fileinfo = getimagesize($image);
            if (!rename($image, $newpath)) {
                error("Could not move file to new location!");
            }
            $newfile = new stdClass();
            $newfile->galleryid = $file->galleryid;
            $newfile->categoryid = $file->categoryid;
            $newfile->userid = $USER->id;
            $newfile->name = basename($image);
            $newfile->path = $newpath;
            $newfile->size = filesize($newpath);
            $newfile->mime = mimeinfo('type', basename($image));
            $newfile->width = $fileinfo[0];
            $newfile->height = $fileinfo[1];
            $newfile->timecreated = time();
            $newfile->timemodified = time();
            // Check dimensions.
            $gallery->check_dimensions($newfile);
            $newfile->path = $gallery->get_file_path($newpath);
            if (!insert_record("imagegallery_images", $newfile)) {
                @unlink($newpath);
                error("Could not add new file {$file->name} to database!", "{$CFG->wwwroot}/mod/imagegallery/view.php?id={$gallery->cm->id}");
            }
            // Make thumbnail.
            $thumb = $origpath . '/thumb_' . $newfile->name;
            $gallery->make_thumbnail($newpath, $thumb);
        }
    }
    fulldelete($fullpath);
    @unlink($file->path);
}
 public function testunzip_file()
 {
     //execute the method and test if it returns true and verify the if unzipped files exist
     $cache_dir = rtrim($GLOBALS['sugar_config']['cache_dir'], '/\\');
     $files_list = array('config.php', 'config_override.php');
     $file = $cache_dir . '/zipTest.zip';
     //creata a zip file first, to unzip
     if (!file_exists($file)) {
         zip_files_list($file, $files_list);
     }
     $result = unzip_file($file, null, $cache_dir);
     $this->assertTrue($result);
     $this->assertFileExists($cache_dir . '/config.php');
     $this->assertFileExists($cache_dir . '/config_override.php');
     unlink($cache_dir . '/config.php');
     unlink($cache_dir . '/config_override.php');
 }
Example #20
0
 /**
  * @desc Processes a zip file into an object containing the import data.
  * @param $string filename The zip file to be processed.
  * @return object The data.
  */
 function readdata($filename)
 {
     global $CFG;
     set_time_limit(0);
     echo "<h2>Processing Stage</h2>";
     flush();
     //EXTRACTION PROCESS
     echo "Extracting '{$filename}'...";
     flush();
     $unique_code = time();
     $temp_dir = $CFG->dataroot . "/temp/webworkquiz_import/" . $unique_code;
     $this->temp_dir = $temp_dir;
     //failures we cannot handle
     if (!$this->check_and_create_import_dir($unique_code)) {
         error("Could not create temporary directory");
         return;
     }
     if (!is_readable($filename)) {
         error("Could not read uploaded file");
         return;
     }
     if (!copy($filename, "{$temp_dir}/webwork.zip")) {
         error("Could not copy backup file");
         return;
     }
     if (!unzip_file("{$temp_dir}/webwork.zip", '', false)) {
         print "filename: {$filename}<br />tempdir: {$temp_dir} <br />";
         error("Could not unzip file.");
         return;
     }
     echo "Done<br>";
     flush();
     //INITIALIZING VARIABLES
     echo "Initializing Variables...";
     flush();
     $this->questions = array();
     $this->sets = array();
     $this->tempdirs = array();
     $this->counter = 0;
     echo "Done<br>";
     flush();
     //recurse through categories
     $this->process_category_directory($temp_dir, "Default");
     return $this->questions;
 }
Example #21
0
 private function download_and_activate_new_version($zip_url)
 {
     if (!One_And_One_Utility::check_credentials('plugins.php', null)) {
         return false;
     }
     $response_body = One_And_One_Utility::get_remote_response_body($zip_url);
     if (empty($response_body)) {
         return false;
     }
     $zip_file_path = One_And_One_Wizard::get_plugin_dir_path() . 'plugin.zip';
     global $wp_filesystem;
     $wp_filesystem->put_contents($zip_file_path, $response_body, FS_CHMOD_FILE);
     // delete all transient data
     $transience_manager = new One_And_One_Transience_Manager();
     $transience_manager->erase_transient_data();
     $unzip = unzip_file($zip_file_path, WP_PLUGIN_DIR);
     @unlink($zip_file_path);
     activate_plugin(One_And_One_Wizard::get_plugin_file_path());
 }
 protected function extract_zip($file_name = '')
 {
     if (!$file_name) {
         $file_name = $this->get_upload_dir() . self::folder_key . '.zip';
     }
     if (class_exists('ZipArchive')) {
         $zip = new ZipArchive();
         if ($zip->open($file_name) === TRUE) {
             $zip->extractTo($this->get_upload_dir());
             $zip->close();
             $zipfile = true;
         } else {
             $zipfile = false;
         }
     } else {
         WP_Filesystem();
         $zipfile = unzip_file($file_name, $this->get_upload_dir());
     }
     return $zipfile;
 }
Example #23
0
function watupro_modules()
{
    global $wp_filesystem;
    $form_url = "admin.php?page=watupro_modules";
    $form_url = wp_nonce_url($form_url, 'watupro_modules_nonce');
    $output = $error = '';
    $fields = array("module");
    if (!empty($_POST['upload'])) {
        if (get_option('watupro_sandbox_mode')) {
            wp_die("Sorry, this feature is disabled for security reasons");
        }
        // define the module
        if ($_FILES['module']['name'] == 'i.zip') {
            $module = "Intelligence";
        }
        if ($_FILES['module']['name'] == 'reports.zip') {
            $module = "Reporting";
        }
        if (empty($module)) {
            wp_die("Incorrect module file");
        }
        // destination folder
        if ($module == 'Intelligence') {
            $context = WP_PLUGIN_DIR . "/watupro";
        }
        if ($module == 'Reporting') {
            $context = WP_PLUGIN_DIR . "/watupro/modules";
        }
        $form_fields = array("module");
        $method = "";
        if (!watupro_filesystem_init($form_url, $method, $context, $form_fields)) {
            return false;
        }
        $error = unzip_file($_FILES['module']['tmp_name'], $context);
    }
    if (@file_exists(get_stylesheet_directory() . '/watupro/modules.php')) {
        require get_stylesheet_directory() . '/watupro/modules.php';
    } else {
        require WATUPRO_PATH . "/views/modules.php";
    }
}
Example #24
0
 private function _installFrameworkForFirstTime($zipFilePath)
 {
     $fileSystem = $this->_getFileSystem();
     if ($fileSystem == false) {
         return false;
     }
     $pluginDir = $this->_getPluginDir();
     $unzipFileResult = unzip_file($zipFilePath, $pluginDir);
     if ($unzipFileResult instanceof WP_Error) {
         $notificationText = __('Fresh Framework requires wp-content/plugins folder, to be writable, in order to install itself, ', 'zero');
         $notificationText .= __('this could be achieved by setting 775 or 777 permissions to wp-content/plugins folder, ', 'zero');
         $notificationText .= __('please install Fresh Framework plugin, otherwise our theme will not work<br><br>', 'zero');
         $notificationText .= __('Plugin could be found here: ', 'zero') . get_template_directory() . '/install/fresh-framework.zip';
         $this->_addNotification($notificationText);
     } else {
         require_once ABSPATH . '/wp-admin/includes/plugin.php';
         activate_plugin($pluginDir . '/fresh-framework/freshplugin.php');
         header("Refresh:0");
         die;
     }
 }
 /**
  * Download translation files from woocommerce repo.
  *
  * @global \WP_Filesystem_Base $wp_filesystem
  *
  * @param string $locale locale
  * @param string $name   langauge name
  *
  * @return bool true when the translation is downloaded successfully
  *
  * @throws \RuntimeException on errors
  */
 public static function download($locale, $name)
 {
     /* Check if already downlaoded */
     if (static::isDownloaded($locale)) {
         return true;
     }
     /* Check if we can download */
     if (!static::isAvaliable($locale)) {
         $notAvaliable = sprintf(__('Woocommerce translation %s can not be found in : <a href="%2$s">%2$s</a>', 'woo-poly-integration'), sprintf('%s(%s)', $name, $locale), static::getRepoUrl());
         throw new \RuntimeException($notAvaliable);
     }
     /* Download the language pack */
     $cantDownload = sprintf(__('Unable to download woocommerce translation %s from : <a href="%2$s">%2$s</a>'), sprintf('%s(%s)', $name, $locale), static::getRepoUrl());
     $response = wp_remote_get(sprintf('%s/%s.zip', static::getRepoUrl(), $locale), array('sslverify' => false, 'timeout' => 200));
     if (!is_wp_error($response) && ($response['response']['code'] >= 200 && $response['response']['code'] < 300)) {
         /* Initialize the WP filesystem, no more using 'file-put-contents' function */
         global $wp_filesystem;
         if (empty($wp_filesystem)) {
             require_once ABSPATH . '/wp-admin/includes/file.php';
             WP_Filesystem();
         }
         $uploadDir = wp_upload_dir();
         $file = trailingslashit($uploadDir['path']) . $locale . '.zip';
         /* Save the zip file */
         if (!$wp_filesystem->put_contents($file, $response['body'], FS_CHMOD_FILE)) {
             throw new \RuntimeException($cantDownload);
         }
         /* Unzip the file to wp-content/languages/woocommerce directory */
         $dir = trailingslashit(WP_LANG_DIR) . 'woocommerce/';
         $unzip = unzip_file($file, $dir);
         if (true !== $unzip) {
             throw new \RuntimeException($cantDownload);
         }
         /* Delete the package file */
         $wp_filesystem->delete($file);
         return true;
     } else {
         throw new \RuntimeException($cantDownload);
     }
 }
 /**
  * Wann soll das ausgeführt werden?
  * * Am 28. Dezember des Vorjahres (via cron -> Failures should be reported via email)
  * * Direkt nach Installation des Plugins (activate?)
  * * Manuell im Backend (Knopf im Widget? Optionen?)
  * 
  * @param int $year
  */
 public function doUpdate($date)
 {
     global $wp_filesystem;
     $download_url = $this->_getDownloadUrl($date);
     $this->_setup_WP_Filesystem($download_url);
     // 1) Downlaod File
     $tmpFile = download_url($download_url);
     if (is_wp_error($tmpFile)) {
         return $tmpFile;
     }
     // 2) Unzip to tempDir
     $tempDir = $this->alternate_dir . '/update-losungen-' . time() . '/';
     if (!is_dir($tempDir)) {
         $wp_filesystem->mkdir($tempDir);
     }
     $ret = unzip_file($tmpFile, $tempDir);
     if (is_wp_error($ret)) {
         return $ret;
     }
     // 3) Search any XML File!
     $losungenFile = '';
     foreach (list_files($tempDir) as $file) {
         if (substr($file, -4) == '.xml') {
             $losungenFile = $file;
             break;
         }
     }
     // TODO Syntax Validation of XML file
     if (!$losungenFile) {
         return new WP_Error(17000, 'In der Zip-Datei war keine Losungs-XML! (' . $download_url . ')');
     }
     // 4) Put in the right place
     if (!$wp_filesystem->move($losungenFile, $this->xmlFileName('', $date), true)) {
         return new WP_Error(17000, 'Die XML-Datei konnte nicht geschrieben werden! (' . $this->xmlFileName('', $date) . ')');
     }
     // 5) Finally, clean up
     $wp_filesystem->delete($tmpFile);
     $wp_filesystem->delete($tempDir, true);
     return file_exists($this->xmlFileName('', $date));
 }
 public function upgradeFilterFromEnvato($reply, $package, $updater)
 {
     global $wp_filesystem;
     if (isset($updater->skin->plugin) && $updater->skin->plugin === TM_PLUGIN_SLUG || isset($updater->skin->plugin_info) && isset($updater->skin->plugin_info['Name']) && $updater->skin->plugin_info['Name'] === $this->title) {
         $updater->strings['download_envato'] = __('Downloading package from envato market...', TM_EPO_TRANSLATION);
         $updater->skin->feedback('download_envato');
         $package_filename = 'woocommerce-tm-extra-product-options.zip';
         $res = $updater->fs_connect(array(WP_CONTENT_DIR));
         if (!$res) {
             return new WP_Error('no_credentials', __("Error! Can't connect to filesystem", TM_EPO_TRANSLATION));
         }
         $username = get_option('tm_epo_envato_username');
         $api_key = get_option('tm_epo_envato_apikey');
         $purchase_code = get_option('tm_epo_envato_purchasecode');
         if (!TM_EPO_LICENSE()->check_license()) {
             return new WP_Error('no_credentials', __('To receive automatic updates license activation is required. Please visit <a href="' . admin_url('admin.php?page=wc-settings&tab=' . TM_ADMIN_SETTINGS_ID) . '">' . 'Settings</a> to activate WooCommerce Extra Product Options.', TM_EPO_TRANSLATION));
         }
         $json = wp_remote_get($this->envatoDownloadPurchaseUrl($username, $api_key, $purchase_code));
         $result = json_decode($json['body'], true);
         if (!isset($result['download-purchase']['download_url'])) {
             return new WP_Error('no_credentials', __('Error! Envato API error' . (isset($result['error']) ? ': ' . $result['error'] : '.'), TM_EPO_TRANSLATION));
         }
         $download_file = download_url($result['download-purchase']['download_url']);
         if (is_wp_error($download_file)) {
             return $download_file;
         }
         $upgrade_folder = $wp_filesystem->wp_content_dir() . 'uploads/woocommerce-tm-extra-product-options-envato-package';
         if (is_dir($upgrade_folder)) {
             $wp_filesystem->delete($upgrade_folder);
         }
         $result = unzip_file($download_file, $upgrade_folder);
         if ($result && is_file($upgrade_folder . '/' . $package_filename)) {
             return $upgrade_folder . '/' . $package_filename;
         }
         return new WP_Error('no_credentials', __('Error on unzipping package', TM_EPO_TRANSLATION));
     }
     return $reply;
 }
Example #28
0
 /**
  * Export app sources for PhoneGap CLI compilation
  * 
  * ## OPTIONS
  * 
  * <app_id_or_slug> : Application ID or Application slug
  * 
  * <target_directory> : Target directory where the export files will be copied
  * 
  * <export_type> : (Optionnal) Export type can be "phonegap-cli" (default if not provided) or "phonegap-build"
  * 
  * ## EXAMPLES
  * 
  *     PhoneGap CLI export : wp wpak export 123 /target/directory/
  *     PhoneGap Build export : wp wpak export 123 /target/directory/ "phonegap-build"
  *
  * @synopsis <app_id> <target_directory> [<export_type>]
  * 
  * @subcommand export
  */
 public function export($args, $assoc_args)
 {
     list($app_id_or_slug, $target_directory, $export_type) = $args;
     if (empty($export_type)) {
         $export_type = "phonegap-cli";
     }
     if (!in_array($export_type, array("phonegap-cli", "phonegap-build"))) {
         WP_CLI::error('Unknown export type "' . $export_type . '"');
     }
     //Check that the given app exists :
     if (WpakApps::app_exists($app_id_or_slug)) {
         if (is_dir($target_directory)) {
             WP_CLI::line('Export app "' . $app_id_or_slug . '" to ' . $target_directory);
             $app_id = WpakApps::get_app_id($app_id_or_slug);
             $answer = WpakBuild::build_app_sources($app_id, $export_type);
             if ($answer['ok'] === 1) {
                 $zip_file = $answer['export_full_name'];
                 WP_CLI::line("App sources zipped to " . $zip_file);
                 WP_CLI::line("Extract zip to destination");
                 //Extract to target directory :
                 WP_Filesystem();
                 $result = unzip_file($zip_file, $target_directory);
                 if (!is_wp_error($result)) {
                     WP_CLI::success("App sources extracted successfully to {$target_directory}");
                 } else {
                     WP_CLI::line('Could not extract ZIP export to : ' . $target_directory);
                     WP_CLI::error($result->get_error_message());
                 }
             } else {
                 WP_CLI::error('Export error : ' . $answer['msg']);
             }
         } else {
             WP_CLI::error('Destination directory not found : ' . $target_directory);
         }
     } else {
         WP_CLI::error('Application "' . $app_id_or_slug . '" not found');
     }
 }
 /**
  * Unpack a compressed package file.
  * @param  string $package Full path to the package file.
  * @return string|WP_Error The path to the unpacked contents, or a {@see WP_Error} on failure.
  */
 public static function unpack_package($package)
 {
     global $wp_filesystem;
     // WordPress Filesystem Abstraction.
     require_once ABSPATH . 'wp-admin/includes/file.php';
     if (!$wp_filesystem || !is_object($wp_filesystem)) {
         WP_Filesystem();
     }
     $temp_folder = get_temp_dir() . basename(AC_ICONFONT_DIR);
     // Clean up temp directory
     if ($wp_filesystem->is_dir($temp_folder)) {
         $wp_filesystem->delete($temp_folder, true);
     }
     // Unzip package to temp directory
     $result = unzip_file($package, $temp_folder);
     if (is_wp_error($result)) {
         $wp_filesystem->delete($temp_folder, true);
         if ('incompatible_archive' == $result->get_error_code()) {
             return new WP_Error('incompatible_archive', __('The package could not be extracted.', 'axiscomposer'), $result->get_error_data());
         }
         return $result;
     }
 }
 public function install($name, $file)
 {
     if (!defined('FS_METHOD')) {
         define('FS_METHOD', 'direct');
     }
     WP_Filesystem();
     $params = array('key' => $this->key, 'name' => $name, 'site' => get_site_url());
     $download_file = download_url("{$this->get_url()}/download?" . http_build_query($params));
     if (is_wp_error($download_file)) {
         $errorMsg = $download_file->get_error_messages();
         throw new Exception(__('There was an error downloading your premium extension') . ' - ' . $errorMsg[0]);
     }
     $result = unzip_file($download_file, EXTENSIONS_DIR);
     if (is_wp_error($result)) {
         $errorMsg = $result->get_error_messages();
         if ($errorMsg[0] == "Incompatible Archive.") {
             $errorMsg[0] = file_get_contents($download_file);
         }
         unlink($download_file);
         throw new Exception(__('There was an error installing your premium extension') . ' - ' . $errorMsg[0]);
     }
     unlink($download_file);
     $extensions = get_option('backup-to-dropbox-premium-extensions');
     $extensions[$name] = $file;
     update_option('backup-to-dropbox-premium-extensions', $extensions);
 }