Exemplo n.º 1
0
        public static void Show(Core core, TPage page, Primitive owner, int year, int month)
        {
            core.Template.SetTemplate("Calendar", "viewcalendarmonth");

            if (month < 1 || month > 12)
            {
                core.Functions.Generate404();
            }

            // 15 year window
            if (year < DateTime.Now.Year - 10 || year > DateTime.Now.Year + 5)
            {
                core.Functions.Generate404();
            }

            /* pages */
            core.Display.ParsePageList(owner, true);

            core.Template.Parse("PAGE_TITLE", core.Functions.IntToMonth(month) + " " + year.ToString());

            core.Template.Parse("CURRENT_MONTH", core.Functions.IntToMonth(month));
            core.Template.Parse("CURRENT_YEAR", year.ToString());

            core.Template.Parse("U_PREVIOUS_MONTH", Calendar.BuildMonthUri(core, owner, YearOfPreviousMonth(year, month), PreviousMonth(month)));
            core.Template.Parse("U_NEXT_MONTH", Calendar.BuildMonthUri(core, owner, YearOfNextMonth(year, month), NextMonth(month)));

            Calendar cal = null;
            try
            {
                cal = new Calendar(core, owner);
            }
            catch (InvalidCalendarException)
            {
                cal = Calendar.Create(core, owner);
            }

            if (cal.Access.Can("CREATE_EVENTS"))
            {
                core.Template.Parse("U_NEW_EVENT", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-event", true,
                    string.Format("year={0}", year),
                    string.Format("month={0}", month),
                    string.Format("day={0}", ((month == core.Tz.Now.Month) ? core.Tz.Now.Day : 1))));
            }

            int days = DateTime.DaysInMonth(year, month);
            DayOfWeek firstDay = new DateTime(year, month, 1).DayOfWeek;
            int offset = Calendar.GetFirstDayOfMonthOffset(firstDay);
            int weeks = (int)Math.Ceiling((days + offset) / 7.0);
            int daysPrev = DateTime.DaysInMonth(YearOfPreviousMonth(year, month), PreviousMonth(month));

            long startTime = 0;
            if (offset > 0)
            {
                // the whole month including entry days
                startTime = core.Tz.GetUnixTimeStamp(new DateTime(YearOfPreviousMonth(year, month), PreviousMonth(month), daysPrev - offset + 1, 0, 0, 0));
            }
            else
            {
                // the whole month
                startTime = core.Tz.GetUnixTimeStamp(new DateTime(year, month, 1, 0, 0, 0));
            }

            // the whole month including exit days
            long endTime = startTime + 60 * 60 * 24 * weeks * 7;

            List<Event> events = cal.GetEvents(core, owner, startTime, endTime);

            /*if (startTime == -8885289600 || startTime == 11404281600 || endTime == -8885289600 || endTime == 11404281600)
            {
                Functions.Generate404();
                return;
            }*/

            for (int week = 0; week < weeks; week++)
            {
                VariableCollection weekVariableCollection = core.Template.CreateChild("week");

                weekVariableCollection.Parse("WEEK", (week + 1).ToString());

                /* lead in week */
                if (week + 1 == 1)
                {
                    int daysPrev2 = DateTime.DaysInMonth(YearOfPreviousMonth(year, month), PreviousMonth(month));
                    /* days in month prior */
                    for (int i = offset - 1; i >= 0; i--)
                    {
                        int day = daysPrev2 - i;

                        Calendar.showDayEvents(core, owner, YearOfPreviousMonth(year, month), PreviousMonth(month), day, weekVariableCollection, events);
                    }
                    /* first days in month */
                    for (int i = offset; i < 7; i++)
                    {
                        int day = i - offset + 1;

                        Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events);
                    }
                }
                /* lead out week */
                else if (week + 1 == weeks)
                {
                    /* last days in month */
                    for (int i = week * 7 - offset; i < days; i++)
                    {
                        int day = i + 1;

                        Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events);
                    }
                    /* days in month upcoming */
                    for (int i = 0; i < weeks * 7 - days - offset; i++)
                    {
                        int day = i + 1;

                        Calendar.showDayEvents(core, owner, YearOfNextMonth(year, month), NextMonth(month), day, weekVariableCollection, events);
                    }
                }
                else
                {
                    for (int i = 0; i < 7; i++)
                    {
                        int day = week * 7 + i + 1 - offset;

                        Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events);
                    }
                }
            }

            List<string[]> calendarPath = new List<string[]>();
            calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") });
            calendarPath.Add(new string[] { year.ToString(), year.ToString() });
            calendarPath.Add(new string[] { month.ToString(), core.Functions.IntToMonth(month) });
            owner.ParseBreadCrumbs(calendarPath);
        }
