protected override void Render(HtmlTextWriter writer)
        {
            CmsLanguage   lang               = CmsContext.currentLanguage;
            string        imgText            = CmsConfig.getConfigValue("UserImageGallery.ImageText", "Number of images", lang);
            string        noGalleryText      = CmsConfig.getConfigValue("UserImageGallery.NoGalleryText", "No image galleries are currently available", lang);
            CmsPage       galleryPage        = CmsContext.currentPage;
            int           numGalleriesOutput = 0;
            StringBuilder html               = new StringBuilder();

            CmsPage[] sortedPages = CmsPage.SortPagesBySortOrdinal(galleryPage.ChildPages);
            for (int i = sortedPages.Length - 1; i >= 0; i--)
            {
                CmsPage g = sortedPages[i];
                if (true) // g.showInMenu
                {
                    UserImageGalleryDb db = new UserImageGalleryDb();
                    UserImageGalleryPlaceholderData data = new UserImageGalleryPlaceholderData();
                    data = db.getUserImageGalleryPlaceholderData(g, 1, CmsContext.currentLanguage, true);

                    string dirOnDiskToView = data.getImageStorageDirectory(g);

                    if (Directory.Exists(dirOnDiskToView))
                    {
                        DirectoryInfo di = new DirectoryInfo(dirOnDiskToView);

                        int update = Hatfield.Web.Portal.PageUtils.getFromForm("update", 0);
                        if (update == 1 && g.currentUserCanWrite)
                        {
                            CmsLocalImageOnDisk[] updates = CmsLocalImageOnDisk.UpdateFolderInDatabase(di);
                        }

                        CmsLocalImageOnDisk[] allResources = CmsLocalImageOnDisk.FetchAllImagesInDirectory(di, UserImageGalleryPlaceholderData.ImageExtensionsToDisplay);

                        if (allResources.Length >= 1)
                        {
                            numGalleriesOutput++;

                            string thumbUrl = showThumbPage.getThumbDisplayUrl(allResources[0], 100, 100);;
                            html.Append("<tr><td><a href=\"" + g.Url + "\"><img border=\"0\" src=\"" + thumbUrl + "\"></a></td><td><a href=\"" + g.Url + "\">" + g.Title + "</a><br />(" + allResources.Length + " images)</td></tr>");
                        }
                    }
                }
            } // foreach

            if (numGalleriesOutput > 0)
            {
                writer.Write("<table cellspacing=\"10\">");
                writer.Write(html.ToString());

                writer.Write("</table>");
            }
            else
            {
                writer.Write("<em>" + noGalleryText + "</em>");
            }
        }
Example #2
0
        public void RenderMultipleItems_InViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            UserImageGalleryDb db   = (new UserImageGalleryDb());
            StringBuilder      html = new StringBuilder();

            UserImageGalleryPlaceholderData placeholderData = db.getUserImageGalleryPlaceholderData(page, identifier, langToRenderFor, true);
            string imageStorageDir = placeholderData.getImageStorageDirectory(page);

            if (!System.IO.Directory.Exists(imageStorageDir))
            {
                bool b = placeholderData.createImageStorageDirectory(page);
                if (!b)
                {
                    if (CmsContext.currentUserIsSuperAdmin)
                    {
                        html.Append("<h1>System Error: could not create image storage directory: '" + imageStorageDir + "'</h1>");
                    }
                    else
                    {
                        html.Append("<h1>System Error: could not create image storage directory!!</h1>");
                    }
                    writer.Write(html.ToString());
                    return;
                }
            }

            CmsLocalImageOnDisk[] allResources = CmsLocalImageOnDisk.FetchAllImagesInDirectory(imageStorageDir, UserImageGalleryPlaceholderData.ImageExtensionsToDisplay);

            if (allResources.Length == 0 && page.currentUserCanWrite)
            {
                CmsLocalImageOnDisk.UpdateFolderInDatabase(new System.IO.DirectoryInfo(imageStorageDir));
                allResources = CmsLocalImageOnDisk.FetchAllImagesInDirectory(imageStorageDir, UserImageGalleryPlaceholderData.ImageExtensionsToDisplay);
            }

            html.Append("<div class=\"UserImageGallery\">");
            html.Append(getGalleryView(placeholderData, allResources, page, langToRenderFor));
            html.Append("</div>");

            if (page.currentUserCanWrite)
            {
                html.Append(getSwfUploadHtml(page, placeholderData, langToRenderFor));
            }

            writer.Write(html.ToString());
        }
