public SingleImageData getSingleImage(CmsPage page, int identifier, CmsLanguage forLanguage, bool createNewIfDoesNotExist)
        {
            if (page.Id < 0 || identifier < 0)
            {
                return(new SingleImageData());
            }

            string sql = "select PageId,Identifier, SingleImageId, ImagePath, Caption, Credits, Tags from singleimage c ";

            sql += " where c.pageid = " + page.Id.ToString() + " and c.identifier = " + identifier.ToString() + " and RevisionNumber = " + page.RevisionNumber.ToString() + " and langShortCode like '" + dbEncode(forLanguage.shortCode) + "' and deleted is null;";
            DataSet ds = this.RunSelectQuery(sql);

            if (this.hasRows(ds))
            {
                DataRow dr = ds.Tables[0].Rows[0];

                SingleImageData info = fromDataRow(dr);

                return(info);
            }
            else
            {
                if (createNewIfDoesNotExist)
                {
                    return(createNewSingleImage(page, identifier, forLanguage, new SingleImageData()));
                }
                else
                {
                    throw new Exception("getSingleImage database error: placeholder does not exist");
                }
            }
            return(new SingleImageData());
        } // getSingleImage
        // ALTER TABLE `singleimage` ADD COLUMN `Tags` VARCHAR(255) NOT NULL DEFAULT '' AFTER `Credits`;
        private SingleImageData fromDataRow(DataRow dr)
        {
            SingleImageData info = new SingleImageData();

            info.SingleImageId  = Convert.ToInt32(dr["SingleImageId"]);
            info.PageId         = Convert.ToInt32(dr["PageId"]);
            info.PageIdentifier = Convert.ToInt32(dr["Identifier"]);
            info.ImagePath      = dr["ImagePath"].ToString();

            /*
             * info.ThumbnailDisplayBoxWidth = Convert.ToInt32(dr["ThumbnailDisplayBoxWidth"]);
             * info.ThumbnailDisplayBoxHeight = Convert.ToInt32(dr["ThumbnailDisplayBoxHeight"]);
             * info.FullSizeDisplayBoxWidth = Convert.ToInt32(dr["FullSizeDisplayBoxWidth"]);
             * info.FullSizeDisplayBoxHeight = Convert.ToInt32(dr["FullSizeDisplayBoxHeight"]);
             */
            info.Caption = (dr["Caption"]).ToString();
            info.Credits = (dr["Credits"]).ToString();

            string sTags = (dr["Tags"]).ToString();

            string[] arrTags = sTags.Split(new string[] { SingleImageData.TagStorageSeperator }, StringSplitOptions.RemoveEmptyEntries);
            info.Tags = arrTags;

            return(info);
        }
        } // getSingleImage

        public SingleImageData createNewSingleImage(CmsPage page, int identifier, CmsLanguage forLanguage, SingleImageData imgData)
        {
            string sql = "insert into singleimage (pageid, identifier,RevisionNumber, ImagePath, ThumbnailDisplayBoxWidth, ThumbnailDisplayBoxHeight, FullSizeDisplayBoxWidth, FullSizeDisplayBoxHeight, Caption, Credits, Tags, langShortCode) values (";

            sql  = sql + page.Id.ToString() + "," + identifier.ToString() + "," + page.RevisionNumber.ToString() + ",";
            sql += "'" + imgData.ImagePath + "', -1, ";
            sql += "-1, ";
            sql += "-1, ";
            sql += "-1, ";
            sql += "'" + dbEncode(imgData.Caption) + "', ";
            sql += "'" + dbEncode(imgData.Credits) + "', ";
            sql += "'" + dbEncode(String.Join(SingleImageData.TagStorageSeperator, imgData.Tags)) + "', ";
            sql += "'" + dbEncode(forLanguage.shortCode) + "' ";
            sql += "); ";

            int newId = this.RunInsertQuery(sql);

            if (newId > -1)
            {
                page.setLastUpdatedDateTimeToNow();
                SingleImageData info = new SingleImageData();
                info.PageId        = page.Id;
                info.SingleImageId = newId;
                return(info);
            }
            else
            {
                return(new SingleImageData());
            }
        }
        } // RenderEdit

        public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            string controlId        = "SingleImageGallery_" + page.ID.ToString() + identifier.ToString() + langToRenderFor.shortCode;
            SingleImageGalleryDb db = new SingleImageGalleryDb();
            SingleImageGalleryPlaceholderData placeholderData = db.getSingleImageGallery(page, identifier, langToRenderFor, true);

            SingleImageData[] imageDatas              = new SingleImageData[0];
            SingleImageDb     singleImageDb           = new SingleImageDb();
            List <CmsPage>    pagesToGatherImagesFrom = new List <CmsPage>();

            // -- gather images to display from selected pages

            CmsPage startPage = CmsContext.getPageById(placeholderData.PageIdToGatherImagesFrom);

            if (placeholderData.RecursiveGatherImages)
            {
                Dictionary <int, CmsPage> allPages = startPage.getLinearizedPages();
                pagesToGatherImagesFrom = new List <CmsPage>(allPages.Values);
            }
            else
            {
                pagesToGatherImagesFrom.Add(startPage);
            }

            imageDatas = singleImageDb.getSingleImages(pagesToGatherImagesFrom.ToArray(), langToRenderFor);

            imageDatas = filterOutDuplicateImagePaths(placeholderData, imageDatas);
            imageDatas = filterImagesByRequiredTags(placeholderData, imageDatas);
            imageDatas = sortByPageOrder(placeholderData, imageDatas, pagesToGatherImagesFrom.ToArray());


            // -- override the full-sized display

            int imgIdToView = PageUtils.getFromForm("galleryimage", Int32.MinValue);

            if (imgIdToView >= 0)
            {
                foreach (SingleImageData i in imageDatas)
                {
                    if (i.SingleImageId == imgIdToView)
                    {
                        writer.Write(renderSinglePageDisplayOfImage(placeholderData, i, imageDatas, pagesToGatherImagesFrom.ToArray()));
                        return;
                    }
                } // foreach
            }
            else
            {
                writer.Write(getGalleryView(placeholderData, imageDatas, pagesToGatherImagesFrom.ToArray(), langToRenderFor));
            }
        } // RenderView
