Skip to content

Commit

Permalink
Refactoring for themes-manager (admin.php, load.php, object.php, sett…
Browse files Browse the repository at this point in the history
…ings-object.php)
  • Loading branch information
alexxgermann committed Oct 11, 2016
1 parent 2fbbc68 commit c7def88
Show file tree
Hide file tree
Showing 4 changed files with 591 additions and 487 deletions.
147 changes: 80 additions & 67 deletions runway-framework/framework/includes/themes-manager/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,166 +7,179 @@
add_filter( 'filesystem_method', 'direct_filesystem_method' );

$required = '<em class="required">' . __( 'Required', 'runway' ) . '</em>';
$_data = $developer_tools->data;
$_data = $developer_tools->data;

$themes_path = explode( '/', get_template_directory() );
unset( $themes_path[count( $themes_path ) - 1] );
unset( $themes_path[ count( $themes_path ) - 1 ] );
$themes_path = implode( '/', $themes_path );

wp_register_script('themes-manager-themes', FRAMEWORK_URL.'framework/includes/themes-manager/js/themes.js');
wp_enqueue_script('themes-manager-themes');
wp_register_script( 'themes-manager-themes', FRAMEWORK_URL . 'framework/includes/themes-manager/js/themes.js' );
wp_enqueue_script( 'themes-manager-themes' );

