Last active
March 9, 2016 10:09
-
-
Save keithdevon/db6e90f4a419c4a2c08b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_hr_link_type($link_url) { | |
//strip query string (everything after the ?) | |
$link_url = preg_replace('/\?.*/', '', $link_url); | |
// get the file extension | |
$pathinfo = pathinfo($link_url); | |
$filetype = $pathinfo['extension']; | |
$document_extensions = array('pdf','jpg','jpeg','gif','tif','png','pptx','pptm','ppt','pot','potx','potm','wav','mp3','mp4','avi','flv','mov','mpg','rm','swf','wmv','zip','xls','xla','xlb','xlc','xld','xlk','xll','xlm','xlt','xlv','xlw','doc','docx'); | |
$in_array = in_array($filetype, $document_extensions); | |
if( empty($filetype) || $in_array == FALSE ){ | |
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; | |
if(preg_match($reg_exUrl, $link_url, $url)) { | |
$filetype = 'web'; | |
} else { | |
$filetype = 'unknown'; | |
} | |
} | |
switch ($filetype) | |
{ | |
case "web": | |
$icon_type = 'web'; | |
break; | |
case "pdf": | |
$icon_type = 'pdf'; | |
break; | |
case "jpg": | |
case "png": | |
case "gif": | |
case "jpeg": | |
case "tif": | |
$icon_type = 'image'; | |
break; | |
case "pptx": | |
case "pptm": | |
case "ppt": | |
case "pot": | |
case "potx": | |
case "potm": | |
$icon_type = 'presentation'; | |
break; | |
case "wav": | |
case "mp3": | |
$icon_type = 'audio'; | |
break; | |
case "mp4": | |
case "avi": | |
case "flv": | |
case "mov": | |
case "mpg": | |
case "rm": | |
case "swf": | |
case "wmv": | |
$icon_type = 'video'; | |
break; | |
case "zip": | |
$icon_type = 'zip'; | |
break; | |
case "xls": | |
case "xla": | |
case "xlb": | |
case "xlc": | |
case "xld": | |
case "xlk": | |
case "xll": | |
case "xlm": | |
case "xlt": | |
case "xlv": | |
case "xlw": | |
$icon_type = 'spreadsheet'; | |
break; | |
case "doc": | |
$icon_type = 'word-doc'; | |
break; | |
case "docx": | |
$icon_type = 'open-doc'; | |
break; | |
case "unknown": | |
$icon_type = 'default'; | |
break; | |
default: | |
$icon_type = 'default'; | |
} | |
return $icon_type; | |
} | |
function get_link_dashicon($link_url) { | |
$link_type = get_link_type($link_url); | |
switch ($link_type) | |
{ | |
case "web": | |
$icon = 'dashicons-admin-links'; | |
break; | |
case "pdf": | |
$icon = 'dashicons-media-document'; | |
break; | |
case "jpg": | |
case "png": | |
case "gif": | |
case "jpeg": | |
case "tif": | |
$icon = 'dashicons-format-image'; | |
break; | |
case "pptx": | |
case "pptm": | |
case "ppt": | |
case "pot": | |
case "potx": | |
case "potm": | |
$icon = 'dashicons-media-interactive'; | |
break; | |
case "wav": | |
case "mp3": | |
$icon = 'dashicons-controls-volumeon'; | |
break; | |
case "mp4": | |
case "avi": | |
case "flv": | |
case "mov": | |
case "mpg": | |
case "rm": | |
case "swf": | |
case "wmv": | |
$icon = 'dashicons-format-video'; | |
break; | |
case "zip": | |
$icon = 'dashicons-media-archive'; | |
break; | |
case "xls": | |
case "xla": | |
case "xlb": | |
case "xlc": | |
case "xld": | |
case "xlk": | |
case "xll": | |
case "xlm": | |
case "xlt": | |
case "xlv": | |
case "xlw": | |
$icon = 'dashicons-media-spreadsheet'; | |
break; | |
case "doc": | |
$icon = 'dashicons-media-text'; | |
break; | |
case "docx": | |
$icon = 'dashicons-media-text'; | |
break; | |
default: | |
$icon = 'dashicons-admin-links'; | |
} | |
return $icon; | |
} | |
function the_hr_link_dashicon($link_url) { | |
echo get_hr_link_dashicon($link_url); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load stylesheets, and load dashicons as a dependency | |
function hr_load_your_css(){ | |
if(!is_admin()){ | |
$css_link = get_stylesheet_directory_uri() . '/assets/css/style.min.css'; | |
$css_file = get_stylesheet_directory() . '/assets/css/style.min.css'; | |
wp_enqueue_style('theme-style', $css_link, array('dashicons'), filemtime($css_file), 'all'); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'hr_load_your_css'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="<?php echo esc_url( $resource_link ); ?>"><i class="dashicons <?php the_hr_link_dashicon($resource_link); ?>"></i> View document</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment