Ejemplo n.º 1
0
        protected override void OnPreRender(EventArgs e)
        {
            if (Resource != null)
            {
                // build a definition list just for this item
                using (HtmlGenericControl dl = new HtmlGenericControl("dl"))
                {
                    using (HtmlGenericControl dt = new HtmlGenericControl("dt"))
                    {
                        using (HtmlGenericControl dd = new HtmlGenericControl("dd"))
                        {
                            dl.Controls.Add(dt);
                            dl.Controls.Add(dd);

                            // get file extension
                            string format = Resource.Values["umbracoExtension"].Replace(".", "").ToLower(CultureInfo.CurrentCulture);
                            dt.Attributes["class"] = format;

                            // link to file using name of format
                            using (HtmlAnchor link = new HtmlAnchor())
                            {
                                switch (format)
                                {
                                case "rtf":
                                    format = "Rich text";
                                    link.Attributes["type"] = "application/rtf";
                                    break;

                                case "doc":
                                    format = "Word";
                                    link.Attributes["type"] = "application/msword";
                                    break;

                                case "xls":
                                    format = "Excel";
                                    link.Attributes["type"] = "application/excel";
                                    break;

                                case "pdf":
                                    format = "Acrobat (PDF)";
                                    link.Attributes["type"] = "application/pdf";
                                    break;

                                case "ppt":
                                    format = "PowerPoint";
                                    link.Attributes["type"] = "application/powerpoint";
                                    break;

                                case "xml":
                                    format = "XML";
                                    link.Attributes["type"] = "text/xml";
                                    break;

                                default:
                                    format = "Alternative format";
                                    break;
                                }
                                link.HRef      = AttachmentUrl.ToString();
                                link.InnerText = Resource.Name;
                                link.Title     = "View '" + link.InnerText + "' in " + format + " format";
                                dt.Controls.Add(link);
                            }

                            // display the description, if present
                            if (Resource.Values.ContainsKey("Description") && !String.IsNullOrEmpty(Resource.Values["Description"]))
                            {
                                dd.InnerHtml = HttpUtility.HtmlEncode(Resource.Values["Description"]);
                                dd.Visible   = true;
                            }
                            else
                            {
                                dd.Visible = false;
                            }
                        }
                    }
                    this.Controls.Add(dl);
                }
                this.Visible = true;
            }
            else
            {
                this.Visible = false;
            }
        }
Ejemplo n.º 2
0
        public static AttachmentData GetAttachment(AttachmentType type, XmlNode attachmentData)
        {
            XmlUtils.UseNode(attachmentData);
            switch (type)
            {
            case AttachmentType.Application:
            {
                AttachmentApplication a = new AttachmentApplication();
                a.Id           = XmlUtils.Int("app_id");
                a.Name         = XmlUtils.String("app_name");
                a.PictureUrl   = XmlUtils.String("src_big");
                a.ThumbnailUrl = XmlUtils.String("src");
                return(a);

                break;
            }

            case AttachmentType.Audio:
            {
                AttachmentAudio a = new AttachmentAudio();
                a.Id        = XmlUtils.Int("aid");
                a.OwnerId   = XmlUtils.Int("owner_id");
                a.Performer = XmlUtils.String("performer");
                a.Title     = XmlUtils.String("title");
                a.Duration  = XmlUtils.Int("duration");
                return(a);

                break;
            }

            case AttachmentType.Checkin:
            {
                break;
            }

            case AttachmentType.Graffiti:
            {
                AttachmentGraffiti a = new AttachmentGraffiti();
                a.Id           = XmlUtils.Int("gid");
                a.OwnerId      = XmlUtils.Int("owner_id");
                a.PictureUrl   = XmlUtils.String("src_big");
                a.ThumbnailUrl = XmlUtils.String("src");
                return(a);

                break;
            }

            case AttachmentType.Note:
            {
                AttachmentNote a = new AttachmentNote();
                a.Id            = XmlUtils.Int("nid");
                a.OwnerId       = XmlUtils.Int("owner_id");
                a.Title         = XmlUtils.String("title");
                a.CommentsCount = XmlUtils.Int("ncom");
                break;
            }

            case AttachmentType.Photo:
            {
                AttachmentPhoto a = new AttachmentPhoto();
                a.Id           = XmlUtils.Int("pid");
                a.OwnerId      = XmlUtils.Int("owner_id");
                a.PictureUrl   = XmlUtils.String("src_big");
                a.ThumbnailUrl = XmlUtils.String("src");
                return(a);

                break;
            }

            case AttachmentType.PostedPhoto:
            {
                AttachmentPhoto a = new AttachmentPhoto();
                a.Id           = XmlUtils.Int("pid");
                a.OwnerId      = XmlUtils.Int("owner_id");
                a.PictureUrl   = XmlUtils.String("src_big");
                a.ThumbnailUrl = XmlUtils.String("src");
                return(a);

                break;
            }

            case AttachmentType.Poll:
            {
                AttachmentPoll a = new AttachmentPoll();
                a.Question = XmlUtils.String("question");
                return(a);

                break;
            }

            case AttachmentType.Share:
            {
                break;
            }

            case AttachmentType.Video:
            {
                AttachmentVideo a = new AttachmentVideo();
                a.Id       = XmlUtils.Int("vid");
                a.OwnerId  = XmlUtils.Int("owner_id");
                a.Title    = XmlUtils.String("title");
                a.Duration = XmlUtils.Int("duration");
                return(a);

                break;
            }

            case AttachmentType.Url:
            {
                AttachmentUrl a = new AttachmentUrl();
                a.Url          = XmlUtils.String("url");
                a.Title        = XmlUtils.String("title");
                a.Description  = XmlUtils.String("description");
                a.ThumbnailUrl = XmlUtils.String("image_src");
                break;
            }
            }
            return(null);
        }
