Skip to content

Commit

Permalink
Avoid global variables, use instance of Total Slider class and instan…
Browse files Browse the repository at this point in the history
…ce vars
  • Loading branch information
PeterUpfold committed Oct 29, 2014
1 parent e690092 commit c8665e3
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 118 deletions.
8 changes: 4 additions & 4 deletions admin/metaboxes/slide-preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@
<script id="slide-ejs" type="text/ejs">
<?php

if ( ! $TS_The_Template || ! is_a( $TS_The_Template, 'Total_Slider_Template' ) ) {
if ( ! $TS_Total_Slider->template || ! is_a( $TS_Total_Slider->template, 'Total_Slider_Template' ) ) {
// determine the current template
if ( ! Total_Slider::determineTemplate() ) {
if ( ! $this->determineTemplate() ) {
?><div class="template-render-error"><?php
_e( 'Unable to load the preview.', 'total_slider' );
?></div><?php
}
}

if ( is_a( $TS_The_Template, 'Total_Slider_Template' ) ) {
if ( is_a( $TS_Total_Slider->template, 'Total_Slider_Template' ) ) {
try {
echo $TS_The_Template->render();
echo $TS_Total_Slider->template->render();
}
catch ( Exception $e )
{
Expand Down
4 changes: 2 additions & 2 deletions admin/metaboxes/slide-sorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

?><!--sortable slides-->
<?php $current_slides = Total_Slider::get_current_slides($TS_The_Slug); ?>
<?php $current_slides = $TS_Total_Slider->get_current_slides($TS_Total_Slider->slug); ?>
<div id="slidesort-container">
<ul id="slidesort" style="width:<?php echo intval( count( $current_slides ) * 180 ); ?>px;">
<?php
Expand All @@ -44,7 +44,7 @@

foreach( $current_slides as $slide ) {

$my_id = Total_Slider::id_filter( $slide['id'] );
$my_id = $TS_Total_Slider->id_filter( $slide['id'] );

if ( is_numeric($slide['background'] ) )
{
Expand Down
2 changes: 1 addition & 1 deletion admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
}

Total_Slider::set_capability_for_roles($roles_to_add);
$this->set_capability_for_roles($roles_to_add);
$success = true;
$message = __( 'Settings saved.', 'total_slider' );

Expand Down
24 changes: 12 additions & 12 deletions admin/slide-groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}

// add the credits/notes metabox
add_meta_box( 'credits-notes', __( 'Credits', 'total_slider' ), array( 'Total_Slider', 'print_credits_metabox' ), '_total_slider_slide_groups', 'side', 'core' );
add_meta_box( 'credits-notes', __( 'Credits', 'total_slider' ), array( $TS_Total_Slider, 'print_credits_metabox' ), '_total_slider_slide_groups', 'side', 'core' );

// if we are to remove a slide group, do that and redirect to home
if ( array_key_exists( 'action', $_GET ) && 'remove' == $_GET['action'] && array_key_exists( 'group', $_GET ) ) {
Expand All @@ -56,10 +56,10 @@
$new_group->delete();

// remove the option
delete_option( 'total_slider_slides_'. Total_Slider::sanitize_slide_group_slug( $_GET['group'] ) );
delete_option( 'total_slider_slides_'. $this->sanitize_slide_group_slug( $_GET['group'] ) );

// redirect back to the admin total slider root page
Total_Slider::ugly_js_redirect( 'root' );
$this->ugly_js_redirect( 'root' );
die();

}
Expand Down Expand Up @@ -94,19 +94,19 @@
$new_group->delete();

// remove the option
delete_option( 'total_slider_slides_'. Total_Slider::sanitize_slide_group_slug( $slide_group ) );
delete_option( 'total_slider_slides_'. $this->sanitize_slide_group_slug( $slide_group ) );
}

// redirect back to the admin total slider root page
Total_Slider::ugly_js_redirect( 'root' );
$this->ugly_js_redirect( 'root' );
die();
}
}

// if the URL otherwise has 'group' in the GET parameters, it's time to pass control
// to print_slides_page() for editing purposes
if ( array_key_exists( 'group', $_GET ) ) {
Total_Slider::print_slides_page();
$this->print_slides_page();
return;
}

Expand All @@ -120,19 +120,19 @@

if ( ! empty( $_POST['group-name'] ) && ! empty( $_POST['template-slug'] ) ) {
// add the new slide group
$new_slug = Total_Slider::sanitize_slide_group_slug( sanitize_title_with_dashes( $_POST['group-name'] ) );
$new_slug = $this->sanitize_slide_group_slug( sanitize_title_with_dashes( $_POST['group-name'] ) );

// slide group already with this name?
$existing = new Total_Slide_Group( $new_slug );
if ( $existing->load() ) {
$new_slug = substr( $new_slug, 0, ( 63 - strlen( 'total_slider_slides_' ) - 23 ) ); // truncate so that the uniqid portion is retained.
$new_slug .= Total_Slider::id_filter( uniqid( '_', true ) );
$new_slug = Total_Slider::sanitize_slide_group_slug( $new_slug );
$new_slug .= $this->id_filter( uniqid( '_', true ) );
$new_slug = $this->sanitize_slide_group_slug( $new_slug );
}

if ( empty( $new_slug) ) {
$new_slug = 'group_' . Total_Slider::id_filter( uniqid( '', true ) );
$new_slug = Total_Slider::sanitize_slide_group_slug( $newSlug );
$new_slug = 'group_' . $this->id_filter( uniqid( '', true ) );
$new_slug = $this->sanitize_slide_group_slug( $newSlug );
}

$new_group = new Total_Slide_Group( $new_slug, $_POST['group-name'] );
Expand Down Expand Up @@ -184,7 +184,7 @@
add_option( 'total_slider_slides_' . $new_slug, array(), '', 'yes' );

// redirect to the new edit page for this slide group
Total_Slider::ugly_js_redirect( 'edit-slide-group', $new_slug );
$this->ugly_js_redirect( 'edit-slide-group', $new_slug );
die();
}
}
Expand Down
36 changes: 18 additions & 18 deletions admin/slides.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@
return;
}

