Example #1
0
 /**
  * Edit an existing or new gallery
  *
  * This will render the edit form, in place of the gallery list, unless
  * the user does not have the privileges to edit any theme options.
  *
  * @see onGalleriesMenu()
  */
 public static function showEditScreen(Main $owner, $per_page)
 {
     // Get the main meta box output (for Twig)
     ob_start();
     do_meta_boxes(Main::PT_GALLERY, 'normal', $owner->gallery);
     do_meta_boxes(Main::PT_GALLERY, 'advanced', $owner->gallery);
     $meta_boxes_main = ob_get_clean();
     // Get the side meta box output (for Twig)
     ob_start();
     do_meta_boxes(Main::PT_GALLERY, 'side', $owner->gallery);
     $meta_boxes_side = ob_get_clean();
     // Check if we start by displaying the right-side column;
     $screen = get_current_screen();
     $columns = (int) get_user_option('screen_layout_' . $screen->id);
     if ($columns == 0) {
         $columns = 2;
     }
     // Image upload button iframe src (href)
     $image_media_library = add_query_arg(array('post_id' => $owner->gallery ? $owner->gallery->ID : '', 'type' => 'image'), admin_url('media-upload.php'));
     $image_media_library = apply_filters('image_upload_iframe_src', $image_media_library);
     // As used by WordPress
     // Add an "Add Image" media button
     $media_buttons['image']['id'] = 'add_image';
     $media_buttons['image']['url'] = add_query_arg('filter', \Myatu\WordPress\BackgroundManager\Filter\MediaLibrary::FILTER, $image_media_library);
     // Add filter
     $media_buttons['image']['icon'] = admin_url('images/media-button-image.gif');
     $media_buttons['image']['title'] = __('Add an Image', $owner->getName());
     // Allow additional media buttons to be specified
     $media_buttons = apply_filters(Main::BASE_PUB_PREFIX . 'media_buttons', $media_buttons);
     // Ensure that media buttons have a `TB_iframe` as the last query arg
     foreach ($media_buttons as $media_button_key => $media_button_value) {
         if (isset($media_button_value['url'])) {
             $media_buttons[$media_button_key]['url'] = add_query_arg('TB_iframe', true, remove_query_arg('TB_iframe', $media_buttons[$media_button_key]['url']));
         }
     }
     // Iframe source for listing the images - @see onIframeImages()
     $images_iframe_src = add_query_arg(array('iframe' => 'images', 'edit' => $owner->gallery->ID, 'orderby' => false, 'order' => false, 'pp' => $per_page, 'paged' => false));
     // Iframe source for editing a single image - @see onIframeEditImage()
     $image_edit_src = add_query_arg(array('iframe' => 'edit_image', 'edit' => false, 'orderby' => false, 'order' => false, 'post_id' => $owner->gallery->ID, 'filter' => \Myatu\WordPress\BackgroundManager\Filter\MediaLibrary::FILTER));
     $vars = array('is_wp34' => Helpers::checkWPVersion('3.4', '>='), 'has_right_sidebar' => $columns == 2 ? 'columns-2' . (Helpers::checkWPVersion('3.4', '>=') ? '' : ' has-right-sidebar') : '', 'nonce' => wp_nonce_field(Main::NONCE_EDIT_GALLERY . $owner->gallery->ID, '_nonce', true, false), 'nonce_meta_order' => wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false, false), 'nonce_meta_clsd' => wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false, false), 'images_iframe_src' => $images_iframe_src, 'image_edit_src' => $image_edit_src, 'gallery' => $owner->gallery, 'post_type' => Main::PT_GALLERY, 'meta_boxes_main' => $meta_boxes_main, 'meta_boxes_side' => $meta_boxes_side, 'media_buttons' => $media_buttons, 'is_new' => $owner->gallery->post_status != 'auto-draft', 'edit' => $owner->gallery->ID, 'images_per_page' => $per_page, 'images_count' => $owner->images->getCount($owner->gallery->ID), 'images_hash' => $owner->images->getHash($owner->gallery->ID), 'img_large_loader' => $owner->getPluginUrl() . Main::DIR_IMAGES . 'large_loader.gif', 'image_del_is_perm' => !EMPTY_TRASH_DAYS || !MEDIA_TRASH ? true : false);
     $owner->template->display('edit_gallery.html.twig', $vars);
 }
