fixed #11: Added yourls.org url shortener support

This commit is contained in:
Jaex 2014-01-20 03:04:03 +02:00
parent bbfc9b7017
commit d256efdb44
11 changed files with 621 additions and 358 deletions

View file

@ -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))
{

View file

@ -200,6 +200,13 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
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

View file

@ -129,6 +129,8 @@ public enum UrlShortenerType
TINYURL,
[Description("turl.ca")]
TURL,
[Description("yourls.org")]
YOURLS,
[Description("Custom URL shortener")]
CustomURLShortener
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

File diff suppressed because it is too large Load diff

View file

@ -985,6 +985,31 @@ private void oauth2Bitly_CompleteButtonClicked(string code)
#endregion bit.ly
#region yourls.org
private void txtYourlsAPIURL_TextChanged(object sender, EventArgs e)
{
Config.YourlsAPIURL = txtYourlsAPIURL.Text;
}
private void txtYourlsSignature_TextChanged(object sender, EventArgs e)
{
Config.YourlsSignature = txtYourlsSignature.Text;
txtYourlsUsername.Enabled = txtYourlsPassword.Enabled = string.IsNullOrEmpty(Config.YourlsSignature);
}
private void txtYourlsUsername_TextChanged(object sender, EventArgs e)
{
Config.YourlsUsername = txtYourlsUsername.Text;
}
private void txtYourlsPassword_TextChanged(object sender, EventArgs e)
{
Config.YourlsPassword = txtYourlsPassword.Text;
}
#endregion yourls.org
#endregion URL Shorteners
#region Other Services

View file

@ -82,6 +82,7 @@ private void ControlSettings()
urlShortenersImageList.ColorDepth = ColorDepth.Depth32Bit;
urlShortenersImageList.Images.Add("Google", Resources.Google);
urlShortenersImageList.Images.Add("Bitly", Resources.Bitly);
urlShortenersImageList.Images.Add("Yourls", Resources.Yourls);
tcURLShorteners.ImageList = urlShortenersImageList;
ImageList socialNetworkingServicesImageList = new ImageList();
@ -114,6 +115,7 @@ private void ControlSettings()
tpPastebin.ImageKey = "Pastebin";
tpGoogleURLShortener.ImageKey = "Google";
tpBitly.ImageKey = "Bitly";
tpYourls.ImageKey = "Yourls";
tpTwitter.ImageKey = "Twitter";
tpMega.ImageKey = "Mega";
tpGist.ImageKey = "Gist";
@ -404,6 +406,14 @@ public void LoadSettings(UploadersConfig uploadersConfig)
oauth2Bitly.LoginStatus = true;
}
// yourls.org
txtYourlsAPIURL.Text = Config.YourlsAPIURL;
txtYourlsSignature.Text = Config.YourlsSignature;
txtYourlsUsername.Enabled = txtYourlsPassword.Enabled = string.IsNullOrEmpty(Config.YourlsSignature);
txtYourlsUsername.Text = Config.YourlsUsername;
txtYourlsPassword.Text = Config.YourlsPassword;
#endregion URL Shorteners
#region Other Services

View file

@ -659,5 +659,15 @@ internal class Resources {
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon Yourls {
get {
object obj = ResourceManager.GetObject("Yourls", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
}
}

View file

@ -298,4 +298,7 @@
<data name="Gist" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Favicons\Gist.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
<data name="Yourls" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\favicons\yourls.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#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<string, string> arguments = new Dictionary<string, string>();
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;
}
}
}

View file

@ -301,6 +301,7 @@
<Compile Include="URLShorteners\TinyURLShortener.cs" />
<Compile Include="URLShorteners\TurlURLShortener.cs" />
<Compile Include="ImageUploaders\MediaCrushUploader.cs" />
<Compile Include="URLShorteners\YourlsURLShortener.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ApiKeys\ApiKeysUI.resx">
@ -372,6 +373,7 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="Favicons\Yourls.ico" />
<None Include="Resources\gist.ico" />
<None Include="packages.config" />
<EmbeddedResource Include="ApiKeys\jira_sharex.pfx" />