| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using System.Web;
|
|---|
| 5 | using System.Web.Mvc;
|
|---|
| 6 | using System.Web.Routing;
|
|---|
| 7 | using System.Configuration;
|
|---|
| 8 |
|
|---|
| 9 | namespace Platnosci.Helpers
|
|---|
| 10 | {
|
|---|
| 11 | public static class helper
|
|---|
| 12 | {
|
|---|
| 13 | public static string ImageTag(this HtmlHelper helper, string src, string alt)
|
|---|
| 14 | {
|
|---|
| 15 | TagBuilder tb = new TagBuilder("img");
|
|---|
| 16 | tb.Attributes.Add("src", helper.Encode(src));
|
|---|
| 17 | tb.Attributes.Add("alt", helper.Encode(alt));
|
|---|
| 18 | return tb.ToString(TagRenderMode.SelfClosing);
|
|---|
| 19 | }
|
|---|
| 20 | public static string ImageLink(this HtmlHelper htmlHelper, string filename, string alt, string querystring)
|
|---|
| 21 | {
|
|---|
| 22 |
|
|---|
| 23 | var action = htmlHelper.CurrentAction();
|
|---|
| 24 | var controller = htmlHelper.CurrentController();
|
|---|
| 25 |
|
|---|
| 26 | UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url;
|
|---|
| 27 | string src = urlHelper.UrlImage(filename);
|
|---|
| 28 | string imgtag = htmlHelper.ImageTag(src, alt);
|
|---|
| 29 |
|
|---|
| 30 | RouteValueDictionary tab = new RouteValueDictionary();
|
|---|
| 31 |
|
|---|
| 32 | string id = "";
|
|---|
| 33 | if (htmlHelper.ViewContext.RouteData.Values["id"] != null) id = htmlHelper.ViewContext.RouteData.Values["id"].ToString();
|
|---|
| 34 | tab.Add("language", alt);
|
|---|
| 35 | if (id != null) tab.Add("id", id);
|
|---|
| 36 |
|
|---|
| 37 | string url = urlHelper.Action(action, controller, tab);
|
|---|
| 38 |
|
|---|
| 39 | string[] param = querystring.ToString().Split(("&").ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
|---|
| 40 | for (int i = 0; i < param.Length; i++ )
|
|---|
| 41 | {
|
|---|
| 42 | if (i == 0 ) url += "?" + param[i];
|
|---|
| 43 | else url += "&" + param[i];
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | TagBuilder link = new TagBuilder("a");
|
|---|
| 47 | link.Attributes.Add("href", url);
|
|---|
| 48 | link.InnerHtml = imgtag;
|
|---|
| 49 | return link.ToString();
|
|---|
| 50 | }
|
|---|
| 51 | public static string CurrentController(this HtmlHelper htmlHelper)
|
|---|
| 52 | {
|
|---|
| 53 | return htmlHelper.ViewContext.RouteData.Values["controller"].ToString();
|
|---|
| 54 | }
|
|---|
| 55 | public static string CurrentAction(this HtmlHelper htmlHelper)
|
|---|
| 56 | {
|
|---|
| 57 | return htmlHelper.ViewContext.RouteData.Values["action"].ToString();
|
|---|
| 58 | }
|
|---|
| 59 | public static string Home(this UrlHelper urlHelper)
|
|---|
| 60 | {
|
|---|
| 61 | return urlHelper.Content("~/");
|
|---|
| 62 | }
|
|---|
| 63 | public static string Css(this UrlHelper urlHelper, string fileName)
|
|---|
| 64 | {
|
|---|
| 65 | string url = urlHelper.Home() + "Content/" + fileName;
|
|---|
| 66 | return urlHelper.Content(url);
|
|---|
| 67 | }
|
|---|
| 68 | public static string UrlImage(this UrlHelper urlHelper, string fileName)
|
|---|
| 69 | {
|
|---|
| 70 | string url = urlHelper.Home() + "Images/" + fileName;
|
|---|
| 71 | return urlHelper.Content(url);
|
|---|
| 72 | }
|
|---|
| 73 | public static string FileUrl(this UrlHelper urlHelper, string fileName)
|
|---|
| 74 | {
|
|---|
| 75 | string url = urlHelper.Home() + "Images/";
|
|---|
| 76 | if (ConfigurationManager.AppSettings["Css"] == "truck") url += "truck/";
|
|---|
| 77 | else if(ConfigurationManager.AppSettings["Css"] == "admoto") url += "admoto/";
|
|---|
| 78 | url += fileName;
|
|---|
| 79 | return urlHelper.Content(url);
|
|---|
| 80 | }
|
|---|
| 81 | public static string MainCss(this HtmlHelper htmlHelper, string filename)
|
|---|
| 82 | {
|
|---|
| 83 | UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
|
|---|
| 84 | string url = urlHelper.Css(filename);
|
|---|
| 85 | string strCss = htmlHelper.LinkTag(url, "stylesheet", "text/css");
|
|---|
| 86 | return strCss;
|
|---|
| 87 | }
|
|---|
| 88 | public static string LinkTag(this HtmlHelper htmlHelper, string url, string rel, string type)
|
|---|
| 89 | {
|
|---|
| 90 | TagBuilder linkcss = new TagBuilder("link");
|
|---|
| 91 | linkcss.Attributes.Add("href", url);
|
|---|
| 92 | linkcss.Attributes.Add("rel", rel);
|
|---|
| 93 | if (type != "" ) linkcss.Attributes.Add("type", type);
|
|---|
| 94 | return linkcss.ToString(TagRenderMode.SelfClosing);
|
|---|
| 95 | }
|
|---|
| 96 | public static string AddCssToPortal(this HtmlHelper htmlHelper)
|
|---|
| 97 | {
|
|---|
| 98 | string filename = "";
|
|---|
| 99 | if (ConfigurationManager.AppSettings["Css"] == "truck") filename = "truck.css" ;
|
|---|
| 100 | else if(ConfigurationManager.AppSettings["Css"] == "admoto") filename = "admoto.css";
|
|---|
| 101 |
|
|---|
| 102 | string css = htmlHelper.MainCss(filename);
|
|---|
| 103 | return css;
|
|---|
| 104 | }
|
|---|
| 105 | public static string Favicon(this HtmlHelper htmlHelper){
|
|---|
| 106 | string url = "";
|
|---|
| 107 | string str = "";
|
|---|
| 108 | if (ConfigurationManager.AppSettings["Css"] == "admoto"){
|
|---|
| 109 | UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
|
|---|
| 110 | url = urlHelper.FileUrl("favicon.ico");
|
|---|
| 111 | str = htmlHelper.LinkTag(url,"shortcut icon","");
|
|---|
| 112 | }
|
|---|
| 113 | return str;
|
|---|
| 114 | }
|
|---|
| 115 | public static string Logo(this HtmlHelper htmlHelper)
|
|---|
| 116 | {
|
|---|
| 117 | string rowspan = "";
|
|---|
| 118 | if (ConfigurationManager.AppSettings["Css"] == "truck") rowspan = "";
|
|---|
| 119 | else if (ConfigurationManager.AppSettings["Css"] == "admoto") rowspan = "2";
|
|---|
| 120 | string str = htmlHelper.TdTag("logo", rowspan);
|
|---|
| 121 | return str;
|
|---|
| 122 | }
|
|---|
| 123 | public static string TdTag(this HtmlHelper helper, string tdClass, string tdRowspan)
|
|---|
| 124 | {
|
|---|
| 125 | UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
|
|---|
| 126 | string url = urlHelper.FileUrl("logo.gif");
|
|---|
| 127 | string logotag = helper.ImageTag(url, "logo");
|
|---|
| 128 |
|
|---|
| 129 | TagBuilder tb = new TagBuilder("td");
|
|---|
| 130 | tb.Attributes.Add("class", tdClass);
|
|---|
| 131 | if (tdRowspan != "") tb.Attributes.Add("rowspan", tdRowspan);
|
|---|
| 132 |
|
|---|
| 133 | if (ConfigurationManager.AppSettings["Css"] == "admoto")
|
|---|
| 134 | {
|
|---|
| 135 | logotag += "<span>"+HttpContext.GetGlobalResourceObject("tlumaczenia", "tytul").ToString()+"</span>";
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | tb.InnerHtml = logotag;
|
|---|
| 139 | return tb.ToString();
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|