Skip to content

Instantly share code, notes, and snippets.

View quodos's full-sized avatar

Thomas Wilhelm quodos

View GitHub Profile
@quodos
quodos / strSlug.ftl
Last active April 16, 2018 08:06
Freemarker function that generates a URL friendly "slug" from a given string
<#-- The strSlug function generates a URL friendly "slug" from the given string -->
<#-- TODO: convert non-ASCII chars to ASCII chars -->
<#-- Copyright (c) 2018 Thomas Wilhelm <thomas.p.wilhelm@gmail.com> -->
<#function strSlug title seperator="-" idSafe=true>
<#local flipped = "_" />
<#if seperator == "_">
<#local flipped = "-" />
</#if>
<#local string = title?replace("[" + flipped + "]+", seperator, "r") />
<?php
/**
* Given a string containing any combination of YouTube and Vimeo video URLs in
* a variety of formats (iframe, shortened, etc), each separated by a line break,
* parse the video string and determine it's valid embeddable URL for usage in
* popular JavaScript lightbox plugins.
*
* In addition, this handler grabs both the maximize size and thumbnail versions
* of video images for your general consumption. In the case of Vimeo, you must
* have the ability to make remote calls using file_get_contents(), which may be