// this will look for code block like this {contentblock alias="header_html"} // this is hard code we only alias is accepted.. that needs to change /// <summary> </summary> public String processContentblocks(string text, posting post, Hashtable paramsbag) { string strRegex = @"\#{\w+(\s+(.*?))?\}"; RegexOptions myRegexOptions = RegexOptions.IgnoreCase | RegexOptions.Multiline; Regex myRegex = new Regex(strRegex, myRegexOptions); if (!String.IsNullOrWhiteSpace(text) && myRegex.IsMatch(text)) { /* * string blockstrRegex = @"(#{(?<block>\w+)\s+alias=""(?<alias>.*?)""})"; * RegexOptions blockRegexOptions = RegexOptions.IgnoreCase | RegexOptions.Multiline; * Regex blockRegex = new Regex(blockstrRegex, blockRegexOptions); */ String block = ""; String controller = ""; String alias = ""; String param = ""; string pattern = @"(?<block>\#\{(?<controller>\w+)?(?<ablock>\s+alias=""(?<alias>.*?)"")?(?:(?<params>(?:[^alias]\w+[=""].*[""])))?\}$?)"; MatchCollection matches = Regex.Matches(text, pattern); foreach (Match match in matches) { block = ""; controller = ""; alias = ""; param = ""; block = match.Groups["block"].Value; controller = match.Groups["controller"].Value.ToLower(); alias = match.Groups["alias"].Value; param = match.Groups["params"].Value; String tmp_str = ""; if (!String.IsNullOrWhiteSpace(controller)) { posting_type type = ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", controller) }.ToArray() ); if (type != null) { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Eq("deleted", false)); filtering.Add(Expression.Eq("post_type", type)); filtering.Add(Expression.Eq("alias", alias)); posting cBlock = ActiveRecordBase <posting> .FindFirst(new Order[] { Order.Desc("version"), Order.Asc("revision"), Order.Desc("sort") }, filtering.ToArray()); if (cBlock != null) { if (!Controllers.BaseController.usedev) { cBlock = cBlock.get_published(); // find the published version } if (post.is_frontend_editable && Controllers.BaseController.editing) { used_contentblocks.Add(cBlock); } PropertyBag["item"] = cBlock; if (cBlock.post_type.alias == "menu") { PropertyBag["menuItems"] = cBlock.menuoptions.OrderBy(x => x.sort); } /* now process the posttype templae if there is one /////--->moved to render() * String post_type_tmplate = cBlock.get_template(cBlock.post_type.alias + "_template");*/ paramsbag = objectService.marge_params(PropertyBag, objectService.pull_params(param, paramsbag)); //objectService.params_to_PropertyBag(PropertyBag, paramsbag); Hashtable content_params = objectService.marge_params(PropertyBag, paramsbag); Hashtable paramlist = objectService.pull_params(param, content_params); text = text.Replace(block, render(cBlock, paramlist)); } else { if (siteService.debug_mode()) { tmp_str = "Block error"; text = text.Replace(block, tmp_str); } } } else { if (widgetFactoryService.method_exists(controller)) { //Hashtable paramlist = pull_params(param, new Hashtable()); List <string> paramlist = new List <string>(); string parampattern = @"(?<block>(?<name>\w+)=""(?<value>.*?)"")"; MatchCollection parammatches = Regex.Matches(param, parampattern); foreach (Match matched in parammatches) { String paramblock = ""; String paramname = ""; String paramvalue = ""; paramblock = matched.Groups["block"].Value; paramname = matched.Groups["name"].Value.ToLower(); paramvalue = renderService.proccessText(new Hashtable(), matched.Groups["value"].Value, false); if (!String.IsNullOrWhiteSpace(paramvalue) && !String.IsNullOrWhiteSpace(paramname)) { paramlist.Add(paramvalue); } } tmp_str = widgetFactoryService.reference_method(controller, paramlist.ToArray()); text = text.Replace(block, tmp_str); } else { if (siteService.debug_mode()) { tmp_str = "Block error"; text = text.Replace(block, tmp_str); } } } } } } return(text); }
/// <summary> </summary> public void help(int iid) { //if (!usedev) filtering.Add(Expression.Eq("revision", 0)); posting post = null; if (iid > 0) { post = ActiveRecordBase <posting> .Find(iid).get_published(); } else { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Eq("is_default", true)); filtering.Add(Expression.Eq("deleted", false)); filtering.Add(Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", "documentation") }.ToArray()) )); post = ActiveRecordBase <posting> .FindFirst(filtering.ToArray()); if (post != null) { post = post.get_published(); } } if (post == null) { post = postingService.get_posting_by_url("/404.html", usedev); Response.StatusCode = 404; } /* Items that should be globaly accessed */ //PropertyBag["campus"] = ActiveRecordBase<campus>.FindAllByProperty("name", "Pullman")[0]; site site = siteService.getCurrentSite(); PropertyBag["site"] = site; PropertyBag["baseurl"] = "admin/help.castle"; PropertyBag["htmlService"] = new htmlService(); /* add site options */ if (site.options != null && site.options.Count > 0) { foreach (options item in site.options) { PropertyBag[item.option_key.ToUpper()] = item.value; //ie: post.get_meta("title"); } } /* add meta */ if (post.meta_data != null && post.meta_data.Count > 0) { foreach (meta_data item in post.meta_data) { PropertyBag[item.meta_key.ToUpper()] = item.value; //ie: post.get_meta("title"); } } String urlQueries = ""; PropertyBag["urlQueries"] = String.IsNullOrWhiteSpace(urlQueries) ? "" : "iid[]=" + urlQueries.TrimStart(','); if (iid > 0) { PropertyBag["urlQueries"] += (String.IsNullOrWhiteSpace(urlQueries) ? "" : "&") + "iid=" + iid.ToString(); } PropertyBag["siteroot"] = httpService.getRootUrl().TrimEnd('/'); PropertyBag["Controller"] = base.MemberwiseClone(); Hashtable content_params = objectService.marge_params(PropertyBag, new Hashtable()); String output = new renderService().render(post, content_params); // bool ActiveRecordBase<site_base>.FindFirst(new List<AbstractCriterion>() { Expression.Eq("name", "minhtml") }.ToArray()) Boolean tmpB = false; if (tmpB) { output = htmlService.stripNonSenseContent(output, false); } //RenderText(output); PropertyBag["content"] = output; RenderView("../admin/default/actions/help"); }
/// <summary> </summary> public String render(posting post, Hashtable param) { String mode = param.ContainsKey("mode") ? param["mode"].ToString() : "published"; posting pub_post = post.get_published(); String tmp_str = pub_post.load_content(mode); if (!PropertyBag.ContainsKey("post_content") && post.post_type.root && !post.post_type.use_layout_templates && !post.post_type.use_posting_templates) { PropertyBag["post_content"] = tmp_str; } posting temp = post.get_template_obj(post.post_type.alias + "_template"); if (temp != null) { tmp_str = renderposting(temp.load_content(mode), post, objectService.marge_params(PropertyBag, param)); } //param.Add("Controller", base.MemberwiseClone()); tmp_str = renderposting(tmp_str, post, objectService.marge_params(PropertyBag, param)); String name = pub_post.name;//for testing only if (post.post_type.is_frontend_editable && post.is_frontend_editable && Controllers.BaseController.editing) { tmp_str = editingService.make_editable(tmp_str, post, areacount++); } if (!PropertyBag.ContainsKey("post_content") && post.post_type.root) { PropertyBag["post_content"] = tmp_str; } Hashtable post_params = objectService.marge_params(PropertyBag, param); /* now process the content template RETHINK THIS */ if (post.post_type.use_posting_templates) { posting posting_template = post.get_template_obj("posting_template"); if (posting_template != null) { tmp_str = renderposting(posting_template.load_content(mode), post, post_params); } if (!PropertyBag.ContainsKey("childContent") && post.post_type.root) { PropertyBag["childContent"] = tmp_str; } } else { if (!PropertyBag.ContainsKey("childContent") && post.post_type.root) { PropertyBag["childContent"] = tmp_str; } } //NOTE THIS SHOULD HAVE FIELDS TEMPLATES SHOULD BE THAT ABLE /* now process the layout */ if (post.post_type.use_layout_templates) { posting layout_template = post.get_template_obj("layout_template"); if (layout_template != null) { tmp_str = renderposting(layout_template.load_content(mode), post, objectService.marge_params(PropertyBag, param)); } } Controllers.BaseController.vardump(post_params, "Post:" + post.name, "<code><pre>${1}</pre></code>"); return(tmp_str); }
/// <summary> </summary> public void posting(int iid, string[] cat, int activeitem, Boolean eb, Boolean hasUrl, string sm_url, Boolean dev) { //posting post = ActiveRecordBase<posting>.Find(iid); List<AbstractCriterion> filtering = new List<AbstractCriterion>(); editing = false; PropertyBag["dev"] = dev; //if (!usedev) filtering.Add(Expression.Eq("revision", 0)); posting post = null; if (iid > 0) { post = ActiveRecordBase<posting>.Find(iid).get_published(); } else { filtering.Add(Expression.Eq("is_default", true)); filtering.Add(Expression.Eq("deleted", false)); filtering.Add(Expression.IsNull("parent")); // the parent null makes it the working copy to first look too filtering.Add(Expression.Eq("post_type", ActiveRecordBase<posting_type>.FindFirst( new List<AbstractCriterion>() { Expression.Eq("alias", "page") }.ToArray()) )); post = ActiveRecordBase<posting>.FindFirst(new Order[] { Order.Desc("revision"), Order.Desc("version") }, filtering.ToArray()); if (post != null) post = post.get_published(); } if(post == null){ post = postingService.get_posting_by_url("/404.html", usedev).get_published(); Response.StatusCode = 404; } /* Items that should be globaly accessed */ PropertyBag["url"] = sm_url; //PropertyBag["campus"] = ActiveRecordBase<campus>.FindAllByProperty("name", "Pullman")[0]; PropertyBag["selected_taxanony"] = cat; PropertyBag["activeitem"] = activeitem; PropertyBag["embeded"] = eb; site site = siteService.getCurrentSite(); PropertyBag["site"] = site; PropertyBag["baseurl"] = "public/posting.castle"; PropertyBag["htmlService"] = HtmlService; /* add site options */ if (site.options != null && site.options.Count > 0) { foreach (options item in site.options) { PropertyBag[item.option_key.ToUpper()] = item.value.ToString();//ie: post.get_meta("title"); } } /* add meta */ if (post.meta_data != null && post.meta_data.Count > 0) { foreach (meta_data item in post.meta_data) { PropertyBag[item.meta_key.ToUpper()] = item.value;//ie: post.get_meta("title"); } } String urlQueries = ""; PropertyBag["urlQueries"] = String.IsNullOrWhiteSpace(urlQueries) ? "" : "iid[]=" + urlQueries.TrimStart(','); if (iid > 0) { PropertyBag["urlQueries"] += (String.IsNullOrWhiteSpace(urlQueries) ? "" : "&") + "iid=" + iid.ToString(); } PropertyBag["siteroot"] = httpService.getRootUrl().TrimEnd('/'); PropertyBag["Controller"] = base.MemberwiseClone(); PropertyBag["mode"] = "published"; posting pub_post = post.get_published(); PropertyBag["post"] = pub_post; Hashtable content_params = objectService.marge_params(PropertyBag, new Hashtable()); String output = new renderService().render(post, content_params); // bool ActiveRecordBase<site_base>.FindFirst(new List<AbstractCriterion>() { Expression.Eq("name", "minhtml") }.ToArray()) Boolean tmpB = false; if (tmpB) output = htmlService.stripNonSenseContent(output, false); RenderText(output); }