Exemplo n.º 2
0
        public static void Show(Core core, TPage page, Primitive owner, int year, int month, int day)
        {
            core.Template.SetTemplate("Calendar", "viewcalendarday");

            // 15 year window
            if (year < DateTime.Now.Year - 10 || year > DateTime.Now.Year + 5)
            {
                core.Functions.Generate404();
            }

            if (month < 1 || month > 12)
            {
                core.Functions.Generate404();
            }

            if (day < 1 || day > DateTime.DaysInMonth(year, month))
            {
                core.Functions.Generate404();
            }

            /* pages */
            core.Display.ParsePageList(owner, true);

            core.Template.Parse("PAGE_TITLE", day.ToString() + " " + core.Functions.IntToMonth(month) + " " + year.ToString());

            core.Template.Parse("CURRENT_DAY", day.ToString());
            core.Template.Parse("CURRENT_MONTH", core.Functions.IntToMonth(month));
            core.Template.Parse("CURRENT_YEAR", year.ToString());

            long startTime = core.Tz.GetUnixTimeStamp(new DateTime(year, month, day, 0, 0, 0));
            long endTime = startTime + 60 * 60 * 24;

            Calendar cal = null;
            try
            {
                cal = new Calendar(core, owner);
            }
            catch (InvalidCalendarException)
            {
                cal = Calendar.Create(core, owner);
            }

            if (cal.Access.Can("CREATE_EVENTS"))
            {
                core.Template.Parse("U_NEW_EVENT", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-event", true,
                    string.Format("year={0}", year),
                    string.Format("month={0}", month),
                    string.Format("day={0}", day)));
            }

            List<Event> events = cal.GetEvents(core, owner, startTime, endTime);

            bool hasAllDaysEvents = false;

            foreach (Event calendarEvent in events)
            {
                if (calendarEvent.AllDay)
                {
                    hasAllDaysEvents = true;
                    VariableCollection eventVariableCollection = core.Template.CreateChild("event");

                    eventVariableCollection.Parse("TITLE", calendarEvent.Subject);
                    eventVariableCollection.Parse("URI", calendarEvent.Uri);
                }
            }

            if (hasAllDaysEvents)
            {
                core.Template.Parse("ALL_DAY_EVENTS", "TRUE");
            }

            VariableCollection[] hours = new VariableCollection[24];

            for (int hour = 0; hour < 24; hour++)
            {
                VariableCollection timeslotVariableCollection = core.Template.CreateChild("timeslot");

                DateTime hourTime = new DateTime(year, month, day, hour, 0, 0);

                timeslotVariableCollection.Parse("TIME", hourTime.ToString("h tt").ToLower());
                hours[hour] = timeslotVariableCollection;
            }

            showHourEvents(core, owner, year, month, day, hours, events);

            List<string[]> calendarPath = new List<string[]>();
            calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") });
            calendarPath.Add(new string[] { year.ToString(), year.ToString() });
            calendarPath.Add(new string[] { month.ToString(), core.Functions.IntToMonth(month) });
            calendarPath.Add(new string[] { day.ToString(), day.ToString() });
            owner.ParseBreadCrumbs(calendarPath);
        }
Exemplo n.º 3
0
 public static void Show(Core core, TPage page, Primitive owner)
 {
     Show(core, page, owner, core.Tz.Now.Year, core.Tz.Now.Month);
 }
Exemplo n.º 4
0
        public static void Show(Core core, TPage page, Primitive owner, int year)
        {
            core.Template.SetTemplate("Calendar", "viewcalendaryear");

            // 15 year window
            if (year < DateTime.Now.Year - 10 || year > DateTime.Now.Year + 5)
            {
                core.Functions.Generate404();
            }

            /* pages */
            core.Display.ParsePageList(owner, true);

            core.Template.Parse("PAGE_TITLE", year.ToString());

            core.Template.Parse("CURRENT_YEAR", year.ToString());

            if (year - 1 >= DateTime.Now.Year - 10)
            {
                core.Template.Parse("U_PREVIOUS_YEAR", Calendar.BuildYearUri(core, owner, year - 1));
            }
            if (year + 1 <= DateTime.Now.Year + 5)
            {
                core.Template.Parse("U_NEXT_YEAR", Calendar.BuildYearUri(core, owner, year + 1));
            }

            for (int i = 1; i <= 12; i++)
            {
                DisplayMiniCalendar(core, core.Template.CreateChild("month"), owner, year, i);
            }

            List<string[]> calendarPath = new List<string[]>();
            calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") });
            calendarPath.Add(new string[] { year.ToString(), year.ToString() });
            owner.ParseBreadCrumbs(calendarPath);
        }
