]> git.mxchange.org Git - friendica-addons.git/commitdiff
modified: statusnet.tgz First url shortener is a custom YourLS url âshortener...
authorKeith Fernie <keith@fernie.eu>
Thu, 9 Feb 2012 21:15:41 +0000 (21:15 +0000)
committerKeith Fernie <keith@fernie.eu>
Thu, 9 Feb 2012 21:15:41 +0000 (21:15 +0000)
modified:   statusnet/statusnet.php First url shortener is a custom YourLS url �shortener, if it is configured.
modified:   twitter.tgz First url shortener is a custom YourLS url �shortener, if it is configured.
modified:   twitter/twitter.php First url shortener is a custom YourLS url �shortener, if it is configured.
new file:   yourls.tgz sets up the config for a custom YourLS url shortener.
new file:   yourls/README sets up the config for a custom YourLS url shortener.
new file:   yourls/yourls.css sets up the config for a custom YourLS url shortener.
new file:   yourls/yourls.php sets up the config for a custom YourLS url shortener.

statusnet.tgz
statusnet/statusnet.php
twitter.tgz
twitter/twitter.php
yourls.tgz [new file with mode: 0755]
yourls/README [new file with mode: 0755]
yourls/yourls.css [new file with mode: 0755]
yourls/yourls.php [new file with mode: 0755]

