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
/**
 * Returns all sliders
 */
function fa_get_sliders($status = 'publish')
{
    $args = array('post_type' => fa_post_type_slider(), 'post_status' => $status);
    $sliders = get_posts($args);
    return $sliders;
}
Example #3
0
 /**
  * Update sliders
  */
 private function process_sliders()
 {
     // ge tthe sliders
     $sliders = get_posts(array('post_type' => fa_post_type_slider(), 'post_status' => 'any', 'posts_per_page' => -1));
     if (!$sliders) {
         return;
     }
     // load themes manager to allow options from themes to be merged with the plugin options
     fa_get_themes();
     // run sliders
     foreach ($sliders as $slider) {
         $options = $this->process_old_slider_options($slider->ID);
         // get old content option
         $o = get_post_meta($slider->ID, '_fa_lite_content', true);
         // set the slider content
         if (isset($o['displayed_content'])) {
             $options['slides']['type'] = 1 == $o['displayed_content'] ? 'post' : 'mixed';
         }
         // set the categories
         if (isset($o['display_from_category'])) {
             $tags = array();
             if ($o['display_from_category']) {
                 if (1 == count($o['display_from_category']) && empty($o['display_from_category'][0])) {
                     $tags['category'] = array();
                 } else {
                     $tags['category'] = (array) $o['display_from_category'];
                 }
             }
             $options['slides']['tags'] = $tags;
         }
         // set orderby
         if (isset($o['display_order'])) {
             switch ($o['display_order']) {
                 case 1:
                 default:
                     $options['slides']['orderby'] = 'date';
                     break;
                 case 2:
                     $options['slides']['orderby'] = 'comments';
                     break;
                 case 3:
                     $options['slides']['orderby'] = 'random';
                     break;
             }
         }
         // set posts
         if (isset($o['display_pages'])) {
             $options['slides']['posts'] = (array) $o['display_pages'];
             if ($options['slides']['posts']) {
                 foreach ($options['slides']['posts'] as $pid) {
                     delete_post_meta($pid, '_fa_lite_' . $slider->ID . '_page_ord');
                 }
                 $this->slides = array_merge($this->slides, $options['slides']['posts']);
             }
         }
         // get old aspect option
         $o = get_post_meta($slider->ID, '_fa_lite_aspect', true);
         // set the content to be displayed
         if (isset($o['use_custom_text']) && $o['use_custom_text']) {
             $options['content_text']['use'] = 'custom';
         } else {
             if (isset($o['use_excerpt']) && $o['use_excerpt']) {
                 $options['content_text']['use'] = 'excerpt';
             } else {
                 $options['content_text']['use'] = 'content';
             }
         }
         // set slider fullwidth
         if (isset($o['slider_width'])) {
             if ('100%' == $o['slider_width']) {
                 $options['layout']['full_width'] = true;
             } else {
                 $options['layout']['width'] = $o['slider_width'];
             }
         }
         // set homepage display - part of automatic display feature
         $o = get_post_meta($slider->ID, '_fa_lite_home_display', true);
         if ($o) {
             $options['display']['home'] = true;
             $this->auto_display['loop_start'][] = $slider->ID;
         }
         // set categories display
         $o = get_post_meta($slider->ID, '_fa_lite_categ_display', true);
         if ($o) {
             if (in_array('all', (array) $o)) {
                 $options['display']['all_categories'] = true;
             } elseif (in_array('everywhere', $o)) {
                 $options['display']['everywhere'] = true;
             } else {
                 $args = array('include' => $o, 'hide_empty' => false);
                 $taxonomies = get_taxonomies(array('public' => true));
                 $terms = get_terms($taxonomies, $args);
                 $opt = array();
                 if ($terms) {
                     foreach ($terms as $term) {
                         $opt[$term->taxonomy][] = $term->term_id;
                     }
                     $this->auto_display['loop_start'][] = $slider->ID;
                 }
                 $options['display']['tax'] = $opt;
             }
         }
         // set pages display
         $o = get_post_meta($slider->ID, '_fa_lite_page_display', true);
         if ($o) {
             $opt = array();
             foreach ($o as $post_id) {
                 $post_type = get_post_type($post_id);
                 if ($post_type) {
                     $opt[$post_type][] = $post_id;
                 }
             }
             $options['display']['posts'] = $opt;
             $this->auto_display['loop_start'][] = $slider->ID;
         }
         // get current theme
         $o = get_post_meta($slider->ID, '_fa_lite_theme', true);
         if (isset($o['active_theme'])) {
             $theme = $this->get_new_theme($o['active_theme']);
             if ($theme) {
                 $options['theme']['active'] = $theme['theme'];
                 if ($theme['params']) {
                     foreach ($theme['params'] as $key1 => $values1) {
                         if (is_array($values1)) {
                             foreach ($values1 as $key2 => $values2) {
                                 if (is_array($values2)) {
                                     foreach ($values2 as $key3 => $values3) {
                                         $options[$key1][$key2][$key3] = $values3;
                                     }
                                 } else {
                                     $options[$key1][$key2] = $values2;
                                 }
                             }
                         } else {
                             $options[$key1] = $values1;
                         }
                     }
                 }
             }
         }
         // set the new option
         $result = fa_update_slider_options($slider->ID, $options);
         // delete the old options
         delete_post_meta($slider->ID, '_fa_lite_content');
         delete_post_meta($slider->ID, '_fa_lite_aspect');
         delete_post_meta($slider->ID, '_fa_lite_display');
         delete_post_meta($slider->ID, '_fa_lite_js');
         delete_post_meta($slider->ID, '_fa_lite_theme');
         delete_post_meta($slider->ID, '_fa_lite_theme_details');
         delete_post_meta($slider->ID, '_fa_lite_home_display');
         delete_post_meta($slider->ID, '_fa_lite_categ_display');
         delete_post_meta($slider->ID, '_fa_lite_page_display');
     }
     $this->store_auto_displays();
     $this->process_slides();
 }