$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
switch ( $action ) {
case 'delete-package':{
case 'delete-package': {
$package = isset( $_REQUEST['package'] ) ? $_REQUEST['package'] : '';
$name = isset( $_REQUEST['name'] ) ? $_REQUEST['name'] : '';
$name = isset( $_REQUEST['name'] ) ? $_REQUEST['name'] : '';
if ( $name != '' && $package != '' ) {
$alone_theme_file = "$name-($package).a.zip";
$child_theme_file = "$name-($package).c.zip";
$download_dir = $developer_tools->themes_path."/$name/download/";
if ( unlink( $download_dir.$alone_theme_file ) ) {
$download_dir = $developer_tools->themes_path . "/$name/download/";
if ( unlink( $download_dir . $alone_theme_file ) ) {
// out message
}

if ( unlink( $download_dir.$child_theme_file ) ) {
if ( unlink( $download_dir . $child_theme_file ) ) {
// out message
}
}
} break;
}
break;

case 'delete-package-all':{
case 'delete-package-all': {
$theme_name = isset( $_REQUEST['name'] ) ? $_REQUEST['name'] : '';
if ( $theme_name != '') {
$history = $developer_tools->get_history($theme_name);
$current_package = array_shift($history);
foreach ( $history as $ts => $info ) {
unset( $history[$ts] );
if ( file_exists( $this->themes_path . "/{$theme_name}/download/".$info['c_file'] ) )
unlink( $this->themes_path . "/{$theme_name}/download/".$info['c_file'] );
if ( file_exists( $this->themes_path . "/{$theme_name}/download/".$info['a_file'] ) )
unlink( $this->themes_path . "/{$theme_name}/download/".$info['a_file'] );
if ( $theme_name != '' ) {
$history = $developer_tools->get_history( $theme_name );
$current_package = array_shift( $history );
foreach ( $history as $ts => $info ) {
unset( $history[ $ts ] );
if ( file_exists( $this->themes_path . "/{$theme_name}/download/" . $info['c_file'] ) ) {
unlink( $this->themes_path . "/{$theme_name}/download/" . $info['c_file'] );
}
if ( file_exists( $this->themes_path . "/{$theme_name}/download/" . $info['a_file'] ) ) {
unlink( $this->themes_path . "/{$theme_name}/download/" . $info['a_file'] );
}
}
}
} break;
}
}
break;

}

switch ( $this->navigation ) {
case 'do-package': {
case 'do-package': {

if ( isset( $_REQUEST['name'] ) ) {
$vals['developer_tools'] = $developer_tools;
$vals['developer_tools'] = $developer_tools;
$vals['Themes_Manager_Admin'] = $developer_tools;
$this->view( 'download', false, $vals );
} else {
echo 'oops...';
}
} break;
}
break;

case 'do-download': {
case 'do-download': {
$theme_settings = $developer_tools->load_settings( $_REQUEST['name'] );
$history = $theme_settings['History'];
$history = $theme_settings['History'];

$vals['developer_tools'] = $developer_tools;
$vals['developer_tools'] = $developer_tools;
$vals['Themes_Manager_Admin'] = $developer_tools;
$this->view( 'download', false, $vals );
} break;
}
break;

case 'duplicate-theme': {
case 'duplicate-theme': {
/* under construction */
if ( isset( $_REQUEST['name'] ) && isset( $_REQUEST['new_name'] ) ) {
$options = $developer_tools->make_theme_copy( $_REQUEST['name'], $_REQUEST['new_name'] );

$link = admin_url('admin.php?page=themes&navigation=edit-theme&name='.$_REQUEST['new_name']);
echo '<script type="text/javascript">window.location = "'. esc_url_raw($link) .'";</script>';
$link = admin_url( 'admin.php?page=themes&navigation=edit-theme&name=' . $_REQUEST['new_name'] );
echo '<script type="text/javascript">window.location = "' . esc_url_raw( $link ) . '";</script>';
}
} break;
}
break;

case 'edit-theme': {
case 'edit-theme': {
$developer_tools->mode = 'edit';

if ( isset( $_REQUEST['save'] ) ) {
$post = stripslashes_deep( $_POST['theme_options'] );
$post = stripslashes_deep( $_POST['theme_options'] );
$errors = $developer_tools->validate_theme_settings( $post );
if ( count( $errors ) ) {
$options = $post;
$this->view( 'theme-conf', false, array('errors'=>$errors) );
$this->view( 'theme-conf', false, array( 'errors' => $errors ) );
} else {
$options = $developer_tools->build_and_save_theme( $post, false );

if ( $post['Folder'] != $post['old_folder_name'] ) {
update_option( 'stylesheet', $post['Folder'] );
}

$ts = time();
$history = $developer_tools->get_history( $options['Folder'] );
$ts = time();
$history = $developer_tools->get_history( $options['Folder'] );
$alone_package_download_url = $developer_tools->build_alone_theme( $options['Folder'], $ts );
$child_package_download_url = $developer_tools->build_child_package( $options['Folder'], $ts );
$developer_tools->make_package_info_from_ts( $options['Folder'], $ts );

$link = admin_url('admin.php?page=themes');
echo '<script type="text/javascript">window.location = "'. esc_url_raw($link).'";</script>';
$link = admin_url( 'admin.php?page=themes' );
echo '<script type="text/javascript">window.location = "' . esc_url_raw( $link ) . '";</script>';
}
} else {
$this->view( 'theme-conf' );
}
} break;
}
break;

case 'delete-theme': {
case 'delete-theme': {

if ( isset( $_REQUEST['confirm'] ) ) {
if ( isset( $_REQUEST['name'] ) && $_REQUEST['name'] != 'runway' ) {
$developer_tools->delete_child_theme( $_REQUEST['name'] );
}

require_once 'views/themes-list.php';
}
else {
require_once __DIR__ . '/views/themes-list.php';
} else {
if ( isset( $_REQUEST['name'] ) ) {
$del_theme_info = rw_get_theme_data( $themes_path.'/'.$_REQUEST['name'] );
include_once 'views/del-theme-confirmation.php';
$del_theme_info = rw_get_theme_data( $themes_path . '/' . $_REQUEST['name'] );
include_once __DIR__ . '/views/del-theme-confirmation.php';
}
}
} break;
}
break;

case 'new-theme': {
case 'new-theme': {
$developer_tools->mode = 'new';

if ( isset( $_POST['theme_options'] ) ) {
$post = stripslashes_deep( $_POST['theme_options'] );
$post = stripslashes_deep( $_POST['theme_options'] );
$errors = $developer_tools->validate_theme_settings( $post );
if ( count( $errors ) ) {
$options = $post;
$this->view( 'theme-conf' );
} else {
$options = $developer_tools->build_and_save_theme( $post );
require_once 'views/themes-list.php';
require_once __DIR__ . '/views/themes-list.php';
}
} else {
$this->view( 'theme-conf' );
}
} break;
}
break;

case 'list-runway-themes': { }
case 'list-runway-themes': {
}

case 'confirm-del-package':{
$name = $_REQUEST['name'];
case 'confirm-del-package': {
$name = $_REQUEST['name'];
$package = isset( $_REQUEST['package'] ) ? $_REQUEST['package'] : '';
if ($package !== 'all') {
if ( $package !== 'all' ) {
$alone_theme_file = "$name-($package).a.zip";
$child_theme_file = "$name-($package).c.zip";
$package_info = $developer_tools->make_package_info_from_ts( $name, $package );
$package_info = $developer_tools->make_package_info_from_ts( $name, $package );
}
include_once 'views/del-package-confirmation.php';
} break;
include_once __DIR__ . '/views/del-package-confirmation.php';
}
break;

case 'confirm-del-packages-all':{
case 'confirm-del-packages-all': {
$name = $_REQUEST['name'];
include_once 'views/del-packages-confirmation-all.php';
} break;

default: {
require_once 'views/themes-list.php';
} break;
include_once __DIR__ . '/views/del-packages-confirmation-all.php';
}
break;

default: {
require_once __DIR__ . '/views/themes-list.php';
}
break;
}
?>
Loading

0 comments on commit c7def88

Please sign in to comment.