Exemplo n.º 5
0
        public static void Show(Core core, TPage page, User owner)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (!owner.Access.Can("VIEW"))
            {
                core.Functions.Generate403();
                return;
            }

            if (core.ResponseFormat == ResponseFormats.Xml)
            {
                ShowMore(core, page, owner);
                return;
            }

            core.Template.SetTemplate("Profile", "viewfeed");

            if (core.Session.IsLoggedIn && owner == core.Session.LoggedInMember)
            {
                core.Template.Parse("OWNER", "TRUE");

            }

            core.Template.Parse("PAGE_TITLE", core.Prose.GetString("FEED"));

            PermissionGroupSelectBox permissionSelectBox = new PermissionGroupSelectBox(core, "permissions", owner.ItemKey);

            core.Template.Parse("S_STATUS_PERMISSIONS", permissionSelectBox);

            bool moreContent;
            long lastId = 0;
            bool first = true;

            List<Action> feedActions = CombinedFeed.GetItems(core, owner, page.TopLevelPageNumber, 20, page.TopLevelPageOffset, out moreContent);

            foreach (Action feedAction in feedActions)
            {
                if (first)
                {
                    first = false;
                    core.Template.Parse("NEWEST_ID", feedAction.Id.ToString());
                }

                VariableCollection feedItemVariableCollection = core.Template.CreateChild("feed_days_list.feed_item");

                core.Display.ParseBbcode(feedItemVariableCollection, "TITLE", feedAction.FormattedTitle);
                core.Display.ParseBbcode(feedItemVariableCollection, "TEXT", feedAction.Body, core.PrimitiveCache[feedAction.OwnerId], true, string.Empty, string.Empty);

                feedItemVariableCollection.Parse("USER_DISPLAY_NAME", feedAction.Owner.DisplayName);

                feedItemVariableCollection.Parse("ID", feedAction.ActionItemKey.Id);
                feedItemVariableCollection.Parse("TYPE_ID", feedAction.ActionItemKey.TypeId);

                if (feedAction.ActionItemKey.GetType(core).Likeable)
                {
                    feedItemVariableCollection.Parse("LIKEABLE", "TRUE");

                    if (feedAction.Info.Likes > 0)
                    {
                        feedItemVariableCollection.Parse("LIKES", string.Format(" {0:d}", feedAction.Info.Likes));
                        feedItemVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", feedAction.Info.Dislikes));
                    }
                }

                if (feedAction.ActionItemKey.GetType(core).Commentable)
                {
                    feedItemVariableCollection.Parse("COMMENTABLE", "TRUE");

                    if (feedAction.Info.Comments > 0)
                    {
                        feedItemVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", feedAction.Info.Comments));
                    }
                }

                //Access access = new Access(core, feedAction.ActionItemKey, true);
                if (feedAction.PermissiveParent.Access.IsPublic())
                {
                    feedItemVariableCollection.Parse("IS_PUBLIC", "TRUE");
                    if (feedAction.ActionItemKey.GetType(core).Shareable)
                    {
                        feedItemVariableCollection.Parse("SHAREABLE", "TRUE");
                        //feedItemVariableCollection.Parse("U_SHARE", feedAction.ShareUri);

                        if (feedAction.Info.SharedTimes > 0)
                        {
                            feedItemVariableCollection.Parse("SHARES", string.Format(" {0:d}", feedAction.Info.SharedTimes));
                        }
                    }
                }
                else
                {
                    feedItemVariableCollection.Parse("IS_PUBLIC", "FALSE");
                    feedItemVariableCollection.Parse("SHAREABLE", "FALSE");
                }

                if (feedAction.Owner is User)
                {
                    feedItemVariableCollection.Parse("USER_TILE", ((User)feedAction.Owner).Tile);
                    feedItemVariableCollection.Parse("USER_ICON", ((User)feedAction.Owner).Icon);
                }

                lastId = feedAction.Id;
            }

            core.Display.ParseBlogPagination(core.Template, "PAGINATION", core.Hyperlink.BuildCombinedFeedUri((User)owner), 0, moreContent ? lastId : 0);
            core.Template.Parse("U_NEXT_PAGE", core.Hyperlink.BuildCombinedFeedUri((User)owner) + "?p=" + (core.TopLevelPageNumber + 1) + "&o=" + lastId);

            /* pages */
            core.Display.ParsePageList(owner, true);

            List<string[]> breadCrumbParts = new List<string[]>();

            breadCrumbParts.Add(new string[] { "*profile", core.Prose.GetString("PROFILE") });
            breadCrumbParts.Add(new string[] { "feed", core.Prose.GetString("FEED") });

            owner.ParseBreadCrumbs(breadCrumbParts);
        }
Exemplo n.º 6
0
        public static void ShowMore(Core core, TPage page, User owner)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            Template template = new Template("pane.feeditem.html");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            bool moreContent = false;
            long lastId = 0;
            List<Action> feedActions = CombinedFeed.GetItems(core, owner, page.TopLevelPageNumber, 20, page.TopLevelPageOffset, out moreContent);

            foreach (Action feedAction in feedActions)
            {
                VariableCollection feedItemVariableCollection = template.CreateChild("feed_days_list.feed_item");

                core.Display.ParseBbcode(feedItemVariableCollection, "TITLE", feedAction.FormattedTitle);
                core.Display.ParseBbcode(feedItemVariableCollection, "TEXT", feedAction.Body, core.PrimitiveCache[feedAction.OwnerId], true, string.Empty, string.Empty);

                feedItemVariableCollection.Parse("USER_DISPLAY_NAME", feedAction.Owner.DisplayName);

                feedItemVariableCollection.Parse("ID", feedAction.ActionItemKey.Id);
                feedItemVariableCollection.Parse("TYPE_ID", feedAction.ActionItemKey.TypeId);

                if (feedAction.ActionItemKey.GetType(core).Likeable)
                {
                    feedItemVariableCollection.Parse("LIKEABLE", "TRUE");

                    if (feedAction.Info.Likes > 0)
                    {
                        feedItemVariableCollection.Parse("LIKES", string.Format(" {0:d}", feedAction.Info.Likes));
                        feedItemVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", feedAction.Info.Dislikes));
                    }
                }

                if (feedAction.ActionItemKey.GetType(core).Commentable)
                {
                    feedItemVariableCollection.Parse("COMMENTABLE", "TRUE");

                    if (feedAction.Info.Comments > 0)
                    {
                        feedItemVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", feedAction.Info.Comments));
                    }
                }

                //Access access = new Access(core, feedAction.ActionItemKey, true);
                if (feedAction.PermissiveParent.Access.IsPublic())
                {
                    feedItemVariableCollection.Parse("IS_PUBLIC", "TRUE");
                    if (feedAction.ActionItemKey.GetType(core).Shareable)
                    {
                        feedItemVariableCollection.Parse("SHAREABLE", "TRUE");
                        //feedItemVariableCollection.Parse("U_SHARE", feedAction.ShareUri);

                        if (feedAction.Info.SharedTimes > 0)
                        {
                            feedItemVariableCollection.Parse("SHARES", string.Format(" {0:d}", feedAction.Info.SharedTimes));
                        }
                    }
                }

                if (feedAction.Owner is User)
                {
                    feedItemVariableCollection.Parse("USER_TILE", ((User)feedAction.Owner).Tile);
                    feedItemVariableCollection.Parse("USER_ICON", ((User)feedAction.Owner).Icon);
                }

                lastId = feedAction.Id;
            }

            string loadMoreUri = core.Hyperlink.BuildHomeUri() + "?p=" + (core.TopLevelPageNumber + 1) + "&o=" + lastId;
            core.Response.SendRawText(moreContent ? loadMoreUri : "noMoreContent", template.ToString());
        }
