diff options
Diffstat (limited to 'addon')
-rw-r--r-- | addon/facebook/facebook.php | 34 | ||||
-rw-r--r-- | addon/js_upload/js_upload.php | 6 | ||||
-rw-r--r-- | addon/statusnet/statusnet.php | 66 | ||||
-rw-r--r-- | addon/twitter/twitter.php | 24 |
4 files changed, 107 insertions, 23 deletions
diff --git a/addon/facebook/facebook.php b/addon/facebook/facebook.php index 73518afb2..47e7691e4 100644 --- a/addon/facebook/facebook.php +++ b/addon/facebook/facebook.php @@ -111,13 +111,13 @@ function facebook_init(&$a) { $token = substr($token,0,strpos($token,'&')); set_pconfig($uid,'facebook','access_token',$token); set_pconfig($uid,'facebook','post','1'); + set_pconfig($uid,'facebook','no_linking',1); fb_get_self($uid); fb_get_friends($uid); fb_consume_all($uid); } - // todo: is this a browser session or a server session? where do we go? } } @@ -214,7 +214,7 @@ function fb_get_friends($uid) { dbesc(($jp->nickname) ? $jp->nickname : strtolower($jp->first_name)), dbesc('https://graph.facebook.com/' . $jp->id . '/picture'), dbesc(NETWORK_FACEBOOK), - intval(REL_BUD), + intval(CONTACT_IS_FRIEND), intval(1), intval(1) ); @@ -258,6 +258,8 @@ function fb_get_friends($uid) { } } +// This is the POST method to the facebook settings page +// Content is posted to Facebook in the function facebook_post_hook() function facebook_post(&$a) { @@ -298,6 +300,8 @@ function facebook_post(&$a) { return; } +// Facebook settings form + function facebook_content(&$a) { if(! local_user()) { @@ -347,14 +351,18 @@ function facebook_content(&$a) { $o .= '<form action="facebook" method="post" >'; $post_by_default = get_pconfig(local_user(),'facebook','post_by_default'); $checked = (($post_by_default) ? ' checked="checked" ' : ''); - $o .= '<input type="checkbox" name="post_by_default" value="1"' . $checked . '/>' . ' ' . t('Post to Facebook by default') . '<br />'; + $o .= '<input type="checkbox" name="post_by_default" value="1"' . $checked . '/>' . ' ' . t('Post to Facebook by default') . EOL; $no_linking = get_pconfig(local_user(),'facebook','no_linking'); $checked = (($no_linking) ? '' : ' checked="checked" '); - $o .= '<input type="checkbox" name="facebook_linking" value="1"' . $checked . '/>' . ' ' . t('Link all your Facebook friends and conversations') . '<br />'; - - + $o .= '<input type="checkbox" name="facebook_linking" value="1"' . $checked . '/>' . ' ' . t('Link all your Facebook friends and conversations') . EOL ; + $hidden = (($a->user['hidewall'] || get_config('system','block_public')) ? true : false); + if(! $hidden) { + $o .= EOL; + $o .= t('Warning: Your Facebook privacy settings can not be imported.') . EOL; + $o .= t('Linked Facebook items <strong>may</strong> be publicly visible, depending on your privacy settings for this website/account.') . EOL; + } $o .= '<input type="submit" name="submit" value="' . t('Submit') . '" /></form></div>'; } @@ -522,6 +530,13 @@ function facebook_post_hook(&$a,&$b) { $fb_enable = (($fb_post && x($_POST,'facebook_enable')) ? intval($_POST['facebook_enable']) : 0); $fb_token = get_pconfig(local_user(),'facebook','access_token'); + // if API is used, default to the chosen settings + if($_POST['api_source'] && intval(get_pconfig(local_user(),'facebook','post_by_default'))) + $fb_enable = 1; + + + + logger('facebook: $fb_post: ' . $fb_post . ' $fb_enable: ' . $fb_enable . ' $fb_token: ' . $fb_token,LOGGER_DEBUG); // post to facebook if it's a public post and we've ticked the 'post to Facebook' box, @@ -564,7 +579,7 @@ function facebook_post_hook(&$a,&$b) { $msg = preg_replace("/\[img\](.*?)\[\/img\]/is", t('Image: ') . '$1', $msg); - if((strpos($link,$a->get_baseurl()) !== false) && (! $image)) + if((strpos($link,z_root()) !== false) && (! $image)) $image = $a->get_baseurl() . '/images/friendika-64.jpg'; $msg = trim(strip_tags(bbcode($msg))); @@ -746,6 +761,8 @@ function fb_consume_all($uid) { $access_token = get_pconfig($uid,'facebook','access_token'); if(! $access_token) return; + + $s = fetch_url('https://graph.facebook.com/me/feed?access_token=' . $access_token); if($s) { $j = json_decode($s); @@ -772,13 +789,12 @@ function fb_consume_stream($uid,$j,$wall = false) { intval($uid) ); - $user = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1", + $user = q("SELECT `nickname`, `blockwall` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid) ); if(count($user)) $my_local_url = $a->get_baseurl() . '/profile/' . $user[0]['nickname']; - $self_id = get_pconfig($uid,'facebook','self_id'); if(! count($j->data) || (! strlen($self_id))) return; diff --git a/addon/js_upload/js_upload.php b/addon/js_upload/js_upload.php index 331548f88..1996b8504 100644 --- a/addon/js_upload/js_upload.php +++ b/addon/js_upload/js_upload.php @@ -298,10 +298,10 @@ class qqFileUploader { return array('error' => t('Uploaded file is empty')); } - if ($size > $this->sizeLimit) { +// if ($size > $this->sizeLimit) { - return array('error' => t('Uploaded file is too large')); - } +// return array('error' => t('Uploaded file is too large')); +// } $maximagesize = get_config('system','maximagesize'); diff --git a/addon/statusnet/statusnet.php b/addon/statusnet/statusnet.php index 062884b96..2f02ded54 100644 --- a/addon/statusnet/statusnet.php +++ b/addon/statusnet/statusnet.php @@ -1,7 +1,7 @@ <?php /** * Name: StatusNet Connector - * Version: 1.0 + * Version: 1.0.2 * Author: Tobias Diekershoff <https://diekershoff.homeunix.net/friendika/profile/tobias> */ @@ -51,6 +51,57 @@ class StatusNetOAuth extends TwitterOAuth { parent::__construct($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret); $this->host = $apipath; } + /** + * Make an HTTP request + * + * @return API results + * + * Copied here from the twitteroauth library and complemented by applying the proxy settings of friendika + */ + function http($url, $method, $postfields = NULL) { + $this->http_info = array(); + $ci = curl_init(); + /* Curl settings */ + $prx = get_config('system','proxy'); + logger('Proxy SN: '.$prx); + if(strlen($prx)) { + curl_setopt($ci, CURLOPT_HTTPPROXYTUNNEL, 1); + curl_setopt($ci, CURLOPT_PROXY, $prx); + $prxusr = get_config('system','proxyuser'); + if(strlen($prxusr)) + curl_setopt($ci, CURLOPT_PROXYUSERPWD, $prxusr); + } + curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent); + curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout); + curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout); + curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:')); + curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer); + curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader')); + curl_setopt($ci, CURLOPT_HEADER, FALSE); + + switch ($method) { + case 'POST': + curl_setopt($ci, CURLOPT_POST, TRUE); + if (!empty($postfields)) { + curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields); + } + break; + case 'DELETE': + curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE'); + if (!empty($postfields)) { + $url = "{$url}?{$postfields}"; + } + } + + curl_setopt($ci, CURLOPT_URL, $url); + $response = curl_exec($ci); + $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); + $this->http_info = array_merge($this->http_info, curl_getinfo($ci)); + $this->url = $url; + curl_close ($ci); + return $response; + } } function statusnet_install() { @@ -276,7 +327,7 @@ function statusnet_settings(&$a,&$s) { $connection = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret); $details = $connection->get('account/verify_credentials'); $s .= '<div id="statusnet-info" ><img id="statusnet-avatar" src="'.$details->profile_image_url.'" /><p id="statusnet-info-block">'. t('Currently connected to: ') .'<a href="'.$details->statusnet_profile_url.'" target="_statusnet">'.$details->screen_name.'</a><br /><em>'.$details->description.'</em></p></div>'; - $s .= '<p>'. t('If enabled all your <strong>public</strong> postings will be posted to the associated StatusNet account.') .'</p>'; + $s .= '<p>'. t('If enabled all your <strong>public</strong> postings can be posted to the associated StatusNet account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.') .'</p>'; $s .= '<div id="statusnet-enable-wrapper">'; $s .= '<label id="statusnet-enable-label" for="statusnet-checkbox">'. t('Allow posting to StatusNet') .'</label>'; $s .= '<input id="statusnet-checkbox" type="checkbox" name="statusnet-enable" value="1" ' . $checked . '/>'; @@ -322,6 +373,9 @@ function statusnet_post_hook(&$a,&$b) { $statusnet_post = get_pconfig(local_user(),'statusnet','post'); $statusnet_enable = (($statusnet_post && x($_POST,'statusnet_enable')) ? intval($_POST['statusnet_enable']) : 0); + // if API is used, default to the chosen settings + if($_POST['api_source'] && intval(get_pconfig(local_user(),'statusnet','post_by_default'))) + $statusnet_enable = 1; if($statusnet_enable && $statusnet_post) { require_once('include/bbcode.php'); @@ -402,10 +456,10 @@ function statusnet_plugin_admin(&$a, &$o){ /* empty form to add new site */ $id++; $sitesform[] = Array( - 'sitename' => Array("sitename[$id]", "Site name", "", ""), - 'apiurl' => Array("apiurl[$id]", "Api url", "", ""), - 'secret' => Array("secret[$id]", "Secret", "", ""), - 'key' => Array("key[$id]", "Key", "", ""), + 'sitename' => Array("sitename[$id]", t("Site name"), "", ""), + 'apiurl' => Array("apiurl[$id]", t("API URL"), "", ""), + 'secret' => Array("secret[$id]", t("Consumer Secret"), "", ""), + 'key' => Array("key[$id]", t("Consumer Key"), "", ""), ); diff --git a/addon/twitter/twitter.php b/addon/twitter/twitter.php index 26b324aca..b1c8a0a89 100644 --- a/addon/twitter/twitter.php +++ b/addon/twitter/twitter.php @@ -1,7 +1,7 @@ <?php /** * Name: Twitter Connector - * Version: 1.0 + * Version: 1.0.1 * Author: Tobias Diekershoff <https://diekershoff.homeunix.net/friendika/profile/tobias> */ @@ -87,7 +87,8 @@ function twitter_settings_post ($a,$post) { */ del_pconfig( local_user(), 'twitter', 'consumerkey' ); del_pconfig( local_user(), 'twitter', 'consumersecret' ); - del_pconfig( local_user(), 'twitter', 'post' ); + del_pconfig( local_user(), 'twitter', 'post' ); + del_pconfig( local_user(), 'twitter', 'post_by_default' ); } else { if (isset($_POST['twitter-pin'])) { // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen @@ -105,11 +106,13 @@ function twitter_settings_post ($a,$post) { 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 - header('Location: '.$a->get_baseurl().'/settings/addon'); + goaway($a->get_baseurl().'/settings/addon'); } 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'])); + info( t('Twitter settings updated.') . EOL); }} } function twitter_settings(&$a,&$s) { @@ -127,6 +130,9 @@ function twitter_settings(&$a,&$s) { $osecret = get_pconfig(local_user(), 'twitter', 'oauthsecret' ); $enabled = get_pconfig(local_user(), 'twitter', 'post'); $checked = (($enabled) ? ' checked="checked" ' : ''); + $defenabled = get_pconfig(local_user(),'twitter','post_by_default'); + $defchecked = (($defenabled) ? ' checked="checked" ' : ''); + $s .= '<div class="settings-block">'; $s .= '<h3>'. t('Twitter Posting Settings') .'</h3>'; @@ -172,11 +178,15 @@ function twitter_settings(&$a,&$s) { $connection = new TwitterOAuth($ckey,$csecret,$otoken,$osecret); $details = $connection->get('account/verify_credentials'); $s .= '<div id="twitter-info" ><img id="twitter-avatar" src="'.$details->profile_image_url.'" /><p id="twitter-info-block">'. t('Currently connected to: ') .'<a href="https://twitter.com/'.$details->screen_name.'" target="_twitter">'.$details->screen_name.'</a><br /><em>'.$details->description.'</em></p></div>'; - $s .= '<p>'. t('If enabled all your <strong>public</strong> postings will be posted to the associated Twitter account as well.') .'</p>'; + $s .= '<p>'. t('If enabled all your <strong>public</strong> 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.') .'</p>'; $s .= '<div id="twitter-enable-wrapper">'; - $s .= '<label id="twitter-enable-label" for="twitter-checkbox">'. t('Send public postings to Twitter'). '</label>'; + $s .= '<label id="twitter-enable-label" for="twitter-checkbox">'. t('Allow posting to Twitter'). '</label>'; $s .= '<input id="twitter-checkbox" type="checkbox" name="twitter-enable" value="1" ' . $checked . '/>'; + $s .= '<div class="clear"></div>'; + $s .= '<label id="twitter-default-label" for="twitter-default">'. t('Send public postings to Twitter by default') .'</label>'; + $s .= '<input id="twitter-default" type="checkbox" name="twitter-default" value="1" ' . $defchecked . '/>'; $s .= '</div><div class="clear"></div>'; + $s .= '<div id="twitter-disconnect-wrapper">'; $s .= '<label id="twitter-disconnect-label" for="twitter-disconnect">'. t('Clear OAuth configuration') .'</label>'; $s .= '<input id="twitter-disconnect" type="checkbox" name="twitter-disconnect" value="1" />'; @@ -215,6 +225,10 @@ function twitter_post_hook(&$a,&$b) { $twitter_post = intval(get_pconfig(local_user(),'twitter','post')); $twitter_enable = (($twitter_post && x($_POST,'twitter_enable')) ? intval($_POST['twitter_enable']) : 0); + // if API is used, default to the chosen settings + if($_POST['api_source'] && intval(get_pconfig(local_user(),'twitter','post_by_default'))) + $twitter_enable = 1; + if($twitter_post && $twitter_enable) { logger('Posting to Twitter', LOGGER_DEBUG); require_once('library/twitteroauth.php'); |