public void Test_ConvertRelativeUrlToAbsoluteUrl_WithoutPreceedingSlash() { string url = "Folder1/folder2/file.html";//HttpContext.Current.Request.Url.ToString(); string expected = "http://localhost/Folder1/folder2/file.html"; UrlConverter converter = new UrlConverter("/"); converter.Protocol = "http"; converter.Host = "localhost"; string result = converter.ToAbsolute(url); Assert.AreEqual(expected, result, "Doesn't match."); }
public void Test_ToRelative() { string url = "http://www.Test.com/Folder1/folder2/file.html"; string applicationPath = "http://www.test.com/folder1/"; string expected = "/folder2/file.html"; UrlConverter converter = new UrlConverter(applicationPath); converter.Protocol = "http"; converter.Host = "localhost"; string result = converter.ToRelative(url); Assert.AreEqual(expected, result, "Doesn't match."); }
public void Test_ToAbsolute() { string url = "/Folder1/folder2/file.html";//HttpContext.Current.Request.Url.ToString(); string expected = "http://localhost/Folder1/folder2/file.html"; //string protocol = "http"; //string host = "localhost"; UrlConverter converter = new UrlConverter(ApplicationPath); converter.Protocol = "http"; converter.Host = "localhost"; string result = converter.ToAbsolute(url); Assert.AreEqual(expected, result, "Doesn't match."); }
private async void Clipboard_ContentChanged(object sender, object e) { try { if (!SubmitButton.IsEnabled) { string url = await UrlConverter.CheckClipBoardAsync(); if (url != string.Empty && !SubmitButton.IsEnabled) { URLBox.Text = url; if (sender == null && e == null) { URLBox_TextChanged(null, null); } } } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
public IActionResult AddCategory(CategoryAddViewModel model) { if (ModelState.IsValid) { var urlConvertor = new UrlConverter(); var titleConverter = new TitleConverter(); var category = new Category() { Name = titleConverter.TitleToPascalCase(model.Name), Url = urlConvertor.StringReplace(model.Name.ToLower()) }; if (_context.Categories.Any(x => x.Name == model.Name)) { ViewBag.CategoryExsit = titleConverter.TitleToPascalCase(model.Name); return(View(model)); } _categoryService.Create(category); return(RedirectToAction("Index", "Category", new { area = "Member" })); } return(View(model)); }
private void updateRoute_Menu(MvcContext ctx, List <IMenu> list, String cleanUrlWithoutOwner) { foreach (IMenu menu in list) { if (cleanUrlWithoutOwner.Equals(menu.Url)) // 如果友好网址相同 // 获取实际的网址 { String fullUrl = UrlConverter.getMenuFullPath(ctx, menu); Route.setRoutePath(fullUrl); Route newRoute = RouteTool.Recognize(fullUrl, ctx.web.PathApplication); if (newRoute == null) { break; } refreshRouteAndOwner(ctx, newRoute); break; } } }
private IMemberApp createApp() { int appInfoId = 4; AppInstaller info = appinfoService.GetById(appInfoId); IMember owner = this.user; User creator = this.user; String name = lang.get("homepage"); IMemberApp myuserApp = appService.Add(creator, owner, name, info.Id, AccessStatus.Public); //String appUrl = UrlConverter.clearUrl( myuserApp, ctx ); String appUrl = UrlConverter.clearUrl(myuserApp, ctx, owner); IMenu menu = menuService.AddMenuByApp(myuserApp, name, "", appUrl); menu.Url = "default"; menu.OrderId = 99; menuService.Update(menu); this.app = ContentApp.findById(myuserApp.AppOid); return(myuserApp); }
private void bindMenus(List <IMenu> menus) { IBlock block = getBlock("list"); foreach (IMenu menu in menus) { int depth = getTree().GetDepth(menu.Id); int indent = 20 * depth; String strIndent = "<span style=\"margin-left:" + indent + "px\"></span>"; block.Set("d.Indent", strIndent); block.Set("d.Id", menu.Id); block.Set("d.Name", menu.Name); block.Set("d.Style", menu.Style); String externalLink = menu.OpenNewWindow == 1 ? " class=\"externalLink\" " : ""; block.Set("d.ExternalLink", externalLink); block.Set("d.Url", strUtil.CutString(menu.Url, 50)); String showUrl = UrlConverter.getMenuFullUrl(menu, ctx); block.Set("d.RawUrl", strUtil.CutString(showUrl, 80)); block.Set("d.DeleteUrl", to(Delete, menu.Id)); block.Set("d.EditUrl", to(Edit, menu.Id)); String lnkSubMenu = ""; if (menu.ParentId == 0) { lnkSubMenu = string.Format("<a href=\"{0}\" class=\"frmBox\" >{1}</a>", to(AddSubMenu, menu.Id), lang("addSubMenu")); } block.Set("d.AddSubMenu", lnkSubMenu); block.Next(); } }
public async Task <IActionResult> AddArticle(ArticleAddViewModel model, IFormFile pic) { if (ModelState.IsValid) { var titleConv = new TitleConverter(); var urlConv = new UrlConverter(); if (pic != null) { var extension = Path.GetExtension(pic.FileName); var name = urlConv.StringReplace(model.Title) + extension; var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/article-cover/" + name); using var stream = new FileStream(path, FileMode.Create); await pic.CopyToAsync(stream); model.Picture = name; } var article = new Article() { Title = titleConv.TitleToPascalCase(model.Title), Content = model.Content.Replace(" ", " "), CategoryId = model.CategoryId, Url = urlConv.StringReplace(model.Title), Picture = model.Picture }; if (_context.Articles.Any(x => x.Title == model.Title)) { ViewBag.TitleExist = titleConv.TitleToPascalCase(model.Title); return(View(model)); } _articleService.Create(article); return(RedirectToAction("Index", "Article", new { area = "Admin" })); } return(View(model)); }
private string GetReportIssueUrl() { string path = String.Empty; // If running on localhost use the test page if (WebUtilities.GetLocationVariation(Page.Request.Url) == "local") path = new UrlConverter().ToAbsolute(Page.Request.ApplicationPath) + "/Admin/Tests/TestReportIssue.aspx?ProjectID=${Project.ID}&ProjectVersion=${Project.Version}"; else path = ConfigurationSettings.AppSettings["ReportIssueUrl"]; path = path.Replace("${Project.ID}", ProjectID); path = path.Replace("${Project.Version}", VersionUtilities.GetCurrentVersion().ToString()); return path; }
protected IMenu validateMenu(IMenu menu) { menu.Name = ctx.Post("Name"); menu.Url = ctx.Post("Url"); menu.Style = getMenuStyle(ctx); String rawUrl = ctx.Post("RawUrl"); if (strUtil.IsNullOrEmpty(menu.Name)) { errors.Add(lang("exName")); } if (strUtil.IsNullOrEmpty(rawUrl)) { errors.Add(lang("exUrl")); } Boolean isUrl = RegPattern.IsMatch(rawUrl, RegPattern.Url); if (!isUrl) { errors.Add(lang("exUrlFormat")); } if (ctx.HasErrors) { return(null); } Boolean isOutUrl = PathHelper.IsOutUrl(rawUrl); logger.Info("isOutUrl=" + isOutUrl); if (isOutUrl) { menu.RawUrl = rawUrl; menu.Url = ""; } else { IMember owner = ctx.owner.obj; String cleanedUrl = UrlConverter.clearUrl(rawUrl, ctx, owner.GetType().FullName, owner.Url); logger.Info("cleanedUrl=" + cleanedUrl); menu.RawUrl = cleanedUrl; } menu.OpenNewWindow = ctx.PostIsCheck("chkBlank"); if (strUtil.IsNullOrEmpty(menu.Name)) { errors.Add(lang("exName")); } if (strUtil.IsNullOrEmpty(menu.RawUrl)) { errors.Add(lang("exUrl")); } if (strUtil.HasText(menu.Url) && strUtil.IsUrlItem(menu.Url) == false) { errors.Add(lang("exFriendUrlFormat")); } return(menu); }
public void ToConfigFavorite(OptionsConversionContext context) { context.ConfigFavorite.Url = UrlConverter.ExtractAbsoluteUrl(context.Favorite); }
public override string ConvertUrl(string origin) { return(UrlConverter.Convert(origin)); }
private void addUserAppAndMenus(User user) { if (strUtil.IsNullOrEmpty(config.Instance.Site.UserInitApp)) { return; } List <String> menus = new List <string>(); String[] arr = config.Instance.Site.UserInitApp.Split(','); foreach (String app in arr) { if (strUtil.IsNullOrEmpty(app)) { continue; } menus.Add(app.Trim()); } if (menus.Contains("home")) { new UserHomeInstaller().Install(ctx, user, lang("homepage"), wojilu.Common.AppBase.AccessStatus.Public); } if (menus.Contains("blog")) { IMemberApp blogApp = appService.Add(user, "博客", 2); // 添加菜单:此处需要明确传入MemberType,否则将会使用ctx.Owner,也就是Site的值,导致bug String blogUrl = UrlConverter.clearUrl(alink.ToUserAppFull(blogApp), ctx, typeof(User).FullName, user.Url); menuService.AddMenuByApp(blogApp, blogApp.Name, "", blogUrl); } if (menus.Contains("photo")) { IMemberApp photoApp = appService.Add(user, "相册", 3); String photoUrl = UrlConverter.clearUrl(alink.ToUserAppFull(photoApp), ctx, typeof(User).FullName, user.Url); menuService.AddMenuByApp(photoApp, photoApp.Name, "", photoUrl); } if (menus.Contains("microblog")) { IMenu menu = getMenu(user, "微博", alink.ToUserMicroblog(user)); menuService.Insert(menu, user, user); } if (menus.Contains("share")) { IMenu menu = getMenu(user, "转帖", t2(new Users.ShareController().Index)); menuService.Insert(menu, user, user); } if (menus.Contains("friend")) { IMenu menu = getMenu(user, "好友", t2(new Users.FriendController().FriendList)); menuService.Insert(menu, user, user); } if (menus.Contains("visitor")) { IMenu menu = getMenu(user, "访客", t2(new Users.VisitorController().Index)); menuService.Insert(menu, user, user); } if (menus.Contains("forumpost")) { IMenu menu = getMenu(user, "论坛帖子", t2(new Users.ForumController().Topic)); menuService.Insert(menu, user, user); } if (menus.Contains("about")) { IMenu menu = getMenu(user, "关于我", t2(new Users.ProfileController().Main)); menuService.Insert(menu, user, user); } if (menus.Contains("feedback")) { IMenu menu = getMenu(user, "留言", t2(new Users.FeedbackController().List)); menuService.Insert(menu, user, user); } }
private static void Main(string[] args) { UrlConverter.ConvertToXml(UrlReader.ReadUrl("url.txt", new UrlLogger()), "url.xml"); Console.Read(); }
public void FromConfigFavorite(OptionsConversionContext context) { UrlConverter.UpdateFavoriteUrl(context.Favorite, context.ConfigFavorite.Url); }
public TransactionResult CreateItem(string UserId, string categoryslug, string title, string description, string provinceId, string districtId, string whenTypeId, string whenDateId, string whenTimeId, IEnumerable <CategoryQuestions> questions, decimal?price, IEnumerable <IFormFile> galleryImages) { try { var today = DateTime.Now; var item = new Item(); item.Id = Guid.NewGuid(); item.AddedDate = today; item.SlugUrl = UrlConverter.ToUrlSlug(title + "-" + today.DayOfYear + today.Year); var category = _categoryServices.GetCategory(categoryslug); item.CategoryId = category.Id; item.Description = description; int ProvinceId = 0; if (int.TryParse(provinceId, out ProvinceId)) { item.ProvinceId = ProvinceId; } int DistrictId = 0; if (int.TryParse(districtId, out DistrictId)) { item.DistrictId = DistrictId; } int WhenTypeId = 0; if (int.TryParse(whenTypeId, out WhenTypeId)) { item.WhenType = WhenTypeId; } if (!string.IsNullOrWhiteSpace(whenDateId) && !string.IsNullOrWhiteSpace(whenTimeId)) { var datetime = DateTime.ParseExact(whenDateId + " " + whenTimeId, "yyyyMMdd HHmm", CultureInfo.InvariantCulture); item.WhenDate = datetime; } item.Price = price; item.StatusID = (int)StatusTypes.Open; item.Title = title; item.UserId = UserId; item.ItemCategoryQuestionsJSON = JsonConvert.SerializeObject(questions); //// TODO Uncomment here //var upload = new FormUpload(_environment.WebRootPath); //var index = 0; //foreach (var image in galleryImages) //{ // if (image.Length != 0) // { // var filename = string.Format("{0}-{1}", item.Id, index); // var imageResult = upload.SaveFile(image, filename, "itemgallery"); // if (imageResult.Type != TransactionType.Success) // return imageResult; // switch (index) // { // case 0: // item.ImageUrl = imageResult.Result as string; // break; // case 1: // item.ImageUrl2 = imageResult.Result as string; // break; // case 2: // item.ImageUrl3 = imageResult.Result as string; // break; // case 3: // item.ImageUrl4 = imageResult.Result as string; // break; // case 4: // item.ImageUrl5 = imageResult.Result as string; // break; // } // index++; // } //} _dbContext.Item.Add(item); _dbContext.SaveChanges(); _notificationService.AddNotification(UserId, NotificationTypes.CreateItem, itemId: item.Id.ToString()); SendBulkSMS(item); return(new TransactionResult() { Type = TransactionType.Success }); } catch (Exception ex) { return(new TransactionResult(message: "Beklenmedik bir hata oluştu. Lütfen tekrar deneyiniz.", type: TransactionType.Error)); } }
public static string Make(UrlConverter converterType, string srcUrl) { string src; try { src = MyCommon.GetUrlEncodeMultibyteChar(srcUrl); } catch (Exception) { return "Can't convert"; } var orgSrc = srcUrl; var param = new Dictionary<string, string>(); var content = string.Empty; if (ShortUrlServices.Any(svc => srcUrl.StartsWith(svc))) { return "Can't convert"; } // nico.msは短縮しない if (srcUrl.StartsWith("http://nico.ms/")) { return "Can't convert"; } srcUrl = HttpUtility.UrlEncode(srcUrl); switch (converterType) { case UrlConverter.TinyUrl: // tinyurl if (srcUrl.StartsWith("http")) { if ("http://tinyurl.com/xxxxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } if (!(new HttpVarious()).PostData("http://tinyurl.com/api-create.php?url=" + srcUrl, null, ref content)) { return "Can't convert"; } } if (!content.StartsWith("http://tinyurl.com/")) { return "Can't convert"; } break; case UrlConverter.Isgd: if (srcUrl.StartsWith("http")) { if ("http://is.gd/xxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } if (!(new HttpVarious()).PostData("http://is.gd/api.php?longurl=" + srcUrl, null, ref content)) { return "Can't convert"; } } if (!content.StartsWith("http://is.gd/")) { return "Can't convert"; } break; case UrlConverter.Twurl: if (srcUrl.StartsWith("http")) { if ("http://twurl.nl/xxxxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } param.Add("link[url]", orgSrc); // twurlはpostメソッドなので日本語エンコードのみ済ませた状態で送る if (!(new HttpVarious()).PostData("http://tweetburner.com/links", param, ref content)) { return "Can't convert"; } } if (!content.StartsWith("http://twurl.nl/")) { return "Can't convert"; } break; case UrlConverter.Bitly: case UrlConverter.Jmp: const string BitlyLogin = "******"; // TODO: Hoehoenize const string BitlyApiKey = "R_c5ee0e30bdfff88723c4457cc331886b"; const string BitlyApiVersion = "3"; if (srcUrl.StartsWith("http")) { if ("http://bit.ly/xxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } string req = "http://api.bitly.com/v" + BitlyApiVersion + "/shorten?"; req += "login="******"&apiKey=" + BitlyApiKey + "&format=txt" + "&longUrl=" + srcUrl; if (!string.IsNullOrEmpty(bitlyId) && !string.IsNullOrEmpty(bitlyKey)) { req += "&x_login="******"&x_apiKey=" + bitlyKey; } if (converterType == UrlConverter.Jmp) { req += "&domain=j.mp"; } if (!(new HttpVarious()).GetData(req, null, ref content)) { return "Can't convert"; } } break; case UrlConverter.Uxnu: if (srcUrl.StartsWith("http")) { if ("http://ux.nx/xxxxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } if (!(new HttpVarious()).PostData("http://ux.nu/api/short?url=" + srcUrl + "&format=plain", null, ref content)) { return "Can't convert"; } } if (!content.StartsWith("http://ux.nu/")) { return "Can't convert"; } break; } // 変換結果から改行を除去 content = content.TrimEnd(new[] { '\r', '\n' }); // 圧縮の結果逆に長くなった場合は圧縮前のURLを返す if (src.Length < content.Length) { content = src; } return content; }
public void URLIfyRefactor() { Assert.AreEqual("My%20Home%20Page", UrlConverter.UrlifyRefactor("My Home Page ", 16)); }
public static string Make(UrlConverter converterType, string srcUrl) { string src; try { src = MyCommon.GetUrlEncodeMultibyteChar(srcUrl); } catch (Exception) { return("Can't convert"); } var orgSrc = srcUrl; var param = new Dictionary <string, string>(); var content = string.Empty; if (ShortUrlServices.Any(svc => srcUrl.StartsWith(svc))) { return("Can't convert"); } // nico.msは短縮しない if (srcUrl.StartsWith("http://nico.ms/")) { return("Can't convert"); } srcUrl = HttpUtility.UrlEncode(srcUrl); switch (converterType) { case UrlConverter.TinyUrl: // tinyurl if (srcUrl.StartsWith("http")) { if ("http://tinyurl.com/xxxxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } if (!(new HttpVarious()).PostData("http://tinyurl.com/api-create.php?url=" + srcUrl, null, ref content)) { return("Can't convert"); } } if (!content.StartsWith("http://tinyurl.com/")) { return("Can't convert"); } break; case UrlConverter.Isgd: if (srcUrl.StartsWith("http")) { if ("http://is.gd/xxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } if (!(new HttpVarious()).PostData("http://is.gd/api.php?longurl=" + srcUrl, null, ref content)) { return("Can't convert"); } } if (!content.StartsWith("http://is.gd/")) { return("Can't convert"); } break; case UrlConverter.Twurl: if (srcUrl.StartsWith("http")) { if ("http://twurl.nl/xxxxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } param.Add("link[url]", orgSrc); // twurlはpostメソッドなので日本語エンコードのみ済ませた状態で送る if (!(new HttpVarious()).PostData("http://tweetburner.com/links", param, ref content)) { return("Can't convert"); } } if (!content.StartsWith("http://twurl.nl/")) { return("Can't convert"); } break; case UrlConverter.Bitly: case UrlConverter.Jmp: const string BitlyLogin = "******"; // TODO: Hoehoenize const string BitlyApiKey = "R_c5ee0e30bdfff88723c4457cc331886b"; const string BitlyApiVersion = "3"; if (srcUrl.StartsWith("http")) { if ("http://bit.ly/xxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } string req = "http://api.bitly.com/v" + BitlyApiVersion + "/shorten?"; req += "login="******"&apiKey=" + BitlyApiKey + "&format=txt" + "&longUrl=" + srcUrl; if (!string.IsNullOrEmpty(bitlyId) && !string.IsNullOrEmpty(bitlyKey)) { req += "&x_login="******"&x_apiKey=" + bitlyKey; } if (converterType == UrlConverter.Jmp) { req += "&domain=j.mp"; } if (!(new HttpVarious()).GetData(req, null, ref content)) { return("Can't convert"); } } break; case UrlConverter.Uxnu: if (srcUrl.StartsWith("http")) { if ("http://ux.nx/xxxxxx".Length > src.Length && !src.Contains("?") && !src.Contains("#")) { // 明らかに長くなると推測できる場合は圧縮しない content = src; break; } if (!(new HttpVarious()).PostData("http://ux.nu/api/short?url=" + srcUrl + "&format=plain", null, ref content)) { return("Can't convert"); } } if (!content.StartsWith("http://ux.nu/")) { return("Can't convert"); } break; } // 変換結果から改行を除去 content = content.TrimEnd(new[] { '\r', '\n' }); // 圧縮の結果逆に長くなった場合は圧縮前のURLを返す if (src.Length < content.Length) { content = src; } return(content); }
/// <summary> /// t.coで投稿時自動短縮する場合は、外部サービスでの短縮禁止 /// Converter_Type=Nicomsの場合は、nicovideoのみ短縮する /// 参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax /// Appendix A. Collected ABNF for URI /// http://www.ietf.org/rfc/rfc3986.txt /// </summary> /// <param name="urlCoonverterType"></param> /// <returns></returns> private bool ConvertUrl(UrlConverter urlCoonverterType) { const string NicoUrlPattern = "^https?://[a-z]+\\.(nicovideo|niconicommons|nicolive)\\.jp/[a-z]+/[a-z0-9]+$"; if (StatusText.SelectionLength > 0) { // 文字列が選択されている場合はその文字列について処理 string tmp = StatusText.SelectedText; // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない if (tmp.StartsWith("http")) { // nico.ms使用、nicovideoにマッチしたら変換 string result; if (_configs.Nicoms && Regex.IsMatch(tmp, NicoUrlPattern)) { result = nicoms.Shorten(tmp); } else if (urlCoonverterType != UrlConverter.Nicoms) { // 短縮URL変換 日本語を含むかもしれないのでURLエンコードする result = ShortUrl.Make(urlCoonverterType, tmp); if (result.Equals("Can't convert")) { StatusLabel.Text = result.Insert(0, string.Format("{0}:", urlCoonverterType)); return false; } } else { return true; } SetUrlUndoInfo(tmp, result); } } else { const string UrlPattern = "(?<before>(?:[^\\\"':!=]|^|\\:))" + "(?<url>(?<protocol>https?://)" + "(?<domain>(?:[\\.-]|[^\\p{P}\\s])+\\.[a-z]{2,}(?::[0-9]+)?)" + "(?<path>/[a-z0-9!*'();:&=+$/%#\\-_.,~@]*[a-z0-9)=#/]?)?" + "(?<query>\\?[a-z0-9!*'();:&=+$/%#\\-_.,~@?]*[a-z0-9_&=#/])?)"; // 正規表現にマッチしたURL文字列をtinyurl化 foreach (Match mt in Regex.Matches(StatusText.Text, UrlPattern, RegexOptions.IgnoreCase)) { string url = mt.Result("${url}"); if (StatusText.Text.IndexOf(url, StringComparison.Ordinal) == -1) { continue; } string tmp = url; if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase)) { tmp = "http://" + tmp; } // 選んだURLを選択(?) StatusText.Select(StatusText.Text.IndexOf(url, StringComparison.Ordinal), url.Length); // nico.ms使用、nicovideoにマッチしたら変換 string result; if (_configs.Nicoms && Regex.IsMatch(tmp, NicoUrlPattern)) { result = nicoms.Shorten(tmp); } else if (urlCoonverterType != UrlConverter.Nicoms) { // 短縮URL変換 日本語を含むかもしれないのでURLエンコードする result = ShortUrl.Make(urlCoonverterType, tmp); if (result.Equals("Can't convert")) { StatusLabel.Text = result.Insert(0, string.Format("{0}:", urlCoonverterType)); continue; } } else { continue; } SetUrlUndoInfo(url, result); } } return true; }
public virtual void Create() { int appInfoId = cvt.ToInt(ctx.Post("appInfoId")); AppInstaller info = getAppInfo(appInfoId); if (info.IsClose(ctx.owner.obj.GetType())) { echo("app closed"); return; } if (!checkInstall(info)) { return; } String name = ctx.Post("Name"); AccessStatus accs = AccessStatus.Public; if (strUtil.IsNullOrEmpty(name)) { echoError("请填写名称"); return; } // 自定义安装 Type appType = ObjectContext.Instance.TypeList[info.TypeFullName]; if (rft.IsInterface(appType, typeof(IAppInstaller))) { // 主题ID String themeId = ctx.Post("themeId"); IAppInstaller customInstaller = ObjectContext.Create(appType) as IAppInstaller; IMemberApp capp = customInstaller.Install(ctx, ctx.owner.obj, name, accs, themeId, ""); intiAppPermission(capp); echoToParentPart(lang("opok"), to(Index), 1); return; } // 主题安装 if (strUtil.HasText(info.InstallerType)) { // 主题ID String themeId = ctx.Post("themeId"); Type installerType = ObjectContext.GetType(info.InstallerType); IAppInstaller customInstaller = ObjectContext.Create(installerType) as IAppInstaller; IMemberApp capp = customInstaller.Install(ctx, ctx.owner.obj, name, accs, themeId, ""); intiAppPermission(capp); echoToParentPart(lang("opok"), to(Index), 1); return; } // 默认安装 IMember owner = ctx.owner.obj; User creator = (User)ctx.viewer.obj; // 1、添加一条 IMemberApp IMemberApp app = userAppService.Add(creator, owner, name, info.Id, accs); if (app != null) { // 2、添加菜单 String appUrl = UrlConverter.clearUrl(app, ctx); menuService.AddMenuByApp(app, name, "", appUrl); // 3、初始化权限 intiAppPermission(app); log(SiteLogString.InsertApp(), app); echoToParentPart(lang("opok"), to(Index), 1); } else { errors.Add(lang("exop")); run(NewApp, info.Id); } }
private static void addUserAppAndMenus(User user, MvcContext ctx) { if (strUtil.IsNullOrEmpty(config.Instance.Site.UserInitApp)) { return; } IMemberAppService appService = new UserAppService(); IMenuService menuService = new UserMenuService(); List <String> menus = new List <string>(); String[] arr = config.Instance.Site.UserInitApp.Split(','); foreach (String app in arr) { if (strUtil.IsNullOrEmpty(app)) { continue; } menus.Add(app.Trim()); } if (menus.Contains("home")) { addMenu(user, "主页", Link.ToMember(user), true); } if (menus.Contains("blog")) { IMemberApp blogApp = appService.Add(user, "博客", 2); // 添加菜单:此处需要明确传入MemberType,否则将会使用ctx.Owner,也就是Site的值,导致bug String blogUrl = UrlConverter.clearUrl(alink.ToUserAppFull(blogApp), ctx, typeof(User).FullName, user.Url); menuService.AddMenuByApp(blogApp, blogApp.Name, "", blogUrl); } if (menus.Contains("photo")) { IMemberApp photoApp = appService.Add(user, "相册", 3); String photoUrl = UrlConverter.clearUrl(alink.ToUserAppFull(photoApp), ctx, typeof(User).FullName, user.Url); menuService.AddMenuByApp(photoApp, photoApp.Name, "", photoUrl); } if (menus.Contains("microblog")) { IMenu menu = getMenu(user, "微博", alink.ToUserMicroblog(user), ctx); menuService.Insert(menu, user, user); } if (menus.Contains("friend")) { IMenu menu = getMenu(user, "好友", lnkToUser(user, new Users.FriendController().FriendList), ctx); menuService.Insert(menu, user, user); } if (menus.Contains("visitor")) { IMenu menu = getMenu(user, "访客", lnkToUser(user, new Users.VisitorController().Index), ctx); menuService.Insert(menu, user, user); } if (menus.Contains("forumpost")) { IMenu menu = getMenu(user, "论坛帖子", lnkToUser(user, new Users.ForumController().Topic), ctx); menuService.Insert(menu, user, user); } if (menus.Contains("about")) { IMenu menu = getMenu(user, "关于我", lnkToUser(user, new Users.ProfileController().Main), ctx); menuService.Insert(menu, user, user); } if (menus.Contains("feedback")) { IMenu menu = getMenu(user, "留言", lnkToUser(user, new Users.FeedbackController().List), ctx); menuService.Insert(menu, user, user); } }