Beispiel #1
0
        public ImageGalleryData getImageGallery(CmsPage page, int identifier, bool createNewIfDoesNotExist)
        {
            if (page.Id < 0 || identifier < 0)
            {
                return(new ImageGalleryData());
            }

            string sql = "";

            sql  = "select g.ImageGalleryId, g.subDir, g.thumbSize, g.largeSize, g.numThumbsPerRow, i.ImageGalleryImageId, i.Caption, I.Filename from imagegallery g left join imagegalleryimages i on i.ImageGalleryId = g.ImageGalleryId";
            sql += " where g.pageid = " + page.Id.ToString() + " and g.identifier = " + identifier.ToString() + " and g.deleted is null;";

            DataSet ds = this.RunSelectQuery(sql);

            if (this.hasRows(ds))
            {
                ImageGalleryData data = new ImageGalleryData();
                DataRow          dr   = ds.Tables[0].Rows[0];
                data.ImageGalleryId  = Convert.ToInt32(dr["ImageGalleryId"]);
                data.subDir          = (dr["subDir"].ToString().Trim());
                data.thumbSize       = Convert.ToInt32(dr["thumbSize"]);
                data.largeSize       = Convert.ToInt32(dr["largeSize"]);
                data.numThumbsPerRow = Convert.ToInt32(dr["numThumbsPerRow"]);
                foreach (DataRow r in ds.Tables[0].Rows)
                {
                    if (r["ImageGalleryImageId"] != System.DBNull.Value && r["ImageGalleryImageId"] != null)
                    {
                        ImageGalleryImageData img = new ImageGalleryImageData();
                        img.Filename            = r["Filename"].ToString();
                        img.Caption             = r["Caption"].ToString();
                        img.ImageGalleryImageId = Convert.ToInt32(r["ImageGalleryImageId"]);
                        data.addImage(img);
                    }
                }
                return(data);
            }
            else
            {
                if (createNewIfDoesNotExist)
                {
                    ImageGalleryData data = new ImageGalleryData();
                    bool             b    = createNewImageGallery(page, identifier, data);

                    if (!b)
                    {
                        throw new Exception("getImageGallery database error: Error creating new placeholder");
                    }
                    else
                    {
                        return(data);
                    }
                }
                else
                {
                    throw new Exception("getImageGallery database error: placeholder does not exist");
                }
            }
        }         // getImageGallery
Beispiel #2
0
        private string getHtmlForThumbView(CmsPage page, ImageGalleryData data, string ImageGalleryId, bool inEditMode)
        {
            StringBuilder html            = new StringBuilder();
            string        DirOnDiskToView = getDirOnDiskToView(data);


            if (!Directory.Exists(DirOnDiskToView))
            {
                return("Error with Image Gallery: ImageGallery directory does not exist!");
            }

            string[] JPGFiles = Directory.GetFiles(DirOnDiskToView, "*.jpg");
            if (JPGFiles.Length < 1)
            {
                return("no images are in this image gallery");
            }

            html.Append("<table>");
            int       imgCount         = 0;
            ArrayList formCaptionNames = new ArrayList();

            foreach (string jpg in JPGFiles)
            {
                if (imgCount % data.numThumbsPerRow == 0)
                {
                    html.Append("<tr>");
                }

                string imgFilenameUnderAppPath = data.subDir + Path.GetFileName(jpg);
                string thumbUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(imgFilenameUnderAppPath, data.thumbSize, -1);

                ImageGalleryImageData imgData = data.getImageData(imgFilenameUnderAppPath);

                NameValueCollection imgParams = new NameValueCollection();
                imgParams.Add("galleryMode", Convert.ToInt32(RenderMode.FullSize).ToString());
                imgParams.Add("galleryImg", Path.GetFileName(jpg));

                string fullSizeUrl = CmsContext.getUrlByPagePath(page.Path, imgParams);

                html.Append("<td class=\"ImageGalleryImage_td\">");

                if (!inEditMode)
                {
                    html.Append("<a class=\"ImageGalleryImageLink\" href=\"" + fullSizeUrl + "\">");
                }

                html.Append("<img class=\"ImageGalleryImage\" src=\"" + thumbUrl + "\">");

                if (!inEditMode)
                {
                    html.Append("</a>");
                }

                html.Append("<br>");
                if (inEditMode)
                {
                    string tbName = System.Web.HttpUtility.UrlEncode("imgCaption" + ImageGalleryId + "_" + imgFilenameUnderAppPath);
                    formCaptionNames.Add(tbName);
                    string tb = PageUtils.getInputTextHtml(tbName, tbName, imgData.Caption, 15, 255);
                    tb = "<nobr>caption: " + tb + "</nobr>";
                    html.Append(tb);
                }
                else
                {
                    html.Append(imgData.Caption);
                }
                html.Append("</td>");
                if (imgCount % data.numThumbsPerRow == data.numThumbsPerRow)
                {
                    html.Append("</tr>");
                }

                imgCount++;
            }
            if (imgCount % data.numThumbsPerRow != data.numThumbsPerRow)
            {
                html.Append("</tr>");
            }
            html.Append("</table>");

            if (inEditMode)
            {
                string csv = "";
                foreach (string id in formCaptionNames)
                {
                    csv = csv + id + ",";
                }
                string h = PageUtils.getHiddenInputHtml(ImageGalleryId + "_captions", csv);
                html.Append(h);
            }

            return(html.ToString());
        } // getHtmlForThumbView