Example #3
0
        /// <summary>
        /// returns the number of image galleries updated.
        /// </summary>
        /// <returns></returns>
        public static int UpdateDatabaseCacheOfImageInfos()
        {
            // -- Update the CmsLocalImageOnDisk database cache from the disk source.
            int ret = 0;
            UserImageGalleryDb db = (new UserImageGalleryDb());

            UserImageGalleryPlaceholderData[] phs = db.getAllUserImageGalleryPlaceholderDatas();
            foreach (UserImageGalleryPlaceholderData ph in phs)
            {
                CmsPage p = CmsContext.getPageById(ph.PageId);
                if (p.ID >= 0)
                {
                    string dir = ph.getImageStorageDirectory(p);
                    if (dir != String.Empty)
                    {
                        CmsLocalImageOnDisk[] updates = CmsLocalImageOnDisk.UpdateFolderInDatabase(new System.IO.DirectoryInfo(dir));
                        ret++;
                    } // if
                }     // if
            }         // foreach
            return(ret);
        }
        protected void FolderTreeView_SelectedNodeChanged(object sender, EventArgs e)
        {
            int imagesPerRow = 2;

            FolderTreeView.SelectedNode.Expand();


            DirectoryInfo di = new DirectoryInfo(FolderTreeView.SelectedNode.Value);

            CmsLocalImageOnDisk[] dirResources = CmsLocalImageOnDisk.UpdateFolderInDatabase(di);
            // CmsResource.GetResourcesInDirectory(di.FullName);

            CmsLocalImageOnDisk[] imgResources = FilterOutNonImageFiles(dirResources);



            StringBuilder html      = new StringBuilder();
            List <string> filenames = new List <string>();

            filenames.Add(di.FullName);
            int fileNum = 0; bool rowStarted = false;

            html.Append("<table cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">");
            foreach (CmsLocalImageOnDisk res in imgResources)
            {
                bool updateResource = false;

                string imgHtmlTag = res.getImageHtmlTag(120, -1, "");
                // -- create the file's Url
                string fileUrl = res.getUrl(Context);


                string fiName = res.FileName;
                if (fiName.IndexOf("'") > -1)
                {
                    fiName  = fiName.Replace("'", "\\'");
                    fileUrl = fileUrl.Replace("'", "\\'");
                }


                if (!fileUrl.StartsWith(CmsContext.ApplicationPath))
                {
                    fileUrl = CmsContext.ApplicationPath + fileUrl;
                }


                int    phThumbWidth   = 999;
                int    phThumbHeight  = 222;
                string thumbUrlFormat = showThumbPage.getThumbDisplayUrl(res, phThumbWidth, phThumbHeight);
                thumbUrlFormat = thumbUrlFormat.Replace(phThumbWidth.ToString(), "{0}");
                thumbUrlFormat = thumbUrlFormat.Replace(phThumbHeight.ToString(), "{1}");

                if (fileNum % imagesPerRow == 0)
                {
                    if (rowStarted)
                    {
                        html.Append("</tr>");
                    }
                    html.Append("<tr>");
                }

                int[] dimensions = res.getImageDimensions();
                if (dimensions.Length != 2)
                {
                    dimensions = WebEditor.Helpers.InlineImageBrowser2.getImageDimensions(res.FilePath);
                    res.setImageDimensions(dimensions);
                    updateResource = true;
                }


                string imgId = "file_" + res.ResourceId.ToString();
                html.Append("<td align=\"center\">");
                string onclick = "doSelImg('" + imgId + "'); parent.selectImage('" + fiName + "','" + fileUrl + "'," + dimensions[0] + ", " + dimensions[1] + ", '" + thumbUrlFormat + "'); ";
                if (IsCKEditor)
                {
                    onclick = "ckSelImg('" + imgId + "', '" + fileUrl.Replace("'", "\\'") + "'," + dimensions[0] + ", " + dimensions[1] + ");";
                }
                html.Append(" <a href=\"#\" onclick=\"" + onclick + " return false;\">");

                html.Append(imgHtmlTag);

                html.Append("</a> ");
                html.Append("<br /><div style=\"font-family: arial; font-size: 8pt; text-align: center; width: 120px; overflow: hidden;\">" + res.FileName + "</div>");

                if (SelImagePath != "" && fileUrl == SelImagePath)
                {
                    html.Append("<script>" + onclick + "</script>" + Environment.NewLine);
                }

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

                filenames.Add(res.FilePath);

                fileNum++;

                if (updateResource)
                {
                    bool b = res.SaveToDatabase();
                    if (!b)
                    {
                        Console.Write("resource failed to update.");
                    }
                }
            } // foreach
            if (rowStarted)
            {
                html.Append("</tr>");
            }
            html.Append("</table>");


            ph_ImagePanel.Controls.Add(new LiteralControl(html.ToString()));
        }