public object GetSiteData(int siteId, string period, bool cache = true)
        {
            DashboardHelpers.EnsureCurrentUserCulture();

            try {
                // Get the site
                IDashboardSite site = DashboardContext.Current.GetSiteById(siteId);
                if (site == null)
                {
                    throw new DashboardException(HttpStatusCode.NotFound, "Site ikke fundet", "Et site det angivne ID blev ikke fundet");
                }

                // Get analytics information
                IAnalyticsSite analytics = site as IAnalyticsSite;
                if (analytics == null || !analytics.HasAnalytics)
                {
                    throw new DashboardException(HttpStatusCode.InternalServerError, "Analytics", "Det valgte side understøtter eller er ikke konfigureret til visning af statistik fra Google Analytics");
                }

                // Build the query
                DataQuery query = DataQuery.GetFromPeriod(analytics, period, cache);
                query.Type = DataQueryType.Site;

                // Generate the response object
                DataResponse res = query.GetResponse();

                // Return a nice JSON response
                return(JsonMetaResponse.GetSuccess(res));
            } catch (DashboardException ex) {
                return(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Title + ": " + ex.Message));
            } catch (Exception ex) {
                return(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, "Oopsie (" + ex.GetType() + "): " + ex.Message, ex.StackTrace.Split('\n')));
            }
        }
        public object GetSite(int siteId, bool blocks = true)
        {
            try {
                // Look for the site with the specified ID
                IDashboardSite site = DashboardContext.Current.GetSiteById(siteId);

                // Throw an exception if the site wasn't found
                if (site == null)
                {
                    throw new DashboardException(HttpStatusCode.NotFound, "Det efterspurgte site blev ikke fundet.");
                }

                // Convert to JSON
                JObject obj = JObject.FromObject(site);

                if (blocks)
                {
                    obj.Add("blocks", JToken.FromObject(site.GetBlocks()));
                }

                return(obj);
            } catch (DashboardException ex) {
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            } catch (Exception ex) {
                return(Request.CreateResponse(JsonMetaResponse.GetError(
                                                  HttpStatusCode.InternalServerError,
                                                  "Unknown server error. Check the log for further information."
                                                  )));
            }
        }
Example #3
0
 private DashboardPage(IPublishedContent content, IDashboardSite site)
 {
     Content = content;
     Site    = site;
     Id      = content.Id;
     Name    = content.Name;
     Url     = content.UrlWithDomain();
 }
Example #4
0
 /// <summary>
 /// Sets the default <code>site</code> of the specified backoffice <code>user</code>.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="site">The site.</param>
 public static void SetDefaultSite(IUser user, IDashboardSite site)
 {
     if (user == null || site == null)
     {
         return;
     }
     SetValue(user, "site", site.Id);
 }
        public object GetPageData(int siteId, int pageId, string period, bool cache = true)
        {
            DashboardHelpers.EnsureCurrentUserCulture();

            try {
                // Look for the site with the specified ID
                IDashboardSite site = DashboardContext.Current.GetSiteById(siteId);
                if (site == null)
                {
                    throw new DashboardException(HttpStatusCode.NotFound, "Site ikke fundet", "Et site det angivne ID blev ikke fundet");
                }

                // Attempt to cast the site to an Analytics site
                IAnalyticsSite analytics = site as IAnalyticsSite;
                if (analytics == null || !analytics.HasAnalytics)
                {
                    throw new DashboardException(HttpStatusCode.InternalServerError, "Analytics", "Det valgte side understøtter eller er ikke konfigureret til visning af statistik fra Google Analytics");
                }

                // Get the published content of the page
                IPublishedContent content = UmbracoContext.ContentCache.GetById(pageId);

                // Build the query
                DataQuery query = DataQuery.GetFromPeriod(analytics, period, cache);
                query.Type   = DataQueryType.Page;
                query.PageId = content.Id;

                // Set the URL for the query. The protocol and domain is stripped so we only have the path
                query.PageUrl = Regex.Replace(content.Url, "^http(s|)://[a-z0-9-.]+/", "/");

                // Google Analytics sees the same URL with and without a trailing slash as two different pages, so we should tell the query to check both
                string pageUrlTrimmed = query.PageUrl.TrimEnd('/');
                string pageUrlSlashed = pageUrlTrimmed + '/';
                query.PageUrls = String.IsNullOrEmpty(pageUrlTrimmed) ? new[] { pageUrlSlashed } : new[] { pageUrlTrimmed, pageUrlSlashed };

                // Generate the response object
                DataResponse res = query.GetResponse();

                // Return a nice JSON response
                return(JsonMetaResponse.GetSuccess(res));
            } catch (DashboardException ex) {
                return(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Title + ": " + ex.Message));
            } catch (Exception ex) {
                return(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, "Oopsie (" + ex.GetType() + "): " + ex.Message, ex.StackTrace.Split('\n')));
            }
        }