$TS_The_Slug = Total_Slider::sanitize_slide_group_slug( $_GET['group'] );
$TS_Total_Slider->slug = $TS_Total_Slider->sanitize_slide_group_slug( $_GET['group'] );

if ( empty( $TS_The_Slug ) ) {
if ( empty( $TS_Total_Slider->slug ) ) {
echo '<div class="wrap"><h1>';
_e( 'No Slide Group selected.', 'total_slider' );
echo '</h1></div>';
return;
}

// get the name data for this slide group based on its slug
$slide_group = new Total_Slide_Group( $TS_The_Slug );
$slide_group = new Total_Slide_Group( $TS_Total_Slider->slug );

if ( ! $slide_group->load() ) {
echo '<div class="wrap"><h1>';
Expand All @@ -63,9 +63,9 @@
}

// determine and load template
if ( ! $TS_The_Template || ! is_a( $TS_The_Template, 'Total_Slider_Template' ) )
if ( ! $TS_Total_Slider->template || ! is_a( $TS_Total_Slider->template, 'Total_Slider_Template' ) )
{
Total_Slider::determine_template();
$TS_Total_Slider->determine_template();
}

if (
Expand Down Expand Up @@ -114,7 +114,7 @@
) {
// avoid being destructive if it's unnecessary
// there is no change, so just go back
Total_Slider::ugly_js_redirect( 'edit-slide-group', $slide_group->slug );
$this->ugly_js_redirect( 'edit-slide-group', $slide_group->slug );
die();
}

Expand All @@ -131,18 +131,18 @@
$slide_group->remove_xy_data();
$slide_group->save();

Total_Slider::ugly_js_redirect( 'edit-slide-group', $slide_group->slug );
$TS_Total_Slider->ugly_js_redirect( 'edit-slide-group', $slide_group->slug );
die();

}

// add the metaboxes
add_meta_box( 'slide-sorter-mb', __( 'Slides', 'total_slider' ), array( 'Total_Slider', 'print_slide_sorter_metabox' ), '_total_slider_slide', 'normal', 'core' );
add_meta_box( 'slide-preview-mb', __( 'Preview', 'total_slider' ), array( 'Total_Slider', 'print_slide_preview_metabox' ), '_total_slider_slide', 'normal', 'core' );
add_meta_box( 'slide-sorter-mb', __( 'Slides', 'total_slider' ), array( $TS_Total_Slider, 'print_slide_sorter_metabox' ), '_total_slider_slide', 'normal', 'core' );
add_meta_box( 'slide-preview-mb', __( 'Preview', 'total_slider' ), array( $TS_Total_Slider, 'print_slide_preview_metabox' ), '_total_slider_slide', 'normal', 'core' );