Example #2
0
 /**
  * Load public scripts
  */
 public function onPublicScripts()
 {
     if (!$this->canDisplayBackground()) {
         return;
     }
     extract($this->getFilteredOptions());
     $is_preview = false;
     // If we're in the 3.4 Customize Theme Preview, this will be set to true.
     // 3.4+ filters
     if (Helpers::checkWPVersion('3.4', '>=')) {
         global $wp_customize;
         if (is_a($wp_customize, static::WP_CUSTOMIZE_MANAGER_CLASS)) {
             $is_preview = $wp_customize->is_preview();
         }
     }
     /* Only load the scripts if:
      * - there's custom change frequency
      * - the background is full screen
      * - there's a click-able image in the background set // since @1.0.45 - see http://wordpress.org/support/topic/plugin-background-manager-link-in-background-not-working
      * - or, there's an info tab with a short description
      */
     /*if ($change_freq != static::CF_CUSTOM &&
       $background_size != static::BS_FULL &&
       !$this->images->hasLinkedImages($active_gallery) && // since @1.0.45
       !($info_tab && $info_tab_desc))
       return;*/
     // Enqueue jQuery and base functions
     list($js_url, $version, $debug) = $this->getResourceUrl();
     wp_enqueue_script('jquery');
     wp_enqueue_script($this->getName() . '-functions', $js_url . 'functions' . $debug . '.js', array('jquery'), $version);
     wp_enqueue_script($this->getName() . '-flux', $js_url . 'flux' . $debug . '.js', array($this->getName() . '-functions'), $version);
     wp_enqueue_script($this->getName() . '-pub', $js_url . 'pub' . $debug . '.js', array($this->getName() . '-functions', $this->getName() . '-flux'), $version);
     // If the info tab is enabled along with the short description, also include qTip2
     if ($info_tab && $info_tab_desc) {
         wp_enqueue_script('jquery.qtip', $js_url . 'vendor/qtip/jquery.qtip.min.js', array('jquery'), $version);
     }
     // The change frequency is not 0 (disabled) if we have a custom frequency, valid gallery and it contans more than one image
     if ($change_freq == static::CF_CUSTOM && $this->getGallery($active_gallery) != false && $this->images->getCount($active_gallery) > 1) {
         $script_change_freq = $change_freq_custom >= 1 ? $change_freq_custom : 10;
     } else {
         $script_change_freq = 0;
         // Disabled
     }
     // Current background variable
     $current_background = $this->getImage();
     $current_background['transition'] = $background_transition;
     $current_background['transition_speed'] = $script_change_freq;
     // Spit out variables for JavaScript to use
     $script_vars = array('current_background' => (object) $current_background, 'change_freq' => $script_change_freq, 'active_gallery' => $active_gallery, 'is_fullsize' => $background_size == static::BS_FULL ? 'true' : 'false', 'is_preview' => $is_preview ? 'true' : 'false', 'initial_ease_in' => $initial_ease_in ? 'true' : 'false', 'info_tab_thumb' => $info_tab_thumb ? 'true' : 'false', 'bg_click_new_window' => $this->options->bg_click_new_window ? 'true' : 'false', 'bg_track_clicks' => $this->options->bg_track_clicks ? 'true' : 'false', 'bg_track_clicks_category' => $this->options->bg_track_clicks_category, 'display_on_mobile' => $this->options->display_on_mobile ? 'true' : 'false');
     // Add to variables if in full screen mode
     if ($background_size == static::BS_FULL) {
         $script_vars = array_merge($script_vars, array('fs_center' => $full_screen_center ? 'true' : 'false'));
     }
     // Also add the active transtion, transition speed and available transitions if we're in a preview (3.4+)
     if ($is_preview) {
         $script_vars = array_merge($script_vars, array('active_transition' => $background_transition, 'transition_speed' => $transition_speed, 'image_selection' => $image_selection, 'transitions' => array_values(array_diff_key($this->getBgOptions('transition'), array('none', 'random')))));
     }
     // Spit out the script variables (!! always attach to -functions !!)
     wp_localize_script($this->getName() . '-functions', 'myatu_bgm', $script_vars);
 }