/// <summary> </summary> public void show_diff(int parent, int rev1id, int rev2id, Boolean ajxed) { if (ajxed) { CancelLayout(); } posting parent_post = ActiveRecordBase <posting> .Find(parent); posting rev1 = ActiveRecordBase <posting> .FindFirst(new Order("revision", false), new List <AbstractCriterion>() { Expression.Eq("revision", rev1id), Expression.Eq("parent", parent_post) }.ToArray() ); posting rev2 = ActiveRecordBase <posting> .FindFirst(new Order("revision", false), new List <AbstractCriterion>() { Expression.Eq("revision", rev2id), Expression.Eq("parent", parent_post) }.ToArray() ); String text1 = rev1.content; String text2 = rev2.content; PropertyBag["rev1"] = rev1; PropertyBag["rev2"] = rev2; PropertyBag["parent_post"] = parent_post; PropertyBag["rev1text"] = text1; PropertyBag["rev2text"] = text2; PropertyBag["diff"] = cms.utils.Diff.PrintItems(cms.utils.Diff.DiffText(text1, text2, true, true, true)); RenderView("/admin/diff/show_diff.vm"); }
/// <summary> </summary> public static IList <posting> get_postings(String type_alias, Boolean usedev, Boolean deleted, posting parent) { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.IsNull("parent")); //make it the working post filtering.Add(Expression.Eq("deleted", deleted)); filtering.Add(Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", type_alias) }.ToArray()) )); posting[] postlist = ActiveRecordBase <posting> .FindAll(new Order[] { Order.Desc("baseid") }, filtering.ToArray()); List <posting> outputlist = new List <posting>(); if (postlist.Count() > 0) { foreach (posting post in postlist) { posting posting = post.get_published(); if (posting != null) { outputlist.Add(posting); } } } return(outputlist); }
/// <summary> </summary> public static posting_type get_post_type(String alias) { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Eq("alias", alias)); return(ActiveRecordBase <posting_type> .FindFirst(filtering.ToArray())); }
/// <summary> </summary> public static Hashtable make_all_post_json_table(String type, Boolean dev) { Hashtable all = new Hashtable(); Dictionary <string, string> queries = httpService.get_request_parmas_obj(); List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", type) }.ToArray()) )); posting[] posts = ActiveRecordBase <posting> .FindAll(new Order[] { Order.Desc("revision"), Order.Desc("version") }, filtering.ToArray()); var i = 0; foreach (posting post in posts) { String name = (queries.ContainsKey("format") && queries["format"] == "xml") ? ("post_" + i.ToString()) : i.ToString(); all.Add(name, make_post_json_table(post.baseid, type, dev)); i++; } return(all); }
/// <summary> </summary> public void configuration(int siteid) { PropertyBag["frontend_themelist"] = themeService.list_themes(); PropertyBag["posting_types"] = ActiveRecordBase <posting_type> .FindAll(); PropertyBag["posting_type_actions"] = ActiveRecordBase <posting_type_action> .FindAll(); site site_obj = new site(); if (siteid > 0) { site_obj = ActiveRecordBase <site> .Find(siteid); } else { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Eq("is_default", true)); site_obj = ActiveRecordBase <site> .FindFirst(filtering.ToArray()); } PropertyBag["site"] = site_obj; foreach (options option in site_obj.options) { if (!String.IsNullOrWhiteSpace(option.option_key)) { PropertyBag[option.option_key.ToUpper()] = option.value;//ie: post.get_meta("title"); } } RenderView("../admin/configuration"); }
/// <summary> </summary> public static dynamic make_model_property_item <t>(String prop_name) where t : new() { dynamic item = ActiveRecordBase <t> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", prop_name) }.ToArray() ); return(item); }
/// <summary> </summary> public static taxonomy get_taxonomy(String alias) { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Eq("alias", alias)); taxonomy taxonomy = ActiveRecordBase <taxonomy> .FindFirst(filtering.ToArray()); return(taxonomy); }
/// <summary> </summary> public static IList <taxonomy> get_taxonomies(String type_alias) { return(ActiveRecordBase <taxonomy> .FindAll( new List <AbstractCriterion>() { Expression.Eq("taxonomy_type", ActiveRecordBase <taxonomy_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", type_alias) }.ToArray() )) }.ToArray() )); }
public users setUser() { List <AbstractCriterion> userEx = new List <AbstractCriterion>(); userEx.Add(Expression.Eq("nid", getNid())); users user = ActiveRecordBase <users> .FindFirst(userEx.ToArray()); HttpContext.Current.Session["you"] = user; return(user); }
public virtual bool IsChangePasswordByOneself() { var log = ActiveRecordBase <PasswordChangeLogEntity> .FindFirst( DetachedCriteria.For <PasswordChangeLogEntity>() .Add(Restrictions.Eq("TargetUserName", Login)) .AddOrder(Order.Desc("LogTime"))); if (log == null) { return(false); } return(log.IsChangedByOneSelf()); }
/// <summary> </summary> public static string get_field_value(field_types field_type, posting _post) { string value = ""; List <AbstractCriterion> typeEx = new List <AbstractCriterion>(); typeEx.Add(Expression.Eq("type", field_type)); if (!object.ReferenceEquals(_post, null)) { typeEx.Add(Expression.Eq("owner", _post.baseid)); } fields field = ActiveRecordBase <fields> .FindFirst(typeEx.ToArray()); value = fieldsService.getFieldVal(field_type, field); return(value); }
/// <summary> </summary> public static string get_field(field_types field_type, dynamic item) { List <AbstractCriterion> typeEx = new List <AbstractCriterion>(); typeEx.Add(Expression.Eq("type", field_type)); if (!object.ReferenceEquals(item, null)) { typeEx.Add(Expression.Eq("owner", item.baseid)); } fields field = ActiveRecordBase <fields> .FindFirst(typeEx.ToArray()); string ele_str = fieldsService.getfieldmodel_dynamic(field_type, field == null ? null : field.value.ToString()); return(ele_str); }
public int placeByURL_id(string url) { List <AbstractCriterion> baseEx = new List <AbstractCriterion>(); baseEx.Add(Expression.Eq("CustomUrl", url)); place place = ActiveRecordBase <place> .FindFirst(baseEx.ToArray()); if (place != null) { return(place.id); } else { return(0); } }
/// <summary> </summary> public static int get_last_revision(dynamic item) { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Gt("revision", 0)); filtering.Add(Expression.Eq("deleted", false)); filtering.Add(Expression.Eq("parent", item)); filtering.Add(Expression.Eq("version", item.version)); posting lastversion = ActiveRecordBase <posting> .FindFirst( new Order[] { Order.Desc("revision") }, filtering.ToArray() ); int rev = lastversion != null ? lastversion.revision : 0; return(rev); }
/// <summary> </summary> public static taxonomy get_taxonomy(String prefix, String alias, String taxonomy_type) { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Eq("alias", String.IsNullOrWhiteSpace(prefix) ? "" : prefix + "__" + alias)); filtering.Add(Expression.Eq("taxonomy_type", ActiveRecordBase <taxonomy_type> .FindAll( new List <AbstractCriterion>() { Expression.Eq("alias", taxonomy_type) }.ToArray() ).FirstOrDefault())); taxonomy taxonomy = ActiveRecordBase <taxonomy> .FindFirst(filtering.ToArray()); if (taxonomy == null) { taxonomy = get_taxonomy(alias); //fallback on single } return(taxonomy); }
/// <summary> </summary> public posting_type getPostType(String posttype) { posting tmp = new posting(); tmp.tmp = true; dynamic type; if (String.IsNullOrWhiteSpace(posttype)) { type = ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("_default", 1) }.ToArray() ); } else { type = ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", posttype) }.ToArray() ); } return(type); }
/// <summary> </summary> public static IList <posting> get_general_postings(String type_alias, Boolean usedev, Boolean deleted, posting parent) { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); if (parent == null) { filtering.Add(Expression.IsNull("parent")); } else { filtering.Add(Expression.Eq("parent", parent)); } filtering.Add(Expression.Eq("deleted", deleted)); filtering.Add(Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", type_alias) }.ToArray()) )); posting[] postlist = ActiveRecordBase <posting> .FindAll(new Order[] { Order.Desc("baseid") }, filtering.ToArray()); return(postlist); }
//this = posting /// <summary> </summary> virtual public posting get_template_obj(String type) { if (!this.is_templatable) { return(null); } posting post_obj = ActiveRecordBase <posting> .Find(this.baseid); posting[] templatelist = ActiveRecordBase <posting> .FindAll(new Order[] { Order.Asc("baseid") }, new List <AbstractCriterion>() { Expression.Eq("deleted", false), Expression.IsNull("parent"), // the parent null makes it the working copy Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", type) }.ToArray() ) ) }.ToArray() ); if (templatelist.Length > 0) { templatelist = templatelist.Where( x => (x.postchildren.Contains(post_obj) && post_obj.postparents.Contains(x) || (post_obj.postparents.Count == 0 && x.is_default) )).ToArray(); if (templatelist.Length > 0) { posting template = templatelist.First(); return(template); } } return(null); }
/// <summary> </summary> public void posting(int iid, string[] cat, int activeitem, Boolean eb, Boolean hasUrl, string sm_url, Boolean dev) { List <AbstractCriterion> filtering = new List <AbstractCriterion>(); editing = true; PropertyBag["dev"] = dev; //if (!usedev) filtering.Add(Expression.Eq("revision", 0)); if (iid > 0) { posting tmp = ActiveRecordBase <posting> .Find(iid); if (tmp.children.Count > 0) { filtering.Add(Expression.Eq("parent", tmp)); } else { filtering.Add(Expression.Eq("baseid", iid)); } } else { filtering.Add(Expression.Eq("is_default", true)); //parent filtering.Add(Expression.Eq("deleted", false)); filtering.Add(Expression.In("post_type", ActiveRecordBase <posting_type> .FindAll( new List <AbstractCriterion>() { Expression.Eq("root", true) }.ToArray()) )); } posting post = ActiveRecordBase <posting> .FindFirst(new Order[] { Order.Desc("revision"), Order.Desc("version") }, filtering.ToArray()); PropertyBag["post"] = post; //posting post = ActiveRecordBase<posting>.Find(iid); posting[] lastversions = ActiveRecordBase <posting> .FindAll(Order.Asc("revision"), new List <AbstractCriterion>() { Expression.Eq("parent", post), Expression.Gt("revision", 0) }.ToArray() ); PropertyBag["lastversions"] = lastversions; /* 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["siteroot"] = httpService.getRootUrl().TrimEnd('/'); PropertyBag["baseurl"] = "visible_editor/posting.castle"; PropertyBag["htmlService"] = HtmlService; // maybe get rid of this? PropertyBag["Controller"] = base.MemberwiseClone(); /* add site options */ 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) { 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["mode"] = "published"; Hashtable content_params = objectService.marge_params(PropertyBag, new Hashtable()); String output = new renderService().render(post, content_params); output = editingService.ini_editor(output, post, PropertyBag); RenderText(output); }
/// <summary> /// This take a file, regardless of if there is a post already for this file, /// and ingests it to the database as a posting. /// </summary> /// <param name="file">What file to use</param> /// <param name="name">Basic post data.</param> /// <param name="theme">What theme should it respond to?</param> /// <param name="posting_type">What posting type should be used</param> /// <param name="mode"></param> /// <param name="version">The starting version</param> /// <param name="revision">The starting revision</param> /// <param name="user">the user the post belongs to</param> /// <param name="loads_file">Should the post use the file or the database.</param> /// <returns></returns> /// <remarks>A new pst from file may only be created from a file with in the working folder or it'll fail to make the post.</remarks> public static posting create_post_from_file(String file, String name, String theme, String posting_type, String mode, int version, int revision, appuser user, Boolean loads_file) { posting doc_tmp = new posting(); site site = siteService.getCurrentSite(); file = file_handler.normalize_path(file); String[] fpath = file.Split(new string[] { posting_type + "/" }, StringSplitOptions.None); String static_file = fpath[fpath.Length - 1].Trim('/'); String dst = ""; String basepath = themeService.theme_path(site, theme, mode, posting_type); dst = basepath.Trim('/') + "/" + static_file.Trim('/'); if (!file_info.file_exists(dst)) { basepath = themeService.theme_path(site, "base", mode, posting_type); dst = basepath.Trim('/') + "/" + static_file.Trim('/'); } /*if (!file_info.is_relative_path(file)) { //if it's not absoulte then lets try to figure out what was wanted * } else { * //the path was absolute so lets trust it's what was meant to be * dst = file; * }*/ if (file_info.file_exists(dst)) { posting_type ptype = ActiveRecordBase <posting_type> .FindFirst(new List <AbstractCriterion>() { Expression.Eq("alias", posting_type) }.ToArray()); Hashtable fileinfo = get_post_file_info(dst); // if there was any file metadata that belongs to this app, apply it to the post doc_tmp = new posting() { loads_file = loads_file, static_file = static_file, content = file_handler.read_from_file(dst), post_type = ptype, useTiny = ptype.useTiny, is_Code = ptype.is_Code, owner = user, editors = new List <appuser>() { user } }; // loop over the object properties and see if they are in the file meta info // if they are apply them. List <string> properties = objectService.get_type_properties("posting"); foreach (String property in fileinfo.Keys) { if (properties.Contains(property)) { PropertyInfo propInfo = doc_tmp.GetType().GetProperty(property); if (propInfo != null) { String prop_type = propInfo.PropertyType.Namespace; if (prop_type == "System") { String value = fileinfo[property].ToString(); if (value != null && value != "") { dynamic val = Convert.ChangeType(value, propInfo.PropertyType, CultureInfo.InvariantCulture); propInfo.SetValue(doc_tmp, val, null); } } } } } ActiveRecordMediator <posting> .SaveAndFlush(doc_tmp); //backup minimums for a respectably factioning out object if (String.IsNullOrWhiteSpace(doc_tmp.name)) { doc_tmp.name = name; } if (String.IsNullOrWhiteSpace(doc_tmp.alias)) { doc_tmp.alias = doc_tmp.name.Replace(' ', '-').ToLower(); } if (doc_tmp.version > 0) { doc_tmp.version = version; } if (doc_tmp.revision > 0) { doc_tmp.revision = revision; } if (String.IsNullOrWhiteSpace(doc_tmp.theme)) { doc_tmp.theme = theme; } if (fileinfo["is_core"] == null) { doc_tmp.is_core = ptype.is_core; } if (fileinfo["is_admin"] == null) { doc_tmp.is_admin = ptype.is_admin; } if (fileinfo["is_frontend_editable"] == null) { doc_tmp.is_frontend_editable = true; } if (fileinfo["is_visible"] == null) { doc_tmp.is_visible = true; } if (fileinfo["is_default"] == null) { doc_tmp.is_default = true; } ActiveRecordMediator <posting> .Save(doc_tmp); doc_tmp = versionService.make_working_post(doc_tmp, static_file); } return(doc_tmp); }
public static T FindFirstByProperties(params object[] nameAndValues) { return(ActiveRecordBase <T> .FindFirst(EntityBase <T> .GetCriteriaByProperties(nameAndValues), new Order[0])); }
/// <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 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); }
/// <summary> /// 根据非ID字段查询实体 /// </summary> /// <param name="queryConditions"></param> /// <returns></returns> public T GetFirstEntityByFields(IList <ICriterion> queryConditions, IList <Order> orderList) { return(ActiveRecordBase.FindFirst(typeof(T), orderList.ToArray(), queryConditions.ToArray()) as T); }
public void Update([ARDataBind("user", Validate = true, AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey)] users user, [ARDataBind("image", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] media_repo image, HttpPostedFile newimage, int[] Sections, string apply, string cancel) { if (cancel != null) { RedirectToAction("list"); return; } if (cancel != null) { RedirectToAction("list"); return; } if (user.groups.id <= 0) { List <AbstractCriterion> baseEx = new List <AbstractCriterion>(); baseEx.Add(Expression.Eq("default", true)); user.groups = ActiveRecordBase <user_groups> .FindFirst(baseEx.ToArray()); } /* * author.place_types.Clear(); * foreach (int section in Sections) * { * place_types tmp=ActiveRecordBase<place_types>.Find(section); * if (!author.place_types.Contains(tmp) && tmp.id > 0) * { * author.place_types.Add(tmp); * } * } * * user.media.Clear(); * * try { * * } catch (Exception ex) { * Flash["error"] = ex.Message; * Flash["author"] = user; * }*/ ActiveRecordMediator <users> .Save(user); /* * ActiveRecordMediator<media_repo>.Save(image); * if (newimage.ContentLength != 0) * { * String Fname = System.IO.Path.GetFileName(newimage.FileName); * String[] fileparts = Fname.Split('.'); * if (String.IsNullOrEmpty(image.file_name)) * { * image.file_name = fileparts[0]; * } * image.ext = fileparts[1]; * * //set up the image up from the stream * System.Drawing.Image processed_image = System.Drawing.Image.FromStream(newimage.InputStream); * * // a var for uploads will start here * String uploadPath = Context.ApplicationPhysicalPath + @"\uploads\mugshots\"; * * if (!HelperService.DirExists(uploadPath)) * { * System.IO.Directory.CreateDirectory(uploadPath); * } * string newFile = uploadPath + image.id + ".ext"; * //helperService.ResizeImage(newimage, uploadPath + image.id + ".ext", 1000, 1000, true); * imageService.process(image.id, processed_image, newFile, ImageService.imageMethod.Constrain, 0, 0, 1000, ImageService.Dimensions.Width, true, "", image.ext); * * ActiveRecordMediator<media_repo>.Save(image); * author.media.Add(image); * } */ RedirectToAction("list"); }
/// <summary> </summary> public void posting_list(string post_type, int page, int searchId, string target, string filter, Boolean ajax, bool skiplayout, Boolean show_core) { posting_type postType = getPostType(post_type); userService.clearConnections <posting>(); var pageing = new Dictionary <string, int>(); switch (target) { case "templates": { pageing.Add("templatePaging", page); break; } case "name_types": { pageing.Add("name_typesPaging", page); break; } case "types": { pageing.Add("typesPaging", page); break; } case "draft": { pageing.Add("draftPaging", page); break; } case "review": { pageing.Add("reviewPaging", page); break; } case "published": { pageing.Add("publishedPaging", page); break; } case "filteredResults": { pageing.Add("filterPaging", page); break; } default: { pageing.Add("AllPaging", page); break; } } //SETUP SEARCHID and parts if (searchId.Equals(0)) { searchId = -2; } else { //event_type type = new event_type(); } PropertyBag["searchId"] = searchId; //user.categories.Contains(events.categories); //IList<cal_events> items; int pagesize = 15; List <AbstractCriterion> baseEx = new List <AbstractCriterion>(); if (searchId > 0) { // find all places of cat IList <_base> cats = ActiveRecordBase <posting> .FindAll(new Order("sort", false), new List <AbstractCriterion>() { Expression.Eq("deleted", false), Expression.Eq("revision", 0), Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", "page") }.ToArray() ) ) }.ToArray() ); IList <posting> pitems = new List <posting>(); foreach (_base c in cats) { foreach (posting p in c.children.Where(x => x.GetType().Name.Contains(postType.alias))) { pitems.Add(p); } } int[] obj = new int[pitems.Count]; int i = 0; foreach (posting p in pitems) { obj[i] = p.baseid; i++; } baseEx.Add(Expression.In("baseid", obj)); } if (searchId.Equals(-2)) { IList <posting> userevents = userService.getUserFull().getUserPostings(); object[] obj = new object[userevents.Count]; int i = 0; foreach (posting e in userevents) { obj[i] = e.baseid; i++; } baseEx.Add(Expression.In("baseid", obj)); } String cachePath = file_info.root_path(); IList <string> buttons = new List <string>(); int pag = 0; if (!String.IsNullOrWhiteSpace(filter)) { List <posting> listtems = searchService.filterPage(filter.Replace("+", " ")); PropertyBag["filteredResults_list"] = PaginationHelper.CreatePagination((IList)listtems, 15, (pageing.TryGetValue("fliterPaging", out pag) ? pag : 0)); buttons = new List <string>(); foreach (posting_type_action action in postType.actions) { buttons.Add(action.alias); } PropertyBag["filteredResults_ButtonSet"] = buttons; } string name = "All"; List <AbstractCriterion> revEx = new List <AbstractCriterion>(); revEx.AddRange(baseEx); revEx.Add(Expression.Eq("deleted", false)); revEx.Add(Expression.Eq("post_type", postType)); PropertyBag["show_core"] = true; if (!show_core) { revEx.Add(Expression.Not(Expression.Eq("is_core", true))); PropertyBag["show_core"] = false; } IList <posting> listing_tems = ActiveRecordBase <posting> .FindAll(new Order[] { Order.Desc("sort") }, revEx.ToArray()) .Where(x => x.parent == null).ToArray(); PropertyBag[name + "_list"] = PaginationHelper.CreatePagination(listing_tems, pagesize, (pageing.TryGetValue(name + "Paging", out pag) ? pag : 0)); buttons = new List <string>(); foreach (posting_type_action action in postType.actions) { buttons.Add(action.alias); } PropertyBag[name + "ButtonSet"] = buttons; PropertyBag["users"] = ActiveRecordBase <appuser> .FindAll(); PropertyBag["user_groups"] = ActiveRecordBase <user_group> .FindAll(); PropertyBag["statuses"] = new List <string> { "All" }; PropertyBag["ajax"] = ajax; PropertyBag["named_type"] = postType.alias; PropertyBag["named_type_dname"] = postType.name; PropertyBag["itemNamed"] = "post";// postType.alias; if (!skiplayout) { RenderView("../admin/listings/list"); } }
/// <summary> </summary> public static Hashtable make_post_json_table(int iid, String type, Boolean dev) { //posting post = ActiveRecordBase<posting>.Find(iid); List <AbstractCriterion> filtering = new List <AbstractCriterion>(); //if (!usedev) filtering.Add(Expression.Eq("revision", 0)); if (iid > 0) { posting tmp = ActiveRecordBase <posting> .Find(iid); if (tmp.children.Count > 0) { filtering.Add(Expression.Eq("parent", tmp)); } else { filtering.Add(Expression.Eq("baseid", iid)); } } else { filtering.Add(Expression.Eq("is_default", true)); } //parent filtering.Add(Expression.Eq("deleted", false)); if (!String.IsNullOrWhiteSpace(type)) { filtering.Add(Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", type) }.ToArray()) )); } posting post = ActiveRecordBase <posting> .FindFirst(new Order[] { Order.Desc("revision"), Order.Desc("version") }, filtering.ToArray()); Hashtable post_json_obj = new Hashtable(); Hashtable post_options_object = new Hashtable(); String post_type = post.post_type.alias; List <string> properties = objectService.get_type_properties("posting"); Assembly assembly = Assembly.GetExecutingAssembly(); dynamic item = assembly.CreateInstance("stellar.Models." + type); foreach (String prop in properties) { PropertyInfo propInfo = post.GetType().GetProperty(prop); String prop_type = propInfo.PropertyType.Namespace; if (prop_type == "System") //keep it to the basics to aviod a circular reference while serializing { dynamic value = propInfo.GetValue(post, null); if (prop == "static_file") { if (post.post_type.alias == "media") { string uploads_path = file_info.relative_site_uploads_path(); string[] generalized_file_path = value.Split(new String[] { "uploads/", "images/" }, StringSplitOptions.RemoveEmptyEntries); string file_path = file_handler.normalize_path(uploads_path.Trim('/') + "/images/" + generalized_file_path[generalized_file_path.Length - 1].Trim('/')); value = file_path; } } post_options_object.Add(prop, value); } } Hashtable post_content_object = new Hashtable(); post_content_object.Add("is_Code", post.is_Code); post_content_object.Add("useTiny", post.useTiny); List <Hashtable> post_partents = new List <Hashtable>(); foreach (posting par_post in post.postparents) { Hashtable post_partent = new Hashtable(); post_partent.Add("id", par_post.baseid); post_partent.Add("alias", par_post.alias); post_partent.Add("name", par_post.name); post_partent.Add("post_type", par_post.post_type.alias); post_partents.Add(post_partent); } post_content_object.Add("post_parents", post_partents); List <Hashtable> post_children = new List <Hashtable>(); foreach (posting par_post in post.postchildren) { Hashtable post_child = new Hashtable(); post_child.Add("id", par_post.baseid); post_child.Add("alias", par_post.alias); post_child.Add("name", par_post.name); post_child.Add("post_type", par_post.post_type.alias); post_children.Add(post_child); } post_content_object.Add("post_children", post_children); List <Hashtable> post_editors = new List <Hashtable>(); foreach (appuser par_post in post.editors) { Hashtable post_editor = new Hashtable(); post_editor.Add("id", par_post.baseid); post_editor.Add("alias", par_post.nid); post_editor.Add("name", par_post.display_name); post_editors.Add(post_editor); } post_content_object.Add("editors", post_editors); post_content_object.Add("fields", post.fields); post_content_object.Add("content", post.content); post_content_object.Add("post_type", post.post_type.alias); post_json_obj.Add("post_content", post_content_object); post_json_obj.Add("post_options", post_options_object); post_json_obj.Add("meta_data", post.get_all_meta()); post_json_obj.Add("post_id", post.baseid); return(post_json_obj); }
/// <summary> </summary> public static DTOBase Create(FileInfo info, Root root, Hashtable posting_json_obj) { if (info == null) { throw new ArgumentNullException("info"); } if (root == null) { throw new ArgumentNullException("root"); } string ext = info.Extension.ToLower(); string parentPath = info.Directory.FullName.Substring(root.Directory.FullName.Length); FileDTO response; String relative_path = info.FullName.Substring(root.Directory.FullName.Length); string hash = root.VolumeId + file_helper.encode_path(relative_path); if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || info.Extension == ".gif") { response = new ImageDTO(); } else { response = new FileDTO(); } response.read = 1; response.write = root.IsReadOnly ? (byte)0 : (byte)1; response.locked = root.IsReadOnly ? (byte)1 : (byte)0; response.name = info.Name; response.size = info.Length; response.ts = (long)(info.LastWriteTimeUtc - _unixOrigin).TotalSeconds; response.mime = file_helper.get_mime_type(info); response.hash = hash; response.phash = root.VolumeId + file_helper.encode_path(parentPath.Length > 0 ? parentPath : info.Directory.Name); Hashtable post = new Hashtable(); int pid = 0; posting posting = postingService.get_posting_by_hash(hash, false); pid = posting.baseid; if (pid > 0) { post = postingService.make_post_json_table(pid); } else { posting = postingService.get_posting_by_file(relative_path, false); pid = posting.baseid; if (pid > 0) { post = postingService.make_post_json_table(pid); if (String.IsNullOrWhiteSpace(posting.filehash)) { posting.filehash = hash; ActiveRecordMediator <posting> .Save(posting); } } else { if (HttpContext.Current.Request.Params.AllKeys.Contains("iid")) { pid = Int16.Parse(HttpContext.Current.Request.Params["iid"]); post = postingService.make_post_json_table(pid); } else { if (HttpContext.Current.Request.Params.AllKeys.Contains("ptype")) { //Boolean dev = false; // for now String type = HttpContext.Current.Request.Params["ptype"]; Hashtable all = new Hashtable(); Dictionary <string, string> queries = httpService.get_request_parmas_obj(); List <AbstractCriterion> filtering = new List <AbstractCriterion>(); filtering.Add(Expression.Eq("post_type", ActiveRecordBase <posting_type> .FindFirst( new List <AbstractCriterion>() { Expression.Eq("alias", type) }.ToArray()) )); posting[] posts = ActiveRecordBase <posting> .FindAll(new Order[] { Order.Desc("revision"), Order.Desc("version") }, filtering.ToArray()); //var i = 0; foreach (posting posted in posts) { if (posted.static_file.IndexOf(info.Name) > -1) { pid = posted.baseid; } post = postingService.make_post_json_table(pid); } } } } } response.post = post; if (pid > 0 && (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || info.Extension == ".gif")) { //response = new ImageDTO(); String path = image_handler.image(pid, 50, 50, 0, "constrain", false, "thumb_", "", false); String[] path_parts = path.Split(new string[] { "uploads/" }, StringSplitOptions.None); //note that the root will always be uploads? well it is atm ((ImageDTO)response).tmb = path_parts[path_parts.Length - 1].Trim('/'); } return(response); }
/// <summary> </summary> public void update_user( [ARDataBind("user", Validate = true, AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey)] appuser user, [ARDataBind("image", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting image, HttpPostedFile newimage, int[] Sections, string apply, string cancel, Boolean ajaxed, String[] value, String[] meta_key ) { if (user.user_meta_data != null) { user.user_meta_data.Clear(); } else { user.user_meta_data = new List <user_meta_data>(); } int i = 0; foreach (String item in value) { user_meta_data tmp = new user_meta_data() { value = item, meta_key = meta_key[i] }; i++; user.user_meta_data.Add(tmp); } if (cancel != null) { RedirectToAction("list_user"); return; } if (user.groups == null || user.groups.baseid == 0) { List <AbstractCriterion> baseEx = new List <AbstractCriterion>(); baseEx.Add(Expression.Eq("default_group", true)); baseEx.Add(Expression.Eq("isAdmin", true)); user.groups = ActiveRecordBase <user_group> .FindFirst(baseEx.ToArray()); } try { ActiveRecordMediator <appuser> .Save(user); if (user == userService.getUser()) { userService.setUser(); } } catch (Exception ex) { Flash["error"] = ex.Message; Flash["user"] = user; } if (apply != null || ajaxed) { logger.writelog("Applied user edits", getView(), getAction(), user.baseid); if (user.baseid > 0) { if (ajaxed) { CancelLayout(); RenderText(user.baseid.ToString()); } else { RedirectToUrl("~/users/edit_user.castle?id=" + user.baseid); } return; } else { RedirectToReferrer(); return; } } else { logger.writelog("Saved user edits on", getView(), getAction(), user.baseid); RedirectToAction("list_users"); return; } }
// 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); }