/* all parent posts are a working copy so we never 'make' this one * /// <summary> * /// In the version handling process this is the first stop. This will make a copy of the object * /// and or file (in the site_content>>...>>working folder) and make version adjustments to match. * /// Really, it should only be done on the first ingestion of the post. * /// </summary> * /// <param name="post"></param> * /// <param name="version"></param> * /// <param name="revision"></param> * /// <retruns></retruns> * public static posting make_post_working_version(posting post, int version, int revision) { * //first since the working version is the start of the edit saving process, we will * //only have to do something if this is a file * posting_type type = post.post_type; * posting working_post = copy_post_to_post(new posting(), post); * * if (working_post.loads_file) { * // get the content * String content = working_post.content; * * if (!String.IsNullOrWhiteSpace(working_post.static_file)) { * String fullpath = file_handler.true_file_path(working_path().Trim('/') + "/" + working_post.static_file.Trim('/')); * content = file_handler.read_from_file(fullpath); * } * String dst = working_post.static_file; * * if (file_info.does_in_content_metadata(file_info.file_extension(dst))) { * content = postingService.create_post_file_info(working_post) + "\r\n" + postingService.strip_post_file_info(content); * working_post.content = content; * dst = remove_filepath_version(working_post.static_file); * } * * if (!String.IsNullOrWhiteSpace(working_post.static_file)) { * dst = working_path().Trim('/') + "/" + type.alias + "/" + dst.Trim('/'); * * String dir = Path.GetDirectoryName(dst); * if (!Directory.Exists(dir)) { * DirectoryInfo di = Directory.CreateDirectory(dir); * } * file_handler.write_to_file(dst, content); * } * } * * if (working_post.parent == null || working_post.parent.baseid <=0) * working_post.parent = post; * * ActiveRecordMediator<posting>.Save(working_post); * return working_post; * } * * //MAY BE update working? */ //DB to File (um hardcoded?) /// <summary> </summary> public static String make_post_working_file(posting working_post, String file) { String dst = file; String content = file_handler.read_from_file(dst); if (file_info.does_in_content_metadata(file_info.file_extension(dst))) { content = postingService.create_post_file_info(working_post) + "\r\n" + content; dst = remove_filepath_version(dst); } String basepath = "/working/" + working_post.post_type.alias + "/" + dst.Trim('/'); dst = file_info.site_content_path().Trim('/') + basepath; String dir = Path.GetDirectoryName(dst); if (!Directory.Exists(dir)) { DirectoryInfo di = Directory.CreateDirectory(dir); } if (!String.IsNullOrWhiteSpace(content)) { file_handler.write_to_file(dst, content); } else { dst = file; } return(dst); }
/// <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 Boolean restorePost(posting post, int version, int revision) { posting copy = null; String dest = ""; if (copy.loads_file) { String[] fileparts = copy.static_file.Split('.'); dest = fileparts[0] + "." + version + "." + revision + "." + fileparts[0]; } try { copy = make_revision <posting>(post.baseid, version, revision); if (copy != null) { if (copy.loads_file) { file_handler.copyfile(copy.static_file, dest); } } return(true); } catch { ActiveRecordMediator <dynamic> .Delete(copy); if (!String.IsNullOrWhiteSpace(dest)) { file_handler.deletefile(dest); } return(false); } }
/* from file that exists */ /// <summary> </summary> public void createNewFile(object[] media) { posting mediaObj = (posting)media[0]; String types_path = getUploadsPath("image\\" + mediaObj.taxonomy_types.First().alias + "\\" + mediaObj.taxonomy_types.First().alias, false); String url = getUploadsURL("image", true); string newFilePath = types_path + mediaObj.id + ".ext"; string FileName = mediaObj.id + ".ext"; byte[] contents = null; contents = File.ReadAllBytes(HttpContext.Server.MapPath(mediaObj.static_file)); MemoryStream memoryStream = new MemoryStream(contents); System.Drawing.Image processed_image = null; processed_image = System.Drawing.Image.FromStream(memoryStream); try { log.Info("preping StartTheThread for " + mediaObj.static_file + " with id " + mediaObj.id + " at path " + newFilePath); StartTheThread(mediaObj, processed_image, newFilePath); } catch { log.Error("Failed trying to StartTheThread for " + mediaObj.static_file + " with id " + mediaObj.id + " at path " + newFilePath); } }
/// <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 void applyMediaToObject(posting media, int id, string type) { switch (type) { case "events": posting events = ActiveRecordBase <posting> .Find(id); //events.images.Add(media);//FIX IT ActiveRecordMediator <posting> .Save(events); //events.Save(); // So this should be abstracted to the bottom where the events is a var and same with the id String cachePath = file_info.root_path(); cachePath += @"uploads\"; cachePath += @"events\cache\"; string file = events.id + "_centralevents" + ".ext"; String file_path = cachePath + file; if (File.Exists(file_path)) { File.Delete(file_path); } break; } }
/// <summary> </summary> public void save_stub([ARDataBind("item", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting item, String post_type, Boolean skiplayout ) { if (skiplayout) { CancelLayout(); } CancelView(); item.site = siteService.getCurrentSite(); item.theme = themeService.current_theme_alias(); item.published = false; appuser user = userService.getUserFull(); item.owner = user; item.editors = new List <appuser>() { user }; item.post_type = getPostType(post_type); item.alias = item.name.Replace(' ', '-').ToLower();//should add a check here ActiveRecordMediator <posting> .Save(item); RenderText("true"); }
/// <summary> </summary> public string[] get_feild_short_codes(posting cal_events) { //log.Info("________________________________________________________________________________\nLoading feilds For:" + place.prime_name+"("+place.baseid+")\n"); List <AbstractCriterion> typeEx = new List <AbstractCriterion>(); typeEx.Add(Expression.Eq("model", "placeController")); // typeEx.Add(Expression.Eq("set", cal_events.model.baseid)); field_types[] ft = ActiveRecordBase <field_types> .FindAll(typeEx.ToArray()); List <string> fields = new List <string>(); string[] codes = new string[ft.Length]; int i = 0; if (ft != null) { foreach (field_types ft_ in ft) { codes[i] = "${" + ft_.alias + "}"; i++; } } return(codes); }
/* this, the process order, bubbles out ... when started it bubbles in, like the event box model in html*/ /// <summary> </summary> public static String simple_field_layout(String text, posting post, Hashtable param) { string processed = renderService.proccessText(param, text, false); string feild = renderService.field_processing(processed, post, param); return(new renderService().processContentblocks(feild, post, param)); }
/// <summary> </summary> public string process_fields(string text, posting place, Hashtable param) { String result = text; if (place.post_type != null) { List <AbstractCriterion> typeEx = new List <AbstractCriterion>(); typeEx.Add(Expression.Eq("type", place.post_type.alias)); field_types[] ft = ActiveRecordBase <field_types> .FindAll(typeEx.ToArray()); List <string> fields = new List <string>(); if (ft != null) { foreach (field_types ft_ in ft) { string value = ""; if (text.Contains("$!{" + ft_.alias + "}")) { //log.Error("on field:" + ft_.alias); value = get_field_value(ft_, place); result = result.Replace("$!{" + ft_.alias + "}", value); PropertyBag["" + ft_.alias] = value; } } } } return(result); }
public ActionResult change(posting post) { var model = new List <posting>(); string usdsa = Request.Form["111"]; Session["111"] = usdsa; return(RedirectToAction("join", "join")); }
/// <summary> </summary> public Thread StartTheThread(posting media, System.Drawing.Image processed_image, string tmp_File) { log.Info("StartTheThread for " + media.static_file + " with id " + media.id + " at path " + tmp_File); var t = new Thread(() => new image_handler().process(media.id, processed_image, tmp_File, image_handler.imageMethod.Constrain, 0, 0, 1000, image_handler.Dimensions.Width, true, "", media.get_meta("ext"))); t.Start(); return(t); }
/// <summary> </summary> public void restorePostRevision(int id) { posting post = ActiveRecordBase <posting> .Find(id); if (versionService.restorePost(ActiveRecordBase <posting> .Find(post.parent.baseid), post.version, post.revision)) { Flash["message"] = "Restored post " + post.name + "."; logger.writelog("Restored post " + post.name + "", getView(), getAction(), post.baseid); } CancelLayout(); RedirectToAction("posting_list", new string[] { "post_type=" + post.post_type.alias }); }
/// <summary> </summary> public void list_revisions(int id) { posting post = ActiveRecordBase <posting> .Find(id); posting[] lastversions = ActiveRecordBase <posting> .FindAll(new Order("revision", false), new List <AbstractCriterion>() { Expression.Eq("parent", post), Expression.Gt("revision", 0) }.ToArray() ); PropertyBag["full"] = true; PropertyBag["lastversions"] = lastversions; RenderView("../admin/postings/post_blocks/revisions"); }
/// <summary> </summary> public void render() { // I don't like this.. need a better way to tell it's installed. More passive, //like change the config file and reload it then read it from there the rest of the time?? if (!Controllers.installController.is_installed()) Controllers.installController.start_install(); /* * get regisitored routes * test if uri matches * get ogject id * get object * get query params * go to action with params * if no action or route 404 * on eception 5xx */ HttpRequest httpRequest = HttpContext.Current.Request; if (httpRequest.Browser.IsMobileDevice) { HttpContext.Current.Response.Redirect("http://goo.gl/maps/4P71"); } String everUrl = Context.Request.Url; // URL comes in like http://sitename/edit/dispatch/handle404.castle?404;http://sitename/pagetorender.html // So strip it all out except http://sitename/pagetorender.html everUrl = Regex.Replace(everUrl, "(.*:80)(.*)", "$2"); everUrl = Regex.Replace(everUrl, "(.*:443)(.*)", "$2"); String urlwithnoparams = Regex.Replace(everUrl, @"(.*?)(\?.*)", "$1"); String querystring = HttpUtility.UrlDecode(Regex.Replace(everUrl, @"(.*?)(\?.*)", "$2")); Dictionary<string, string> queryparams = httpService.getUrlQueries(urlwithnoparams, querystring); //String sitePath = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority); CancelView(); int id = 0; Boolean usedev = (querystring.IndexOf("dev=1") > -1); urlwithnoparams = urlwithnoparams.Replace("/ams/", "/"); posting post = (!String.IsNullOrWhiteSpace(urlwithnoparams))?postingService.get_posting_by_url(urlwithnoparams, usedev): new posting(); if(post.baseid>0) id = post.baseid; //check is it a real place or do 404 if (!String.IsNullOrWhiteSpace(urlwithnoparams) && urlwithnoparams != "/" && post.baseid == 0) { id = postingService.get_posting_by_url("/404.html", usedev).baseid; Response.StatusCode = 404; } //check if we need to login if (post.baseid > 0 && !post.is_Public && !Context.Request.IsLocal && Controllers.BaseController.authenticated()) { Redirect("center", "login", new Hashtable()); } posting(id,usedev); return; }
/// <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); }
//Should be benign to a working post but refit a published or revision configured post /// <summary> </summary> public static posting make_working_post(posting working_post, String file) { if (String.IsNullOrWhiteSpace(file)) { file = working_post.static_file; } String dst = remove_filepath_version(file); String content = file_handler.read_from_file(dst); String basepath = relative_working_path().Trim('/') + "/" + working_post.post_type.alias; dst = basepath + "/" + dst.Trim('/'); String dir = Path.GetDirectoryName(dst); if (!Directory.Exists(dir)) { DirectoryInfo di = Directory.CreateDirectory(dir); } if (String.IsNullOrWhiteSpace(content)) { content = file_handler.read_from_file(dst); } if (!String.IsNullOrWhiteSpace(content)) { if (file_info.does_in_content_metadata(file_info.file_extension(dst))) { content = postingService.create_post_file_info(working_post) + "\r\n" + postingService.strip_post_file_info(content); dst = remove_filepath_version(dst); } file_handler.write_to_file(dst, content); String[] tmpf = dst.Split(new string[] { working_post.post_type.alias + "/" }, StringSplitOptions.None); file = tmpf[tmpf.Length - 1]; working_post.static_file = file.Trim('/'); } if (!String.IsNullOrWhiteSpace(content)) { working_post.content = content; } ActiveRecordMediator <posting> .Save(working_post); return(working_post); }
/// <summary> /// This is to make the meta string block for a non-meta files. /// </summary> /// <param name="post"></param> /// <returns></returns> internal static String create_post_file_info(posting post) { String Block = ""; Block = @" #* * name:" + post.name + @" * alias:" + post.alias + @" * theme:" + post.theme + @" * version:" + post.version.ToString() + @" * revision:" + post.revision.ToString() + @" * owner:" + post.owner.nid + @" * discription: This is the comtentblock *# "; return(Block); }
/// <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 void delete_post(int id) { posting post = ActiveRecordBase <posting> .Find(id); if (post.owner.baseid == userService.getUser().baseid) { Flash["message"] = "A Place, <strong>" + post.name + "</strong>, has been <strong>deleted</strong>."; logger.writelog("Moved event to the trash", getView(), getAction(), post.baseid); post.deleted = true; ActiveRecordMediator <posting> .Save(post); } else { Flash["message"] = "You can't delete something you don't own. Contact the owner, " + post.owner.display_name + ", for farther action."; logger.writelog("Attepted to delete an event they didn't own", getView(), getAction(), post.baseid); } CancelLayout(); RedirectToAction("posting_list", new string[] { "post_type=" + post.post_type.alias }); }
/// <summary> </summary> public static bool smushit(int id, string image_name, String mimeType) { // sent file to yahoo string url = "http://www.smushit.com/ysmush.it/ws.php?"; // "http://www.smushit.com/ysmush.it/ws.php?"; log.Info("trying smushit" + image_name); //reset the .ext file name posting image = ActiveRecordBase <posting> .Find(id); string orgFile = image_name; image_name = Regex.Replace(image_name, ".ext", "." + image.get_meta("ext"), RegexOptions.IgnoreCase); File.Copy(orgFile, image_name, true); NameValueCollection nvc = new NameValueCollection(); //nvc.Add("id", "TTR"); //nvc.Add("btn-submit-photo", "Upload"); string yurl = ""; try { String responseData = httpService.HttpUploadFile(url, image_name, "files", file_mime.mime_type(image.get_meta("ext")), nvc); JObject obj = JObject.Parse(responseData); yurl = (string)obj["dest"]; // what is the path? } catch { } if (!String.IsNullOrEmpty(yurl)) { log.Info("did smushit" + yurl); byte[] imagebytes = httpService.DownloadBinary(yurl); file_handler.ByteArrayToFile(image_name, imagebytes); File.Copy(image_name, orgFile, true); // overwirte the .ext with the new file. //File.Delete(image_name); deleteTmpIamges(image_name); return(true); } else { return(false); } }
/// <summary> </summary> public static String make_editable(String txt, posting post, int areacount) { String draft = ""; post = post.get_working_copy(); if (post.has_draft()) { draft = "data-has_draft='true'"; } String status = "data-status='false'"; if (post.is_published()) { status = "data-status='true'"; } txt = "<bdo data-id='" + post.baseid + "' " + draft + " " + status + " data-type='" + post.post_type.alias + "' data-name='" + post.name + "' data-alias='" + post.alias + "' data-blockid='" + areacount + "' class='editor_block'>" + txt + "</bdo>"; return(txt); }
/// <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 void create(String post_type, Boolean skipLayout) { posting tmp = new posting(); tmp.tmp = true; tmp.site = siteService.getCurrentSite(); tmp.theme = themeService.current_theme_alias(); tmp.published = false; appuser user = userService.getUserFull(); tmp.owner = user; tmp.editors = new List <appuser>() { user }; tmp.editing = user; tmp.post_type = getPostType(post_type); ActiveRecordMediator <posting> .Save(tmp); RedirectToUrl("~/post/edit_post.castle?id=" + tmp.baseid + (skipLayout ? "&skipLayout=true" : "")); }
/**/ /// <summary> </summary> public void New() { String CreditList = GetCredit(); PropertyBag["credits"] = CreditList; PropertyBag["imagetypes"] = ActiveRecordBase <taxonomy> .FindAll(); PropertyBag["images"] = ActiveRecordBase <posting> .FindAll(); } /// <summary> </summary> public void inlineupload() { String CreditList = GetCredit(); PropertyBag["credits"] = CreditList; PropertyBag["imagetypes"] = ActiveRecordBase <taxonomy> .FindAll(); PropertyBag["images"] = ActiveRecordBase <posting> .FindAll(); CancelLayout(); } /// <summary> </summary> public void Edit(int id) { String CreditList = GetCredit(); PropertyBag["credits"] = CreditList; // string should be "location1","location2","location3" PropertyBag["imagetypes"] = ActiveRecordBase <taxonomy> .FindAll(); PropertyBag["image"] = ActiveRecordBase <posting> .Find(id); PropertyBag["images"] = ActiveRecordBase <posting> .FindAll(); RenderView("new"); } /// <summary> </summary> public String GetCredit() { String sql = "SELECT DISTINCT s.credit FROM media_repo AS s WHERE NOT s.credit = 'NULL'"; SimpleQuery <String> q = new SimpleQuery <String>(typeof(posting), sql); Array credits = q.Execute(); String creditsList = ""; foreach (String s in credits) { creditsList += '"' + s.ToString() + '"' + ','; } return(creditsList.TrimEnd(',')); } /**/ /// <summary> </summary> public void removeImage(int image_id, int event_id, bool ajax) { posting image = ActiveRecordBase <posting> .Find(image_id); // a var for uploads will start here String uploadPath = file_info.root_path() + @"uploads\"; if (event_id != 0) { uploadPath += @"events\" + event_id + @"\"; } string newFile = uploadPath + image.id + ".ext"; ActiveRecordMediator <posting> .Delete(image); if (event_id != 0) { posting events = ActiveRecordBase <posting> .Find(event_id); //events.images.Remove(image);//FIX IT FileInfo ImgFile = new FileInfo(newFile); ImgFile.Delete(); ActiveRecordMediator <posting> .Save(events); } if (ajax) { CancelView(); CancelLayout(); RenderText("true"); return; } Flash["message"] = "Image Added"; RedirectToAction("list"); }
/// <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; } }
/// <summary> </summary> public void update_field( [ARDataBind("field", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] field_types field, [DataBind("ele", Validate = false)] elementSet ele, [ARDataBind("template", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting template, [ARDataBind("note", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting note, string ele_type, int placemodel, bool ajaxed_update, string apply, string cancel ) { if (cancel != null) { RedirectToAction("list"); return; } //dynamic value; var jss = new JavaScriptSerializer(); ActiveRecordMediator <fields> .Save(field); field.type = this.GetType().Name; field.set = ActiveRecordBase <posting_type> .Find(placemodel).baseid; // NOTE THIS IS THE ONLY REASON WE CAN ABSTRACT YET... FIX? ele.attr.name = "fields[" + field.baseid + "]"; //+ (ele.type == "dropdown"?"[]":""); ele.options.RemoveAt(ele.options.Count - 1); //to remove ele.options[9999] at the end string tmpNull = null; dynamic jsonstr = new { type = ele.type, label = ((ele.label == "") ? field.name : ele.label), attr = ele.attr, events = tmpNull, options = ele.options }; var json = jss.Serialize(jsonstr); field.attr = json; ActiveRecordMediator <fields> .Save(field); posting tmpTemplate = new posting(); if (template.baseid == 0) { tmpTemplate = new posting() { alias = template.alias.Replace("__TEMP__", field.baseid.ToString()), post_type = template.post_type, content = template.content }; } else { tmpTemplate = template; } ActiveRecordMediator <posting> .Save(tmpTemplate); field.template = tmpTemplate; posting tmpNotes = new posting(); if (note.baseid == 0) { tmpNotes = new posting() { alias = note.alias.Replace("__TEMP__", field.baseid.ToString()), post_type = note.post_type, content = note.content }; } else { tmpNotes = note; } ActiveRecordMediator <posting> .Save(tmpNotes); field.notes = tmpNotes; ActiveRecordMediator <fields> .Save(field); if (apply != null || ajaxed_update) { if (field.baseid > 0) { RedirectToUrl("edit_field.castle?id=" + field.baseid); return; } else { RedirectToReferrer(); } } else { RedirectToAction("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> /// 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); }
/// <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); }