Skip to content

Instantly share code, notes, and snippets.

@opn
Last active April 10, 2016 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opn/41c304ca4981a32b4d49df60cbce8768 to your computer and use it in GitHub Desktop.
Save opn/41c304ca4981a32b4d49df60cbce8768 to your computer and use it in GitHub Desktop.
This stack contains all the handlers that are specific to Himalayan Academy site structure.
--> MetaData
-
license: GPLv3
name: lib_HAP
type: script library
version: 0.4
/*
This script-only stack is designed to work as a library file for the [[Himalayan Academy Web Site]].
It contains handlers which manipulate and understand teh web sites structure.
*/
--> HAP | To Rename
-
function gist_DeconstructFileArray
-- was "sitemap_FetchPhotoArray"
put hap_SitemapRestURL ("list_PhotoArray") into someURL
put url someURL into tEncodedArray
put arrayDecode(base64Decode(tEncodedArray)) into tResultArray
return tResultArray
end gist_DeconstructFileArray
--> HAP | Only on server
-
function hap_GetFileNameArray relFolderPath
if the environment is "server" then
rigLoadHelper "file"
put rigTrim (relFolderPath, "/") into relFolderPath
put hap_GetPathTranslated() into tPathTranslated
put tPathTranslated & relFolderPath into someFolder
if there is a folder (someFolder) then
put rigGetFileNames (someFolder, TRUE) into tFileNamesArray
return tFileNamesArray
else
return empty
end if
end if
end hap_GetFileNameArray
function hap_GetPathTranslated
if the environment is "server" then
# GET PATH TRANSLATED - NEEDED TO GET FILE INFO
put $_SERVER["PATH_TRANSLATED"] into tPathTranslated
# REMOVE index.lc
set the itemDel to "/"
put (item 1 to - 2 of tPathTranslated) & "/" into tPathTranslated
end if
return tPathTranslated
end hap_GetPathTranslated
--> HAP
-
/*
Himlayan Academy Project specific handlers.
These handlers we extract from the HAP revIgniter application code, in order to make them independent of server side functionality.
This allows for testing and use in Desktop and mobile clients.
*/
function hap_ListImageFiles recordArray
put hap_GetImageFolder (recordArray) into relFolderPath
put hap_ListFiles (relFolderPath) into fileNamesList
return fileNamesList
end hap_ListImageFiles
function hap_ListFiles relFolderPath
put hap_GetFileNameArray (relFolderPath) into fileNameArray
repeat for each key tKey in fileNameArray
put tFileNamesArray [tKey] & CR after fileNamesList
end repeat
delete byte -1 of fileNamesList
sort lines of fileNamesList ascending text by item -1 of each
return fileNamesList
end hap_ListFiles
function hap_GetImageFolder recordArray
return folderForArt (recordArray)
-- equivalent to folderForArt (pA) in art.lc
set the itemDel to "/"
put item 2 of recordArray ["media_type"] into mType
-- put mType into gData ["artFolder"]
put recordArray ["file_id"] into fileID
put hap_GetDocumentRoot() into docRoot
if mType is empty then return docRoot
put docRoot & "/media/art/" & mType into artFolder
if fileID is empty then return artFolder
put "/" & fileID after artFolder
return artFolder
end hap_GetImageFolder
function hap_GetImageRelativePath artFolder, fileID, pSize
if pSize is empty then put "med" into pSize
text_AddTrailing artFolder, "/"
put fileID & "_" & pSize & ".jpg" into shortFile
put artFolder & shortFile into relmagePath
return relmagePath
end hap_GetImageRelativePath
function hap_GetImageDescription recordArray
put recordArray ["description"] into markdownDescription
return markdownDescription
put markdown (markdownDescription) into htmlDescription
return htmlDescription
end hap_GetImageDescription
function hap_GetImageAuthor recordArray
switch
case recordArray ["artists"] is not empty
return recordArray ["artists"] into tBuf
case recordArray ["photographer"] is not empty
return recordArray ["photographer"]
default
return empty
end switch
end hap_GetImageAuthor
function hap_GetAllImageFormats recordArray
repeat for each key itemNum in recordArray ["formats"]
put recordArray ["formats"][itemNum]["filename"] & CR after imageFiles
end repeat
delete char -1 of imageFiles
return imageFiles
end hap_GetAllImageFormats
function hap_ListImageFormats
return "440x390,564x500,3081x2730"
end hap_ListImageFormats
function hap_GetDocumentRoot
-- so we can test and debug on desktop as well
if the environment is "server" then
put $_SERVER["DOCUMENT_ROOT"] into docRoot
else
put "/home/devhap/public_html" into docRoot
end if
return docRoot
end hap_GetDocumentRoot
function hap_ConstructShortSitemapFileName refinementName
put tolower (refinementName) & "-sitemap.xml" into shortSitemapFile
return shortSitemapFile
end hap_ConstructShortSitemapFileName
function hap_ListRefinementNames pCalculate
if pCalculate is not true then
return "Art,ArtPhoto,Audio,Book,Galleria,Image,Photo,Slideshow,Video"
else
put the script of me into someScript
put script_GetFunction ("hap_RefinementToMediaTypes", someScript) into someHandler
put script_ExtractCaseConditions (someHandler) into caseConditions
sort caseConditions
replace CR with comma in caseConditions
return caseConditions
end if
end hap_ListRefinementNames
function hap_RefinementToMediaTypes refinementName
switch refinementName
case "Image"
put "art/photography,art/painting,art/drawing,art/vector" into mTypeList
case "Photo"
return "art/photography,slideshow/external,slideshow/galleria" into mTypeList
case "Art"
return "art/drawing,art/painting,art/vector" into mTypeList
case "ArtPhoto"
return "art/photography" into mTypeList
case "Galleria"
return "slideshow/galleria" into mTypeList
case "Slideshow"
return "slideshow/external,slideshow/galleria" into mTypeList
case "Book"
return "text/book,text/booklet,text/review" into mTypeList
case "Audio"
return "audio/inspiredtalk,audio/shum,audio/chant,audio/song" into mTypeList
case "Video"
return "video/building,video/news,video/pubdesk,video/ritual,video/talk,video/teaching,video/travel" into mTypeList
default
return empty
end switch
end hap_RefinementToMediaTypes
function hap_ConstructUrls shortFoundHtmlFiles
put cHapRoot into urlStem
repeat for each line shortFile in shortFoundHtmlFiles
set the itemdelimiter to "/"
if item -1 of shortFile is among the items of "index.html/index.xml" then
delete item -1 of shortFile
else
set the itemdelimiter to "."
if item -1 of shortFile is among the items of "html.xml.htm" then
delete item -1 of shortFile
end if
end if
put urlStem & shortFile & CR after someURLs
end repeat
delete char -1 of someURLs
return someURLs
end hap_ConstructUrls
function hap_SitemapRestURL handlerName, pID
return hap_ConstructRestURL ("list", handlerName, pID)
end hap_SitemapRestURL
function hap_ConstructRestURL someController, pHandlerName, pID
text_TopAndTail someController, "/"
text_TopAndTail pHandlerName, "/"
if pHandlerName is empty then put "index" into pHandlerName
put someController & "/" & pHandlerName into somePath
return url_Construct (cHapDevRoot, somePath, pID)
end hap_ConstructRestURL
function hap_ConstructMediaUrl fileSlug
sitemap_EntityEscape fileSlug
put cHapRoot & "/view/" & fileSlug into someURL
put cHapRoot & "/site/viewmedia/" & fileSlug into someURL
return someURL
end hap_ConstructMediaUrl
--> Galleria
-
function galleria_GetRecordFiles pGalleryPath
put rigTrim(pGalleryPath, "/") into tGalleryPath
# GET PATH TRANSLATED - NEEDED TO GET FILE INFO
put $_SERVER["PATH_TRANSLATED"] into tPathTranslated
# REMOVE index.lc
set the itemDel to "/"
put (item 1 to - 2 of tPathTranslated) & "/" into tPathTranslated
# GET BASE URL
put rigFetchConfigItem("baseUrl") into tURLbase
# GET FULL PATHS TO FILES
rigLoadHelper "file"
if there is a folder (tPathTranslated & tGalleryPath) then
put rigGetFileNames((tPathTranslated & tGalleryPath), TRUE,) into tFileNamesArray
else
-- rigLogMessage "error", "Missing galleria folder."
return "error, Missing galleria folder."
end if
# GET SORTED LIST OF FILES
repeat for each key tKey in tFileNamesArray
put tFileNamesArray[tKey] & return after tFileNamesList
end repeat
delete byte -1 of tFileNamesList
sort lines of tFileNamesList ascending text by item -1 of each
return tFileNamesList
end galleria_GetRecordFiles
function galleria_GetRecordFolder pRecordA
put pRecordA ["file_id"] into tFileID
set the itemdel to "-"
put item 1 of pRecordA ["date_created"] into tYear
put format ("media/slideshows/%s/%s", tYear, tFileID) into tFilePath
return tFilePath
end galleria_GetRecordFolder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment