Documentation here. Version: 5 alpha 2 Author: Casey Bisson Author URI: http://maisonbisson.com/blog/ */ class bSuite { function bSuite(){ global $wpdb; $this->search_table = $wpdb->prefix . 'bsuite4_search'; $this->hits_incoming = ( empty( $wpdb->base_prefix ) ? $wpdb->prefix : $wpdb->base_prefix ) .'bsuite4_hits_incoming'; $this->hits_terms = ( empty( $wpdb->base_prefix ) ? $wpdb->prefix : $wpdb->base_prefix ) .'bsuite4_hits_terms'; $this->hits_targets = ( empty( $wpdb->base_prefix ) ? $wpdb->prefix : $wpdb->base_prefix ) .'bsuite4_hits_targets'; $this->hits_searchphrases = ( empty( $wpdb->base_prefix ) ? $wpdb->prefix : $wpdb->base_prefix ) .'bsuite4_hits_searchphrases'; // $this->hits_searchwords = ( empty( $wpdb->base_prefix ) ? $wpdb->prefix : $wpdb->base_prefix ) .'bsuite4_hits_searchwords'; $this->hits_sessions = ( empty( $wpdb->base_prefix ) ? $wpdb->prefix : $wpdb->base_prefix ) .'bsuite4_hits_sessions'; $this->hits_shistory = ( empty( $wpdb->base_prefix ) ? $wpdb->prefix : $wpdb->base_prefix ) .'bsuite4_hits_shistory'; $this->hits_pop = ( empty( $wpdb->base_prefix ) ? $wpdb->prefix : $wpdb->base_prefix ) .'bsuite4_hits_pop'; $this->loadavg = $this->get_loadavg(); // establish web path to this plugin's directory $this->path_web = plugins_url( basename( dirname( __FILE__ ))); $this->is_quickview = FALSE; // register and queue javascripts wp_register_script( 'bsuite', $this->path_web . '/js/bsuite.js', array('jquery'), '20080503' , TRUE ); wp_enqueue_script( 'bsuite' ); // jQuery text highlighting plugin http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html wp_register_script( 'highlight', $this->path_web . '/js/jquery.highlight-1.js', array('jquery'), '1' , TRUE ); wp_enqueue_script( 'highlight' ); // is this wpmu? if( function_exists( 'is_site_admin' )) $this->is_mu = TRUE; else $this->is_mu = FALSE; if ( isset( $_GET['bsuite_mycss'] ) && !is_admin() ) add_action( 'init', array( &$this, 'bsuite_mycss_printstyles' )); // // register hooks // // shortcodes add_shortcode('include', array(&$this, 'shortcode_include')); add_shortcode('icon', array(&$this, 'shortcode_icon')); add_shortcode('feed', array(&$this, 'shortcode_feed')); // filter the_excerpt and x_rss through do_shortcode(). wish this was in core // http://trac.wordpress.org/ticket/7093 add_filter('the_content_rss', 'do_shortcode', 11); add_filter('the_excerpt', 'do_shortcode', 11); add_filter('the_excerpt_rss', 'do_shortcode', 11); add_filter('widget_text', 'do_shortcode', 11); // bsuite post icons add_action('wp_ajax_bsuite_icon_form', array( &$this, 'icon_ajax_form' )); add_action('wp_ajax_bsuite_icon_upload', array( &$this, 'icon_ajax_upload' )); add_action('wp_ajax_bsuite_icon_delete', array( &$this, 'icon_ajax_delete' )); $this->icon_sizes_default(); // initialize default icons // tokens // tokens are deprecated. please use shortcode functionality instead. add_filter('bsuite_tokens', array(&$this, 'tokens_default')); add_filter('the_content', array(&$this, 'tokens_the_content'), 0); add_filter('the_content_rss', array(&$this, 'tokens_the_content_rss'), 0); add_filter('the_excerpt', array(&$this, 'tokens_the_excerpt'), 0); add_filter('the_excerpt_rss', array(&$this, 'tokens_the_excerpt_rss'), 0); add_filter('get_the_excerpt ', array(&$this, 'tokens_the_excerpt'), 0); add_filter('widget_text', array(&$this, 'tokens'), 0); // bsuggestive related posts add_filter('save_post', array(&$this, 'bsuggestive_delete_cache')); if( get_option( 'bsuite_insert_related' )){ add_filter('the_content', array(&$this, 'bsuggestive_bypageviews_the_content'), 5); add_filter('the_content', array(&$this, 'bsuggestive_the_content'), 5); } // sharelinks if( get_option( 'bsuite_insert_sharelinks' )) add_filter('the_content', array(&$this, 'sharelinks_the_content'), 6); // redirection add_filter('template_redirect', array(&$this, 'searchsmart_direct'), 8); add_filter('post_link', array(&$this, 'searchsmart_post_link_direct'), 11, 2); // default CSS if( get_option( 'bsuite_insert_css' )){ add_action('wp_head', 'wp_print_styles', 9); wp_register_style( 'bsuite-default', $this->path_web .'/css/default.css' ); wp_enqueue_style( 'bsuite-default' ); } // bstat add_action('get_footer', array(&$this, 'bstat_js')); // cron add_filter('cron_schedules', array(&$this, 'cron_reccurences')); if( $this->loadavg < get_option( 'bsuite_load_max' )){ // only do cron if load is low-ish add_filter('bsuite_interval', array(&$this, 'bstat_migrator')); } // machine tags add_action('save_post', array(&$this, 'machtag_save_post'), 2, 2); // cms goodies add_filter('user_has_cap', array(&$this, 'edit_current_user_can'), 10, 3); add_filter('save_post', array(&$this, 'edit_publish_page')); // add_action('dbx_page_advanced', array(&$this, 'edit_insert_excerpt_form')); // add_action('dbx_page_sidebar', array(&$this, 'edit_insert_category_form')); // add_action('edit_form_advanced', array(&$this, 'edit_post_form')); // add_action('edit_page_form', array(&$this, 'edit_page_form')); add_action('widgets_init', array(&$this, 'widgets_register')); /* // user-contributed tags add_action('preprocess_comment', array(&$this, 'uctags_preprocess_comment'), 1); */ // activation and menu hooks register_activation_hook(__FILE__, array(&$this, 'activate')); add_action('admin_menu', array(&$this, 'admin_menu_hook')); add_action('admin_init', array(&$this, 'admin_init')); add_action('init', array(&$this, 'init')); // end register WordPress hooks } function admin_init(){ /* // set things up so authors can edit their own pages $role = get_role('author'); if ( ! empty($role) ) { $role->add_cap('edit_pages'); $role->add_cap('edit_published_pages'); } */ register_setting( 'bsuite-options', 'bsuite_insert_related', 'absint' ); register_setting( 'bsuite-options', 'bsuite_insert_sharelinks', 'absint' ); register_setting( 'bsuite-options', 'bsuite_searchsmart', 'absint' ); register_setting( 'bsuite-options', 'bsuite_swhl', 'absint' ); register_setting( 'bsuite-options', 'bsuite_who_can_edit' ); register_setting( 'bsuite-options', 'bsuite_managefocus_month', 'absint' ); register_setting( 'bsuite-options', 'bsuite_managefocus_author', 'absint' ); register_setting( 'bsuite-options', 'bsuite_insert_css', 'absint' ); register_setting( 'bsuite-options', 'bsuite_migration_interval', 'absint' ); register_setting( 'bsuite-options', 'bsuite_migration_count', 'absint' ); register_setting( 'bsuite-options', 'bsuite_load_max', 'absint' ); } function init(){ if( get_option( 'bsuite_mycss_replacethemecss' ) && !is_admin() ){ add_filter( 'stylesheet_uri', array( &$this, 'bsuite_mycss_hidesstylesheet' ), 11 ); add_filter( 'locale_stylesheet_uri', array( &$this, 'bsuite_mycss_hidesstylesheet' ), 11 ); } if(( get_option( 'bsuite_mycss' ) || get_option( 'bsuite_mycss_replacethemecss' )) && !is_admin() ){ wp_register_style( 'bsuite-mycss', get_option('home') .'/index.php?bsuite_mycss=print' ); wp_enqueue_style( 'bsuite-mycss' ); } if( 0 < get_option( 'bsuite_mycss_maxwidth' )) $GLOBALS['content_width'] = absint( get_option( 'bsuite_mycss_maxwidth' )); if( !isset( $GLOBALS['content_width'] )) $GLOBALS['content_width'] = 500; load_plugin_textdomain( 'bsuite', FALSE, basename( dirname( __FILE__ )) .'/lang/' ); /* // handle user-contributed tags via comments if( strpos( $_SERVER['PHP_SELF'], 'wp-comments-post.php' ) && ( !empty( $_REQUEST['bsuite_uctags'] ))) $_REQUEST['comment'] = 'BSUITE_UCTAG'; */ // add_rewrite_endpoint( 'quickview', EP_PERMALINK ); // this doesn't quite work as I want it to } function admin_menu_hook() { if( (( 'edit.php' == basename( $_SERVER['PHP_SELF'] )) || ( 'edit-pages.php' == basename( $_SERVER['PHP_SELF'] ))) && ( !count( $_GET )) ){ global $current_user; if( !current_user_can( 'edit_others_posts' ) ) die( wp_redirect( admin_url( basename( $_SERVER['PHP_SELF'] ) .'?author='. $current_user->id . ( ( get_option( 'bsuite_managefocus_month' ) && ( 'edit-pages.php' <> basename( $_SERVER['PHP_SELF'] )) ) ? '&m='. date( 'Ym' ) : '') ))); die( wp_redirect( admin_url( basename( $_SERVER['PHP_SELF'] ) .'?s'. ( get_option( 'bsuite_managefocus_author' ) ? '&author='. $current_user->id : '' ) . ( ( get_option( 'bsuite_managefocus_month' ) && ( 'edit-pages.php' <> basename( $_SERVER['PHP_SELF'] )) ) ? '&m='. date( 'Ym' ) : '') ))); } /* // the machine tags js and style wp_register_script( 'bsuite-machtags', $this->path_web . '/js/bsuite-machtags.js', array('jquery-ui-sortable'), '1' ); wp_enqueue_script( 'bsuite-machtags' ); wp_register_style( 'bsuite-machtags', $this->path_web .'/css/machtags.css' ); wp_enqueue_style( 'bsuite-machtags' ); */ /* // add the sweet categories and tags JS from the post editor to the page editor wp_register_script( 'edit_page', $this->path_web . '/js/edit_page.js', array('jquery'), '1' ); if( strpos( $_SERVER['REQUEST_URI'], 'admin/page' )){ wp_enqueue_script( 'edit_page' ); wp_enqueue_script( 'jquery-ui-tabs' ); wp_enqueue_script( 'suggest' ); wp_enqueue_script( 'ajaxcat' ); } */ // add the options page add_options_page('bSuite Settings', 'bSuite', 'manage_options', plugin_basename( dirname( __FILE__ )) .'/ui_options.php' ); // the bstat reports are handled in a seperate file add_submenu_page('index.php', 'bSuite bStat Reports', 'bStat Reports', 'edit_posts', plugin_basename( dirname( __FILE__ )) .'/ui_stats.php' ); // the custom css page add_theme_page( __('Custom CSS'), __('Custom CSS'), 'switch_themes', plugin_basename( dirname( __FILE__ )) .'/ui_mycss.php' ); // add the post icon widget to the post and page editors add_meta_box('bsuite_post_icon', __('bSuite Post Icon'), array( &$this, 'icon_editor_iframe' ), 'post', 'advanced', 'high'); add_meta_box('bsuite_post_icon', __('bSuite Post Icon'), array( &$this, 'icon_editor_iframe' ), 'page', 'advanced', 'high'); } // // shortcode functions // function shortcode_icon( $arg ){ // [innerindex ] global $id; $arg = shortcode_atts( array( 'post_id' => $id, 'size' => 's', 'width' => 0, 'height' => 0, ), $arg ); return( $this->icon_get_h( $arg['post_id'], $arg['size'], $arg['width'], $arg['height'] )); } function shortcode_include( $arg ){ // [include ] global $id, $post; $arg = shortcode_atts( array( 'post_id' => FALSE, 'url' => FALSE, 'field' => 'post_excerpt', ), $arg ); if( !( $arg[ 'post_id' ] || $arg[ 'url' ] )) return( FALSE ); if( isset( $arg[ 'url' ] )) $include_id = url_to_postid( $arg[ 'url' ] ); if( (int) $arg[ 'post_id' ] ) $include_id = (int) $arg[ 'post_id' ]; if( !$include_id || ( $id == $include_id )) return( FALSE ); $post_orig = unserialize( serialize( $post )); // how else to prevent passing object by reference? $id_orig = $id; $post = get_post( $arg[ 'post_id' ] ); $id = $post->ID; if( ( 'post_excerpt' == $arg[ 'field' ] ) && !( get_post_field( $arg[ 'field' ], $include_id ))) $arg[ 'field' ] = 'post_content'; $content = apply_filters( 'the_content', get_post_field( $arg[ 'field' ], $include_id )); $post = $post_orig; $id = $id_orig; return( $content ); } function shortcode_feed( $arg ){ // [feed ] $arg = shortcode_atts( array( 'title' => FALSE, 'div_class' => FALSE, 'ul_class' => 'feed', 'ol_class' => FALSE, 'feed_url' => FALSE, 'count' => 5, 'template' => '
%%content%%
' );
}
return( FALSE );
}
// end post icon related functions
function bsuite_mycss_printstyles(){
@header('Content-Type: text/css; charset=' . get_option('blog_charset'));
echo get_option( 'bsuite_mycss' );
die();
}
function bsuite_mycss_hidesstylesheet( $input ){
return( $this->path_web . '/css/empty.css' );
}
function mycss_sanitize( $input ){
$input = wp_filter_nohtml_kses( $input );
$input = preg_replace('/\/\*.*?\*\//sm', '', $input); // strip comments
$safecss = '';
foreach( explode( "\n", $input ) as $line )
$safecss .= $this->mycss_cleanline( $line );
return( $safecss );
}
function mycss_cleanline( $input ){
$evil = 0;
$filtered = wp_kses_decode_entities( $input );
$filtered = preg_replace('/expression[^\(]?\(.*?\)/i', '', $filtered, -1, $flag ); // strip expressions
if( $flag ) $evil++;
$filtered = preg_replace('/@import/i', '', $filtered, -1, $flag ); // strip @import
if( $flag ) $evil++;
$filtered = preg_replace('/about:/i', '', $filtered, -1, $flag ); // strip about: uris
if( $flag ) $evil++;
$filtered = preg_replace_callback('/([\w]*?):\/\//si', array( $this, 'mycss_cleanuri' ), $filtered, -1, $flag ); // strip non http uris
if( $flag ) $evil++;
return( $evil ? $filtered : $input );
}
function mycss_cleanuri( $input ){
if( !preg_match( '/^http:\/\//', $input[0] ))
return '';
return( $input[0] );
}
//
// sharelinks
//
function sharelinks(){
global $wp_query;
// exit if 404
if($wp_query->is_404)
return(FALSE);
// identify the based post ID, if any, and establish some basics
$post_id = FALSE;
if(!empty($wp_query->is_singular) && !empty($wp_query->query_vars['p']))
$post_id = $wp_query->query_vars['p'];
else if(!empty($wp_query->is_singular) && !empty($wp_query->queried_object_id))
$post_id = $wp_query->queried_object_id;
else if( !empty( $this->bsuggestive_to ))
$post_id = $this->bsuggestive_to;
if($post_id){
$the_permalink = urlencode(get_permalink($post_id));
$the_title = urlencode(get_the_title($post_id));
$the_excerpt = apply_filters('the_excerpt', get_the_excerpt());
}else{
$the_permalink = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['HTTP_HOST'] . add_query_arg('bsuite_share');
unset($wp_query->query['bsuite_share']);
unset($wp_query->query['attachment']);
if(count($wp_query->query))
$the_title = get_bloginfo('name') .' ('. wp_specialchars( implode(array_unique(explode('|', strtolower(implode(array_values($wp_query->query), '|')))), ', ')) .')';
else
$the_title = get_bloginfo('name');
$the_excerpt = '';
}
$content = 'Powered by bSuite.
'; return( $content ); //return(array('the_id' => $post_id, 'the_title' => urldecode($the_title), 'the_permalink' => urldecode($the_permalink), 'the_content' => $content, )); } function sharelinks_the_content( $content ) { if( is_single() && $sharelinks = $this->sharelinks() ) return( $content . $sharelinks); return( $content ); } // end sharelinks related functions // // link to me // function link2me_links( $post_id ){ if( !$post_id ) return( FALSE ); //''. strip_tags( get_the_title( $post_id )) .''; //not using this now //echo 'use them in your template'); ?>