Beispiel #3
0
 public void addImage(ImageGalleryImageData img)
 {
     imageData.Add(img);
 }
Beispiel #4
0
        }         // RenderEdit

        public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            ImageGalleryData data = new ImageGalleryData();

            data.subDir          = "images" + DirSeperator + "ImageGallery" + DirSeperator;
            data.thumbSize       = 200;
            data.largeSize       = 500;
            data.numThumbsPerRow = 3;

            ImageGalleryDb db = new ImageGalleryDb();

            data = db.getImageGallery(page, identifier, true);

            if (!data.subDir.EndsWith(DirSeperator))
            {
                data.subDir += DirSeperator;
            }



            if (currentViewRenderMode == RenderMode.FullSize)
            {             // -- render full size
                writer.Write("<div class=\"ImageGallery FullSize\">");
                string jpg = PageUtils.getFromForm("galleryImg", "");
                if (jpg == "")
                {
                    writer.Write("Invalid galleryImg parameter");
                    return;
                }

                string imgCaption            = "";
                int    currentImageDataIndex = -1;
                for (int i = 0; i < data.ImageData.Length; i++)
                {
                    ImageGalleryImageData d = data.ImageData[i];
                    if (Path.GetFileName(d.Filename) == Path.GetFileName(jpg) || d.Filename == jpg)
                    {
                        imgCaption            = "<p align=\"center\" class=\"caption full\">" + d.Caption + "</p>";
                        currentImageDataIndex = i;
                        break;
                    }
                }

                string imgFilenameUnderAppPath = data.subDir + Path.GetFileName(jpg);
                string largeUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(imgFilenameUnderAppPath, data.largeSize, -1);

                string backUrl = CmsContext.getUrlByPagePath(page.Path);
                writer.Write("<p class=\"ImageGalleryBackLink\"><a class=\"ImageGalleryBackLink\" href=\"" + backUrl + "\">&#171; back to thumbnails</a><p>");

                List <string> nextPrevLinks = new List <string>();
                if (currentImageDataIndex > 0)
                {
                    NameValueCollection prevImgParams = new NameValueCollection();
                    prevImgParams.Add("galleryMode", Convert.ToInt32(RenderMode.FullSize).ToString());
                    prevImgParams.Add("galleryImg", Path.GetFileName(data.ImageData[currentImageDataIndex - 1].Filename));
                    string prevUrl  = CmsContext.getUrlByPagePath(page.Path, prevImgParams);
                    string prevHtml = "<a class=\"ImageGalleryBackLink prev\" href=\"" + prevUrl + "\">&#171; prev</a>";
                    nextPrevLinks.Add(prevHtml);
                }

                if (data.ImageData.Length > 1 && currentImageDataIndex < (data.ImageData.Length - 1))
                {
                    NameValueCollection nextImgParams = new NameValueCollection();
                    nextImgParams.Add("galleryMode", Convert.ToInt32(RenderMode.FullSize).ToString());
                    nextImgParams.Add("galleryImg", Path.GetFileName(data.ImageData[currentImageDataIndex + 1].Filename));
                    string nextUrl  = CmsContext.getUrlByPagePath(page.Path, nextImgParams);
                    string nextHtml = "<a class=\"ImageGalleryBackLink next\" href=\"" + nextUrl + "\">next &#187;</a>";
                    nextPrevLinks.Add(nextHtml);
                }

                if (nextPrevLinks.Count > 0)
                {
                    writer.Write("<p class=\"ImageGalleryBackLink\">" + string.Join(" | ", nextPrevLinks.ToArray()) + "</p>");
                }


                writer.Write("<img class=\"ImageGalleryFullSizedImage\" src=\"" + largeUrl + "\">");
                writer.WriteLine(imgCaption);
            }
            else
            {             // -- render the directory
                writer.Write("<div class=\"ImageGallery thumbnails\">");

                string ImageGalleryId = "ImageGallery_" + page.Id.ToString() + "_" + identifier.ToString();
                string thumbViewHtml  = getHtmlForThumbView(page, data, ImageGalleryId, false);
                writer.WriteLine(thumbViewHtml);
            }     // render directory
            writer.Write("</div>");
        }         // RenderView
