protected void Page_Load(object sender, EventArgs e) { this.RegisterWorkareaCssLink(); this.RegisterDialogCssLink(); Ektron.Cms.API.JS.RegisterJS(this, "../ContentDesigner/ekxbrowser.js", "ekxbrowserJS"); Ektron.Cms.API.JS.RegisterJS(this, "../ContentDesigner/ekutil.js", "ekutilJS"); Ektron.Cms.API.JS.RegisterJS(this, "../ContentDesigner/RadWindow.js", "RadWindowJS"); this.ClientScript.RegisterClientScriptBlock(this.GetType(), "InitializeRadWindow", "InitializeRadWindow(); self.focus();", true); m_refMsg = m_refAPI.EkMsgRef; Utilities.ValidateUserLogin(); titlePage.Text = m_refMsg.GetMessage("lbl imagetool edit title"); if (!Page.IsPostBack) { // Information from the URL parameters if (null != Request.Params.Get("s")) { if (null != Session["ImageToolNewFile"]) { // save image clicked // update the thumbnail for the image Ektron.Cms.ImageTool.ImageTool imager = new Ektron.Cms.ImageTool.ImageTool(); string imagefilepath = (string) Session["ImageToolNewFile"]; string thumbfilepath = imagefilepath; if (thumbfilepath.ToLower().EndsWith(".gif")) { thumbfilepath = thumbfilepath.Substring(0, thumbfilepath.LastIndexOf(".")) + ".png"; } thumbfilepath = thumbfilepath.Substring(0, thumbfilepath.LastIndexOf("\\") + 1) + "thumb_" + thumbfilepath.Substring(thumbfilepath.LastIndexOf("\\") + 1); /**** THIS IS NOW DONE in ImageScore.aspx.cs on CommitPersistentCommand try { imager.Resize(125, -1, true, imagefilepath, thumbfilepath); } catch (IOException) { // the thumbnail service might be already updating the thumbnail // so just ignore any I/O exceptions } */ // copy image to any load balance locations Ektron.Cms.Library.EkLibrary refLib = m_refAPI.EkLibraryRef; foreach (Microsoft.VisualBasic.Collection libpath in refLib.GetAllLBPaths("images")) { string relLBpath = (string) libpath["LoadBalancePath"]; string realLBpath = Server.MapPath(relLBpath); string imgfilename = imagefilepath.Substring(imagefilepath.LastIndexOf("\\")+1); string thumbnailfname = thumbfilepath.Substring(thumbfilepath.LastIndexOf("\\")+1); try { File.Copy(imagefilepath, realLBpath + imgfilename); } catch (Exception) {} try { File.Copy(thumbfilepath, realLBpath + thumbnailfname); } catch (Exception) { } } // clear out the session variable holding the new filename Session["ImageToolNewFile"] = null; Session["ImageToolNewFileUrl"] = null; Session["ImageToolOldLibId"] = null; Session["ImageToolOldLibContentId"] = null; Session["ImageToolNewLibFileName"] = null; Session["ImageToolLibFolderId"] = null; Session["ImageToolAssetName"] = null; } } else if (null != Request.Params.Get("c")) { // cancel, so delete the new image file // then delete the session variable holding the new filename if (null != Session["ImageToolNewFile"]) { // get rid of library entry for image Ektron.Cms.ContentAPI refContApi = getContentAPI(); refContApi.DeleteLibraryItemForImageTool((string)Session["ImageToolNewFileUrl"]); if ((Session["ImageToolAssetName"] != null) && !((string)Session["ImageToolAssetName"]).StartsWith("thumb_")) { refContApi.DeleteAssetForImageTool((string)Session["ImageToolAssetName"]); } // get rid of image file string imagefilepath = (string)Session["ImageToolNewFile"]; if (File.Exists(imagefilepath)) { try { File.Delete(imagefilepath); } catch (IOException) { } } string thumbfilepath = imagefilepath; if (thumbfilepath.ToLower().EndsWith(".gif")) { thumbfilepath = thumbfilepath.Substring(0, thumbfilepath.LastIndexOf(".")) + ".png"; } thumbfilepath = thumbfilepath.Substring(0, thumbfilepath.LastIndexOf("\\") + 1) + "thumb_" + thumbfilepath.Substring(thumbfilepath.LastIndexOf("\\") + 1); // and the thumbnail if (File.Exists(thumbfilepath)) { try { File.Delete(thumbfilepath); } catch (IOException) { } } } Session["ImageToolNewFile"] = null; Session["ImageToolNewFileUrl"] = null; Session["ImageToolOldLibId"] = null; Session["ImageToolOldLibContentId"] = null; Session["ImageToolNewLibFileName"] = null; Session["ImageToolLibFolderId"] = null; Session["ImageToolAssetName"] = null; } else if (null != Request.Params.Get("i")) { string strValue = Page.Server.UrlDecode(Request.Params.Get("i")).Trim(); if (!strValue.Contains("://")) { // see if we're editing a thumbnailed image which comes in w/o a full URL strValue = Request.Url.Scheme + "://" + Request.Url.Host + ((((Request.Url.Scheme == "http") && (Request.Url.Port != 80)) || ((Request.Url.Scheme == "https") && (Request.Url.Port != 443))) ? (":" + Request.Url.Port) : "") + strValue; } if (strValue.Contains("://")) { URL url = new URL(strValue); URL myURL = new URL(Page.Request.Url.ToString()); strValue = url.Path; if (strValue.StartsWith(":")) { // work around asp.net bug where url.path includes port# for path strValue = strValue.Substring(strValue.IndexOf("/")); } // get info for old library item string origImagePath = strValue; bool fEditingThumbnail = false; bool fIsAssetImage = false; Ektron.Cms.ContentAPI refContApi = getContentAPI(); Ektron.Cms.LibraryData library_data = refContApi.GetLibraryItemByUrl(strValue); if ((library_data == null) && strValue.Contains("thumb_")) { // this is a thumbnail so try to locate the image associated with it // since we don't store the thumbnail path in the DB origImagePath = strValue.Replace("thumb_", ""); library_data = refContApi.GetLibraryItemByUrl(origImagePath); if (library_data == null) { // thumbnails are PNG files so see if the original was a JPEG or GIF string[] imageexts = { ".jpg", ".gif" }; foreach (string ext in imageexts) { string origImageGuess = origImagePath.Replace(".png", ext); library_data = refContApi.GetLibraryItemByUrl(origImageGuess); if (library_data != null) { origImagePath = origImageGuess; break; } } } fEditingThumbnail = true; } if (library_data == null) { panelMessage.Visible = true; lblMessage.Text = m_refMsg.GetMessage("err imagetool unable to find image") + strValue; imagetool.Visible = false; return; } long folderid = library_data.ParentId; if ((library_data.ParentId == 0) && (library_data.ContentId != 0)) { // this is a DMS asset, so look up the folder it belongs in folderid = refContApi.GetFolderIdForContentId(library_data.ContentId); fIsAssetImage = true; } Ektron.Cms.PermissionData security_data = refContApi.LoadPermissions(folderid, "folder", Ektron.Cms.ContentAPI.PermissionResultType.Common); Ektron.Cms.PermissionData usersecurity_data = refContApi.LoadPermissions(refContApi.UserId, "users", Ektron.Cms.ContentAPI.PermissionResultType.All); if (!security_data.CanAddToImageLib && !usersecurity_data.IsAdmin) { panelMessage.Visible = true; lblMessage.Text = m_refMsg.GetMessage("err imagetool no library permission"); imagetool.Visible = false; return; } // generate new filename if ((url.HostName == myURL.HostName) || (url.HostName.ToLower() == "localhost")) { string strFilePath = null; try { strFilePath = Server.MapPath(origImagePath); } catch (Exception) { panelMessage.Visible = true; lblMessage.Text = m_refMsg.GetMessage("err imagetool non site image"); imagetool.Visible = false; return; } string strNewFilePath = strFilePath; if (File.Exists(strFilePath)) { FileInfo fileinfo = new FileInfo(strFilePath); // name the file "<oldname>.N.<extension>" string origfname = fileinfo.Name; string fname = origfname; string newfname = fname; do { string[] fnamepieces = fname.Split(new char[] { '.' }); newfname = fname; if (fnamepieces.Length > 2) { // loop until we find one that doesn't exist string strCurVer = fnamepieces[fnamepieces.Length - 2]; string strExt = fnamepieces[fnamepieces.Length - 1]; int newVer = int.Parse(strCurVer) + 1; newfname = fname.Replace("." + strCurVer + "." + strExt, "." + newVer + "." + strExt); } else if (fnamepieces.Length == 2) { newfname = fnamepieces[0] + ".1." + fnamepieces[1]; } else { // not sure what to do w/ filename w/ no extension??? } strNewFilePath = strNewFilePath.Replace(fname, newfname); fileinfo = new FileInfo(strNewFilePath); if (fileinfo.Exists) { fname = fileinfo.Name; } } while (fileinfo.Exists); if (strFilePath != strNewFilePath) { File.Copy(strFilePath, strNewFilePath); strValue = origImagePath.Replace(origfname, newfname); // save new filename so we can clean it up when user clicks on "cancel" button Session["ImageToolNewFile"] = strNewFilePath; // save URL so we can delete it from the library Session["ImageToolNewFileUrl"] = strValue; // save asset filename if we it's an asset Session["ImageToolAssetName"] = null; if (fIsAssetImage) { Session["ImageToolAssetName"] = newfname; } if (library_data != null) { // save tags and metadata for original image Ektron.Cms.TagData[] oldtags = null; Ektron.Cms.Community.TagsAPI refTagsApi = new Ektron.Cms.Community.TagsAPI(); Ektron.Cms.ContentMetaData[] oldmeta = null; if (library_data.Id > 0) { Session["ImageToolOldLibId"] = library_data.Id; Session["ImageToolOldLibContentId"] = library_data.ContentId; oldtags = refTagsApi.GetTagsForObject(library_data.Id, Ektron.Cms.Common.EkEnumeration.CMSObjectTypes.Library, refContApi.ContentLanguage); if (library_data.ContentId != 0) { Ektron.Cms.ContentData content_data = refContApi.GetContentById(library_data.ContentId, Ektron.Cms.ContentAPI.ContentResultType.Published); if (content_data != null) { oldmeta = content_data.MetaData; } } else { oldmeta = library_data.MetaData; } } // create new image to edit library_data.Id = 0; if (fEditingThumbnail) { origfname = new FileInfo(origImagePath).Name; library_data.FileName = library_data.FileName.Replace(origfname, newfname); } else { library_data.FileName = library_data.FileName.Replace(origfname, newfname); } library_data.ParentId = folderid; Session["ImageToolNewLibFileName"] = library_data.FileName; Session["ImageToolLibFolderId"] = library_data.ParentId; long newLibId = refContApi.AddLibraryItemForImageTool(ref library_data); if (fIsAssetImage && !newfname.StartsWith("thumb_")) { // only need to add this for assets, not thumbnail of assets refContApi.AddAssetForImageTool(origfname, newfname); } // add original tags/metadata to new image if (oldtags != null) { foreach (Ektron.Cms.TagData tag in oldtags) { refTagsApi.AddTagToObject(tag.Id, newLibId, Ektron.Cms.Common.EkEnumeration.CMSObjectTypes.Library, -1, refContApi.ContentLanguage); } } if (oldmeta != null) { refContApi.UpdateLibraryMetadataByID(newLibId, oldmeta); } } // can't show filenames or it'll be too long and the DMS filenames are ugly //titlePage.Text = m_refMsg.GetMessage("lbl imagetool edit title") + ": " + origfname; } } imagetool.Edit(strValue); } else { panelMessage.Visible = true; lblMessage.Text = m_refMsg.GetMessage("err imagetool non site image"); imagetool.Visible = false; } } } } }
public bool Rotate(ImageTool.ImageRotation rotateValue) { bool bRet = false; if ((null != m_imageTool) && (m_physicalTargetPath.Length > 0)) { //if (false == File.Exists(m_physicalTargetPath)) // These are taken out for performance. // EnsureDestPathExists(m_physicalTargetPath); // When the image is initialized, this should be done. bRet = m_imageTool.Rotate(rotateValue, m_physicalSourcePath, m_physicalTargetPath); m_lastCommand = ImageCommand.Rotate.ToString(); // mc_commandRotate; //m_lastParams = rotateValue.ToString(m_numberFormatInfo); // Compiler states that this is obsolete, to not use format info. m_lastParams = rotateValue.ToString(); } return bRet; }
/// <summary> /// This constructor loads the object with the data /// of the image that has the given ID. /// </summary> /// <param name="?"></param> public ImageData(int idImage) { InitFormatInfo(); if (0 != InitializeImageId(idImage)) { m_imageTool = new ImageTool(); } }
/// <summary> /// This constructor loads the object with the data /// of the image that exists on the given physical /// path. /// </summary> /// <param name="strPath"></param> public ImageData(string imagePhysicalPath) { InitFormatInfo(); if (0 != InitializeImage(imagePhysicalPath)) { m_imageTool = new ImageTool(); } }