Ejemplo n.º 1
0
        protected override void AddedControl(Control control, int index)
        {
            //base.AddedControl(control, index);

            if ((SPContext.Current.Item is SPListItem) && (WebSitePage.IsWebSitePage(SPContext.Current.Item as SPListItem)))
            {
                this.Controls.Clear();
                return;
            }

            SPListItem item = null;

            try
            {
                if (!HttpContext.Current.Request.Url.AbsolutePath.StartsWith("/_layouts/"))
                {
                    item = SPContext.Current.Web.GetListItem(HttpContext.Current.Request.Url.AbsolutePath);
                }
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                item = null;
            }
            if ((item != null) && ((item is SPListItem) && WebSitePage.IsWebSitePage(item)))
            {
                this.Controls.Clear();
                return;
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            WebSitePage entity = _webSitePageStoreBase.GetById((int)id);

            if (entity == null)
            {
                return(HttpNotFound());
            }
            return(View("_Edit", entity));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(WebSitePage entity)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_Edit", entity));
            }
            WebSitePage editedEntity = _webSitePageStoreBase.Update(entity);

            if (editedEntity != null)
            {
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "something went wrong");
            return(View("_Edit", entity));
        }
Ejemplo n.º 4
0
        public ActionResult Info(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            WebSitePage WebSitePage = _webSitePageStoreBase.GetById((int)id);

            if (WebSitePage == null)
            {
                return(HttpNotFound());
            }

            return(View("_Info", WebSitePage));
        }
Ejemplo n.º 5
0
        public ActionResult Create(WebSitePage entity)
        {
            if (!ModelState.IsValid)
            {
                return(View("_Create", entity));
            }

            entity.Slug = entity.TitleEn.GenerateSlug();
            WebSitePage addedEntity = _webSitePageStoreBase.Create(entity);

            if (addedEntity != null)
            {
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "something went wrong");
            return(View("_Create", entity));
        }
 public virtual WebSitePage Update(WebSitePage entity)
 {
     this.Context.Entry <WebSitePage>(entity).State = EntityState.Modified;
     Context.SaveChanges();
     return(GetById(entity.PageId));
 }
 public bool Delete(WebSitePage entity)
 {
     this.DbEntitySet.Remove(entity);
     return(Context.SaveChanges() > 0);
 }
 public WebSitePage Create(WebSitePage entity)
 {
     entity = this.DbEntitySet.Add(entity);
     Context.SaveChanges();
     return(entity);
 }