index 4067e682f847b66514e07e6c4698d07a505e6892..5865f1513301106336edef626e7791cdd74710c8 100755 (executable)
Binary files a/statusnet.tgz and b/statusnet.tgz differ
index 7e9226a0e55bf512a3ed569fdef11ae627345ec7..bf606cba0b5811b7759a8c881404bc19c000d309 100755 (executable)
@@ -407,10 +407,24 @@ function statusnet_post_hook(&$a,&$b) {
                        $shortlink = "";
                        require_once('library/slinky.php');
                        $slinky = new Slinky( $b['plink'] );
-                       // setup a cascade of shortening services
-                       // try to get a short link from these services
-                       // in the order ur1.ca, trim, id.gd, tinyurl
-                       $slinky->set_cascade( array( new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
+            $yourls_url = get_config('yourls','url1');
+            if ($yourls_url) {
+                $yourls_username = get_config('yourls','username1');
+                $yourls_password = get_config('yourls', 'password1');
+                               $yourls_ssl = get_config('yourls', 'ssl1');
+                $yourls = new Slinky_YourLS();
+                $yourls->set( 'username', $yourls_username );
+                $yourls->set( 'password', $yourls_password );
+                               $yourls->set( 'ssl', $yourls_ssl );
+                $yourls->set( 'yourls-url', $yourls_url );
+                $slinky->set_cascade( array( $yourls, new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
+            }
+            else {
+                               // setup a cascade of shortening services
+                               // try to get a short link from these services
+                               // in the order ur1.ca, trim, id.gd, tinyurl
+                               $slinky->set_cascade( array( new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
+                       }
                        $shortlink = $slinky->short();
                        // the new message will be shortened such that "... $shortlink"
                        // will fit into the character limit
index 740e3c8178280205941be90a502fe164a948a0b9..ee5caa899bc5ed51a996f997528e2c5707ce46bd 100755 (executable)
Binary files a/twitter.tgz and b/twitter.tgz differ
index a6f73c86429ea0d2fdd6be09a27d2759bc51a059..11b92d4eefd87a3d348974e9a9471ce478710657 100755 (executable)
@@ -269,10 +269,25 @@ function twitter_post_hook(&$a,&$b) {
                        $shortlink = "";
                        require_once('library/slinky.php');
                        $slinky = new Slinky( $b['plink'] );
-                       // setup a cascade of shortening services
-                       // try to get a short link from these services
-                       // in the order ur1.ca, trim, id.gd, tinyurl
-                       $slinky->set_cascade( array( new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
+            $yourls_url = get_config('yourls','url1');
+            if ($yourls_url) {
+                               $max_char = 135;
+                   $yourls_username = get_config('yourls','username1');
+                $yourls_password = get_config('yourls', 'password1');
+                $yourls_ssl = get_config('yourls', 'ssl1');
+                $yourls = new Slinky_YourLS();
+                $yourls->set( 'username', $yourls_username );
+                $yourls->set( 'password', $yourls_password );
+                $yourls->set( 'ssl', $yourls_ssl );
+                $yourls->set( 'yourls-url', $yourls_url );
+                $slinky->set_cascade( array( $yourls, new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
+            }
+            else {
+                               // setup a cascade of shortening services
+                               // try to get a short link from these services
+                               // in the order ur1.ca, trim, id.gd, tinyurl
+                               $slinky->set_cascade( array( new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL() ) );
+                       }
                        $shortlink = $slinky->short();
                        // the new message will be shortened such that "... $shortlink"
                        // will fit into the character limit
@@ -282,7 +297,7 @@ function twitter_post_hook(&$a,&$b) {
                // and now tweet it :-)
                if(strlen($msg)) {
                        $result = $tweet->post('statuses/update', array('status' => $msg));
-                       logger('twitter_post send', LOGGER_DEBUG);
+                       logger('twitter_post send' , LOGGER_DEBUG);
                }
        }
 }
diff --git a/yourls.tgz b/yourls.tgz
new file mode 100755 (executable)
index 0000000..6778dfb
Binary files /dev/null and b/yourls.tgz differ
diff --git a/yourls/README b/yourls/README
new file mode 100755 (executable)
index 0000000..3950f02
--- /dev/null
@@ -0,0 +1,8 @@
+YourLS
+
+For server admins only.
+Defines a YourLS url shortener for the Statusnet & Twitter plugins.
+
+This plugin will not do anything else unless the Statusnet and/or Twitter plugins are installed.
+
+The message is entered in the admin account at Settings -> Plugin settings.
diff --git a/yourls/yourls.css b/yourls/yourls.css
new file mode 100755 (executable)
index 0000000..07a73d3
--- /dev/null
@@ -0,0 +1,21 @@
+#yourls-label {
+       float: left;
+       width: 300px;
+       margin-top: 10px;
+}
+
+yourls-url {
+       float: left;
+       margin-top: 10px;
+}
+
+#yourls-submit {
+       margin-top: 15px;
+}
+
+.yourls {
+    text-align: left;
+       width 100%;
+       margin-top: 25px;
+       font-size: 20px;
+}
diff --git a/yourls/yourls.php b/yourls/yourls.php
new file mode 100755 (executable)
index 0000000..bbaa96b
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+
+
+/**
+ * Name: Yourls
+ * Description: Defines a YourLS url shortener for the Statusnet & Twitter plugins
+ * Version: 1.0
+ * Author: Keith Fernie <http://friendika.me4.it/profile/keith>
+ * 
+ */
+
+function yourls_install() {
+       register_hook('plugin_settings', 'addon/yourls/yourls.php', 'yourls_addon_settings');
+       register_hook('plugin_settings_post', 'addon/yourls/yourls.php', 'yourls_addon_settings_post');
+
+}
+
+
+function yourls_uninstall() {
+       unregister_hook('plugin_settings', 'addon/yourls/yourls.php', 'yourls_addon_settings');
+       unregister_hook('plugin_settings_post', 'addon/yourls/yourls.php', 'yourls_addon_settings_post');
+    set_config('yourls','url1',trim($_POST['']));
+    set_config('yourls','username1',trim($_POST['']));
+    set_config('yourls','password1',trim($_POST['']));
+    set_config('yourls','ssl1',trim($_POST['']));
+
+}
+
+
+
+
+
+function yourls_addon_settings(&$a,&$s) {
+
+
+       if(! is_site_admin())
+               return;
+
+    /* Add our stylesheet to the page so we can make our settings look nice */
+
+    $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/yourls/yourls.css' . '" media="all" />' . "\r\n";
+
+
+       $yourls_url = get_config('yourls','url1');
+    $yourls_username = get_config('yourls','username1');
+    $yourls_password = get_config('yourls', 'password1');
+    $ssl_enabled = get_config('yourls','ssl1');
+    $ssl_checked = (($ssl_enabled) ? ' checked="checked" ' : '');
+
+
+
+$yourls_ssl = get_config('yourls', 'ssl1');
+
+    $s .= '<div class="settings-block">';
+    $s .= '<h3>' . t('YourLS Settings') . '</h3>';
+    $s .= '<div id="yourls-url-wrapper">';
+       $s .= '<label id="yourls-url-label" for="yourls-url">' . t('URL: http://') . '</label>';
+    $s .= '<input id="yourls-url" type="text" name="yourls_url" value="' . $yourls_url .'" />';
+    $s .= '</div><div class="clear"></div>';
+
+    $s .= '<div id="yourls-username-wrapper">';
+    $s .= '<label id="yourls-username-label" for="yourls-username">' . t('Username:') . '</label>';
+    $s .= '<input id="yourls-username" type="text" name="yourls_username" value="' . $yourls_username .'" />';
+    $s .= '</div><div class="clear"></div>';
+
+    $s .= '<div id="yourls-password-wrapper">';
+    $s .= '<label id="yourls-password-label" for="yourls-password">' . t('Password:') . '</label>';
+    $s .= '<input id="yourls-password" type="password" name="yourls_password" value="' . $yourls_password .'" />';
+    $s .= '</div><div class="clear"></div>';
+
+       $s .= '<div id="yourls-ssl-wrapper">';
+    $s .= '<label id="yourls-ssl-label" for="yourls-ssl">' . t('Use SSL ') . '</label>';
+    $s .= '<input id="yourls-ssl" type="checkbox" name="yourls_ssl" value="1" ' . $ssl_checked . '"/>';
+    $s .= '</div><div class="clear"></div>';
+
+    $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="yourls-submit" name="yourls-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
+
+       return;
+
+}
+
+function yourls_addon_settings_post(&$a,&$b) {
+
+       if(! is_site_admin())
+               return;
+
+       if($_POST['yourls-submit']) {
+               set_config('yourls','url1',trim($_POST['yourls_url']));
+        set_config('yourls','username1',trim($_POST['yourls_username']));
+        set_config('yourls','password1',trim($_POST['yourls_password']));
+        set_config('yourls','ssl1',intval($_POST['yourls_ssl']));
+               info( t('yourls Settings saved.') . EOL);
+       }
+}