Your ur1 is: /', $result, $matches ) )
+ return $matches[1];
+ else
+ return $url;
+ }
+}
+
+// PtitURL.com
+class Slinky_PtitURL extends Slinky_Service {
+ function url_is_short( $url ) {
+ return stristr( $url, 'ptiturl.com/' );
+ }
+
+ function url_is_long( $url ) {
+ return !stristr( $url, 'ptiturl.com/' );
+ }
+
+ function make_short( $url ) {
+ $result = $this->url_get( 'http://ptiturl.com/index.php?creer=oui&url=' . urlencode( $url ) );
+ if ( preg_match( '/ '. t('No consumer key pair for StatusNet found. Register your Friendika Account as an desktop client on your StatusNet account, copy the consumer key pair here and enter the API base root. '. t('To connect to your StatusNet account click the button below to get a security code from StatusNet which you have to copy into the input box below and submit the form. Only your public posts will be posted to StatusNet.') .' '. t('Currently connected to: ') .''.$details->screen_name.' '. t('If enabled all your public postings will be posted to the associated StatusNet account as well.') .' Your ur1 is: /', $result, $matches ) )
+ return $matches[1];
+ else
+ return $url;
+ }
+}
+
+// PtitURL.com
+class Slinky_PtitURL extends Slinky_Service {
+ function url_is_short( $url ) {
+ return stristr( $url, 'ptiturl.com/' );
+ }
+
+ function url_is_long( $url ) {
+ return !stristr( $url, 'ptiturl.com/' );
+ }
+
+ function make_short( $url ) {
+ $result = $this->url_get( 'http://ptiturl.com/index.php?creer=oui&url=' . urlencode( $url ) );
+ if ( preg_match( '/ '. t('No consumer key pair for Twitter found. Please contact your site administrator.') .' '. t('At this Friendika instance the Twitter plugin was enabled but you have not yet connected your account to your Twitter account. To do so click the button below to get a PIN from Twitter which you have to copy into the input box below and submit the form. Only your public posts will be posted to Twitter.') .' '. t('Currently connected to: ') .''.$details->screen_name.' '. t('If enabled all your public postings will be posted to the associated Twitter account as well.') .' /is',
'/\<\/p\>/is',
@@ -26,6 +31,7 @@ function html2bbcode($s) {
'/\(.*?)\<\/a\>/is',
'/\]+)\'?>/', $result, $matches ) )
+ return $matches[1];
+ else
+ return $url;
+ }
+}
+
+// Tighturl.com
+class Slinky_TightURL extends Slinky_Service {
+ function url_is_short( $url ) {
+ return stristr( $url, 'tighturl.com/' )
+ || stristr( $url, '2tu.us/' );
+ }
+
+ function url_is_long( $url ) {
+ return !stristr( $url, 'tighturl.com/' )
+ && !stristr( $url, '2tu.us/' );
+ }
+
+ function make_short( $url ) {
+ $response = $this->url_get( 'http://tighturl.com/?save=y&url=' . urlencode( $url ) );
+ if ( preg_match( '/Your tight URL is:
/', $response, $matches ) ) {
+ return $matches[1];
+ } else {
+ return $url;
+ }
+ }
+}
+
+// Snipr for Slinky
+/*
+To use Snipr, you MUST set your user_id and API (key) for the service first, e.g.
+
+$snipr = new Slinky_Snipr();
+$snipr->set( 'user_id', 'Snipr User ID' );
+$snipr->set( 'API', 'Snipr API Key' );
+
+$slinky = new Slinky( $url, $snipr );
+echo $slinky->short();
+
+NOTE: Snipr requires the SimpleXML extension to be installed for lengthening URLs
+*/
+class Slinky_Snipr extends Slinky_Service {
+ // Snipurl, Snurl, Snipr, Sn.im
+ function url_is_short( $url ) {
+ return stristr( $url, 'snipr.com/' ) || stristr( $url, 'snipurl.com/' ) || stristr( $url, 'snurl.com/' ) || stristr( $url, 'sn.im/' );
+ }
+
+ function url_is_long( $url ) {
+ return !stristr( $url, 'snipr.com/' ) || !stristr( $url, 'snipurl.com/' ) || !stristr( $url, 'snurl.com/' ) || !stristr( $url, 'sn.im/' );
+ }
+
+ function make_short( $url ) {
+ if ( !$this->get( 'user_id' ) || !$this->get( 'API' ) )
+ return $url;
+
+ $response = $this->url_post( 'http://snipr.com/site/getsnip', array( 'sniplink' => urlencode( $url ), 'snipuser' => $this->get( 'user_id'), 'snipapi' => $this->get( 'API' ), 'snipformat' => 'simple' ) );
+ if ( 'ERROR' != substr( $response, 0, 5 ) )
+ return $response;
+ else
+ return $url;
+ }
+}
+
+// If you're testing things out, http://dentedreality.com.au/ should convert to:
+// - http://tinyurl.com/jw5sh
+// - http://bit.ly/hEkAD
+// - http://tr.im/sk1H
+// - http://is.gd/1yJ81
+// - http://fon.gs/tc1p8c
+// - http://micurl.com/qen3uub
+// - http://ur1.ca/7dcd
+// - http://ptiturl.com/?id=bac8fb
+// - http://tighturl.com/kgd
+// - http://snipr.com/nbbw3
+//
+// $slinky = new Slinky( 'http://dentedreality.com.au/' );
+// echo $slinky->short();
diff --git a/addon/statusnet/statusnet.css b/addon/statusnet/statusnet.css
new file mode 100644
index 000000000..4e27b0938
--- /dev/null
+++ b/addon/statusnet/statusnet.css
@@ -0,0 +1,67 @@
+
+
+#statusnet-avatar {
+ float: left;
+ width: 48px;
+ height: 48px;
+ padding: 2px;
+}
+#statusnet-info-block {
+ height: 52px;
+ vertical-align: middle;
+}
+#statusnet-disconnect-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 25px;
+}
+
+#statusnet-disconnect {
+ float: left;
+}
+#statusnet-enable-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 5px;
+}
+
+#statusnet-checkbox {
+ float: left;
+}
+#statusnet-pin-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 25px;
+}
+#statusnet-pin {
+ float: left;
+}
+
+
+#statusnet-consumerkey-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 8px;
+}
+#statusnet-consumerkey {
+ float: left;
+ margin-bottom: 8px;
+}
+#statusnet-consumersecret-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 8px;
+}
+#statusnet-consumersecret {
+ float: left;
+ margin-bottom: 8px;
+}
+#statusnet-baseapi-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 25px;
+}
+#statusnet-baseapi {
+ float: left;
+ margin-bottom: 8px;
+}
diff --git a/addon/statusnet/statusnet.php b/addon/statusnet/statusnet.php
new file mode 100644
index 000000000..bc47242fc
--- /dev/null
+++ b/addon/statusnet/statusnet.php
@@ -0,0 +1,244 @@
+config['system']['addon']
+ * setting. After this, your user can configure their Twitter account settings
+ * from "Settings -> Plugin Settings".
+ *
+ * Requirements: PHP5, curl [Slinky library]
+ *
+ * Documentation: http://diekershoff.homeunix.net/redmine/wiki/friendikaplugin/StatusNet_Plugin
+ */
+
+/* __TODO__
+ *
+ * - what about multimedia content?
+ * so far we just strip HTML tags from the message
+ */
+
+
+/***
+ * We have to alter the TwitterOAuth class a little bit to work with any StatusNet
+ * installation abroad. Basically it's only make the API path variable and be happy.
+ *
+ * Thank you guys for the Twitter compatible API!
+ */
+require_once('addon/twitter/twitteroauth.php');
+class StatusNetOAuth extends TwitterOAuth {
+ function get_maxlength() {
+ $config = $this->get($this->host . 'statusnet/config.json');
+ return $config->site->textlimit;
+ }
+ function accessTokenURL() { return $this->host.'oauth/access_token'; }
+ function authenticateURL() { return $this->host.'oauth/authenticate'; }
+ function authorizeURL() { return $this->host.'oauth/authorize'; }
+ function requestTokenURL() { return $this->host.'oauth/request_token'; }
+ function __construct($apipath, $consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
+ parent::__construct($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
+ $this->host = $apipath;
+ }
+}
+
+function statusnet_install() {
+ // we need some hooks, for the configuration and for sending tweets
+ register_hook('plugin_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
+ register_hook('plugin_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
+ register_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
+ logger("installed statusnet");
+}
+
+
+function statusnet_uninstall() {
+ unregister_hook('plugin_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
+ unregister_hook('plugin_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
+ unregister_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
+}
+
+function statusnet_settings_post ($a,$post) {
+ if(! local_user())
+ return;
+ if (isset($_POST['statusnet-disconnect'])) {
+ /***
+ * if the statusnet-disconnect checkbox is set, clear the statusnet configuration
+ * TODO can we revoke the access tokens at Twitter and do we need to do so?
+ */
+ del_pconfig( local_user(), 'statusnet', 'consumerkey' );
+ del_pconfig( local_user(), 'statusnet', 'consumersecret' );
+ del_pconfig( local_user(), 'statusnet', 'post' );
+ del_pconfig( local_user(), 'statusnet', 'oauthtoken' );
+ del_pconfig( local_user(), 'statusnet', 'oauthsecret' );
+ del_pconfig( local_user(), 'statusnet', 'baseapi' );
+ } else {
+ if (isset($_POST['statusnet-consumersecret'])) {
+ set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
+ set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
+ set_pconfig(local_user(), 'statusnet', 'baseapi', $_POST['statusnet-baseapi']);
+ header('Location: '.$a->get_baseurl().'/settings/addon');
+ } else {
+ if (isset($_POST['statusnet-pin'])) {
+ // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen
+ logger('got a StatusNet security code');
+ $api = get_pconfig(local_user(), 'statusnet', 'baseapi');
+ $ckey = get_pconfig(local_user(), 'statusnet', 'consumerkey' );
+ $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' );
+ // the token and secret for which the PIN was generated were hidden in the settings
+ // form as token and token2, we need a new connection to Twitter using these token
+ // and secret to request a Access Token with the PIN
+ $connection = new StatusNetOAuth($api, $ckey, $csecret, $_POST['statusnet-token'], $_POST['statusnet-token2']);
+ $token = $connection->getAccessToken( $_POST['statusnet-pin'] );
+ // ok, now that we have the Access Token, save them in the user config
+ set_pconfig(local_user(),'statusnet', 'oauthtoken', $token['oauth_token']);
+ set_pconfig(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']);
+ set_pconfig(local_user(),'statusnet', 'post', 1);
+ // reload the Addon Settings page, if we don't do it see Bug #42
+ header('Location: '.$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(),'statusnet','post',intval($_POST['statusnet-enable']));
+ }}}
+}
+function statusnet_settings(&$a,&$s) {
+ if(! local_user())
+ return;
+ $a->page['htmlhead'] .= '' . "\r\n";
+ /***
+ * 1) Check that we have a base api url and a consumer key & secret
+ * 2) If no OAuthtoken & stuff is present, generate button to get some
+ * 3) Checkbox for "Send public notices (respect size limitation)
+ */
+ $api = get_pconfig(local_user(), 'statusnet', 'baseapi');
+ $ckey = get_pconfig(local_user(), 'statusnet', 'consumerkey' );
+ $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' );
+ $otoken = get_pconfig(local_user(), 'statusnet', 'oauthtoken' );
+ $osecret = get_pconfig(local_user(), 'statusnet', 'oauthsecret' );
+ $enabled = get_pconfig(local_user(), 'statusnet', 'post');
+ $checked = (($enabled) ? ' checked="checked" ' : '');
+ $s .= '
'.t('StatusNet Posting Settings').'
';
+
+ if ( (!$ckey) && (!$csecret) ) {
+ /***
+ * no consumer keys
+ */
+ $s .= '
Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendika installation at your favorited StatusNet installation.') .'
';
+ $s .= '';
+ $s .= '
';
+ $s .= '';
+ $s .= '
';
+ $s .= '';
+ $s .= '
'.$details->description.']+)\'?>/', $result, $matches ) )
+ return $matches[1];
+ else
+ return $url;
+ }
+}
+
+// Tighturl.com
+class Slinky_TightURL extends Slinky_Service {
+ function url_is_short( $url ) {
+ return stristr( $url, 'tighturl.com/' )
+ || stristr( $url, '2tu.us/' );
+ }
+
+ function url_is_long( $url ) {
+ return !stristr( $url, 'tighturl.com/' )
+ && !stristr( $url, '2tu.us/' );
+ }
+
+ function make_short( $url ) {
+ $response = $this->url_get( 'http://tighturl.com/?save=y&url=' . urlencode( $url ) );
+ if ( preg_match( '/Your tight URL is:
/', $response, $matches ) ) {
+ return $matches[1];
+ } else {
+ return $url;
+ }
+ }
+}
+
+// Snipr for Slinky
+/*
+To use Snipr, you MUST set your user_id and API (key) for the service first, e.g.
+
+$snipr = new Slinky_Snipr();
+$snipr->set( 'user_id', 'Snipr User ID' );
+$snipr->set( 'API', 'Snipr API Key' );
+
+$slinky = new Slinky( $url, $snipr );
+echo $slinky->short();
+
+NOTE: Snipr requires the SimpleXML extension to be installed for lengthening URLs
+*/
+class Slinky_Snipr extends Slinky_Service {
+ // Snipurl, Snurl, Snipr, Sn.im
+ function url_is_short( $url ) {
+ return stristr( $url, 'snipr.com/' ) || stristr( $url, 'snipurl.com/' ) || stristr( $url, 'snurl.com/' ) || stristr( $url, 'sn.im/' );
+ }
+
+ function url_is_long( $url ) {
+ return !stristr( $url, 'snipr.com/' ) || !stristr( $url, 'snipurl.com/' ) || !stristr( $url, 'snurl.com/' ) || !stristr( $url, 'sn.im/' );
+ }
+
+ function make_short( $url ) {
+ if ( !$this->get( 'user_id' ) || !$this->get( 'API' ) )
+ return $url;
+
+ $response = $this->url_post( 'http://snipr.com/site/getsnip', array( 'sniplink' => urlencode( $url ), 'snipuser' => $this->get( 'user_id'), 'snipapi' => $this->get( 'API' ), 'snipformat' => 'simple' ) );
+ if ( 'ERROR' != substr( $response, 0, 5 ) )
+ return $response;
+ else
+ return $url;
+ }
+}
+
+// If you're testing things out, http://dentedreality.com.au/ should convert to:
+// - http://tinyurl.com/jw5sh
+// - http://bit.ly/hEkAD
+// - http://tr.im/sk1H
+// - http://is.gd/1yJ81
+// - http://fon.gs/tc1p8c
+// - http://micurl.com/qen3uub
+// - http://ur1.ca/7dcd
+// - http://ptiturl.com/?id=bac8fb
+// - http://tighturl.com/kgd
+// - http://snipr.com/nbbw3
+//
+// $slinky = new Slinky( 'http://dentedreality.com.au/' );
+// echo $slinky->short();
diff --git a/addon/twitter/twitter.css b/addon/twitter/twitter.css
new file mode 100644
index 000000000..899cfd173
--- /dev/null
+++ b/addon/twitter/twitter.css
@@ -0,0 +1,41 @@
+
+
+#twitter-avatar {
+ float: left;
+ width: 48px;
+ height: 48px;
+ padding: 2px;
+}
+#twitter-info-block {
+ height: 52px;
+ vertical-align: middle;
+}
+#twitter-disconnect-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 25px;
+}
+
+#twitter-disconnect {
+ float: left;
+}
+#twitter-enable-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 5px;
+}
+
+#twitter-checkbox {
+ float: left;
+}
+#twitter-pin-label {
+ float: left;
+ width: 200px;
+ margin-bottom: 25px;
+}
+
+#twitter-pin {
+ float: left;
+}
+
+
diff --git a/addon/twitter/twitter.php b/addon/twitter/twitter.php
index 9fccefbee..0b706f9b1 100644
--- a/addon/twitter/twitter.php
+++ b/addon/twitter/twitter.php
@@ -1,16 +1,197 @@
config['twitter']['consumerkey'] = 'your consumer_key here';
+ * $a->config['twitter']['consumersecret'] = 'your consumer_secret here';
+ *
+ * To activate the plugin itself add it to the $a->config['system']['addon']
+ * setting. After this, your user can configure their Twitter account settings
+ * from "Settings -> Plugin Settings".
+ *
+ * Requirements: PHP5, curl [Slinky library]
+ *
+ * Documentation: http://diekershoff.homeunix.net/redmine/wiki/friendikaplugin/Twitter_Plugin
+ */
+
+/* __TODO__
+ *
+ * - what about multimedia content?
+ * so far we just strip HTML tags from the message
+ */
function twitter_install() {
+ // we need some hooks, for the configuration and for sending tweets
+ register_hook('plugin_settings', 'addon/twitter/twitter.php', 'twitter_settings');
+ register_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
register_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
+ register_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
+ register_hook('post_local_start', 'addon/twitter/twitter.php', 'twitter_post_start');
+ logger("installed twitter");
}
function twitter_uninstall() {
+ unregister_hook('plugin_settings', 'addon/twitter/twitter.php', 'twitter_settings');
+ unregister_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
+ unregister_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
+ unregister_hook('post_local_start', 'addon/twitter/twitter.php', 'twitter_post_start');
+
+}
+
+function twitter_jot_nets(&$a,&$b) {
+ if(! local_user())
+ return;
+
+ $tw_post = get_pconfig(local_user(),'twitter','post');
+ if(intval($tw_post) == 1) {
+ $tw_defpost = get_pconfig(local_user(),'twitter','post_by_default');
+ $selected = ((intval($tw_defpost == 1)) ? ' selected="selected" ' : '');
+ $b .= '
'. t('Twitter Posting Settings') .'
';
+
+ if ( (!$ckey) && (!$csecret) ) {
+ /***
+ * no global consumer keys
+ * display warning and skip personal config
+ */
+ $s .= '';
+ $s .= '
'.$details->description.'
\r\n" );
@@ -195,7 +195,7 @@ class App {
public $hooks;
public $timezone;
public $interactive = true;
-
+ public $plugins;
private $scheme;
private $hostname;
@@ -305,9 +305,9 @@ class App {
$this->scheme = $parsed['scheme'];
$this->hostname = $parsed['host'];
- if($parsed['port'])
+ if(x($parsed,'port'))
$this->hostname .= ':' . $parsed['port'];
- if($parsed['path'])
+ if(x($parsed,'path'))
$this->path = trim($parsed['path'],'\\/');
}
@@ -478,6 +478,8 @@ function check_config(&$a) {
if($plugins)
$plugins_arr = explode(',',str_replace(' ', '',$plugins));
+ $a->plugins = $plugins_arr;
+
$installed_arr = array();
if(count($installed)) {
@@ -514,6 +516,7 @@ function check_config(&$a) {
}
}
}
+ load_hooks();
return;
}}
@@ -1378,10 +1381,12 @@ function webfinger($s) {
logger('webfinger: lrdd template: ' . $tpl);
if(strlen($tpl)) {
$pxrd = str_replace('{uri}', urlencode('acct:'.$s), $tpl);
+ logger('webfinger: pxrd: ' . $pxrd);
$links = fetch_xrd_links($pxrd);
if(! count($links)) {
// try with double slashes
$pxrd = str_replace('{uri}', urlencode('acct://'.$s), $tpl);
+ logger('webfinger: pxrd: ' . $pxrd);
$links = fetch_xrd_links($pxrd);
}
return $links;
@@ -1453,6 +1458,7 @@ function fetch_lrdd_template($host) {
$tpl = '';
$url = 'http://' . $host . '/.well-known/host-meta' ;
$links = fetch_xrd_links($url);
+logger('template: ' . print_r($links,true));
if(count($links)) {
foreach($links as $link)
if($link['@attributes']['rel'] && $link['@attributes']['rel'] === 'lrdd')
@@ -1479,15 +1485,30 @@ function fetch_xrd_links($url) {
$h = simplexml_load_string($xml);
$arr = convert_xml_element_to_array($h);
+ $links = array();
+
if(isset($arr['xrd']['link'])) {
$link = $arr['xrd']['link'];
if(! isset($link[0]))
$links = array($link);
else
$links = $link;
- return $links;
}
- return array();
+ if(isset($arr['xrd']['alias'])) {
+ $alias = $arr['xrd']['alias'];
+ if(! isset($alias[0]))
+ $aliases = array($alias);
+ else
+ $aliases = $alias;
+ foreach($aliases as $alias) {
+ $links[]['@attributes'] = array('rel' => 'alias' , 'href' => $alias);
+ }
+ }
+
+ logger('fetch_xrd_links: ' . print_r($links,true), LOGGER_DATA);
+
+ return $links;
+
}}
// Convert an ACL array to a storable string
@@ -2079,7 +2100,7 @@ function profile_sidebar($profile) {
$tabs = '';
- $photo = '$1
' ,$Text);
diff --git a/include/html2bbcode.php b/include/html2bbcode.php
index 6af8df824..734282d95 100644
--- a/include/html2bbcode.php
+++ b/include/html2bbcode.php
@@ -7,10 +7,15 @@
function html2bbcode($s) {
+
+ // only keep newlines from source that are within pre tags
+
+ $s = stripnl_exceptinpre($s);
+
+
// Tags to Find
$htmltags = array(
- '/\n/is',
'/\(.*?)\<\/pre\>/is',
'/\
(.*?)\<\/code\>/is',
'/\(.*?)\<\/span\>/is',
+ '/\(.*?)\<\/span\>/is',
'/\
(.*?)\<\/blockquote\>/is',
'/\