Example #6
0
        /// <summary>
        /// Gets the site with the specified <code>siteId</code>, or <code>null</code> if the site couldn't be found.
        /// </summary>
        /// <param name="siteId">The ID of the site.</param>
        public IDashboardSite GetSiteById(int siteId)
        {
            // Get the sites specified by each resolver
            foreach (IDashboardPlugin plugin in Plugins)
            {
                try {
                    IDashboardSite site = plugin.GetSiteById(siteId);
                    if (site != null)
                    {
                        return(site);
                    }
                } catch (Exception ex) {
                    LogHelper.Error <DashboardContext>("Plugin of type " + plugin.GetType() + " has failed for GetSiteById(" + siteId + ")", ex);
                }
            }

            return(null);
        }
        public static LastEditedItem[] GetLastEditedData(IDashboardSite site, int userId, int max)
        {
            // List for constructing the raw query
            List <string> query = new List <string>();

            // Get a reference to the internal searcher
            BaseSearchProvider externalSearcher = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"];

            // Limit the search to pages under the specified site
            query.Add("sky_path:" + site.Id);

            // Limit the search to pages last edited by the specified user
            if (userId >= 0)
            {
                query.Add("writerID:" + userId);
            }

            // Initialize the criteria for the Examine search
            ISearchCriteria criteria = externalSearcher.CreateSearchCriteria().RawQuery(String.Join(" AND ", query));

            // Make the actual search in Examine
            ISearchResults results = externalSearcher.Search(criteria);

            // Order the results (and limit the amount of results)
            IEnumerable <SearchResult> sorted = results.OrderByDescending(x => x.Fields["updateDate"]).Take(max);

            return((
                       from result in sorted
                       select new LastEditedItem {
                Id = result.Id,
                CreateDate = ParseExamineDate(result.Fields["createDate"]),
                UpdateDate = ParseExamineDate(result.Fields["updateDate"]),
                IsPublished = UmbracoContext.Current.ContentCache.GetById(result.Id) != null,
                Name = result.Fields["nodeName"],
                Path = result.Fields["path"]
            }
                       ).ToArray());
        }
        public object GetLastEditedData(int siteId, int max = 5)
        {
            try {
                // Look for the site with the specified ID
                IDashboardSite site = DashboardContext.Current.GetSiteById(siteId);

                // Throw an exception if the site wasn't found
                if (site == null)
                {
                    throw new DashboardException(HttpStatusCode.NotFound, "Det efterspurgte site blev ikke fundet.");
                }

                // Get a reference to the current user
                //User user = umbraco.BusinessLogic.User.GetCurrent();

                // Get the last editied pages
                var pages = LastEditedItem.GetLastEditedData(site, null, max);

                // Return a nice JSON response
                return(new
                {
                    culture = CultureInfo.CurrentCulture.Name,
                    data = pages,
                });
            } catch (DashboardException ex) {
                LogHelper.Error <DashboardController>("Unable to load last edited pages for site with ID " + siteId, ex);

                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            } catch (Exception ex) {
                LogHelper.Error <DashboardController>("Unable to load last edited pages for site with ID " + siteId + ": " + ex.Message, ex);

                return(Request.CreateResponse(JsonMetaResponse.GetError(
                                                  HttpStatusCode.InternalServerError,
                                                  "Unknown server error. Check the log for further information."
                                                  )));
            }
        }
        public object SetDefaultSite(int siteId)
        {
            try {
                // Look for the site with the specified ID
                IDashboardSite site = DashboardContext.Current.GetSiteById(siteId);

                // Throw an exception if the site wasn't found
                if (site == null)
                {
                    throw new DashboardException(HttpStatusCode.NotFound, "Det efterspurgte site blev ikke fundet.");
                }

                DashboardHelpers.UserSettings.SetDefaultSite(UmbracoContext.Security.CurrentUser, site);

                return(site);
            } catch (DashboardException ex) {
                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            } catch (Exception ex) {
                return(Request.CreateResponse(JsonMetaResponse.GetError(
                                                  HttpStatusCode.InternalServerError,
                                                  "Unknown server error. Check the log for further information."
                                                  )));
            }
        }
        public object GetBlocksForSite(int siteId, int save = 0)
        {
            try {
                // Look for the site with the specified ID
                IDashboardSite site = DashboardContext.Current.GetSiteById(siteId);

                // Throw an exception if the site wasn't found
                if (site == null)
                {
                    throw new DashboardException(HttpStatusCode.NotFound, "Det efterspurgte site blev ikke fundet.");
                }

                // Set the active site of the user.
                //if (save == 1) DashboardHelpers.UserSettings.SetCurrentSite(umbraco.helper.GetCurrentUmbracoUser(), site);

                // Get the blocks for the site
                IDashboardBlock[] blocks = site.GetBlocks();

                // Return the blocks
                return(new {
                    site,
                    blocks
                });
            } catch (DashboardException ex) {
                LogHelper.Error <DashboardController>("Unable to load blocks for site with ID " + siteId, ex);

                return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, ex.Message)));
            } catch (Exception ex) {
                LogHelper.Error <DashboardController>("Unable to load blocks for site with ID " + siteId, ex);

                return(Request.CreateResponse(JsonMetaResponse.GetError(
                                                  HttpStatusCode.InternalServerError,
                                                  "Unknown server error. Check the log for further information."
                                                  )));
            }
        }
 public static LastEditedItem[] GetLastEditedData(IDashboardSite site, IUser user)
 {
     return(GetLastEditedData(site, user == null ? -1 : user.Id, 15));
 }
 /// <summary>
 /// Gets the 15 last edited pages for the specified <code>site</code>.
 /// </summary>
 /// <param name="site">The site.</param>
 /// <returns>Returns an array of <see cref="LastEditedItem"/>.</returns>
 public static LastEditedItem[] GetLastEditedData(IDashboardSite site)
 {
     return(GetLastEditedData(site, -1, 15));
 }
 public static LastEditedItem[] GetLastEditedData(IDashboardSite site, User user, int max)
 {
     return(GetLastEditedData(site, user == null ? -1 : user.Id, max));
 }
Example #14
0
 public static DashboardPage GetFromContent(IPublishedContent content, IDashboardSite site = null)
 {
     return(content == null ? null : new DashboardPage(content, site));
 }