public ItemModuleModeEventArgs(string mode, NumberedItem item)
 {
     this.mode = mode;
     this.item = item;
 }
Example #2
0
        private string saveImage(NumberedItem post, string imageType, byte[] imageData)
        {
            BlogEntry myBlogEntry = null;
            if (post is BlogEntry)
            {
                myBlogEntry = (BlogEntry)myBlogEntry;
            }

            string imagePath = string.Empty;

            Gallery.Gallery parent = null;
            Gallery.Gallery grandParent = null;

            string grandParentSlug = "photos-from-posts";
            try
            {
                grandParent = new Gallery.Gallery(core, Owner, grandParentSlug);
            }
            catch (InvalidGalleryException)
            {
                Gallery.Gallery root = new Gallery.Gallery(core, Owner);
                grandParent = Gallery.Gallery.Create(core, Owner, root, "Photos From Posts", ref grandParentSlug, "All my unsorted uploads");
            }

            string gallerySlug = "blog-" + post.Id.ToString();

            try
            {
                parent = new Gallery.Gallery(core, Owner, gallerySlug);

                parent.GalleryTitle = myBlogEntry.Title;
                parent.Update();
            }
            catch (InvalidGalleryException)
            {
                parent = Gallery.Gallery.Create(core, Owner, grandParent, myBlogEntry.Title, ref gallerySlug, string.Empty);
            }

            AccessControlLists acl = new AccessControlLists(core, parent);
            acl.SaveNewItemPermissions();

            MemoryStream stream = new MemoryStream();
            stream.Write(imageData, 0, imageData.Length);

            string slug = "image-" + parent.Items.ToString();
            GalleryItem newGalleryItem = GalleryItem.Create(core, Owner, parent, string.Empty, ref slug, slug, imageType, (ulong)imageData.Length, string.Empty, core.Functions.GetLicenseId(), core.Functions.GetClassification(), stream, true /*, width, height*/);

            imagePath = newGalleryItem.FullPath;

            return imagePath;
        }
Example #3
0
        public static void LogView(Core core, NumberedItem item)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (item.Id < 1)
            {
                throw new InvalidItemException();
            }

            if (core.Session.IsBot)
            {
                // Do not count page views from robots
                return;
            }

            ItemViewDiscountedReason reason = ItemViewDiscountedReason.None;
            ItemKey ownerKey = null;

            if (item is IPermissibleItem)
            {
                IPermissibleItem pitem = (IPermissibleItem)item;

                ownerKey = pitem.OwnerKey;

                if (core.Session.SignedIn && pitem.OwnerKey == core.LoggedInMemberItemKey)
                {
                    reason = ItemViewDiscountedReason.ItemOwner;
                }
            }

            if (item is IPermissibleSubItem)
            {
                IPermissibleSubItem pitem = (IPermissibleSubItem)item;

                ownerKey = pitem.OwnerKey;

                if (core.Session.SignedIn && pitem.OwnerKey == core.LoggedInMemberItemKey)
                {
                    reason = ItemViewDiscountedReason.ItemOwner;
                }
            }

            long timestamp = UnixTime.UnixTimeStamp();
            string urlreferer = core.Http.UrlReferer;

            if (string.IsNullOrEmpty(urlreferer))
            {
                SelectQuery sQuery = Session.GetSelectQueryStub(core, typeof(Session));
                sQuery.AddCondition("session_string", core.Session.SessionId);

                DataTable sessionTable = core.Db.Query(sQuery);
                if (sessionTable.Rows.Count == 1)
                {
                    if (sessionTable.Rows[0]["session_http_referer"] is string)
                    {
                        string session_referer = (string)sessionTable.Rows[0]["session_http_referer"];
                        if (!string.IsNullOrEmpty(session_referer))
                        {
                            urlreferer = session_referer;
                        }
                    }
                }
            }

            InsertQuery iQuery = new InsertQuery("item_views");
            iQuery.AddField("view_item_id", item.ItemKey.Id);
            iQuery.AddField("view_item_type_id", item.ItemKey.TypeId);
            if (ownerKey != null)
            {
                iQuery.AddField("view_item_owner_id", ownerKey.Id);
                iQuery.AddField("view_item_owner_type_id", ownerKey.TypeId);
            }
            if (core.Session.SignedIn)
            {
                iQuery.AddField("user_id", core.LoggedInMemberId);
            }
            iQuery.AddField("view_ip", core.Session.IPAddress.ToString());
            iQuery.AddField("view_session_id", core.Session.SessionId);
            iQuery.AddField("view_time_ut", timestamp);
            iQuery.AddField("view_timespan", 0);
            iQuery.AddField("view_update_time_ut", timestamp);
            iQuery.AddField("view_referral_uri", core.Http["ref"]);
            iQuery.AddField("view_http_referer", urlreferer);
            iQuery.AddField("view_http_user_agent", core.Http.UserAgent);
            iQuery.AddField("view_cookies", core.Session.SessionMethod == SessionMethods.Cookie);
            iQuery.AddField("view_javascript", core.Http.BrowserIdentifiesJavascript);
            iQuery.AddField("view_counted", false);
            iQuery.AddField("view_discounted", false);
            iQuery.AddField("view_processed", false);
            iQuery.AddField("view_discounted_reason", (int)reason);
            iQuery.AddField("view_state", (int)ItemViewState.New);

            // commit the query
            long viewId = core.Db.Query(iQuery);

            core.Template.Parse("ITEM_VIEW_ID", viewId.ToString());
        }
 protected void SaveItemMode(ItemModuleModeHandler saveHandler, NumberedItem item)
 {
     if (core.Http.Form["save"] != null)
     {
         if (core.Http.Form["mode"] != null)
         {
             saveHandler((object)this, new ItemModuleModeEventArgs(core.Http.Form["mode"], item));
         }
     }
 }
