/// <summary> /// /// </summary> public override void Process() { // Mucho TO-DO in this action: // - Escape slashes in senses // - Proper checking for all sorts of stuff string simp = Req.Params["simp"]; if (simp == null) { throw new ApiException(400, "Missing 'simp' parameter."); } string trad = Req.Params["trad"]; if (trad == null) { throw new ApiException(400, "Missing 'trad' parameter."); } string pinyin = Req.Params["pinyin"]; if (pinyin == null) { throw new ApiException(400, "Missing 'pinyin' parameter."); } string trg = Req.Params["trg"]; if (trg == null) { throw new ApiException(400, "Missing 'trg' parameter."); } Result res = new Result(); res.Passed = true; CedictEntry entry = SqlDict.BuildEntry(simp, trad, pinyin, trg); StringBuilder sb = new StringBuilder(); using (HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb))) { EntryRenderer er = new EntryRenderer(entry, null, null); er.Render(writer); } res.Preview = sb.ToString(); // Tell our caller Res = res; }
/// <summary> /// /// </summary> public override void Process() { string simp = Req.Params["simp"]; if (simp == null) { throw new ApiException(400, "Missing 'simp' parameter."); } string trad = Req.Params["trad"]; if (trad == null) { throw new ApiException(400, "Missing 'trad' parameter."); } string pinyin = Req.Params["pinyin"]; if (pinyin == null) { throw new ApiException(400, "Missing 'pinyin' parameter."); } Result res = new Result(); res.Passed = true; // DBG if (simp == "大家" || simp == "污染") { res.Passed = false; } // Prepare pinyin as list of proper syllables List <PinyinSyllable> pyList = new List <PinyinSyllable>(); string[] pyRawArr = pinyin.Split(' '); foreach (string pyRaw in pyRawArr) { pyList.Add(PinyinSyllable.FromDisplayString(pyRaw)); } // Return all entries, CEDICT and HanDeDict, rendered as HTML CedictEntry[] ced, hdd; Global.HWInfo.GetEntries(simp, out ced, out hdd); StringBuilder sb = new StringBuilder(); using (HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb))) { writer.AddAttribute(HtmlTextWriterAttribute.Id, "newEntryRefCED"); writer.RenderBeginTag(HtmlTextWriterTag.Div); foreach (CedictEntry entry in ced) { EntryRenderer er = new EntryRenderer(entry, trad, pyList); er.Render(writer); } writer.RenderEndTag(); writer.AddAttribute(HtmlTextWriterAttribute.Id, "newEntryRefHDD"); writer.RenderBeginTag(HtmlTextWriterTag.Div); foreach (CedictEntry entry in hdd) { EntryRenderer er = new EntryRenderer(entry, trad, pyList); er.Render(writer); } writer.RenderEndTag(); } res.RefEntries = sb.ToString(); // Tell our caller Res = res; }
private void histRenderChange(HtmlTextWriter writer, SqlDict.ChangeItem ci, bool trailingSeparator) { writer.WriteLine(); writer.AddAttribute("class", "historyItem"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "changeHead"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "fa fa-lightbulb-o ctNew"); writer.RenderBeginTag(HtmlTextWriterTag.I); writer.RenderEndTag(); writer.AddAttribute("class", "changeSummary"); writer.RenderBeginTag(HtmlTextWriterTag.Div); string changeMsg; string changeCls = "changeType"; if (ci.ChangeType == SqlDict.ChangeType.New) { changeMsg = "Új szócikk"; } else if (ci.ChangeType == SqlDict.ChangeType.Edit) { changeMsg = "Szerkesztve"; } else if (ci.ChangeType == SqlDict.ChangeType.Note) { changeMsg = "Megjegyzés"; } else { changeMsg = ci.ChangeType.ToString(); } changeMsg += ": "; writer.AddAttribute("class", changeCls); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.WriteEncodedText(changeMsg); writer.RenderEndTag(); writer.AddAttribute("class", "changeUser"); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.WriteEncodedText(ci.User); writer.RenderEndTag(); writer.Write(" • "); writer.AddAttribute("class", "changeTime"); writer.RenderBeginTag(HtmlTextWriterTag.Span); DateTime dt = TimeZoneInfo.ConvertTimeFromUtc(ci.When, Global.TimeZoneInfo); string dtFmt = "{0}-{1:00}-{2:00} {3:00}:{4:00}"; dtFmt = string.Format(dtFmt, dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute); writer.WriteEncodedText(dtFmt); writer.RenderEndTag(); writer.RenderEndTag(); writer.AddAttribute("class", "changeNote"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.WriteEncodedText(ci.Note); writer.RenderEndTag(); writer.RenderEndTag(); writer.AddAttribute("class", "changeEntry"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "histEntryOps"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "opHistEdit fa fa-pencil-square-o"); writer.RenderBeginTag(HtmlTextWriterTag.I); writer.RenderEndTag(); writer.AddAttribute("class", "opHistComment fa fa-commenting-o"); writer.RenderBeginTag(HtmlTextWriterTag.I); writer.RenderEndTag(); writer.AddAttribute("class", "opHistFlag fa fa-flag-o"); writer.RenderBeginTag(HtmlTextWriterTag.I); writer.RenderEndTag(); writer.RenderEndTag(); CedictEntry entry = SqlDict.BuildEntry(ci.EntryHead, ci.EntryBody); EntryRenderer er = new EntryRenderer(entry); er.OneLineHanziLimit = 12; er.Render(writer); writer.RenderEndTag(); writer.RenderEndTag(); if (trailingSeparator) { writer.AddAttribute("class", "historySep"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderEndTag(); } }
private void doSearch(string lang, string rel) { // No search query in URL: show welcome page. if (rel == "") { Res = makeWelcomeResult(lang); return; } // Seach's special parameters string strScript = Req.Params["searchScript"]; string strTones = Req.Params["searchTones"]; UiScript uiScript = UiScript.Both; if (strScript == "simp") { uiScript = UiScript.Simp; } else if (strScript == "trad") { uiScript = UiScript.Trad; } UiTones uiTones = UiTones.Pleco; if (strTones == "dummitt") { uiTones = UiTones.Dummitt; } else if (strTones == "none") { uiTones = UiTones.None; } // Perform query string query = rel.Replace("search/", ""); query = HttpUtility.UrlDecode(query); CedictLookupResult lr; using (SqlDict.Query q = new SqlDict.Query()) { lr = q.Lookup(query); } // No results if (lr.Results.Count == 0 && lr.Annotations.Count == 0) { return; } // Render results var prov = lr.EntryProvider; StringBuilder sb = new StringBuilder(); using (HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb))) { int max = Math.Min(lr.Results.Count, 256); for (int i = 0; i != max; ++i) { var lres = lr.Results[i]; EntryRenderer er = new EntryRenderer(lres, prov, uiScript, uiTones); er.OneLineHanziLimit = 9; er.Render(writer); if (i != max - 1) { writer.AddAttribute("class", "resultSep"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderEndTag(); } } } // Assemble HTML for result StringBuilder sbHtml; string title, keywords, description; readFile(getFileName(lang, "_search"), out sbHtml, out title, out keywords, out description); sbHtml.Replace("<!-- RESULTS -->", sb.ToString()); // Special treatment of metainfo title = TextProvider.Instance.GetString(lang, "TitleSearchZho"); title = string.Format(title, lr.Query); // Build result SearchResult res = new SearchResult(); res.Html = sbHtml.ToString(); res.Title = title; res.Keywords = keywords; res.Description = description; res.Query = lr.Query; Res = res; }
protected override void Render(HtmlTextWriter writer) { EntryRenderer er = new EntryRenderer(res, prov, script, tones, isMobile); er.Render(writer); }
protected override void Render(HtmlTextWriter writer) { writer.WriteLine(); writer.AddAttribute("class", "historyItem"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "changeHead"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "changeSummary"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddAttribute("class", "changeUser"); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.WriteEncodedText(ci.User); writer.RenderEndTag(); writer.Write(" • "); writer.AddAttribute("class", "changeTime"); writer.RenderBeginTag(HtmlTextWriterTag.Span); DateTime dt = TimeZoneInfo.ConvertTimeFromUtc(ci.When, Global.TimeZoneInfo); string dtFmt = "{0}-{1:00}-{2:00} {3:00}:{4:00}:{5:00}"; dtFmt = string.Format(dtFmt, dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); writer.WriteEncodedText(dtFmt); writer.RenderEndTag(); writer.Write(" • "); string changeMsg; string changeCls = "changeType"; if (ci.ChangeType == SqlDict.ChangeType.New) { changeMsg = "új szócikk"; changeCls += " ctNew"; } else if (ci.ChangeType == SqlDict.ChangeType.Edit) { changeMsg = "szerkesztve"; changeCls += " ctEdit"; } else if (ci.ChangeType == SqlDict.ChangeType.Note) { changeMsg = "megjegyzés"; changeCls += " ctNote"; } else { changeMsg = ci.ChangeType.ToString(); } writer.AddAttribute("class", changeCls); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.WriteEncodedText(changeMsg); writer.RenderEndTag(); writer.RenderEndTag(); writer.AddAttribute("class", "changeNote"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.WriteEncodedText("~~ " + ci.Note); writer.RenderEndTag(); writer.RenderEndTag(); writer.AddAttribute("class", "entry"); writer.RenderBeginTag(HtmlTextWriterTag.Div); CedictEntry entry = SqlDict.BuildEntry(ci.EntryHead, ci.EntryBody); EntryRenderer er = new EntryRenderer(entry, null, null); er.Render(writer); writer.RenderEndTag(); writer.RenderEndTag(); }