Skip to content

Commit

Permalink
The use of separate filesystem method within the framework - fixes fo…
Browse files Browse the repository at this point in the history
…r options-builder #185
  • Loading branch information
alexxgermann committed Sep 19, 2016
1 parent aea3968 commit 254a3bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
27 changes: 11 additions & 16 deletions runway-framework/framework/includes/options-builder/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@

// edit page
case 'edit-page': {
if(!function_exists('WP_Filesystem'))
require_once(ABSPATH . 'wp-admin/includes/file.php');
WP_Filesystem();
global $wp_filesystem;
$wp_filesystem = get_runway_wp_filesystem();

$page_id = $_GET['page_id'];

if ( file_exists( $pages_dir.$page_id.'.json' ) ) {
$page_json = $wp_filesystem->get_contents( $pages_dir.$page_id.'.json' );
$page_json = $wp_filesystem->get_contents( runway_prepare_path( $pages_dir . $page_id . '.json' ) );
$page = json_decode( $page_json, true );

$page = $apm->inputs_decode( $page );
Expand All @@ -60,14 +57,11 @@
} break;

case 'confirm-remove-page':{
if(!function_exists('WP_Filesystem'))
require_once(ABSPATH . 'wp-admin/includes/file.php');
WP_Filesystem();
global $wp_filesystem;
$wp_filesystem = get_runway_wp_filesystem();
$page_id = $_GET['page_id'];

if ( file_exists( $pages_dir.$page_id.'.json' ) ) {
$page_json = $wp_filesystem->get_contents( $pages_dir.$page_id.'.json' );
$page_json = $wp_filesystem->get_contents( runway_prepare_path( $pages_dir . $page_id . '.json' ) );
$page = json_decode( $page_json, true );

$item_confirm = 'option page';
Expand All @@ -89,15 +83,12 @@
} break;

case 'duplicate-page': {
if(!function_exists('WP_Filesystem'))
require_once(ABSPATH . 'wp-admin/includes/file.php');
WP_Filesystem();
global $wp_filesystem;
$wp_filesystem = get_runway_wp_filesystem();

$page_id = $_GET['page_id'];

if ( file_exists( $pages_dir.$page_id.'.json' ) ) {
$page_json = $wp_filesystem->get_contents( $pages_dir.$page_id.'.json' );
$page_json = $wp_filesystem->get_contents( runway_prepare_path( $pages_dir . $page_id . '.json' ) );
$page = json_decode( $page_json );

$page->settings->page_id = time();
Expand All @@ -108,7 +99,11 @@
$page->settings->alias = $alias_;

$page_json = json_encode( $page );
$wp_filesystem->put_contents($pages_dir.$page->settings->page_id.'.json', $page_json, FS_CHMOD_FILE);
$wp_filesystem->put_contents(
runway_prepare_path( $pages_dir . $page->settings->page_id . '.json' ),
$page_json,
FS_CHMOD_FILE
);

$pages = $apm->get_pages_list();
include_once 'views/list-pages.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ public function check_is_options_page_alias_unique_ajax() {
}

public function save_option_page() {
if(!function_exists('WP_Filesystem'))
require_once(ABSPATH . 'wp-admin/includes/file.php');
WP_Filesystem();
global $wp_filesystem;
$wp_filesystem = get_runway_wp_filesystem();

$json_page = $_REQUEST['json_form'];
// $new_page_id = $_REQUEST['page_id'];
Expand Down Expand Up @@ -126,7 +123,7 @@ public function save_option_page() {
}

if ( file_exists( "{$pages_dir}{$page_id}.json" ) ) {
$old = $wp_filesystem->get_contents( "{$pages_dir}{$page_id}.json" );
$old = $wp_filesystem->get_contents( runway_prepare_path( "{$pages_dir}{$page_id}.json" ) );
}
else
$old = '';
Expand Down Expand Up @@ -195,7 +192,7 @@ public function save_option_page() {
}
}
if( IS_CHILD && get_template() == 'runway-framework') {
$wp_filesystem->put_contents("{$pages_dir}{$page_id}.json", $new, FS_CHMOD_FILE);
$wp_filesystem->put_contents( runway_prepare_path( "{$pages_dir}{$page_id}.json" ), $new, FS_CHMOD_FILE);
}

$message = '<div id="message" class="updated below-h2"><p>'. __( 'Page saved.', 'runway' ) .'</div>';
Expand Down Expand Up @@ -297,17 +294,19 @@ function duplicate_page( $page_id, $pages_dir ) {
}

function reset_to_default( $pages_dir, $page_id ) {
if(!function_exists('WP_Filesystem'))
require_once(ABSPATH . 'wp-admin/includes/file.php');
WP_Filesystem();
global $wp_filesystem, $shortname;

$page = json_decode( $wp_filesystem->get_contents( $pages_dir.$page_id.'.json' ) );
global $shortname;
$wp_filesystem = get_runway_wp_filesystem();

$page = json_decode( $wp_filesystem->get_contents( runway_prepare_path( $pages_dir . $page_id . '.json' ) ) );

$settings = get_settings_json();
$json_prefix = isset($settings['ThemeID']) ? $settings['ThemeID'] . '_' : $shortname;
$json_dir = get_stylesheet_directory() . '/data';
$json = json_decode($wp_filesystem->get_contents($json_dir . '/' . $json_prefix.$page->settings->alias.'.json'), true);
$json = json_decode(
$wp_filesystem->get_contents( runway_prepare_path( $json_dir . '/' . $json_prefix . $page->settings->alias . '.json' ) ),
true
);

foreach($page->elements as $elm) {
if(isset($elm->template) && $elm->template == 'field' && isset($elm->type)) {
Expand All @@ -332,10 +331,7 @@ function reset_to_default( $pages_dir, $page_id ) {
}

function get_pages_list() {
if(!function_exists('WP_Filesystem'))
require_once(ABSPATH . 'wp-admin/includes/file.php');
WP_Filesystem();
global $wp_filesystem;
$wp_filesystem = get_runway_wp_filesystem();

$error_flag = true;
$error_message = __( '<b>Error</b>: "data" and it\'s sub-folder "pages" must both exists and be writable. Please check these folders and their permissions in your child theme.', 'runway' );
Expand Down Expand Up @@ -366,7 +362,7 @@ function get_pages_list() {
$pages = array();

foreach ( $page_files as $page_file ) {
$json = $wp_filesystem->get_contents( $this->pages_dir . $page_file );
$json = $wp_filesystem->get_contents( runway_prepare_path( $this->pages_dir . $page_file ) );
$pages[] = json_decode( $json );
}
$sorted_list = sort_pages_list($pages);
Expand Down

0 comments on commit 254a3bf

Please sign in to comment.