| Current Path : /home/ereika83/www/wp-content/plugins/genesis-club-pro/classes/ |
| Current File : /home/ereika83/www/wp-content/plugins/genesis-club-pro/classes/class-post-pro.php |
<?php
class Genesis_Club_Post_Pro extends Genesis_Club_Post {
private $post_id;
function init() {
parent::init();
add_action('widgets_init', array($this,'register_pro_widgets'));
add_action('wp', array($this,'prepare'));
}
function register_pro_widgets() {
register_widget( 'Genesis_Club_Post_Icons_Widget' );
}
function prepare() {
if (is_singular() || is_archive())
add_filter('genesis_post_title_output', array($this, 'add_subtitle'), 10, version_compare(PARENT_THEME_VERSION, '2.4') == -1 ? 1 : 3);
}
function add_subtitle($output, $wrap='', $title ='' ) {
if (($post_id = $this->utils->get_post_id())
&& ($subtitle = get_post_meta($post_id, self::SUBTITLE_META_KEY, true))) {
if ($wrap)
$subtitle_wrap = 'h2' == $wrap ? 'h3' : 'h2';
else
$subtitle_wrap = strpos($output, '<h2') !== FALSE ? 'h3' : 'h2';
$output .= sprintf('<%2$s class="genesis-club-subtitle">%1$s</%2$s>', $subtitle, $subtitle_wrap);
}
return $output;
}
}
class Genesis_Club_Post_Icons_Widget extends Genesis_Club_Post_Widget {
const ICON_META_KEY = '_genesis_club_post_icon';
private $post;
private $tips = array(
'show_title' => array('heading' => 'Show Title', 'tip' => 'Show Title'),
'show_excerpt' => array('heading' => 'Show Excerpt', 'tip' => 'Show official excerpt of post'),
'show_content' => array('heading' => 'Show Content', 'tip' => 'Show some content from the post'),
'show_limit' => array('heading' => 'Character Limit', 'tip' => 'Number of characters to show from content of the post'),
'content_class' => array('heading' => 'Content Classes', 'tip' => 'Optionally add some classes to the entry content. Examples are aligncenter or alignjustify'),
'show_more' => array('heading' => 'Show More Link', 'tip' => 'Show more link'),
'more_link' => array('heading' => 'More Link Text', 'tip' => 'Supply text to go on the more link or leave blank to not have a link'),
'more_class' => array('heading' => 'More Link Classes', 'tip' => 'Optionally add some classes to the more link for styling purposes'),
'no_links' => array('heading' => 'No Links', 'tip' => 'Do not link back to post from either the title or the icon'),
'icon_size' => array('heading' => 'Icon Size', 'tip' => 'Size of icon to show above or alongside the post excerpt'),
'icon_align' => array('heading' => 'Icon Alignment', 'tip' => 'Horizontal alignment of icon'),
'icon_title' => array('heading' => 'Icon Title', 'tip' => 'The short title of the post appears with the icon'),
'icon_color' => array('heading' => 'Icon Color', 'tip' => 'Default icon color (may be overriden if supplied in the post)'),
'icon_custom' => array('heading' => 'Custom Code', 'tip' => 'Default custom code. You can use a shortcode here to display an image, slideshow, video, etc. Value will normally be overriden on individual posts.'),
'source_type' => array('heading' => 'Source', 'tip' => 'Choosing <i>Specific term</i> means that the selection can be based on a specific category, tag or other taxonomy term,<br/><i>Specific list of posts</i> is choice based on post ID,<br/>,<i>Current context</i> means they are chosen based on the current page so on a category archive page the selection is based on posts in that category <br/><i>Current top parent</i> means that posts are chosen based the same top level category as the current post'),
'post_type' => array('heading' => 'Post Type', 'tip' => 'Would you like to use posts or pages?'),
'posts_term' => array('heading' => 'Terms To Include', 'tip' => 'Select the posts for inclusion'),
'exclude_terms' => array('heading' => 'Terms To Exclude', 'tip' => 'List which category, tag or other taxonomy IDs to exclude. (1,2,3,4 for example)'),
'include_exclude' => array('heading' => 'Include/Exclude', 'tip' => 'Choose whether to include or exclude the posts below from your slider'),
'exclude_displayed' => array('heading' => 'Exclude Previous Posts', 'tip' => 'Choose whether to exclude posts earlier on the page to avoid repetition'),
'post_id' => array('heading' => 'Post IDs', 'tip' => 'List which post IDs to include / exclude. (1,2,3,4 for example'),
'posts_num' => array('heading' => '# of posts to show', 'tip' => 'Show up to a maximum of this number of posts'),
'posts_per_row' => array('heading' => '# of posts per row', 'tip' => 'Number of posts to show per row on a medium to large device'),
'posts_offset' => array('heading' => '# of posts to offset', 'tip' => 'Return content from posts not from the first post but with an offset'),
'orderby' => array('heading' => 'Order by', 'tip' => 'Choose the order in which you wants the posts to be displayed'),
'direction' => array('heading' => 'Order', 'tip' => 'Ascending or descending order'),
);
private $defaults = array('title' => '',
'show_title' => false,
'show_excerpt' => false,
'show_content' => false,
'show_limit' => false,
'content_class' => '',
'show_more' => false,
'more_link' => '',
'more_class' => '',
'no_links' => false,
'icon_class' => 'fa-cog',
'icon_size' => 'fa-3x',
'icon_align' => 'none',
'icon_color' => '#000',
'icon_title' => '',
'icon_custom' => '',
'source_type' => '',
'post_type' => 'post',
'posts_term' => '',
'exclude_terms' => '',
'include_exclude' => '',
'posts_num' => 4,
'posts_per_row' => 4,
'posts_offset' => 0,
'post_id' => '',
'orderby' => 'date',
'direction' => 'desc'
) ;
static function get_post_icon_defaults() {
return array('title' => '', 'class' => '', 'color' => '', 'alt' => '', 'custom' => '') ;
}
private $css = '';
function icon_sizes() {
return array(
'' => __('Normal size', GENESIS_CLUB_DOMAIN ),
'fa-lg' => __('Slightly larger size', GENESIS_CLUB_DOMAIN ),
'fa-2x' => __('Double size', GENESIS_CLUB_DOMAIN ),
'fa-3x' => __('Triple size', GENESIS_CLUB_DOMAIN ),
'fa-4x' => __('Quadruple size', GENESIS_CLUB_DOMAIN ),
'fa-5x' => __('Quintuple size', GENESIS_CLUB_DOMAIN ),
);
}
function __construct() {
$widget_ops = array(
'classname' => 'genesis-club-posts genesis-club-post-icons featured-content',
'description' => __( "Display selected featured posts/custom posts using post excerpts/content with icons", GENESIS_CLUB_DOMAIN ) );
$control_ops = array('width' => 420, 'height' => 500);
parent::__construct('genesis-club-post-icons', __('Genesis Club Post Icons', GENESIS_CLUB_DOMAIN), $widget_ops, $control_ops);
$this->post = $this->plugin->get_module('post');
$this->set_defaults($this->defaults);
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
}
function enqueue_styles() {
if (is_active_widget( false, false, $this->id_base, true )) {
wp_enqueue_style( 'genesis-club-post-widgets', plugins_url( 'styles/post-widgets.css', dirname(__FILE__)), array(), GENESIS_CLUB_VERSION );
$this->utils->register_icons_font();
}
}
function widget( $args, $instance ) {
global $_genesis_displayed_ids;
$instance = wp_parse_args( (array) $instance, $this->get_defaults() );
$args = $this->override_args($args, $instance) ;
extract( $args );
$is_list = $instance['show_title']
&& !(isset($instance['show_excerpt']) && $instance['show_excerpt'])
&& !(isset($instance['show_content']) && $instance['show_content'])
&& ($instance['icon_align'] != 'aligncenter');
$post_list = '';
$posts = $this->get_selected_posts($instance);
while ( $posts->have_posts()) : $posts->the_post();
$post_id = get_the_ID();
$_genesis_displayed_ids[] = $post_id;
$permalink = get_permalink($post_id);
$title = $this->get_post_title_text($post_id);
$post_title = $this->get_post_title($instance, $title, $permalink);
$icon_meta = $this->utils->get_meta($post_id, self::ICON_META_KEY) ;
$post_icon = $this->get_post_icon($instance, esc_attr($title), $permalink, $icon_meta );
$post_excerpt = $this->get_post_excerpt($instance);
if ($instance['show_excerpt'] || $instance['show_content'] )
$post_list .= $this->format_post_excerpt($post_title, $post_icon, $post_excerpt) ;
elseif ($is_list)
$post_list .= $this->format_list_icon($post_title, $post_icon) ;
else
$post_list .= $this->format_post_icon($post_title, $post_icon) ;
endwhile;
wp_reset_query();
if (!empty($post_list)) {
$format = $is_list ? '%1$s<ul>%2$s</ul>%3$s': '%1$s%2$s%3$s';
printf($format, $before_widget, $post_list, $after_widget);
}
}
function update( $new_instance, $old_instance ) {
$instance = $this->update_instance( $new_instance, $old_instance );
$instance['show_title'] = !empty($new_instance['show_title']);
$instance['show_excerpt'] = !empty($new_instance['show_excerpt']);
$instance['show_content'] = !empty($new_instance['show_content']);
$instance['show_limit'] = $new_instance['show_limit'];
$instance['content_class'] = $this->utils->clean_css_classes($new_instance['content_class']);
$instance['show_more'] = !empty($new_instance['show_more']);
$instance['more_link'] = trim($new_instance['more_link']);
$instance['more_class'] = $this->utils->clean_css_classes($new_instance['more_class']);
$instance['no_links'] = !empty($new_instance['no_links']);
$instance['icon_size'] = strip_tags( $new_instance['icon_size']);
$instance['icon_align'] = $new_instance['icon_align'] ;
$instance['icon_color'] = $new_instance['icon_color'] ;
$instance['icon_custom'] = $new_instance['icon_custom'] ;
$instance['source_type'] = $new_instance['source_type'];
$instance['post_type'] = $new_instance['post_type'] ;
$instance['posts_term'] = $new_instance['posts_term'] ;
$instance['exclude_terms'] = $new_instance['exclude_terms'] ;
$instance['exclude_displayed'] = !empty($new_instance['exclude_displayed']) ;
$instance['include_exclude'] = $new_instance['include_exclude'] ;
$instance['posts_num'] = !empty($new_instance['posts_num']) ? $new_instance['posts_num'] : 4 ;
$instance['posts_per_row'] = !empty($new_instance['posts_per_row']) ? $new_instance['posts_per_row'] : 1 ;
$instance['posts_offset'] = !empty($new_instance['posts_offset']) ? $new_instance['posts_offset'] :0;
$instance['post_id'] = $new_instance['post_id'] ;
$instance['orderby'] = $new_instance['orderby'] ;
$instance['direction'] = $new_instance['direction'] ;
return $instance;
}
function form( $instance ) {
$this->form_init ($instance, $this->tips);
print('<h4>General Settings</h4>');
$this->print_form_field('show_title', 'checkbox');
$this->print_form_field('show_excerpt', 'checkbox');
$this->print_form_field('show_content', 'checkbox');
$this->print_form_field('show_limit', 'text', array(), array('size' => 5));
$this->print_form_field('content_class', 'text', array(), array('size' => 20));
$this->print_form_field('show_more', 'checkbox');
$this->print_form_field('more_link', 'text', array(), array('size' => 20));
$this->print_form_field('more_class', 'text', array(), array('size' => 20));
$this->print_form_field('no_links', 'checkbox');
print ('<hr/><h4>Icon Defaults</h4>');
$this->print_form_field('icon_size', 'select', $this->icon_sizes());
$this->print_form_field('icon_align', 'select', $this->align_options());
$this->print_form_field('icon_color', 'text', array(), array('class' => 'color-picker'));
$this->print_form_field('icon_custom', 'textarea', array(), array('class' => 'large-text', 'rows' => 3));
print ('<hr/><h4>Post Selection</h4>');
$this->print_form_field('post_type', 'select', $this->post_type_options());
$this->print_form_field('source_type', 'select', $this->source_type_options());
print ('<hr/>Include or Exclude by Terms');
$this->print_form_field('posts_term','select', $this->taxonomy_options('posts_term'), array('multiple' => true));
$this->print_form_field('exclude_terms', 'text', array(), array('size' => 20));
print ('<hr/>Include or Exclude by Post ID');
$this->print_form_field('include_exclude', 'select', array('include' => 'Include', 'exclude' => 'Exclude'));
$this->print_form_field('post_id', 'text', array(), array('size' => 20));
$this->print_form_field('exclude_displayed', 'checkbox');
print ('<hr/><h4>Numbers And Ordering</h4>');
$this->print_form_field('posts_num', 'text', array(), array('size' => 4));
$this->print_form_field('posts_per_row', 'radio', array('1' => 1, '2' => '2', '3' => 3, '4' => 4 ));
$this->print_form_field('posts_offset', 'text', array(), array('size' => 4));
$this->print_form_field('orderby', 'select', $this->sort_options());
$this->print_form_field('direction', 'select', array('asc' => 'Ascending', 'desc' => 'Descending'));
}
}