Example #5
0
        public static void LoadTagsIntoItem(Core core, NumberedItem item, string tagList, bool isNewItem)
        {
            if (isNewItem)
            {
                if (string.IsNullOrEmpty(tagList))
                {
                    return;
                }

                if (tagList.Trim(new char[] { ' ', '\t', ';', ',', ':', '.', '-', '(', ')', '<', '>', '[', ']', '{', '}', '|', '\\', '/' }).Length < 2)
                {
                    return;
                }
            }

            List<Tag> itemTags = GetTags(core, item);
            List<string> tagsListNormalised = new List<string>();
            List<string> tagsNormalised = new List<string>();
            List<string> tagsToAdd = new List<string>();
            List<string> tagsToAddNormalised = new List<string>();
            List<string> tagsToRemoveNormalised = new List<string>();
            List<string> tagsToLoad = new List<string>();

            int totalTags = 0;

            foreach (Tag tag in itemTags)
            {
                tagsListNormalised.Add(tag.TagTextNormalised);
            }

            string[] tags = tagList.Split(new char[] {' '});

            for (int i = 0; i < tags.Length; i++)
            {
                string tag = tags[i].Trim(new char[] { ',', ';', ' ' });
                string tagNormalised = string.Empty;
                NormaliseTag(tag, ref tagNormalised);

                if (!tagsListNormalised.Contains(tagNormalised))
                {
                    tagsListNormalised.Add(tagNormalised);
                    tagsToAddNormalised.Add(tagNormalised);
                    tagsToAdd.Add(tag);
                }

                tagsNormalised.Add(tagNormalised);

                totalTags++;
                /* Limit to 10 tags per item */
                if (totalTags == 10)
                {
                    break;
                }
            }

            foreach (Tag tag in itemTags)
            {
                if (!tagsNormalised.Contains(tag.TagTextNormalised))
                {
                    tagsToRemoveNormalised.Add(tag.TagTextNormalised);
                }
            }

            foreach (string tag in tagsToAddNormalised)
            {
                tagsToLoad.Add(tag);
            }

            foreach (string tag in tagsToRemoveNormalised)
            {
                tagsToLoad.Add(tag);
            }

            List<Tag> tagIds = GetTags(core, tagsToLoad.ToArray());
            Dictionary<string, Tag> tagIdsNormalised = new Dictionary<string, Tag>();

            foreach (Tag tag in tagIds)
            {
                tagIdsNormalised.Add(tag.TagTextNormalised, tag);
            }

            if (tagsToAddNormalised.Count > 0)
            {
                for (int i = 0; i < tagsToAddNormalised.Count; i++)
                {
                    if (!tagIdsNormalised.ContainsKey(tagsToAddNormalised[i]))
                    {
                        Tag newTag = Tag.Create(core, tagsToAdd[i]);
                        ItemTag.Create(core, item, newTag);
                    }
                    else
                    {
                        ItemTag.Create(core, item, tagIdsNormalised[tagsToAddNormalised[i]]);
                    }
                }

                UpdateQuery uQuery = new UpdateQuery(typeof(Tag));
                uQuery.AddField("tag_items", new QueryOperation("tag_items", QueryOperations.Addition, 1));
                uQuery.AddCondition("tag_text_normalised", ConditionEquality.In, tagsToAddNormalised.ToArray());

                core.Db.Query(uQuery);
            }

            if (tagsToRemoveNormalised.Count > 0)
            {
                List<long> tagToRemoveIds = new List<long>();
                foreach (string tag in tagsToRemoveNormalised)
                {
                    tagToRemoveIds.Add(tagIdsNormalised[tag].Id);
                }

                DeleteQuery dQuery = new DeleteQuery(typeof(ItemTag));
                dQuery.AddCondition("tag_id", ConditionEquality.In, tagToRemoveIds.ToArray());
                dQuery.AddCondition("item_id", item.Id);
                dQuery.AddCondition("item_type_id", item.ItemKey.TypeId);

                core.Db.Query(dQuery);

                UpdateQuery uQuery = new UpdateQuery(typeof(Tag));
                uQuery.AddField("tag_items", new QueryOperation("tag_items", QueryOperations.Subtraction, 1));
                uQuery.AddCondition("tag_id", ConditionEquality.In, tagToRemoveIds.ToArray());

                core.Db.Query(uQuery);
            }
        }