Exemplo n.º 7
0
        public static void ShowAll(Core core, TPage page, Primitive owner)
        {
            core.Template.SetTemplate("Calendar", "viewcalendartasks");

            long startTime = core.Tz.GetUnixTimeStamp(new DateTime(core.Tz.Now.Year, core.Tz.Now.Month, core.Tz.Now.Day, 0, 0, 0)) - 60 * 60 * 24 * 7; // show tasks completed over the last week
            long endTime = startTime + 60 * 60 * 24 * 7 * (8 + 1); // skip ahead eight weeks into the future

            Calendar cal = null;
            try
            {
                cal = new Calendar(core, owner);
            }
            catch (InvalidCalendarException)
            {
                cal = Calendar.Create(core, owner);
            }

            if (cal.Access.Can("CREATE_TASKS"))
            {
                core.Template.Parse("U_NEW_TASK", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-task", true,
                    string.Format("year={0}", core.Tz.Now.Year),
                    string.Format("month={0}", core.Tz.Now.Month),
                    string.Format("day={0}", core.Tz.Now.Day)));
            }

            List<Task> tasks = cal.GetTasks(core, owner, startTime, endTime, true);

            /* pages */
            core.Display.ParsePageList(owner, true);

            core.Template.Parse("PAGE_TITLE", core.Prose.GetString("TASKS"));

            VariableCollection taskDaysVariableCollection = null;
            string lastDay = core.Tz.ToStringPast(core.Tz.Now);

            if (tasks.Count > 0)
            {
                core.Template.Parse("HAS_TASKS", "TRUE");
            }

            foreach (Task calendarTask in tasks)
            {
                DateTime taskDue = calendarTask.GetDueTime(core.Tz);

                if (taskDaysVariableCollection == null || lastDay != core.Tz.ToStringPast(taskDue))
                {
                    lastDay = core.Tz.ToStringPast(taskDue);
                    taskDaysVariableCollection = core.Template.CreateChild("task_days");

                    taskDaysVariableCollection.Parse("DAY", lastDay);
                }

                VariableCollection taskVariableCollection = taskDaysVariableCollection.CreateChild("task_list");

                taskVariableCollection.Parse("DATE", taskDue.ToShortDateString() + " (" + taskDue.ToShortTimeString() + ")");
                taskVariableCollection.Parse("TOPIC", calendarTask.Topic);
                taskVariableCollection.Parse("ID", calendarTask.Id.ToString());
                taskVariableCollection.Parse("URI", Task.BuildTaskUri(core, calendarTask));
                taskVariableCollection.Parse("U_MARK_COMPLETE", Task.BuildTaskMarkCompleteUri(core, calendarTask));

                if (calendarTask.Status == TaskStatus.Overdue)
                {
                    taskVariableCollection.Parse("OVERDUE", "TRUE");
                    taskVariableCollection.Parse("CLASS", "overdue-task");
                }
                else if (calendarTask.Status == TaskStatus.Completed)
                {
                    taskVariableCollection.Parse("COMPLETE", "TRUE");
                    taskVariableCollection.Parse("CLASS", "complete-task");
                }
                else
                {
                    taskVariableCollection.Parse("CLASS", "task");
                }

                // TODO: fix this
                if (calendarTask.Priority == TaskPriority.High)
                {
                    taskDaysVariableCollection.ParseRaw("PRIORITY", "[<span class=\"high-priority\" title=\"High Priority\">H</span>]");
                }
                else if (calendarTask.Priority == TaskPriority.Low)
                {
                    taskDaysVariableCollection.ParseRaw("PRIORITY", "[<span class=\"low-priority\" title=\"Low Priority\">L</span>]");
                }
            }

            List<string[]> calendarPath = new List<string[]>();
            calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") });
            calendarPath.Add(new string[] { "*tasks", core.Prose.GetString("TASKS") });
            owner.ParseBreadCrumbs(calendarPath);
        }