Ejemplo n.º 3
0
        protected override void OnPreRender(EventArgs e)
        {
            if (Resource != null)
            {
                // get file extension
                string format = Resource.Values["umbracoExtension"].ToLower(CultureInfo.CurrentCulture);

                // start with icon for file format
                using (HtmlGenericControl also = new HtmlGenericControl("span"))
                {
                    also.Attributes.Add("class", "downloadAlso");
                    also.InnerText = "Also in: ";
                    this.Controls.Add(also);
                }

                // link to file using name of format
                using (HtmlAnchor link = new HtmlAnchor())
                {
                    link.Title = "View "; // default action
                    switch (format)
                    {
                    case "rtf":
                        link.InnerText          = "Rich text";
                        link.Attributes["type"] = "application/rtf";
                        break;

                    case "doc":
                        link.InnerText          = "Word";
                        link.Attributes["type"] = "application/msword";
                        break;

                    case "xls":
                        link.InnerText          = "Excel";
                        link.Attributes["type"] = "application/excel";
                        break;

                    case "pdf":
                        link.InnerText          = "Acrobat (PDF)";
                        link.Attributes["type"] = "application/pdf";
                        break;

                    case "ppt":
                        link.InnerText          = "PowerPoint";
                        link.Attributes["type"] = "application/powerpoint";
                        break;

                    case "mp3":
                        link.InnerText          = "MP3";
                        link.Attributes["type"] = "audio/mpeg3";
                        link.Title = "Listen to ";     // change action
                        break;

                    case "wma":
                        link.InnerText          = "Windows Media";
                        link.Attributes["type"] = "audio/x-ms-wma";
                        link.Title = "Listen to ";     // change action
                        break;

                    case "xml":
                        link.InnerText          = "XML";
                        link.Attributes["type"] = "text/xml";
                        break;

                    default:
                        link.InnerText = "Alternative format";
                        break;
                    }
                    link.Attributes["class"] = format + " no-meta";
                    link.HRef = AttachmentUrl.ToString();
                    string docTitle = "'" + Resource.Name + "'";
                    link.Title += docTitle + " in " + link.InnerText + " format";
                    this.Controls.Add(link);


                    // display the file size in brackets
                    string size = CmsUtilities.GetResourceFileSize(Resource);
                    if (size.Length > 0)
                    {
                        using (var sizeElement = new HtmlGenericControl("span"))
                        {
                            ;
                            sizeElement.InnerText = " (" + size + ")";
                            sizeElement.Attributes.Add("class", "downloadSize");
                            link.Controls.Add(sizeElement);
                        }
                    }
                }
                this.Visible = true;
            }
            else
            {
                this.Visible = false;
            }
        }