Example #6
0
        public static ItemHashtag Create(Core core, NumberedItem item, Tag tag)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            Item newItem = Item.Create(core, typeof(ItemHashtag), new FieldValuePair("item_id", item.Id),
                new FieldValuePair("item_type_id", item.ItemKey.TypeId),
                new FieldValuePair("hashtag_id", tag.Id));

            return (ItemHashtag)newItem;
        }
Example #7
0
        public static void LoadTagsIntoItem(Core core, NumberedItem item, List<long> tagIds, bool isNewItem)
        {
            if (isNewItem)
            {
                if (tagIds.Count == 0)
                {
                    return;
                }
            }

            List<Tag> itemTags = GetTags(core, item);
            List<long> itemTagIds = new List<long>();

            List<long> tagsToAdd = new List<long>();
            List<long> tagsToRemove = new List<long>();

            foreach (Tag tag in itemTags)
            {
                itemTagIds.Add(tag.Id);
                if (!tagIds.Contains(tag.Id))
                {
                    tagsToRemove.Add(tag.Id);
                }
            }

            foreach (long tagId in tagIds)
            {
                if (!itemTagIds.Contains(tagId))
                {
                    tagsToAdd.Add(tagId);
                }
            }

            if (tagsToAdd.Count > 0)
            {
                for (int i = 0; i < tagsToAdd.Count; i++)
                {
                    ItemTag.Create(core, item, tagsToAdd[i]);
                }

                UpdateQuery uQuery = new UpdateQuery(typeof(Tag));
                uQuery.AddField("tag_items", new QueryOperation("tag_items", QueryOperations.Addition, 1));
                uQuery.AddCondition("tag_id", ConditionEquality.In, tagsToAdd.ToArray());

                core.Db.Query(uQuery);
            }

            if (tagsToRemove.Count > 0)
            {
                DeleteQuery dQuery = new DeleteQuery(typeof(ItemTag));
                dQuery.AddCondition("tag_id", ConditionEquality.In, tagsToRemove.ToArray());
                dQuery.AddCondition("item_id", item.Id);
                dQuery.AddCondition("item_type_id", item.ItemKey.TypeId);

                core.Db.Query(dQuery);

                UpdateQuery uQuery = new UpdateQuery(typeof(Tag));
                uQuery.AddField("tag_items", new QueryOperation("tag_items", QueryOperations.Subtraction, 1));
                uQuery.AddCondition("tag_id", ConditionEquality.In, tagsToRemove.ToArray());

                core.Db.Query(uQuery);
            }
        }
