st_url = WP_PLUGIN_URL . '/socialize-this';
add_action('admin_menu', array($this, 'admin_menu'));
add_action('publish_post', array($this, 'admin_submit_post'), 10, 1);
add_action('admin_head', array($this, 'st_admin_jquery_css'), 10, 1);
add_action('wp_head', array($this, 'runSocialGraph'));
if (get_option('st_include_in_posts') == 'yes') {
add_filter('comments_template', array($this, 'show_social_widgets'), 10, 0);
}
if (get_option('st_css_sheet') == TRUE) {
wp_register_style('SocializeThis', WP_PLUGIN_URL . '/socialize-this/st.css');
wp_enqueue_style('SocializeThis');
}
add_filter('plugin_row_meta', array($this, 'extra_plugin_links'), 10, 2);
add_shortcode('socializethis', array($this, 'show_social_widgets'));
wp_register_sidebar_widget('st_show_sidebar_widgets', 'Socialize This Widgets', array($this, 'show_sidebar_widgets'), array('description' => 'Show your Socialize This Widgets. If your not on a page/post, the home URL will be used.'));
// Set up the Twitter Class
$consumer_key = '0r2lXhprQxR5tY1XBZhc8g';
$consumer_secret = 'q0BLVNV2kEtrKYSM4OiRqcYe5xxjUYuStBOwXVjj1ko';
if (get_option('st_consumer_key') != '' && get_option('st_consumer_secret') != '') {
$consumer_key = get_option('st_consumer_key');
$consumer_secret = get_option('st_consumer_secret');
}
$this->t = new Twitter($consumer_key, $consumer_secret, get_option('st_oauth_token'), get_option('st_oauth_token_secret'));
if (get_option('st_url_shortening_service') == 'bitly') {
$this->bitly = new BitLy(get_option('st_bitly_user'), get_option('st_bitly_apikey'));
}
add_action( 'add_meta_boxes', array($this, 'postInfo'));
}
// Save a bit of CPU/RAM by only setting these up when the admin is in the admin end.
private function adminSettings__construct(){
if (wp_get_schedule('updateSocialized') == FALSE) {
wp_schedule_event(time(), 'hourly', 'updateSocialized');
}
if (wp_get_schedule('updateSocializedSite') == FALSE) {
wp_schedule_event(time(), 'daily', 'updateSocializedSite');
}
}
public function stCSS() {
echo ' ';
}
public function extra_plugin_links($links, $file) {
if ($file == 'socialize-this/socialize-this.php') {
$links[] = '@MikeRogers0 ';
}
return $links;
}
public function postInfo(){
global $post;
if($post->post_status == 'publish'){
add_meta_box(
'st_postInfo',
__( 'Socialize This Stats', 'st_plugin' ),
array($this, 'postInfoDisplay'),
'post',
'side'
);
add_meta_box(
'st_postInfo',
__( 'Socialize This Stats', 'st_plugin' ),
array($this, 'postInfoDisplay'),
'page',
'side'
);
}
}
public function postInfoDisplay(){
global $post;
if(get_post_meta($post->ID, 'st_twitter', true) !== ''){
$twitter = get_post_meta($post->ID, 'st_twitter', true);
$facebook = get_post_meta($post->ID, 'st_facebook', true);
$googleplusone = get_post_meta($post->ID, 'st_googleplusones', true);
echo '
'.__('Tweets').': '.$twitter.'
'.__('Facebook Shares').': '.$facebook.'
'.__('Google Plus Ones').': '.$googleplusone.'
';
}else{
echo ''.__('This post\'s socialisation has not been analysed yet.').''.__('Click here to run on this test').' '.'
';
}
if(get_post_meta($post->ID, 'st_tiny_url', true)){
echo ''.__('Short URL: ').'
';
}
}
// admin_menu() - add's the admin menus
public function admin_menu() {
if (get_option('st_menu_page') == TRUE) {
add_menu_page('Socialize This', 'Socialize This', 'manage_options', 'socialize-this', array($this, 'socialize_this_settings'));
} else {
add_options_page('Socialize This', 'Socialize This', 'manage_options', 'socialize-this', array($this, 'socialize_this_settings'));
}
}
public function st_admin_jquery_css() {
global $plugin_page;
if ($plugin_page == 'socialize-this') {
wp_enqueue_script("jquery");
echo ' ';
}
}
// st_adm_header() - echos the Header HTML
private function st_adm_header() {
?>
()
' . $note . '';
}
}
private function st_adm_general() {
$orderby = 'st_social_score';
if(isset($_GET['orderby']) && ($_GET['orderby'] == 'st_twitter' || $_GET['orderby'] == 'st_facebook' || $_GET['orderby'] == 'st_googleplusones' || $_GET['orderby'] == 'st_last_socialized')){
$orderby = $_GET['orderby'];
}
$order = 'DESC';
$orderRv = 'ASC';
if(isset($_GET['orderby']) && $_GET['order'] == 'ASC'){
$order = 'ASC';
$orderRv = 'DESC';
}
?>
: st_ifBlankPutZero(get_option('st_site_twitter')); ?> , st_ifBlankPutZero(get_option('st_site_facebook')); ?> st_ifBlankPutZero(get_option('st_site_googleplusones')); ?> +1's.
st_ifBlankPutZero(get_post_meta($socialPost->ID, 'st_twitter', true));
$reddit = get_post_meta($socialPost->ID, 'st_reddit', true);
$facebook = $this->st_ifBlankPutZero(get_post_meta($socialPost->ID, 'st_facebook', true));
$googleplusone = $this->st_ifBlankPutZero(get_post_meta($socialPost->ID, 'st_googleplusones', true));
?>
post_title; ?>
st_ifBlankPutZero($reddit['score']); ?> (st_ifBlankPutZero($reddit['num_comments']); ?> )
+1's
ID, 'st_last_socialized', true)){
echo date("F j, Y, g:i a", get_post_meta($socialPost->ID, 'st_last_socialized', true));
} else {
_e('Refresh', 'st_plugin');
}
?>
t->accessToken($_GET['oauth_verifier']) != FALSE) {
update_option('st_oauth_token', (string) $this->t->oauth_token);
update_option('st_oauth_token_secret', (string) $this->t->oauth_token_secret);
update_option('st_oauth_results', '');
update_option('st_noti_twitter', 'authenticated');
update_option('st_noti_twitter_user', (string) $this->t->screen_name);
$note .= '' . __('Twitter Authentication Suscessful.') . '
';
} else {
$note .= '' . __('Twitter Authentication Failed. Try Again.') . '
';
}
}
if (isset($_POST['Submit'])) {
update_option('st_include_in_posts', 'no');
if ($_POST['include_in_posts'] == 'yes') {
update_option('st_include_in_posts', 'yes');
}
update_option('st_url_shortening_service', $_POST['st_url_shortening_service']);
if ($_POST['st_url_shortening_service'] == 'bitly') {
$this->bitly = new BitLy($_POST['st_bitly_user'], $_POST['st_bitly_apikey']);
if ($this->bitly->verifyBitLy() == TRUE) {
update_option('st_bitly_user', $_POST['st_bitly_user']);
update_option('st_bitly_apikey', $_POST['st_bitly_apikey']);
update_option('st_url_shortening_service', 'bitly');
} else {
update_option('st_url_shortening_service', 'isgd');
update_option('st_bitly_user', NULL);
update_option('st_bitly_apikey', NULL);
$note .= '' . __('Bit.ly Authentication Failed. Check your credentials') . '
';
}
} else {
update_option('st_bitly_user', NULL);
update_option('st_bitly_apikey', NULL);
}
if ($_POST['st_noti_twitter'] == 'deactivate') {
update_option('st_noti_twitter', 'deactivated');
}
update_option('st_template_twitter_noti', $_POST['st_template_twitter_noti']);
$note .= '' . __('Settings Updated') . '
';
}
$this->st_adm_notice($note);
?>
st_adm_tagList();
}
private function st_adm_social_widgets() {
if (isset($_POST['add_widget'])) {
$this->addWidget($_POST['author'], $_POST['html'], $_POST['name'], $_POST['author_url']);
$note .= '' . __('Widget Added') . '
';
} elseif (isset($_POST['add_set'])) {
$count = 0;
if (is_array($_POST['set_file'])) {
foreach ($_POST['set_file'] as $set_file) {
$count = $count + ($this->addWidgetSet($set_file));
}
}
if ($count >= 1) {
$note .= 'Widget Set (' . $count . ' Widgets) Added
';
} else {
$note .= '' . __('Widget Set Failed to add') . '.
';
}
} elseif (isset($_POST['edit_widget'])) {
if (is_numeric($_POST['id'])) {
$enabled = 2;
if ($_POST['enabled'] != 2) {
$enabled = 1;
}
$this->updateWidget($_POST['id'], stripslashes($_POST['html']), $_POST['position'], $enabled);
$note .= '' . __('Widget Updated') . '
';
}
} elseif (isset($_POST['save_widgets'])) {
foreach ($_POST['position'] as $id => $position) {
$this->updateWidget($id, NULL, $position, $_POST['enabled'][$id]);
}
$note .= '' . __('Widgets Updated') . '
';
} elseif (isset($_GET['delete_widget'])) {
$this->deleteWidget((int) $_GET['delete_widget']);
$note .= '' . __('Widgets Deleted') . '
';
}
$this->st_adm_notice($note);
?>
st_adm_notice('Open Graph Settings Updated');
}
?>
.
.
updateSocializePost($socialPost);
$note .= __('Post Socialized').' - '.__('Return to Post').' ';
}
}
if(isset($_GET['updateSocializedSite'])){
$this->updateSocializedSite();
$note .= __('Site Socialize Data updated');
}
if (isset($_POST['save_advanced_settings'])) {
if ($_POST['st_css_sheet'] == 'yes') {
update_option('st_css_sheet', FALSE, TRUE);
} else {
update_option('st_css_sheet', TRUE, TRUE);
}
if ($_POST['st_cache'] == 'yes') {
update_option('st_cache', TRUE, TRUE);
} else {
update_option('st_cache', FALSE, TRUE);
}
if ($_POST['st_menu_page'] == 'yes') {
update_option('st_menu_page', TRUE, TRUE);
} else {
update_option('st_menu_page', FALSE, TRUE);
}
update_option('st_consumer_key', $_POST['st_consumer_key']);
update_option('st_consumer_secret', $_POST['st_consumer_secret']);
update_option('st_twitter_apikey', $_POST['st_twitter_apikey']);
$note .= __('Advanced Settings Updated');
}
if (isset($_POST['regenerate_urls'])) {
global $wpdb;
$posts = get_posts('numberposts=-1&post_type=any');
if (is_array($posts)) {
foreach ($posts as $post) {
$permalink = get_permalink($post->ID);
update_post_meta($post->ID, 'st_tiny_url', $this->shorten_url($permalink));
//sleep(1); // Sleep for a few seconds so we don't overload the url shortening system.
}
}
$note .= __('URL\'s ReGenerated');
}
if (isset($_POST['update_socialized'])) {
$this->updateSocialized(4);
$note .= __('Updated Socialized Data');
}
if (isset($_POST['update_all_socialized'])) {
$this->updateSocialized(FALSE);
$note .= __('Updated Socialized Data');
}
if (isset($_POST['reset'])) {
$this->st_uninstall();
$this->st_install();
$note .= __('Setting\'s Reset');
}
if (isset($_POST['test_tweet'])) {
$this->t->updateStatus('This is a test tweet.');
}
$this->st_adm_notice($note);
?>
-
-
-
-
-
%permalink%
%raw_permalink%
%short_url%
%raw_short_url%
%title%
%raw_title%
%description%
%rss_url%
%anywhere%
%twitter_name%
%raw_tags%
%tags%
%raw_date_posted%
%date_posted%
%widgets_url%
adminSettings__construct();
echo '';
$this->st_adm_header();
if (isset($_GET['module'])) {
switch ($_GET['module']) {
case 'social_widgets': $this->st_adm_social_widgets();
break;
case 'edit_widget': $this->st_adm_edit_widget();
break;
case 'templates': $this->st_adm_templates();
break;
case 'open_graph': $this->st_adm_open_graph();
break;
case 'advanced_functions': $this->st_adm_advanced_functions();
break;
case 'settings': $this->st_adm_settings();
break;
case 'tagList': $this->st_adm_tagList();
break;
default: $this->st_adm_general();
}
} else {
$this->st_adm_general();
}
$this->st_adm_footer();
echo '
';
}
private function getTags($post=NULL, $permalink=NULL, $title=NULL) {
// Set up blank data.
$vars = array('%raw_short_url%' => '', '%short_url%' => '', '%description%' => '', '%descirption%' => '',
'%raw_short_url%' => '', '%short_url%' => '', '%raw_tags%' => '', '%tags%' => '', '%raw_date_posted%' => '', '%date_posted%' => '',
'%reddit_score%' => '0', '%reddit_comments%' => '0', '%reddit_link%' => '', '%tweets_count%' => '0');
// Set up some of the custom data
if ($permalink != NULL) {
$vars['%raw_short_url%'] = $permalink;
$vars['%short_url%'] = urlencode($permalink);
}
if (is_numeric($post)) {
$post = get_post($post);
}
if (is_object($post)) {
$permalink = get_permalink($post->ID);
$title = $post->post_title;
if ($post->post_excerpt != '') {
$vars['%description%'] = $post->post_excerpt;
} else {
$vars['%description%'] = $post->post_title;
}
$vars['%descirption%'] = $vars['%description%']; // TODO Remove this line in 2.3.*
$vars['%raw_short_url%'] = get_post_meta($post->ID, 'st_tiny_url', TRUE);
$vars['%short_url%'] = urlencode($vars['%raw_short_url%']);
if ($vars['%short_url%'] == '') {
$vars['%raw_short_url%'] = $permalink;
$vars['%short_url%'] = urlencode($permalink);
}
$posttags = get_the_tags($post->ID);
if (is_array($posttags)) {
foreach ($posttags as $posttag) {
$tags[] = '#' . str_replace(' ', '', $posttag->name);
}
$vars['%raw_tags%'] = implode(' ', $tags);
$vars['%tags%'] = urlencode($vars['%raw_tags%']);
}
if(is_array(get_post_meta($post->ID, 'st_reddit'))){
$reddit = get_post_meta($post->ID, 'st_reddit');
} else {
$reddit = array('permalink'=>'');
}
$twitter = get_post_meta($post->ID, 'st_twitter');
if($reddit != null && $twitter != null){
$vars['%reddit_link%'] = 'http://www.reddit.com/submit?url='.urlencode($permalink).'&title='.urlencode($title);
if($reddit['permalink'] != ''){
$vars['%reddit_link%'] = $reddit['permalink'];
$vars['%reddit_score%'] = $reddit['score'];
$vars['%reddit_comments%'] = $reddit['num_comments'];
}
$vars['%tweets_count%'] = $twitter;
}
$vars['%raw_date_posted%'] = mysql2date(get_option('date_format'), $post->post_date);
$vars['%date_posted%'] = urlencode($vars['%raw_date_posted%']);
}
$vars['%widgets_url%'] = $this->st_url . '/widgets';
$vars['%raw_permalink%'] = $permalink;
$vars['%permalink_raw%'] = $permalink;
$vars['%permalink%'] = urlencode($permalink);
$vars['%raw_title%'] = $title;
$vars['%title%'] = urlencode($title);
$vars['%anywhere%'] = get_option('st_twitter_apikey');
$vars['%twitter_name%'] = get_option('st_noti_twitter_user');
$vars['%rss_url%'] = get_bloginfo('rss2_url');
return $vars;
}
// admin_submit_post()) - Sets up bits of the post which are useful.
public function admin_submit_post($postID) {
$post = get_post($postID);
if (is_object($post) && get_post_meta($post->ID, 'st_tiny_url', TRUE) == '') { // If the tiny url already exists, we will assume it's already been twittered.
$permalink = get_permalink($post->ID);
// Add the shortened URL.
add_post_meta($post->ID, 'st_tiny_url', $this->shorten_url($permalink), true);
// Add the Socialize MetaInfo
add_post_meta($post->ID, 'st_twitter', 0, true);
add_post_meta($post->ID, 'st_reddit', 0, true);
add_post_meta($post->ID, 'st_social_score', 0, true);
add_post_meta($post->ID, 'st_last_socialized', 0, true);
if (get_option('st_noti_twitter') == 'authenticated') {
$vars = $this->getTags($post);
$vars = apply_filters('st-tweet-tags', $vars);
$this->twitter_update_status($this->sprintf4(get_option('st_template_twitter_noti'), $vars));
}
}
}
private function shorten_url($url) {
if (get_option('st_url_shortening_service') == 'tinyurl') {
return $this->get_link('http://tinyurl.com/api-create.php?url=' . urlencode($url));
} elseif (get_option('st_url_shortening_service') == 'urly') {
return $this->get_link('http://ur.ly/new.txt?href=' . urlencode($url));
} elseif (get_option('st_url_shortening_service') == 'trim') {
return $this->get_link('http://api.tr.im/v1/trim_simple?url=' . urlencode($url));
} elseif (get_option('st_url_shortening_service') == 'klam') {
return $this->get_link('http://kl.am/api/shorten/?format=text&url=' . urlencode($url));
} elseif (get_option('st_url_shortening_service') == 'unu') {
return $this->get_link('http://u.nu/unu-api-simple?url=' . urlencode($url));
} elseif (get_option('st_url_shortening_service') == 'bitly') {
return $this->bitly->shorten($url);
} elseif (get_option('st_url_shortening_service') == 'googl') {
return $this->googlLink($url);
} else {
return $this->get_link('http://is.gd/api.php?longurl=' . urlencode($url));
}
return $url;
}
public function get_link($url) {
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
//curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$resultArray = curl_getinfo($ch);
curl_close($ch);
if ($resultArray['http_code'] == 200) {
return $result;
} else {
return FALSE;
}
} elseif (ini_get('allow_url_fopen') == 1) {
return fopen($url, 'r');
}
return FALSE;
}
public function googlLink($url) {
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://goo.gl/api/shorten');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'security_token=null&url=' . urlencode($url));
$results = curl_exec($ch);
$headerInfo = curl_getinfo($ch);
curl_close($ch);
if ($headerInfo['http_code'] === 201) { // HTTP Code 201 = Created
$results = json_decode($results);
if (isset($results->short_url)) {
return $results->short_url;
}
return $url;
}
return $url;
}
return $url;
}
public function show_sidebar_widgets($args=null, $params=null){
$this->show_social_widgets();
}
public function show_social_widgets($wigets=NULL, $post=NULL, $permalink=NULL, $title=NULL) {
// If this is for a custom post.
if (is_numeric($post)) {
$post = get_post($post);
} elseif($post == NULL) {
global $post;
}
// If we have the html already, show the cache.
if (is_object($post)) {
if (get_post_meta($post->ID, 'st_hide_icons', TRUE) == TRUE) {
return FALSE;
}
if (get_option('st_cache') != TRUE && get_post_meta($post->ID, 'st_cached_time', TRUE) > get_option('st_cached_time')) { // Check if the cache is up to date.
echo get_post_meta($post->ID, 'st_cached', TRUE);
return TRUE;
}
} elseif(!is_object($post) && $permalink == null && $title == null) { // If we don't have a post Object or anything, lets show the homepage.
$permalink = get_site_url();
$title = get_bloginfo('name');
}
$vars = $this->getTags($post, $permalink, $title);
$vars = apply_filters('st-tags', $vars);
if ($wigets != null) {
$widgets = $this->getWidgets(NULL, $wigets, TRUE);
} else {
$widgets = $this->getWidgets(2, NULL, TRUE);
}
$output = $this->sprintf4('' . implode(' ', $widgets) . ' ', $vars);
echo $output;
if (is_object($post)) {
// Now update the cache
update_post_meta($post->ID, 'st_cached', $output);
update_post_meta($post->ID, 'st_cached_time', time());
}
return TRUE;
}
private function showSocialGraphMeta($property, $content) {
if ($property == 'admins' || $property == 'app_id') { // Check for Page Administration properties.
echo ' ' . "\n";
return TRUE;
}
echo ' ' . "\n";
return TRUE;
}
public function runSocialGraph() {
// Check that we can show all the required meta datas.
foreach (array('title', 'type', 'image', 'url') as $value) {
if (get_option('st_og_' . $value . '_enabled') == FALSE) {
return FALSE;
}
}
// Run though the metas which are page/user dependent.
if (get_option('st_og_use' . 'title') == FALSE) {
if(is_home()){
$this->showSocialGraphMeta('title', get_bloginfo( 'name' ).' | '.get_bloginfo( 'description', 'display' ));
} else{
$this->showSocialGraphMeta('title', get_the_title());
}
} else {
$this->showSocialGraphMeta('title', get_option('st_og_' . 'title'));
}
if (get_option('st_og_use' . 'url') == FALSE) {
if(is_home()){
$this->showSocialGraphMeta('url', site_url());
} else{
$this->showSocialGraphMeta('url', get_permalink());
}
} else {
$this->showSocialGraphMeta('url', get_option('st_og_' . 'url'));
}
if (get_option('st_og_use' . 'type') == FALSE) {
if (is_single() || is_page()) {
$this->showSocialGraphMeta('type', 'article');
} else {
$this->showSocialGraphMeta('type', 'blog');
}
} else {
$this->showSocialGraphMeta('type', get_option('st_og_' . 'type'));
}
// Cycle though other meta options.
foreach (array('image', 'site_name', 'admins', 'app_id', 'description') as $value) {
if (get_option('st_og_' . $value . '_enabled') == TRUE) {
$this->showSocialGraphMeta($value, get_option('st_og_' . $value));
}
}
// Do the other Meta stuff.
if (get_option('st_og_' . 'othermeta' . '_enabled') == TRUE) {
echo get_option('st_og_' . 'othermeta');
}
}
// function taken from PHP.net's str_replace documentation.
private function sprintf4($str, $vars) {
return str_replace(array_keys($vars), array_values($vars), $str);
}
public function updateSocialized($limit=2, $debug=FALSE) {
if ($limit == FALSE) {
$socialPosts = get_posts('numberposts=-1&post_type=any');
} else {
$socialPosts = get_posts('numberposts=' . $limit . '&meta_key=st_last_socialized&orderby=meta_value_num&order=ASC&post_type=any');
if ($socialPosts[0] == '') {
$socialPosts = get_posts('numberposts=' . $limit . '&post_type=any');
}
}
foreach ($socialPosts as $socialPost) {
$this->updateSocializePost($socialPost);
}
return TRUE;
}
public function updateSocializePost($socialPost, $debug=FALSE){
$sAPI = new SocializeAPIs;
$url = get_permalink($socialPost->ID);
// Get data about each post + Update.
$twitter = $sAPI->Twitter($url);
update_post_meta($socialPost->ID, 'st_twitter', $twitter);
$reddit = $sAPI->Reddit($url);
update_post_meta($socialPost->ID, 'st_reddit', $reddit);
$FacebookLikes = $sAPI->FacebookLikes($url);
update_post_meta($socialPost->ID, 'st_facebook', $FacebookLikes);
$GooglePlusOnes = $sAPI->GooglePlusOnes($url);
update_post_meta($socialPost->ID, 'st_googleplusones', $GooglePlusOnes);
// Give each post a social score. Which is pretty much (site count * influence)
update_post_meta($socialPost->ID, 'st_social_score', (
($twitter * 3) +
($reddit['score'] * ($reddit['num_comments'] * 2 )) +
($FacebookLikes *3) +
($GooglePlusOnes)
), true);
// Make sure we do the other posts next.
update_post_meta($socialPost->ID, 'st_last_socialized', time());
if ($debug == TRUE) {
echo 'Updated: ' . $socialPost->ID . ' ';
}
return TRUE;
}
public function updateSocializedSite() {
$sAPI = new SocializeAPIs;
$url = site_url();
update_option('st_site_twitter', $sAPI->Twitter($url));
//update_option('st_site_reddit', serialize($sAPI->Reddit($url)));
update_option('st_site_facebook', $sAPI->FacebookLikes($url));
update_option('st_site_googleplusones', $sAPI->GooglePlusOnes($url));
//update_option('st_site_feed', $sAPI->GoogleReader(get_bloginfo('rss2_url')));
update_option('st_site_last_socialized', time());
}
private function twitter_update_status($status) {
return $this->t->updateStatus($status);
}
private function deleteWidget($id=NULL) {
global $wpdb;
$table_name = $wpdb->prefix . "st_social_widgets";
$SQL = 'DELETE FROM ' . $table_name . ' WHERE `ID` = \'' . (int) $id . '\'';
return $wpdb->query($SQL, ARRAY_A);
}
private function getWidgets($enabled=NULL, $widgets=null, $getHTML=null) {
global $wpdb;
$table_name = $wpdb->prefix . "st_social_widgets";
$SQL = 'SELECT * FROM ' . $table_name . ' ';
if ($getHTML == TRUE) {
$SQL = 'SELECT `html` FROM ' . $table_name . ' ';
}
$where[] = 'WHERE 1=1';
if(is_numeric($widgets)){
$where[] = "`ID` = '" . $widgets . "'";
}elseif(is_array($widgets)){
if(is_numeric($widgets[0])){
foreach ($widgets as $var) {
$where_array[] = "`ID` = '" . $var . "'";
}
}else{
foreach ($widgets as $var) {
$where_array[] = "`name` = '" . $var . "'";
}
}
$where[] = '(' . implode(' OR ', $where_array) . ')';
}elseif(!is_numeric($widgets) && !is_array($widgets) && $widgets != null){
$where[] = "`name` = '" . $widgets . "'";
}
if ($enabled == 2 || $enabled == 1) {
$where[] = "`enabled` = " . $enabled . "";
}
if (is_array($where)) {
$SQL = $SQL . implode(' AND ', $where);
}
if ($getHTML == TRUE) {
return $wpdb->get_col($SQL . ' ORDER BY `position` ASC');
}
return $wpdb->get_results($SQL . ' ORDER BY `position` ASC', ARRAY_A);
}
private function addWidgetSet($set_file) {
$widget_set = simplexml_load_file(ST_FOLER . 'widgets/' . $set_file);
if (is_object($widget_set)) {
$author = (string) $widget_set->author;
$author_url = (string) $widget_set->author_url;
$count = 0;
foreach ($widget_set->widget as $widget) {
$count++;
$enabled = 2;
if (isset($widget->enabled)) {
$enabled = $widget->enabled;
}
if (isset($widget->author) && isset($widget->author_url)) {
$this->addWidget((string) $widget->author, (string) $widget->html, (string) $widget->name, (string) $widget->author_url, $enabled);
} else {
$this->addWidget($author, (string) $widget->html, (string) $widget->name, $author_url, $enabled);
}
}
return $count;
}
return FALSE;
}
private function addWidget($author, $html, $name, $author_url='', $enabled=2) {
global $wpdb;
$table_name = $wpdb->prefix . "st_social_widgets";
return $wpdb->insert($table_name, array(
'author' => $author,
'html' => stripslashes($html),
'author_url' => $author_url,
'name' => $name,
'enabled' => (int) $enabled));
}
private function updateWidget($id, $html=NULL, $position=NULL, $enabled=2) {
global $wpdb;
$table_name = $wpdb->prefix . "st_social_widgets";
if ($html != NULL) {
$update['html'] = $html;
}
if ($position != NULL) {
$update['position'] = (int) $position;
}
$update['enabled'] = (int) $enabled;
return $wpdb->update($table_name, $update, array('ID' => $id));
}
public function st_install($upgrade=NULL) {
global $wpdb;
$table_name = $wpdb->prefix . "st_social_widgets";
if ($wpdb->get_var("SHOW TABLES LIKE '.$table_name.'") != $table_name) {
$sql = "CREATE TABLE IF NOT EXISTS " . $table_name . " (
ID mediumint(9) NOT NULL AUTO_INCREMENT,
position mediumint(9) NOT NULL,
enabled int(2) NOT NULL,
author VARCHAR(255) NOT NULL,
author_url VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
html text NOT NULL,
UNIQUE KEY ID (ID)
);";
$wpdb->query($sql);
$this->addWidgetSet('cute.stset.xml');
//if ($upgrade == NULL) { // If it's a fresh install.
update_option('st_template_twitter_noti', 'New Post: %raw_title% %raw_short_url%');
update_option('st_include_in_posts', 'yes'); // activated by default.
update_option('st_menu_page', true);
// Twitter
update_option('st_noti_twitter', 'no');
update_option('st_noti_twitter_user', '');
update_option('st_twitter_apikey', '');
// bit.ly
update_option('st_bitly_user', '');
update_option('st_bitly_apikey', '');
update_option('st_url_shortening_service', 'isgd');
update_option('st_css_sheet', TRUE);
// Open Graph
update_option('st_og_site_name', get_bloginfo('name'));
update_option('st_og_description', get_bloginfo('description'));
//}
}
update_option('st_current_version', ST_VERSION);
//$this->updateSocialized(2); // Do a quick Socialization.
//$this->updateSocializedSite();
}
public function st_uninstall($upgrade=NULL) {
global $wpdb;
//if ($upgrade == NULL) {
$table_name = $wpdb->prefix . "st_social_widgets";
$wpdb->query('DROP TABLE `' . $table_name . '`');
delete_option('st_template_twitter_noti');
// General Settings
delete_option('st_include_in_posts');
delete_option('st_noti_twitter');
delete_option('st_noti_twitter_user');
delete_option('st_twitter_apikey');
// bit.ly
delete_option('st_bitly_user');
delete_option('st_bitly_apikey');
delete_option('st_url_shortening_service');
// Advanced options
delete_option('st_enable_api');
delete_option('st_hide_donate');
delete_option('st_extend_php_limits');
delete_option('st_css_sheet');
delete_option('st_consumer_key');
delete_option('st_consumer_secret');
// House Keeping
delete_option('st_current_version');
// }
// Can get messy.
_set_cron_array(NULL);
}
}
?>