Esempio n. 1
0
		public string dsiTagReplacement(Match m)
		{
			string tagName = "dsi";
			try
			{
				//string[] arrParts = m.Groups[1].Value.Split[" "];
				//Dictionary<string, string> parts = new Dictionary<string, string>();
				SgmlReader sgml = new SgmlReader();
				string inStr = m.Groups[0].Value;
				if (inStr.StartsWith("<dsi:link"))
					inStr += "</dsi:link>";
				sgml.InputStream = new StringReader(inStr);
				sgml.DocType = "HTML";
				sgml.Read();

				tagName = sgml.Name;
				string uniqueId = Guid.NewGuid().ToString("N");

				#region Parse attributes
				Dictionary<string, string> attributes = new Dictionary<string, string>();
				while (sgml.MoveToNextAttribute())
				{
					attributes.Add(sgml.Name.ToLower(), sgml.Value);
				}
				#endregion

				string typeAtt = attributes.ContainsKey("type") ? attributes["type"] : null;
				string refAtt = attributes.ContainsKey("ref") ? attributes["ref"] : null;

				#region Parse styles
				Dictionary<string, string> style = new Dictionary<string, string>();
				if (attributes.ContainsKey("style"))
				{
					foreach (string s in attributes["style"].Split(';'))
					{
						try
						{
							if (s.Contains(":"))
								style[s.Split(':')[0].Trim()] = s.Split(':')[1].Trim();
						}
						catch
						{
						}
					}
				}
				#endregion

				#region Parse class
				List<string> classes = new List<string>();
				if (attributes.ContainsKey("class"))
				{
					foreach (string s in attributes["class"].Split(' '))
					{
						try
						{
							classes.Add(s);
						}
						catch
						{
						}
					}
				}
				#endregion

				if (tagName == "dsi:video")
				{
					#region dsi:video
					/*
					<dsi:video 
						type = [dsi | flv | youtube | google | metacafe | myspace | break | collegehumor | redtube | ebaumsworld | dailymotion] 
						ref = [dsi-photo-k | site-ref]
						src = [flv-url]
						width = [width] (optional)
						height = [height] (optional)
						nsfw = [true | false] (optional)
						/> 
					*/
					bool nsfw = attributes.ContainsKey("nsfw") ? bool.Parse(attributes["nsfw"].ToLower()) : false;
					string draw = attributes.ContainsKey("draw") ? attributes["draw"].ToLower() : "auto";
					if (typeAtt == "youtube")
					{
						#region youtube
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 425;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 355;

						//<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/8VtWo8tFdPQ&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/8VtWo8tFdPQ&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.youtube.com/v/" + refAtt + "&rel=1");
						#endregion
					}
					else if (typeAtt == "metacafe")
					{
						#region metacafe
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 400;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 345;

						//<embed src="http://www.metacafe.com/fplayer/1029494/how_to_make_fire_balls.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"> </embed><br><font size = 1><a href="http://www.metacafe.com/watch/1029494/how_to_make_fire_balls/">How To Make Fire Balls</a> - <a href="http://www.metacafe.com/">The funniest videos clips are here</a></font>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.metacafe.com/fplayer/" + refAtt + ".swf");
						#endregion
					}
					else if (typeAtt == "google")
					{
						#region google
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 400;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 326;

						//<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-7477616603879486362&hl=en-GB" flashvars=""> </embed>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://video.google.com/googleplayer.swf?docId=" + refAtt + "&hl=en-GB");
						#endregion
					}
					else if (typeAtt == "flv")
					{
						#region flv
						string flvUrl = attributes.ContainsKey("src") ? attributes["src"] : null;
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 450;
						int height = attributes.ContainsKey("height") ? (int.Parse(attributes["height"]) + 20) : 357;

						return GetFlash(uniqueId, height, width, nsfw, draw, "/misc/flvplayer.swf", "file", flvUrl, "autoStart", "0");
						#endregion
					}
					else if (typeAtt == "dsi")
					{
						#region dsi
						try
						{
							Photo p = new Photo(int.Parse(refAtt));
							if (p.MediaType != Photo.MediaTypes.Video)
							{
								return "[Invalid ref " + refAtt + " - this is not a video]";
							}
							else
							{
								if (p.ContentDisabled)
								{
									return "[Invalid ref " + refAtt + " - video disabled]";
								}
								else
								{
									if (p.Status == Photo.StatusEnum.Enabled)
									{
										//int width = p.VideoMedWidth;
										//int height = p.VideoMedHeight + 20;

										int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : p.VideoMedWidth;
										int height = attributes.ContainsKey("height") ? (int.Parse(attributes["height"]) + 20) : (p.VideoMedHeight + 20);

										return GetFlash(uniqueId, height, width, nsfw, draw, "/misc/flvplayer.swf", "file", p.VideoMedPath, "autoStart", "0", "jpg", p.WebPath);
									}
									else if (p.Status == Photo.StatusEnum.Moderate)
									{
										return "[Invalid ref " + refAtt + " - video waiting for moderation]";
									}
									else if (p.Status == Photo.StatusEnum.Processing)
									{
										return "[Invalid ref " + refAtt + " - video still processing]";
									}
								}
							}
						}
						catch
						{
							return "[Invalid ref " + refAtt + " - video not found]";
						}
						return "[Invalid ref " + refAtt + " - error]";
						#endregion
					}
					else if (typeAtt == "collegehumor")
					{
						#region collegehumor
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 450;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 337;

						//<object type="application/x-shockwave-flash" data="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1754304&fullscreen=1" width="480" height="360" ><param name="allowfullscreen" value="true" /><param name="movie" quality="best" value="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1754304&fullscreen=1" /></object>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=" + refAtt + "&fullscreen=1");
						#endregion
					}
					else if (typeAtt == "myspace")
					{
						#region myspace
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 430;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 346;

						//<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m=25330587&v=2&type=video" type="application/x-shockwave-flash" width="430" height="346"></embed>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://lads.myspace.com/videos/vplayer.swf", "m", refAtt, "v", "2", "type", "video");
						#endregion
					}
					else if (typeAtt == "break")
					{
						#region break
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 464;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 392;

						//<object width="464" height="392"><param name="movie" value="http://embed.break.com/NDMyNjg3"></param><embed src="http://embed.break.com/NDMyNjg3" type="application/x-shockwave-flash" width="464" height="392"></embed></object>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://embed.break.com/" + refAtt);
						#endregion
					}
					else if (typeAtt == "redtube")
					{
						#region redtube
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 434;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 344;

						//<object height="344" width="434"><param name="movie" value="http://embed.redtube.com/player/"><param name="FlashVars" value="id=2394&style=redtube"><embed src="http://embed.redtube.com/player/?id=2394&style=redtube" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" height="344" width="434"></object>
						return GetFlash(uniqueId, height, width, true, draw, "http://embed.redtube.com/player/?id=" + refAtt + "&style=redtube", "id", refAtt, "style", "redtube");
						#endregion
					}
					else if (typeAtt == "ebaumsworld")
					{
						#region ebaumsworld
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 425;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 345;

						//<embed src="http://www.ebaumsworld.com/mediaplayer.swf" flashvars="file=http://media.ebaumsworld.com/2008/01/trouble-leaving-parking-lot.flv&displayheight=321&image=http://media.ebaumsworld.com/2008/01/trouble-leaving-parking-lot.jpg" loop="false" menu="false" quality="high" bgcolor="#ffffff" width="425" height="345" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.ebaumsworld.com/mediaplayer.swf", "file", "http://media.ebaumsworld.com/" + refAtt + ".flv", "displayheight", (height - 24).ToString(), "image", "http://media.ebaumsworld.com/" + refAtt + ".jpg");
						#endregion
					}
					else if (typeAtt == "dailymotion")
					{
						#region dailymotion
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 420;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 331;

						//<div><object width="420" height="331"><param name="movie" value="http://www.dailymotion.com/swf/x3xmzx"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.dailymotion.com/swf/x3xmzx" type="application/x-shockwave-flash" width="420" height="331" allowFullScreen="true" allowScriptAccess="always"></embed></object><br /><b><a href="http://www.dailymotion.com/video/x3xmzx_time-attack-evo-crash-knockhill-200_auto">TIME ATTACK EVO CRASH KNOCKHILL 2007</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/TIMEATTACKTV">TIMEATTACKTV</a></i></div>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.dailymotion.com/swf/" + refAtt);
						#endregion
					}
					else if (typeAtt == "veoh")
					{
						return "[Veoh videos disabled]";
						#region veoh
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 450;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 365;

						//<embed src="http://www.veoh.com/videodetails2.swf?player=videodetailsembedded&type=v&permalinkId=v1644215kQ3H8PG2&id=anonymous" allowFullScreen="true" width="540" height="438" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed><br/><a href="http://www.veoh.com/">Online Videos by Veoh.com</a>
						return GetFlash(uniqueId, height, width, nsfw, draw, "http://www.veoh.com/videodetails2.swf?player=videodetailsembedded&type=v&permalinkId=" + refAtt + "&id=anonymous");
						#endregion
					}
					else
					{
						return "[Invalid type attribute]";
					}
					#endregion
				}
				else if (tagName == "dsi:audio")
				{
					#region dsi:audio
					/*
					<dsi:audio 
						type = [mp3]
						src = [mp3-url]
						nsfw = [true | false] (optional)
					/>
					*/
					if (typeAtt == "mp3")
					{
						#region mp3
						string mp3Url = attributes.ContainsKey("src") ? attributes["src"] : null;
						int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 290;
						int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 24;

						string audioPlayerSwfPath = Storage.Path(new Guid("7abb3119-f8ad-43ff-be01-764b2ae111fc"), "swf", Storage.Stores.Pix);

						return GetFlash(uniqueId, height, width, false, "load", audioPlayerSwfPath, "soundFile", mp3Url, "autoStart", "no") +
								@"<a href=""" + mp3Url + @"""><img src=""/gfx/download-button2.png"" width=""73"" height=""16"" border=""0"" /></a>";
						#endregion
					}
					else
					{
						return "[Invalid type attribute]";
					}
					#endregion
				}
				else if (tagName == "dsi:flash")
				{
					#region dsi:flash
					/*
					<dsi:flash 
						src = [swf-url]
						width = [width] 
						height = [height]
						nsfw = [true | false] (optional)
						play = [true | false] (optional)
						loop = [true | false] (optional)
						menu = [true | false] (optional)
						quality = [low | autolow | autohigh | medium | high | best] (optional)
						scale = [default | noorder | exactfit] (optional)
						align = [l | t | r | b] (optional)
						salign = [l | t | r | b | tl | tr | bl | br] (optional)
						wmode = [window | opaque | transparent] (optional)
						bgcolor = [colour] (optional)
						base = [base-url] (optional)
						flashvars = [flashvars] (optional)
						/>
					*/
					string swfUrl = attributes.ContainsKey("src") ? attributes["src"] : null;
					return getFlashAttributesFromSgml(uniqueId, swfUrl, attributes);
					#endregion
				}
				else if (tagName == "dsi:quote")
				{
					#region dsi:quote
					Usr u = null;
					try
					{
						u = new Usr(int.Parse(refAtt));
					}
					catch { }

					if (u != null)
					{
						StringBuilder sb = new StringBuilder();
						sb.Append("<div class=\"QuoteName\">");
						sb.Append(u.Link());
						sb.Append(" said:");
						sb.Append("</div>");
						sb.Append("<div class=\"QuoteBody\">");
						return sb.ToString();
					}
					else
					{
						return "<div class=\"QuoteBody\">";
					}
					#endregion
				}
				else if (tagName == "dsi:object" || tagName == "dsi:link")
				{
					#region dsi:object, dsi:link
					/*
					<dsi:object
						type = [usr | event | venue | place | group | brand | photo | misc]
						ref = [object-k]
						style = [
							content: {text* | icon | text-under-icon};   // for type=usr, event, venue, place, group, brand
							details: {none* | venue | place | country};  // for type=event, venue, place
							date: {false* | true};                       // for type=event
							snip: {number};                              // for type=event
							rollover: {true* | false}                    // for type=usr, photo
							photo: {icon* | thumb | web}                 // for type=photo
							link: {true* | false}
						]
					/>
					*/

					string app = attributes.ContainsKey("app") ? (attributes["app"] == "home" ? null : attributes["app"]) : null;
					string date = attributes.ContainsKey("date") ? attributes["date"].Replace('-', '/') : null;
					string jump = attributes.ContainsKey("jump") ? "#" + attributes["jump"] : "";
					string parStr = attributes.ContainsKey("par") ? attributes["par"] : null;
					#region Decode par array
					string[] par = null;
					if (parStr != null)
					{
						List<string> parList = new List<string>();
						foreach (string s in parStr.Split('&'))
						{
							if (s.Contains("="))
							{
								parList.Add(System.Web.HttpUtility.UrlDecode(s.Split('=')[0]));
								parList.Add(System.Web.HttpUtility.UrlDecode(s.Split('=')[1]));
							}
							else
							{
								parList.Add(System.Web.HttpUtility.UrlDecode(s));
								parList.Add("");
							}
						}
						par = parList.ToArray();
					}
					#endregion

					string styleContent = style.ContainsKey("content") ? style["content"] : "text";
					string styleDetails = style.ContainsKey("details") ? style["details"] : "none";
					bool styleDate = style.ContainsKey("date") ? bool.Parse(style["date"]) : false;
					int styleSnip = style.ContainsKey("snip") ? int.Parse(style["snip"]) : 0;
					bool styleRollover = style.ContainsKey("rollover") ? bool.Parse(style["rollover"]) : true;
					string stylePhoto = style.ContainsKey("photo") ? style["photo"] : "icon";
					bool styleLink = style.ContainsKey("link") ? bool.Parse(style["link"]) : true;

					string extraHtmlAttributes = "";
					string extraStyleAttribute = "";
					string extraStyleElements = "";
					string extraClassAttribute = "";
					string extraClassElements = "";
					foreach (string k in attributes.Keys)
					{
						if (k != "href" && k != "src" && k != "type" && k != "ref" && k != "style" && k != "app" && k != "date" && k != "par" && k != "class")
						{
							extraHtmlAttributes += " " + k + "=\"" + attributes[k] + "\"";
						}
					}

					foreach (string s in style.Keys)
					{
						if (s != "content" && s != "details" && s != "date" && s != "snip" && s != "rollover" && s != "photo" && s != "link")
						{
							extraStyleElements += s + ":" + style[s] + ";";
						}
					}
					if (extraStyleElements.Length > 0)
					{
						extraStyleAttribute = " style=\"" + extraStyleElements + "\"";
					}

					foreach (string s in classes)
					{
						extraClassElements += " " + s;
					}
					if (extraClassElements.Length > 0)
					{
						extraClassAttribute = " class=\"" + extraClassElements + "\"";
					}

					if (typeAtt == "usr")
					{
						#region Usr
						Usr u = new Usr(int.Parse(refAtt));
						string url = getObectPageUrl(u, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						string rolloverHtml = styleRollover ? ((styleContent == "icon" || styleContent == "text-under-icon") ? u.RolloverNoPic : u.Rollover) : "";

						if (styleContent == "icon" || styleContent == "text-under-icon")
						{
							#region Pic
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(rolloverHtml);
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append("<img src=\"");
							sb.Append(u.AnyPicPath);
							sb.Append("\"");
							if (styleContent == "icon" && !styleLink)
							{
								//Just image with no link around the image... lets apply any extra html to the image tag.
								if (!attributes.ContainsKey("width"))
									sb.Append(" width=\"100\"");

								if (!attributes.ContainsKey("height"))
									sb.Append(" height=\"100\"");

								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
								sb.Append(" />");
							}
							else
								sb.Append(" width=\"100\" height=\"100\" class=\"BorderBlack All\" />");
							if (styleLink)
								sb.Append("</a>");
							if (styleContent == "text-under-icon")
								sb.Append("<br />");
							#endregion
						}
						if (styleContent == "text" || styleContent == "text-under-icon")
						{
							#region Nickname
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(rolloverHtml);
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append(getObjectName(u.NickNameDisplay, app, styleSnip));
							if (styleLink)
								sb.Append("</a>");
							#endregion
						}
						return sb.ToString();
						#endregion
					}
					else if (typeAtt == "event")
					{
						#region Event
						Event e = new Event(int.Parse(refAtt));
						string url = getObectPageUrl(e, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0) && (styleDate || styleDetails == "venue" || styleDetails == "place" || styleDetails == "country"))
						{
							sb.Append("<span");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						#endregion

						if (styleContent == "icon" || styleContent == "text-under-icon")
						{
							#region Pic
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append("<img src=\"");
							sb.Append(e.AnyPicPath);
							sb.Append("\"");
							if (styleContent == "icon" && !styleLink)
							{
								//Just image with no link around the image... lets apply any extra html to the image tag.
								if (!attributes.ContainsKey("width"))
									sb.Append(" width=\"100\"");

								if (!attributes.ContainsKey("height"))
									sb.Append(" height=\"100\"");

								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
								sb.Append(" />");
							}
							else
								sb.Append(" width=\"100\" height=\"100\" class=\"BorderBlack All\" />");

							if (styleLink)
								sb.Append("</a>");

							if (styleContent == "text-under-icon")
								sb.Append("<br />");

							#endregion
						}
						if (styleContent == "text" || styleContent == "text-under-icon")
						{
							#region Event link
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}

							sb.Append(getObjectName(e.Name, app, styleSnip));

							if (styleLink)
								sb.Append("</a>");
							#endregion

							#region Venue link
							if (styleDetails == "venue" || styleDetails == "place" || styleDetails == "country")
							{
								sb.Append(" @ ");
								if (styleLink)
								{
									sb.Append("<a href=\"");
									sb.Append(e.Venue.Url());
									sb.Append("\"");
									sb.Append(extraHtmlAttributes);
									sb.Append(extraStyleAttribute);
									sb.Append(extraClassAttribute);
									sb.Append(">");
								}
								sb.Append(Cambro.Misc.Utility.Snip(e.Venue.Name, styleSnip));
								if (styleLink)
									sb.Append("</a>");
							}
							#endregion

							#region Place link
							if (styleDetails == "place" || styleDetails == "country")
							{
								sb.Append(" in ");
								if (styleLink)
								{
									sb.Append("<a href=\"");
									sb.Append(e.Venue.Place.Url());
									sb.Append("\"");
									sb.Append(extraHtmlAttributes);
									sb.Append(extraStyleAttribute);
									sb.Append(extraClassAttribute);
									sb.Append(">");
								}
								if (styleDetails == "country")
								{
									sb.Append(Cambro.Misc.Utility.Snip(e.Venue.Place.Name, styleSnip));
								}
								else
								{
									sb.Append(Cambro.Misc.Utility.Snip(e.Venue.Place.NamePlain, styleSnip));
								}
								if (styleLink)
									sb.Append("</a>");

							}
							#endregion

							#region Date
							if (styleDate)
							{
								sb.Append(", ");
								sb.Append(e.FriendlyDate(false));
							}
							#endregion
						}

						#region End container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0) && (styleDetails == "venue" || styleDetails == "place" || styleDetails == "country"))
						{
							sb.Append("</span>");
						}
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "venue")
					{
						#region Venue
						Venue v = new Venue(int.Parse(refAtt));
						string url = getObectPageUrl(v, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0) && (styleDetails == "place" || styleDetails == "country"))
						{
							sb.Append("<span");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						#endregion

						if (styleContent == "icon" || styleContent == "text-under-icon")
						{
							#region Pic
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append("<img src=\"");
							sb.Append(v.AnyPicPath);
							sb.Append("\"");
							if (styleContent == "icon" && !styleLink)
							{
								//Just image with no link around the image... lets apply any extra html to the image tag.
								if (!attributes.ContainsKey("width"))
									sb.Append(" width=\"100\"");

								if (!attributes.ContainsKey("height"))
									sb.Append(" height=\"100\"");

								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
								sb.Append(" />");
							}
							else
								sb.Append(" width=\"100\" height=\"100\" class=\"BorderBlack All\" />");
							if (styleLink)
								sb.Append("</a>");

							if (styleContent == "text-under-icon")
								sb.Append("<br />");
							#endregion
						}

						if (styleContent == "text" || styleContent == "text-under-icon")
						{
							#region Venue link
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}

							sb.Append(getObjectName(v.Name, app, styleSnip));

							if (styleLink)
								sb.Append("</a>");
							#endregion

							#region Place link
							if (styleDetails == "place" || styleDetails == "country")
							{
								sb.Append(" in ");
								if (styleLink)
								{
									sb.Append("<a href=\"");
									sb.Append(v.Place.Url());
									sb.Append("\"");
									sb.Append(extraHtmlAttributes);
									sb.Append(extraStyleAttribute);
									sb.Append(extraClassAttribute);
									sb.Append(">");
								}
								if (styleDetails == "country")
								{
									sb.Append(Cambro.Misc.Utility.Snip(v.Place.Name, styleSnip));
								}
								else
								{
									sb.Append(Cambro.Misc.Utility.Snip(v.Place.NamePlain, styleSnip));
								}
								if (styleLink)
									sb.Append("</a>");
							}
							#endregion
						}

						#region End container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0) && (styleDetails == "place" || styleDetails == "country"))
						{
							sb.Append("</span>");
						}
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "place")
					{
						#region Place
						Place p = new Place(int.Parse(refAtt));
						string url = getObectPageUrl(p, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0))
						{
							sb.Append("<span");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						#endregion

						if (styleContent == "icon" || styleContent == "text-under-icon")
						{
							#region Pic
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							sb.Append("<img src=\"");
							sb.Append(p.AnyPicPath);
							sb.Append("\"");
							if (styleContent == "icon" && !styleLink)
							{
								//Just image with no link around the image... lets apply any extra html to the image tag.
								if (!attributes.ContainsKey("width"))
									sb.Append(" width=\"100\"");

								if (!attributes.ContainsKey("height"))
									sb.Append(" height=\"100\"");

								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								if (style.ContainsKey("border"))
								{
									sb.Append(extraClassAttribute);
								}
								else
								{
									sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
								}
								
								sb.Append(" />");
							}
							else
								sb.Append(" width=\"100\" height=\"100\" class=\"BorderBlack All\" />");
							if (styleLink)
								sb.Append("</a>");
							if (styleContent == "text-under-icon")
								sb.Append("<br />");
							#endregion
						}

						if (styleContent == "text" || styleContent == "text-under-icon")
						{
							#region Place link
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							if (styleDetails == "country")
							{
								sb.Append(getObjectName(p.Name, app, styleSnip));
							}
							else
							{
								sb.Append(getObjectName(p.NamePlain, app, styleSnip));
							}
							if (styleLink)
								sb.Append("</a>");
							#endregion
						}

						#region End container span
						if ((styleContent == "text" || styleContent == "text-under-icon") && !styleLink && (extraHtmlAttributes.Length > 0 || extraStyleAttribute.Length > 0 || extraClassAttribute.Length > 0))
						{
							sb.Append("</span>");
						}
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "group")
					{
						#region Group
						Group g = new Group(int.Parse(refAtt));
						string url = getObectPageUrl(g, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Group link
						if (styleLink)
						{
							sb.Append("<a href=\"");
							sb.Append(url);
							sb.Append("\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						sb.Append(getObjectName(g.FriendlyName, app, styleSnip));
						if (styleLink)
							sb.Append("</a>");
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "brand")
					{
						#region Brand
						Brand b = new Brand(int.Parse(refAtt));
						string url = getObectPageUrl(b, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Brand link
						if (styleLink)
						{
							sb.Append("<a href=\"");
							sb.Append(url);
							sb.Append("\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						sb.Append(getObjectName(b.FriendlyName, app, styleSnip));
						if (styleLink)
							sb.Append("</a>");
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "photo")
					{
						#region Photo
						Photo p = new Photo(int.Parse(refAtt));
						string url = getObectPageUrl(p, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Link
						if (styleLink)
						{
							sb.Append("<a href=\"");
							sb.Append(url);
							sb.Append("\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						#endregion

						if (app != null && app == "chat")
						{
							#region For chat app, just show the name of the parent...
							sb.Append(Cambro.Misc.Utility.Snip(((IName)p.ParentObject).Name, styleSnip) + " (chat)");
							#endregion
						}
						else
						{
							#region Image tag
							sb.Append("<img");

							#region Src attribute
							sb.Append(" src=\"");
							if (stylePhoto == "thumb")
								sb.Append(p.ThumbPath);
							else if (stylePhoto == "icon")
								sb.Append(p.IconPath);
							else if (stylePhoto == "web")
								sb.Append(p.WebPath);
							sb.Append("\"");
							#endregion

							#region Width attribute
							if (styleLink || !attributes.ContainsKey("width"))
							{
								sb.Append(" width=\"");
								if (stylePhoto == "thumb")
									sb.Append(p.ThumbWidth);
								else if (stylePhoto == "icon")
									sb.Append("100");
								else if (stylePhoto == "web")
									sb.Append(p.WebWidth);
								sb.Append("\"");
							}
							#endregion

							#region Height attribute
							if (styleLink || !attributes.ContainsKey("height"))
							{
								sb.Append(" height=\"");
								if (stylePhoto == "thumb")
									sb.Append(p.ThumbHeight);
								else if (stylePhoto == "icon")
									sb.Append("100");
								else if (stylePhoto == "web")
									sb.Append(p.WebHeight);
								sb.Append("\"");
							}
							#endregion

							#region Extra html attributes
							if (!styleLink)
							{
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
							}
							#endregion

							#region Style attribute
							if (styleLink)
							{
								
								sb.Append(" class=\"BorderBlack All\"");
							}
							else if (style.ContainsKey("border"))
							{
								sb.Append(extraClassAttribute);
							}
							else
							{
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
							}
							#endregion

							#region Rollover
							if (styleRollover && stylePhoto != "web")
							{
								sb.Append(" onmouseover=\"stm('<img src=" + p.WebPath + " width=" + p.WebWidth + " height=" + p.WebHeight + " class=Block />');\" onmouseout=\"htm();\"");
							}
							#endregion

							sb.Append(" />");
							#endregion
						}

						#region End link
						if (styleLink)
							sb.Append("</a>");
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "misc")
					{
						#region Misc
						Misc mi = new Misc(int.Parse(refAtt));

						if (tagName == "dsi:link")
							return "<a href=\"" + mi.Url() + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						if (mi.Extention.ToLower() == "jpg" || mi.Extention.ToLower() == "jpeg" || mi.Extention.ToLower() == "gif" || mi.Extention.ToLower() == "png")
						{
							StringBuilder sb = new StringBuilder();

							#region Width and height
							int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : mi.Width;
							int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : mi.Height;
							#endregion

							#region Image tag
							sb.Append("<img src=\"");
							sb.Append(mi.Url());
							sb.Append("\" width=\"");
							sb.Append(width);
							sb.Append("\" height=\"");
							sb.Append(height);
							sb.Append("\" border=\"0\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(" />");
							#endregion

							return sb.ToString();

						}
						else if (mi.Extention.ToLower() == "swf")
						{
							#region Swf
							return getFlashAttributesFromSgml(uniqueId, mi.Url(), attributes);
							#endregion
						}
						#endregion
					}
					else if (typeAtt == "article")
					{
						#region Article
						Article a = new Article(int.Parse(refAtt));
						string url = getObectPageUrl(a, app, date, par) + jump;

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						#region Article link
						if (styleLink)
						{
							sb.Append("<a href=\"");
							sb.Append(url);
							sb.Append("\"");
							sb.Append(extraHtmlAttributes);
							sb.Append(extraStyleAttribute);
							sb.Append(extraClassAttribute);
							sb.Append(">");
						}
						sb.Append(getObjectName(a.FriendlyName, app, styleSnip));
						if (styleLink)
							sb.Append("</a>");
						#endregion

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "url") //if (attributes.ContainsKey("href"))
					{
						#region Url
						string url = attributes.ContainsKey("href") ? attributes["href"] : "";
						#region Get name
						string name = url;
						string path = url;
						string domain = url;
						string targetAttribute = "";
						try
						{
							if (UrlRegex.IsMatch(url))
							{
								Match urlMatch = UrlRegex.Match(url);
								if (urlMatch.Groups[3].Value.StartsWith("www."))
									name = urlMatch.Groups[3].Value.Substring(4);
								else
									name = urlMatch.Groups[3].Value;

								domain = urlMatch.Groups[3].Value;
								path = urlMatch.Groups[4].Value;
								if (!domain.ToLower().EndsWith(".dontstayin.com") && !attributes.ContainsKey("target"))
									targetAttribute = " target=\"_blank\"";

							}
						}
						catch
						{ }
						#endregion

						if (tagName == "dsi:link")
							return "<a href=\"" + url + "\"" + targetAttribute + extraHtmlAttributes + extraStyleAttribute + extraClassAttribute + ">";

						StringBuilder sb = new StringBuilder();

						if (path.ToLower().EndsWith(".jpg") || path.ToLower().EndsWith(".jpeg") || path.ToLower().EndsWith(".gif") || path.ToLower().EndsWith(".png"))
						{
							#region Image tag
							sb.Append("<img");

							#region Src attribute
							sb.Append(" src=\"");
							sb.Append(url);
							sb.Append("\"");
							#endregion

							sb.Append(extraHtmlAttributes);

							#region Style attribute
							if (domain.EndsWith(".dontstayin.com") && !style.ContainsKey("border"))
							{
								sb.Append(" class=\"BorderBlack All" + extraClassElements + "\"");
							}
							else
							{
								sb.Append(extraClassAttribute);
							}
							#endregion

							sb.Append(extraStyleAttribute);

							sb.Append(" />");
							#endregion
						}
						else if (path.ToLower().EndsWith(".mp3") || path.ToLower().EndsWith(".wav"))
						{
							#region Audio
							int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 290;
							int height = attributes.ContainsKey("height") ? int.Parse(attributes["height"]) : 24;
							string audioPlayerSwfPath = Storage.Path(new Guid("7abb3119-f8ad-43ff-be01-764b2ae111fc"), "swf", Storage.Stores.Pix);
							return GetFlash(uniqueId, height, width, false, "load", audioPlayerSwfPath, "soundFile", url, "autoStart", "no") +
								@"<a href=""" + url + @"""><img src=""/gfx/download-button2.png"" width=""73"" height=""16"" border=""0"" /></a>";
							#endregion
						}
						else if (path.ToLower().EndsWith(".swf"))
						{
							#region Swf
							return getFlashAttributesFromSgml(uniqueId, path, attributes);
							#endregion
						}
						else if (path.ToLower().EndsWith(".flv"))
						{
							#region Flv
							int width = attributes.ContainsKey("width") ? int.Parse(attributes["width"]) : 450;
							int height = attributes.ContainsKey("height") ? (int.Parse(attributes["height"]) + 20) : 357;
							bool nsfw = attributes.ContainsKey("nsfw") ? bool.Parse(attributes["nsfw"].ToLower()) : false;
							string draw = attributes.ContainsKey("draw") ? attributes["draw"].ToLower() : "auto";
							return GetFlash(uniqueId, height, width, nsfw, draw, "/misc/flvplayer.swf", "file", url, "autoStart", "0");
							#endregion
						}
						else
						{
							#region Link
							if (styleLink)
							{
								sb.Append("<a href=\"");
								sb.Append(url);
								sb.Append("\"");
								sb.Append(targetAttribute);
								sb.Append(extraHtmlAttributes);
								sb.Append(extraStyleAttribute);
								sb.Append(extraClassAttribute);
								sb.Append(">");
							}
							#endregion
							#region Name
							sb.Append(name);
							#endregion
							#region End link
							if (styleLink)
								sb.Append("</a>");
							#endregion
						}

						return sb.ToString();

						#endregion
					}
					else if (typeAtt == "room")
					{
						#region Chat room
						Guid guid = refAtt.UnPackGuid();
						Chat.RoomSpec room = Chat.RoomSpec.FromGuid(guid);

						if (room == null)
							return "[Room not found]";
						
						StringBuilder sb = new StringBuilder();
						
						if (tagName == "dsi:link")
							room.LinkHtmlAppendJustStartOfAnchorTag(sb, "selected-onyellow", extraHtmlAttributes, extraStyleAttribute, extraClassAttribute);
						else
							room.LinkHtmlAppend(sb, "selected-onyellow", extraHtmlAttributes, extraStyleAttribute, extraClassAttribute);

						return sb.ToString();

						#endregion
					}
					#endregion
				}
				return "[Invalid tag " + tagName + "]";
			}
			catch (Exception ex)
			{
				if (Vars.DevEnv)
					throw ex;

				return "[Error in " + tagName + " tag]";
			}
		}
Esempio n. 2
0
		public void DeleteAll(Transaction transaction)
		{
			if (!this.Bob.DbRecordExists)
				return;

			//Events
			EventSet es = new EventSet(new Query(new Q(Event.Columns.VenueK,this.K)));
			foreach(Event e in es)
				e.DeleteAll(transaction);

			
			Delete CommentAlertDelete = new Delete(
				TablesEnum.CommentAlert,
				new And(
				new Q(CommentAlert.Columns.ParentObjectK,this.K),
				new Q(CommentAlert.Columns.ParentObjectType,Model.Entities.ObjectType.Venue)
				)
				);
			CommentAlertDelete.Run(transaction);
			
			//Threads
			ThreadSet ts = new ThreadSet(
				new Query(
					new And(
						new Q(Thread.Columns.ParentObjectType,Model.Entities.ObjectType.Venue),
						new Q(Thread.Columns.ParentObjectK,this.K)
					)
				)
			);
			foreach (Thread t in ts)
				t.DeleteAll(transaction);

			//Articles
			ArticleSet ars = new ArticleSet(new Query(new Q(Article.Columns.VenueK, this.K)));
			foreach (Article a in ars)
				a.DeleteAll(transaction);


			Guid oldPic = this.HasPic ? this.Pic : Guid.Empty;
			int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0;

			this.Delete(transaction);

			if (oldPic != Guid.Empty)
				Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg");

			if (oldPicMiscK > 0)
			{
				Misc m = new Misc(oldPicMiscK);
				m.DeleteAll(transaction);
			}

			this.Place.UpdateTotalEvents(transaction);

			
		}
		public void FileAssign_Next(object o, System.EventArgs e)
		{
			if (FileAssignDropDown.Items.Count == 0)
			{
				Response.Redirect(CurrentPromoter.UrlApp("files", "mode", "upload"));
			}
			else
			{
				Bobs.Misc m = new Bobs.Misc(int.Parse(FileAssignDropDown.SelectedValue));

				Banner.AssignReturns assignReturn = CurrentBanner.AssignMisc(m);

				if (assignReturn.Equals(Banner.AssignReturns.CanUseNow) || assignReturn.Equals(Banner.AssignReturns.WaitingForCheck))
					RedirectEdit();
				else if (assignReturn.Equals(Banner.AssignReturns.Failed))
					throw new DsiUserFriendlyException("File assign failed!");
			}
		}
Esempio n. 4
0
		public void DeleteAll(Transaction transaction)
		{
			if (!this.Bob.DbRecordExists)
				return;
			
			if (this.ThreadK > 0)
				this.Thread.DeleteAll(transaction);


			foreach (Thread t in this.Threads)
				t.DeleteAll(transaction);

			foreach (Para p in this.AllPara)
				p.DeleteAll(transaction);


			GallerySet gs = new GallerySet(new Query(new Q(Gallery.Columns.ArticleK,this.K)));
			foreach (Gallery g in gs)
				g.DeleteAll(transaction);

			Guid oldPic = this.HasPic ? this.Pic : Guid.Empty;
			int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0;

			this.Delete(transaction);

			if (oldPic != Guid.Empty)
				Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg");

			if (oldPicMiscK > 0)
			{
				Misc m = new Misc(oldPicMiscK);
				m.DeleteAll(transaction);
			}
		}
Esempio n. 5
0
		protected void UploadNow_Click(object sender, EventArgs eventArgs)
		{

			if (InputFile.PostedFile != null)
			{

				#region Upload file
				Bobs.Misc m = new Bobs.Misc();

				m.UsrK = Usr.Current.K;

				if (CurrentPromoter != null)
					m.PromoterK = CurrentPromoter.K;

				m.DateTime = DateTime.Now;
				m.Folder = CurrentFolder;

				m.Guid = Guid.NewGuid();

				if (InputFile.PostedFile.FileName.IndexOf(".") == -1)
					m.Extention = "";
				else
					m.Extention = InputFile.PostedFile.FileName.Substring(InputFile.PostedFile.FileName.LastIndexOf(".") + 1).ToLower();

				if (m.Extention.Equals("jpeg") || m.Extention.Equals("jpe"))
					m.Extention = "jpg";

				if (!(m.Extention.Equals("jpg") ||
					m.Extention.Equals("gif") ||
					m.Extention.Equals("png") ||
					m.Extention.Equals("flv") ||
					m.Extention.Equals("mp4") ||
					(Usr.Current.IsAdmin && m.Extention.Equals("zip")) ||
					m.Extention.Equals("swf")))
					throw new DsiUserFriendlyException("You can only upload gif, jpg, png, flv or swf files with this page.");

				m.Size = InputFile.PostedFile.ContentLength;
				m.Name = InputFile.PostedFile.FileName.Substring(InputFile.PostedFile.FileName.LastIndexOf("\\") + 1);

				byte[] bytes = new byte[InputFile.PostedFile.InputStream.Length];
				InputFile.PostedFile.InputStream.Read(bytes, 0, (int)InputFile.PostedFile.InputStream.Length);

				if (m.Extention.Equals("jpg") || m.Extention.Equals("gif") || m.Extention.Equals("png"))
				{
					using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bytes)))
					{
						m.Width = image.Width;
						m.Height = image.Height;
					}
				}

				if (CurrentPromoter != null)
				{
					if (m.Extention.Equals("swf"))
					{
                        if (m.Size <= 150 * 1024)
							m.NeedsAuth = true;
					}
				}

				m.Update();
				try
				{
					Storage.AddToStore(bytes, Storage.Stores.Pix, m.Guid, m.Extention, m, "");
				}
				catch
				{
					m.Delete();
				}

				
				if (m.NeedsAuth)
				{
					Mailer adminMail = new Mailer();
					adminMail.Subject = "New files waiting to be approved!!! uploaded by" + Usr.Current.NickNameSafe;
					adminMail.To = "*****@*****.**";
					adminMail.Body += "<p>New FILES uploaded by <a href=\"[LOGIN(" + Usr.Current.Url() + ")]\">" + Usr.Current.NickNameSafe + "</a></p>";
					if (CurrentPromoter != null)
						adminMail.Body += "<p>... for promoter <a href=\"[LOGIN(" + CurrentPromoter.Url() + ")]\">" + CurrentPromoter.Name + "</a></p>";
					adminMail.Body += "<h2>Files:</h2>";
					adminMail.Body += "<p><a href=\"" + m.Url() + "\">" + HttpUtility.HtmlEncode(m.Name) + "</a> - " + m.FileSizeString + "</p>";
					adminMail.TemplateType = Mailer.TemplateTypes.AdminNote;
					adminMail.RedirectUrl = Usr.Current.Url();
					adminMail.Send();
				}
				if (CurrentBanner != null)
					CurrentBanner.AssignMisc(m);

				#endregion

				if (CurrentBanner != null)
					Response.Redirect(CurrentBanner.Url());
				else
					Response.Redirect(ContainerPage.Url.CurrentUrl("mode","view","misck",m.K));

			}
		
		}
Esempio n. 6
0
		protected void UploadCssButton_Click(object sender, EventArgs eventArgs)
		{
			cssFile = Misc.UploadFile(InputCssFile, Usr.Current);
			CssUrlHiddenTextBox.Text = cssFile != null ? cssFile.Url() : "";
		}
Esempio n. 7
0
		private static void SetAndCheckWidthAndHeight(Misc m, byte[] bytes)
		{
			using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bytes)))
			{
				m.Width = image.Width;
				m.Height = image.Height;
			}
		}
Esempio n. 8
0
		protected void UploadBackgroundButton_Click(object sender, EventArgs eventArgs)
		{
			backgroundFile = Misc.UploadFile(InputBackgroundFile, Usr.Current, CurrentPromoter, new List<string>() { "jpg", "gif", "png" });
			BackgroundUrlHiddenTextBox.Text = backgroundFile != null ? backgroundFile.Url() : "";
		}
Esempio n. 9
0
		private Misc SaveMisc()
		{
			Misc m = new Misc();

			if (uiInputFile.PostedFile.FileName.Length == 0)
				return m;

			m.Guid = Guid.NewGuid();

			SetAndCheckExtension(m);

			m.UsrK = Usr.Current.K;
			m.PromoterK = int.Parse(uiPromotersAutoComplete.Value);
			m.DateTime = DateTime.Now;
			m.Size = uiInputFile.PostedFile.ContentLength;
			m.Name = uiInputFile.PostedFile.FileName.Substring(uiInputFile.PostedFile.FileName.LastIndexOf("\\") + 1);

			byte[] bytes = new byte[uiInputFile.PostedFile.InputStream.Length];
			uiInputFile.PostedFile.InputStream.Read(bytes, 0, (int)uiInputFile.PostedFile.InputStream.Length);

			SetAndCheckWidthAndHeight(m, bytes);

			m.Update();

			try
			{
				Storage.AddToStore(bytes, Storage.Stores.Pix, m.Guid, m.Extention, m, "");
			}
			catch (Exception ex)
			{
				m.Delete();
				throw ex;
			}

			return m;

		}
Esempio n. 10
0
		private void SetAndCheckExtension(Misc m)
		{
			if (uiInputFile.PostedFile.FileName.IndexOf(".") == -1)
				m.Extention = "";
			else
				m.Extention = uiInputFile.PostedFile.FileName.Substring(uiInputFile.PostedFile.FileName.LastIndexOf(".") + 1).ToLower();

			if (m.Extention.Equals("jpeg") || m.Extention.Equals("jpe"))
				m.Extention = "jpg";

			if (!(m.Extention.Equals("jpg") || m.Extention.Equals("gif")))
				throw new DsiUserFriendlyException("You can only upload gif or jpg files with this page.");
		}
Esempio n. 11
0
		public void DeleteImage(object o, System.EventArgs e)
		{

			if (!CurrentPic.Pic.Equals(Guid.Empty))
			{
				Guid oldPic = CurrentPic.Pic;
				int oldPicMiscK = CurrentPic.PicMisc != null ? CurrentPic.PicMiscK : 0;

				CurrentPic.Pic = Guid.Empty;
				CurrentPic.PicMiscK = 0;
				CurrentPic.PicPhotoK = 0;
				CurrentPic.PicState = "";
				CurrentBob.Update();

				if (oldPic != Guid.Empty)
					Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg");

				if (oldPicMiscK > 0)
				{
					Misc oldMisc = new Misc(oldPicMiscK);
					oldMisc.DeleteAll(null);
				}
			}

			BindPicDisplay();
			if (CurrentBob is IPage)
				Response.Redirect(((IPage)CurrentBob).Url());
		}
Esempio n. 12
0
		public void DeleteImageClick(object o, System.EventArgs e)
		{
			if (!ThisPic.Pic.Equals(Guid.Empty))
			{
				Guid oldPic = ThisPic.Pic;
				int oldPicMiscK = ThisPic.PicMisc != null ? ThisPic.PicMiscK : 0;

				ThisPic.Pic = Guid.Empty;
				ThisPic.PicMiscK = 0;
				ThisPic.PicPhotoK = 0;
				ThisPic.PicState = "";
				ThisBob.Update();

				if (oldPic != Guid.Empty)
					Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg");

				if (oldPicMiscK > 0)
				{
					Misc oldMisc = new Misc(oldPicMiscK);
					oldMisc.DeleteAll(null);
				}
			}

			if (ActionDeleted != null)
				ActionDeleted(this, EventArgs.Empty);

			ChangePanel(NoPicPanel);

		}
Esempio n. 13
0
		void UpdateChoice()
		{
			if (FileAssignDropDown.Items.Count > 0)
			{
				FileAssignPreview.Controls.Clear();
				FileAssignPreviewDiv.Visible = true;
				Bobs.Misc m = new Bobs.Misc(int.Parse(FileAssignDropDown.SelectedValue));

				bool waiting = m.CanUseAsBanner(CurrentBanner.Position).CanUseAfterAdminCheck;
				FileWaitingForCheckP.Visible = waiting;
				FileCheckedP.Visible = !waiting;

				if (m.Extention.Equals("swf"))
				{
					Spotted.Controls.Banners.FlashBanner banner = (Spotted.Controls.Banners.FlashBanner)this.LoadControl("/Controls/Banners/FlashBanner.ascx");
					banner.ShowClickHelper = false;
					banner.BannerUrl = m.Url();
					banner.LinkUrl = "http://www.google.com/";
					banner.LinkTargetBlank = true;
					if (CurrentBanner.Position.Equals(Banner.Positions.Leaderboard))
					{
						banner.Width = 728;
						banner.Height = 90;
					}
					else if (CurrentBanner.Position.Equals(Banner.Positions.Hotbox))
					{
						banner.Width = 300;
						banner.Height = 250;
					}
					else if (CurrentBanner.Position.Equals(Banner.Positions.Skyscraper))
					{
						//XMAS
						banner.Width = 300;
						banner.Height = 250;//600
					}
					else if (CurrentBanner.Position.Equals(Banner.Positions.PhotoBanner))
					{
						banner.Width = 450;
						banner.Height = 50;
					}
					banner.DataBind();
					FileAssignPreview.Controls.Add(banner);
					FileAssignDiv.Style["width"] = ((int)(banner.Width + 2)).ToString() + "px";
					FileAssignDiv.Style["height"] = ((int)(banner.Height + 2)).ToString() + "px";
				}
				else if (m.Extention.Equals("gif") || m.Extention.Equals("jpg"))
				{
					Spotted.Controls.Banners.ImageBanner banner = (Spotted.Controls.Banners.ImageBanner)this.LoadControl("/Controls/Banners/ImageBanner.ascx");
					banner.BannerUrl = m.Url();
					banner.LinkUrl = "http://www.google.com/";
					banner.LinkTargetBlank = true;
					if (CurrentBanner.Position.Equals(Banner.Positions.Leaderboard))
					{
						banner.Width = 728;
						banner.Height = 90;
					}
					else if (CurrentBanner.Position.Equals(Banner.Positions.Hotbox))
					{
						banner.Width = 300;
						banner.Height = 250;
						if (m.Width == 191 && m.Height == 191)
						{
							banner.Width = 191;
							banner.Height = 191;
						}
					}
					else if (CurrentBanner.Position.Equals(Banner.Positions.Skyscraper))
					{
						//XMAS
						banner.Width = 300;
						banner.Height = 250;//600;
					}
					else if (CurrentBanner.Position.Equals(Banner.Positions.PhotoBanner))
					{
						banner.Width = 450;
						banner.Height = 50;
					}
					else if (CurrentBanner.Position.Equals(Banner.Positions.EmailBanner))
					{
						banner.Width = 331;
						banner.Height = 51;
					}
					banner.DataBind();
					FileAssignPreview.Controls.Add(banner);
					FileAssignDiv.Style["width"] = ((int)(banner.Width + 2)).ToString() + "px";
					FileAssignDiv.Style["height"] = ((int)(banner.Height + 2)).ToString() + "px";
				}
				
			}
			else
			{
				FileAssignPreviewDiv.Visible = false;
			}
			if (CurrentBanner.Position.Equals(Banner.Positions.Leaderboard))
				FileAssignPreviewDiv.Style["padding-bottom"] = "35px;";
			else
				FileAssignPreviewDiv.Style.Remove("padding-bottom");
		}
Esempio n. 14
0
		protected void UploadLogoButton_Click(object sender, EventArgs eventArgs)
		{
			logoFile = Misc.UploadFile(InputLogoFile, Usr.Current, CurrentPromoter, new List<string>(){ "jpg", "gif", "png" });
			LogoUrlHiddenTextBox.Text = logoFile != null ? "div.MainImage{background-image: url('" + logoFile.Url() + "'); height: " + logoFile.Height.ToString() + "px;}" : "";
		}
Esempio n. 15
0
		public Misc Duplicate()
		{
			Misc m = new Misc();
			m.Guid = Guid.NewGuid();
			m.Extention = this.Extention;
			m.Update();
			try
			{
				Storage.AddToStore(
					Storage.GetFromStore(Storage.Stores.Pix, this.Guid, this.Extention),
					Storage.Stores.Pix,
					m.Guid,
					m.Extention,
					m,
					"");
				m.UsrK = this.UsrK;
				m.PromoterK = this.PromoterK;
				m.Size = this.Size;
				m.DateTime = this.DateTime;
				m.DateTimeExpires = this.DateTimeExpires;
				m.Folder = this.Folder;
				m.Name = this.Name;
				m.Note = this.Note;
				m.Xml = this.Xml;
				m.NeedsAuth = this.NeedsAuth;
				m.BannerLinkTag = this.BannerLinkTag;
				m.BannerBroken = this.BannerBroken;
				m.BannerBrokenReason = this.BannerBrokenReason;
				m.Width = this.Width;
				m.Height = this.Height;
				m.Update();
				return m;
			}
			catch (Exception ex)
			{
				m.Delete();
				throw ex;
			}

		}
Esempio n. 16
0
		protected void UploadCssButton_Click(object sender, EventArgs eventArgs)
		{
			cssFile = Misc.UploadFile(InputCssFile, Usr.Current, CurrentPromoter, new List<string>() { "css" });
			CssUrlHiddenTextBox.Text = cssFile != null ? cssFile.Url() : "";
		}
Esempio n. 17
0
		public static Misc UploadFile(HtmlInputFile inputFile, Usr uploadUsr, Promoter promoter, Banner banner, string folder, List<string> acceptedFileExtensions)
		{
			if (inputFile.PostedFile != null)
			{
				#region Upload file
				Misc m = new Misc();

				m.UsrK = uploadUsr.K;

				if (promoter != null)
					m.PromoterK = promoter.K;

				m.DateTime = DateTime.Now;
				m.Folder = folder;

				m.Guid = Guid.NewGuid();


				if (inputFile.PostedFile.FileName.IndexOf(".") == -1)
					m.Extention = "";
				else
					m.Extention = inputFile.PostedFile.FileName.Substring(inputFile.PostedFile.FileName.LastIndexOf(".") + 1).ToLower();

				if (m.Extention.Equals("jpeg") || m.Extention.Equals("jpe"))
					m.Extention = "jpg";

				if (!acceptedFileExtensions.Contains(m.Extention))
				{
					string listOfFileExtensions = "";
					foreach(string s in acceptedFileExtensions)
						listOfFileExtensions += s + ", ";
					throw new DsiUserFriendlyException("You can only upload " + listOfFileExtensions.Substring(0, listOfFileExtensions.Length-2) + " files with this page.");
				}

				if (promoter != null && m.Extention.Equals("swf"))
				{
					if (m.Size <= 150 * 1024)
						m.NeedsAuth = true;
				}
				
				byte[] bytes = new byte[inputFile.PostedFile.InputStream.Length];
				inputFile.PostedFile.InputStream.Read(bytes, 0, (int)inputFile.PostedFile.InputStream.Length);
				
				m.Size = inputFile.PostedFile.ContentLength;

				m.Name = inputFile.PostedFile.FileName.Substring(inputFile.PostedFile.FileName.LastIndexOf("\\") + 1);

				if (m.Extention.Equals("jpg") || m.Extention.Equals("gif") || m.Extention.Equals("png"))
				{
					using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bytes)))
					{
						m.Width = image.Width;
						m.Height = image.Height;
					}
				}

				m.Update();

				try
				{
					Storage.AddToStore(bytes, Storage.Stores.Pix, m.Guid, m.Extention, m, "");
				}
				catch (Exception ex)
				{
					m.Delete();
					throw ex;
				}

				if (promoter != null)
				{
					if (promoter != null && m.NeedsAuth)
					{
						Mailer adminMail = new Mailer();
						adminMail.Subject = "New files waiting to be approved!!! uploaded by" + uploadUsr.NickNameSafe;
						adminMail.To = "*****@*****.**";
						adminMail.Body += "<p>New FILES uploaded by <a href=\"[LOGIN(" + uploadUsr.Url() + ")]\">" + uploadUsr.NickNameSafe + "</a></p>";
						if (promoter != null)
							adminMail.Body += "<p>... for promoter <a href=\"[LOGIN(" + promoter.Url() + ")]\">" + promoter.Name + "</a></p>";
						adminMail.Body += "<h2>Files:</h2>";
						adminMail.Body += "<p><a href=\"" + m.Url() + "\">" + HttpUtility.HtmlEncode(m.Name) + "</a> - " + m.FileSizeString + "</p>";
						adminMail.TemplateType = Mailer.TemplateTypes.AdminNote;
						adminMail.RedirectUrl = uploadUsr.Url();
						adminMail.Send();
					}
				}

				if (banner != null)
					banner.AssignMisc(m);

				return m;

				#endregion
			}
			else
				return null;
		}
Esempio n. 18
0
		public void DeleteAll(Transaction transaction)
		{
			if (!this.Bob.DbRecordExists)
				return;

			//EventBrands
			Delete BrandDelete = new Delete(
				TablesEnum.EventBrand,
				new Q(EventBrand.Columns.BrandK, this.K)
				);
			BrandDelete.Run(transaction);

			CompSet cs = new CompSet(new Query(new Q(Comp.Columns.BrandK, this.K)));
			foreach (Comp c in cs)
			{
				c.BrandK = 0;
				c.LinkType = Comp.LinkTypes.None;
				c.Update();
			}

			try
			{
				this.Group.DeleteAll(transaction);
			}
			catch { }

			Guid oldPic = this.HasPic ? this.Pic : Guid.Empty;
			int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0;

			this.Delete(transaction);

			if (oldPic != Guid.Empty)
				Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg");

			if (oldPicMiscK > 0)
			{
				Misc m = new Misc(oldPicMiscK);
				m.DeleteAll(transaction);
			}
		}
Esempio n. 19
0
		public void Upload(object o, System.EventArgs e)
		{
			if (Pic == null)
				throw new Exception("No Pic!!!");
			if (InputFile.PostedFile != null && InputFile.PostedFile.ContentLength > 0)
			{
				if (Photo.GetMediaType(InputFile.PostedFile.FileName).Equals(Photo.MediaTypes.Image))
				{
				//	byte[] uploadedFileBytes = new byte[InputFile.PostedFile.InputStream.Length];
				//	InputFile.PostedFile.InputStream.Read(uploadedFileBytes, 0, (int)InputFile.PostedFile.InputStream.Length);

					//using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(uploadedFileBytes)))
					using (System.Drawing.Image image = System.Drawing.Image.FromStream(InputFile.PostedFile.InputStream))
					{
						if (image.Height < 100 || image.Width < 100)
						{
							throw new Bobs.DsiUserFriendlyException("Image is too small - it must be at least 100x100 pixels.");
						}
						else if (image.Height == 100 && image.Width == 100)
						{
							//save file straight away.
							if (!Pic.HasPic)
								Pic.Pic = Guid.NewGuid();

							int oldMiscK = Pic.PicMisc != null ? Pic.PicMiscK : 0;
							
							
							Pic.PicState = "";
							Pic.PicMiscK = 0;

							Storage.AddToStore(
								Photo.SaveJPGWithCompressionSetting(image, (long)85.0),
								Storage.Stores.Pix,
								Pic.Pic,
								"jpg",
								(IBob)Pic,
								"Pic");

							((IBob)Pic).Update();

							if (oldMiscK > 0)
							{
								Misc oldMisc = new Misc(oldMiscK);
								oldMisc.DeleteAll(null);
							}

							if (Saved != null)
								Saved(this, new EventArgs());

							return;

						}
						else
						{
							bool newMisc = false;
							Bobs.Misc m = null;
							if (Pic.PicMisc == null)
							{
								m = new Bobs.Misc();
								newMisc = true;
							}
							else
							{
								m = Pic.PicMisc;
							}

							m.Extention = "jpg";

							bool deletePreviousFile = false;
							Guid previousFile = Guid.Empty;
							if (!m.Guid.Equals(Guid.Empty))
							{
								deletePreviousFile = true;
								previousFile = m.Guid;
							}

							m.Guid = Guid.NewGuid();

							byte[] bytes = null;
							if (image.Height > 1000 || image.Width > 1000)
							{
								Photo.OperationReturn operation = Photo.Operation(image, Photo.OperationType.MaxSide, new Photo.OperationParams() { MaxSide = 1000, ReturnBytes = true, AllowMaxSideToEnlarge = true });
								m.Width = operation.ImageSize.Width;
								m.Height = operation.ImageSize.Height;
								bytes = operation.Bytes;
							}
							else
							{
								bytes = Photo.SaveJPGWithCompressionSetting(image, (long)85.0);
								m.Width = image.Width;
								m.Height = image.Height;
							}
							
							if (newMisc)
								m.Update();

							try
							{
								Storage.AddToStore(bytes, Storage.Stores.Pix, m.Guid, m.Extention, m, "");
							}
							catch(Exception ex)
							{
								if (newMisc)
								{
									m.Delete();
								}
								throw ex;
							}

							m.Size = bytes.Length;
							m.UsrK = Usr.Current.K;
							m.PromoterK = 0;
							m.DateTime = DateTime.Now;
							m.DateTimeExpires = DateTime.Now.AddHours(1);
							m.Name = InputFile.PostedFile.FileName.ToLower();

							m.Update();

							if (Pic.PicMiscK != m.K)
							{
								Pic.PicMiscK = m.K;
								((IBob)Pic).Update();
							}
							
							if (deletePreviousFile)
								Storage.RemoveFromStore(Storage.Stores.Pix, previousFile, "jpg");

							Cropper.ImageUrl = m.Url();
							Cropper.ImageGuid = m.Guid;
							Cropper.ImageStore = Storage.Stores.Pix;
							SaveButton.Visible = true;
							Cropper.Visible = true;
							JpgErrorPanel.Visible = false;

						}
					}
				}
				else
				{
					JpgErrorPanel.Visible = true;
				}
			}

		}
Esempio n. 20
0
		protected void UploadLogoButton_Click(object sender, EventArgs eventArgs)
		{
			logoFile = Misc.UploadFile(InputLogoFile, Usr.Current);
			LogoUrlHiddenTextBox.Text = logoFile != null ? logoFile.Url() : "";
		}
Esempio n. 21
0
		public void DeleteAll(Transaction transaction)
		{
			if (!this.Bob.DbRecordExists)
				return;

			if (this.ThreadK>0)
				this.Thread.DeleteAll(transaction);

			Guid oldPic = this.HasPic ? this.Pic : Guid.Empty;
			int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0;

			this.Delete(transaction);

			if (oldPic != Guid.Empty)
				Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg");

			if (oldPicMiscK > 0)
			{
				Misc m = new Misc(oldPicMiscK);
				m.DeleteAll(transaction);
			}

		}
Esempio n. 22
0
		protected void UploadBackgroundButton_Click(object sender, EventArgs eventArgs)
		{
			backgroundFile = Misc.UploadFile(InputBackgroundFile, Usr.Current);
			BackgroundUrlHiddenTextBox.Text = backgroundFile != null ? backgroundFile.Url() : "";
		}
Esempio n. 23
0
		public void DeleteAll(Transaction transaction)
		{
			
			if (!this.Bob.DbRecordExists)
				return;

			//GroupUsrs
			Delete GroupUsrDelete = new Delete(
				TablesEnum.GroupUsr,
				new Q(GroupUsr.Columns.GroupK, this.K)
				);
			GroupUsrDelete.Run(transaction);

			//GroupUsrs
			Delete GroupPhotoDelete = new Delete(
				TablesEnum.GroupPhoto,
				new Q(GroupPhoto.Columns.GroupK, this.K)
				);
			GroupPhotoDelete.Run(transaction);

			//GroupEvents
			Delete GroupEventDelete = new Delete(
				TablesEnum.GroupEvent,
				new Q(GroupEvent.Columns.GroupK, this.K)
			);
			GroupEventDelete.Run(transaction);

			ThreadSet ts = new ThreadSet(new Query(new Q(Thread.Columns.GroupK,this.K)));
			foreach (Thread t in ts)
				t.DeleteAll(transaction);

			Guid oldPic = this.HasPic ? this.Pic : Guid.Empty;
			int oldPicMiscK = this.PicMisc != null ? this.PicMiscK : 0;

			this.Delete(transaction);

			if (oldPic != Guid.Empty)
				Storage.RemoveFromStore(Storage.Stores.Pix, oldPic, "jpg");

			if (oldPicMiscK > 0)
			{
				Misc m = new Misc(oldPicMiscK);
				m.DeleteAll(transaction);
			}
		}