Ejemplo n.º 9
0
        /*
         * private SPListItem _Author;
         *
         * public SPListItem Author
         * {
         *  get { return _Author; }
         *  set { _Author = value; }
         * }
         *
         * private SPListItem _Editor;
         *
         * public SPListItem Editor
         * {
         *  get { return _Editor; }
         *  set { _Editor = value; }
         * }
         */
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            try
            {
                SPContext _current = SPContext.Current;

                if (_current == null)
                {
                    _current = SPContext.GetContext(HttpContext.Current);
                }

                settings = new MetaDataSettings();
                settings = settings.Load(_current.Site);

                facebook = new FaceBookSettings();
                facebook = facebook.Load(_current.Site);

                twitter = new TwitterSettings();
                twitter = twitter.Load(_current.Site);

                listItem = _current.ListItem;

                /*
                 * try
                 * {
                 *  SPSecurity.RunWithElevatedPrivileges(delegate()
                 *  {
                 *      SPList userList = _current.Site.RootWeb.SiteUserInfoList;
                 *
                 *      if (userList != null && listItem != null)
                 *      {
                 *          SPFieldUserValue userValue = new SPFieldUserValue(_current.Web, listItem[SPBuiltInFieldId.Editor].ToString());
                 *          SPUser editor = userValue.User;
                 *          Editor = userList.Items.GetItemById(editor.ID);
                 *
                 *          userValue = new SPFieldUserValue(_current.Web, listItem[SPBuiltInFieldId.Author].ToString());
                 *          SPUser author = userValue.User;
                 *          Author = userList.Items.GetItemById(editor.ID);
                 *      }
                 *  });
                 * }
                 * catch { }
                 */

                GetMetaFields();

                if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    UpdateMetaFields();
                }


                if (_current.List == null)
                {
                    HtmlMeta compatible = new HtmlMeta();
                    compatible.HttpEquiv = "X-UA-Compatible";
                    compatible.Content   = "IE=edge,chrome=1";
                    this.Control.Controls.Add(compatible);
                    this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                }
                else
                {
                    string editform = _current.List.Forms[PAGETYPE.PAGE_EDITFORM].ServerRelativeUrl;
                    //string editdialogform = SPContext.Current.List.Forms[PAGETYPE.PAGE_EDITFORMDIALOG].ServerRelativeUrl;
                    string newform = _current.List.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl;
                    //string newdialogform = SPContext.Current.List.Forms[PAGETYPE.PAGE_NEWFORMDIALOG].ServerRelativeUrl;

                    bool isEdit = Page.Request.Url.OriginalString.Contains(editform);
                    bool isNew  = Page.Request.Url.OriginalString.Contains(newform);

                    bool isSharePresence = false;
                    if (listItem != null && listItem.ContentType != null && listItem.ContentType.Id.IsChildOf(ContentTypeId.PageTemplate))
                    {
                        isSharePresence = true;
                    }

                    if (isSharePresence)
                    {
                        this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                        this.Control.Controls.Add(new LiteralControl("<!-- Managed MetaData -->"));
                        this.Control.Controls.Add(new LiteralControl(Environment.NewLine));

                        HtmlMeta compatible = new HtmlMeta();
                        compatible.HttpEquiv = "X-UA-Compatible";

                        DisplayControlModes modes = WebSitePage.DetermineDisplayControlModes();

                        if (modes.displayMode == SPControlMode.Display && (!isNew && !isEdit))
                        {
                            //compatible.Content = "IE=10";
                            compatible.Content = "IE=edge,chrome=1";
                        }
                        else
                        {
                            if (isNew && isEdit)
                            {
                                compatible.Content = "IE=8";
                            }
                            else
                            {
                                compatible.Content = "IE=edge,chrome=1";
                            }
                        }


                        this.Control.Controls.Add(compatible);
                        this.Control.Controls.Add(new LiteralControl(Environment.NewLine));

                        /*
                         * string googleId = Editor["Google_x0020_Id"] as string;
                         * string twitterId = Editor["Twitter_x0020_Id"] as string;
                         * string linkedinId = Editor["LinkedIn_x0020_Id"] as string;
                         * string facebookId = Editor["FaceBook_x0020_Id"] as string;
                         */

                        if (SPContext.Current.FormContext.FormMode == SPControlMode.Display)
                        {
                            if (settings.UseMSNBotDMOZ)
                            {
                                HtmlMeta msnbot = new HtmlMeta();
                                msnbot.Name    = "msnbot";
                                msnbot.Content = "NOODP";
                                this.Control.Controls.Add(msnbot);
                                this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                            }

                            /*
                             * if (!string.IsNullOrEmpty(Editor["Google_x0020_Id"] as string))
                             * {
                             *  HtmlLink googleplus = new HtmlLink();
                             *  googleplus.Attributes.Add(HtmlTextWriterAttribute.Rel.ToString().ToLower(), "author");
                             *  googleplus.Attributes.Add(HtmlTextWriterAttribute.Href.ToString().ToLower(), string.Format("https://plus.google.com/{0}/posts", Editor["Google_x0020_Id"] as string));
                             *  this.Control.Controls.Add(googleplus);
                             *  this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                             * }
                             */

                            Regex mapping = new Regex(@"\[(.*?)\]", RegexOptions.Compiled);

                            foreach (SPField oField in metafields)
                            {
                                string fieldname = SharePointWebControls.GetFieldName(oField);

                                if (listItem.Fields.ContainsField(fieldname))
                                {
                                    string value = listItem.GetFormattedValue(fieldname);// field.Title);
                                    //string value = listItem[fieldname] as string;
                                    HtmlMeta meta = new HtmlMeta();
                                    meta.Name = fieldname;

                                    if (String.IsNullOrEmpty(value))
                                    {
                                        value = oField.DefaultValue;
                                        //meta.Content = oField.DefaultValue;
                                    }
                                    else
                                    {
                                        value = value.Replace(";#", ",");
                                        //meta.Content = value;
                                    }

                                    if (!string.IsNullOrEmpty(value) && mapping.IsMatch(value))
                                    {
                                        string shallow = value.ToString();

                                        foreach (Match match in mapping.Matches(shallow))
                                        {
                                            string field  = match.Value;
                                            string sfield = field.Trim(new char[2] {
                                                '[', ']'
                                            });

                                            if (listItem.Fields.ContainsField(sfield))
                                            {
                                                //string fieldvalue = listItem.GetFormattedValue(sfield);
                                                string fieldvalue = listItem[sfield] as string;


                                                if (string.IsNullOrEmpty(fieldvalue))
                                                {
                                                    try
                                                    {
                                                        SPField internalfield = listItem.Fields.GetFieldByInternalName(sfield);
                                                        if (internalfield != null)
                                                        {
                                                            fieldvalue = internalfield.DefaultValue as string;
                                                        }

                                                        //fieldvalue = listItem.Fields[sfield].DefaultValue;
                                                    }
                                                    catch { }
                                                }

                                                if (sfield.ToLower().Contains("author") || sfield.ToLower().Contains("editor") || sfield.ToLower().Contains("publisher"))
                                                {
                                                    /*
                                                     * if (sfield.ToLower().Contains("author"))
                                                     * {
                                                     *  fieldvalue = Author["Title"] as string;
                                                     * }
                                                     * else
                                                     * {
                                                     *  fieldvalue = Editor["Title"] as string;
                                                     * }
                                                     */
                                                    /*
                                                     * string[] sections = fieldvalue.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
                                                     * if (sections.Length > 1)
                                                     * {
                                                     *  fieldvalue = sections[1];
                                                     * }
                                                     */
                                                    //meta.Content = value;
                                                }

                                                if (sfield.ToLower().Contains("html5"))
                                                {
                                                    if (sfield.ToLower().Contains("image"))
                                                    {
                                                        HTML5Image      image  = listItem.Fields.GetFieldByInternalName(sfield) as HTML5Image;
                                                        HTML5ImageField ifield = new HTML5ImageField(image.FieldRenderingControl.Value.ToString());
                                                        fieldvalue = listItem.Web.Site.Url + "/" + ifield.Src;
                                                    }

                                                    if (sfield.ToLower().Contains("header"))
                                                    {
                                                        HTML5Header      header = listItem.Fields.GetFieldByInternalName(sfield) as HTML5Header;
                                                        HTML5HeaderField ifield = new HTML5HeaderField(header.FieldRenderingControl.Value.ToString());
                                                        fieldvalue = ifield.Text;
                                                    }

                                                    if (sfield.ToLower().Contains("footer"))
                                                    {
                                                        HTML5Footer      footer = listItem.Fields.GetFieldByInternalName(sfield) as HTML5Footer;
                                                        HTML5FooterField ifield = new HTML5FooterField(footer.FieldRenderingControl.Value.ToString());
                                                        fieldvalue = ifield.Text;
                                                    }

                                                    if (sfield.ToLower().Contains("video"))
                                                    {
                                                        HTML5Video      video  = listItem.Fields.GetFieldByInternalName(sfield) as HTML5Video;
                                                        HTML5VideoField ifield = new HTML5VideoField(video.FieldRenderingControl.Value.ToString());
                                                        fieldvalue = listItem.Web.Site.Url + "/" + ifield.Src;
                                                    }

                                                    //fieldvalue = fieldvalue.Replace("//", "/");
                                                }

                                                value = value.Replace(field, fieldvalue);
                                            }

                                            /*
                                             * if (sfield.Contains("Twitter_x0020_Id"))
                                             * {
                                             *  value = Editor["Twitter_x0020_Id"] as string;
                                             * }
                                             *
                                             * if (sfield.Contains("Google_x0020_Id"))
                                             * {
                                             *  value = Editor["Google_x0020_Id"] as string;
                                             * }
                                             *
                                             * if (sfield.Contains("FaceBook_x0020_Id"))
                                             * {
                                             *  value = Editor["FaceBook_x0020_Id"] as string;
                                             * }
                                             *
                                             * if (sfield.Contains("LinkedIn_x0020_Id"))
                                             * {
                                             *  value = Editor["LinkedIn_x0020_Id"] as string;
                                             * }
                                             */

                                            if (sfield.ToLower().Contains("site"))
                                            {
                                                value = listItem.Web.Site.Url + "/";
                                            }

                                            if (sfield.ToLower().Contains("url"))
                                            {
                                                value = HttpContext.Current.Request.Url.OriginalString;
                                                //value = listItem.Web.Site.Url + "/" + listItem.Url;
                                            }
                                        }
                                    }

                                    meta.Content = value;

                                    if (fieldname == "keywords")
                                    {
                                        if (settings.AutoKeywords)
                                        {
                                            if (String.IsNullOrEmpty(value))
                                            {
                                                value = String.Empty;
                                            }

                                            meta.Content += GetAutoKeywords(value);
                                        }
                                    }

                                    if (fieldname == "language" && settings.UseSiteLanguage)
                                    {
                                        CultureInfo cult = new CultureInfo((int)SPContext.Current.Web.RegionalSettings.LocaleId);
                                        //CultureInfo cult = new CultureInfo((int)SPContext.Current.Web.Language);
                                        meta.Content = cult.DisplayName.ToLower();

                                        HtmlMeta equiv = new HtmlMeta();
                                        equiv.HttpEquiv = "content-language";
                                        equiv.Content   = cult.Name;

                                        this.Control.Controls.Add(equiv);
                                        this.Control.Controls.Add(new LiteralControl(Environment.NewLine));

                                        equiv           = new HtmlMeta();
                                        equiv.HttpEquiv = "language";
                                        equiv.Content   = cult.Name;

                                        this.Control.Controls.Add(equiv);
                                        this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                                    }

                                    /*
                                     * if (fieldname == "author" && settings.AuthorOverride != Authors.NoOverride)
                                     * {
                                     *  value = listItem[settings.AuthorOverride.ToString()] as string;
                                     *  meta.Content = value;
                                     * }
                                     *
                                     * if (fieldname == "web_author" && settings.WebAuthorOverride != Authors.NoOverride)
                                     * {
                                     *  value = listItem[settings.AuthorOverride.ToString()] as string;
                                     *  meta.Content = value;
                                     * }
                                     */

                                    this.Control.Controls.Add(meta);
                                    this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                                }
                            }
                            this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                        }
                        else
                        {
                            HtmlMeta pragma = new HtmlMeta();
                            pragma.HttpEquiv = "Pragma";
                            pragma.Content   = "no-cache";
                            this.Control.Controls.Add(pragma);
                            this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                            HtmlMeta expires = new HtmlMeta();
                            expires.HttpEquiv = "Expires";
                            expires.Content   = "-1";
                            this.Control.Controls.Add(expires);
                            this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                            HtmlMeta store = new HtmlMeta();
                            store.HttpEquiv = "Cache-Control";
                            store.Content   = "no-store, no-cache, must-revalidate";
                            this.Control.Controls.Add(store);
                            this.Control.Controls.Add(new LiteralControl(Environment.NewLine));

                            HtmlMeta post = new HtmlMeta();
                            post.HttpEquiv = "Cache-Control";
                            post.Content   = "post-check=0, pre-check=0";
                            this.Control.Controls.Add(post);
                            this.Control.Controls.Add(new LiteralControl(Environment.NewLine));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Ejemplo n.º 10
0
        public override string CombineVirtualPaths(string basePath, string relativePath)
        {
            if (relativePath.ToLower() == "~masterurl/website.master")
            {
                try
                {
                    return("website.master");
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }

            if (relativePath.ToLower() == "~masterurl/default.master")
            {
                try
                {
                    //SPControl.SetContextSite(HttpContext.Current, web);
                    //string incorrect = SPContext.Current.Site.RootWeb.MasterUrl;
                    //string rootsite = SPContext.Current.Site.RootWeb.Url.Replace(SPContext.Current.Site.ServerRelativeUrl, string.Empty);
                    //string correct = SPUtility.ConcatUrls(rootsite, incorrect);
                    //SPControl.SetContextSite(HttpContext.Current, new SPSite(rootsite));
                    //string correct = "~" + incorrect;
                    return(SPContext.Current.Site.RootWeb.CustomMasterUrl);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }

            if (relativePath.ToLower() == "~masterurl/custom.master")
            {
                try
                {
                    //string incorrect = SPContext.Current.Site.RootWeb.CustomMasterUrl;
                    //string rootsite = SPContext.Current.Site.RootWeb.Url.Replace(SPContext.Current.Site.ServerRelativeUrl,string.Empty);
                    //string correct = SPUtility.ConcatUrls(rootsite, incorrect);
                    //SPControl.SetContextSite(HttpContext.Current, new SPSite(rootsite));
                    //string correct = "~" + incorrect;
                    return(SPContext.Current.Site.RootWeb.CustomMasterUrl);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }

            if (relativePath.ToLower() == "~TemplatePageUrl")
            {
                try
                {
                    //string incorrect = SPContext.Current.Site.RootWeb.WelcomePage;
                    //string corrent = incorrect.Replace(SPContext.Current.Site.ServerRelativeUrl, string.Empty);

                    return(SPContext.Current.Site.RootWeb.RootFolder.WelcomePage);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            if (relativePath.ToLower().EndsWith(".master"))
            {
                string what = relativePath;
            }

            WebSitePage.DetermineDisplayControlModes();
            return(base.Previous.CombineVirtualPaths(basePath, relativePath));
        }