From d256efdb44044b88342e90740470580bc1b27224 Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 20 Jan 2014 03:04:03 +0200 Subject: [PATCH] fixed #11: Added yourls.org url shortener support --- ShareX/UploadTask.cs | 9 + UploadersLib/Config/UploadersConfig.cs | 7 + UploadersLib/Enums.cs | 2 + UploadersLib/Favicons/Yourls.ico | Bin 0 -> 318 bytes .../GUI/UploadersConfigForm.Designer.cs | 835 ++++++++++-------- UploadersLib/GUI/UploadersConfigForm.cs | 25 + UploadersLib/GUI/UploadersConfigFormGUI.cs | 10 + UploadersLib/Properties/Resources.Designer.cs | 10 + UploadersLib/Properties/Resources.resx | 5 +- .../URLShorteners/YourlsURLShortener.cs | 74 ++ UploadersLib/UploadersLib.csproj | 2 + 11 files changed, 621 insertions(+), 358 deletions(-) create mode 100644 UploadersLib/Favicons/Yourls.ico create mode 100644 UploadersLib/URLShorteners/YourlsURLShortener.cs diff --git a/ShareX/UploadTask.cs b/ShareX/UploadTask.cs index b23450c93..c592c34b2 100644 --- a/ShareX/UploadTask.cs +++ b/ShareX/UploadTask.cs @@ -857,6 +857,15 @@ public UploadResult ShortenURL(string url) case UrlShortenerType.TURL: urlShortener = new TurlURLShortener(); break; + case UrlShortenerType.YOURLS: + urlShortener = new YourlsURLShortener + { + APIURL = Program.UploadersConfig.YourlsAPIURL, + Signature = Program.UploadersConfig.YourlsSignature, + Username = Program.UploadersConfig.YourlsUsername, + Password = Program.UploadersConfig.YourlsPassword + }; + break; case UrlShortenerType.CustomURLShortener: if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomURLShortenerSelected)) { diff --git a/UploadersLib/Config/UploadersConfig.cs b/UploadersLib/Config/UploadersConfig.cs index 021997e99..337884b15 100644 --- a/UploadersLib/Config/UploadersConfig.cs +++ b/UploadersLib/Config/UploadersConfig.cs @@ -200,6 +200,13 @@ public class UploadersConfig : SettingsBase public AccountType GoogleURLShortenerAccountType = AccountType.Anonymous; public OAuth2Info GoogleURLShortenerOAuth2Info = null; + // yourls.org + + public string YourlsAPIURL = "http://yoursite.com/yourls-api.php"; + public string YourlsSignature = string.Empty; + public string YourlsUsername = string.Empty; + public string YourlsPassword = string.Empty; + #endregion URL shorteners #region Social networking services diff --git a/UploadersLib/Enums.cs b/UploadersLib/Enums.cs index 466b06954..7eebaf0e7 100644 --- a/UploadersLib/Enums.cs +++ b/UploadersLib/Enums.cs @@ -129,6 +129,8 @@ public enum UrlShortenerType TINYURL, [Description("turl.ca")] TURL, + [Description("yourls.org")] + YOURLS, [Description("Custom URL shortener")] CustomURLShortener } diff --git a/UploadersLib/Favicons/Yourls.ico b/UploadersLib/Favicons/Yourls.ico new file mode 100644 index 0000000000000000000000000000000000000000..a04cba04097cc8b4cdbfc10a3bdc5363d70d3118 GIT binary patch literal 318 zcmb`BF%E@52nA<}u_jwsvz;f>_8;Y6%*xi2cnJj!iKT^*dGLS&D4we7+A$UwfYDLM zoR~-aFTEvp8QV0mrTMzn29EeEfl95dSuryZk@UHb+l!Zf90xpES6CMK^)T;u4IlI8 GUG^uZoFI + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon Yourls { + get { + object obj = ResourceManager.GetObject("Yourls", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } } } diff --git a/UploadersLib/Properties/Resources.resx b/UploadersLib/Properties/Resources.resx index 64d43d37c..8732498e9 100644 --- a/UploadersLib/Properties/Resources.resx +++ b/UploadersLib/Properties/Resources.resx @@ -298,4 +298,7 @@ ..\Favicons\Gist.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - + + ..\favicons\yourls.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/UploadersLib/URLShorteners/YourlsURLShortener.cs b/UploadersLib/URLShorteners/YourlsURLShortener.cs new file mode 100644 index 000000000..606ae3195 --- /dev/null +++ b/UploadersLib/URLShorteners/YourlsURLShortener.cs @@ -0,0 +1,74 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2008-2014 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using UploadersLib.HelperClasses; + +namespace UploadersLib.URLShorteners +{ + public sealed class YourlsURLShortener : URLShortener + { + public string APIURL { get; set; } + public string Signature { get; set; } + public string Username { get; set; } + public string Password { get; set; } + + public override UploadResult ShortenURL(string url) + { + UploadResult result = new UploadResult { URL = url }; + + if (!string.IsNullOrEmpty(url)) + { + Dictionary arguments = new Dictionary(); + + if (!string.IsNullOrEmpty(Signature)) + { + arguments.Add("signature", Signature); + } + else if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) + { + arguments.Add("username", Username); + arguments.Add("password", Password); + } + else + { + throw new Exception("Signature or Username/Password is missing."); + } + + arguments.Add("action", "shorturl"); + arguments.Add("url", url); + //arguments.Add("keyword", ""); + //arguments.Add("title", ""); + arguments.Add("format", "simple"); + + result.Response = SendGetRequest(APIURL, arguments); + result.ShortenedURL = result.Response; + } + + return result; + } + } +} \ No newline at end of file diff --git a/UploadersLib/UploadersLib.csproj b/UploadersLib/UploadersLib.csproj index ff647c397..fc5cefc55 100644 --- a/UploadersLib/UploadersLib.csproj +++ b/UploadersLib/UploadersLib.csproj @@ -301,6 +301,7 @@ + @@ -372,6 +373,7 @@ +