Beispiel #5
0
        public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            ImageGalleryDb   db   = new ImageGalleryDb();
            ImageGalleryData data = new ImageGalleryData();

            data.subDir          = "";
            data.thumbSize       = 200;
            data.largeSize       = 500;
            data.numThumbsPerRow = 3;

            data = db.getImageGallery(page, identifier, true);

            string ImageGalleryId = "ImageGallery_" + page.Id.ToString() + "_" + identifier.ToString();

            // ------- CHECK THE FORM FOR ACTIONS
            string action = Hatfield.Web.Portal.PageUtils.getFromForm(ImageGalleryId + "_Action", "");

            if (action.Trim().ToLower() == "update")
            {
                data.ImageGalleryId  = PageUtils.getFromForm(ImageGalleryId + "_DataId", -1);
                data.subDir          = PageUtils.getFromForm("subDir_" + ImageGalleryId, "");
                data.thumbSize       = PageUtils.getFromForm("thumbSize_" + ImageGalleryId, data.thumbSize);
                data.largeSize       = PageUtils.getFromForm("largeSize_" + ImageGalleryId, data.largeSize);
                data.numThumbsPerRow = PageUtils.getFromForm("numThumbsPerRow_" + ImageGalleryId, data.numThumbsPerRow);

                string[] captionIds = PageUtils.getFromForm(ImageGalleryId + "_captions");
                foreach (string captionId in captionIds)
                {
                    // captionId is in the form
                    // "imgCaption"+ImageGalleryId+"_"+imgFilenameUnderAppPath;
                    if (captionId != "")
                    {
                        string capId = System.Web.HttpUtility.UrlDecode(captionId);
                        if (capId.StartsWith("imgCaption" + ImageGalleryId + "_"))
                        {
                            string imgFilenameUnderAppPath = capId.Substring(("imgCaption" + ImageGalleryId + "_").Length);
                            string caption            = PageUtils.getFromForm(System.Web.HttpUtility.UrlEncode(capId), "");
                            ImageGalleryImageData img = data.getImageData(imgFilenameUnderAppPath);
                            img.Caption  = caption;
                            img.Filename = imgFilenameUnderAppPath;

                            if (img.ImageGalleryImageId < 0)
                            {
                                data.addImage(img);
                            }
                        }
                    }
                }

                db.saveUpdatedImageGallery(page, identifier, data);
            }

            // ------- START RENDERING
            // note: no need to put in the <form></form> tags.

            StringBuilder html = new StringBuilder();

            html.Append("<strong>Image Gallery Settings:</strong><br>");
            html.Append("<table>");

            string[] subDirs = getAllAvailableSubDirs();
            string   s       = PageUtils.getDropDownHtml("subDir_" + ImageGalleryId, "subDir_" + ImageGalleryId, subDirs, data.subDir);

            html.Append("<tr><td>Image SubDirectory:</td>");
            html.Append("<td>" + s + "</td></tr>");

            s = PageUtils.getInputTextHtml("numThumbsPerRow_" + ImageGalleryId, "numThumbsPerRow_" + ImageGalleryId, data.numThumbsPerRow.ToString(), 3, 5);
            html.Append("<tr><td>Number of Thumbnails per row:</td>");
            html.Append("<td>" + s + "</td></tr>");

            s = PageUtils.getInputTextHtml("thumbSize_" + ImageGalleryId, "thumbSize_" + ImageGalleryId, data.thumbSize.ToString(), 3, 5);
            html.Append("<tr><td>Thumbnail Size:</td>");
            html.Append("<td>" + s + "</td></tr>");

            s = PageUtils.getInputTextHtml("largeSize_" + ImageGalleryId, "largeSize_" + ImageGalleryId, data.largeSize.ToString(), 3, 5);
            html.Append("<tr><td>Full-Sized Image size:</td>");
            html.Append("<td>" + s + "</td></tr>");


            html.Append("</table>");

            string thumbViewHtml = getHtmlForThumbView(page, data, ImageGalleryId, true);

            writer.WriteLine(thumbViewHtml);

            html.Append("<input type=\"hidden\" name=\"" + ImageGalleryId + "_Action\" value=\"update\">");
            html.Append("<input type=\"hidden\" name=\"" + ImageGalleryId + "_DataId\" value=\"" + data.ImageGalleryId.ToString() + "\">");

            writer.WriteLine(html.ToString());
        }         // RenderEdit