コード例 #1
0
        public static void GetBlogConfig(
            string blogConfigReferenceName,
            out AgilityContentItem blogConfig,
            out IAgilityContentRepository <AgilityContentItem> blogPosts,
            out IAgilityContentRepository <AgilityContentItem> blogCategories,
            out IAgilityContentRepository <AgilityContentItem> blogTags,
            out IAgilityContentRepository <AgilityContentItem> blogAuthors)
        {
            blogConfig = new AgilityContentRepository <AgilityContentItem>(blogConfigReferenceName).Item("");

            string blogPostsRef = blogConfig["BlogPosts"] as string;

            blogPosts = new AgilityContentRepository <AgilityContentItem>(blogPostsRef);

            string blogCategoriesRef = blogConfig["BlogCategories"] as string;

            blogCategories = new AgilityContentRepository <AgilityContentItem>(blogCategoriesRef);

            string blogTagsRef = blogConfig["BlogTags"] as string;

            blogTags = new AgilityContentRepository <AgilityContentItem>(blogTagsRef);

            string blogAuthorsRef = blogConfig["BlogAuthors"] as string;

            blogAuthors = new AgilityContentRepository <AgilityContentItem>(blogAuthorsRef);
        }
コード例 #2
0
        public ActionResult GlobalHeader()
        {
            var header = new AgilityContentRepository <GlobalHeader>("GlobalHeader").Item("");

            var viewModel = new GlobalHeaderViewModel();

            viewModel.GlobalHeader = header.ToFrontendProps();
            viewModel.Menu         = new List <Link>();

            if (SiteMap.Provider.RootNode != null)
            {
                foreach (AgilitySiteMapNode node in SiteMap.Provider.RootNode.ChildNodes)
                {
                    if (node.IsVisibleInMenu())
                    {
                        viewModel.Menu.Add(new Link()
                        {
                            Url = node.Url.Replace("~", ""), Title = node.Title, Target = node.Target
                        });
                    }
                }
            }

            return(new ReactActionResult("Components.Global_Header", viewModel));
        }
コード例 #3
0
 public Task <IViewComponentResult> InvokeAsync()
 {
     return(Task.Run <IViewComponentResult>(() =>
     {
         var footer = new AgilityContentRepository <GlobalFooter>("GlobalFooter").Item("");
         return View("~/Views/Shared/Footer.cshtml", footer);
     }));
 }
コード例 #4
0
        public ActionResult TwitterRedirect(string config, string callback)
        {
            HttpContext.Response.Cache.VaryByParams["*"] = true;

            try
            {
                string configReferenceName = config;
                if (string.IsNullOrEmpty(configReferenceName) || new AgilityContentRepository <AgilityContentItem>(configReferenceName).Item("") == null)
                {
                    throw new HttpException(500, string.Format("Agility Comments Configuration Item '{0}' not found", configReferenceName));
                }

                var configItem = new AgilityContentRepository <AgilityContentItem>(configReferenceName).Item("");

                Uri rq = new Uri("https://api.twitter.com/oauth/request_token");

                string callbackUrl = Request.Url.ToString();
                callbackUrl = callbackUrl.Substring(0, callbackUrl.IndexOf("/", callbackUrl.IndexOf("://") + 4));
                callbackUrl = string.Format("{0}/Agility_Comments/TwitterRedirectStep2?config={1}&callback={2}", callbackUrl, configReferenceName, callback);

                OAuthBase oauth = new OAuthBase();

                string timestamp = oauth.GenerateTimeStamp();
                string nonce     = oauth.GenerateNonce();

                string consumerKey    = configItem["TwitterAPIConsumerKey"] as string;
                string consumerSecret = configItem["TwitterAPIConsumerSecret"] as string;

                if (string.IsNullOrWhiteSpace(consumerKey) || string.IsNullOrWhiteSpace(consumerSecret))
                {
                    throw new ApplicationException("The Twitter Consumer key or Secret has not been filled out in the Agility Comments Configuration shared content item.");
                }

                string postData = oauth.CreateCanonicalizedRequest(rq.ToString(), consumerKey, consumerSecret, callbackUrl);

                WebClient client = new WebClient();

                var authenticationHeader = oauth.CreateAuthenticationHeader(rq.ToString(), consumerKey, consumerSecret, callbackUrl);

                client.Headers.Add("Authorization", authenticationHeader);

                string response = client.UploadString(rq, postData);

                var    retData = HttpUtility.ParseQueryString(response);
                string token   = retData["oauth_token"];


                string redirectUrl = string.Format("https://api.twitter.com/oauth/authenticate?oauth_token={0}", HttpUtility.UrlEncode(token));

                return(Redirect(redirectUrl));
            }
            catch (Exception ex)
            {
                Agility.Web.Tracing.WebTrace.WriteException(ex);
                return(Content("An error occurred while contacting Twitter for authentication.  Please close this window and try again."));
            }
        }
