Example #1
0
 /**
  * Constructor. Takes as argument the slider ID
  * @param int $slider_id
  */
 public function __construct($slider_id)
 {
     $this->timer_start = microtime(true);
     // get the slider post
     $post = get_post($slider_id);
     if (!$post || $post->post_type != fa_post_type_slider()) {
         return;
     }
     // check post status, allow any if preview
     if (!fa_is_preview() && 'publish' != $post->post_status) {
         return;
     }
     // if preview, check other sliders status that might be displayed into the page and allow only published ones
     if (fa_is_preview()) {
         $preview_id = absint($_GET['slider_id']);
         if ($slider_id != $preview_id && 'publish' != $post->post_status) {
             return false;
         }
     }
     // store the slider
     $this->slider = $post;
     // If preview, get the options from the revision, if any is available
     if (fa_is_preview()) {
         $statuses = array('future', 'publish', 'draft');
         if (in_array($post->post_status, $statuses)) {
             $children = get_children(array('post_parent' => $slider_id, 'post_type' => 'revision', 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 1));
             if ($children) {
                 $revision = array_pop($children);
                 $options = fa_get_slider_options($revision->ID);
                 $this->options = $options;
             }
         }
     }
     // filter the options to push the theme from preview
     if (fa_is_preview()) {
         if (isset($_GET['slider_id']) && $slider_id == $_GET['slider_id']) {
             // filter the slider options to set the theme from preview
             add_filter('fa_get_slider_options', array($this, 'modify_preview_options'), 1, 3);
         }
     }
     // if options aren't already set by a preview, set them now
     if (!$this->options) {
         // get the slider options
         $this->options = fa_get_slider_options($post->ID);
     }
     // get the slides
     $this->slides = $this->get_slides();
 }
Example #2
0
/**
 * Retrieves the images attached to a slider that are used to
 * create the slides. Used when slides are made of manually
 * selected images
 * 
 * @param $post_id - slider ID
 */
function fa_get_slider_images($post_id)
{
    $settings = fa_get_options('settings');
    $slider_options = fa_get_slider_options($post_id, 'slides');
    $image_ids = (array) $slider_options['images'];
    if (!$image_ids) {
        return;
    }
    $args = array('posts_per_page' => -1, 'nopaging' => true, 'ignore_sticky_posts' => true, 'offset' => 0, 'post__in' => $image_ids, 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'image');
    $query = new WP_Query($args);
    $images = $query->get_posts();
    $result = array();
    foreach ($image_ids as $image_id) {
        foreach ($images as $image) {
            if ($image_id == $image->ID) {
                $result[] = $image;
                break;
            }
        }
    }
    return $result;
}
Example #3
0
/**
 * Returns a custom image size for the image attached to a given slide post.
 * @param object $post - a given slide post
 * @param array $size - image width ( as: array('width' => W, 'height' => H) ) or string ( ie: thumbnail )
 * @return string - the image URL
 */
function fa_get_custom_image($post, $size = array('width' => 0, 'height' => 0))
{
    if (!$post) {
        return;
    }
    // slide can be attachment image, in this case the image ID is the actual post ID
    if ('attachment' == $post->post_type) {
        $image_id = $post->ID;
    } else {
        $image_id = get_the_fa_image_id($post->ID);
        if (!$image_id) {
            global $fa_slider;
            if ($fa_slider) {
                $slider_options = fa_get_slider_options($fa_slider->ID, 'content_image');
            }
            if (!$image_id) {
                return false;
            }
        }
    }
    if (is_string($size)) {
        $imgsz = get_intermediate_image_sizes();
        if (in_array($size, $imgsz)) {
            $width = get_option($size . '_size_w');
            $height = get_option($size . '_size_h');
        }
    } elseif (is_array($size)) {
        extract($size, EXTR_SKIP);
    } else {
        return;
    }
    $image_url = fa_get_custom_image_size($image_id, $width, $height);
    return $image_url;
}
Example #4
0
/**
 * Gets the options implemented by a theme based on the absolute path
 * of the functions.php slider theme file
 * 
 * @param string $file - absolute path to slider theme functions.php file
 */
function fa_get_theme_options($file, $post)
{
    $key = fa_get_theme_key($file);
    if (is_object($post)) {
        $post_id = $post->ID;
    } else {
        $post_id = absint($post);
    }
    $options = fa_get_slider_options($post_id, 'themes_params');
    if ($options) {
        if (isset($options[$key])) {
            return $options[$key];
        }
    }
    return false;
}
Example #5
0
/**
 * Implements a deprecated action not used since version 3.0.
 * Instead of action fa_extra_animation_fields use fa_theme_layout_settings--THEME_NAME.
 * 
 * @deprecated 3.0
 * 
 */
