Skip to content

Commit

Permalink
Push new updates to installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Jackson committed Nov 3, 2014
1 parent c42a4f3 commit 874fb9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 108 deletions.
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: http://www.formidablepropdfextended.com
Tags: formidable, pro, pdf, extended, automation, attachment
Requires at least: 3.9
Tested up to: 3.9.1
Stable tag: 1.5.3
Stable tag: 1.5.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -79,6 +79,9 @@ All FAQs can be [viewed on the Formidable Pro PDF Extended website](http://formi

== Changelog ==

= 1.5.4 =
* Fixed up initialisation over FTP/SSH

= 1.5.3 =
* Fixed up PHP notices when form fields are empty in PDF

Expand Down
130 changes: 25 additions & 105 deletions installation-update-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

class FPPDF_InstallUpdater
{
private static $directory = FP_PDF_PLUGIN_DIR;
private static $template_directory = FP_PDF_TEMPLATE_LOCATION;
private static $directory = FP_PDF_PLUGIN_DIR;
private static $template_directory = FP_PDF_TEMPLATE_LOCATION;
private static $template_save_directory = FP_PDF_SAVE_LOCATION;
private static $template_font_directory = FP_PDF_FONT_LOCATION;

Expand All @@ -36,24 +36,15 @@ public function install()
public static function update_file_paths()
{
global $wp_filesystem;
/*
* We need to set up some filesystem compatibility checkes to work with the different server file management types
* Most notably is the FTP options, but SSH may be effected too
*/

if($wp_filesystem->method === 'ftpext' || $wp_filesystem->method === 'ftpsockets')
{
/*
* Assume FTP is rooted to the Wordpress install
*/
$base_directory = self::get_base_directory();

$directory = str_replace(ABSPATH, $base_directory, $directory);
$template_directory = str_replace(ABSPATH, $base_directory, $template_directory);
$template_save_directory = str_replace(ABSPATH, $base_directory, $template_save_directory);
$template_font_directory = str_replace(ABSPATH, $base_directory, $template_font_directory);

}
/*
* Assume FTP is rooted to the Wordpress install
*/
self::$directory = self::get_base_directory(FP_PDF_PLUGIN_DIR);
self::$template_directory = self::get_base_directory(FP_PDF_TEMPLATE_LOCATION);
self::$template_save_directory = self::get_base_directory(FP_PDF_SAVE_LOCATION);
self::$template_font_directory = self::get_base_directory(FP_PDF_FONT_LOCATION);

}

/**
Expand All @@ -63,8 +54,7 @@ public function pdf_extended_activate()
{
/*
* Initialise the Wordpress Filesystem API
*/

*/
ob_start();
if(FPPDF_Common::initialise_WP_filesystem_API(array('FP_PDF_DEPLOY'), 'fp-pdf-extended-filesystem') === false)
{
Expand All @@ -74,7 +64,7 @@ public function pdf_extended_activate()
exit;
}
ob_end_clean();

/*
* If we got here we should have $wp_filesystem available
*/
Expand All @@ -86,14 +76,16 @@ public function pdf_extended_activate()
*/
self::update_file_paths();



/**
* If FP_PDF_TEMPLATE_LOCATION already exists then we will remove the old template files so we can redeploy the new ones
*/

if(FP_PDF_DEPLOY === true && $wp_filesystem->exists(self::$template_directory))
{
/* read all file names into array and unlink from active theme template folder */
foreach(glob(self::$directory.'templates/*.php') as $file) {
foreach(glob(PDF_PLUGIN_DIR . 'templates/*.php') as $file) {
$path_parts = pathinfo($file);
if($wp_filesystem->exists(self::$template_directory.$path_parts['basename']))
{
Expand Down Expand Up @@ -252,7 +244,7 @@ private static function install_fonts($directory, $template_directory, $fonts_lo
*/

/* read all file names into array and unlink from active theme template folder */
foreach(glob($fonts_location.'*.[tT][tT][fF]') as $file) {
foreach(glob(FP_PDF_FONT_LOCATION.'*.[tT][tT][fF]') as $file) {
$path_parts = pathinfo($file);

/*
Expand Down Expand Up @@ -514,22 +506,13 @@ public function do_theme_switch($previous_pdf_path, $current_pdf_path)
*/
global $wp_filesystem;

/*
* We need to set up some filesystem compatibility checkes to work with the different server file management types
* Most notably is the FTP options, but SSH may be effected too
*/

if($wp_filesystem->method === 'ftpext' || $wp_filesystem->method === 'ftpsockets')
{
/*
* Assume FTP is rooted to the Wordpress install
*/
$base_directory = self::get_base_directory();

$previous_pdf_path = str_replace(ABSPATH, $base_directory, $previous_pdf_path);
$current_pdf_path = str_replace(ABSPATH, $base_directory, $current_pdf_path);

}
/*
* Assume FTP is rooted to the Wordpress install
*/
$previous_pdf_path = self::get_base_directory($previous_pdf_path);
$current_pdf_path = self::get_base_directory($current_pdf_path);


if($wp_filesystem->is_dir($previous_pdf_path))
{
Expand Down Expand Up @@ -592,47 +575,6 @@ public function pdf_extended_copy_directory( $source, $destination, $copy_base =
}
}

private static function check_access_path($directory, $file_path, $directory_list)
{
global $wp_filesystem;

//$directory = false;
foreach($directory_list as $name => $data)
{
/*
* Check if one of the file/folder names matches what is in $file_path, make sure it is a directory and
* the name has a value
*/
$match = array_search($name, $file_path);
if((strlen($name) > 0) && ($match !== false) && ((int) $data['isdir'] === 1) )
{

/*
* We have a match but it could be fake
* Look inside the target folder and see if the next folder in $file_path can be found
* If it can we will assume it is the correct path
*/
if(isset($file_path[$match+1]))
{

$next_match = $file_path[$match+1];
$directory_list2 = $wp_filesystem->dirlist('/'.$name.'/');

if(isset($directory_list2[$next_match]) && (int) $directory_list2[$next_match]['isdir'] === 1)
{
return self::merge_path($file_path, $match);
}

}
else
{
return self::merge_path($file_path, $match);
}
}
}
return $directory;
}

/*
* Merge the path array back together from the matched key
*/
Expand All @@ -645,32 +587,10 @@ private static function merge_path($file_path, $key)
* Get the base directory for the current filemanagement type
* In this case it is FTP but may be SSH
*/
private static function get_base_directory()
private static function get_base_directory($path = '')
{
global $wp_filesystem;

/*
* Assume FTP is rooted to the Wordpress install
*/
$directory = '/';

/*
* Test if the FTP is below the Wordpress base by sniffing the base directory
*/
$directory_list = $wp_filesystem->dirlist('/');

/*
* Use the ABSPATH to compare the directory structure
*/
$file_path = array_filter(explode('/', ABSPATH ));

/*
* Rekey the array
*/
$file_path = array_values($file_path);

return self::check_access_path($directory, $file_path, $directory_list);

global $wp_filesystem;
return str_replace(ABSPATH, $wp_filesystem->abspath(), $path);
}

}
4 changes: 2 additions & 2 deletions pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin Name: Formidable Pro PDF Extended
Plugin URI: http://www.formidablepropdfextended.com
Description: Formidable Pro PDF Extended allows you to save/view/download a PDF from the front- and back-end, and automate PDF creation on form submission. Our Business Plus package also allows you to overlay field onto an existing PDF.
Version: 1.5.3
Version: 1.5.4
Author: Blue Liquid Designs
Author URI: http://www.blueliquiddesigns.com.au
Expand Down Expand Up @@ -33,7 +33,7 @@
/*
* Define our constants
*/
if(!defined('FP_PDF_EXTENDED_VERSION')) { define('FP_PDF_EXTENDED_VERSION', '1.5.2'); }
if(!defined('FP_PDF_EXTENDED_VERSION')) { define('FP_PDF_EXTENDED_VERSION', '1.5.4'); }
if(!defined('FP_PDF_EXTENDED_SUPPORTED_VERSION')) { define('FP_PDF_EXTENDED_SUPPORTED_VERSION', '1.07.01'); }
if(!defined('FP_PDF_EXTENDED_WP_SUPPORTED_VERSION')) { define('FP_PDF_EXTENDED_WP_SUPPORTED_VERSION', '3.6'); }

Expand Down

0 comments on commit 874fb9a

Please sign in to comment.