コード例 #5
0
        public static List <AgilityContentItem> GetItemsByIDs(string referenceName, string commaIDs)
        {
            List <AgilityContentItem> items = new List <AgilityContentItem>();

            if (!string.IsNullOrEmpty(commaIDs))
            {
                items = new AgilityContentRepository <AgilityContentItem>(referenceName).GetByIDs(commaIDs).ToList();
            }

            return(items);
        }
コード例 #6
0
        public static AgilityContentItem GetItemByID(string referenceName, int id)
        {
            AgilityContentItem item = null;

            if (id > 0)
            {
                item = new AgilityContentRepository <AgilityContentItem>(referenceName).GetByID(id);
            }

            return(item);
        }
        public Task <IViewComponentResult> InvokeAsync(Module_ProductListing module)
        {
            return(Task.Run <IViewComponentResult>(() =>
            {
                int categoryID = 0;
                int page = 0;

                var catStr = Request.Query["category"];
                var pageStr = Request.Query["page"];

                int.TryParse(catStr, out categoryID);
                int.TryParse(pageStr, out page);

                if (page == 0)
                {
                    page = 1;
                }

                int totalCount = 0;
                int pageSize = module.ProductsPerPage;
                string rowFilter = "";

                if (categoryID > 0)
                {
                    rowFilter = string.Format("ProductCategoryID = {0}", categoryID);
                }

                int skip = (page - 1) * pageSize;
                int take = pageSize;

                var products = new AgilityContentRepository <Product>("Products").Items(rowFilter, "Title ASC", take, skip, out totalCount);

                var model = new ProductListingModule();
                model.Categories = new AgilityContentRepository <ProductCategory>("ProductCategories").Items();
                model.FilteredCategory = model.Categories.Where(i => i.ContentID == categoryID).FirstOrDefault();
                model.Products = products;
                model.Module = module;

                var pagination = new Pagination();
                pagination.BaseUrl = Request.Path.Value;
                pagination.CurrentPageNumber = page;
                pagination.ResultsPerPage = module.ProductsPerPage;
                pagination.PaginationAs = PaginationMode.PageNumbers;
                pagination.TotalResults = totalCount;

                model.Pagination = pagination;


                return View("~/Views/Products/ProductListingModule.cshtml", model);
            }));
        }
コード例 #8
0
        public ActionResult ProductListingModule(Module_ProductListing module)
        {
            HttpContext.Response.Cache.VaryByParams["*"] = true;

            int categoryID = 0;
            int page       = 0;

            int.TryParse(string.Format("{0}", Request.QueryString["category"]), out categoryID);
            int.TryParse(string.Format("{0}", Request.QueryString["page"]), out page);

            if (page == 0)
            {
                page = 1;
            }

            int    totalCount = 0;
            int    pageSize   = module.ProductsPerPage;
            string rowFilter  = "";

            if (categoryID > 0)
            {
                rowFilter = string.Format("ProductCategoryID = {0}", categoryID);
            }

            int skip = (page - 1) * pageSize;
            int take = pageSize;

            var products = new AgilityContentRepository <Product>("Products").Items(rowFilter, "Title ASC", take, skip, out totalCount);

            var model = new ProductListingModule();

            model.Categories       = new AgilityContentRepository <ProductCategory>("ProductCategories").Items();
            model.FilteredCategory = model.Categories.Where(i => i.ContentID == categoryID).FirstOrDefault();
            model.Products         = products;
            model.Module           = module;

            var pagination = new Pagination();

            pagination.BaseUrl           = Request.Url;
            pagination.CurrentPageNumber = page;
            pagination.ResultsPerPage    = module.ProductsPerPage;
            pagination.PaginationAs      = PaginationMode.PageNumbers;
            pagination.TotalResults      = totalCount;

            model.Pagination = pagination;

            return(PartialView(model));
        }
コード例 #9
0
        public T GetContentItem <T>() where T : AgilityContentItem
        {
            var content = BaseCache.GetContent(ContentReferenceName, AgilityContext.LanguageCode, AgilityContext.WebsiteName, false);

            var row = content.GetItemByContentID(ContentID);

            if (row == null)
            {
                return(null);
            }

            Type            type   = typeof(T);
            ConstructorInfo constr = type.GetConstructor(System.Type.EmptyTypes);

            return(AgilityContentRepository <T> .ConvertDataRowToObject(constr, row, AgilityContext.LanguageCode, ContentReferenceName));
        }