function _deprecated_show_themes_layout_fields()
{
    global $post;
    echo '<div class="fa_deprecated theme_layout_fields">';
    $options = fa_get_slider_options($post->ID, 'themes_params');
    ob_start();
    /**
     * Deprecated action. Use fa_theme_layout_settings-THEME_NAME action instead.
     * 
     * @see fa_extra_slider_options
     */
    do_action('fa_extra_theme_fields', $options);
    $output = ob_get_clean();
    if ($output) {
        echo '<hr />';
        ?>
		<p class="description">
			<?php 
        _e('Below are parameters from themes designed for FA PRO before version 3.0.', 'fapro');
        ?>
<br />
			<?php 
        _e('We strongly recommend that you update all deprecated slider themes to current FA PRO version.', 'fapro');
        ?>
		</p>
		<?php 
        echo str_replace('disabled="disabled"', '', $output);
    }
    echo '</div><br class="clear" />';
}
Example #6
0
 /**
  * Filter fa_display_slider callback function. Verifies if the currently
  * displayed slider is inside a dynamic area and if true, if it should display
  * on the current page according to user settings.
  * 
  * @param bool $show - show slider
  * @param int $slider_id - ID of slider
  * @param bool/string $dynamic_area - if displayed in dynamic area, this parameter contains the area ID
  */
 public function dynamic_areas_filter($show, $slider_id, $dynamic_area)
 {
     // only registered plugin areas should be managed by this function.
     // if any other area, allow it to display
     $areas = fa_get_options('hooks');
     if (empty($dynamic_area) || !$dynamic_area || !array_key_exists($dynamic_area, $areas)) {
         return $show;
     }
     // check for the ID
     if (!$slider_id) {
         return false;
     }
     // get slider options
     $options = fa_get_slider_options($slider_id, 'display');
     // if slider is allowed everywhere, show it
     if ($options['everywhere']) {
         return true;
     }
     // check if slider should display on homepage
     if (is_front_page()) {
         // allow previews on front page
         if (fa_is_preview() && $slider_id == $_GET['slider_id']) {
             return true;
         }
         return $options['home'];
     }
     // display on archive pages
     if (is_archive()) {
         // allow display on all categories
         if ($options['all_categories']) {
             return true;
         }
         // if no categories are set, bail out
         if (!$options['tax']) {
             return false;
         }
         // merge all types of tags into one array
         $categories = array();
         foreach ($options['tax'] as $tags) {
             $categories = array_merge($categories, $tags);
         }
         // check categories
         if (is_category($categories)) {
             return true;
         }
         // check taxonomies
         if (is_tax()) {
             $tax_id = get_queried_object()->term_id;
             return in_array($tax_id, $categories);
         }
     }
     // display on singular post/page
     if (is_singular()) {
         // allow display on all pages
         if ($options['all_pages']) {
             return true;
         }
         if (!$options['posts']) {
             return false;
         }
         $post_id = get_queried_object()->ID;
         $post_ids = array();
         foreach ($options['posts'] as $posts) {
             $post_ids = array_merge($post_ids, $posts);
         }
         if (in_array($post_id, $post_ids)) {
             return true;
         }
     }
 }
Example #7
0
 /**
  * Output the extra columns data
  * 
  * @param string $column_name
  * @param int $post_id
  */
 public function output_extra_slider_columns($column_name, $post_id)
 {
     switch ($column_name) {
         // output slider content type (latest posts, mixed content, images)
         case 'content':
             $options = fa_get_slider_options($post_id, 'slides');
             switch ($options['type']) {
                 case 'post':
                     $order = 'latest';
                     if ('comments' == $options['orderby']) {
                         $order = __('most commented', 'fapro');
                     } else {
                         if ('random' == $options['orderby']) {
                             $order = __('random', 'fapro');
                         }
                     }
                     // 5 (recent|most commented|random) posts from
                     printf(__('%d %s posts', 'fapro'), $options['limit'], $order);
                     break;
                 case 'mixed':
                     $count = count($options['posts']);
                     printf(__('%d manually selected posts', 'fapro'), $count);
                     break;
                 case 'image':
                     $count = count($options['images']);
                     printf(__('%d manually selected images', 'fapro'), $count);
                     break;
             }
             break;
         case 'theme':
             $options = fa_get_slider_options($post_id, 'theme');
             $name = isset($options['details']['theme_config']['name']) ? $options['details']['theme_config']['name'] : ucfirst($options['active']);
             printf(__('%s', 'fapro'), $name);
             break;
         case 'auto_display':
             $options = fa_get_slider_options($post_id, 'display');
             $output = array();
             if ($options['home']) {
                 $output[] = __('Homepage', 'fapro');
             }
             if ($options['posts']) {
                 $count = 0;
                 foreach ($options['posts'] as $posts) {
                     $count += count($posts);
                 }
                 $output[] = sprintf(__('%d posts/pages', 'fapro'), $count);
             }
             if ($options['tax']) {
                 $count = 0;
                 foreach ($options['tax'] as $categories) {
                     $count += count($categories);
                 }
                 $output[] = sprintf(__('%d category pages', 'fapro'), $count);
             }
             if ($output) {
                 echo implode(', ', $output);
             } else {
                 echo '-';
             }
             break;
     }
 }