예제 #5
0
        public override RevertToRevisionResult RevertToRevision(CmsPage oldPage, CmsPage currentPage, int[] identifiers, CmsLanguage language)
        {
            SingleImageDb imageDb = new SingleImageDb();

            foreach (int identifier in identifiers)
            {
                SingleImageData oldData = imageDb.getSingleImage(oldPage, identifier, language, false);
                bool            b       = imageDb.saveUpdatedSingleImage(currentPage, identifier, language, oldData);
                if (!b)
                {
                    return(RevertToRevisionResult.Failure);
                }
            } // foreach
            return(RevertToRevisionResult.Success);
        }
        private int getCurrentPageNumber(SingleImageData[] searchResults, SingleImageData imageToShow, SingleImageGalleryPlaceholderData placeholderData)
        {
            int numPages = (int)Math.Ceiling((double)searchResults.Length / placeholderData.NumThumbsPerPage);

            if (numPages <= 0)
            {
                numPages = 1;
            }

            int startAtItemNumber = 0;

            if (imageToShow != null)
            {
                for (int i = 0; i < searchResults.Length; i++)
                {
                    if (searchResults[i].SingleImageId == imageToShow.SingleImageId)
                    {
                        int rem = 0;
                        Math.DivRem(i, placeholderData.NumThumbsPerPage, out rem);
                        startAtItemNumber = i - rem;
                        break;
                    }
                }
            }
            else
            {
                startAtItemNumber = PageUtils.getFromForm("gn", Int32.MinValue);
            }


            if (startAtItemNumber >= searchResults.Length)
            {
                startAtItemNumber = searchResults.Length - 1;
            }
            else if (startAtItemNumber < 0)
            {
                startAtItemNumber = 0;
            }

            int currPageNum = (int)Math.Ceiling((double)startAtItemNumber / placeholderData.NumThumbsPerPage) + 1;

            return(currPageNum);
        }
        /// <summary>
        /// returns NULL if not found
        /// </summary>
        /// <param name="SingleImageId"></param>
        /// <returns></returns>
        public SingleImageData getSingleImage(int SingleImageId)
        {
            string sql = "select PageId, Identifier, SingleImageId, ImagePath, Caption, Credits, Tags from singleimage c ";

            sql += " where c.SingleImageId = " + SingleImageId.ToString() + "; ";

            DataSet ds = this.RunSelectQuery(sql);

            if (this.hasSingleRow(ds))
            {
                DataRow dr = ds.Tables[0].Rows[0];

                SingleImageData info = fromDataRow(dr);

                return(info);
            }

            return(null);
        }
        public bool saveUpdatedSingleImage(CmsPage page, int identifier, CmsLanguage forLanguage, SingleImageData image)
        {
            // with revisions we insert, not update the database
            int newRevisionNumber = page.createNewRevision();

            if (newRevisionNumber < 0)
            {
                return(false);
            }

            // insert values for un-used columns because default values may not be present.

            string sql = "insert into singleimage (pageid, identifier,RevisionNumber, ImagePath, ThumbnailDisplayBoxWidth, ThumbnailDisplayBoxHeight, FullSizeDisplayBoxWidth, FullSizeDisplayBoxHeight, Caption, Credits, Tags, langShortCode) values (";

            sql  = sql + page.Id.ToString() + "," + identifier.ToString() + "," + newRevisionNumber.ToString() + ",";
            sql += "'" + dbEncode(image.ImagePath) + "', ";
            sql += "-1, ";
            sql += "-1, ";
            sql += "-1, ";
            sql += "-1, ";
            sql += "'" + dbEncode(image.Caption) + "',";
            sql += "'" + dbEncode(image.Credits) + "', ";
            sql += "'" + dbEncode(String.Join(SingleImageData.TagStorageSeperator, image.Tags)) + "', ";
            sql += "'" + dbEncode(forLanguage.shortCode) + "' ";
            sql += "); ";

            int newId = this.RunInsertQuery(sql);

            if (newId > -1)
            {
                page.setLastUpdatedDateTimeToNow();
                SingleImageData info = new SingleImageData();
                info.PageId        = page.Id;
                info.SingleImageId = newId;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public SingleImageData[] getSingleImages(CmsPage[] pages, CmsLanguage specifiedLanguage)
        {
            if (pages.Length < 0)
            {
                return(new SingleImageData[0]);
            }

            List <string> whereOrStatements = new List <string>();

            foreach (CmsPage p in pages)
            {
                whereOrStatements.Add("( c.pageid = " + p.Id + " and c.RevisionNumber = " + p.RevisionNumber + "   )");
            } // foreach

            string sql = "select PageId, Identifier, SingleImageId, ImagePath, Caption, Credits, Tags from singleimage c ";

            sql += " where (" + String.Join(" OR ", whereOrStatements.ToArray()) + ") ";
            if (CmsConfig.Languages.Length > 1)
            {
                sql += " and langShortCode like '" + dbEncode(specifiedLanguage.shortCode) + "' ";
            }
            sql += " and ImagePath <> '' and deleted is null;";
            DataSet ds = this.RunSelectQuery(sql);
            List <SingleImageData> ret = new List <SingleImageData>();

            if (this.hasRows(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    SingleImageData d = fromDataRow(dr);
                    ret.Add(d);
                } // foreach
            }

            return(ret.ToArray());
        } // getSingleImages
예제 #10
0
        public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            string formName = getEditFormName(page, identifier, langToRenderFor);

            SingleImageDb   db    = (new SingleImageDb());
            SingleImageData image = db.getSingleImage(page, identifier, langToRenderFor, true);

            string[] possibleTags = (new SingleImageDb()).getAllPossibleTags();



            StringBuilder html = new StringBuilder();
            // ------- CHECK THE FORM FOR ACTIONS
            string action = Hatfield.Web.Portal.PageUtils.getFromForm(formName + "_SingleImageAction", "");

            if (action.Trim().ToLower() == "saveimage")
            {
                image.ImagePath = PageUtils.getFromForm(formName + "ImagePath", "");
                // remove the Application path from the file location
                if (image.ImagePath.StartsWith(CmsContext.ApplicationPath))
                {
                    image.ImagePath = image.ImagePath.Substring(CmsContext.ApplicationPath.Length);
                }


                image.Caption = PageUtils.getFromForm(formName + "Caption", "");
                image.Credits = PageUtils.getFromForm(formName + "Credits", "");

                image.Tags = PageUtils.getFromForm(formName + "Tags");

                bool b = db.saveUpdatedSingleImage(page, identifier, langToRenderFor, image);
                if (!b)
                {
                    html.Append("Error: Image not saved - database error");
                }
            }

            string creditsPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPrefix", "Credit:");

            int thumbWidth  = getThumbDisplayWidth(page, paramList);
            int thumbHeight = getThumbDisplayHeight(page, paramList);

            // ------- START RENDERING

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

            html.Append("<div class=\"SingleImagePlaceholder Edit\">" + Environment.NewLine);
            string ImageRenderAreaId = formName + "ImageRendered";

            html.Append("<div id=\"" + ImageRenderAreaId + "\"></div>");
            html.Append(PageUtils.getHiddenInputHtml(formName + "ImagePath", formName + "ImagePath", image.ImagePath));

            List <string> editParams = new List <string>();

            editParams.Add("i=" + image.SingleImageId);
            editParams.Add("formName=" + formName);
            editParams.Add("tw=" + thumbWidth.ToString());
            editParams.Add("th=" + thumbHeight.ToString());

            string editUrl                    = CmsContext.ApplicationPath + "_system/tools/SingleImage/SingleImageEditor.aspx?" + string.Join("&", editParams.ToArray());;
            string jsResetFunctionName        = formName + "Reset";
            string jsUpdateRenderFunctionName = formName + "UpdateDisplay";

            html.Append("<table>");
            html.Append("<tr>" + Environment.NewLine);
            html.Append("<td colspan=\"2\">");
            html.Append("<p>");
            html.Append("<a id=\"" + formName + "OpenEditorLink\" href=\"" + editUrl + "\" onclick=\"window.open(this.href, 'SingleImageEdit','width=680,height=540'); return false;\">select image</a>");
            html.Append(" | ");
            html.Append("<a href=\"#\" onclick=\"" + jsResetFunctionName + "(); return false;\">clear</a>");
            if (CmsConfig.Languages.Length > 1)
            {
                html.Append(" | ");
                html.Append("copy from language: ");
                List <string> langCopyLinks = new List <string>();
                foreach (CmsLanguage lang in CmsConfig.Languages)
                {
                    if (lang != langToRenderFor)
                    {
                        string langClick = "document.getElementById('" + formName + "ImagePath').value = document.getElementById('" + getEditFormName(page, identifier, lang) + "ImagePath').value;" + jsUpdateRenderFunctionName + "(); if (document.getElementById('" + formName + "ImagePath').value == '') {alert('No image is selected because the source image is blank.');} return false;";
                        langCopyLinks.Add("<a href=\"#\" onclick=\"" + langClick + "\">" + lang.shortCode + "</a>");
                    }
                } // foreach
                html.Append(string.Join("; ", langCopyLinks.ToArray()));
            }
            html.Append("</p>");
            html.Append("</td>");
            html.Append("</tr>" + Environment.NewLine);


            html.Append("<tr><td>");
            html.Append("Caption:");
            html.Append("</td><td class=\"CaptionInputTD\">");
            html.Append(PageUtils.getInputTextHtml(formName + "Caption", formName + "Caption", image.Caption.ToString(), 40, 250));
            html.Append("</td></tr>");


            html.Append("<tr><td>");
            html.Append(creditsPrefix);
            html.Append("</td><td class=\"CreditInputTD\">");
            html.Append(PageUtils.getInputTextHtml(formName + "Credits", formName + "Credits", image.Credits.ToString(), 40, 250));
            html.Append("</td></tr>" + Environment.NewLine);

            if (possibleTags.Length > 0)
            {
                html.Append("<tr><td>");
                html.Append("Tags:");
                html.Append("</td><td>");
                foreach (string t in possibleTags)
                {
                    if (t != "")
                    {
                        html.Append(PageUtils.getCheckboxHtml(t.Trim(), formName + "Tags", formName + "tag_" + t, t.Trim(), Array.IndexOf(image.Tags, t) > -1));
                        html.Append("<br />");
                    }
                } // foreach
                html.Append("</td></tr>");
            }

            html.Append("</table>");
            html.Append("</div>" + Environment.NewLine);
            // -- hidden field actions
            html.Append("<input type=\"hidden\" name=\"" + formName + "_SingleImageAction\" value=\"saveImage\">");

            // -- javascript

            StringBuilder js = new StringBuilder();

            js.Append("function " + jsResetFunctionName + "() " + Environment.NewLine);
            js.Append("{ " + Environment.NewLine);
            js.Append("document.getElementById('" + formName + "ImagePath').value = '';" + Environment.NewLine);
            js.Append("document.getElementById('" + ImageRenderAreaId + "').innerHTML = '<span style=\"margin: 10px; padding: 10px; background: #edff96; border: 1px solid #C00;\">no image is selected</span>';" + Environment.NewLine);
            js.Append("} " + Environment.NewLine);

            js.Append("function " + jsUpdateRenderFunctionName + "() " + Environment.NewLine);
            js.Append("{ " + Environment.NewLine);
            js.Append(" var ImagePath = document.getElementById('" + formName + "ImagePath').value;" + Environment.NewLine);
            js.Append(" if (ImagePath == '') { " + Environment.NewLine);
            js.Append("   document.getElementById('" + ImageRenderAreaId + "').innerHTML = '<span style=\"margin: 10px; padding: 10px; background: #edff96; border: 1px solid #C00;\">no image is selected</span>';" + Environment.NewLine);
            js.Append(" } // if " + Environment.NewLine);
            js.Append(" else { " + Environment.NewLine);
            js.Append("   document.getElementById('" + ImageRenderAreaId + "').innerHTML = '<img src=\"" + CmsContext.ApplicationPath + "_system/tools/showThumb.aspx?file='+ImagePath+'&w=" + thumbWidth + "&h=" + thumbHeight + "&nocache='+((new Date()).getTime())+'\">';" + Environment.NewLine);
            js.Append(" } // else " + Environment.NewLine);
            js.Append(" document.getElementById('" + formName + "OpenEditorLink').href = '" + editUrl + "&SelImagePath='+ImagePath;" + Environment.NewLine);
            js.Append("} " + Environment.NewLine + Environment.NewLine);

            // add javascript to head section
            page.HeadSection.AddJSStatements(js.ToString());
            page.HeadSection.AddJSOnReady(jsUpdateRenderFunctionName + "();");



            writer.WriteLine(html.ToString());
        }
예제 #11
0
        /*
         * public static string getStandardHtmlView_Old(SingleImageData image, FullSizeImageLinkMode fullSizeLinkMode, string fullSizeDisplayUrl)
         * {
         *  StringBuilder html = new StringBuilder();
         *  if (image.ImagePath != "")
         *  {
         *      bool linkToLarger = false;
         *      if (image.FullSizeDisplayBoxHeight > 0 || image.FullSizeDisplayBoxWidth > 0)
         *          linkToLarger = true;
         *
         *      string thumbUrl = showThumbPage.getThumbDisplayUrl(image.ImagePath, image.ThumbnailDisplayBoxWidth, image.ThumbnailDisplayBoxHeight);
         *      System.Drawing.Size ThumbSize = showThumbPage.getDisplayWidthAndHeight(image.ImagePath, image.ThumbnailDisplayBoxWidth, image.ThumbnailDisplayBoxHeight);
         *
         *      html.Append("<div class=\"SingleImagePlaceholder View\">");
         *      if (linkToLarger)
         *      {
         *          bool useSubmodal = CmsConfig.getConfigValue("SingleImagePlaceHolderUseSubModal", false);
         *          bool useMultibox = CmsConfig.getConfigValue("SingleImagePlaceHolderUseMultibox", false);
         *
         *
         *          int popupPaddingWidth = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupPaddingWidth", 50);
         *          int popupPaddingHeight = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupPaddingHeight", 60);
         *
         *          int maxPopWidth = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupMaxWidth", 700 - popupPaddingWidth);
         *          int maxPopHeight = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupMaxHeight", 500 - popupPaddingHeight);
         *
         *
         *          int minPopWidth = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupMinWidth", 200);
         *          int minPopHeight = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupMinHeight", 200);
         *
         *
         *          string showLargerPagePath = CmsConfig.getConfigValue("SingleImage.DisplayPath", "/_internal/showImage");
         *
         *          NameValueCollection largerParams = new NameValueCollection();
         *          largerParams.Add("i", image.SingleImageId.ToString());
         *          string showLargerPageUrl = CmsContext.getUrlByPagePath(showLargerPagePath, largerParams);
         *
         *          System.Drawing.Size imgLargeSize = showThumbPage.getDisplayWidthAndHeight(image.ImagePath, image.FullSizeDisplayBoxWidth, image.FullSizeDisplayBoxHeight);
         *
         *          if (ThumbSize.Width > imgLargeSize.Width || ThumbSize.Height > imgLargeSize.Height)
         *          {
         *              linkToLarger = false;
         *          }
         *          else
         *          {
         *
         *              int popWidth = imgLargeSize.Width + popupPaddingWidth;
         *              int popHeight = imgLargeSize.Height + popupPaddingHeight;
         *
         *              if (popWidth < minPopWidth)
         *                  popWidth = minPopWidth;
         *              if (popHeight < minPopHeight)
         *                  popHeight = minPopHeight;
         *
         *              if (popWidth > maxPopWidth)
         *                  popWidth = maxPopWidth;
         *              if (popHeight > maxPopHeight)
         *                  popHeight = maxPopHeight;
         *
         *              if (useSubmodal &&
         *                  (fullSizeLinkMode == FullSizeImageLinkMode.SubModalOrPopupFromConfig || fullSizeLinkMode == FullSizeImageLinkMode.SubModalWindow))
         *              {
         *                  string submodalCssClass = "class=\"submodal-" + popWidth.ToString() + "-" + popHeight.ToString() + "\"";
         *                  html.Append("<a " + submodalCssClass + " href=\"" + showLargerPageUrl + "\" >");
         *              }
         *              else if (useMultibox && (fullSizeLinkMode == FullSizeImageLinkMode.SubModalOrPopupFromConfig || fullSizeLinkMode == FullSizeImageLinkMode.SubModalWindow))
         *              {
         *                  string submodalCssClass = "class=\"mb\"";
         *                  html.Append("<a " + submodalCssClass + " href=\"" + showLargerPageUrl + "\" rel=\"width:" + popWidth + ",height:" + popHeight + "\" >");
         *              }
         *              else if (fullSizeLinkMode == FullSizeImageLinkMode.SingleImagePopup || fullSizeLinkMode == FullSizeImageLinkMode.SubModalOrPopupFromConfig)
         *              {
         *                  string onclick = "var w = window.open(this.href, 'popupLargeImage', 'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,height=" + popWidth.ToString() + ",width=" + popWidth.ToString() + "'); ";
         *                  onclick += " return false;";
         *                  html.Append("<a href=\"" + showLargerPageUrl + "\" onclick=\"" + onclick + "\">");
         *              }
         *              else if (fullSizeLinkMode == FullSizeImageLinkMode.ProvidedUrl)
         *                  html.Append("<a href=\"" + fullSizeDisplayUrl + "\">");
         *              else
         *                  linkToLarger = false;
         *          } // else
         *      } // if link to larger
         *
         *      string width = "";
         *      string height = "";
         *      if (!ThumbSize.IsEmpty)
         *      {
         *          width = " width=\"" + ThumbSize.Width + "\"";
         *          height = " height=\"" + ThumbSize.Height.ToString() + "\"";
         *      }
         *
         *      html.Append("<img src=\"" + thumbUrl + "\"" + width + "" + height + ">");
         *      if (linkToLarger)
         *      {
         *          html.Append("</a>");
         *      }
         *
         *      if (image.Caption.Trim() != "")
         *      {
         *          html.Append("<div class=\"caption\">");
         *          html.Append(image.Caption);
         *          html.Append("</div>"); // caption
         *      }
         *
         *      if (image.Credits.Trim() != "")
         *      {
         *          html.Append("<div class=\"credits\">");
         *          string creditsPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPrefix", "");
         *          html.Append(creditsPrefix + image.Credits);
         *          html.Append("</div>"); // credits
         *      }
         *
         *      if (linkToLarger)
         *      {
         *          string clickToEnlargeText = CmsConfig.getConfigValue("SingleImage.ClickToEnlargeText", "");
         *          if (clickToEnlargeText != "")
         *          {
         *              html.Append("<div class=\"clickToEnlarge\">");
         *              html.Append(clickToEnlargeText);
         *              html.Append("</div>"); // clickToEnlarge
         *          }
         *      }
         *
         *      html.Append("</div>");
         *  }
         *
         *  return html.ToString();
         * }
         */

        public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            // -- all rendering in View mode is handled by getStandardHtmlView()
            SingleImageDb   db    = (new SingleImageDb());
            SingleImageData image = db.getSingleImage(page, identifier, langToRenderFor, true);

            int fullWidth  = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayWidth", -1);
            int fullHeight = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayHeight", -1);

            int thumbWidth  = getThumbDisplayWidth(page, paramList);
            int thumbHeight = getThumbDisplayHeight(page, paramList);

            int popupPaddingWidth  = CmsConfig.getConfigValue("SingleImage.PopupPaddingWidth", 50);
            int popupPaddingHeight = CmsConfig.getConfigValue("SingleImage.PopupPaddingHeight", 60);

            int maxPopWidth  = CmsConfig.getConfigValue("SingleImage.PopupMaxWidth", 700 - popupPaddingWidth);
            int maxPopHeight = CmsConfig.getConfigValue("SingleImage.PopupMaxHeight", 500 - popupPaddingHeight);


            int minPopWidth  = CmsConfig.getConfigValue("SingleImage.PopupMinWidth", 200);
            int minPopHeight = CmsConfig.getConfigValue("SingleImage.PopupMinHeight", 200);

            string withLinkTemplate    = CmsConfig.getConfigValue("SingleImage.WithLinkTemplate", "<a href=\"{5}\"><img src=\"{2}\" width=\"{0}\" height=\"{1}\" /></a>");
            string withoutLinkTemplate = CmsConfig.getConfigValue("SingleImage.WithoutLinkTemplate", "<img src=\"{2}\" width=\"{0}\" height=\"{1}\" />");

            string showLargerPagePath = CmsConfig.getConfigValue("SingleImage.DisplayPath", "/_internal/showImage");

            NameValueCollection largerParams = new NameValueCollection();

            largerParams.Add("i", image.SingleImageId.ToString());
            string showLargerPageUrl = CmsContext.getUrlByPagePath(showLargerPagePath, largerParams);

            System.Drawing.Size imgLargeSize = showThumbPage.getDisplayWidthAndHeight(image.ImagePath, fullWidth, fullHeight);

            int popWidth  = imgLargeSize.Width + popupPaddingWidth;
            int popHeight = imgLargeSize.Height + popupPaddingHeight;

            if (popWidth < minPopWidth)
            {
                popWidth = minPopWidth;
            }
            if (popHeight < minPopHeight)
            {
                popHeight = minPopHeight;
            }

            if (popWidth > maxPopWidth)
            {
                popWidth = maxPopWidth;
            }
            if (popHeight > maxPopHeight)
            {
                popHeight = maxPopHeight;
            }


            // -- create the SingleImageDisplayInfo object
            SingleImageDisplayInfo displayInfo = new SingleImageDisplayInfo();

            displayInfo.ImagePath = image.ImagePath;

            displayInfo.FullImageDisplayBox  = new System.Drawing.Size(fullWidth, fullHeight);
            displayInfo.ThumbImageDisplayBox = new System.Drawing.Size(thumbWidth, thumbHeight);
            displayInfo.PopupDisplayBox      = new System.Drawing.Size(popWidth, popHeight);

            displayInfo.FullImageDisplayUrl = showLargerPageUrl;

            displayInfo.ThumbDisplayWithLinkTemplate    = withLinkTemplate;
            displayInfo.ThumbDisplayWithoutLinkTemplate = withoutLinkTemplate;

            displayInfo.Caption = image.Caption;
            displayInfo.Credits = image.Credits;

            // -- Multilingual CreditsPromptPrefix
            string creditPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPromptPrefix", "");

            string[] creditPrefixParts = creditPrefix.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (creditPrefixParts.Length >= CmsConfig.Languages.Length)
            {
                int index = CmsLanguage.IndexOf(langToRenderFor.shortCode, CmsConfig.Languages);
                if (index >= 0)
                {
                    creditPrefix = creditPrefixParts[index];
                }
            }

            // -- Multilingual ClickToEnlargeText
            string clickToEnlargeText = CmsConfig.getConfigValue("SingleImage.ClickToEnlargeText", "");

            string[] clickToEnlargeTextParts = clickToEnlargeText.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (clickToEnlargeTextParts.Length >= CmsConfig.Languages.Length)
            {
                int index = CmsLanguage.IndexOf(langToRenderFor.shortCode, CmsConfig.Languages);
                if (index >= 0)
                {
                    clickToEnlargeText = clickToEnlargeTextParts[index];
                }
            }

            displayInfo.CreditsPromptPrefix = creditPrefix;
            displayInfo.ClickToEnlargeText  = clickToEnlargeText;

            string html = getStandardHtmlView(displayInfo);

            writer.WriteLine(html.ToString());
        } // RenderView
        public string getGalleryView(SingleImageGalleryPlaceholderData placeholderData, SingleImageData[] imageDatas, CmsPage[] pagesToGatherImagesFrom, CmsLanguage langToRenderFor)
        {
            if (imageDatas.Length == 0)
            {
                return("<p><strong>There currently aren't any images to view in this gallery</strong></p>");
            }

            StringBuilder html = new StringBuilder();

            string pagerHtml = getThumbnailPagerOutput(imageDatas, placeholderData);

            html.Append("<p>" + pagerHtml + "</p>");

            int startAtItemNumber = PageUtils.getFromForm("gn", 0);

            if (startAtItemNumber >= imageDatas.Length)
            {
                startAtItemNumber = imageDatas.Length - 1;
            }
            int endAt = Math.Min(startAtItemNumber + placeholderData.NumThumbsPerPage - 1, imageDatas.Length - 1);


            if (startAtItemNumber == 0 && endAt == 0 && imageDatas.Length == 1)
            {
                html.Append(renderThumbnail(placeholderData, imageDatas[0], langToRenderFor));
            }
            else
            {
                html.Append("<table>" + Environment.NewLine);
                bool rowStarted = false;

                for (int i = startAtItemNumber; i <= endAt; i++)
                {
                    if (endAt <= 0)
                    {
                        break;
                    }

                    if (i % placeholderData.NumThumbsPerRow == 0)
                    {
                        if (rowStarted)
                        {
                            html.Append("</tr>" + Environment.NewLine);
                        }
                        html.Append("<tr>" + Environment.NewLine);
                        rowStarted = true;
                    }

                    SingleImageData image = imageDatas[i];
                    html.Append("<td>");
                    html.Append(renderThumbnail(placeholderData, image, langToRenderFor));
                    if (CmsContext.currentPage.currentUserCanWrite)
                    {
                        CmsPage pageContainingImage = image.getPageContainingImage(pagesToGatherImagesFrom);
                        if (pageContainingImage != null)
                        {
                            html.Append("<br />");
                            html.Append("<a title=\"found on page '" + pageContainingImage.Title.Replace("\"", "") + "'\" href=\"" + pageContainingImage.Url + "\">( found here )</a>");
                        }
                    }
                    html.Append("</td>" + Environment.NewLine);
                } // for
                if (rowStarted)
                {
                    html.Append("</tr>");
                }
                html.Append("</table>" + Environment.NewLine);
            } // else

            html.Append("<p>" + pagerHtml + "</p>");

            return(html.ToString());
        } // RenderView
        private string renderThumbnail(SingleImageGalleryPlaceholderData placeholderData, SingleImageData img, CmsLanguage langToRenderFor)
        {
            string fullDisplayUrl = "";
            Dictionary <string, string> pageParams = new Dictionary <string, string>();

            pageParams.Add("galleryimage", img.SingleImageId.ToString());
            fullDisplayUrl = CmsContext.currentPage.getUrl(pageParams);

            SingleImageDisplayInfo displayInfo = new SingleImageDisplayInfo();

            displayInfo.FullImageDisplayUrl = fullDisplayUrl;

            displayInfo.PopupDisplayBox = new System.Drawing.Size(-1, -1);
            displayInfo.ImagePath       = img.ImagePath;

            displayInfo.ThumbImageDisplayBox = new System.Drawing.Size(placeholderData.ThumbImageDisplayBoxWidth, placeholderData.ThumbImageDisplayBoxHeight);
            displayInfo.Caption = img.Caption;
            displayInfo.Credits = img.Credits;

            int fullImageBoxWidth  = -1;
            int fullImageBoxHeight = -1;

            if (placeholderData.OverrideFullDisplayBoxSize)
            {
                fullImageBoxWidth  = placeholderData.FullSizeDisplayBoxWidth;
                fullImageBoxHeight = placeholderData.FullSizeDisplayBoxHeight;
            }
            else
            {
                fullImageBoxWidth  = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayWidth", -1);
                fullImageBoxHeight = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayHeight", -1);
            }
            displayInfo.FullImageDisplayBox = new System.Drawing.Size(fullImageBoxWidth, fullImageBoxHeight);

            // -- Multilingual CreditsPromptPrefix
            string creditPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPromptPrefix", "");

            string[] creditPrefixParts = creditPrefix.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (creditPrefixParts.Length >= CmsConfig.Languages.Length)
            {
                int index = CmsLanguage.IndexOf(langToRenderFor.shortCode, CmsConfig.Languages);
                if (index >= 0)
                {
                    creditPrefix = creditPrefixParts[index];
                }
            }

            // -- Multilingual ClickToEnlargeText
            string clickToEnlargeText = CmsConfig.getConfigValue("SingleImage.ClickToEnlargeText", "");

            string[] clickToEnlargeTextParts = clickToEnlargeText.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (clickToEnlargeTextParts.Length >= CmsConfig.Languages.Length)
            {
                int index = CmsLanguage.IndexOf(langToRenderFor.shortCode, CmsConfig.Languages);
                if (index >= 0)
                {
                    clickToEnlargeText = clickToEnlargeTextParts[index];
                }
            }

            displayInfo.CreditsPromptPrefix = creditPrefix;
            displayInfo.ClickToEnlargeText  = clickToEnlargeText;

            string displayTemplate = "<a href=\"{5}\"><img src=\"{2}\" width=\"{0}\" height=\"{1}\" /></a>";

            displayTemplate = CmsConfig.getConfigValue("SingleImage.WithLinkTemplate", displayTemplate);

            displayInfo.ThumbDisplayWithLinkTemplate    = displayTemplate;
            displayInfo.ThumbDisplayWithoutLinkTemplate = displayTemplate;

            return(SingleImage.getStandardHtmlView(displayInfo));
        }
        } // RenderView

        private string renderSinglePageDisplayOfImage(SingleImageGalleryPlaceholderData placeholderData, SingleImageData imageToShow, SingleImageData[] imageDatas, CmsPage[] pagesToGatherImagesFrom)
        {
            string nextUrl = "";

            string prevUrl = "";

            for (int i = 0; i < imageDatas.Length; i++)
            {
                if (imageToShow.SingleImageId == imageDatas[i].SingleImageId)
                {
                    Dictionary <string, string> pageParams = new Dictionary <string, string>();

                    if (i > 0)
                    {
                        pageParams.Add("galleryimage", imageDatas[i - 1].SingleImageId.ToString());
                        prevUrl = CmsContext.currentPage.getUrl(pageParams);
                    }
                    if (i < imageDatas.Length - 1)
                    {
                        pageParams.Clear();
                        pageParams.Add("galleryimage", imageDatas[i + 1].SingleImageId.ToString());
                        nextUrl = CmsContext.currentPage.getUrl(pageParams);
                    }
                    break;
                }
            } // for



            List <string> navLinks = new List <string>();

            if (prevUrl != "")
            {
                navLinks.Add("<a href=\"" + prevUrl + "\">&#171; prev</a>");
            }

            int currentPageNum = getCurrentPageNumber(imageDatas, imageToShow, placeholderData);

            navLinks.Add("<a href=\"" + getPagerUrl(currentPageNum, placeholderData) + "\">return to gallery</a>");
            if (nextUrl != "")
            {
                navLinks.Add("<a href=\"" + nextUrl + "\">next &#187;</a>");
            }

            StringBuilder html = new StringBuilder();

            html.Append("<div class=\"SingleImageGallery SingleImageDisplay\">");

            html.Append("<p class=\"pager\">");
            html.Append(String.Join(" | ", navLinks.ToArray()));

            if (imageToShow.Caption.Trim() != "")
            {
                html.Append("<div class=\"caption top\">");
                html.Append(imageToShow.Caption);
                html.Append("</div>"); // caption
            }
            html.Append("</p>");

            int fullImageBoxWidth  = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayWidth", -1);
            int fullImageBoxHeight = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayHeight", -1);

            if (placeholderData.OverrideFullDisplayBoxSize)
            {
                fullImageBoxWidth  = placeholderData.FullSizeDisplayBoxWidth;
                fullImageBoxHeight = placeholderData.FullSizeDisplayBoxHeight;
            }

            string imgUrl = showThumbPage.getThumbDisplayUrl(imageToShow.ImagePath, fullImageBoxWidth, fullImageBoxHeight);

            System.Drawing.Size imgSize = showThumbPage.getDisplayWidthAndHeight(imageToShow.ImagePath, fullImageBoxWidth, fullImageBoxHeight);

            string width  = "";
            string height = "";

            if (!imgSize.IsEmpty)
            {
                width  = " width=\"" + imgSize.Width + "\"";
                height = " height=\"" + imgSize.Height.ToString() + "\"";
            }

            html.Append("<img src=\"" + imgUrl + "\"" + width + "" + height + ">");

            if (imageToShow.Caption.Trim() != "")
            {
                html.Append("<div class=\"caption bottom\">");
                html.Append(imageToShow.Caption);
                html.Append("</div>"); // caption
            }

            if (imageToShow.Credits.Trim() != "")
            {
                html.Append("<div class=\"credits\">");
                string creditsPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPrefix", "");
                html.Append(creditsPrefix + imageToShow.Credits);
                html.Append("</div>"); // credits
            }

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

            return(html.ToString());
        }