/// <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> /// 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); }