Example #8
0
 public static void LoadTagsIntoItem(Core core, NumberedItem item, string tagList)
 {
     LoadTagsIntoItem(core, item, tagList, false);
 }
Example #9
0
 public static void LoadTagsIntoItem(Core core, NumberedItem item, List<long> tagIds)
 {
     LoadTagsIntoItem(core, item, tagIds, false);
 }
Example #10
0
        public static List<Tag> GetTags(Core core, NumberedItem item)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            List<Tag> tags = new List<Tag>();

            SelectQuery query = Item.GetSelectQueryStub(core, typeof(ItemTag));
            query.AddCondition("item_id", item.Id);
            query.AddCondition("item_type_id", item.ItemKey.TypeId);
            query.AddSort(SortOrder.Ascending, "tag_text_normalised");

            System.Data.Common.DbDataReader tagsReader = core.Db.ReaderQuery(query);

            while (tagsReader.Read())
            {
                tags.Add(new Tag(core, tagsReader));
            }

            tagsReader.Close();
            tagsReader.Dispose();

            return tags;
        }
Example #11
0
        public void RegisterItem(NumberedItem item)
        {
            try
            {
                long id = item.Id;
            }
            catch (NotImplementedException)
            {
                // Cannot cache this item
            }
            NumberedItemId itemKey = new NumberedItemId(item.Id, item.ItemKey.TypeId);

            if (itemKey.TypeId == 0)
            {
                return;
            }
            if (!typesAccessed.ContainsKey(itemKey.TypeId))
            {
                typesAccessed.Add(itemKey.TypeId, item.GetType());
            }

            if (!(itemsCached.ContainsKey(itemKey)))
            {
                itemsCached.Add(itemKey, item);
            }

            /*Type typeToGet;

            typeToGet = typesAccessed[itemKey.TypeId];

            if (typeToGet != null && itemsPersisted != null && typeToGet.GetCustomAttributes(typeof(CacheableAttribute), false).Length > 0)
            {
                lock (itemsPersistedLock)
                {
                    if (!(itemsPersisted.ContainsKey(itemKey)))
                    {
                        itemsPersisted.Add(itemKey, item);
                    }
                }
            }*/
            batchedItemIds.Remove(itemKey);
        }
Example #12
0
        public string ExtractAndSaveImageData(string input, NumberedItem post, SaveBbcodeImage saveImage)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }

            MatchCollection matches = Regex.Matches(input, "\\[img\\]data\\:(image/png|image/jpeg|image/jpg);base64,([a-zA-Z0-9\\+/=]+)\\[/img\\]", RegexOptions.IgnoreCase);

            foreach (Match match in matches)
            {
                string imageType = match.Groups[1].Value;
                string imageString = match.Groups[2].Value;
                byte[] imageData = Convert.FromBase64String(imageString);

                string name = string.Empty;
                if (saveImage != null)
                {
                    name = saveImage(post, imageType, imageData);
                }

                if (!string.IsNullOrEmpty(name))
                {
                    input = input.Replace(match.Value, string.Format("[inline]{0}[/inline]", name));
                }
            }

            return input;
        }
Example #13
0
 public void PublishToFeed(Core core, User owner, IActionableItem item, NumberedItem subItem, string description)
 {
     if (subItem != null)
     {
         PublishToFeed(core, owner, item, new List<NumberedItem> { subItem }, description);
     }
     else
     {
         PublishToFeed(core, owner, item, new List<NumberedItem>(), description);
     }
 }