Skip to content

Instantly share code, notes, and snippets.

@opn
Last active November 21, 2017 17:51
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/3d6681040c5c09b5a0d4479b5609a2bb to your computer and use it in GitHub Desktop.
Save opn/3d6681040c5c09b5a0d4479b5609a2bb to your computer and use it in GitHub Desktop.
This is Revigniter controller 'imagine.lc' from the domain 'rest.livecode.world'.
<?lc
/* = DESCRIPTION =
--
The imagine.lc controller can be found at: imagine.lc
Here is some test help
Below we declare the global variables gControllerHandlers AND gData
And put the public method names that we wish to expose into gControllerHandlers
--
*/
global gControllerHandlers, gData
put "pinterest,flickr,twitter,photo,index,webpage,imagine" into gControllerHandlers
/* == INITIALISATION ==
--
Put all the handlers and variables that you wish to merge into your views
into the global array "gData".
Write any initialisation statements (loading any neeeded libraries for instance)
into the initialisation handler "imagine.lc" below.
--
*/
command imagine
start using stack (gAPPPATH & "stacks/lib_Fedwiki.livecode")
start using stack (gAPPPATH & "stacks/lib_MediaWiki.livecode")
start using stack (gAPPPATH & "stacks/lib_FedWikiPedia.livecode")
start using stack (gAPPPATH & "stacks/lib_HTML.livecode")
start using stack (gAPPPATH & "stacks/lib_Scrape.livecode")
start using stack (gAPPPATH & "stacks/lib_REST.livecodescript")
start using stack (gAPPPATH & "stacks/lib_Citation.livecodescript")
end imagine
/* == CODE ==
--
Here we put the public handlers the controller uses and exposes as urls.
--
*/
on index
local pageArray
put fedwiki_GetDroppedUrl ($_POST_RAW) into droppedURL
switch
case droppedURL begins with "https://player.fm/series/"
fedwiki_ForwardAndReturn "https://rest.livecode.world/bbc/playerfm"
break
case droppedURL begins with "http://www.radiolab.org/story/"
case droppedURL begins with "http://www.bbc.co.uk/programmes/"
case droppedURL begins with "https://www.theguardian.com/science/audio/" -- plenty of other podcast urls
fedwiki_ForwardAndReturn "https://rest.livecode.world/bbc"
break
case droppedURL begins with "http://www.openstreetmap.org/"
case droppedURL begins with "https://www.openstreetmap.org/"
case droppedURL begins with "https://www.google.co.uk/maps/place/"
case droppedURL begins with "https://www.google.com/maps/place/"
case matchtext (droppedURL, "^https://tools.wmflabs.org/geohack/geohack.php\?pagename=(.+)&params=(.+)", pageName, geoInfo)
fedwiki_ForwardAndReturn "https://rest.livecode.world/map"
break
case matchText (droppedURL, "https://www.one-tab.com/page/(.+)", oneTabID)
fedwiki_ForwardAndReturn "https://rest.livecode.world/onetab"
break
case matchText (droppedURL, "https://(.+).wikipedia.org/(.+)", lastBit)
fedwiki_ForwardAndReturn "https://rest.livecode.world/mediawiki"
break
case matchText (droppedURL, "http://britishlibrary.typepad.co.uk/.a/(.+)", assetID)
case matchText (droppedURL, "https://static.+.squarespace.com/static/.+", photoID)
photo droppedURL
break
case matchText (droppedURL, "https://www.pinterest.com/pin/(.+)/|https://www.pinterest.co.uk/pin/(.+)/", photoID)
pinterest droppedURL
break
case matchText (droppedURL, "https://www.flickr.com/photos/(.+)/(.+)/in/.+", userID, photoID)
flickr droppedURL
break
case matchText (droppedURL, "https://twitter.com/.+/status/.+")
twitter droppedURL
break
default
webpage droppedURL
break
end switch
end index
on pinterest droppedURL
if droppedURL is empty then
put fedwiki_GetDroppedUrl ($_POST_RAW) into droppedURL
end if
if matchText (droppedURL, "https://www.flickr.com/photos/(.+)/(.+)/in/.+", userID, photoID) then
put pinterest_FetchPinPageJson (photoID) into pageJSON
fedwiki_ReturnJSON pageJSON
else
fedwiki_ExitAndReturnError "Dropped url is nor recognised.", "Error"
end if
end pinterest
on flickr droppedURL
if droppedURL is empty then
put fedwiki_GetDroppedUrl ($_POST_RAW) into droppedURL
end if
if matchText (droppedURL, "https://www.flickr.com/photos/(.+)/(.+)/in/.+", userID, photoID) then
flickr_FetchAndDeconstructFromDroppedUrl droppedURL, photoTitle, photoDescription, mediumURL, photoTags
put the result into photoArray
put photoArray ["location"] into locationArray
put flickr_ConstructPhotoMapPageArray (photoTitle, photoDescription, mediumURL, droppedURL, locationArray, photoTags) into pageJSON
fedwiki_ReturnJSON pageJSON
else
fedwiki_ExitAndReturnError "Dropped url is nor recognised.", "Error"
end if
end flickr
on photo droppedURL
if droppedURL is empty then
put fedwiki_GetDroppedUrl ($_POST_RAW) into droppedURL
end if
put droppedURL into imageURL
put imageURL into captionLinkURL
--
put "Dropped Image" into pageTitle
put "This is a simple image dropped on to a wiki." into pageText
put empty into imageCaption
--
put fedwiki_ConstructNewPageArray (pageTitle, pageText) into pageArray
fedwiki_AddImageToPageArray pageArray, imageURL, imageCaption, captionLinkURL
--
put json_FromArray (pageArray) into pageJSON
fedwiki_ReturnJSON pageJSON
end photo
on twitter droppedURL
if droppedURL is empty then
put fedwiki_GetDroppedUrl ($_POST_RAW) into droppedURL
end if
put twitter_FetchPageJson (droppedURL) into pageJSON
fedwiki_ReturnJSON pageJSON
end twitter
on webpage droppedURL
/*
Here we try to produce a nice result from any dropped URL
*/
if droppedURL is empty then
put fedwiki_GetDroppedUrl ($_POST_RAW) into droppedURL
end if
set the itemdelimiter to "."
if item -1 of droppedURL is among the items of "jpg.jpeg.png.gif.webp" then
photo droppedURL
else
put fedwiki_ConstructWebPageArray (droppedURL, true, true, true) into pageArray
put json_FromArray (pageArray) into pageJSON
fedwiki_ReturnJSON pageJSON
end if
end webpage
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment