~cszikszoy/do-plugins/pastebin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//  LodgeIt.cs
//
//  GNOME Do is the legal property of its developers, whose names are too
//  numerous to list here.  Please refer to the COPYRIGHT file distributed with
//  this source distribution.
//
//  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 3 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, see <http://www.gnu.org/licenses/>.

using System;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace Pastebin
{
	public class LodgeIt : IPastebinProvider
	{		
		private const string urlRoot = "http://paste.pocoo.org/";
	
		private NameValueCollection parameters;
		private List<TextSyntaxItem> supportedLanguages;
		
		public LodgeIt ()
		{
			parameters = new NameValueCollection();
			parameters["language"] = "text";
			parameters["code"] = "";
			
			supportedLanguages = new List<TextSyntaxItem> (); 
			supportedLanguages.Add (new TextSyntaxItem ("Apache Config (.htaccess)", "Apache Config (.htaccess)", "file", "apache"));
			supportedLanguages.Add (new TextSyntaxItem ("Bash", "Bash", "file", "bash"));
			supportedLanguages.Add (new TextSyntaxItem ("Batch (.bat)", "Batch (.bat)", "file", "bat"));
			supportedLanguages.Add (new TextSyntaxItem ("C", "C", "file", "c"));
			supportedLanguages.Add (new TextSyntaxItem ("C#", "C#", "file", "csharp"));
			supportedLanguages.Add (new TextSyntaxItem ("C++", "C++", "file", "cpp"));
			supportedLanguages.Add (new TextSyntaxItem ("CSS", "CSS", "file", "css"));
			supportedLanguages.Add (new TextSyntaxItem ("D", "D", "file", "d"));
			supportedLanguages.Add (new TextSyntaxItem ("Django / Jinja Templates", "Django / Jinja Templates", "file", "html+django"));
			supportedLanguages.Add (new TextSyntaxItem ("Dylan", "Dylan", "file", "dylan"));
			supportedLanguages.Add (new TextSyntaxItem ("Erlang", "Erlang", "file", "erlang"));
			supportedLanguages.Add (new TextSyntaxItem ("GAS", "GAS", "file", "gas"));
			supportedLanguages.Add (new TextSyntaxItem ("Genshi Templates", "Genshi Templates", "file", "html+genshi"));
			supportedLanguages.Add (new TextSyntaxItem ("HTML", "HTML", "file", "html"));
			supportedLanguages.Add (new TextSyntaxItem ("Haskell", "Haskell", "file", "haskell"));
			supportedLanguages.Add (new TextSyntaxItem ("IRC Logs", "IRC Logs", "file", "irc"));
			supportedLanguages.Add (new TextSyntaxItem ("Interactive Ruby", "Interactive Ruby", "file", "irb"));
			supportedLanguages.Add (new TextSyntaxItem ("JSP", "JSP", "file", "jsp"));
			supportedLanguages.Add (new TextSyntaxItem ("Java", "Java", "file", "java"));
			supportedLanguages.Add (new TextSyntaxItem ("JavaScript", "JavaScript", "file", "js"));
			supportedLanguages.Add (new TextSyntaxItem ("Lua", "Lua", "file", "lua"));
			supportedLanguages.Add (new TextSyntaxItem ("Mako Templates", "Mako Templates", "file", "html+mako"));
			supportedLanguages.Add (new TextSyntaxItem ("MiniD", "MiniD", "file", "minid"));
			supportedLanguages.Add (new TextSyntaxItem ("Myghty Templates", "Myghty Templates", "file", "html+myghty"));
			supportedLanguages.Add (new TextSyntaxItem ("OCaml", "OCaml", "file", "ocaml"));
			supportedLanguages.Add (new TextSyntaxItem ("PHP", "PHP", "file", "html+php"));
			supportedLanguages.Add (new TextSyntaxItem ("Perl", "Perl", "file", "perl"));
			supportedLanguages.Add (new TextSyntaxItem ("Python", "Python", "file", "python"));
			supportedLanguages.Add (new TextSyntaxItem ("Python Console Sessions", "Python Console Sessions", "file", "pycon"));
			supportedLanguages.Add (new TextSyntaxItem ("Python Tracebacks", "Python Tracebacks", "file", "pytb"));
			supportedLanguages.Add (new TextSyntaxItem ("Ruby", "Ruby", "file", "ruby"));
			supportedLanguages.Add (new TextSyntaxItem ("SQL", "SQL", "file", "sql"));
			supportedLanguages.Add (new TextSyntaxItem ("Scheme", "Scheme", "file", "scheme"));
			supportedLanguages.Add (new TextSyntaxItem ("Smarty", "Smarty", "file", "smarty"));
			supportedLanguages.Add (new TextSyntaxItem ("SquidConf", "SquidConf", "file", "squidconf"));
			supportedLanguages.Add (new TextSyntaxItem ("TeX / LaTeX", "TeX / LaTeX", "file", "tex"));
			supportedLanguages.Add (new TextSyntaxItem ("Text", "Text", "file", "text"));
			supportedLanguages.Add (new TextSyntaxItem ("Unified Diff", "Unified Diff", "file", "diff"));
			supportedLanguages.Add (new TextSyntaxItem ("Vim", "Vim", "file", "vim"));
			supportedLanguages.Add (new TextSyntaxItem ("XML", "XML", "file", "xml"));
			supportedLanguages.Add (new TextSyntaxItem ("eRuby / rhtml", "eRuby / rhtml", "file", "rhtml"));
			supportedLanguages.Add (new TextSyntaxItem ("reStructuredText", "reStructuredText", "file", "rst"));
			supportedLanguages.Add (new TextSyntaxItem ("sources.list", "sources.list", "file", "sourceslist"));
		}
	
		public LodgeIt (string content, string syntax) : this ()
		{		
			parameters["language"] = syntax;
			parameters["code"] = content;
		}
		
		public LodgeIt (string content) : this ()
		{		
			parameters["code"] = content;
		}

		public bool ShouldAllowAutoRedirect
		{
			get { return false; }
		}
		
		public string BaseUrl 
		{ 
			get { return urlRoot; } 
		}
		
		public NameValueCollection Parameters 
		{ 
			get { return parameters; } 
		}
		
		public string GetPasteUrlFromResponse (HttpWebResponse response)
		{	
			string responseText;
			using (Stream responseStream = response.GetResponseStream ()) {
               using (StreamReader reader = new StreamReader (responseStream)) {
                   responseText = reader.ReadToEnd ();
               }
			}
			return responseText;
		}
		
		public List<TextSyntaxItem> SupportedLanguages 
		{ 
			get { return supportedLanguages; }
		}
	}
}