Esempio n. 1
0
/**
 * For the full license information, please view the Licensing folder
 * that was distributed with this source code.
 *
 * @package G1_Theme03
 * @subpackage G1_Simple_Sliders_Module
 * @since G1_Simple_Sliders_Module 1.0.0
 */
// Prevent direct script access
if (!defined('ABSPATH')) {
    die('No direct script access allowed');
}
global $pagenow;
require_once trailingslashit(dirname(__FILE__)) . 'lib/functions.php';
require_once trailingslashit(dirname(__FILE__)) . 'lib/slider-builder.php';
/**
 * Quasi-singleton for our module
 *
 * @return G1_Simple_Sliders_Module
 */
function G1_Simple_Sliders_Module()
{
    static $instance;
    if (!isset($instance)) {
        $instance = new G1_Simple_Sliders_Module();
    }
    return $instance;
}
// Fire in the hole :)
G1_Simple_Sliders_Module();
Esempio n. 2
0
 /**
  * Shortcode callback function.
  *
  * @return string
  */
 protected function do_shortcode()
 {
     extract($this->extract());
     global $post;
     $content = preg_replace('#^<\\/p>|<p>$#', '', $content);
     $imgs = strip_tags($content);
     $imgs = explode("\n", trim($imgs));
     // Clean attributes
     $entry_id = absint($slider);
     $config = G1_Simple_Sliders_Module()->get_default_config();
     $slides = array();
     /* --------------------------------------------------------------------- */
     /* Build slider from attachments */
     /* --------------------------------------------------------------------- */
     if ($entry_id) {
         // Compose final HTML id attribute
         $id = strlen($id) ? $id : 'g1-simple-slider-entry-' . $entry_id;
         $slider = get_post($entry_id);
         if (!$slider) {
             return '';
         }
         // Get configuration from the attachments parent ( slider )
         $config = G1_Simple_Sliders_Module()->get_post_config($slider);
         $width = G1_Simple_Sliders_Module::get_slider_width_in_pixels($config['width']);
         $height = !empty($config['height']) ? $config['height'] : null;
         // Prepare query arguments
         $query_args = array('post_parent' => $entry_id, 'post_type' => 'attachment', 'post_mime_type' => array('image'), 'post_status' => 'inherit', 'posts_per_page' => 50, 'orderby' => 'menu_order', 'order' => 'ASC', 'suppress_filters' => true);
         $query = new WP_Query($query_args);
         if ($query->have_posts()) {
             while ($query->have_posts()) {
                 $query->the_post();
                 $slide = array('id' => $post->ID, 'title' => $post->post_excerpt, 'content' => $post->post_content, 'link' => get_post_meta($post->ID, '_g1_alt_link', true), 'linking' => get_post_meta($post->ID, '_g1_alt_linking', true), 'layout' => get_post_meta($post->ID, '_g1_layout', true));
                 $orig_src = wp_get_attachment_url($post->ID);
                 $img_data = aq_resize($orig_src, $width, $height, true, false);
                 if ($img_data !== false) {
                     $slide['src'] = $img_data[0];
                     $slide['width'] = $img_data[1];
                     $slide['height'] = $img_data[2];
                     $slides[] = $slide;
                 }
             }
             wp_reset_postdata();
         }
         /* --------------------------------------------------------------------- */
         /* Build slider from shortcode content */
         /* --------------------------------------------------------------------- */
     } else {
         foreach ($imgs as $img) {
             $slide = array('title' => '', 'content' => '', 'link' => '', 'linking' => '', 'layout' => '', 'src' => $img);
             $slides[] = $slide;
         }
     }
     $args = array('id' => $id, 'class' => $class, 'width' => $width, 'height' => $height);
     return G1_Simple_Sliders_Module()->capture($slides, $config, $args);
 }