diff --git a/wheels/view/assets.cfm b/wheels/view/assets.cfm index aff2522d89..3923806a4b 100644 --- a/wheels/view/assets.cfm +++ b/wheels/view/assets.cfm @@ -19,42 +19,42 @@ ' categories="view-helper,assets" chapters="miscellaneous-helpers" functions="javaScriptIncludeTag,imageTag"> - - - - - - var loc = {}; - $args(name="styleSheetLinkTag", args=arguments, combine="sources/source/!", reserved="href,rel"); - arguments.rel = "stylesheet"; - loc.returnValue = ""; - arguments.sources = $listClean(list=arguments.sources, returnAs="array"); - loc.iEnd = ArrayLen(arguments.sources); - for (loc.i=1; loc.i <= loc.iEnd; loc.i++) - { - loc.item = arguments.sources[loc.i]; - if (ReFindNoCase("^https?:\/\/", loc.item)) - { - arguments.href = arguments.sources[loc.i]; - } - else - { - arguments.href = application.wheels.webPath & application.wheels.stylesheetPath & "/" & loc.item; - if (!ListFindNoCase("css,cfm", ListLast(loc.item, "."))) - arguments.href = arguments.href & ".css"; - arguments.href = $assetDomain(arguments.href) & $appendQueryString(); - } - loc.returnValue = loc.returnValue & $tag(name="link", skip="sources,head", close=true, attributes=arguments) & chr(10); - } - if (arguments.head) - { - $htmlhead(text=loc.returnValue); - loc.returnValue = ""; - } - - - - + + + + + + var loc = {}; + $args(name="styleSheetLinkTag", args=arguments, combine="sources/source/!", reserved="href,rel"); + arguments.rel = "stylesheet"; + loc.returnValue = ""; + arguments.sources = $listClean(list=arguments.sources, returnAs="array"); + loc.iEnd = ArrayLen(arguments.sources); + for (loc.i=1; loc.i <= loc.iEnd; loc.i++) + { + loc.item = arguments.sources[loc.i]; + if (ReFindNoCase("^https?:\/\/", loc.item)) + { + arguments.href = arguments.sources[loc.i]; + } + else + { + arguments.href = application.wheels.webPath & application.wheels.stylesheetPath & "/" & loc.item; + if (!ListFindNoCase("css,cfm", ListLast(loc.item, "."))) + arguments.href = arguments.href & ".css"; + arguments.href = $assetDomain(arguments.href) & $appendQueryString(); + } + loc.returnValue = loc.returnValue & $tag(name="link", skip="sources,head", close=true, attributes=arguments) & chr(10); + } + if (arguments.head) + { + $htmlhead(text=loc.returnValue); + loc.returnValue = ""; + } + + + + - - - - - var loc = {}; - $args(name="javaScriptIncludeTag", args=arguments, combine="sources/source/!", reserved="src"); - loc.returnValue = ""; - arguments.sources = $listClean(list=arguments.sources, returnAs="array"); - loc.iEnd = ArrayLen(arguments.sources); - for (loc.i=1; loc.i <= loc.iEnd; loc.i++) - { - loc.item = arguments.sources[loc.i]; - if (ReFindNoCase("^https?:\/\/", loc.item)) - { - arguments.src = arguments.sources[loc.i]; - } - else - { - arguments.src = application.wheels.webPath & application.wheels.javascriptPath & "/" & loc.item; - if (!ListFindNoCase("js,cfm", ListLast(loc.item, "."))) - arguments.src = arguments.src & ".js"; - arguments.src = $assetDomain(arguments.src) & $appendQueryString(); - } - loc.returnValue = loc.returnValue & $element(name="script", skip="sources,head", attributes=arguments) & chr(10); - } - if (arguments.head) - { - $htmlhead(text=loc.returnValue); - loc.returnValue = ""; - } - - - - - - ##imageTag("logo.png")## - - - ##imageTag("http://cfwheels.org/images/logo.png", alt="ColdFusion on Wheels")## - - - ##imageTag(source="logo.png", class="logo")## - ' - categories="view-helper,assets" chapters="miscellaneous-helpers" functions="javaScriptIncludeTag,styleSheetLinkTag"> - - - var loc = {}; - $args(name="imageTag", reserved="src", args=arguments); - // ugly fix due to the fact that id can't be passed along to cfinvoke - if (StructKeyExists(arguments, "id")) - { - arguments.wheelsId = arguments.id; - StructDelete(arguments, "id"); - } - if (application.wheels.cacheImages) - { - loc.category = "images"; - loc.key = $hashedKey(arguments); - loc.lockName = loc.category & loc.key; - loc.conditionArgs = {}; - loc.conditionArgs.category = loc.category; - loc.conditionArgs.key = loc.key; - loc.executeArgs = arguments; - loc.executeArgs.category = loc.category; - loc.executeArgs.key = loc.key; - loc.returnValue = $doubleCheckedLock(name=loc.lockName, condition="$getFromCache", execute="$addImageTagToCache", conditionArgs=loc.conditionArgs, executeArgs=loc.executeArgs); - } - else - { - loc.returnValue = $imageTag(argumentCollection=arguments); - } - // ugly fix continued - if (StructKeyExists(arguments, "wheelsId")) - loc.returnValue = ReplaceNoCase(loc.returnValue, "wheelsId", "id"); - - - - - - - var returnValue = ""; - returnValue = $imageTag(argumentCollection=arguments); - $addToCache(key=arguments.key, value=returnValue, category=arguments.category); - - - - - - - var loc = {}; - loc.localFile = true; - - if(Left(arguments.source, 7) == "http://" || Left(arguments.source, 8) == "https://") - loc.localFile = false; - - if (!loc.localFile) - { - arguments.src = arguments.source; - } - else - { - arguments.src = application.wheels.webPath & application.wheels.imagePath & "/" & arguments.source; - if (application.wheels.showErrorInformation) - { - if (loc.localFile && !FileExists(ExpandPath(arguments.src))) - $throw(type="Wheels.ImageFileNotFound", message="Wheels could not find `#expandPath('#arguments.src#')#` on the local file system.", extendedInfo="Pass in a correct relative path from the `images` folder to an image."); - else if (!IsImageFile(ExpandPath(arguments.src))) - $throw(type="Wheels.ImageFormatNotSupported", message="Wheels can't read image files with that format.", extendedInfo="Use one of these image types instead: #GetReadableImageFormats()#."); - } - // height and/or width arguments are missing so use cfimage to get them - if (!StructKeyExists(arguments, "width") or !StructKeyExists(arguments, "height")) - { - loc.image = $image(action="info", source=ExpandPath(arguments.src)); - if (!StructKeyExists(arguments, "width") and loc.image.width gt 0) - arguments.width = loc.image.width; - if (!StructKeyExists(arguments, "height") and loc.image.height gt 0) - arguments.height = loc.image.height; - } - // only append a query string if the file is local - arguments.src = $assetDomain(arguments.src) & $appendQueryString(); - } - if (!StructKeyExists(arguments, "alt")) - arguments.alt = capitalize(ReplaceList(SpanExcluding(Reverse(SpanExcluding(Reverse(arguments.src), "/")), "."), "-,_", " , ")); - loc.returnValue = $tag(name="img", skip="source,key,category", close=true, attributes=arguments); - - - - - - - var returnValue = ""; - // if assetQueryString is a boolean value, it means we just reloaded, so create a new query string based off of now - // the only problem with this is if the app doesn't get used a lot and the application is left alone for a period longer than the application scope is allowed to exist - if (IsBoolean(application.wheels.assetQueryString) and YesNoFormat(application.wheels.assetQueryString) == "no") - return returnValue; - - if (!IsNumeric(application.wheels.assetQueryString) and IsBoolean(application.wheels.assetQueryString)) - application.wheels.assetQueryString = Hash(DateFormat(Now(), "yyyymmdd") & TimeFormat(Now(), "HHmmss")); - returnValue = returnValue & "?" & application.wheels.assetQueryString; - - - - - - - - var loc = {}; - loc.returnValue = arguments.pathToAsset; - if (application.wheels.showErrorInformation) - { - if (!IsStruct(application.wheels.assetPaths) && !IsBoolean(application.wheels.assetPaths)) - $throw(type="Wheels.IncorrectConfiguration", message="The setting `assetsPaths` must be false or a struct."); - if (IsStruct(application.wheels.assetPaths) && !ListFindNoCase(StructKeyList(application.wheels.assetPaths), "http")) - $throw(type="Wheels.IncorrectConfiguration", message="The `assetPaths` setting struct must contain the key `http`"); - } - - // return nothing if assetPaths is not a struct - if (!IsStruct(application.wheels.assetPaths)) - return loc.returnValue; - - loc.protocol = "http://"; - loc.domainList = application.wheels.assetPaths.http; - - if (isSecure()) - { - loc.protocol = "https://"; - if (StructKeyExists(application.wheels.assetPaths, "https")) - loc.domainList = application.wheels.assetPaths.https; - } - - loc.domainLen = ListLen(loc.domainList); - - if (loc.domainLen gt 1) - { - // now comes the interesting part, lets take the pathToAsset argument, hash it and create a number from it - // so that we can do mod based off the length of the domain list - // this is an easy way to apply the same sub-domain to each asset, so we do not create more work for the server - // at the same time we are getting a very random hash value to rotate the domains over the assets evenly - loc.pathNumber = Right(REReplace(Hash(arguments.pathToAsset), "[A-Za-z]", "", "all"), 5); - - loc.position = (loc.pathNumber mod (loc.domainLen)) + 1; - } - else - { - loc.position = loc.domainLen; - } - loc.returnValue = loc.protocol & Trim(ListGetAt(loc.domainList, loc.position)) & arguments.pathToAsset; - - + + + + + var loc = {}; + $args(name="javaScriptIncludeTag", args=arguments, combine="sources/source/!", reserved="src"); + loc.returnValue = ""; + arguments.sources = $listClean(list=arguments.sources, returnAs="array"); + loc.iEnd = ArrayLen(arguments.sources); + for (loc.i=1; loc.i <= loc.iEnd; loc.i++) + { + loc.item = arguments.sources[loc.i]; + if (ReFindNoCase("^https?:\/\/", loc.item)) + { + arguments.src = arguments.sources[loc.i]; + } + else + { + arguments.src = application.wheels.webPath & application.wheels.javascriptPath & "/" & loc.item; + if (!ListFindNoCase("js,cfm", ListLast(loc.item, "."))) + arguments.src = arguments.src & ".js"; + arguments.src = $assetDomain(arguments.src) & $appendQueryString(); + } + loc.returnValue = loc.returnValue & $element(name="script", skip="sources,head", attributes=arguments) & chr(10); + } + if (arguments.head) + { + $htmlhead(text=loc.returnValue); + loc.returnValue = ""; + } + + + + + + ##imageTag("logo.png")## + + + ##imageTag("http://cfwheels.org/images/logo.png", alt="ColdFusion on Wheels")## + + + ##imageTag(source="logo.png", class="logo")## + ' + categories="view-helper,assets" chapters="miscellaneous-helpers" functions="javaScriptIncludeTag,styleSheetLinkTag"> + + + var loc = {}; + $args(name="imageTag", reserved="src", args=arguments); + // ugly fix due to the fact that id can't be passed along to cfinvoke + if (StructKeyExists(arguments, "id")) + { + arguments.wheelsId = arguments.id; + StructDelete(arguments, "id"); + } + if (application.wheels.cacheImages) + { + loc.category = "images"; + loc.key = $hashedKey(arguments); + loc.lockName = loc.category & loc.key; + loc.conditionArgs = {}; + loc.conditionArgs.category = loc.category; + loc.conditionArgs.key = loc.key; + loc.executeArgs = arguments; + loc.executeArgs.category = loc.category; + loc.executeArgs.key = loc.key; + loc.returnValue = $doubleCheckedLock(name=loc.lockName, condition="$getFromCache", execute="$addImageTagToCache", conditionArgs=loc.conditionArgs, executeArgs=loc.executeArgs); + } + else + { + loc.returnValue = $imageTag(argumentCollection=arguments); + } + // ugly fix continued + if (StructKeyExists(arguments, "wheelsId")) + loc.returnValue = ReplaceNoCase(loc.returnValue, "wheelsId", "id"); + + + + + + + var returnValue = ""; + returnValue = $imageTag(argumentCollection=arguments); + $addToCache(key=arguments.key, value=returnValue, category=arguments.category); + + + + + + + var loc = {}; + loc.localFile = true; + + if(Left(arguments.source, 7) == "http://" || Left(arguments.source, 8) == "https://") + loc.localFile = false; + + if (!loc.localFile) + { + arguments.src = arguments.source; + } + else + { + arguments.src = application.wheels.webPath & application.wheels.imagePath & "/" & arguments.source; + if (application.wheels.showErrorInformation) + { + if (loc.localFile && !FileExists(ExpandPath(arguments.src))) + $throw(type="Wheels.ImageFileNotFound", message="Wheels could not find `#expandPath('#arguments.src#')#` on the local file system.", extendedInfo="Pass in a correct relative path from the `images` folder to an image."); + else if (!IsImageFile(ExpandPath(arguments.src))) + $throw(type="Wheels.ImageFormatNotSupported", message="Wheels can't read image files with that format.", extendedInfo="Use one of these image types instead: #GetReadableImageFormats()#."); + } + // height and/or width arguments are missing so use cfimage to get them + if (!StructKeyExists(arguments, "width") or !StructKeyExists(arguments, "height")) + { + loc.image = $image(action="info", source=ExpandPath(arguments.src)); + if (!StructKeyExists(arguments, "width") and loc.image.width gt 0) + arguments.width = loc.image.width; + if (!StructKeyExists(arguments, "height") and loc.image.height gt 0) + arguments.height = loc.image.height; + } else { + // remove height and width attributes if false + if (arguments.width EQ false) { + StructDelete(arguments, "width"); + } + if (arguments.height EQ false) { + StructDelete(arguments,"height"); + } + } + // only append a query string if the file is local + arguments.src = $assetDomain(arguments.src) & $appendQueryString(); + } + if (!StructKeyExists(arguments, "alt")) + arguments.alt = capitalize(ReplaceList(SpanExcluding(Reverse(SpanExcluding(Reverse(arguments.src), "/")), "."), "-,_", " , ")); + loc.returnValue = $tag(name="img", skip="source,key,category", close=true, attributes=arguments); + + + + + + + var returnValue = ""; + // if assetQueryString is a boolean value, it means we just reloaded, so create a new query string based off of now + // the only problem with this is if the app doesn't get used a lot and the application is left alone for a period longer than the application scope is allowed to exist + if (IsBoolean(application.wheels.assetQueryString) and YesNoFormat(application.wheels.assetQueryString) == "no") + return returnValue; + + if (!IsNumeric(application.wheels.assetQueryString) and IsBoolean(application.wheels.assetQueryString)) + application.wheels.assetQueryString = Hash(DateFormat(Now(), "yyyymmdd") & TimeFormat(Now(), "HHmmss")); + returnValue = returnValue & "?" & application.wheels.assetQueryString; + + + + + + + + var loc = {}; + loc.returnValue = arguments.pathToAsset; + if (application.wheels.showErrorInformation) + { + if (!IsStruct(application.wheels.assetPaths) && !IsBoolean(application.wheels.assetPaths)) + $throw(type="Wheels.IncorrectConfiguration", message="The setting `assetsPaths` must be false or a struct."); + if (IsStruct(application.wheels.assetPaths) && !ListFindNoCase(StructKeyList(application.wheels.assetPaths), "http")) + $throw(type="Wheels.IncorrectConfiguration", message="The `assetPaths` setting struct must contain the key `http`"); + } + + // return nothing if assetPaths is not a struct + if (!IsStruct(application.wheels.assetPaths)) + return loc.returnValue; + + loc.protocol = "http://"; + loc.domainList = application.wheels.assetPaths.http; + + if (isSecure()) + { + loc.protocol = "https://"; + if (StructKeyExists(application.wheels.assetPaths, "https")) + loc.domainList = application.wheels.assetPaths.https; + } + + loc.domainLen = ListLen(loc.domainList); + + if (loc.domainLen gt 1) + { + // now comes the interesting part, lets take the pathToAsset argument, hash it and create a number from it + // so that we can do mod based off the length of the domain list + // this is an easy way to apply the same sub-domain to each asset, so we do not create more work for the server + // at the same time we are getting a very random hash value to rotate the domains over the assets evenly + loc.pathNumber = Right(REReplace(Hash(arguments.pathToAsset), "[A-Za-z]", "", "all"), 5); + + loc.position = (loc.pathNumber mod (loc.domainLen)) + 1; + } + else + { + loc.position = loc.domainLen; + } + loc.returnValue = loc.protocol & Trim(ListGetAt(loc.domainList, loc.position)) & arguments.pathToAsset; + + \ No newline at end of file