You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
264 lines
9.1 KiB
264 lines
9.1 KiB
<?php
|
|
|
|
/*
|
|
Plugin Name: YaFed Slider Plugin
|
|
Description: YaFed's Slider Plugin for LNW
|
|
Author: YaFedImYaEatIm
|
|
Version: 1.1
|
|
*/
|
|
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//Initialisers
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/**
|
|
* Initialise Function
|
|
*/
|
|
|
|
function ys_init() {
|
|
$args = array(
|
|
'public' => true,
|
|
'labels' => array('name' => __('YSlides'), 'singular_name' => __("YSlide"),
|
|
'add_new' => "Add New YSlide", "edit_item" => "Edit YSlide", "new_item" => "Add New YSlide",
|
|
"view_items" => "View YSlides"),
|
|
'supports' => array(
|
|
'title',
|
|
'thumbnail',
|
|
'editor'
|
|
)
|
|
);
|
|
add_image_size('ys_image', 180, 240);
|
|
register_post_type('ys_slides', $args);
|
|
add_shortcode('ys-shortcode', 'ys_function');
|
|
}
|
|
add_theme_support( 'post-thumbnails' );
|
|
add_action('init', 'ys_init');
|
|
|
|
/**
|
|
* Add to Page Function
|
|
*/
|
|
|
|
function ys_function($type='ys_image'){
|
|
$args = array(
|
|
'post_type' => 'ys_slides',
|
|
'posts_per_page' => 10,
|
|
'meta_key' => 'custom_ys_checkbox',
|
|
'meta_value' => 'on'
|
|
);
|
|
$result = '<div class="wrapper ys-slider">';
|
|
$result .= '<img src="'.plugins_url("/next.png", __FILE__).'" class="ys-slider-next" onclick="ys_next_slide();"/>';
|
|
$result .= '<img src="'.plugins_url("/prev.png", __FILE__).'" class="ys-slider-prev" onclick="ys_prev_slide();"/>';
|
|
//the loop
|
|
$loop = new WP_Query($args);
|
|
$num_posts = 0;
|
|
if ($loop->have_posts() ) :
|
|
while ($loop->have_posts()) : $loop->the_post();
|
|
$result .= '<div class="ys-slide">';
|
|
$result .= "<div class='ys-image'>";
|
|
$result .= get_the_post_thumbnail(null, 'ys_image');
|
|
$result .= "</div>";
|
|
$result .= "<div class='ys-content'>";
|
|
$result .= "<h2>".get_the_title().'</h2>';
|
|
$result .= "<hr/>";
|
|
$result .= "<p>".get_the_content()."</p>";
|
|
$result .= "<div>";
|
|
$result .= "<div class='ys-read-more'><a href='".get_post_meta(get_the_ID(), "custom_ys_url", true)."'>Read More...</a></div>";
|
|
$result .= "</div>";
|
|
$result .= "</div>";
|
|
$result .= '</div>';
|
|
$num_posts++;
|
|
endwhile;
|
|
endif;
|
|
if ($num_posts == 0){
|
|
$result .= '<div class="ys-slide">';
|
|
$result .= "<div class='ys-image'>";
|
|
$result .= "</div>";
|
|
$result .= "<div class='ys-content'>";
|
|
$result .= "<h2>Slides Missing</h2>";
|
|
$result .= "<hr/>";
|
|
$result .= "<p></p>";
|
|
$result .= "<div>";
|
|
$result .= "<div class='ys-read-more'></div>";
|
|
$result .= "</div>";
|
|
$result .= "</div>";
|
|
$result .= '</div>';
|
|
}
|
|
$result .= "<div class='ys-page-nav'>";
|
|
for ($i = 0; $i < $num_posts; $i ++){
|
|
$result .= "<span onclick='gotoSlide({$i}, false);'></span>";
|
|
}
|
|
$result .= "</div>";
|
|
$result .='</div>';
|
|
wp_reset_postdata();
|
|
return $result;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//Widget
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class ys_slider_widget extends WP_Widget{
|
|
|
|
public function __construct(){
|
|
parent::__construct('ys_slider_widget', 'YaFed WP Slider', array('description' => __('A Slider Carousel', 'text_domain')));
|
|
}
|
|
|
|
public function form($instance) {
|
|
if (isset($instance['title'])) {
|
|
$title = $instance['title'];
|
|
}
|
|
else {
|
|
$title = __('Widget Slideshow', 'text_domain');
|
|
}
|
|
?>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
|
|
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
|
|
</p>
|
|
<?php
|
|
}
|
|
|
|
public function update($new_instance, $old_instance) {
|
|
$instance = array();
|
|
$instance['title'] = strip_tags($new_instance['title']);
|
|
|
|
return $instance;
|
|
}
|
|
|
|
public function widget($args, $instance) {
|
|
extract($args);
|
|
// the title
|
|
$title = apply_filters('widget_title', $instance['title']);
|
|
echo $before_widget;
|
|
if (!empty($title))
|
|
echo $before_title . $title . $after_title;
|
|
echo ys_function('ys_image');
|
|
echo $after_widget;
|
|
}
|
|
}
|
|
|
|
function ys_widgets_init() {
|
|
register_widget('ys_slider_Widget');
|
|
}
|
|
|
|
add_action('widgets_init', 'ys_widgets_init');
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//Custom Meta box
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Field Array
|
|
$prefix = 'custom_ys_';
|
|
$custom_meta_fields = array(
|
|
array(
|
|
'label'=> 'URL',
|
|
'desc' => '',
|
|
'id' => $prefix.'url',
|
|
'type' => 'text'
|
|
),
|
|
array(
|
|
'label'=> 'Display on Slider?',
|
|
'desc' => '',
|
|
'id' => $prefix.'checkbox',
|
|
'type' => 'checkbox'
|
|
)
|
|
);
|
|
|
|
// The Callback
|
|
function show_custom_meta_box() {
|
|
global $custom_meta_fields, $post;
|
|
// Use nonce for verification
|
|
echo '<input type="hidden" name="custom_ys_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';
|
|
|
|
// Begin the field table and loop
|
|
echo '<table class="form-table">';
|
|
foreach ($custom_meta_fields as $field) {
|
|
// get value of this field if it exists for this post
|
|
$meta = get_post_meta($post->ID, $field['id'], true);
|
|
// begin a table row with
|
|
echo '<tr>
|
|
<th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
|
|
<td>';
|
|
switch($field['type']) {
|
|
// case items will go here
|
|
// // text
|
|
case 'text':
|
|
echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="20" />
|
|
<br /><span class="description">'.$field['desc'].'</span>';
|
|
break;
|
|
// checkbox
|
|
case 'checkbox':
|
|
echo '<input type="checkbox" name="'.$field['id'].'" id="'.$field['id'].'" ',$meta ? ' checked="checked"' : '','/>
|
|
<label for="'.$field['id'].'">'.$field['desc'].'</label>';
|
|
break;
|
|
} //end switch
|
|
echo '</td></tr>';
|
|
} // end foreach
|
|
echo '</table>'; // end table
|
|
}
|
|
|
|
// Add the Meta Box
|
|
function add_custom_meta_box() {
|
|
add_meta_box(
|
|
'custom_ys_slider_meta', // $id
|
|
'Show on Slider', // $title
|
|
'show_custom_meta_box', // $callback
|
|
'ys_slides', // $page
|
|
'side', // $context
|
|
'high'); // $priority
|
|
}
|
|
add_action('add_meta_boxes', 'add_custom_meta_box');
|
|
|
|
// Save the Data
|
|
function save_custom_meta($post_id) {
|
|
global $custom_meta_fields;
|
|
|
|
// verify nonce
|
|
if (!wp_verify_nonce($_POST['custom_ys_meta_box_nonce'], basename(__FILE__)))
|
|
return $post_id;
|
|
// check autosave
|
|
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
|
|
return $post_id;
|
|
// check permissions
|
|
if ('page' == $_POST['post_type']) {
|
|
if (!current_user_can('edit_page', $post_id))
|
|
return $post_id;
|
|
} elseif (!current_user_can('edit_post', $post_id)) {
|
|
return $post_id;
|
|
}
|
|
|
|
// loop through fields and save the data
|
|
foreach ($custom_meta_fields as $field) {
|
|
$old = get_post_meta($post_id, $field['id'], true);
|
|
$new = $_POST[$field['id']];
|
|
if ($new && $new != $old) {
|
|
update_post_meta($post_id, $field['id'], $new);
|
|
} elseif ('' == $new && $old) {
|
|
delete_post_meta($post_id, $field['id'], $old);
|
|
}
|
|
} // end foreach
|
|
}
|
|
add_action('save_post', 'save_custom_meta');
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
//Carousel Style
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
function register_ys_styles(){
|
|
wp_register_style( 'YS-CSS', plugins_url("/style.css", __FILE__), array(), '1.0', 'all');
|
|
wp_enqueue_style( 'YS-CSS' );
|
|
}
|
|
|
|
// Register style sheet.
|
|
add_action( 'wp_enqueue_scripts', "register_ys_styles");
|
|
/**
|
|
* Register JS functions
|
|
*/
|
|
function register_ys_scripts(){
|
|
wp_deregister_script('jquery');
|
|
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
|
|
wp_enqueue_script('jquery');
|
|
wp_register_script('YSlider Script', plugins_url('/slider_script.js', __FILE__) , array('jquery'), '1.0', true);
|
|
wp_enqueue_script( 'YSlider Script' );
|
|
}
|
|
// Register Scripts
|
|
add_action( 'init', 'register_ys_scripts');
|