Ejemplo n.º 1
0
 /// <summary>
 /// Turns a string such as a title into one usable as a file name or URL (ie lower case separated with dashes).
 /// </summary>
 /// <param name="titleText"></param>
 /// <returns></returns>
 public static string CrunchFileName(string titleText)
 {
     //string returnValue = "";
     //if (!String.IsNullOrEmpty(titleText)) {
     //	returnValue = titleText.ToLower().Trim();
     //	returnValue = returnValue.Replace("&", "and");
     //	returnValue = returnValue.Replace(".", "-");
     //	returnValue = returnValue.Replace(" ", "-");
     //	returnValue = returnValue.Replace("_", "-");
     //	//returnValue = Fmt.CleanString(returnValue, "[^a-z0-9-]");
     //	returnValue = Fmt.CleanAlphaNumeric(returnValue);
     //	while (returnValue.Contains("--")) returnValue = returnValue.Replace("--", "-");
     //	returnValue = returnValue.TrimEnd('-');
     //}
     //return returnValue;
     return(Fmt.Crunch(titleText));
 }
Ejemplo n.º 2
0
        private static string DynamicImage(PictureActiveField pictureField, int width, int height, string cropStyle)
        {
            var    moddate          = pictureField.Record.Advanced.DateModified;
            var    uniqueKey        = pictureField.Record.GetTableName() + "_" + pictureField.Record.ID_Field.ValueObject + "_" + pictureField.Name + "_" + width + "x" + height + "_" + cropStyle;
            var    keywords         = (pictureField.Record.GetName());
            string originalFilename = pictureField.ToString();

            CheckTable();
            //var sql = new Sql();
            //var record = new ActiveRecord("DynamicImage", "");
            //record.LoadData();
            //var imgRecord = ActiveRecordLoader.LoadByField<ActiveRecord>("UniqueKey", uniqueKey, "DynamicImage", Otherwise.New);
            //var imgRecord = ActiveRecordLoader.Load<ActiveRecord>(new Sql("select * from DynamicImage where UniqueKey=", uniqueKey.SqlizeText()), "DynamicImage");
            var imgRecord = Models.DynamicImage.LoadByUniqueKey(uniqueKey);

            if (imgRecord == null)
            {
                imgRecord = new DynamicImage();
            }
            if (imgRecord.IsNewRecord || imgRecord["ImageModDate"].ConvertToDate() != moddate)
            {
                var currentVersion = imgRecord["Version"].ToInt(0);
                if (!imgRecord.IsNewRecord)
                {
                    // delete existing file to save space
                    FileSystem.DeleteAttachment("DynamicImage/" + imgRecord.ID_Field.ValueObject + "_" + currentVersion + ".png");
                }
                // create the record
                imgRecord["UniqueKey"].ValueObject        = uniqueKey;
                imgRecord["ImageUrl"].ValueObject         = Fmt.Crunch(keywords);
                imgRecord["Version"].ValueObject          = currentVersion + 1;
                imgRecord["CropStyle"].ValueObject        = cropStyle;
                imgRecord["Width"].ValueObject            = width;
                imgRecord["Height"].ValueObject           = height;
                imgRecord["OriginalFilename"].ValueObject = originalFilename;
                imgRecord["ImageModDate"].ValueObject     = moddate;
                imgRecord.Save();
            }
            // return file name
            return(Web.Root + "i/" + imgRecord.ID_Field.ValueObject + "_" + imgRecord["Version"] + "/" + imgRecord["ImageUrl"] + ".png");
        }