From ca9bd8b877d8ed2306bef76c93bcc6eb77ed1fd1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 10 Jun 2014 20:13:11 +0200 Subject: [PATCH] Removing blanks with tabs --- fbpost/fbpost.php | 8 +- pumpio/pumpio.php | 355 ++++++++++++++++++++-------------------- statusnet/statusnet.php | 80 ++++----- tumblr/tumblr.php | 200 +++++++++++----------- twitter/twitter.php | 247 ++++++++++++++-------------- 5 files changed, 445 insertions(+), 445 deletions(-) mode change 100755 => 100644 pumpio/pumpio.php mode change 100755 => 100644 tumblr/tumblr.php mode change 100755 => 100644 twitter/twitter.php diff --git a/fbpost/fbpost.php b/fbpost/fbpost.php index 60c8e939..b554453f 100644 --- a/fbpost/fbpost.php +++ b/fbpost/fbpost.php @@ -69,7 +69,7 @@ function fbpost_init(&$a) { if(strlen($nick)) $r = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1", - dbesc($nick) + dbesc($nick) ); if(!(isset($r) && count($r))) return; @@ -154,7 +154,7 @@ function fbpost_post(&$a) { $result = q("SELECT `installed` FROM `addon` WHERE `name` = 'fbsync' AND `installed`"); if (count($result) > 0) { set_pconfig(local_user(),'fbsync','sync',intval($_POST['fbsync'])); - set_pconfig(local_user(),'fbsync','create_user',intval($_POST['create_user'])); + set_pconfig(local_user(),'fbsync','create_user',intval($_POST['create_user'])); } info( t('Settings updated.') . EOL); @@ -316,11 +316,11 @@ function fbpost_content(&$a) { $o .= '
'; - $sync_enabled = get_pconfig(local_user(),'fbsync','sync'); + $sync_enabled = get_pconfig(local_user(),'fbsync','sync'); $checked = (($sync_enabled) ? ' checked="checked" ' : ''); $o .= '' . ' ' . t('Import Facebook newsfeed.') . EOL; - $create_user = get_pconfig(local_user(),'fbsync','create_user'); + $create_user = get_pconfig(local_user(),'fbsync','create_user'); $checked = (($create_user) ? ' checked="checked" ' : ''); $o .= '' . ' ' . t('Automatically create contacts.') . EOL; diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php old mode 100755 new mode 100644 index 78b738fa..62467414 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -11,23 +11,23 @@ require('addon/pumpio/oauth/oauth_client.php'); define('PUMPIO_DEFAULT_POLL_INTERVAL', 5); // given in minutes function pumpio_install() { - register_hook('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local'); - register_hook('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send'); - register_hook('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets'); - register_hook('connector_settings', 'addon/pumpio/pumpio.php', 'pumpio_settings'); - register_hook('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post'); - register_hook('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron'); - register_hook('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook'); + register_hook('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local'); + register_hook('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send'); + register_hook('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets'); + register_hook('connector_settings', 'addon/pumpio/pumpio.php', 'pumpio_settings'); + register_hook('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post'); + register_hook('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron'); + register_hook('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook'); } function pumpio_uninstall() { - unregister_hook('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local'); - unregister_hook('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send'); - unregister_hook('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets'); - unregister_hook('connector_settings', 'addon/pumpio/pumpio.php', 'pumpio_settings'); - unregister_hook('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post'); - unregister_hook('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron'); - unregister_hook('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook'); + unregister_hook('post_local', 'addon/pumpio/pumpio.php', 'pumpio_post_local'); + unregister_hook('notifier_normal', 'addon/pumpio/pumpio.php', 'pumpio_send'); + unregister_hook('jot_networks', 'addon/pumpio/pumpio.php', 'pumpio_jot_nets'); + unregister_hook('connector_settings', 'addon/pumpio/pumpio.php', 'pumpio_settings'); + unregister_hook('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post'); + unregister_hook('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron'); + unregister_hook('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook'); } function pumpio_module() {} @@ -61,37 +61,37 @@ function pumpio_registerclient(&$a, $host) { $url = "https://".$host."/api/client/register"; - $params = array(); + $params = array(); $application_name = get_config('pumpio', 'application_name'); if ($application_name == "") $application_name = $a->get_hostname(); - $params["type"] = "client_associate"; - $params["contacts"] = $a->config['admin_email']; - $params["application_type"] = "native"; - $params["application_name"] = $application_name; - $params["logo_url"] = $a->get_baseurl()."/images/friendica-256.png"; - $params["redirect_uris"] = $a->get_baseurl()."/pumpio/connect"; + $params["type"] = "client_associate"; + $params["contacts"] = $a->config['admin_email']; + $params["application_type"] = "native"; + $params["application_name"] = $application_name; + $params["logo_url"] = $a->get_baseurl()."/images/friendica-256.png"; + $params["redirect_uris"] = $a->get_baseurl()."/pumpio/connect"; logger("pumpio_registerclient: ".$url." parameters ".print_r($params, true), LOGGER_DEBUG); - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); - curl_setopt($ch, CURLOPT_POST,1); - curl_setopt($ch, CURLOPT_POSTFIELDS,$params); - curl_setopt($ch, CURLOPT_USERAGENT, "Friendica"); + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); + curl_setopt($ch, CURLOPT_POST,1); + curl_setopt($ch, CURLOPT_POSTFIELDS,$params); + curl_setopt($ch, CURLOPT_USERAGENT, "Friendica"); - $s = curl_exec($ch); - $curl_info = curl_getinfo($ch); + $s = curl_exec($ch); + $curl_info = curl_getinfo($ch); - if ($curl_info["http_code"] == "200") { - $values = json_decode($s); + if ($curl_info["http_code"] == "200") { + $values = json_decode($s); logger("pumpio_registerclient: success ".print_r($values, true), LOGGER_DEBUG); return($values); - } + } logger("pumpio_registerclient: failed: ".print_r($curl_info, true), LOGGER_DEBUG); return(false); @@ -156,10 +156,10 @@ function pumpio_connect(&$a) { } $success = $client->Finalize($success); } - if($client->exit) - $o = 'Could not connect to pumpio. Refresh the page or try again later.'; + if($client->exit) + $o = 'Could not connect to pumpio. Refresh the page or try again later.'; - if($success) { + if($success) { logger("pumpio_connect: authenticated"); $o .= t("You are now authenticated to pumpio."); $o .= '
'.t("return to the connector page").''; @@ -172,118 +172,117 @@ function pumpio_connect(&$a) { } function pumpio_jot_nets(&$a,&$b) { - if(! local_user()) - return; + if(! local_user()) + return; - $pumpio_post = get_pconfig(local_user(),'pumpio','post'); - if(intval($pumpio_post) == 1) { - $pumpio_defpost = get_pconfig(local_user(),'pumpio','post_by_default'); - $selected = ((intval($pumpio_defpost) == 1) ? ' checked="checked" ' : ''); - $b .= '
' - . t('Post to pumpio') . '
'; - } + $pumpio_post = get_pconfig(local_user(),'pumpio','post'); + if(intval($pumpio_post) == 1) { + $pumpio_defpost = get_pconfig(local_user(),'pumpio','post_by_default'); + $selected = ((intval($pumpio_defpost) == 1) ? ' checked="checked" ' : ''); + $b .= '
' + . t('Post to pumpio') . '
'; + } } function pumpio_settings(&$a,&$s) { - if(! local_user()) - return; + if(! local_user()) + return; - /* Add our stylesheet to the page so we can make our settings look nice */ + /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= '' . "\r\n"; + $a->page['htmlhead'] .= '' . "\r\n"; - /* Get the current state of our config variables */ + /* Get the current state of our config variables */ - $import_enabled = get_pconfig(local_user(),'pumpio','import'); - $import_checked = (($import_enabled) ? ' checked="checked" ' : ''); + $import_enabled = get_pconfig(local_user(),'pumpio','import'); + $import_checked = (($import_enabled) ? ' checked="checked" ' : ''); - $enabled = get_pconfig(local_user(),'pumpio','post'); - $checked = (($enabled) ? ' checked="checked" ' : ''); - $css = (($enabled) ? '' : '-disabled'); + $enabled = get_pconfig(local_user(),'pumpio','post'); + $checked = (($enabled) ? ' checked="checked" ' : ''); + $css = (($enabled) ? '' : '-disabled'); - $def_enabled = get_pconfig(local_user(),'pumpio','post_by_default'); - $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); + $def_enabled = get_pconfig(local_user(),'pumpio','post_by_default'); + $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); - $public_enabled = get_pconfig(local_user(),'pumpio','public'); - $public_checked = (($public_enabled) ? ' checked="checked" ' : ''); + $public_enabled = get_pconfig(local_user(),'pumpio','public'); + $public_checked = (($public_enabled) ? ' checked="checked" ' : ''); - $mirror_enabled = get_pconfig(local_user(),'pumpio','mirror'); - $mirror_checked = (($mirror_enabled) ? ' checked="checked" ' : ''); + $mirror_enabled = get_pconfig(local_user(),'pumpio','mirror'); + $mirror_checked = (($mirror_enabled) ? ' checked="checked" ' : ''); - $servername = get_pconfig(local_user(), "pumpio", "host"); - $username = get_pconfig(local_user(), "pumpio", "user"); + $servername = get_pconfig(local_user(), "pumpio", "host"); + $username = get_pconfig(local_user(), "pumpio", "user"); - /* Add some HTML to the existing form */ + /* Add some HTML to the existing form */ - $s .= ''; - $s .= '

'. t('Pump.io Import/Export/Mirror').'

'; - $s .= '
'; - $s .= ''; $s .= ''; - $s .= ''; - $s .= '
'; + $s .= ''; + $s .= '
'; /* - $s .= ''; - $s .= ''; - $s .= '
'; + $s .= ''; + $s .= ''; + $s .= '
'; */ $s .= '
'; $s .= ''; @@ -439,20 +439,20 @@ function statusnet_action($a, $uid, $pid, $action) { $connection = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret); - logger("statusnet_action '".$action."' ID: ".$pid, LOGGER_DATA); + logger("statusnet_action '".$action."' ID: ".$pid, LOGGER_DATA); - switch ($action) { - case "delete": - $result = $connection->post("statuses/destroy/".$pid); - break; - case "like": - $result = $connection->post("favorites/create/".$pid); - break; - case "unlike": - $result = $connection->post("favorites/destroy/".$pid); - break; - } - logger("statusnet_action '".$action."' send, result: " . print_r($result, true), LOGGER_DEBUG); + switch ($action) { + case "delete": + $result = $connection->post("statuses/destroy/".$pid); + break; + case "like": + $result = $connection->post("favorites/create/".$pid); + break; + case "unlike": + $result = $connection->post("favorites/destroy/".$pid); + break; + } + logger("statusnet_action '".$action."' send, result: " . print_r($result, true), LOGGER_DEBUG); } function statusnet_post_hook(&$a,&$b) { @@ -510,19 +510,19 @@ function statusnet_post_hook(&$a,&$b) { } if (($b['verb'] == ACTIVITY_POST) AND $b['deleted']) - statusnet_action($a, $b["uid"], substr($orig_post["uri"], $hostlength), "delete"); + statusnet_action($a, $b["uid"], substr($orig_post["uri"], $hostlength), "delete"); - if($b['verb'] == ACTIVITY_LIKE) { - logger("statusnet_post_hook: parameter 2 ".substr($b["thr-parent"], $hostlength), LOGGER_DEBUG); - if ($b['deleted']) - statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike"); - else - statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "like"); - return; + if($b['verb'] == ACTIVITY_LIKE) { + logger("statusnet_post_hook: parameter 2 ".substr($b["thr-parent"], $hostlength), LOGGER_DEBUG); + if ($b['deleted']) + statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "unlike"); + else + statusnet_action($a, $b["uid"], substr($b["thr-parent"], $hostlength), "like"); + return; } - if($b['deleted'] || ($b['created'] !== $b['edited'])) - return; + if($b['deleted'] || ($b['created'] !== $b['edited'])) + return; // if posts comes from statusnet don't send it back if($b['app'] == "StatusNet") @@ -700,12 +700,12 @@ function statusnet_cron($a,$b) { } $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); - if(count($r)) { - foreach($r as $rr) { - logger('statusnet: importing timeline from user '.$rr['uid']); - statusnet_fetchhometimeline($a, $rr["uid"]); - } - } + if(count($r)) { + foreach($r as $rr) { + logger('statusnet: importing timeline from user '.$rr['uid']); + statusnet_fetchhometimeline($a, $rr["uid"]); + } + } logger('statusnet: cron_end'); @@ -1429,7 +1429,7 @@ function statusnet_convertmsg($a, $body, $no_tags = false) { $expanded_url = original_url($match[1]); $oembed_data = oembed_fetch_url($expanded_url, true); -print_r($oembed_data); + if ($type == "") $type = $oembed_data->type; if ($oembed_data->type == "video") { diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php old mode 100755 new mode 100644 index 054b53f8..cd9713cf --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -12,19 +12,19 @@ require_once('library/OAuth1.php'); require_once('addon/tumblr/tumblroauth/tumblroauth.php'); function tumblr_install() { - register_hook('post_local', 'addon/tumblr/tumblr.php', 'tumblr_post_local'); - register_hook('notifier_normal', 'addon/tumblr/tumblr.php', 'tumblr_send'); - register_hook('jot_networks', 'addon/tumblr/tumblr.php', 'tumblr_jot_nets'); - register_hook('connector_settings', 'addon/tumblr/tumblr.php', 'tumblr_settings'); - register_hook('connector_settings_post', 'addon/tumblr/tumblr.php', 'tumblr_settings_post'); + register_hook('post_local', 'addon/tumblr/tumblr.php', 'tumblr_post_local'); + register_hook('notifier_normal', 'addon/tumblr/tumblr.php', 'tumblr_send'); + register_hook('jot_networks', 'addon/tumblr/tumblr.php', 'tumblr_jot_nets'); + register_hook('connector_settings', 'addon/tumblr/tumblr.php', 'tumblr_settings'); + register_hook('connector_settings_post', 'addon/tumblr/tumblr.php', 'tumblr_settings_post'); } function tumblr_uninstall() { - unregister_hook('post_local', 'addon/tumblr/tumblr.php', 'tumblr_post_local'); - unregister_hook('notifier_normal', 'addon/tumblr/tumblr.php', 'tumblr_send'); - unregister_hook('jot_networks', 'addon/tumblr/tumblr.php', 'tumblr_jot_nets'); - unregister_hook('connector_settings', 'addon/tumblr/tumblr.php', 'tumblr_settings'); - unregister_hook('connector_settings_post', 'addon/tumblr/tumblr.php', 'tumblr_settings_post'); + unregister_hook('post_local', 'addon/tumblr/tumblr.php', 'tumblr_post_local'); + unregister_hook('notifier_normal', 'addon/tumblr/tumblr.php', 'tumblr_send'); + unregister_hook('jot_networks', 'addon/tumblr/tumblr.php', 'tumblr_jot_nets'); + unregister_hook('connector_settings', 'addon/tumblr/tumblr.php', 'tumblr_settings'); + unregister_hook('connector_settings_post', 'addon/tumblr/tumblr.php', 'tumblr_settings_post'); } function tumblr_module() {} @@ -85,22 +85,22 @@ function tumblr_connect($a) { // Check the HTTP Code. It should be a 200 (OK), if it's anything else then something didn't work. switch ($tum_oauth->http_code) { - case 200: - // Ask Tumblr to give us a special address to their login page - $url = $tum_oauth->getAuthorizeURL($token); + case 200: + // Ask Tumblr to give us a special address to their login page + $url = $tum_oauth->getAuthorizeURL($token); - // Redirect the user to the login URL given to us by Tumblr - header('Location: ' . $url); + // Redirect the user to the login URL given to us by Tumblr + header('Location: ' . $url); - // That's it for our side. The user is sent to a Tumblr Login page and - // asked to authroize our app. After that, Tumblr sends the user back to - // our Callback URL (callback.php) along with some information we need to get - // an access token. + // That's it for our side. The user is sent to a Tumblr Login page and + // asked to authroize our app. After that, Tumblr sends the user back to + // our Callback URL (callback.php) along with some information we need to get + // an access token. - break; - default: - // Give an error message - $o = 'Could not connect to Tumblr. Refresh the page or try again later.'; + break; + default: + // Give an error message + $o = 'Could not connect to Tumblr. Refresh the page or try again later.'; } return($o); } @@ -133,9 +133,9 @@ function tumblr_callback($a) { // Make sure nothing went wrong. if (200 == $tum_oauth->http_code) { - // good to go + // good to go } else { - return('Unable to authenticate'); + return('Unable to authenticate'); } // What's next? Now that we have an Access Token and Secret, we can make an API call. @@ -148,96 +148,96 @@ function tumblr_callback($a) { } function tumblr_jot_nets(&$a,&$b) { - if(! local_user()) - return; + if(! local_user()) + return; - $tmbl_post = get_pconfig(local_user(),'tumblr','post'); - if(intval($tmbl_post) == 1) { - $tmbl_defpost = get_pconfig(local_user(),'tumblr','post_by_default'); - $selected = ((intval($tmbl_defpost) == 1) ? ' checked="checked" ' : ''); - $b .= '
' - . t('Post to Tumblr') . '
'; - } + $tmbl_post = get_pconfig(local_user(),'tumblr','post'); + if(intval($tmbl_post) == 1) { + $tmbl_defpost = get_pconfig(local_user(),'tumblr','post_by_default'); + $selected = ((intval($tmbl_defpost) == 1) ? ' checked="checked" ' : ''); + $b .= '
' + . t('Post to Tumblr') . '
'; + } } function tumblr_settings(&$a,&$s) { - if(! local_user()) - return; + if(! local_user()) + return; - /* Add our stylesheet to the page so we can make our settings look nice */ + /* Add our stylesheet to the page so we can make our settings look nice */ - $a->page['htmlhead'] .= '' . "\r\n"; + $a->page['htmlhead'] .= '' . "\r\n"; - /* Get the current state of our config variables */ + /* Get the current state of our config variables */ - $enabled = get_pconfig(local_user(),'tumblr','post'); - $checked = (($enabled) ? ' checked="checked" ' : ''); - $css = (($enabled) ? '' : '-disabled'); + $enabled = get_pconfig(local_user(),'tumblr','post'); + $checked = (($enabled) ? ' checked="checked" ' : ''); + $css = (($enabled) ? '' : '-disabled'); - $def_enabled = get_pconfig(local_user(),'tumblr','post_by_default'); + $def_enabled = get_pconfig(local_user(),'tumblr','post_by_default'); - $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); + $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); - /* Add some HTML to the existing form */ + /* Add some HTML to the existing form */ - $s .= ''; - $s .= '

'. t('Tumblr Export').'

'; - $s .= '
'; - $s .= ''; } @@ -267,19 +267,19 @@ function tumblr_post_local(&$a,&$b) { if($b['private'] || $b['parent']) return; - $tmbl_post = intval(get_pconfig(local_user(),'tumblr','post')); + $tmbl_post = intval(get_pconfig(local_user(),'tumblr','post')); $tmbl_enable = (($tmbl_post && x($_REQUEST,'tumblr_enable')) ? intval($_REQUEST['tumblr_enable']) : 0); if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'tumblr','post_by_default'))) $tmbl_enable = 1; - if(! $tmbl_enable) - return; + if(! $tmbl_enable) + return; - if(strlen($b['postopts'])) - $b['postopts'] .= ','; - $b['postopts'] .= 'tumblr'; + if(strlen($b['postopts'])) + $b['postopts'] .= ','; + $b['postopts'] .= 'tumblr'; } @@ -287,14 +287,14 @@ function tumblr_post_local(&$a,&$b) { function tumblr_send(&$a,&$b) { - if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) - return; + if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) + return; - if(! strstr($b['postopts'],'tumblr')) - return; + if(! strstr($b['postopts'],'tumblr')) + return; - if($b['parent'] != $b['id']) - return; + if($b['parent'] != $b['id']) + return; $oauth_token = get_pconfig($b['uid'], "tumblr", "oauth_token"); $oauth_token_secret = get_pconfig($b['uid'], "tumblr", "oauth_token_secret"); diff --git a/twitter/twitter.php b/twitter/twitter.php old mode 100755 new mode 100644 index 16debcb7..7c167459 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -161,10 +161,10 @@ function twitter_settings_post ($a,$post) { */ del_pconfig(local_user(), 'twitter', 'consumerkey'); del_pconfig(local_user(), 'twitter', 'consumersecret'); - del_pconfig(local_user(), 'twitter', 'oauthtoken'); - del_pconfig(local_user(), 'twitter', 'oauthsecret'); - del_pconfig(local_user(), 'twitter', 'post'); - del_pconfig(local_user(), 'twitter', 'post_by_default'); + del_pconfig(local_user(), 'twitter', 'oauthtoken'); + del_pconfig(local_user(), 'twitter', 'oauthsecret'); + del_pconfig(local_user(), 'twitter', 'post'); + del_pconfig(local_user(), 'twitter', 'post_by_default'); del_pconfig(local_user(), 'twitter', 'lastid'); del_pconfig(local_user(), 'twitter', 'mirror_posts'); del_pconfig(local_user(), 'twitter', 'import'); @@ -183,30 +183,30 @@ function twitter_settings_post ($a,$post) { $connection = new TwitterOAuth($ckey, $csecret, $_POST['twitter-token'], $_POST['twitter-token2']); $token = $connection->getAccessToken( $_POST['twitter-pin'] ); // ok, now that we have the Access Token, save them in the user config - set_pconfig(local_user(),'twitter', 'oauthtoken', $token['oauth_token']); + set_pconfig(local_user(),'twitter', 'oauthtoken', $token['oauth_token']); set_pconfig(local_user(),'twitter', 'oauthsecret', $token['oauth_token_secret']); - set_pconfig(local_user(),'twitter', 'post', 1); - // reload the Addon Settings page, if we don't do it see Bug #42 - goaway($a->get_baseurl().'/settings/connectors'); + set_pconfig(local_user(),'twitter', 'post', 1); + // reload the Addon Settings page, if we don't do it see Bug #42 + goaway($a->get_baseurl().'/settings/connectors'); } else { // if no PIN is supplied in the POST variables, the user has changed the setting // to post a tweet for every new __public__ posting to the wall set_pconfig(local_user(),'twitter','post',intval($_POST['twitter-enable'])); - set_pconfig(local_user(),'twitter','post_by_default',intval($_POST['twitter-default'])); + set_pconfig(local_user(),'twitter','post_by_default',intval($_POST['twitter-default'])); set_pconfig(local_user(), 'twitter', 'mirror_posts', intval($_POST['twitter-mirror'])); set_pconfig(local_user(), 'twitter', 'import', intval($_POST['twitter-import'])); set_pconfig(local_user(), 'twitter', 'create_user', intval($_POST['twitter-create_user'])); - if (!intval($_POST['twitter-mirror'])) - del_pconfig(local_user(),'twitter','lastid'); + if (!intval($_POST['twitter-mirror'])) + del_pconfig(local_user(),'twitter','lastid'); - info(t('Twitter settings updated.') . EOL); + info(t('Twitter settings updated.') . EOL); }} } function twitter_settings(&$a,&$s) { - if(! local_user()) - return; - $a->page['htmlhead'] .= '' . "\r\n"; + if(! local_user()) + return; + $a->page['htmlhead'] .= '' . "\r\n"; /*** * 1) Check that we have global consumer key & secret * 2) If no OAuthtoken & stuff is present, generate button to get some @@ -216,16 +216,16 @@ function twitter_settings(&$a,&$s) { $csecret = get_config('twitter', 'consumersecret' ); $otoken = get_pconfig(local_user(), 'twitter', 'oauthtoken' ); $osecret = get_pconfig(local_user(), 'twitter', 'oauthsecret' ); - $enabled = get_pconfig(local_user(), 'twitter', 'post'); + $enabled = get_pconfig(local_user(), 'twitter', 'post'); $checked = (($enabled) ? ' checked="checked" ' : ''); - $defenabled = get_pconfig(local_user(),'twitter','post_by_default'); + $defenabled = get_pconfig(local_user(),'twitter','post_by_default'); $defchecked = (($defenabled) ? ' checked="checked" ' : ''); - $mirrorenabled = get_pconfig(local_user(),'twitter','mirror_posts'); - $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : ''); - $importenabled = get_pconfig(local_user(),'twitter','import'); - $importchecked = (($importenabled) ? ' checked="checked" ' : ''); - $create_userenabled = get_pconfig(local_user(),'twitter','create_user'); - $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : ''); + $mirrorenabled = get_pconfig(local_user(),'twitter','mirror_posts'); + $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : ''); + $importenabled = get_pconfig(local_user(),'twitter','import'); + $importchecked = (($importenabled) ? ' checked="checked" ' : ''); + $create_userenabled = get_pconfig(local_user(),'twitter','create_user'); + $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : ''); $css = (($enabled) ? '' : '-disabled'); @@ -254,7 +254,7 @@ function twitter_settings(&$a,&$s) { * which the user can request a PIN to connect the account to a * account at Twitter. */ - require_once('library/twitteroauth.php'); + require_once('library/twitteroauth.php'); $connection = new TwitterOAuth($ckey, $csecret); $request_token = $connection->getRequestToken(); $token = $request_token['oauth_token']; @@ -268,50 +268,50 @@ function twitter_settings(&$a,&$s) { $s .= ''; $s .= ''; $s .= ''; - $s .= '
'; - $s .= '
'; + $s .= '
'; + $s .= '
'; } else { /*** * we have an OAuth key / secret pair for the user * so let's give a chance to disable the postings to Twitter */ - require_once('library/twitteroauth.php'); + require_once('library/twitteroauth.php'); $connection = new TwitterOAuth($ckey,$csecret,$otoken,$osecret); $details = $connection->get('account/verify_credentials'); $s .= '

'. t('Currently connected to: ') .''.$details->screen_name.'
'.$details->description.'

'; $s .= '

'. t('If enabled all your public postings can be posted to the associated Twitter account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.') .'

'; - if ($a->user['hidewall']) { - $s .= '

'. t('Note: Due your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to Twitter will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') .'

'; - } + if ($a->user['hidewall']) { + $s .= '

'. t('Note: Due your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to Twitter will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') .'

'; + } $s .= '
'; $s .= ''; $s .= ''; - $s .= '
'; - $s .= ''; - $s .= ''; + $s .= '
'; + $s .= ''; + $s .= ''; $s .= '
'; - $s .= ''; - $s .= ''; + $s .= ''; + $s .= ''; $s .= '
'; $s .= '
'; - $s .= ''; - $s .= ''; + $s .= ''; + $s .= ''; $s .= '
'; - $s .= ''; - $s .= ''; + $s .= ''; + $s .= ''; $s .= '
'; $s .= '
'; - $s .= ''; - $s .= ''; + $s .= ''; + $s .= ''; $s .= '
'; $s .= '
'; } } - $s .= '
'; + $s .= '
'; } @@ -329,12 +329,12 @@ function twitter_post_local(&$a,&$b) { if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'twitter','post_by_default'))) $twitter_enable = 1; - if(! $twitter_enable) - return; + if(! $twitter_enable) + return; - if(strlen($b['postopts'])) - $b['postopts'] .= ','; - $b['postopts'] .= 'twitter'; + if(strlen($b['postopts'])) + $b['postopts'] .= ','; + $b['postopts'] .= 'twitter'; } } @@ -385,29 +385,31 @@ function twitter_post_hook(&$a,&$b) { if($b['parent'] != $b['id']) { logger("twitter_post_hook: parameter ".print_r($b, true), LOGGER_DATA); - // Looking if its a reply to a twitter post + // Looking if its a reply to a twitter post if ((substr($b["parent-uri"], 0, 9) != "twitter::") AND (substr($b["extid"], 0, 9) != "twitter::") AND (substr($b["thr-parent"], 0, 9) != "twitter::")) { - logger("twitter_post_hook: no twitter post ".$b["parent"]); - return; + logger("twitter_post_hook: no twitter post ".$b["parent"]); + return; } - $r = q("SELECT * FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1", - dbesc($b["thr-parent"]), - intval($b["uid"])); + $r = q("SELECT * FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1", + dbesc($b["thr-parent"]), + intval($b["uid"])); - if(!count($r)) { - logger("twitter_post_hook: no parent found ".$b["thr-parent"]); - return; - } else { - $iscomment = true; - $orig_post = $r[0]; - } + if(!count($r)) { + logger("twitter_post_hook: no parent found ".$b["thr-parent"]); + return; + } else { + $iscomment = true; + $orig_post = $r[0]; + } - $nickname = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]); - $nickname = "@[url=".$orig_post["author-link"]."]".$nickname."[/url]"; - logger("twitter_post_hook: comparing ".$nickname." with ".$b["body"], LOGGER_DEBUG); - if (strpos($b["body"], $nickname) === false) + $nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]); + $nickname = "@[url=".$orig_post["author-link"]."]".$nicknameplain."[/url]"; + $nicknameplain = "@".$nicknameplain; + + logger("twitter_post_hook: comparing ".$nickname." and ".$nicknameplain." with ".$b["body"], LOGGER_DEBUG); + if ((strpos($b["body"], $nickname) === false) AND (strpos($b["body"], $nicknameplain) === false)) $b["body"] = $nickname." ".$b["body"]; logger("twitter_post_hook: parent found ".print_r($orig_post, true), LOGGER_DATA); @@ -428,10 +430,10 @@ function twitter_post_hook(&$a,&$b) { else twitter_action($a, $b["uid"], substr($b["thr-parent"], 9), "like"); return; - } + } if($b['deleted'] || ($b['created'] !== $b['edited'])) - return; + return; // if post comes from twitter don't send it back if($b['app'] == "Twitter") @@ -484,7 +486,7 @@ function twitter_post_hook(&$a,&$b) { // so we are using a new library for twitter // To-Do: // Switching completely to this library with all functions - require_once("addon/twitter/codebird.php"); + require_once("addon/twitter/codebird.php"); $cb = \Codebird\Codebird::getInstance(); $cb->setConsumerKey($ckey, $csecret); @@ -554,7 +556,7 @@ function twitter_post_hook(&$a,&$b) { function twitter_plugin_admin_post(&$a){ $consumerkey = ((x($_POST,'consumerkey')) ? notags(trim($_POST['consumerkey'])) : ''); $consumersecret = ((x($_POST,'consumersecret')) ? notags(trim($_POST['consumersecret'])): ''); - $applicationname = ((x($_POST, 'applicationname')) ? notags(trim($_POST['applicationname'])):''); + $applicationname = ((x($_POST, 'applicationname')) ? notags(trim($_POST['applicationname'])):''); set_config('twitter','consumerkey',$consumerkey); set_config('twitter','consumersecret',$consumersecret); set_config('twitter','application_name',$applicationname); @@ -567,8 +569,8 @@ function twitter_plugin_admin(&$a, &$o){ '$submit' => t('Save Settings'), // name, label, value, help, [extra values] '$consumerkey' => array('consumerkey', t('Consumer key'), get_config('twitter', 'consumerkey' ), ''), - '$consumersecret' => array('consumersecret', t('Consumer secret'), get_config('twitter', 'consumersecret' ), ''), - '$applicationname' => array('applicationname', t('Name of the Twitter Application'), get_config('twitter','application_name'),t('set this to avoid mirroring postings from ~friendica back to ~friendica')) + '$consumersecret' => array('consumersecret', t('Consumer secret'), get_config('twitter', 'consumersecret' ), ''), + '$applicationname' => array('applicationname', t('Name of the Twitter Application'), get_config('twitter','application_name'),t('set this to avoid mirroring postings from ~friendica back to ~friendica')) )); } @@ -605,21 +607,21 @@ function twitter_cron($a,$b) { /* // To-Do - // check for new contacts once a day - $last_contact_check = get_pconfig($rr['uid'],'pumpio','contact_check'); - if($last_contact_check) - $next_contact_check = $last_contact_check + 86400; - else - $next_contact_check = 0; + // check for new contacts once a day + $last_contact_check = get_pconfig($rr['uid'],'pumpio','contact_check'); + if($last_contact_check) + $next_contact_check = $last_contact_check + 86400; + else + $next_contact_check = 0; - if($next_contact_check <= time()) { - pumpio_getallusers($a, $rr["uid"]); - set_pconfig($rr['uid'],'pumpio','contact_check',time()); - } + if($next_contact_check <= time()) { + pumpio_getallusers($a, $rr["uid"]); + set_pconfig($rr['uid'],'pumpio','contact_check',time()); + } */ - } - } + } + } logger('twitter: cron_end'); @@ -628,26 +630,26 @@ function twitter_cron($a,$b) { function twitter_expire($a,$b) { - $days = get_config('twitter', 'expire'); + $days = get_config('twitter', 'expire'); - if ($days == 0) - return; + if ($days == 0) + return; $r = q("DELETE FROM `item` WHERE `deleted` AND `network` = '%s'", dbesc(NETWORK_TWITTER)); - require_once("include/items.php"); + require_once("include/items.php"); - logger('twitter_expire: expire_start'); + logger('twitter_expire: expire_start'); - $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); - if(count($r)) { - foreach($r as $rr) { - logger('twitter_expire: user '.$rr['uid']); - item_expire($rr['uid'], $days, NETWORK_TWITTER, true); - } - } + $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); + if(count($r)) { + foreach($r as $rr) { + logger('twitter_expire: user '.$rr['uid']); + item_expire($rr['uid'], $days, NETWORK_TWITTER, true); + } + } - logger('twitter_expire: expire_end'); + logger('twitter_expire: expire_end'); } function twitter_fetchtimeline($a, $uid) { @@ -684,7 +686,7 @@ function twitter_fetchtimeline($a, $uid) { $posts = array_reverse($items); - if (count($posts)) { + if (count($posts)) { foreach ($posts as $post) { if ($post->id_str > $lastid) $lastid = $post->id_str; @@ -767,8 +769,8 @@ function twitter_fetchtimeline($a, $uid) { // require_once('mod/item.php'); item_post($a); - } - } + } + } } set_pconfig($uid, 'twitter', 'lastid', $lastid); } @@ -842,7 +844,7 @@ function twitter_fetch_contact($uid, $contact, $create_user) { // Check if the unique contact is existing // To-Do: only update once a while - $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", + $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link("https://twitter.com/".$contact->screen_name))); if (count($r) == 0) @@ -1114,16 +1116,16 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud } // it seems as if the entities aren't always covering all mentions. So the rest will be checked here - $tags = get_tags($body); + $tags = get_tags($body); - if(count($tags)) { + if(count($tags)) { foreach($tags as $tag) { if (strstr(trim($tag), " ")) continue; - if(strpos($tag,'#') === 0) { - if(strpos($tag,'[url=')) - continue; + if(strpos($tag,'#') === 0) { + if(strpos($tag,'[url=')) + continue; // don't link tags that are already embedded in links @@ -1138,8 +1140,8 @@ function twitter_expand_entities($a, $body, $item, $no_tags = false, $dontinclud $tags_arr["#".$basetag] = $url; continue; } elseif(strpos($tag,'@') === 0) { - if(strpos($tag,'[url=')) - continue; + if(strpos($tag,'[url=')) + continue; $basetag = substr($tag,1); $url = '@[url=https://twitter.com/'.rawurlencode($basetag).']'.$basetag.'[/url]'; @@ -1458,7 +1460,7 @@ function twitter_fetchhometimeline($a, $uid) { return; } - $posts = array_reverse($items); + $posts = array_reverse($items); logger("twitter_fetchhometimeline: Fetching timeline for user ".$uid." ".sizeof($posts)." items", LOGGER_DEBUG); @@ -1501,7 +1503,7 @@ function twitter_fetchhometimeline($a, $uid) { return; } - $posts = array_reverse($items); + $posts = array_reverse($items); logger("twitter_fetchhometimeline: Fetching mentions for user ".$uid." ".sizeof($posts)." items", LOGGER_DEBUG); @@ -1535,19 +1537,19 @@ function twitter_fetchhometimeline($a, $uid) { require_once('include/enotify.php'); notification(array( 'type' => NOTIFY_TAGSELF, - 'notify_flags' => $u[0]['notify-flags'], - 'language' => $u[0]['language'], - 'to_name' => $u[0]['username'], - 'to_email' => $u[0]['email'], - 'uid' => $u[0]['uid'], - 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item, - 'source_name' => $postarray['author-name'], - 'source_link' => $postarray['author-link'], + 'notify_flags' => $u[0]['notify-flags'], + 'language' => $u[0]['language'], + 'to_name' => $u[0]['username'], + 'to_email' => $u[0]['email'], + 'uid' => $u[0]['uid'], + 'item' => $postarray, + 'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item, + 'source_name' => $postarray['author-name'], + 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], - 'verb' => ACTIVITY_TAG, - 'otype' => 'item' - )); + 'verb' => ACTIVITY_TAG, + 'otype' => 'item' + )); } } } @@ -1578,8 +1580,8 @@ function twitter_fetch_own_contact($a, $uid) { $contact_id = twitter_fetch_contact($uid, $user, true); } else { - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", - intval($uid), dbesc("twitter::".$own_id)); + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", + intval($uid), dbesc("twitter::".$own_id)); if(count($r)) $contact_id = $r[0]["id"]; else @@ -1636,5 +1638,4 @@ function twitter_is_retweet($a, $uid, $body) { return(!isset($result->errors)); } - ?>