Exemplo n.º 8
0
        /// <summary>
        /// returns true on success
        /// </summary>
        /// <param name="page"></param>
        /// <param name="member"></param>
        /// <returns></returns>
        public bool Activate(TPage page, User member, string activateKey)
        {
            long rowsChanged = db.UpdateQuery(string.Format("UPDATE network_members SET member_active = 1 WHERE network_id = {0} AND user_id = {1} AND member_activate_code = '{2}' AND member_active = 0;",
                networkId, member.UserId, activateKey));

            db.UpdateQuery(string.Format("UPDATE network_info SET network_members = network_members + {1} WHERE network_id = {0}",
                networkId, rowsChanged));

            if (rowsChanged == 1)
            {
                networkMemberCache.Add(member.ItemKey, true);
                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Do all header preparation tasks
        /// </summary>
        /// <param name="template">The template that represents the current page</param>
        /// <param name="User"></param>
        /// <param name="loggedInMember"></param>
        public void Header(TPage page)
        {
            Template template = core.Template;
            SessionState session = page.session;

            string noHeader = core.Http["no-header"];
            if (noHeader == null || noHeader.ToLower() != "true")
            {
                template.Parse("S_HEADER", "TRUE");
            }

            template.Parse("TITLE", page.PageTitle); // the set page title function sanitises
            template.Parse("HEADING", page.Core.Settings.SiteTitle);
            template.Parse("SITE_TITLE", page.Core.Settings.SiteTitle);
            template.Parse("SITE_SLOGAN", page.Core.Settings.SiteSlogan);
            template.Parse("YEAR", DateTime.Now.Year.ToString());

            if (page.CanonicalUri != null)
            {
                template.Parse("CANONICAL_URI", page.CanonicalUri);
            }

            template.Parse("HEAD_COLOUR", "ffffff");
            template.Parse("HEAD_FORE_COLOUR", "black");

            if (core.Settings.UseCdn && !string.IsNullOrEmpty(page.Core.Settings.CdnStaticBucketDomain))
            {
                if (core.Http.IsSecure)
                {
                    template.Parse("U_STATIC", "https://" + page.Core.Settings.CdnStaticBucketDomain.TrimEnd(new char[] { '/' }));
                }
                else
                {
                    template.Parse("U_STATIC", "http://" + page.Core.Settings.CdnStaticBucketDomain.TrimEnd(new char[] { '/' }));
                }
            }

            /*
             * URIs
             */
            template.Parse("U_HOME", page.Core.Hyperlink.BuildHomeUri());
            template.Parse("U_ABOUT", page.Core.Hyperlink.BuildAboutUri());
            template.Parse("U_SAFETY", page.Core.Hyperlink.BuildSafetyUri());
            template.Parse("U_PRIVACY", page.Core.Hyperlink.BuildPrivacyUri());
            template.Parse("U_TOS", page.Core.Hyperlink.BuildTermsOfServiceUri());
            template.Parse("U_SIGNIN", page.Core.Hyperlink.BuildLoginUri());
            template.Parse("U_SIGNOUT", page.Core.Hyperlink.BuildLogoutUri());
            template.Parse("U_REGISTER", page.Core.Hyperlink.BuildRegisterUri());
            template.Parse("U_HELP", page.Core.Hyperlink.BuildHelpUri());
            template.Parse("U_SITEMAP", page.Core.Hyperlink.BuildSitemapUri());
            template.Parse("U_COPYRIGHT", page.Core.Hyperlink.BuildCopyrightUri());
            template.Parse("U_SEARCH", page.Core.Hyperlink.BuildSearchUri());
            template.Parse("S_SEARCH", page.Core.Hyperlink.BuildSearchUri());

            template.Parse("U_FOOT_GROUPS", page.Core.Hyperlink.BuildGroupsUri());
            template.Parse("U_FOOT_NETWORKS", page.Core.Hyperlink.BuildNetworksUri());

            template.Parse("U_FOOT_MUSIC", page.Core.Hyperlink.BuildMusicUri());
            template.Parse("U_FOOT_MUSIC_DIRECTORY", page.Core.Hyperlink.BuildMusicDirectoryUri());
            template.Parse("U_FOOT_MUSIC_CHART", page.Core.Hyperlink.BuildMusicChartUri());

            if (session != null)
            {
                template.Parse("SID", session.SessionId);
                if (session.IsLoggedIn && session.LoggedInMember != null)
                {
                    template.Parse("LOGGED_IN", "TRUE");
                    template.Parse("USERNAME", session.LoggedInMember.UserName);
                    template.Parse("USER_ID", session.LoggedInMember.Id.ToString());
                    template.Parse("LOGGED_IN_USER_DISPLAY_NAME", session.LoggedInMember.DisplayName);
                    template.Parse("LOGGED_IN_USER_TILE", session.LoggedInMember.Tile);
                    template.Parse("LOGGED_IN_USER_ICON", session.LoggedInMember.Icon);
                    template.Parse("U_USER_PROFILE", session.LoggedInMember.Uri);
                    template.Parse("U_ACCOUNT", core.Hyperlink.BuildAccountUri());

                    string formSubmitUri = core.Hyperlink.AppendSid(session.LoggedInMember.AccountUriStub, true);
                    template.Parse("S_ACCOUNT", formSubmitUri);

                    template.Parse("UNREAD_NOTIFICATIONS", session.LoggedInMember.UserInfo.UnreadNotifications);

                    if (session.LoggedInMember.UserInfo.UnseenMail > 0)
                    {
                        template.Parse("UNSEEN_MAIL", "TRUE");
                    }
                    template.Parse("U_UNSEEN_MAIL", core.Hyperlink.BuildAccountSubModuleUri("mail", "inbox"));
                }
                if (!core.Hyperlink.SidUrls)
                {
                    template.Parse("S_TRIM_SID", "TRUE");
                }
            }

            template.Parse("IS_CONTENT", "TRUE");

            if (WebConfigurationManager.AppSettings != null && WebConfigurationManager.AppSettings.HasKeys())
            {
                template.Parse("ANALYTICS_CODE", WebConfigurationManager.AppSettings["analytics-code"]);

                template.ParseRaw("ADSENSE_CODE_HEADER", WebConfigurationManager.AppSettings["adsense-code-header"]);
                template.ParseRaw("ADSENSE_CODE_FOOTER", WebConfigurationManager.AppSettings["adsense-code-footer"]);
            }

            foreach (string name in core.Meta.Keys)
            {
                VariableCollection metaVariableCollection = template.CreateChild("meta_list");

                metaVariableCollection.Parse("NAME", name);
                metaVariableCollection.ParseRaw("CONTENT", core.Meta[name]);
            }
        }
Exemplo n.º 10
0
        public static void Show(Core core, TPage page, Primitive owner, long taskId)
        {
            core.Template.SetTemplate("Calendar", "viewcalendartask");

            try
            {
                Task calendarTask = new Task(core, owner, taskId);

                if (!calendarTask.Access.Can("VIEW"))
                {
                    core.Functions.Generate403();
                    return;
                }

                if (calendarTask.Calendar.Access.Can("CREATE_TASKS"))
                {
                    core.Template.Parse("U_NEW_TASK", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-task", true,
                        string.Format("year={0}", core.Tz.Now.Year),
                        string.Format("month={0}", core.Tz.Now.Month),
                        string.Format("day={0}", core.Tz.Now.Day)));
                }

                if (calendarTask.Access.Can("EDIT"))
                {
                    core.Template.Parse("U_EDIT_TASK", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-task", "edit", taskId, true));
                }

                /* pages */
                core.Display.ParsePageList(owner, true);

                core.Template.Parse("PAGE_TITLE", calendarTask.Topic);

                core.Template.Parse("TOPIC", calendarTask.Topic);
                core.Template.Parse("DESCRIPTION", calendarTask.Description);
                core.Template.Parse("DUE_DATE", calendarTask.GetDueTime(core.Tz).ToString());

                List<string[]> calendarPath = new List<string[]>();

                calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") });
                calendarPath.Add(new string[] { "*tasks", core.Prose.GetString("TASKS") });
                calendarPath.Add(new string[] { "task/" + calendarTask.TaskId.ToString(), calendarTask.Topic });

                owner.ParseBreadCrumbs(calendarPath);
            }
            catch (InvalidTaskException)
            {
                core.Display.ShowMessage("Invalid submission", "You have made an invalid form submission.");
            }
        }
Exemplo n.º 11
0
        public Core(TPage page, ResponseFormats responseFormat, Mysql db, Template template)
        {
            HeadHooks += new HookHandler(Core_HeadHooks);
            PrimitiveHeadHooks += new HookHandler(Core_PrimitiveHeadHooks);
            FootHooks +=new HookHandler(Core_FootHooks);
            PageHooks += new HookHandler(Core_Hooks);
            PostHooks += new HookHandler(Core_PostHooks);
            LoadApplication += new LoadHandler(Core_LoadApplication);

            this.page = page;
            this.db = db;
            this.template = template;
            this.responseFormat = responseFormat;

            ItemKey.populateItemTypeCache(this);
            //QueryCache.populateQueryCache();

            userProfileCache = new PrimitivesCache(this);
            itemsCache = new NumberedItemsCache(this);
            accessControlCache = new AccessControlCache(this);

            primitiveTypes = ItemKey.GetPrimitiveTypes(this);
        }
Exemplo n.º 12
0
        public void InvokeApplicationCall(ApplicationEntry ae, string callName)
        {
            if (ae == null)
            {
                // Internal calls
                switch (callName)
                {
                    case "item_types":
                        this.Functions.ReturnItemTypeIds();
                        break;
                    case "update":

                        break;
                    case "feed":
                        Feed.ShowMore(this, Session.LoggedInMember);
                        break;
                    case "primitive":
                        break;
                    case "permission_groups":
                        this.Functions.ReturnPermissionGroupList(ResponseFormats.Json);
                        break;
                    case "page_list":
                        {
                            long id = Functions.RequestLong("id", 0);
                            long typeId = Functions.RequestLong("type_id", 0);
                            string path = Http["path"];
                            ItemKey ownerKey = new ItemKey(id, typeId);

                            PrimitiveCache.LoadPrimitiveProfile(ownerKey);
                            Primitive owner = PrimitiveCache[ownerKey];

                            if (owner != null)
                            {
                                Page page = null;
                                if (!string.IsNullOrEmpty(path))
                                {
                                    page = new Page(this, owner, path);
                                }

                                List<Page> pages = Display.GetPageList(owner, Session.LoggedInMember, page);

                                Response.WriteObject(pages);
                            }
                        }
                        break;
                    case "comments":
                        {
                            long id = Functions.RequestLong("id", 0);
                            long typeId = Functions.RequestLong("type_id", 0);
                            int page = Math.Max(Functions.RequestInt("page", 1), 1);
                            int perPage = Math.Max(Math.Min(20, Functions.RequestInt("per_page", 10)), 1);
                            SortOrder order = Http["sort_order"] == "DESC" ? SortOrder.Descending : SortOrder.Ascending;

                            ItemKey itemKey = new ItemKey(id, typeId);

                            // Check ACLs
                            ICommentableItem item = (ICommentableItem)NumberedItem.Reflect(this, itemKey);
                            bool canViewComments = true;

                            if (item is IPermissibleItem)
                            {
                                if (!((IPermissibleItem)item).Access.Can("VIEW"))
                                {
                                    canViewComments = false;
                                }
                            }

                            if (canViewComments)
                            {
                                List<Comment> comments = Comment.GetComments(this, itemKey, order, page, perPage, null);

                                Response.WriteObject(comments);
                            }
                        }
                        break;
                    case "comment_post":
                        Comment newComment = Comment.Post(this);

                        Response.WriteObject(newComment);
                        break;
                    case "comment_report":
                        //Comment.Report(this);
                        break;
                    case "comment_delete":
                        try
                        {
                            Comment.Delete(this);
                        }
                        catch (InvalidCommentException)
                        {
                            this.Response.ShowMessage("error", "Error", "An error was encountered while deleting the comment, the comment has not been deleted.");
                        }
                        catch (PermissionDeniedException)
                        {
                            this.Response.ShowMessage("permission-denied", "Permission Denied", "You do not have the permissions to delete this comment.");
                        }
                        break;
                    case "rate":
                        {
                            int rating = Functions.RequestInt("rating", 0);
                            long itemId = Functions.RequestLong("item", 0);
                            long itemTypeId = Functions.RequestLong("type", 0);
                            ItemKey itemKey = null;

                            try
                            {
                                itemKey = new ItemKey(itemId, itemTypeId);
                            }
                            catch
                            {
                            }

                            Rating.Vote(this, itemKey, rating);
                        }
                        break;
                    case "get_rating":
                        {
                            long itemId = Functions.RequestLong("item", 0);
                            long itemTypeId = Functions.RequestLong("type", 0);

                            ItemKey itemKey = null;

                            try
                            {
                                itemKey = new ItemKey(itemId, itemTypeId);
                            }
                            catch
                            {
                            }

                            ItemInfo info = new ItemInfo(this, itemKey);

                            Response.WriteObject(info.Rating);
                        }
                        break;
                    case "like":
                        {
                            long itemId = Functions.RequestLong("item", 0);
                            long itemTypeId = Functions.RequestLong("type", 0);
                            string type = this.Http["like"];
                            ItemKey itemKey = null;

                            try
                            {
                                itemKey = new ItemKey(itemId, itemTypeId);
                            }
                            catch
                            {
                            }

                            try
                            {
                                LikeType like = LikeType.Neutral;
                                switch (type)
                                {
                                    case "like":
                                        like = LikeType.Like;
                                        break;
                                    case "dislike":
                                        like = LikeType.Dislike;
                                        break;
                                }
                                Like.LikeItem(this, itemKey, like);

                                switch (like)
                                {
                                    case LikeType.Like:
                                        //NotificationSubscription.Create(core, loggedInMember, itemKey);
                                        try
                                        {
                                            Subscription.SubscribeToItem(this, itemKey);
                                        }
                                        catch (AlreadySubscribedException)
                                        {
                                            // not a problem
                                        }
                                        break;
                                    case LikeType.Neutral:
                                    case LikeType.Dislike:
                                        //NotificationSubscription.Unsubscribe(core, loggedInMember, itemKey);
                                        Subscription.UnsubscribeFromItem(this, itemKey);
                                        break;
                                }
                            }
                            catch
                            {

                            }
                        }
                        break;
                    case "subscribe":
                        {
                            string mode = this.Http["mode"];
                            long itemId = this.Functions.RequestLong("item_id", 0);
                            long itemTypeId = this.Functions.RequestLong("item_type_id", 0);

                            ItemKey itemKey = null;

                            try
                            {
                                itemKey = new ItemKey(itemId, itemTypeId);
                            }
                            catch
                            {
                                this.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to subscribe to is invalid.");
                                return;
                            }

                            //Subscription.Register();
                        }
                        break;
                }
            }
            else
            {
                Application callApplication = Application.GetApplication(this, AppPrimitives.Any, ae);

                if (callApplication != null)
                {
                    callApplication.ExecuteCall(callName);
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Bind the module to the account panel.
        /// </summary>
        /// <param name="account"></param>
        private void Bind(Account account)
        {
            account.RegisterModule += new Account.RegisterModuleHandler(RegisterModule);

            core = account.core;
            page = account.core.page;
            db = account.core.Db;
            loggedInMember = account.core.Session.LoggedInMember;
            tz = account.core.Tz;
            session = account.core.Session;
        }
Exemplo n.º 14
0
 public ShowPageEventArgs(TPage page)
 {
     this.page = page;
     this.core = page.Core;
 }
Exemplo n.º 15
0
        public static void Show(Core core, TPage page, User owner)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (core.ResponseFormat == ResponseFormats.Xml)
            {
                ShowMore(core, page, owner);
                return;
            }

            Template template = new Template(core.Http.TemplatePath, "viewfeed.html");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            PermissionGroupSelectBox permissionSelectBox = new PermissionGroupSelectBox(core, "permissions", owner.ItemKey);

            template.Parse("S_STATUS_PERMISSIONS", permissionSelectBox);

            bool moreContent = false;
            long lastId = 0;
            bool first = true;

            List<Action> feedActions = Feed.GetItems(core, owner, page.TopLevelPageNumber, 20, page.TopLevelPageOffset, out moreContent);

            if (feedActions.Count > 0)
            {
                template.Parse("HAS_FEED_ITEMS", "TRUE");
                VariableCollection feedDateVariableCollection = null;
                string lastDay = core.Tz.ToStringPast(core.Tz.Now);

                foreach (Action feedAction in feedActions)
                {
                    DateTime feedItemDay = feedAction.GetTime(core.Tz);

                    if (feedDateVariableCollection == null || lastDay != core.Tz.ToStringPast(feedItemDay))
                    {
                        lastDay = core.Tz.ToStringPast(feedItemDay);
                        feedDateVariableCollection = template.CreateChild("feed_days_list");

                        feedDateVariableCollection.Parse("DAY", lastDay);
                    }

                    if (first)
                    {
                        first = false;
                        template.Parse("NEWEST_ID", feedAction.Id.ToString());
                    }

                    VariableCollection feedItemVariableCollection = feedDateVariableCollection.CreateChild("feed_item");

                    core.Display.ParseBbcode(feedItemVariableCollection, "TITLE", feedAction.FormattedTitle);
                    /*if ((!core.IsMobile) && (!string.IsNullOrEmpty(feedAction.BodyCache)))
                    {
                        core.Display.ParseBbcodeCache(feedItemVariableCollection, "TEXT", feedAction.BodyCache);
                    }
                    else*/
                    {
                        Primitive itemOwner = core.PrimitiveCache[feedAction.OwnerId];
                        if (feedAction.InteractItem is IActionableItem)
                        {
                            itemOwner = ((IActionableItem)feedAction.InteractItem).Owner;

                            if (((IActionableItem)feedAction.InteractItem).ApplicationId > 0)
                            {
                                try
                                {
                                    ApplicationEntry ae = new ApplicationEntry(core, ((IActionableItem)feedAction.InteractItem).ApplicationId);

                                    if (ae.ApplicationType == ApplicationType.OAuth)
                                    {
                                        OAuthApplication oae = new OAuthApplication(core, ae);

                                        feedItemVariableCollection.Parse("VIA_APP_TITLE", oae.DisplayTitle);
                                        feedItemVariableCollection.Parse("U_VIA_APP", oae.Uri);
                                    }
                                }
                                catch (InvalidApplicationException)
                                {
                                }
                            }
                        }
                        else if (feedAction.ActionedItem is IActionableItem)
                        {
                            itemOwner = ((IActionableItem)feedAction.ActionedItem).Owner;

                            if (((IActionableItem)feedAction.ActionedItem).ApplicationId > 0)
                            {
                                try
                                {
                                    ApplicationEntry ae = new ApplicationEntry(core, ((IActionableItem)feedAction.ActionedItem).ApplicationId);

                                    if (ae.ApplicationType == ApplicationType.OAuth)
                                    {
                                        OAuthApplication oae = new OAuthApplication(core, ae);

                                        feedItemVariableCollection.Parse("VIA_APP_TITLE", oae.DisplayTitle);
                                        feedItemVariableCollection.Parse("U_VIA_APP", oae.Uri);
                                    }
                                }
                                catch (InvalidApplicationException)
                                {
                                }
                            }
                        }
                        core.Display.ParseBbcode(feedItemVariableCollection, "TEXT", feedAction.Body, itemOwner, true, string.Empty, string.Empty);
                    }

                    feedItemVariableCollection.Parse("USER_DISPLAY_NAME", feedAction.Owner.DisplayName);

                    ItemKey interactItemKey = null;

                    if (feedAction.InteractItemKey.Id > 0)
                    {
                        interactItemKey = feedAction.InteractItemKey;
                        feedItemVariableCollection.Parse("ID", feedAction.InteractItemKey.Id);
                        feedItemVariableCollection.Parse("TYPE_ID", feedAction.InteractItemKey.TypeId);
                    }
                    else
                    {
                        interactItemKey = feedAction.ActionItemKey;
                        feedItemVariableCollection.Parse("ID", feedAction.ActionItemKey.Id);
                        feedItemVariableCollection.Parse("TYPE_ID", feedAction.ActionItemKey.TypeId);
                    }

                    if (interactItemKey.GetType(core).Likeable)
                    {
                        feedItemVariableCollection.Parse("LIKEABLE", "TRUE");

                        if (feedAction.Info.Likes > 0)
                        {
                            feedItemVariableCollection.Parse("LIKES", string.Format(" {0:d}", feedAction.Info.Likes));
                            feedItemVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", feedAction.Info.Dislikes));
                        }
                    }

                    if (interactItemKey.GetType(core).Commentable)
                    {
                        feedItemVariableCollection.Parse("COMMENTABLE", "TRUE");

                        if (feedAction.Info.Comments > 0)
                        {
                            feedItemVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", feedAction.Info.Comments));
                        }
                    }

                    //Access access = new Access(core, feedAction.ActionItemKey, true);
                    if (feedAction.PermissiveParent.Access.IsPublic())
                    {
                        feedItemVariableCollection.Parse("IS_PUBLIC", "TRUE");
                        if (interactItemKey.GetType(core).Shareable)
                        {
                            feedItemVariableCollection.Parse("SHAREABLE", "TRUE");
                            //feedItemVariableCollection.Parse("U_SHARE", feedAction.ShareUri);

                            if (feedAction.Info.SharedTimes > 0)
                            {
                                feedItemVariableCollection.Parse("SHARES", string.Format(" {0:d}", feedAction.Info.SharedTimes));
                            }
                        }
                    }
                    else
                    {
                        feedItemVariableCollection.Parse("IS_PUBLIC", "FALSE");
                        feedItemVariableCollection.Parse("SHAREABLE", "FALSE");
                    }

                    if (feedAction.Owner is User)
                    {
                        feedItemVariableCollection.Parse("USER_TILE", ((User)feedAction.Owner).Tile);
                        feedItemVariableCollection.Parse("USER_ICON", ((User)feedAction.Owner).Icon);
                    }

                    lastId = feedAction.Id;
                }
            }

            core.Display.ParseBlogPagination(template, "PAGINATION", core.Hyperlink.BuildHomeUri(), 0, moreContent ? lastId : 0);
            template.Parse("U_NEXT_PAGE", core.Hyperlink.BuildHomeUri() + "?p=" + (core.TopLevelPageNumber + 1) + "&o=" + lastId);

            core.AddMainPanel(template);
        }