Last active
May 16, 2019 14:47
-
-
Save ThatGuySam/554ee89b571d7c5aa1ae 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 | |
class Boxes { | |
static $add_script; | |
static function init() { | |
add_shortcode('boxes', array(__CLASS__, 'handle_shortcode')); | |
add_action('init', array(__CLASS__, 'register_script')); | |
add_action('wp_footer', array(__CLASS__, 'print_script')); | |
add_action('wp_footer', array(__CLASS__, 'internal_script') ); | |
} | |
static function handle_shortcode($raw_atts) { | |
self::$add_script = true; | |
$atts = shortcode_atts( array( | |
'header' => false, | |
'type' => false, | |
'source' => false, | |
'class' => false, | |
'amount' => 8, | |
'show' => 3, | |
), $raw_atts, 'boxes' ); | |
$atts['boxes'] = new stdClass(); | |
$atts['boxes']->cache = new stdClass(); | |
$atts['boxes']->objects = false; | |
$atts['boxes']->site_url = site_url(); | |
$atts['boxes']->links_type = "normal"; | |
global $post; | |
$atts['boxes']->post = $post; | |
foreach ($atts as $key => $value) {$atts['boxes']->{$key} = $value; }//Convert Shortcode attributes to object values | |
$parsed_classes = explode(' ', $atts['class']); | |
$props = array(); | |
foreach( $parsed_classes as $prop ) { | |
$props[$prop] = true; | |
} | |
$atts['boxes']->props = $props; | |
//Feed Type | |
switch ($atts['boxes']) { | |
case "instagram": | |
//Get Instagram Pictures | |
$atts['boxes']->objects = boxesInstagram($atts['boxes']); | |
$target = "_blank"; | |
break; | |
case "vimeo": | |
//Get Vimeo Videos | |
$vid_url = parse_url($atts['boxes']->source); | |
$atts['boxes']->source = $vid_url['path']; | |
$atts['boxes']->id = preg_replace('/[^\da-z]/i', '', $vid_url['path'] ); | |
$atts['boxes']->cache->function_name = "boxesVimeo"; | |
$atts['boxes']->cache->cache_name = "vimeo"; | |
$atts['boxes']->objects = cacheHandler( $atts['boxes'] ); | |
if( $atts['boxes']->post->post_name == "watch" ) { | |
$atts['boxes']->links_type = "hash"; | |
} | |
$target = "_self"; | |
break; | |
case "events": | |
//Get Timely Events | |
$atts['boxes']->id = $atts['source']; | |
$atts['boxes']->cache->function_name = "boxesEvents"; | |
$atts['boxes']->cache->cache_name = "events"; | |
$atts['boxes']->objects = cacheHandler( $atts['boxes'] ); | |
break; | |
case "category": | |
echo $atts['source']; | |
break; | |
case "youtube": | |
echo $atts['source']; | |
break; | |
case "acf": | |
echo $atts['source']; | |
break; | |
default: | |
echo "Nothing here"; | |
} | |
ob_start(); | |
?> | |
<?php | |
if( isset( $props['double-stacked'] ) ){ | |
$atts['boxes']->show = $atts['boxes']->show * 2; | |
} | |
//debug( $atts['boxes']->post ); | |
?> | |
<div id="boxes-<?php echo $atts['boxes']; ?>-<?php echo $atts['boxes']->id; ?>" class="box-boxes boxes-<?php echo $atts['type']; ?> <?php echo $atts['class']; ?>"> | |
<?php if( !empty( $atts['boxes']->header ) ): ?> | |
<div class="boxes-header"> | |
<h3 class="spaced"><?php echo $atts['boxes']->header; ?></h3> | |
<hr> | |
</div> | |
<?php endif; ?> | |
<div class="frame" data-show="<?php echo $atts['boxes']->show; ?>"> | |
<ul class="easecubic"> | |
<?php if( $atts['boxes']->objects ): foreach($atts['boxes']->objects as $key => $box){ ?> | |
<?php | |
if( isset( $props['date-format-human'] ) ){ | |
$normal_date = strtotime( $box->date ); | |
if( strtotime( $box->title ) ) $normal_date = strtotime( $box->title ); | |
$box->title = ago( $normal_date ); | |
} | |
//Hash Links | |
if( $atts['boxes']->links_type == "hash" ){ | |
$box->link = "#".$box->id; | |
} | |
$box->srcType = 'src="'.get_template_directory_uri().'/assets/img/blank.gif" data-lazy'; | |
//if( $key < $atts['boxes']->show ) $box->srcType = "src";//if is showing don't lazyload | |
?> | |
<?php if( !isset( $props['double-stacked'] ) || $box->index % 2 != 0 || !$box->index ){ ?><li><?php } ?> | |
<div id="box-<?php echo $atts['boxes']; ?>-<?php echo $box->id; ?>" class="box-box box-<?php echo $box->type; ?> easecubic" style="<?php | |
//BG Color Overlay | |
if( isset( $box->color ) ): | |
?>background: <?php echo $box->color; ?>; <?php //#000000 | |
endif; ?>"> | |
<a href="<?php echo $box->link; ?>" target="<?php echo $target; ?>" > | |
<div class="box-image"> | |
<img class="easecubic" <?php echo $box->srcType; ?>="<?php echo $box->image_url; ?>" alt="<?php echo $box->title." - ".$box->date; ?>" > | |
</div> | |
<div class="box-header easecubic" style=""> | |
<div class="box-header-content"> | |
<h3><?php echo parse_title( $box->title ); ?></h3> | |
<div class="box-date easecubic"><?php echo $box->date; ?></div> | |
</div> | |
</div> | |
<div class="box-caption easecubic"><p><?php echo parse_title( $box->desc ); ?></p></div> | |
</a> | |
</div> | |
<?php if( !isset( $props['double-stacked'] ) || $box->index % 2 == 0 || !$box->index ){ ?></li><?php } ?> | |
<?php } endif; ?> | |
</ul> | |
</div> | |
</div> | |
<?php | |
$content = ob_get_clean(); | |
debug( $debug ); | |
return $content; | |
} | |
static function register_script() { | |
//wp_register_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(), '4.1.0', 'screen' ); | |
//wp_register_script('imagesloaded', '//cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.0.4/jquery.imagesloaded.js', array('jquery'), '3.0.4', true); | |
} | |
static function print_script() { | |
if ( ! self::$add_script ) | |
return; | |
//wp_print_styles('font-awesome'); | |
//wp_print_scripts('imagesloaded'); | |
} | |
static function internal_script() { | |
if ( ! self::$add_script ) | |
return; | |
?> | |
<script type="text/javascript"> | |
if ( undefined !== window.jQuery ) { jQuery(function ($) { 'use strict'; | |
//Javascript goes here | |
}); } | |
</script> | |
<style> | |
/* CSS Goes Here */ | |
</style> | |
<?php | |
} | |
} | |
Boxes::init(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment