Documentation';
$support_link = 'Support ';
if ($file == plugin_basename(__FILE__)) {
$links[] = $documentation_link;
$links[] = $support_link;
}
return $links;
} // plugin_meta_links
// add settings link to plugins page
function plugin_action_links($links) {
$settings_link = 'Settings ';
array_unshift($links, $settings_link);
return $links;
} // plugin_action_links
// create the admin menu item
function admin_menu() {
add_theme_page('Premium Featured Posts Slider', 'Premium Featured Posts Slider', 'manage_options', 'wf-fps', array('wf_fps', 'options_page'));
} // admin_menu
// all settings are saved in one option
function register_settings() {
register_setting('wf_fps', 'wf_fps', array('wf_fps', 'sanitize_settings'));
} // register_settings
// set default settings
function default_settings($force = false) {
$defaults['width'] = '600px';
$defaults['source'] = 'post';
$defaults['limit'] = 5;
$defaults['thumbnail'] = 'medium';
$defaults['layout'] = 'layout-2';
$defaults['custom-layout'] = '';
$defaults['prev-next'] = 1;
$defaults['pagination'] = 1;
$defaults['autoplay'] = 5000;
$defaults['effect'] = 'slide';
$defaults['effect-speed'] = 350;
$defaults['hover-pause'] = 1;
$defaults['randomize'] = 0;
$defaults['include-css'] = 1;
$defaults['include-jquery'] = 0;
$defaults['include-slides'] = 1;
$defaults['shortcode'] = 'fps';
$defaults['additional-width'] = 330;
$defaults['additional-height'] = 330;
$defaults['additional-crop'] = 1;
$defaults['conditional'] = '';
$defaults['thumbnail-width'] = 50;
$defaults['thumbnail-height'] = 50;
$options = get_option('wf_fps');
if ($force || !$options || !$options['source']) {
update_option('wf_fps', $defaults);
}
} // default_settings
// add custom boxes to all post types
function add_custom_box() {
add_meta_box('featured', 'Featured Posts Slider per-post options', array('wf_fps', 'inner_custom_box'), 'post', 'normal', 'high');
add_meta_box('featured', 'Featured Posts Slider per-post options', array('wf_fps', 'inner_custom_box'), 'page', 'normal', 'high');
// add box to custom post types
$post_types = get_post_types(array('public' => true, '_builtin' => false), 'object', 'and');
if ($post_types) {
foreach ($post_types as $post_type ) {
add_meta_box('featured', 'Featured Posts Slider per-post options', array('wf_fps', 'inner_custom_box'), $post_type->query_var, 'normal', 'high');
}
}
} // add_custom_box
// custom box for post/page edit
function inner_custom_box() {
global $post;
$layouts[] = array('val' => '', 'label' => 'Default layout defined in global FPS options');
$layouts[] = array('val' => 'layout-1', 'label' => 'Layout 1 - Large image with title on image bottom');
$layouts[] = array('val' => 'layout-2', 'label' => 'Layout 2 - Thumbnail with content on right');
$layouts[] = array('val' => 'layout-3', 'label' => 'Layout 3 - Medium image with content on right');
$layouts[] = array('val' => 'layout-4', 'label' => 'Layout 4 - Large image with title above image ');
$layouts[] = array('val' => 'layout-5', 'label' => 'Layout 5 - Thumbnail with content on left');
$layouts[] = array('val' => 'layout-6', 'label' => 'Layout 6 - Medium image with content on left');
$layouts[] = array('val' => 'custom', 'label' => 'Custom layout');
$featured = get_post_meta($post->ID, '_fps_featured', true);
$thumbnail = get_post_meta($post->ID, '_fps_thumbnail', true);
$layout = get_post_meta($post->ID, '_fps_layout', true);
wp_nonce_field(plugin_basename(__FILE__), 'featured_noncename');
echo '
Featured: ';
echo 'No, this post is not featured ';
echo 'Yes, this post is featured ';
echo ' ';
echo 'Layout: ';
self::create_select_options($layouts, $layout);
echo ' ';
global $_wp_additional_image_sizes;
$sizes[] = array('val'=> '', 'label' => 'Default thumbnail size defined in global FPS options');
$sizes[] = array('val'=> 'thumbnail', 'label' => 'Thumbnail, ' . get_option('thumbnail_size_w') . 'x' . get_option('thumbnail_size_h') . (get_option('thumbnail_crop')? ', cropped':''));
$sizes[] = array('val'=> 'medium', 'label' => 'Medium, ' . get_option('medium_size_w') . 'x' . get_option('medium_size_h'));
$sizes[] = array('val'=> 'large', 'label' => 'Large, ' . get_option('large_size_w') . 'x' . get_option('large_size_h'));
if ($_wp_additional_image_sizes) {
foreach ($_wp_additional_image_sizes as $tmp => $tmp2) {
$sizes[] = array('val'=> $tmp, 'label' => $tmp . ', ' . $tmp2['width'] . 'x' . $tmp2['height'] . ($tmp2['crop']? ', cropped':''));
}
}
echo 'Thumbnail: ';
self::create_select_options($sizes, $thumbnail);
echo '
';
echo 'Configure global FPS options
';
} // inner_custom_box
// save fetured box data
function save_postdata($post_id) {
if (!wp_verify_nonce($_POST['featured_noncename'], plugin_basename(__FILE__)) || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) {
return $post_id;
}
update_post_meta($post_id, '_fps_featured', $_POST['fps_featured']);
update_post_meta($post_id, '_fps_layout', $_POST['fps_layout']);
update_post_meta($post_id, '_fps_thumbnail', $_POST['fps_thumbnail']);
return $post_id;
} // save_postdata
// mark post as fetured/unfeatured
function ajax_callback_post_featured() {
$post_id = (int) $_POST['post_id'];
$state = (isset($_POST['state']) && !empty($_POST['state']))? 1: 0;
update_post_meta($post_id, '_fps_featured', $state);
die('1');
} // ajax_callback_post_featured
// mark post as fetured/unfeatured
function ajax_callback_copy_layout() {
require('slider-layout-templates.php');
if (isset($layouts[$_POST['layout']])) {
$template = $layouts[$_POST['layout']];
} else {
$template = '';
}
echo json_encode($template);
die();
} // ajax_callback_post_featured
// featured column for all posts/pages/custom post types
function add_featured_column($cols) {
$cols['fps_featured'] = 'Featured';
return $cols;
} // add_featured_column
// featured column content
function manage_featured_column($column_name, $post_id) {
if ($column_name == 'fps_featured') {
echo ' ';
}
return;
} // manage_featured_column
// admin JS/CSS
function admin_head() {
if (strpos($_SERVER['REQUEST_URI'], 'wf-fps') === false
&& strpos($_SERVER['REQUEST_URI'], 'edit.php') === false
&& strpos($_SERVER['REQUEST_URI'], 'post.php') === false
) {
return;
}
?>
{$tmp['label']} \n";
} else {
$out .= "{$tmp['label']} \n";
}
}
if($output) {
echo $out;
} else {
return $out;
}
} // create_select_options
// sanitize settings on save
function sanitize_settings($values) {
foreach ($values as $key => $value) {
switch ($key) {
case 'limit':
case 'prev-next':
case 'pagination':
case 'autoplay':
case 'effect-speed':
case 'hover-pause':
case 'randomize':
case 'include-css':
case 'include-jquery':
case 'include-slides':
case 'additional-width':
case 'additional-height':
case 'thumbnail-width':
case 'thumbnail-height':
case 'additional-crop':
$values[$key] = (int) $value;
break;
case 'width':
case 'source':
case 'thumbnail':
case 'layout':
case 'effect':
case 'conditional':
$values[$key] = trim($value);
break;
case 'shortcode':
$values[$key] = strtolower(trim($value));
$values[$key] = str_replace(' ', '', $values[$key]);
break;
case 'custom-layout':
break;
} // switch
} // foreach
self::check_var_isset($values, array('prev-next' => 0,
'pagination' => 0,
'hover-pause' => 0,
'randomize' => 0,
'include-css' => 0,
'include-jquery' => 0,
'include-slides' => 0,
'additional-crop' => 0));
set_transient('wf-fps-updated', true, 10);
return $values;
} // sanitize_settings
// helper function for $_POST checkbox handling
function check_var_isset(&$values, $variables) {
foreach ($variables as $key => $value) {
if (!isset($values[$key])) {
$values[$key] = $value;
}
}
} // check_var_isset
// output the whole options page
function options_page() {
if (!current_user_can('manage_options')) {
wp_die('You do not have sufficient permissions to access this page.');
}
$options = get_option('wf_fps');
if (get_transient('wf-fps-updated')) {
echo '';
delete_transient('wf-fps-updated');
}
echo '
Premium Featured Posts Slider ';
echo '
';
} // options_page
// generate HTML code for slider
public function generate_html() {
$out = '';
$options = get_option('wf_fps');
// show slider only in certain circumstances
if ($options['conditional']) {
if ($options['conditional'] == 'is_home' && !is_home()) {
return;
} elseif ($options['conditional'] == 'is_front_page' && !is_front_page()) {
return;
} elseif ($options['conditional'] == 'is_category' && !is_category()) {
return;
} elseif ($options['conditional'] == 'is_singular' && !is_singular()) {
return;
} elseif ($options['conditional'] == 'is_not_singular' && is_singular()) {
return;
}
}
$types = array('post', 'page');
$post_types = get_post_types(array('public' => true, '_builtin' => false), 'object', 'and');
if ($post_types) {
foreach ($post_types as $post_type ) {
$types[] = $post_type->query_var;
}
} else {
$post_types = array();
}
if ($options['source'] == '_featured') {
$filter = array('numberposts' => $options['limit'],
'meta_key' => '_fps_featured',
'meta_value' => 1,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => $types);
} elseif (substr($options['source'], 0, 1) != '|') {
$filter = array('numberposts' => $options['limit'],
'post_type' => $options['source'],
'orderby' => 'post_date',
'order' => 'DESC',);
} else {
$source = explode('|', $options['source']);
if ($source[1] == 'category') {
$category = 'category';
} else {
$category = $source[1] . '_category';
}
$filter = array('numberposts' => $options['limit'],
'post_type' => $types,
$category => $source[2],
'orderby' => 'post_date',
'order' => 'DESC',);
}
$featured_posts = get_posts($filter);
require('slider-layout-templates.php');
$out .= '';
$out .= '
';
$slide_nb = 1;
$pagination = '';
foreach($featured_posts as $featured) {
$pagination .= '
' . get_the_post_thumbnail($featured->ID, 'FPS pagination thumbnail', array('class' => 'fps-thumbnail-mini')) . ' ';
// $featured "is" $post
// get per-post or global layout
if (get_post_meta($featured->ID, '_fps_layout', true)) {
$layout = get_post_meta($featured->ID, '_fps_layout', true);
} else {
$layout = $options['layout'];
}
if ($layout == 'custom') {
$template = $options['custom-layout'];
} else {
$template = $layouts[$layout];
}
// get per-post or global thumbnail size
if (get_post_meta($featured->ID, '_fps_thumbnail', true)) {
$thumbnail_size = get_post_meta($featured->ID, '_fps_thumbnail', true);
} else {
$thumbnail_size = $options['thumbnail'];
}
$tags = get_the_tags($featured->ID);
$tags2 = '';
if ($tags)
foreach($tags as $tag) {
$tags2 .= '
' . $tag->name . ' , ';
}
$tags2 = trim($tags2, ', ');
$content = $featured->post_content;
if (strpos($content, '')) {
$content = substr($content, 0, strpos($content, '')) . '
(more...) ';
}
$content = apply_filters('the_content', $content);
$thumbnail = get_post_thumbnail_id($featured->ID);
$thumbnail = wp_get_attachment_image_src($thumbnail, $thumbnail_size);
global $post;
$post = $featured;
$tmp = str_replace(array('{id}',
'{permalink}',
'{title}',
'{excerpt}',
'{content-full}',
'{content}',
'{author}',
'{author-link}',
'{date}',
'{time}',
'{comments-count}',
'{categories}',
'{tags}',
'{thumbnail}',
'{thumbnail-src}',
'{thumbnail-width}',
'{thumbnail-height}',
'{slider-width}'),
array($featured->ID,
get_permalink($featured->ID),
$featured->post_title,
apply_filters('the_excerpt', $featured->post_excerpt),
apply_filters('the_content', $featured->post_content),
$content,
get_the_author_meta('display_name', $featured->post_author),
get_author_posts_url($featured->post_author),
get_the_date(''),
get_the_time(''),
(int) $featured->comments_count,
get_the_category_list(', ', '', $featured->ID),
$tags2,
get_the_post_thumbnail($featured->ID, $thumbnail_size, array('class' => 'fps-thumbnail')),
$thumbnail[0],
$thumbnail[1],
$thumbnail[2],
$options['width']), $template);
if ($slide_nb != 1) {
$tmp_display = 'display: none; ';
} else {
$tmp_display = '';
}
$out .= '
' . $tmp . '
';
$slide_nb++;
} // foreach post
$out .= '
';
if ($options['pagination'] == 2) {
$out .= '';
}
$out .= "
\n";
// include JS/CSS only if needed
if ($featured_posts) {
self::$do_footer = true;
}
return $out;
} // generate_html
// shortcode for FPS, just a wrapper
function shortcode($options, $content) {
return self::generate_html();
} // shortcode
// slides JS code for footer
function wp_footer() {
if (!self::$do_footer) {
return;
}
$options = get_option('wf_fps');
$preload_img = plugins_url('/images/preload.gif', __FILE__);
if($options['include-css']) {
$slides_css = plugins_url('/css/featured-posts-slider.css?v4', __FILE__);
echo '\n";
}
if($options['include-jquery']) {
$jquery_js = plugins_url('/js/jquery-1.6.2.min.js', __FILE__);
echo '' . "\n";
}
if($options['include-slides']) {
$slides_js = plugins_url('/js/slides.min.jquery.js', __FILE__);
echo '' . "\n";
}
echo '\n";
} // wp_footer
// warning if [fps] shortcode is already taken
public function warning() {
$shortcode = get_option('wf_fps');
$shortcode = $shortcode['shortcode'];
echo 'Featured Posts Slider shortcode is not active! The shortcode [' . $shortcode . '] is already in use by another plugin. Please update the settings and select a different shortcode.
';
} // warning
} // class wf_fps
// template function, echoes slider code
function the_featured_posts_slider() {
echo wf_fps::generate_html();
} // the_featured_posts_slider
// template function, returns slider code
function get_the_featured_posts_slider() {
return wf_fps::generate_html();
} // get_the_featured_posts_slider
// hook Featured Posts Plugin
add_action('init', array('wf_fps', 'init'));
add_action('after_setup_theme', array('wf_fps', 'add_thumb_support'));
?>