path_web = is_object( $bsuite ) ? $bsuite->path_web : get_template_directory_uri(); add_action( 'init', array( &$this, 'init' )); add_action( 'preprocess_comment' , array( &$this, 'preprocess_comment' ), 1 ); add_action( 'bsuite_response_sendmessage' , array( &$this, 'sendmessage' ), 1, 2 ); add_action( 'template_redirect' , array( &$this, 'get_default_posts' ), 0 ); } function init() { if( function_exists( 'add_image_size' )) { add_image_size( 'nines-thumbnail-small' , 100 , 100 , TRUE ); add_image_size( 'nines-thumbnail-wide' , 200 , 150 , TRUE ); } $this->get_instances(); $this->get_templates( 'post' ); $this->get_templates( 'response' ); add_action( 'admin_init', array(&$this, 'admin_init' )); // add_filter( 'posts_request' , array( &$this , 'posts_request' )); } function admin_init() { wp_register_script( 'postloop-editwidgets', $this->path_web . '/components/js/edit_widgets.js', array('jquery'), '1' ); wp_enqueue_script( 'postloop-editwidgets' ); add_action( 'admin_footer', array( &$this, 'footer_activatejs' )); } public function footer_activatejs(){ ?> posts as $post ) { // get the matching post IDs for the $postloops object $this->posts[-1][ $blog_id ][] = $post->ID; // get the matching terms by taxonomy $terms = get_object_term_cache( $post->ID, (array) get_object_taxonomies( $post->post_type ) ); if ( empty( $terms )) $terms = wp_get_object_terms( $post->ID, (array) get_object_taxonomies( $post->post_type ) ); // get the term taxonomy IDs for the $postloops object foreach( $terms as $term ) $this->terms[-1][ $term->taxonomy ][ $term->term_id ]++; } } function get_instances() { global $blog_id; $options = get_option( 'widget_postloop' ); // add an entry for the default conent $options[-1] = array( 'title' => 'The default content', 'blog' => absint( $blog_id ), ); foreach( $options as $number => $option ) { if( is_integer( $number )) { $option['title'] = empty( $option['title'] ) ? 'Instance #'. $number : wp_filter_nohtml_kses( $option['title'] ); $this->instances[ $number ] = $option; } } return $this->instances; } function get_instances_response() { global $blog_id; $options = get_option( 'widget_responseloop' ); // add an entry for the default conent $options[-1] = array( 'title' => 'The default content', 'blog' => absint( $blog_id ), ); foreach( $options as $number => $option ) { if( is_integer( $number )) { $option['title'] = empty( $option['title'] ) ? 'Instance #'. $number : wp_filter_nohtml_kses( $option['title'] ); $this->instances_response[ md5( (string) $number . $option['template'] . $option['email'] ) ] = $option; } } return $this->instances_response; } function get_templates_readdir( $template_base ) { $page_templates = array(); $template_dir = @ dir( $template_base ); if ( $template_dir ) { while ( ( $file = $template_dir->read() ) !== false ) { if ( preg_match('|^\.+$|', $file )) continue; if ( preg_match('|\.php$|', $file )) { $template_data = implode( '', file( $template_base . $file )); $name = ''; if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name )) $name = _cleanup_header_comment( $name[1] ); $wrapper = FALSE; if ( preg_match( '|Wrapper:(.*)$|mi', $template_data )) // any value here will set it true $wrapper = TRUE; if ( !empty( $name ) ) { $file = basename( $file ); $page_templates[ $file ]['name'] = trim( $name ); $page_templates[ $file ]['file'] = basename( $file ); $page_templates[ $file ]['fullpath'] = $template_base . $file; $page_templates[ $file ]['wrapper'] = $wrapper; } } } @$template_dir->close(); } return $page_templates; } function get_templates( $type = 'post' ) { $type = sanitize_file_name( $type ); $type_var = "templates_$type"; if( isset( $this->$type_var )) return $this->$type_var; $this->$type_var = array_merge( (array) $this->get_templates_readdir( dirname( dirname( __FILE__ )) .'/templates-'. $type .'/' ), (array) $this->get_templates_readdir( TEMPLATEPATH . '/templates-'. $type .'/' ), (array) $this->get_templates_readdir( STYLESHEETPATH . '/templates-'. $type .'/' ) ); return $this->$type_var; } function preprocess_comment( $comment ) { $this->get_instances_response(); do_action( 'bsuite_response_'. sanitize_title_with_dashes( preg_replace( '/\.[^\.]*$/' , '', $this->instances_response[ $_REQUEST['bsuite_responsekey'] ]['template'] )), $comment, $this->instances_response[ $_REQUEST['bsuite_responsekey'] ] ); return( $comment ); } function sendmessage( $comment , $input ) { add_action( 'comment_post', array( &$this, '_sendmessage' )); add_filter( 'pre_comment_approved', create_function( '$a', 'return \'message\';'), 1 ); } function _sendmessage( $comment_id , $approved ) { if ( 'spam' == $approved ) return; $also_notify = sanitize_email( $this->instances_response[ $_REQUEST['bsuite_responsekey'] ]['email'] ); $comment = get_comment( $comment_id ); $post = get_post( $comment->comment_post_ID ); $user = get_userdata( $post->post_author ); $current_user = wp_get_current_user(); if(( '' == $also_notify ) && ('' == $user->user_email )) return false; // If there's no email to send the comment to $comment_author_domain = @gethostbyaddr( $comment->comment_author_IP ); $blogname = get_option('blogname'); /* translators: 1: post id, 2: post title */ $notify_message = sprintf( __('New message on %2$s (#%1$s)'), $comment->comment_post_ID, $post->post_title ) . "\r\n\r\n"; $notify_message .= $comment->comment_content . "\r\n\r\n"; /* translators: 1: comment author, 2: author IP, 3: author domain */ $notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n"; $notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n"; $notify_message .= sprintf( __('URL : %s'), $comment->comment_author_url ) . "\r\n"; $notify_message .= __('Network location:') . "\r\nhttp://ws.arin.net/cgi-bin/whois.pl?queryinput=$comment->comment_author_IP\r\n\r\n"; // $notify_message .= __('You can see all messages on this post here: ') . "\r\n"; // $notify_message .= admin_url( '/wp-admin/edit-comments.php?p='. $post->ID ) ."\r\n\r\n"; /* translators: 1: blog name, 2: post title */ $subject = sprintf( __('[%1$s] Message on "%2$s"'), $blogname, $post->post_title ); $wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); if ( '' == $comment->comment_author ) { $from = "From: \"$blogname\" <$wp_email>"; if ( '' != $comment->comment_author_email ) $reply_to = "Reply-To: $comment->comment_author_email"; } else { $from = "From: \"$comment->comment_author\" <$wp_email>"; if ( '' != $comment->comment_author_email ) $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; } $message_headers = "$from\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; if ( isset( $reply_to )) $message_headers .= $reply_to . "\n"; $notify_message = apply_filters('comment_notification_text', $notify_message, $comment_id); $subject = apply_filters('comment_notification_subject', $subject, $comment_id); $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); if( '' <> $also_notify ) @wp_mail( $also_notify , $subject , $notify_message , $message_headers ); if( $user->user_email ) @wp_mail( $user->user_email , $subject , $notify_message , $message_headers ); die( wp_redirect( get_comment_link( $comment_id ))); } function restore_current_blog() { if ( function_exists('restore_current_blog') ) return restore_current_blog(); return TRUE; } function posts_where_comments_yes_once( $sql ) { remove_filter( 'posts_where', array( &$this , 'posts_where_comments_yes_once' ), 10 ); return $sql . ' AND comment_count > 0 '; } function posts_where_comments_no_once( $sql ) { remove_filter( 'posts_where', array( &$this , 'posts_where_comments_no_once' ), 10 ); return $sql . ' AND comment_count < 1 '; } function posts_where_date_since_once( $sql ) { remove_filter( 'posts_where', array( &$this , 'posts_where_date_since_once' ), 10 ); return $sql . ' AND post_date > "'. $this->date_since .'"'; } function posts_where_date_before_once( $sql ) { remove_filter( 'posts_where', array( &$this , 'posts_where_date_since_once' ), 10 ); return $sql . ' AND post_date < "'. $this->date_before .'"'; } function posts_join_recently_popular_once( $sql ) { global $wpdb, $blog_id, $bsuite; remove_filter( 'posts_join', array( &$this , 'posts_join_recently_popular_once' ), 10 ); return " INNER JOIN $bsuite->hits_pop AS popsort ON ( popsort.blog_id = $blog_id AND popsort.hits_recent > 0 AND $wpdb->posts.ID = popsort.post_ID ) ". $sql; } function posts_orderby_recently_popular_once( $sql ) { remove_filter( 'posts_orderby', array( &$this , 'posts_orderby_recently_popular_once' ), 10 ); return ' popsort.hits_recent DESC, '. $sql; } function posts_fields_recently_commented_once( $sql ) { remove_filter( 'posts_fields', array( &$this , 'posts_fields_recently_commented_once' ), 10 ); return $sql. ', MAX( commentsort.comment_date_gmt ) AS commentsort_order '; } function posts_join_recently_commented_once( $sql ) { global $wpdb; remove_filter( 'posts_join', array( &$this , 'posts_join_recently_commented_once' ), 10 ); return " INNER JOIN $wpdb->comments AS commentsort ON ( commentsort.comment_approved = 1 AND $wpdb->posts.ID = commentsort.comment_post_ID ) ". $sql; } function posts_groupby_recently_commented_once( $sql ) { global $wpdb; remove_filter( 'posts_groupby', array( &$this , 'posts_groupby_recently_commented_once' ), 10 ); return $wpdb->posts .'.ID' . ( empty( $sql ) ? '' : ', ' ); } function posts_orderby_recently_commented_once( $sql ) { remove_filter( 'posts_orderby', array( &$this , 'posts_orderby_recently_commented_once' ), 10 ); return ' commentsort_order DESC, '. $sql; } function posts_request( $request ) { echo $request; return $request; } } //end bSuite_PostLoops // initialize that class global $postloops; $postloops = new bSuite_PostLoops(); /** * PostLoop Scroller class * */ class bSuite_PostLoop_Scroller { function __construct( $args = '' ) { // get settings $defaults = array( // configuration 'actionname' => 'postloop_f_default_scroller', 'selector' => '.scrollable', 'lazy' => FALSE, 'css' => TRUE, // scrollable options 'keyboard' => TRUE, // FALSE or 'static' 'circular' => TRUE, 'vertical' => FALSE, 'mousewheel' => FALSE, // scrollable plugins 'navigator' => TRUE, // FALSE or selector (html id or classname) 'autoscroll' => array( 'interval' => 2500, 'autoplay' => TRUE, 'autopause' => TRUE, 'steps' => 1, ) ); $this->settings = (object) wp_parse_args( (array) $args , (array) $defaults ); // get the path to our scripts and styles global $bsuite; $this->path_web = is_object( $bsuite ) ? $bsuite->path_web : get_template_directory_uri(); // register scripts and styles wp_register_script( 'scrollable', $this->path_web . '/components/js/scrollable.min.js', array('jquery'), TRUE ); wp_register_style( 'scrollable', $this->path_web .'/components/css/scrollable.css' ); // register our hook to the named action add_action( $this->settings->actionname , array( &$this, 'do_postloop' ) , 5 , 3 ); } function do_postloop( $action , $ourposts , $postloops ) { switch( $action ) { case 'before': late_enqueue_script( 'scrollable' ); if( $this->settings->css ) late_enqueue_style( 'scrollable' ); add_filter( 'print_footer_scripts', array( $this, 'print_js' )); break; } } function print_js() { //$(".scroller").scrollable({circular: true}).navigator("#myNavi").autoscroll({interval: 4000}); //navigator(".navi"); ?> 'widget_postloop', 'description' => __( 'Build your own post loop') ); $this->WP_Widget('postloop', __('Post Loop'), $widget_ops); global $postloops; $this->post_templates = &$postloops->templates_post; add_filter( 'wijax-actions' , array( $this , 'wjiax_actions' ) ); } function wjiax_actions( $actions ) { global $postloops, $mywijax; foreach( $postloops->instances as $k => $v ) $actions[ $mywijax->encoded_name( 'postloop-'. $k ) ] = (object) array( 'key' => 'postloop-'. $k , 'type' => 'widget'); return $actions; } function widget( $args, $instance ) { global $bsuite, $postloops, $wpdb, $blog_id, $mywijax; $this->wijax_varname = $mywijax->encoded_name( $this->id ); extract( $args ); $title = apply_filters('widget_title', empty( $instance['title'] ) ? '' : $instance['title']); if( 'normal' == $instance['what'] ){ wp_reset_query(); global $wp_query; $ourposts = &$wp_query; }else{ // $criteria['suppress_filters'] = TRUE; if( in_array( $instance['what'], array( 'post', 'page', 'attachment' ))) $criteria['post_type'] = $instance['what']; if( $instance['what'] == 'attachment' ) $criteria['post_status'] = 'inherit'; if( !empty( $instance['categories_in'] )) $criteria['category__'. ( in_array( $instance['categoriesbool'], array( 'in', 'and', 'not_in' )) ? $instance['categoriesbool'] : 'in' ) ] = array_keys( (array) $instance['categories_in'] ); if( $instance['categories_in_related'] ) $criteria['category__'. ( in_array( $instance['categoriesbool'], array( 'in', 'and', 'not_in' )) ? $instance['categoriesbool'] : 'in' ) ] = array_merge( (array) $criteria['category__'. ( in_array( $instance['categoriesbool'], array( 'in', 'and', 'not_in' )) ? $instance['categoriesbool'] : 'in' ) ], (array) array_keys( (array) $postloops->terms[ $instance['categories_in_related'] ]['category'] ) ); if( !empty( $instance['categories_not_in'] )) $criteria['category__not_in'] = array_keys( (array) $instance['categories_not_in'] ); if( $instance['categories_not_in_related'] ) $criteria['category__not_in'] = array_merge( (array) $criteria['category__not_in'] , (array) array_keys( (array) $postloops->terms[ $instance['categories_not_in_related'] ]['category'] )); if( !empty( $instance['tags_in'] )) $criteria['tag__'. ( in_array( $instance['tagsbool'], array( 'in', 'and', 'not_in' )) ? $instance['tagsbool'] : 'in' ) ] = $instance['tags_in']; if( $instance['tags_in_related'] ) $criteria['tag__'. ( in_array( $instance['tagsbool'], array( 'in', 'and', 'not_in' )) ? $instance['tagsbool'] : 'in' ) ] = array_merge( (array) $criteria['tag__'. ( in_array( $instance['tagsbool'], array( 'in', 'and', 'not_in' )) ? $instance['tagsbool'] : 'in' ) ], (array) array_keys( (array) $postloops->terms[ $instance['tags_in_related'] ]['post_tag'] ) ); if( !empty( $instance['tags_not_in'] )) $criteria['tag__not_in'] = $instance['tags_not_in']; if( $instance['tags_not_in_related'] ) $criteria['tag__not_in'] = array_merge( (array) $criteria['tag__not_in'] , (array) array_keys( (array) $postloops->terms[ $instance['tags_not_in_related'] ]['post_tag'] )); foreach( get_object_taxonomies( $instance['what'] ) as $taxonomy ) { if( $taxonomy == 'category' || $taxonomy == 'post_tag' ) continue; if( !empty( $instance['tax_'. $taxonomy .'_in'] )) $criteria['tax_'. $taxonomy .'_in'] = $instance['tax_'. $taxonomy .'_in']; if( !empty( $instance['tax_'. $taxonomy .'_not_in'] )) $criteria['tax_'. $taxonomy .'_not_in'] = $instance['tax_'. $taxonomy .'_not_in']; } if( !empty( $instance['post__in'] )) $criteria['post__in'] = $instance['post__in']; if( !empty( $instance['post__not_in'] )) $criteria['post__not_in'] = $instance['post__not_in']; switch( $instance['comments'] ) { case 'yes': add_filter( 'posts_where', array( &$postloops , 'posts_where_comments_yes_once' ), 10 ); break; case 'no': add_filter( 'posts_where', array( &$postloops , 'posts_where_comments_no_once' ), 10 ); break; default: break; } foreach ( get_object_taxonomies('post') as $taxonomy ) { $criteria[$taxonomy] = apply_filters('ploop_taxonomy_'. $taxonomy, $criteria[$taxonomy]); } if( 0 < $instance['age_num'] ) { $postloops->date_before = $postloops->date_since = date( 'Y-m-d' , strtotime( $instance['age_num'] .' '. $instance['age_unit'] .' ago' )); if( $instance['age_bool'] == 'older' ) add_filter( 'posts_where', array( &$postloops , 'posts_where_date_before_once' ), 10 ); else add_filter( 'posts_where', array( &$postloops , 'posts_where_date_since_once' ), 10 ); } if( $_GET['wijax'] && absint( $_GET['paged'] )) $criteria['paged'] = absint( $_GET['paged'] ); $criteria['showposts'] = absint( $instance['count'] ); switch( $instance['order'] ){ case 'age_new': $criteria['orderby'] = 'date'; $criteria['order'] = 'DESC'; break; case 'age_old': $criteria['orderby'] = 'date'; $criteria['order'] = 'ASC'; break; case 'title_az': $criteria['orderby'] = 'title'; $criteria['order'] = 'ASC'; break; case 'title_za': $criteria['orderby'] = 'title'; $criteria['order'] = 'DESC'; break; case 'comment_new': add_filter( 'posts_fields', array( &$postloops , 'posts_fields_recently_commented_once' ), 10 ); add_filter( 'posts_join', array( &$postloops , 'posts_join_recently_commented_once' ), 10 ); add_filter( 'posts_groupby', array( &$postloops , 'posts_groupby_recently_commented_once' ), 10 ); add_filter( 'posts_orderby', array( &$postloops , 'posts_orderby_recently_commented_once' ), 10 ); break; case 'pop_recent': if( is_object( $bsuite )) { add_filter( 'posts_join', array( &$postloops , 'posts_join_recently_popular_once' ), 10 ); add_filter( 'posts_orderby', array( &$postloops , 'posts_orderby_recently_popular_once' ), 10 ); break; } case 'rand': $criteria['orderby'] = 'rand'; break; default: $criteria['orderby'] = 'post_date'; $criteria['order'] = 'DESC'; break; } if( 'excluding' == $instance['relationship'] && count( (array) $instance['relatedto'] )) { foreach( $instance['relatedto'] as $related_loop => $temp ) { if( isset( $postloops->posts[ $related_loop ] ) && $instance['blog'] == key( $postloops->posts[ $related_loop ] )) $criteria['post__not_in'] = array_merge( (array) $criteria['post__not_in'] , $postloops->posts[ $related_loop ][ $instance['blog'] ] ); else echo ''; } } else if( 'similar' == $instance['relationship'] && count( (array) $instance['relatedto'] )) { if( ! class_exists( 'bSuite_bSuggestive' ) ) require_once( dirname( __FILE__) .'/bsuggestive.php' ); foreach( $instance['relatedto'] as $related_loop => $temp ) { if( isset( $postloops->posts[ $related_loop ] ) && $instance['blog'] == key( $postloops->posts[ $related_loop ] )) $posts_for_related = array_merge( (array) $posts_for_related , $postloops->posts[ $related_loop ][ $instance['blog'] ] ); else echo ''; } $count = ceil( 1.5 * $instance['count'] ); if( 10 > $count ) $count = 10; $criteria['post__in'] = array_merge( (array) $instance['post__in'] , array_slice( (array) bSuite_bSuggestive::getposts( $posts_for_related ) , 0 , $count ) ); } //echo '
'. print_r( $instance , TRUE ) .''; //echo '
'. print_r( $criteria , TRUE ) .''; if( 0 < $instance['blog'] && $instance['blog'] !== $blog_id ) switch_to_blog( $instance['blog'] ); // switch to the other blog $ourposts = new WP_Query( $criteria ); //print_r( $ourposts ); } if( $ourposts->have_posts() ){ $postloops->current_postloop = $instance; $postloops->thumbnail_size = isset( $instance['thumbnail_size'] ) ? $instance['thumbnail_size'] : 'nines-thumbnail-small'; $extra_classes = array(); $extra_classes[] = str_replace( '9spot', 'nines' , sanitize_title_with_dashes( $this->post_templates[ $instance['template'] ]['name'] )); $extra_classes[] = 'widget-post_loop-'. sanitize_title_with_dashes( $instance['title'] ); echo str_replace( 'class="', 'class="'. implode( ' ' , $extra_classes ) .' ' , $before_widget ); $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'] ); if ( $instance['title_show'] && $title ) echo $before_title . $title . $after_title .''; $action_name = sanitize_title( basename( $this->post_templates[ $instance['template'] ]['fullpath'] , '.php' )); $action_name = empty( $action_name ) ? 'postloop' : 'postloop_'. $action_name; if( ! empty( $instance['template'] ) && isset( $this->post_templates[ $instance['template'] ] ) ) { $has_wrapper = $this->post_templates[ $instance['template'] ]['wrapper']; if( $has_wrapper && (! @include preg_replace( '/\.php$/', '_before.php', $this->post_templates[ $instance['template'] ]['fullpath'] ))) echo ''; }//end if $offset_run = $offset_now = 1; do_action( $action_name , 'before' , $ourposts , $postloops ); while( $ourposts->have_posts() ) { unset( $GLOBALS['pages'] ); // to address ticket: http://core.trac.wordpress.org/ticket/12651 $ourposts->the_post(); // weird feature to separate a single postloop into multiple widgets // set where in the loop we start the output if( ! empty( $instance['offset_start'] ) && ($instance['offset_start'] > $offset_now) ) { $offset_now ++; continue; } // set how many we display if( ! empty( $instance['offset_run'] ) && ($instance['offset_run'] < $offset_run) ) { continue; } $offset_run ++; global $id, $post; $instance['blog'] = absint( $instance['blog'] ); // get the matching post IDs for the $postloops object $postloops->posts[ $this->number ][ $instance['blog'] ][] = $id; // get the matching terms by taxonomy $terms = get_object_term_cache( $id, (array) get_object_taxonomies( $post->post_type ) ); if ( empty( $terms )) $terms = wp_get_object_terms( $id, (array) get_object_taxonomies( $post->post_type ) ); // get the term taxonomy IDs for the $postloops object foreach( $terms as $term ) $postloops->terms[ $this->number ][ $term->taxonomy ][ $term->term_id ]++; do_action( $action_name , 'post' , $ourposts , $postloops ); if( empty( $instance['template'] ) || !include $this->post_templates[ $instance['template'] ]['fullpath'] ) { ?> post_templates[ $instance['template'] ]['fullpath'] )) echo ''; }//end if do_action( $action_name , 'after' , $ourposts , $postloops ); echo $after_widget; } $postloops->restore_current_blog(); unset( $postloops->current_postloop ); //print_r( $postloops ); } function update( $new_instance, $old_instance ) { global $blog_id; $instance = $old_instance; $instance['title'] = wp_filter_nohtml_kses( $new_instance['title'] ); $instance['subtitle'] = wp_filter_nohtml_kses( $new_instance['subtitle'] ); $instance['title_show'] = absint( $new_instance['title_show'] ); $instance['what'] = in_array( $new_instance['what'], array( 'normal', 'post', 'page', 'attachment', 'any') ) ? $new_instance['what']: ''; if( $this->control_blogs( $instance , FALSE , FALSE )) // check if the user has permissions to the previously set blog { $new_instance['blog'] = absint( $new_instance['blog'] ); if( $this->control_blogs( $new_instance , FALSE , FALSE )) // check if the user has permissions to the wished-for blog $instance['blog'] = $new_instance['blog']; $instance['categoriesbool'] = in_array( $new_instance['categoriesbool'], array( 'in', 'and', 'not_in') ) ? $new_instance['categoriesbool']: ''; $instance['categories_in'] = array_filter( array_map( 'absint', $new_instance['categories_in'] )); $instance['categories_in_related'] = (int) $new_instance['categories_in_related']; $instance['categories_not_in'] = array_filter( array_map( 'absint', $new_instance['categories_not_in'] )); $instance['categories_not_in_related'] = (int) $new_instance['categories_not_in_related']; $instance['tagsbool'] = in_array( $new_instance['tagsbool'], array( 'in', 'and', 'not_in') ) ? $new_instance['tagsbool']: ''; $tag_name = ''; $instance['tags_in'] = array(); foreach( array_filter( array_map( 'trim', array_map( 'wp_filter_nohtml_kses', explode( ',', $new_instance['tags_in'] )))) as $tag_name ) { if( $temp = is_term( $tag_name, 'post_tag' )) $instance['tags_in'][] = $temp['term_id']; } $instance['tags_in_related'] = (int) $new_instance['tags_in_related']; $tag_name = ''; $instance['tags_not_in'] = array(); foreach( array_filter( array_map( 'trim', array_map( 'wp_filter_nohtml_kses', explode( ',', $new_instance['tags_not_in'] )))) as $tag_name ) { if( $temp = is_term( $tag_name, 'post_tag' )) $instance['tags_not_in'][] = $temp['term_id']; } $instance['tags_not_in_related'] = (int) $new_instance['tags_not_in_related']; if( $instance['what'] <> 'normal' ) { foreach( get_object_taxonomies( $instance['what'] ) as $taxonomy ) { if( $taxonomy == 'category' || $taxonomy == 'post_tag' ) continue; $instance['tax_'. $taxonomy .'_bool'] = in_array( $new_instance['tax_'. $taxonomy .'_bool'], array( 'in', 'and', 'not_in') ) ? $new_instance['tax_'. $taxonomy .'_bool']: ''; $tag_name = ''; $instance['tax_'. $taxonomy .'_in'] = array(); foreach( array_filter( array_map( 'trim', array_map( 'wp_filter_nohtml_kses', explode( ',', $new_instance['tax_'. $taxonomy .'_in'] )))) as $tag_name ) { if( $temp = is_term( $tag_name, $taxonomy )) $instance['tax_'. $taxonomy .'_in'][] = $temp['term_id']; } $tag_name = ''; $instance['tax_'. $taxonomy .'_not_in'] = array(); foreach( array_filter( array_map( 'trim', array_map( 'wp_filter_nohtml_kses', explode( ',', $new_instance['tax_'. $taxonomy .'_not_in'] )))) as $tag_name ) { if( $temp = is_term( $tag_name, $taxonomy )) $instance['tax_'. $taxonomy .'_not_in'][] = $temp['term_id']; } } } $instance['post__in'] = array_filter( array_map( 'absint', explode( ',', $new_instance['post__in'] ))); $instance['post__not_in'] = array_filter( array_map( 'absint', explode( ',', $new_instance['post__not_in'] ))); $instance['comments'] = in_array( $new_instance['comments'], array( 'unset', 'yes', 'no' ) ) ? $new_instance['comments']: ''; } $instance['activity'] = in_array( $new_instance['activity'], array( 'pop_most', 'pop_least', 'pop_recent', 'comment_recent', 'comment_few') ) ? $new_instance['activity']: ''; $instance['age_bool'] = in_array( $new_instance['age_bool'], array( 'newer', 'older') ) ? $new_instance['age_bool']: ''; $instance['age_num'] = absint( $new_instance['age_num'] ); $instance['age_unit'] = in_array( $new_instance['age_unit'], array( 'day', 'month', 'year') ) ? $new_instance['age_unit']: ''; $instance['agestrtotime'] = strtotime( $new_instance['agestrtotime'] ) ? $new_instance['agestrtotime'] : ''; $instance['relationship'] = in_array( $new_instance['relationship'], array( 'similar', 'excluding') ) ? $new_instance['relationship']: ''; $instance['relatedto'] = array_filter( (array) array_map( 'intval', (array) $new_instance['relatedto'] )); $instance['count'] = absint( $new_instance['count'] ); $instance['order'] = in_array( $new_instance['order'], array( 'age_new', 'age_old', 'title_az', 'title_za', 'comment_new', 'pop_recent', 'rand' ) ) ? $new_instance['order']: ''; $instance['template'] = wp_filter_nohtml_kses( $new_instance['template'] ); $instance['offset_run'] = empty( $new_instance['offset_run'] ) ? '' : absint( $new_instance['offset_run'] ); $instance['offset_start'] = empty( $new_instance['offset_start'] ) ? '' : absint( $new_instance['offset_start'] ); in_array( $new_instance['thumbnail_size'], (array) get_intermediate_image_sizes() ) ? $new_instance['thumbnail_size']: ''; if( function_exists( 'get_intermediate_image_sizes' )) $instance['thumbnail_size'] = in_array( $new_instance['thumbnail_size'], (array) get_intermediate_image_sizes() ) ? $new_instance['thumbnail_size']: ''; $instance['columns'] = absint( $new_instance['columns'] ); $this->justupdated = TRUE; /* var_dump( $new_instance['categories_in_related'] ); var_dump( $instance['categories_in_related'] ); die; */ return $instance; } function form( $instance ) { global $blog_id, $postloops, $bsuite; // reset the instances var, in case a new widget was added $postloops->get_instances(); //Defaults $instance = wp_parse_args( (array) $instance, array( 'what' => 'normal', 'template' => 'a_default_full.php', 'blog' => $blog_id, ) ); $title = esc_attr( $instance['title'] ); $subtitle = esc_attr( $instance['subtitle'] ); ?>
"; //print_r($old_instance); //print_r($new_instance); print_r($instance); echo ""; //die; */ return $instance; } function form( $instance ) { global $postloops; //Defaults $instance = wp_parse_args( (array) $instance, array( 'title' => __('Comments'), 'relatedto' => -1, 'template' => 'a_default_full.php', 'email' => '', ) ); $title = esc_attr( $instance['title'] ); ?>
get_instances(); $list = array(); foreach( $postloops->instances as $number => $instance ){ if( $instance['blog'] <> $blog_id ) continue; if ( $default == $number ) $selected = " selected='selected'"; else $selected = ''; $list[] = ''; } echo implode( "\n\t", $list ); } function control_template_dropdown( $default = '' ) { global $postloops; $templates = $postloops->templates_response; array_unshift( $templates , array( 'name' => 'Default Comment Form', 'file' => '', 'fullpath' => '', ) ); foreach ( $templates as $template => $info ) : if ( $default == $template ) $selected = " selected='selected'"; else $selected = ''; echo "\n\t'; endforeach; } }// end bSuite_Widget_ResponseLoop /** * Pages widget class * */ class bSuite_Widget_Pages extends WP_Widget { function bSuite_Widget_Pages() { $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'A buncha yo blog’s WordPress Pages') ); $this->WP_Widget('pages', __('Pages'), $widget_ops); } function widget( $args, $instance ) { extract( $args ); if( $instance['startpage'] < 0 || $instance['startpage'] === 'c' ) { if( ! is_singular() ) // can't generate a menu in this situation return; } if( is_singular() ) { $post = get_post( get_queried_object_id() ); // getting the post for use later if( $post->post_parent && ( ! isset( $post->ancestors ) || ! count( $post->ancestors ))) { // the post has a parent, but the ancestors array is unset or empty unset( $post->ancestors ); _get_post_ancestors( $post ); echo ''; } echo ''; } if( is_404() ) $instance['expandtree'] = 0; $title = apply_filters('widget_title', empty( $instance['title'] ) ? FALSE : $instance['title']); $homelink = empty( $instance['homelink'] ) ? '' : $instance['homelink']; $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; $depth = isset( $instance['depth'] ) ? $instance['depth'] : 1; if( $instance['startpage'] < 0 ) { // get the ancestor tree, including the current page $ancestors = $post->ancestors; array_unshift( $ancestors , $post->ID ); //append the current page to the ancestors array in the correct order // reverse the array so the slice can return empty if startpage is larger than the array $startpage = current( array_slice( array_reverse( (array) $ancestors ) , absint( $instance['startpage'] ) -1 , 1 )); if( ! $startpage ) return; } else if( $instance['startpage'] >= 0 ) { $startpage = $instance['startpage']; } else if( $instance['startpage'] == 'c' ) { $startpage = $post->ID; } if ( $sortby == 'menu_order' ) $sortby = 'menu_order, post_title'; $out = wp_list_pages( array( 'child_of' => $startpage, 'title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude, 'depth' => $depth )); if( $instance['expandtree'] && ( $instance['startpage'] >= 0 ) && is_page() ) { // get the ancestor tree, including the current page $ancestors = $post->ancestors; $ancestors[] = $post->ID; $pages = get_pages( array( 'include' => implode( ',', $ancestors ))); if ( !empty( $pages )){ $subtree .= walk_page_tree( $pages, 0, $post->ID, array() ); // get any siblings, insert them into the tree if( count( $post->ancestors ) && ( $siblings = wp_list_pages( array( 'child_of' => array_shift( $ancestors ), 'title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude, 'depth' => 1 )))){ $subtree = preg_replace( '/
#i', '
/>
%term_name% will be replaced.' ); ?>