Esempio n. 1
0
        /// <summary>
        /// Renders the passage entry.
        /// </summary>
        /// <returns>The rendered html of the passage entry.</returns>
        public string Render(SdwItem item)
        {
            this.IsLink  = false;
            this.IsImage = false;
            this.m_Insertions.Clear();
            this.m_Html = item.Text;

            if (item.Text.StartsWith("{URL}"))
            {
                // {URL}NAME{URL}PATH
                this.IsLink = true;
                var info = item.Text.Split(new [] { "{URL}" }, StringSplitOptions.RemoveEmptyEntries);
                m_Html = string.Format("<a href=\"{1}\" target=\"_blank\">{0}</a>", info[0], info[1]);
                return(m_Html);
            }
            if (m_Html.StartsWith("{IMG}"))
            {
                // {IMG}ALT{IMG}PATH
                this.IsImage = true;
                var info = item.Text.Split(new [] { "{IMG}" }, StringSplitOptions.RemoveEmptyEntries);
                m_Html = string.Format("<img src=\"{1}\" alt=\"{0}\" />", info [0], info [1]);
                return(m_Html);
            }

            foreach (var style in item.Styles)
            {
                this.Insert(style.Start, style.StartIndex, style.End, style.EndIndex);
            }

            if (!string.IsNullOrEmpty(this.SearchText))
            {
                var hilite  = Regex.Escape(this.SearchText);
                var matches = Regex.Matches(item.Text, hilite, RegexOptions.IgnoreCase);
                foreach (Match match in matches)
                {
                    this.Insert("<span style=\"background-color:#A0D3E8\">", match.Index, "</span>", match.Index + match.Length);
                }
            }

            foreach (var footer in item.Footers)
            {
                if (footer.Order.HasValue)
                {
                    footer.Number = this.m_FooterNumber;
                    this.Insert(string.Format("<sup>({0})</sup>", this.m_FooterNumber), -footer.Order.Value);
                    this.m_FooterNumber++;
                }
            }

            return(this.m_Html);
        }
Esempio n. 2
0
        public ActionResult Love(int?id, string items, string history)
        {
            var model = new LoveModel();
            var hash  = new Hashids("GodisLove")
            {
                Order = true
            };
            var ids = hash.Decode(items).ToList();

            if (id == null)
            {
                var lights = this.Database.Light.All(q => q.OrderBy(l => Guid.NewGuid())).Take(25);
                foreach (var light in lights)
                {
                    model.ToAdd.Add(new SdwItem(light));
                }
            }
            else
            {
                var histIds = hash.Decode(history).ToList();
                histIds.Add(id.Value);
                history = hash.Encode(histIds);
                var light = this.Database.Light.Get(id.Value);
                ids.Add(id.Value);
                var loves = (from peace in light.Peaces
                             where peace.Love.Peaces.All(p => ids.Contains(p.Light.Id))
                             select peace.Love).ToList();
                if (loves.Count > 0)
                {
                    var max = loves.Where(l => l.Truths.Any()).Max(l => l.Peaces.Count);
                    foreach (var love in loves.Where(l => l.Peaces.Count == max))
                    {
                        foreach (var truth in love.Truths)
                        {
                            Love truthLove = null;
                            var  truthIds  = new List <int> ();
                            if (truth.Light != null)
                            {
                                truthIds.Add(truth.Light.Id);
                            }
                            if (truth.ParentId.HasValue && (!truth.Order.HasValue || truth.Order.Value > 0))
                            {
                                truthLove = this.Database.Love.Get(truth.ParentId.Value);
                                truthIds.AddRange(truthLove.Peaces.Select(p => p.Light.Id));
                            }
                            if ((truthLove == null && truthIds.All(ids.Contains)) ||
                                (truthIds.All(histIds.Contains) && !truth.Number.HasValue && (!truth.Order.HasValue || truth.Order.Value > 0)) ||
                                (truth.Light != null && truth.Order == null && model.ToAdd.Any(i => i.Id == truth.Light.Id)))
                            {
                                continue;
                            }

                            if (truthLove == null && truthIds.Count <= 0)
                            {
                                continue;
                            }
                            var item = new SdwItem(truth)
                            {
                                History = history
                            };
                            if (truthLove != null)
                            {
                                item.IsLink = true;
                                var text = GetTitle(truthLove.Peaces);
                                if (truth.Light != null)
                                {
                                    item.Title = text;
                                }
                                else
                                {
                                    item.Text = text;
                                    item.Id   = truthLove.Peaces.OrderBy(p => p.Order).Last().Light.Id;
                                }
                                item.Parents = hash.Encode(truthLove.Peaces.Select(p => p.Light.Id));
                            }
                            else if (truth.Light != null)
                            {
                                var parents     = new List <Peace> ();
                                var tempParents = (from peace in truth.Light.Peaces
                                                   from p in peace.Love.Peaces
                                                   where ids.Contains(p.Light.Id)
                                                   select p).ToList();
                                foreach (var tp in tempParents)
                                {
                                    if (parents.Any(p => p.Light.Id == tp.Light.Id))
                                    {
                                        continue;
                                    }
                                    parents.Add(tp);
                                }
                                var parentIds = parents.Select(p => p.Light.Id).ToList();
                                item.Parents    = hash.Encode(parentIds);
                                item.IsSelected = histIds.Contains(truth.Light.Id);
                                item.Title      = GetTitle((parents.Count > 0) ? parents : truth.Number.HasValue || love.Peaces.Count > 1 ? love.Peaces : new List <Peace> ());
                                if (string.IsNullOrEmpty(item.Title))
                                {
                                    item.History = string.Empty;
                                }
                            }
                            model.ToAdd.Add(item);
                        }
                    }
                    SetHeadersAndFooters(model);
                }
            }
            return(PartialView(model));
        }