コード例 #10
0
        public ActionResult Photo(int id, int w, int h, string config)
        {
            string photoUrl = string.Empty;

            try
            {
                using (Agility_UGC_API_WCFClient client = UGCAPIUtil.GetAPIClient("http://ugc.agilitycms.com/agility-ugc-api-wcf.svc", TimeSpan.FromSeconds(10)))
                {
                    DataServiceAuthorization dsa = UGCAPIUtil.GetDataServiceAuthorization(-1);
                    Record userProfile           = client.GetRecord(dsa, id, FileStorage.EdgeURL);

                    if (userProfile != null)
                    {
                        if (!string.IsNullOrEmpty(userProfile.GetValue("AgilityCommentsPhoto") as string))
                        {
                            //if photo found, use this
                            photoUrl = userProfile.GetValue("AgilityCommentsPhoto") as string;

                            photoUrl = CommentsUtils.GetTranscodedUrl(photoUrl, w, h);

                            return(Redirect(photoUrl));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Agility.Web.Tracing.WebTrace.WriteException(ex, string.Format("Error getting profile image for {0},", id));
            }

            //no profile found or no photo found
            var configReferenceName = config;

            var configRepo = new AgilityContentRepository <AgilityContentItem>(configReferenceName);

            if (configRepo != null)
            {
                var defaultImage = configRepo.Item("").GetAttachment("DefaultAvatar");
                if (defaultImage != null)
                {
                    return(Redirect(CommentsUtils.GetTranscodedUrl(defaultImage.URL, w, h)));
                }
            }
            return(new EmptyResult());
        }
コード例 #11
0
        public ActionResult ProductDetailsModule(Module_ProductDetails module)
        {
            var product = AgilityContext.GetDynamicPageItem <Product>();

            var model = new ProductDetailsModule();

            model.Module = module;

            if (product != null && product.ReferenceName == "Products")
            {
                model.Product = product;

                var category = new AgilityContentRepository <ProductCategory>("ProductCategories").Items().Where(i => i.ContentID == product.ProductCategoryID).FirstOrDefault();
                model.Category = category;
            }

            return(PartialView(model));
        }
コード例 #12
0
        public ActionResult Comments(AgilityContentItem item)
        {
            var dynamicItem         = ResolveBlogPostDetails();
            var configReferenceName = item["CommentsConfiguration"] as string;
            var config = new AgilityContentRepository <AgilityContentItem>(configReferenceName).Item("");

            if (config == null || dynamicItem == null || string.IsNullOrEmpty(dynamicItem.CommentsRecordTypeName()))
            {
                return(null);
            }

            var model = new CommentsViewModel();

            model.CommentsRecordTypeName = dynamicItem.CommentsRecordTypeName();
            model.RelatedContentID       = dynamicItem.ContentID;
            model.Config = config;
            model.FacebookLoginEnabled = (CommentsUtils.GetBool(config["EnableFacebookLogin"]) && !string.IsNullOrEmpty(config["FacebookAppID"] as string));
            model.TwitterLoginEnabled  = (CommentsUtils.GetBool(config["EnableTwitterLogin"]) && !string.IsNullOrEmpty(config["TwitterAPIConsumerKey"] as string) && !string.IsNullOrEmpty(config["TwitterAPIConsumerSecret"] as string));
            model.GuestLoginEnabled    = CommentsUtils.GetBool(config["EnableGuestLogin"]);

            return(PartialView(AgilityComponents.TemplatePath("Comments-Module"), model));
        }
        public Task <IViewComponentResult> InvokeAsync(Module_ProductDetails module)
        {
            return(Task.Run <IViewComponentResult>(() =>
            {
                var product = AgilityContext.GetDynamicPageItem <Product>();

                var model = new ProductDetailsModule();
                model.Module = module;

                if (product != null && product.ReferenceName == "Products")
                {
                    model.Product = product;

                    var category = new AgilityContentRepository <ProductCategory>("ProductCategories").Items().Where(i => i.ContentID == product.ProductCategoryID).FirstOrDefault();
                    model.Category = category;
                }



                return View("~/Views/Products/ProductDetailsModule.cshtml", model);
            }));
        }
コード例 #14
0
        public ActionResult TwitterRedirectStep2(string config, string callback)
        {
            HttpContext.Response.Cache.VaryByParams["*"] = true;
            string htmlOutput = "";

            try
            {
                string configReferenceName = config;
                if (string.IsNullOrEmpty(configReferenceName) || new AgilityContentRepository <AgilityContentItem>(configReferenceName).Item("") == null)
                {
                    throw new HttpException(500, string.Format("Agility Comments Configuration Item '{0}' not found", configReferenceName));
                }

                var    configItem       = new AgilityContentRepository <AgilityContentItem>(configReferenceName).Item("");
                string token            = Request.QueryString["oauth_token"];
                string verifier         = Request.QueryString["oauth_verifier"];
                string callbackFunction = callback;

                Uri rq = new Uri("https://api.twitter.com/oauth/access_token");

                OAuthBase oauth = new OAuthBase();

                string timestamp = oauth.GenerateTimeStamp();
                string nonce     = oauth.GenerateNonce();

                string consumerKey    = configItem["TwitterAPIConsumerKey"] as string;
                string consumerSecret = configItem["TwitterAPIConsumerSecret"] as string;

                var postData = string.Format("{0}={1}", "oauth_verifier", verifier);

                var authorizationHeader = oauth.CreateAuthenticationAccessHeader(rq.ToString(), "POST", consumerKey, consumerSecret, token, new Dictionary <string, string> {
                    { "oauth_verifier", verifier }
                });

                WebClient client = new WebClient();

                client.Headers.Add("Authorization", authorizationHeader);

                string response = client.UploadString(rq, postData);

                var retData = HttpUtility.ParseQueryString(response);
                token = retData["oauth_token"];
                string secret     = retData["oauth_token_secret"];
                string userID     = retData["user_id"];
                string screenName = retData["screen_name"];

                if (!string.IsNullOrWhiteSpace(secret) &&
                    !string.IsNullOrWhiteSpace(token) &&
                    !string.IsNullOrWhiteSpace(screenName))
                {
                    //make sure everything came back ok...

                    timestamp = oauth.GenerateTimeStamp();
                    nonce     = oauth.GenerateNonce();

                    //get the fullname and other details as well...
                    string requestUrl = string.Format("https://api.twitter.com/1.1/account/verify_credentials.json");

                    //can't get email unless app is whitelisted https://dev.twitter.com/rest/reference/get/account/verify_credentials
                    if (CommentsUtils.GetBool(configItem["TwitterRequestEmail"]))
                    {
                        requestUrl += "?include_email=true";
                    }

                    rq = new Uri(requestUrl);

                    authorizationHeader             = oauth.CreateAuthenticationAccessHeader(rq.ToString(), "GET", consumerKey, consumerSecret, token, new Dictionary <string, string>(), secret);
                    client.Headers["Authorization"] = authorizationHeader;
                    response = client.DownloadString(rq);

                    TwitterUser tUser = CommentsUtils.DeserializeJSONObject <TwitterUser>(response);

                    string name = tUser.name;
                    string twitterProfileImage = tUser.profile_image_url;
                    string email = tUser.email;

                    //save the larger version of the profile image
                    twitterProfileImage = twitterProfileImage.Replace("_normal", "_bigger");


                    StringBuilder html = new StringBuilder();
                    html.Append("<html>");
                    html.AppendLine("<head>");
                    html.AppendLine("<title>Authenticating...</title>");
                    html.AppendLine("</head>");
                    html.AppendLine("<body>");
                    if (!string.IsNullOrEmpty(userID))
                    {
                        html.AppendLine("<script>");
                        html.AppendLine("if(window.opener) {");
                        html.AppendFormat("window.opener.{5}(\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\");", userID, screenName, name, twitterProfileImage, email, callbackFunction);
                        html.AppendLine("window.close()");
                        html.AppendLine("} else {");
                        html.AppendLine("document.write(\"An error occurred during the authenticatin process. Please close your browser and try again.\");");
                        html.AppendLine("}");
                        html.AppendLine("</script>");
                    }
                    else
                    {
                        html.AppendLine("<script>window.close()</script>");
                    }

                    html.AppendLine("</body>");
                    html.AppendLine("</html>");

                    htmlOutput = html.ToString();
                }

                return(Content(htmlOutput));
            }
            catch (Exception ex)
            {
                Agility.Web.Tracing.WebTrace.WriteException(ex);
                return(Content(ex.Message));
            }
        }
コード例 #15
0
        public ActionResult GlobalFooter()
        {
            var footer = new AgilityContentRepository <GlobalFooter>("GlobalFooter").Item("");

            return(PartialView("~/Views/Shared/Footer.cshtml", footer));
        }