Created
November 15, 2011 04:59
-
-
Save ericpedia/1366198 to your computer and use it in GitHub Desktop.
fig shortcode 2011-11-14
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 | |
/**************************************************** | |
Figures and Tables - [fig] and [figwrapper][/figwrapper] | |
****************************************************/ | |
function my_FiguresTablesCharts_shortcode ( $atts, $content=null ) { | |
extract( shortcode_atts( array( | |
'label' => null, | |
'url' => null, | |
'style' => null, | |
'width' => null, | |
'hidelabel' => null, | |
'inline' => null, | |
), $atts ) ); | |
$view = $_GET["view"]; | |
$this_is_inline = null; | |
$this_is_inline = ( $content && strpos( $content, '<table' ) ) ? 'fig-inline' : null ; | |
$this_is_an_image = null; | |
// Check if there is a URL present | |
// (We can't use if (strpos( $url, 'http' )) because it returns 0, which evaluates to false) | |
$this_is_an_image = ($url && strpos( $url, 'ttp') ) ? 'fig-image' : null; | |
// $this_is_an_image = ($url && strpos( $url, 'ttp') && ( strlen($content) <= 3 ) ) ? 'fig-image' : null; | |
if ( $this_is_an_image || $this_is_inline ) { | |
// Set the image size and CSS class | |
if ( $width == 'half' ) { | |
$w = '360'; | |
$c = ' halfright'; | |
} else { | |
$w = ($label && $hidelabel != 'true') ? '588' : '608'; | |
if ( get_post_type() == 'blog' ) { | |
$w = '536'; | |
} | |
$c = ''; | |
} | |
// If it has a label, wrap it in a border | |
if ( $label && !$hidelabel ) { | |
$before = '<div class="clearfix figure'. $c .'"><div class="figurelabel bg-gradient">' . $label . '</div>'; | |
$after = '<div class="bg-gradient fig-after"></div></div>'; | |
} else { | |
$before = null; | |
$after = null; | |
} | |
// Set up the figure tag | |
if ( $this_is_inline ) { | |
$figure = $before; | |
$figure .= $content; | |
$figure .= $after; | |
} else { | |
if ( $view == "print" ) { | |
$figure = $before; | |
$figure .= '<img src="' . $url . '" alt="' . $label . '">'; | |
$figure .= $after; | |
} else { | |
$figure = $before; | |
$figure .= '<img src="' . get_site_url() . '/m/?src=' . $url . '&w=' . $w . '" alt="' . $label . '">'; | |
$figure .= $after; | |
} | |
} | |
// If there's no figure URL and no wrapped content, return nothing | |
} else { | |
$figure = null; | |
} | |
return $figure; | |
} | |
add_shortcode( 'fig', 'my_FiguresTablesCharts_shortcode' ); | |
add_shortcode( 'figwrapper', 'my_FiguresTablesCharts_shortcode' ); | |
// ob_start(); | |
// return ob_get_clean(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment