Documentation here. Version: 3.0.5 Author: Casey Bisson Author URI: http://maisonbisson.com/blog/ */ $services_feed = array( 'bloglines' => array( 'name' => 'Bloglines' , 'url' => 'http://www.bloglines.com/sub/{url_raw}' ) , 'google' => array( 'name' => 'Google' , 'url' => 'http://fusion.google.com/add?feedurl={url}' ) , 'rssfwd' => array( 'name' => 'RSS:FWD Email' , 'url' => 'http://www.rssfwd.com/rssfwd/preview?url={url}' ) ); $services_translate = array( 'french' => array( 'name' => 'French' , 'url' => 'http://translate.google.com/translate?u={url}&langpair=en%7Cfr' ) , 'spanish' => array( 'name' => 'Spanish' , 'url' => 'http://translate.google.com/translate?u={url}&langpair=en%7Ces' ) , 'german' => array( 'name' => 'German' , 'url' => 'http://translate.google.com/translate?u={url}&langpair=en%7Cde' ) , 'japanese' => array( 'name' => 'Japanese' , 'url' => 'http://translate.google.com/translate?u={url}&langpair=en%7Cja' ) , 'korean' => array( 'name' => 'Korean' , 'url' => 'http://translate.google.com/translate?u={url}&langpair=en%7Cko' ) , 'chineses' => array( 'name' => 'Chinese (simplified)' , 'url' => 'http://translate.google.com/translate?u={url}&langpair=en%7Czh-CN' ) , 'chineset' => array( 'name' => 'Chinese (traditional)' , 'url' => 'http://translate.google.com/translate?u={url}&langpair=en%7Czh-TW' ) , 'russian' => array( 'name' => 'Russian' , 'url' => 'http://translate.google.com/translate?u={url}&langpair=en%7Cru' ) ); $services_bookmark = array( 'delicious' => array( 'name' => 'del.icio.us' , 'url' => 'http://del.icio.us/post?url={url}&title={title}' ) , 'facebook' => array( 'name' => 'Facebook' , 'url' => 'http://www.facebook.com/share.php?u={url}' ) , 'digg' => array( 'name' => 'Digg' , 'url' => 'http://digg.com/submit?phase=2&url={url}&title={title}' ) , 'stumbleupon' => array( 'name' => 'StumbleUpon' , 'url' => 'http://www.stumbleupon.com/submit?url={url}&title={title}' ) , 'reddit' => array( 'name' => 'reddit' , 'url' => 'http://reddit.com/submit?url={url}&title={title}' ) , 'blinklist' => array( 'name' => 'BlinkList' , 'url' => 'http://blinklist.com/index.php?Action=Blink/addblink.php&Url={url}&Title={title}' ) , 'newsvine' => array( 'name' => 'Newsvine' , 'url' => 'http://www.newsvine.com/_tools/seed&save?popoff=0&u={url}&h={title}' ) , 'furl' => array( 'name' => 'Furl' , 'url' => 'http://furl.net/storeIt.jsp?u={url}&t={title}' ) , 'tailrank' => array( 'name' => 'Tailrank' , 'url' => 'http://tailrank.com/share/?link_href={url}&title={title}' ) , 'magnolia' => array( 'name' => 'Ma.gnolia' , 'url' => 'http://ma.gnolia.com/bookmarklet/add?url={url}&title={title}' ) , 'netscape' => array( 'name' => 'Netscape' , 'url' => ' http://www.netscape.com/submit/?U={url}&T={title}' ) , 'yahoo_myweb' => array( 'name' => 'Yahoo! My Web' , 'url' => 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u={url}&t={title}' ) , 'google_bmarks' => array( 'name' => 'Google Bookmarks' , 'url' => ' http://www.google.com/bookmarks/mark?op=edit&bkmk={url}&title={title}' ) , 'technorati' => array( 'name' => 'Technorati' , 'url' => 'http://www.technorati.com/faves?add={url}' ) , 'blinklist' => array( 'name' => 'BlinkList' , 'url' => 'http://blinklist.com/index.php?Action=Blink/addblink.php&Url={url}&Title={title}' ) , 'windows_live' => array( 'name' => 'Windows Live' , 'url' => 'https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url={url}&title={title}&top=1' ) ); class bSuite { function bSuite(){ global $wpdb; $this->search_table = $wpdb->prefix . 'bsuite3_search'; // establish web path to this plugin's directory $this->path_web = '/'. PLUGINDIR .'/'. plugin_basename( dirname( __FILE__ )); // register and queue javascripts wp_register_script( 'scrib-linktome_selectall', $this->path_web . '/js/linktome_selectall.js', array('jquery'), '20080422' ); wp_enqueue_script( 'scrib-linktome_selectall' ); // $this->options = get_option('bsuite3'); // // register hooks // // machine tags add_action('save_post', array(&$this, 'machtag_save_post'), 2, 2); // tokens 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); //innerindex add_filter('content_save_pre', array(&$this, 'innerindex_nametags')); add_filter('save_post', array(&$this, 'innerindex_delete_cache')); add_filter('publish_post', array(&$this, 'innerindex_delete_cache')); add_filter('publish_page', array(&$this, 'innerindex_delete_cache')); $this->kses_allowedposttags(); // allow IDs on H1-H6 tags // bsuggestive add_filter('save_post', array(&$this, 'bsuggestive_delete_cache')); add_filter('publish_post', array(&$this, 'bsuggestive_delete_cache')); add_filter('publish_page', array(&$this, 'bsuggestive_delete_cache')); // pagehooks add_filter('bsuite_pagehooks', array(&$this, 'pagehooks_default')); add_filter('template_redirect', array(&$this, 'pagehooks'), 8); // athooks add_filter('bsuite_athooks', array(&$this, 'athooks_default')); add_filter('template_redirect', array(&$this, 'athooks'), 8); add_filter('get_breadcrumb', array(&$this, 'athooks_breadcrumbs'), 5, 2); // sharelinks add_filter('template_redirect', array(&$this, 'sharelinks_redirect'), 9); // searchsmart add_filter('posts_request', array(&$this, 'searchsmart_query'), 10); add_filter('template_redirect', array(&$this, 'searchsmart_onsingle'), 8); add_filter('content_save_pre', array(&$this, 'searchsmart_upindex_onedit')); // CMS goodies 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')); // activation and menu hooks register_activation_hook(__FILE__, array(&$this, 'activate')); add_action('admin_menu', array(&$this, 'addmenus')); // end register WordPress hooks // 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'); } } // // token functions // tokens are [[token]] in the content of a post. // function tokens_get(){ // establish list of tokens static $tokens = FALSE; if($tokens) return($tokens); $tokens = array(); $tokens = apply_filters('bsuite_tokens', $tokens); return($tokens); } function tokens_fill($thing) { // match tokens $return = $thing[0]; $thing = explode('|', trim($thing[0], '[]'), 2); $tokens = &$this->tokens_get(); if($tokens[$thing[0]]) $return = call_user_func_array($tokens[$thing[0]], $thing[1]); return($return); } function tokens($content) { // find tokens in the page $content = preg_replace_callback( '/\[\[([^\]\]])*\]\]/', array(&$this, 'tokens_fill'), $content); return($content); } public function tokens_the_content($content) { $this->is_content = TRUE; $content = $this->tokens($content); $this->is_content = FALSE; return($content); } public function tokens_the_content_rss($content) { $this->is_content = TRUE; $this->is_rss = TRUE; $content = $this->tokens($content); $this->is_content = FALSE; $this->is_rss = FALSE; return($content); } public function tokens_the_excerpt($content) { $this->is_excerpt = TRUE; $content = $this->tokens($content); $this->is_excerpt = FALSE; return($content); } public function tokens_the_excerpt_rss($content) { $this->is_excerpt = TRUE; $this->is_rss = TRUE; $content = $this->tokens($content); $this->is_excerpt = FALSE; $this->is_rss = FALSE; return($content); } function tokens_default($tokens){ // setup some default tokens $tokens['date'] = array(&$this, 'token_get_date'); $tokens['pagemenu'] = array(&$this, 'token_get_pagemenu'); $tokens['innerindex'] = array(&$this, 'innerindex'); $tokens['feed'] = array(&$this, 'token_get_feed'); $tokens['redirect'] = array(&$this, 'token_get_redirect'); return($tokens); } function token_get_date($stuff = 'F j, Y, g:i a'){ // [[date|options]] return(date($stuff)); } function token_get_pagemenu($stuff = NULL){ // [[pagemenu|depth|extra]] // [[pagemenu|1|sort_column=post_date&sort_order=DESC]] global $id; $stuff = explode('|', $stuff); return(wp_list_pages("child_of=$id&depth=1&echo=0&sort_column=menu_order&title_li=&$stuff[0]")); } function token_get_redirect($stuff){ // [[redirect|$url]] if(!headers_sent()) header("Location: $stuff"); return('redirect: '. $stuff .''); } function token_get_feed($stuff){ // [[feed|feed_url|count]] $stuff = explode('|', $stuff); if(!$stuff[1]) $stuff[1] = 5; if(!$stuff[2]) $stuff[2] = '
  • %%title%%
    %%content%%
  • '; return($this->get_feed($stuff[0], $stuff[1], $stuff[2], TRUE)); } // end token-related functions //innerindex function innerindex($title = 'Contents:'){ global $id, $post_cache; if ( !$menu = wp_cache_get( $id, 'bsuite_innerindex' )) { $menu = $this->innerindex_build( get_post_field( 'post_content', $id )); wp_cache_add( $id, $menu, 'bsuite_innerindex', 864000 ); } if($this->is_excerpt){ return( str_replace( '%%the_permalink%%', get_permalink( $id ), $menu )); }else{ return( '

    '. $title .'

    '. str_replace( '%%the_permalink%%', get_permalink( $id ), $menu ) .'
    ' ); } } function innerindex_build($content){ // find tags with IDs in the content and build an index of them preg_match_all( '|]+>[^<]+]+>|U', $content, $things ); $menu = '
      '; $closers = $count = 0; foreach($things[0] as $thing){ preg_match('| $last){ $menu .= '
        '; $closers++; }else if($count){ $menu .= ''; } if(($h[1] < $last) && ($h[1] >= $low)){ $menu .= '
      '; $closers--; } $last = $h[1]; $menu .= '
    1. '. strip_tags($thing) .''; $count++; } } $menu .= '
    2. '. str_repeat('
    ', $closers) . ''; return($menu); } function innerindex_delete_cache($id) { $id = (int) $id; wp_cache_delete( $id, 'bsuite_innerindex' ); } function innerindex_nametags($content){ // find tags in the content $content = preg_replace_callback( "/(\]*)?\>)(.*?)(\<\/h[0-9]\>)/", array(&$this,'innerindex_nametags_callback'), $content ); return($content); } function innerindex_nametags_callback($content){ // receive tags and insert the ID static $slugs; $slugs[] = $slug = substr(sanitize_title_with_dashes($content[4]), 0, 20); $content = "{$content[4]}{$content[5]}"; return($content); } // end innerindex-related function feedlink(){ return(strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/'))) . '://' . $_SERVER['HTTP_HOST'] . add_query_arg('feed', 'rss', add_query_arg('bsuite_share'))); } // // pagehook functions // function pagehooks_get(){ // establish list of pagehooks static $pagehooks = FALSE; if($pagehooks) return($pagehooks); $pagehooks = array(); $pagehooks = apply_filters('bsuite_pagehooks', $pagehooks); return($pagehooks); } function pagehooks_default($pagehooks){ // setup some default pagehooks, but there are none // $pagehooks['pagename'] = 'function_name'; return($pagehooks); } function pagehooks(){ // process pagehooks // the context of this hook is here: // http://wphooks.flatearth.org/hooks/template_redirect/ // Pagehooks allow you to put a stub-page in WP, then do some action // (like fetch the actual content from another server/script) when it's loaded global $wp_query; $pagehooks = &$this->pagehooks_get(); //print_r($wp_query); if(($wp_query->post->post_type == 'page') && $pagehooks[$wp_query->post->post_name]) call_user_func($pagehooks[$wp_query->post->post_name]); //call_user_func($pagehooks['wikipedia']); return; } // end pagehook-related functions // // athook functions // function athooks_get(){ // establish list of athooks static $athooks = FALSE; if($athooks) return($athooks); $athooks = array(); $athooks = apply_filters('bsuite_athooks', $athooks); return($athooks); } function athooks_default($athooks){ // setup some default athooks // $athooks[hook name][where to act (request or redirect)] = 'function name'; $athooks['related']['redirect'] = array(&$this, 'athook_get_related'); $athooks['related']['title'] = __('Related', 'bsuite'); $athooks['share']['redirect'] = array(&$this, 'athook_sharelinks'); $athooks['share']['title'] = __('Share This', 'bsuite'); return($athooks); } function athooks(){ // process athooks // the context of this hook is here: // http://wphooks.flatearth.org/hooks/template_redirect/ // Athooks allow you to change what WP does when a user loads a post // with an /$athook in the URL. // Example: http://site.org/permalinkpath/athook global $wp_query; $athooks = &$this->athooks_get(); if($wp_query->query_vars['attachment'] && $athooks[$wp_query->query_vars['attachment']]['redirect']){ $wp_query->is_athook = TRUE; $wp_query->athook['name'] = $wp_query->query_vars['attachment']; $wp_query->athook['title'] = $athooks[$wp_query->query_vars['attachment']]['title']; $wp_query->athook['post'] = &$this->athook_get_post('/'. $wp_query->query_vars['attachment']); call_user_func($athooks[$wp_query->query_vars['attachment']]['redirect']); } return; } function athooks_breadcrumbs($breadcrumb, $params){ // makes athooks play nice with Dan Peverill's breadcrumb plugin global $wp_query; if($wp_query->is_athook){ $breadcrumb = array(array_shift($breadcrumb)); if ((breadcrumb_is_paged() || $params["link_all"]) && !$params["link_none"]) $breadcrumb[] = ''. get_the_title($wp_query->athook['post']) .''; else $breadcrumb[] = get_the_title($wp_query->athook['post']); if ($params["link_all"] && !$params["link_none"]) $breadcrumb[] = ''. $wp_query->athook['title'] .''; else $breadcrumb[] = $wp_query->athook['title']; } //print_r($breadcrumb); return $breadcrumb; } function athook_get_related($search){ // get related items global $wp_query, $wpdb, $scrib; if(( $wp_query->athook['post'] ) && ( $the_tags = $this->bsuggestive_tags( $wp_query->athook['post'] ))){ $this->bsuggestive_to = $wp_query->athook['post']; $imploder = is_object( $scrib ) ? '|' : ' '; /* $imploder = ' '; // remove the other post_request filters and add one special for this // remove the Scriblio filter, if present if( is_object( $scrib )){ remove_filter( 'posts_request',array(&$scrib, 'the_query' )); $imploder = '|'; } remove_filter( 'posts_request',array(&$this, 'searchsmart_query' )); add_filter( 'posts_request', array( &$this, 'bsuggestive_postsrequest' ), 20 ); */ // now query the posts query_posts('s='. implode( $imploder, $the_tags )); status_header(200); unset($wp_query->query_vars['attachment']); $wp_query->query['s'] = implode( ' ', $the_tags ); $wp_query->query_vars['s'] = implode( ' ', $the_tags ); $wp_query->is_404 = FALSE; $wp_query->is_attachment = FALSE; $wp_query->is_search = TRUE; $wp_query->is_page = FALSE; $wp_query->is_single = FALSE; $wp_query->is_singular = FALSE; $wp_query->is_archive = FALSE; $wp_query->is_category = FALSE; } return($search); } function athook_sharelinks(){ global $wp_query; $query_vars['p'] = $wp_query->athook['post']; if($query_vars['p']){ $athook = $wp_query->athook; query_posts("p={$query_vars['p']}&bsuite_share=1"); $wp_query->is_athook = TRUE; $wp_query->athook = $athook; status_header(200); $this->sharelinks_redirect(); } return(TRUE); } function athook_get_post($thing){ // get the post ID global $wp; return( url_to_postid( str_replace( $thing, '', $wp->request ))); } // end athook-related functions // // 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 $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, )); } // 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 '

    Hi!

    '; return( apply_filters('bsuite_link2me', array( array('code' => get_permalink($post_id), 'name' => __( 'Permalink', 'bsuite' ))), $post_id)); } function link2me( $post_id ){ if( !$post_id ){ global $id; $post_id = $id; } if( !$links = $this->link2me_links( $post_id )) return( FALSE ); if( count( $links ) ){ $return = '
      '; foreach( $links as $link ){ $return .= '
    • '. $link['name'] .'

    • '; } $return .= '
    '; return( $return ); } return( FALSE ); } // // Searchsmart // function searchsmart_query($query){ global $wp_query, $wpdb; if($wp_query->is_admin) return($query); if (!empty($wp_query->query_vars['s'])) { $limit = explode('LIMIT', $query); if(!$limit[1]){ // $paged, $posts_per_page, and $limit are here for cases // where the query doesn't have an explicit LIMIT declaration $paged = $wp_query->query_vars['paged']; if(!$paged) $paged = 1; $posts_per_page = $wp_query->query_vars['posts_per_page']; if(!$posts_per_page) $posts_per_page = get_settings('posts_per_page'); $limit = explode('LIMIT', $query); if(!$limit[1]) $limit[1] = ($paged - 1) * $posts_per_page .', '. $posts_per_page; } $query = "SELECT SQL_CALC_FOUND_ROWS $wpdb->posts.*, MATCH (content, title) AGAINST ('". $wpdb->escape( stripslashes( $wp_query->query_vars['s'] )) ."') AS relevance FROM $wpdb->posts LEFT JOIN $this->search_table ON ( post_id = ID ) WHERE 1=1 AND (MATCH (content, title) AGAINST ('". $wpdb->escape( stripslashes( $wp_query->query_vars['s'] )) ."')) AND (post_type IN ('post', 'page') AND (post_status IN ('publish', 'private'))) ORDER BY relevance DESC LIMIT $limit[1] "; //print_r($wp_query); //echo "
    $query
    "; } return($query); } function searchsmart_onsingle(){ // redirects the search to the single page if the search returns only one item global $wp_query; if($wp_query->is_search && $wp_query->post_count == 1){ //$wp_query->is_search = NULL; //$wp_query->is_single = TRUE; header('Location: '. get_permalink($wp_query->post->ID)); } return(TRUE); } function searchsmart_upindex($post_id, $content, $title = ''){ // put content in the keyword search index global $wpdb; $content = preg_replace( '/\[\[([^\]])*\]\]/', '', strip_tags( str_ireplace(array('
    ', '
    ', '
    ', '

    ', '', '', '', '', ''), "\n", stripslashes( html_entity_decode($content))))); $content = trim(preg_replace( '/([[:punct:]])*/', '', $content)); $content = apply_filters('bsuite_searchsmart_content', $content); $title = preg_replace( '/([[:punct:]])*/', '', html_entity_decode($title, ENT_QUOTES, 'UTF-8')); $request = "REPLACE INTO $this->search_table (post_id, content, title) VALUES ($post_id, '$content', '$title')"; $wpdb->get_results($request); return(TRUE); } function searchsmart_upindex_onedit($content){ // called when posts are saved if($_POST['post_ID']) $this->searchsmart_upindex(ereg_replace('[^0-9]', '', $_POST['post_ID']), $content); return($content); } // end Searchsmart // bSuggestive related functions function bsuggestive_tags($id = FALSE) { $id = (int) $id; if ( !$id ) $id = (int) $post->ID; if ( !$id ) return FALSE; $tags = get_the_tags($id); if($tags){ foreach( $tags as $tag) { $the_tags[] = $tag->name; } }else{ $the_tags[] = get_the_title($id); } if(!count(array_filter($the_tags))) return FALSE; return apply_filters('bsuite_suggestive_tags', $the_tags, $id); } function bsuggestive_postsrequest($query) { global $wpdb; $the_matching_posts = $this->bsuggestive_getposts( 10 ); if( is_array( $the_matching_posts )) return( "SELECT * FROM $wpdb->posts WHERE 1=1 AND ID IN (" . implode( $the_matching_posts, ', ' ) . ') AND post_status IN ("publish", "private")' ); else return( "SELECT * FROM $wpdb->posts WHERE 1=2" ); } function bsuggestive_query($the_tags, $id) { global $wpdb; $id = (int) $id; if ( !$id ) $id = (int) $post->ID; if ( !$id ) return FALSE; if($id && is_array($the_tags)){ return apply_filters('bsuite_suggestive_query', "SELECT post_id FROM $this->search_table LEFT JOIN $wpdb->posts ON post_id = ID WHERE MATCH (content, title) AGAINST ('". ereg_replace('[^a-z|A-Z|0-9| ]', ' ', implode(' ', $the_tags)) ."') AND post_id <> $id AND post_status = 'publish' LIMIT 150 ", $post_id); } return FALSE; } function bsuggestive_getposts($id = FALSE) { global $post, $wpdb; $id = (int) $id; if ( !$id ) $id = (int) $post->ID; if ( !$id ) return FALSE; if ( !$related_posts = wp_cache_get( $id, 'bsuite_related_posts' ) ) { if(($the_tags = $this->bsuggestive_tags($id)) && ($the_query = $this->bsuggestive_query($the_tags, $id))){ $related_posts = $wpdb->get_col($the_query); wp_cache_add( $id, $related_posts, 'bsuite_related_posts', 864000 ); return($related_posts); // if we have to go to the DB to get the posts, then this will get returned } return FALSE; // if there's nothing in the cache and we've got no tags, then we return false } return($related_posts); // if the cache is still warm, then we return this } function bsuggestive_delete_cache($id) { $id = (int) $id; if ( !$id ) return FALSE; wp_cache_delete( $id, 'bsuite_related_posts' ); } function bsuggestive_the_related($before = '
  • ', $after = '
  • ') { global $post; $report = FALSE; $id = (int) $post->ID; if ( !$id ) return FALSE; $posts = array_slice($this->bsuggestive_getposts($id), 0, 5); if($posts){ $report = ''; foreach($posts as $post_id){ // $post = &get_post( $post_id ); $url = get_permalink($post_id); $linktext = get_the_title($post_id); $report .= $before . "$linktext". $after; } } return($report); } // end bSuggestive function pagetree(){ // identify the family tree of a page, return an array global $wp_query; $tree = NULL; if ($wp_query->is_page){ $object = $wp_query->get_queried_object(); // cycle through the tree and build an array $parent_id = $object->post_parent; $tree[] = $object->ID; while ($parent_id){ $page = get_page($parent_id); $tree[] = $page->ID; $parent_id = $page->post_parent; } // the tree is in reverse order. $tree = array_reverse($tree); } return $tree; } // // loadaverage related functions // function get_loadavg(){ static $result = FALSE; if($result) return($result); if(function_exists('sys_getloadavg')){ $load_avg = sys_getloadavg(); }else{ $load_avg = &$this->sys_getloadavg(); } $result = (($load_avg[0] + $load_avg[1]) / 2); return($result); } function sys_getloadavg(){ // the following code taken from tom pittlik's comment at // http://php.net/manual/en/function.sys-getloadavg.php $str = substr(strrchr(shell_exec('uptime'),':'),1); $avs = array_map('trim',explode(',',$str)); return $avs; } // end load average related functions // set a cookie function cookie($name, $value = NULL) { if($value === NULL){ if($_GET[$name]) return $_GET[$name]; elseif($_POST[$name]) return $_POST[$name]; elseif($_SESSION[$name]) return $_SESSION[$name]; elseif($_COOKIE[$name]) return $_COOKIE[$name]; else return false; }else{ setcookie($name, $value, time()+60*60*24*30, '/', '.scriblio.net'); return($value); } } // end // get and display rss feeds function get_feed($feed, $count = 15, $template = '
  • %%title%%
    %%content%%
  • ', $return = FALSE){ if(!function_exists('fetch_rss')) require_once (ABSPATH . WPINC . '/rss.php'); $rss = fetch_rss($feed); //print_r($rss); $i = $list = NULL; //print_r($rss); foreach($rss->items as $item){ $i++; if($i > $count) break; $link = $item['link']; $title = '' . $item['title'] . ''; if($item['content']['encoded']){ $content = $item['content']['encoded']; }else{ $content = $item['description']; } $list .= str_replace(array('%%title%%','%%content%%','%%link%%'), array($title, $content, $link), $template); //echo $template; } if($return) return($list); echo $list; } // end function get_rss // machine tags function machtag_save_post($post_id, $post) { // Passed machine tags overwrite existing if not empty if ( isset( $_REQUEST['bsuite-machine-tags-input'] )) foreach( $this->machtag_parse_tags( $_REQUEST['bsuite-machine-tags-input'] ) as $taxonomy => $tags ){ if( 'post_tag' == $taxonomy ){ wp_set_post_tags($post_id, $tags, true); continue; } if(!is_taxonomy( $taxonomy )) register_taxonomy($taxonomy, 'post'); wp_set_object_terms($post_id, $tags, $taxonomy); } } function machtag_parse_tags( $tags_input ) { $tags = $tags_parsed = array(); $tag_lines = explode( "\n", $tags_input ); foreach($tag_lines as $tag_line) $tags_parsed[] = $this->machtag_parse_tag( $tag_line ); foreach( $tags_parsed as $tag_parsed ) $tags[$tag_parsed['taxonomy']][] = $tag_parsed['term']; return( $tags ); } function machtag_parse_tag( $tag ) { $namespace = $taxonomy = $term = FALSE; $taxonomy = 'post_tag'; $temp_a = explode(':', $tag, 2); if($temp_a[1]){ $temp_b = explode('=', $temp_a[1], 2); if($temp_b[1]){ // has namespace, fieldname, & value $namespace = trim( $temp_a[0] ); $taxonomy = trim( $temp_b[0] ); $term = trim( $temp_b[1] ); }else{ // has just fieldname & value $taxonomy = trim( $temp_a[0] ); $term = trim( $temp_b[0] ); } }else{ $temp_b = explode('=', $temp_a[0], 2); if($temp_b[1]){ // has just fieldname & value $taxonomy = trim( $temp_b[0] ); $term = trim( $temp_b[1] ); }else{ // has just value $term = trim( $temp_b[0] ); } } return(array('taxonomy' => $taxonomy, 'term' => $term)); } // add tools to edit screens function edit_page_form() { $this->edit_insert_tag_form(); // $this->edit_insert_tools(); $this->edit_insert_machinetag_form(); } function edit_post_form() { // $this->edit_insert_tools(); $this->edit_insert_machinetag_form(); } function edit_comment_form() { // there's no edit_comment_form hook!!! $this->edit_insert_tag_form(); $this->edit_insert_tools(); $this->edit_insert_machinetag_form(); } function edit_insert_tag_form() { global $post_ID; ?>
    Tags (separate multiple tags with commas: cats, pet food, dogs)
    bSuite Tools: Auto Tag Auto Excerpt (about these tools) (NOT WORKING, for now)
    taxonomy == 'post_tag' || $tag->taxonomy == 'category') continue; $tags_to_edit[] = $tag->taxonomy .'='. $tag->name; } natcasesort($tags_to_edit); ?>
    bSuite Machine Tags (separate multiple tags with newlines, about machine tags)

    Optional Excerpt

    ID; // needs an ID of that page/post if(!id) return(NULL); extract($args, EXTR_SKIP); $options = get_option('bsuite_related_posts'); $title = empty($options['title']) ? __('Related Posts', 'bsuite') : $options['title']; if ( !$number = (int) $options['number'] ) $number = 5; else if ( $number < 1 ) $number = 1; else if ( $number > 15 ) $number = 15; if ( $related_posts = array_slice($this->bsuggestive_getposts(), 0, $number) ) { ?>

    '; echo '
  • bookmark and share icon Bookmark and Share
  • '; echo '
  • RSS and feeds icon RSS Feeds
  • '; echo '
  • RSS and feeds icon Translate
  • '; echo ''; echo $after_widget; } function widget_recently_commented_posts($args) { // this code pretty much directly rips off WordPress' native recent comments widget, // the difference here is that I'm displaying recently commented posts, not recent comments. global $wpdb, $commented_posts; extract($args, EXTR_SKIP); $options = get_option('bsuite_recently_commented_posts'); $title = empty($options['title']) ? __('Recently Commented Posts', 'bsuite') : $options['title']; if ( !$number = (int) $options['number'] ) $number = 5; else if ( $number < 1 ) $number = 1; else if ( $number > 15 ) $number = 15; if ( !$commented_posts = wp_cache_get( 'recently_commented_posts', 'widget' ) ) { $commented_posts = $wpdb->get_results("SELECT comment_ID, comment_post_ID, COUNT(comment_post_ID) as comment_count, MAX(comment_date_gmt) AS sort_order FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID ORDER BY sort_order DESC LIMIT $number"); wp_cache_add( 'recently_commented_posts', $commented_posts, 'widget' ); } ?> widget_recently_commented_posts_delete_cache(); } $title = attribute_escape($options['title']); if ( !$number = (int) $options['number'] ) $number = 5; ?>

    'bsuite_recently_commented_posts'); wp_register_sidebar_widget('bsuite-recently-commented-posts', __('bSuite Recently Commented', 'bsuite'), array($this, 'widget_recently_commented_posts'), $class); wp_register_widget_control('bsuite-recently-commented-posts', __('bSuite Recently Commented', 'bsuite'), array($this, 'widget_recently_commented_posts_control'), $class, 'width=320&height=90'); if ( is_active_widget('widget_recently_commented_posts') ){ add_action('wp_head', 'wp_widget_recent_comments_style'); add_action( 'comment_post', array(&$this, 'widget_recently_commented_posts_delete_cache' )); add_action( 'wp_set_comment_status', array(&$this, 'widget_recently_commented_posts_delete_cache' )); } } function widgets_register(){ $this->widget_recently_commented_posts_register(); wp_register_sidebar_widget('bsuite-related-posts', __('bSuite Related Posts', 'bsuite'), array(&$this, 'widget_related_posts'), 'bsuite_related_posts'); wp_register_widget_control('bsuite-related-posts', __('bSuite Related Posts', 'bsuite'), array(&$this, 'widget_related_posts_control'), 'width=320&height=90'); wp_register_sidebar_widget('bsuite-sharelinks', __('bSuite Share Links', 'bsuite'), array(&$this, 'widget_sharelinks'), 'bsuite_sharelinks'); } // end widgets // administrivia function activate() { $this->createtables(); // set some defaults for the widgets if(!get_option('bsuite_related_posts')) update_option('bsuite_related_posts', array('title' => 'Related Posts', 'number' => 7)); if(!get_option('bsuite_recently_commented_posts')) update_option('bsuite_recently_commented_posts', array('title' => 'Recently Commented Posts', 'number' => 7)); } function createtables() { global $wpdb; $charset_collate = ''; if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { if ( ! empty($wpdb->charset) ) $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; if ( ! empty($wpdb->collate) ) $charset_collate .= " COLLATE $wpdb->collate"; } require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta(" CREATE TABLE $this->search_table ( post_id bigint(20) NOT NULL, content text, title text, PRIMARY KEY (post_id), FULLTEXT KEY search (content, title) ) ENGINE=MyISAM $charset_collate "); } function addmenus() { add_options_page('bSuite Settings', 'bSuite', 8, __FILE__, array(&$this, 'optionspage')); } function optionspage() { global $wpdb; //require(ABSPATH . PLUGINDIR .'/'. plugin_basename(dirname(__FILE__)) .'/core_admin.php'); // apply new settings if form submitted if($_REQUEST['Options'] == __('Rebuild bSuite search index', 'bsuite')){ $this->rebuildmetatables(); }else if($_REQUEST['Options'] == __('Show rewrite rules', 'bsuite')){ echo 'The current rewrite rules (permlink settings):
    ';
    			global $wp_rewrite;
    			$wp_rewrite->flush_rules();
    			print_r( $wp_rewrite->rewrite_rules() );
    			echo '
    '; }else if($_REQUEST['Options'] == __('PHP Info', 'bsuite')){ phpinfo(); } // output settings/configuration form ?>

         
    $val) { switch ($val['type']) { case 'open': array_push($hash_stack, $val['tag']); if (isset($val['attributes'])) $ret = $this->composeArray($ret, $hash_stack, $val['attributes']); else $ret = $this->composeArray($ret, $hash_stack); break; case 'close': array_pop($hash_stack); break; case 'cdata': array_push($hash_stack, 'cdata'); $ret = $this->composeArray($ret, $hash_stack, $val['value']); array_pop($hash_stack); break; case 'complete': array_push($hash_stack, $val['tag']); $ret = $this->composeArray($ret, $hash_stack, $val['value']); array_pop($hash_stack); // handle attributes if (isset($val['attributes'])){ foreach($val['attributes'] as $a_k=>$a_v){ $hash_stack[] = $val['tag'].'_attribute_'.$a_k; $ret = $this->composeArray($ret, $hash_stack, $a_v); array_pop($hash_stack); } } break; } } return($ret); } // end makeXMLTree function &composeArray($array, $elements, $value=array()){ // function used exclusively by makeXMLTree to help turn XML into an array // get current element $element = array_shift($elements); // does the current element refer to a list if(sizeof($elements) > 0){ $array[$element][sizeof($array[$element])-1] = &$this->composeArray($array[$element][sizeof($array[$element])-1], $elements, $value); }else{ // if (is_array($value)) $array[$element][sizeof($array[$element])] = $value; } return($array); } // end composeArray function rebuildmetatables() { // update search table with content from all posts global $wpdb; set_time_limit(0); ignore_user_abort(TRUE); $interval = 50; if( !isset( $_REQUEST[ 'n' ] ) ) { $n = 0; $wpdb->hide_errors(); $this->createtables(); $wpdb->show_errors(); } else { $n = (int) $_REQUEST[ 'n' ] ; } $posts = $wpdb->get_results("SELECT ID, post_content, post_title FROM $wpdb->posts ORDER BY ID LIMIT $n, $interval ", ARRAY_A); if( is_array( $posts ) ) { echo '

    ' . __('Rebuilding bSuite search index. Please be patient.', 'bsuite') . '

    '; print "
      "; foreach( $posts as $post ) { $this->searchsmart_upindex($post['ID'], $post['post_content'], $post['post_title']); echo '
    • updated post '. $post['ID'] ."
    • \n "; flush(); } print "
    "; ?>

    '. __('bSuite metdata index rebuilt.', 'bsuite') .'

    '; ?> Code re-used under the terms of the GPL license http://sourceforge.net/projects/sms-api/ SMS-API Sourceforge project page get API ID and account at http://www.clickatell.com/ : Clickatell documentation at https://www.clickatell.com/developers/api_http.php it's worth knowing the Clickatell privacy policy too: http://www.clickatell.com/company/privacy.php example usage: $mysms = new bSuite_sms( $API_ID, $USERNAME, $PASSWORD ); $mysms->send( $YOUR_MESSAGE, $TO_PHONE_NUMBER ); */ var $use_ssl = FALSE; var $balace_limit = 0; var $balance = FALSE; var $sending_method = 'fopen'; var $unicode = FALSE; var $curl_use_proxy = FALSE; var $curl_proxy = 'http://127.0.0.1:8080'; var $curl_proxyuserpwd = 'login:secretpass'; var $session; var $error; var $callback = 0; var $msgstatuscodes = array( '001' => 'Message unknown. The message ID is incorrect or reporting is delayed.', '002' => 'Message queued. The message could not be delivered and has been queued for attempted redelivery.', '003' => 'Delivered to gateway.Delivered to the upstream gateway or network (delivered to the recipient).', '004' => 'Received by recipient. Confirmation of receipt on the handset of the recipient.', '005' => 'Error with message. There was an error with the message, probably caused by the content of the message itself.', '006' => 'User cancelled message delivery. The message was terminated by an internal mechanism.', '007' => 'Error delivering message. An error occurred delivering the message to the handset.', '008' => 'OK. Message received by gateway.', '009' => 'Routing error. The routing gateway or network has had an error routing the message.', '010' => 'Message expired. Message has expired before we were able to deliver it to the upstream gateway. No charge applies.', '011' => 'Message queued for later delivery. Message has been queued at the gateway for delivery at a later time (delayed delivery).', '012' => 'Out of credit. The message cannot be delivered due to a lack of funds in your account. Please re-purchase credits.' ); // codes come from clickatell docs https://www.clickatell.com/downloads/http/Clickatell_HTTP.pdf function bSuite_sms( $api_id = '', $user = '', $password = '' ) { /* authentication details */ if(( !$api_id ) || ( !$user ) || ( !$password )){ $this->error = 'You must specify an api id, username, and password.'; return( FALSE ); } $this->api_id = $api_id; $this->user = $user; $this->password = $password; /* SSL? */ if( $this->use_ssl ) { $this->base = 'http://api.clickatell.com/http'; $this->base_s = 'https://api.clickatell.com/http'; } else { $this->base = 'http://api.clickatell.com/http'; $this->base_s = $this->base; } $this->_auth(); } function _auth() { $comm = sprintf( '%s/auth?api_id=%s&user=%s&password=%s', $this->base_s, $this->api_id, $this->user, $this->password ); $this->session = $this->_parse_auth( $this->_execgw( $comm )); } function getbalance() { $comm = sprintf( '%s/getbalance?session_id=%s', $this->base, $this->session ); $this->balance = $this->_parse_getbalance( $this->_execgw( $comm )); return $this->balance; } /* check the status of a message by the ID returned from the API */ function querymsg( $msgid ) { $comm = sprintf( '%s/querymsg?session_id=%s&apimsgid=%s', $this->base, $this->session, $msgid ); $result = $this->_execgw( $comm ); if( $this->msgstatuscodes[ substr( $result, stripos( $result, 'Status:' ) + 8 ) ] ) return( $this->msgstatuscodes[ substr( $result, stripos( $result, 'Status:' ) + 8 ) ]); else return( $result ); } function send( $text=null, $to=null, $from=null ) { /* Check SMS credits balance */ if( $this->getbalance() < $this->balace_limit ) { $this->error = 'You have reach the SMS credit limit!'; return( FALSE ); }; /* Check SMS $text length */ if( $this->unicode == TRUE ) { $this->_chk_mbstring(); if( mb_strlen( $text ) > 210 ) { $this->error = 'Your unicode message is too long! (Current lenght='.mb_strlen ( $text ).')'; return( FALSE ); } /* Does message need to be concatenate */ if( mb_strlen( $text ) > 70 ) { $concat = '&concat=3'; } else { $concat = ''; } } else { if( strlen( $text ) > 459 ) { $this->error = 'Your message is too long! (Current lenght='.strlen( $text ).')'; return( FALSE ); } /* Does message need to be concatenate */ if( strlen( $text ) > 160 ) { $concat = '&concat=3'; } else { $concat = ''; } } /* Check $to is not empty */ if( empty( $to )) { $this->error = 'You not specify destination address (TO)!'; return( FALSE ); } /* $from is optional and not universally supported */ /* Reformat $to number */ $cleanup_chr = array( '+', ' ', '(', ')', '\r', '\n', '\r\n'); $to = str_replace( $cleanup_chr, '', $to ); /* Mark this for later */ $this->last_to = $to; $this->last_from = $from; $this->last_message = $text; /* Send SMS now */ $comm = sprintf( '%s/sendmsg?session_id=%s&to=%s&from=%s&text=%s&callback=%s&unicode=%s%s', $this->base, $this->session, rawurlencode( $to ), rawurlencode( $from ), $this->encode_message( $text ), $this->callback, $this->unicode, $concat ); return $this->_parse_send( $this->_execgw( $comm )); } function encode_message( $text ) { if( $this->unicode != TRUE ) { //standard encoding return rawurlencode( $text ); } else { //unicode encoding $uni_text_len = mb_strlen( $text, 'UTF-8' ); $out_text = ''; //encode each character in text for( $i=0; $i<$uni_text_len; $i++ ) { $out_text .= $this->uniord( mb_substr( $text, $i, 1, 'UTF-8' )); } return $out_text; } } function uniord( $c ) { $ud = 0; if( ord( $c{0} )>=0 && ord( $c{0} )<=127 ) $ud = ord( $c{0} ); if( ord( $c{0} )>=192 && ord( $c{0} )<=223 ) $ud = ( ord( $c{0} )-192 )*64 + ( ord( $c{1} )-128 ); if( ord( $c{0} )>=224 && ord( $c{0} )<=239 ) $ud = ( ord( $c{0} )-224 )*4096 + ( ord( $c{1} )-128 )*64 + ( ord( $c{2} )-128 ); if( ord( $c{0} )>=240 && ord( $c{0} )<=247 ) $ud = ( ord( $c{0} )-240 )*262144 + ( ord( $c{1} )-128 )*4096 + ( ord( $c{2} )-128 )*64 + ( ord( $c{3} )-128 ); if( ord( $c{0} )>=248 && ord( $c{0} )<=251 ) $ud = ( ord( $c{0} )-248 )*16777216 + ( ord( $c{1} )-128 )*262144 + ( ord( $c{2} )-128 )*4096 + ( ord( $c{3} )-128 )*64 + ( ord( $c{4} )-128 ); if( ord( $c{0} )>=252 && ord( $c{0} )<=253 ) $ud = ( ord( $c{0} )-252 )*1073741824 + ( ord( $c{1} )-128 )*16777216 + ( ord( $c{2} )-128 )*262144 + ( ord( $c{3} )-128 )*4096 + ( ord( $c{4} )-128 )*64 + ( ord( $c{5} )-128 ); if( ord( $c{0} )>=254 && ord( $c{0} )<=255 ) //error $ud = FALSE; return sprintf( '%04x', $ud ); } function token_pay( $token ) { $comm = sprintf( '%s/http/token_pay?session_id=%s&token=%s', $this->base, $this->session, $token ); return $this->_execgw( $comm ); } function _execgw( $command ) { if( $this->sending_method == 'curl' ) return $this->_curl( $command ); if( $this->sending_method == 'fopen' ) return $this->_fopen( $command ); $this->error = 'Unsupported sending method!'; return( FALSE ); } function _curl( $command ) { $this->_chk_curl(); $ch = curl_init( $command ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER,1 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER,0 ); if( $this->curl_use_proxy ) { curl_setopt( $ch, CURLOPT_PROXY, $this->curl_proxy ); curl_setopt( $ch, CURLOPT_PROXYUSERPWD, $this->curl_proxyuserpwd ); } $result=curl_exec( $ch ); curl_close( $ch ); return $result; } function _fopen( $command ) { $result = ''; $handler = @fopen( $command, 'r' ); if( $handler ) { while( $line = @fgets( $handler,1024 )) { $result .= $line; } fclose( $handler ); return $result; } else { $this->error = 'Error while executing fopen sending method!
    Please check does PHP have OpenSSL support and is PHP version is greater than 4.3.0.'; return( FALSE ); } } function _parse_auth( $result ) { $session = substr( $result, 4 ); $code = substr( $result, 0, 2 ); if( $code!='OK' ) { $this->error = "Error in SMS authorization! ($result)"; return( FALSE ); } return $session; } function _parse_send( $result ) { if( 'ID' <> substr( $result, 0, 2 )) { $this->error = "Error sending SMS! ($result)"; $this->last_status = 'ERROR'; return( FALSE ); } else { $this->last_id = trim( substr( $result, 3 )); $this->last_status = 'OK'; return( 'OK' ); } } function _parse_getbalance( $result ) { $result = substr( $result, 8 ); return (int ) $result; } function _chk_curl() { if( !extension_loaded( 'curl' )) { $this->error = 'This SMS API class can not work without CURL PHP module! Try using fopen sending method.'; return( FALSE ); } } function _chk_mbstring() { if( !extension_loaded( 'mbstring' )) { $this->error = 'Error. This SMS API class is setup to use Multibyte String Functions module - mbstring, but module not found. Please try to set unicode=false in class or install mbstring module into PHP.'; return( FALSE ); } } } function the_related(){ global $bsuite; echo $bsuite->bsuggestive_the_related(); } function paginated_links(){ GLOBAL $wp_query; $page = 1; if( (int) $wp_query->query_vars['paged'] ) $page = (int) $wp_query->query_vars['paged']; $total = (int) $wp_query->max_num_pages; $page_links = paginate_links( array( 'base' => add_query_arg( 'paged', '%#%' ), 'format' => '', 'total' => $total, 'current' => $page )); if ( $page_links ) echo ""; } function bsuite_feedlink() { global $bsuite; return( $bsuite->feedlink() ); } function bsuite_link2me() { global $bsuite; echo $bsuite->link2me(); } // php4 compatibility, argh if(!function_exists('str_ireplace')){ function str_ireplace($a, $b, $c){ return str_replace($a, $b, $c); } } ?>