'
)
)
),
'wordcount' => 35 ,
'output' => 'php'
);
// Get the curl session object
$session = curl_init($request);
// Set the POST options.
curl_setopt ($session, CURLOPT_POST, TRUE);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, FALSE);
curl_setopt($session, CURLOPT_RETURNTRANSFER, TRUE);
// Do the POST and then close the session
$response = curl_exec($session);
curl_close($session);
// return
if( $response = unserialize( substr( $response, strpos( $response, 'a:' ))))
return( $response );
else
return( FALSE );
}
// function autoksum_excerpt_image(){
// return( apply_filters( 'bsuite_excerpt', $api_result['summary'] ));
// }
function autoksum_backfill(){
global $wpdb;
$posts = $wpdb->get_results( 'SELECT ID, post_content
FROM '. $wpdb->posts .'
WHERE post_status = "publish"
AND post_excerpt = ""
LIMIT 5' );
if( count( $posts )) {
$insert = array();
foreach( $posts as $post ) {
$api_result = $this->autoksum_doapi( $post->post_content );
if( $api_result['summary'] ){
$insert[] = '('. (int) $post->ID .', "'. $wpdb->escape( $api_result['summary'] ) .'")';
$post_tags[ $post->ID ] = array_merge( $api_result['caps'], $api_result['keywords'] );
}else{
$insert[] = '('. (int) $post->ID .', "'. $wpdb->escape( wp_trim_excerpt( get_post_field( 'post_content', $post->ID ))) .'")';
}
}
}else{
return( FALSE );
}
if( count( $insert )) {
$wpdb->get_results( 'INSERT INTO '. $wpdb->posts .'
(ID, post_excerpt)
VALUES '. implode( ',', $insert ) .'
ON DUPLICATE KEY UPDATE post_excerpt = VALUES( post_excerpt )');
foreach( $post_tags as $post_id => $tags )
if( !get_the_terms( $post_id , 'post_tag' ))
wp_set_post_tags( $post_id, $tags , FALSE);
}
// need to delete any affected post caches here
return( count( $posts ));
}
function css_default() {
?>
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( $id ), 0, $number )) {
?>
';
echo ' Bookmark and Share ';
echo ' RSS Feeds ';
echo ' 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 widget_popular_posts($args) {
global $post, $wpdb;
extract($args, EXTR_SKIP);
$options = get_option('bstat_pop_posts');
$title = empty($options['title']) ? __('Popular Posts') : $options['title'];
if ( !$number = (int) $options['number'] )
$number = 5;
else if ( $number < 1 )
$number = 1;
else if ( $number > 15 )
$number = 15;
if ( !$days = (int) $options['days'] )
$days = 7;
else if ( $days < 1 )
$days = 1;
else if ( $days > 30 )
$days = 30;
if ( !$pop_posts = wp_cache_get( 'bstat_pop_posts', 'widget' ) ) {
$pop_posts = $this->pop_posts("limit=$number&days=$days");
wp_cache_add( 'bstat_pop_posts', $pop_posts, 'widget', 3600 );
}
if ( !empty($pop_posts) ) {
?>
widget_popular_posts_delete_cache();
}
$title = attribute_escape($options['title']);
if ( !$number = (int) $options['number'] )
$number = 5;
if ( !$days = (int) $options['days'] )
$days = 7;
?>
15 )
$number = 15;
if ( !$days = (int) $options['days'] )
$days = 7;
else if ( $days < 1 )
$days = 1;
else if ( $days > 30 )
$days = 30;
if ( !$pop_refs = wp_cache_get( 'bstat_pop_refs', 'widget' ) ) {
$pop_refs = $this->pop_refs("limit=$number&days=$days");
wp_cache_add( 'bstat_pop_refs', $pop_refs, 'widget', 3600 );
}
if ( !empty($pop_refs) ) {
?>
widget_popular_refs_delete_cache();
}
$title = attribute_escape($options['title']);
if ( !$number = (int) $options['number'] )
$number = 5;
if ( !$days = (int) $options['days'] )
$days = 7;
?>
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');
wp_register_sidebar_widget('bstat-pop-posts', __('bStat Posts'), array(&$this, 'widget_popular_posts'), 'bstat-pop-posts');
wp_register_widget_control('bstat-pop-posts', __('bStat Posts'), array(&$this, 'widget_popular_posts_control'), 'width=320&height=90');
wp_register_sidebar_widget('bstat-pop-refs', __('bStat Refs'), array(&$this, 'widget_popular_refs'), 'bstat-pop-refs');
wp_register_widget_control('bstat-pop-refs', __('bStat Refs'), array(&$this, 'widget_popular_refs_control'), 'width=320&height=90');
}
// end widgets
// administrivia
function activate() {
update_option('bsuite_doing_migration', time() + 7200 );
$this->createtables();
$this->cron_register();
// set some defaults for the plugin
if(!get_option('bsuite_insert_related'))
update_option('bsuite_insert_related', TRUE);
if(!get_option('bsuite_insert_sharelinks'))
update_option('bsuite_insert_sharelinks', FALSE);
if(!get_option('bsuite_searchsmart'))
update_option('bsuite_searchsmart', TRUE);
if(!get_option('bsuite_swhl'))
update_option('bsuite_swhl', TRUE);
if(!get_option('bsuite_insert_css'))
update_option('bsuite_insert_css', TRUE);
if(!get_option('bsuite_migration_interval'))
update_option('bsuite_migration_interval', 90);
if(!get_option('bsuite_migration_count'))
update_option('bsuite_migration_count', 100);
if(!get_option('bsuite_load_max'))
update_option('bsuite_load_max', 4);
// allow authors to edit their own pages by default
if(!get_option('bsuite_who_can_edit'))
update_option('bsuite_who_can_edit', 'authors');
// 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));
if(!get_option('bstat_pop_posts'))
update_option('bstat_pop_posts', array('title' => 'Popular Posts', 'number' => 5, 'days' => 7));
if(!get_option('bstat_pop_refs'))
update_option('bstat_pop_refs', array('title' => 'Popular Searches', 'number' => 5));
}
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
");
dbDelta("
CREATE TABLE $this->hits_incoming (
in_time timestamp NOT NULL default CURRENT_TIMESTAMP,
in_type tinyint(4) NOT NULL default '0',
in_session varchar(32) default '',
in_to text NOT NULL,
in_from text,
in_extra text
) ENGINE=MyISAM $charset_collate
");
dbDelta("
CREATE TABLE $this->hits_terms (
term_id bigint(20) NOT NULL auto_increment,
name varchar(255) NOT NULL default '',
PRIMARY KEY (term_id),
UNIQUE KEY name_uniq (name),
KEY name (name(8))
) ENGINE=MyISAM $charset_collate
");
dbDelta("
CREATE TABLE $this->hits_targets (
object_id bigint(20) unsigned NOT NULL default '0',
object_type smallint(6) NOT NULL,
hit_count smallint(6) unsigned NOT NULL default '0',
hit_date date NOT NULL default '0000-00-00',
PRIMARY KEY (object_id,object_type,hit_date)
) ENGINE=MyISAM $charset_collate
");
dbDelta("
CREATE TABLE $this->hits_searchphrases (
object_id bigint(20) unsigned NOT NULL default '0',
object_type smallint(6) NOT NULL,
term_id bigint(20) unsigned NOT NULL default '0',
hit_count smallint(6) unsigned NOT NULL default '0',
PRIMARY KEY (object_id,object_type,term_id),
KEY term_id (term_id)
) ENGINE=MyISAM $charset_collate
");
dbDelta("
CREATE TABLE $this->hits_sessions (
sess_id bigint(20) NOT NULL auto_increment,
sess_cookie varchar(32) NOT NULL default '',
sess_date datetime default NULL,
sess_ip varchar(16) NOT NULL default '',
sess_bl varchar(8) default '',
sess_bb varchar(24) default '',
sess_br varchar(24) default '',
sess_ba varchar(200) default '',
PRIMARY KEY (sess_id),
UNIQUE KEY sess_cookie_uniq (sess_cookie),
KEY sess_cookie (sess_cookie(2))
) ENGINE=MyISAM $charset_collate
");
dbDelta("
CREATE TABLE $this->hits_shistory (
sess_id bigint(20) NOT NULL auto_increment,
object_id bigint(20) NOT NULL,
object_type smallint(6) NOT NULL,
KEY sess_id (sess_id),
KEY object_id (object_id,object_type)
) ENGINE=MyISAM $charset_collate
");
dbDelta("
CREATE TABLE $this->hits_pop (
post_id bigint(20) NOT NULL,
date_start date NOT NULL,
hits_total bigint(20) NOT NULL,
hits_recent int(10) NOT NULL
) ENGINE=MyISAM $charset_collate
");
}
function mu_options( $options ) {
$added = array( 'bsuite' => array( 'bsuite_insert_related', 'bsuite_insert_sharelinks', 'bsuite_searchsmart', 'bsuite_swhl', 'bsuite_who_can_edit' ));
$options = add_option_whitelist( $added, $options );
return( $options );
}
function addmenus() {
add_options_page('bSuite Settings', 'bSuite', 8, 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', 2, plugin_basename( dirname( __FILE__ )) .'/ui_stats.php' );
}
function kses_allowedposttags() {
global $allowedposttags;
$allowedposttags['h1']['id'] = array();
$allowedposttags['h1']['class'] = array();
$allowedposttags['h2']['id'] = array();
$allowedposttags['h2']['class'] = array();
$allowedposttags['h3']['id'] = array();
$allowedposttags['h3']['class'] = array();
$allowedposttags['h4']['id'] = array();
$allowedposttags['h4']['class'] = array();
$allowedposttags['h5']['id'] = array();
$allowedposttags['h5']['class'] = array();
$allowedposttags['h6']['id'] = array();
$allowedposttags['h6']['class'] = array();
return(TRUE);
}
function makeXMLTree($data){
// create parser
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser);
// we store our path here
$hash_stack = array();
// this is our target
$ret = array();
foreach ($values as $key => $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 command_rebuild_searchsmart() {
// update search table with content from all posts
global $wpdb;
set_time_limit(0);
ignore_user_abort(TRUE);
$interval = 25;
if( !isset( $_REQUEST[ 'n' ] ) ) {
$n = 0;
$this->createtables();
$wpdb->get_results( 'TRUNCATE TABLE '. $this->search_table );
} else {
$n = (int) $_REQUEST[ 'n' ] ;
}
if( $count = $this->searchsmart_upindex() ) {
echo '' . __('Rebuilding bSuite search index.', 'bsuite') . ' Already did '. ( $n + $count ) .', be patient already!
'. __('bSuite metdata index rebuilt.', 'bsuite') .'
';
?>
autoksum_backfill() ) {
echo '' . __('Generating excerpts.', 'bsuite') . ' Already did '. ( $n + $count ) .', be patient already!
'. __('All posts now have excerpts! All done.', '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 "$page_links
";
}
function bsuite_feedlink() {
global $bsuite;
return( $bsuite->feedlink() );
}
function bsuite_link2me() {
global $bsuite;
echo $bsuite->link2me();
}
function bstat_hits($template = '%%hits%% hits, about %%avg%% daily', $post_id = NULL, $todayonly = 0, $return = NULL) {
global $bsuite;
if(!empty($return))
return($bsuite->post_hits(array('post_id' => $post_id,'days' => $todayonly, 'template' => $template )));
echo $bsuite->post_hits(array('post_id' => $post_id,'days' => $todayonly, 'template' => $template ));
}
// deprecated functions
function bstat_pulse($post_id = 0, $maxwidth = 400, $disptext = 1, $dispcredit = 1, $accurate = 4) {
// this one isn't so much deprecated as, well,
// the code sucks and I haven't re-written it yet
global $wpdb, $bstat;
$post_id = (int) $post_id;
$for_post_id = $post_id > 1 ? 'AND post_id = '. $post_id : '';
// here's the query, but let's try to get the data from cache first
$request = "SELECT
SUM(hit_count) AS hits,
hit_date
FROM $bstat->hits_table
WHERE 1=1
$for_post_id
GROUP BY hit_date
";
if ( !$result = wp_cache_get( $post_id, 'bstat_post_pulse' ) ) {
$result = $wpdb->get_results($request, ARRAY_A);
wp_cache_add( $post_id, $result, 'bstat_post_pulse', 3600 );
}
if(empty($result))
return(NULL);
$tot = count($result);
if(count($result)>0){
$point = null;
$point[] = 0;
foreach($result as $row){
$point[] = $row['hits'];
}
$sum = array_sum($point);
$max = max($point);
$avg = round($sum / $tot);
if($accurate == 4){
$graphaccurate = get_option('bstat_graphaccurate');
}else{
$graphaccurate = $accurate;
}
$minwidth = ($maxwidth / 8.1);
if($graphaccurate) $minwidth = ($maxwidth / 4.1);
while(count($point) <= $minwidth){
$newpoint = null;
for ($i = 0; $i < count($point); $i++) {
if($i > 0){
if(!$graphaccurate) $newpoint[] = ((($point[$i-1] * 2) + $point[$i]) / 3);
$newpoint[] = (($point[$i-1] + $point[$i]) / 2);
if(!$graphaccurate) $newpoint[] = (($point[$i-1] + ($point[$i-1] * 2)) / 3);
}
$newpoint[] = $point[$i];
}
$point = $newpoint;
}
$tot = count($point);
$width = round($maxwidth / $tot);
if($width > 3)
$width = 4;
if($width < 1)
$width = 1;
if(($width * $tot) > $maxwidth)
$skipstart = (($width * $tot) - $maxwidth) / $width;
$i = 1;
$hit_chart = "";
foreach($point as $row){
if((!$skipstart) || ($i > $skipstart)){
$hit_chart .= " ";
}
$i++;
}
$pre = "";
$post = "
";
$disptext = ($disptext == 1) ? (number_format($sum) .' total reads, averaging '. number_format($avg) .' daily') : ("");
$dispcredit = ($dispcredit == 1) ? ("stats powered by bSuite bStat ") : ("");
$disptext = (($disptext) || ($dispcredit)) ? ("\n$disptext\n $dispcredit
") : ("");
echo($pre . $hit_chart . "\n" . $disptext . $post);
}
}
// php4 compatibility, argh
if(!function_exists('str_ireplace')){
function str_ireplace($a, $b, $c){
return str_replace($a, $b, $c);
}
}
?>