add_meta_box( 'slide-editor-mb', __( 'Edit', 'total_slider' ), array( 'Total_Slider', 'print_slide_editor_metabox' ), '_total_slider_slide_bottom', 'normal', 'core' );
add_meta_box( 'slide-template-mb', __( 'Template', 'total_slider' ), array( 'Total_Slider', 'print_slide_template_metabox' ), '_total_slider_slide_bottom', 'side', 'core' );
add_meta_box( 'credits-notes-mb', __( 'Credits', 'total_slider' ), array( 'Total_Slider', 'print_credits_metabox' ), '_total_slider_slide_bottom', 'side', 'core' );
add_meta_box( 'slide-editor-mb', __( 'Edit', 'total_slider' ), array( $TS_Total_Slider, 'print_slide_editor_metabox' ), '_total_slider_slide_bottom', 'normal', 'core' );
add_meta_box( 'slide-template-mb', __( 'Template', 'total_slider' ), array( $TS_Total_Slider, 'print_slide_template_metabox' ), '_total_slider_slide_bottom', 'side', 'core' );
add_meta_box( 'credits-notes-mb', __( 'Credits', 'total_slider' ), array( $TS_Total_Slider, 'print_credits_metabox' ), '_total_slider_slide_bottom', 'side', 'core' );

if ( function_exists( 'find_posts_div' ) ) {
// bring in the post/page finder interface for links
Expand All @@ -151,7 +151,7 @@

?>
<!-- Proxy template change form -->
<form name="template-switch-form" id="template-switch-form" method="POST" action="admin.php?page=total-slider&amp;group=<?php echo $TS_The_Slug; ?>&amp;action=changeTemplate">
<form name="template-switch-form" id="template-switch-form" method="POST" action="admin.php?page=total-slider&amp;group=<?php echo $TS_Total_Slider->slug; ?>&amp;action=changeTemplate">
<?php wp_nonce_field( 'total-slider-change-template', 'total-slider-change-template-nonce' ); ?>
<input type="hidden" id="template-slug" name="template-slug" value="<?php echo esc_attr( $slide_group->template ); ?>" />
</form>
Expand All @@ -161,16 +161,16 @@
//<![CDATA[
var VPM_WP_ROOT = '<?php echo admin_url(); ?>';
var VPM_HPS_PLUGIN_URL = '<?php echo admin_url(); ?>admin.php?page=total-slider&total-slider-ajax=true&';
var VPM_HPS_GROUP = '<?php echo esc_attr($TS_The_Slug); ?>';
var VPM_HPS_GROUP = '<?php echo esc_attr($TS_Total_Slider->slug); ?>';
document.title = '‘<?php echo esc_attr($slide_group->name); ?>’ Slides ' + document.title.substring(13, document.title.length);//TODO i18n
var VPM_SHOULD_WORKAROUND_16655 = <?php echo ( version_compare( get_bloginfo( 'version' ), '3.4', '>=' ) ? 'false' : 'true' ); ?>;
// on WordPress version <3.4, we need to work around https://core.trac.wordpress.org/ticket/16655. It is fixed in 3.4.

var VPM_SLIDE_GROUP_TEMPLATE = '<?php echo esc_attr( $slide_group->template );?>';
var VPM_SLIDE_GROUP_TEMPLATE_LOCATION = '<?php echo esc_attr( $slide_group->templateLocation );?>';

<?php if ( $TS_The_Template && is_a( $TS_The_Template, 'Total_Slider_Template' ) ) {
$template_options = $TS_The_Template->determine_options();
<?php if ( $TS_Total_Slider->template && is_a( $TS_Total_Slider->template, 'Total_Slider_Template' ) ) {
$template_options = $TS_Total_Slider->template->determine_options();
} ?>

var VPM_SHOULD_DISABLE_XY = <?php echo ( $template_options['disable_xy'] ) ? 'true' : 'false'; ?>;
Expand All @@ -188,10 +188,10 @@
<p><?php _e( 'You will need to enable JavaScript for this page before any of the controls below will work.', 'total_slider' );?></p>
</noscript>

<?php if ( $TS_The_Tpl_Error ): ?>
<?php if ( $TS_Total_Slider->tpl_error ): ?>
<div id="template-error" class="updated settings-error below-h2">
<h3><?php _e( 'There is a problem with this slide group&rsquo;s template.', 'total_slider' ); ?></h3>
<p><?php echo esc_html( $TS_The_Tpl_Error->getMessage() ); ?> <em><?php printf( __( '(error code %d)', 'total_slider' ), intval( $TS_The_Tpl_Error->getCode() ) ); ?></em></p>
<p><?php echo esc_html( $TS_Total_Slider->tpl_error->getMessage() ); ?> <em><?php printf( __( '(error code %d)', 'total_slider' ), intval( $TS_Total_Slider->tpl_error->getCode() ) ); ?></em></p>
<p><?php _e( 'Please either resolve this problem, or choose a different template for this slide group.', 'total_slider' ); ?></p>
</div>
<?php endif; ?>
Expand Down
Loading

0 comments on commit c8665e3

Please sign in to comment.