Пример #1
0
        /// <summary> </summary>
        public static int get_postype_id(dynamic item)
        {
            posting_type posting_type = ActiveRecordBase <posting_type> .FindAll(new Order("revision", false),
                                                                                 new List <AbstractCriterion>() { Expression.Eq("alias", item) }.ToArray()
                                                                                 ).FirstOrDefault();

            return(posting_type.baseid);
        }
Пример #2
0
        /// <summary> </summary>
        public void edit_posting_type(int id)
        {
            posting_type item = ActiveRecordBase <posting_type> .Find(id);

            PropertyBag["item"]    = item;
            PropertyBag["actions"] = ActiveRecordBase <posting_type_action> .FindAll();

            RenderView("../admin/postings/edit_posting_type");
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        // 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);
        }
Пример #5
0
        /// <summary> </summary>
        public void update_posting_type([ARDataBind("item", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting_type item)
        {
            ActiveRecordMediator <posting_type> .Save(item);

            RedirectToAction("list_siteSettings");
        }
Пример #6
0
        /// <summary>
        /// The post partent will be updated with the latest content and setting.
        /// Also this is push a file copy to the published folder as well as make the copies.
        /// </summary>
        /// <returns></returns>
        public static posting make_post_publised_version(posting working_copy)
        {
            //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 published_copy = copy_post_to_post(new posting(), working_copy);


            published_copy.version  = published_copy.version + 1;
            published_copy.revision = 0;
            ActiveRecordMediator <posting> .Save(published_copy);

            posting_type type    = working_copy.post_type;
            String       content = "";
            String       file    = published_copy.static_file;

            if (!String.IsNullOrWhiteSpace(file))
            {
                file = file_info.normalize_path(published_copy.static_file);

                String[] fpath       = file.Split(new string[] { type.alias + "/" }, StringSplitOptions.None);
                String   static_file = fpath[fpath.Length - 1].Trim('/');

                String dst = remove_filepath_version(static_file);
                //find the working to make the published
                String basepath = working_path().Trim('/') + "/" + type.alias;
                dst     = basepath + "/" + dst.Trim('/');
                content = file_handler.read_from_file(dst);


                //create the published path
                fpath       = file.Split(new string[] { type.alias + "/" }, StringSplitOptions.None);
                static_file = fpath[fpath.Length - 1].Trim('/');
                basepath    = published_path().Trim('/') + "/" + type.alias;
                dst         = basepath + "/" + static_file.Trim('/');

                String dir = Path.GetDirectoryName(dst);
                if (!Directory.Exists(dir))
                {
                    DirectoryInfo di = Directory.CreateDirectory(dir);
                }


                if (!String.IsNullOrWhiteSpace(content))
                {
                    if (file_info.does_in_content_metadata(file_info.file_extension(dst)))
                    {
                        content = postingService.create_post_file_info(published_copy) + "\r\n" + postingService.strip_post_file_info(content);
                    }
                    file_handler.write_to_file(dst, content);
                }
            }
            published_copy.published = true;
            if (published_copy.parent == null || published_copy.parent.baseid <= 0)
            {
                published_copy.parent = working_copy;
            }
            if (!String.IsNullOrWhiteSpace(content))
            {
                published_copy.content = content;
            }



            ActiveRecordMediator <posting> .Save(published_copy);

            working_copy.revision  = published_copy.revision;
            working_copy.version   = published_copy.version;
            working_copy.published = true;
            ActiveRecordMediator <posting> .Save(working_copy);


            return(working_copy);   // was published_copy returned.. but seems better to pass the working copy.  That is what everything works off after all.
        }
Пример #7
0
        /// <summary>
        /// This function will take a working copy, add the version it to both the file and
        /// the object and move the file to the revision folder for safe keeping.
        /// </summary>
        /// <param name="working_copy"></param>
        /// <returns></returns>
        /// <remarks> DB >> FILE    (THIS MAY ONLY COME FROM THE WORKING POSTING)</remarks>
        public static posting make_post_revision(posting working_copy)
        {
            posting_type type          = working_copy.post_type;
            posting      revision_copy = copy_post_to_post(new posting(), working_copy);
            //set the path of old file
            String new_dst = "";

            if (revision_copy.loads_file)
            {
                new_dst = adjust_filepath_version(revision_copy.static_file, revision_copy.version, revision_copy.revision + 1);
            }
            revision_copy.revision = revision_copy.revision + 1;
            ActiveRecordMediator <posting> .Save(revision_copy);   // end of object versioning


            if (!String.IsNullOrWhiteSpace(revision_copy.static_file))      // start of file versioning
            // get the content
            {
                String content  = revision_copy.content;
                String basepath = working_path().Trim('/') + "/" + type.alias.Trim('/');     //since we are always making a revision of a working post
                String old_dst  = basepath + "/" + revision_copy.static_file.Trim('/');

                content = file_handler.read_from_file(old_dst);

                if (file_info.does_in_content_metadata(file_info.file_extension(old_dst)))
                {
                    content = postingService.create_post_file_info(revision_copy) + "\r\n" + postingService.strip_post_file_info(content);
                    revision_copy.content = content;
                }

                revision_copy.static_file = new_dst;

                if (!String.IsNullOrWhiteSpace(new_dst))
                {
                    new_dst = file_info.site_cache_path().Trim('/') + "/revision/" + type.alias + "/" + new_dst.Trim('/');

                    String dir = Path.GetDirectoryName(new_dst);
                    if (!Directory.Exists(dir))
                    {
                        DirectoryInfo di = Directory.CreateDirectory(dir);
                    }
                    file_handler.write_to_file(new_dst, content);
                }
            }

            if (revision_copy.parent == null || revision_copy.parent.baseid <= 0)
            {
                revision_copy.parent = working_copy;
            }

            revision_copy.published = false;
            ActiveRecordMediator <posting> .Save(revision_copy);

            //we move this up one now that we have finished making the revision
            working_copy.revision  = revision_copy.revision;
            working_copy.version   = revision_copy.version;
            working_copy.published = false;
            ActiveRecordMediator <posting> .Save(working_copy);

            return(working_copy);   // was revision_post returned.. but seems better to pass the working copy.  That is what everything works off after all.
        }
Пример #8
0
        /// <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");
            }
        }