Skip to content

Instantly share code, notes, and snippets.

@p-drolima
Created February 5, 2016 11:35
Show Gist options
  • Save p-drolima/0b311e195694271aabb3 to your computer and use it in GitHub Desktop.
Save p-drolima/0b311e195694271aabb3 to your computer and use it in GitHub Desktop.
<?php
/*
Name: Heroic Hollywood
Author: Pedro Lima
Description: heroichollywood.com
Version: 1.0
Class: heroic
*/
class heroic extends thesis_skin {
/*
Skin API $functionality array. Enable or disable certain Skin features with ease.
— (documentation link needed)
*/
public $functionality = array(
'css_preprocessor' => 'scss',
'editor_grt' => true,
'fonts_google' => true,
'header_image' => true);
/*
Skin API pseudo-constructor; place hooks, filters, and other initializations here.
— http://diythemes.com/thesis/rtfm/api/skin/#section-construct
*/
protected function construct() {
// hooks and filter magic
add_action('wp_enqueue_scripts', array($this, 'scripts_enqueue'));
add_action( 'after_setup_theme', array($this, 'wpdocs_theme_setup'));
add_action('hook_top_logo', array($this, 'add_logo'));
add_action('hook_top_carrousel', array($this, 'add_carrousel'));
add_action('hook_top_hero_filters', array($this, 'add_hero_filters'));
add_action('hook_top_ticker', array($this, 'add_ticker'));
add_action('hook_top_follow', array($this, 'add_follow'));
add_action('hook_top_newsletter', array($this, 'add_newsletter'));
add_action('hook_top_popular_stories', array($this, 'add_popular_stories'));
add_action('hook_top_recent_stories', array($this, 'add_recent_stories'));
// implement display options that do not follow the normal pattern
if (!empty($this->display['misc']['display']['braces'])) {
add_filter('thesis_post_num_comments', array($this, 'num_comments'));
add_filter('thesis_comments_intro', array($this, 'comments_intro'));
}
// the previous/next links (found on home, archive, and single templates) require special filtering based on page context
add_filter('thesis_html_container_prev_next_show', array($this, 'prev_next'));
// hook header image into the proper location for this Skin
add_action('hook_bottom_header', array($this, 'header_image'));
}
// Custom functions
function scripts_enqueue() {
if(is_front_page()){
wp_enqueue_style('ticker', '/wp-content/thesis/skins/heroic/css/ticker-style.css');
wp_enqueue_style('font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css');
wp_enqueue_script('flexslider', '/wp-content/thesis/skins/heroic/js/flexslider.min.js', array('jquery'), false);
wp_enqueue_script('isotope', 'https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.js', array('jquery'), false);
wp_enqueue_script('imagesLoaded', 'https://npmcdn.com/imagesloaded@4.1/imagesloaded.pkgd.js', array('jquery'), false);
wp_enqueue_script('ticker', '/wp-content/thesis/skins/heroic/js/jquery.ticker.js', array('jquery'), false);
wp_enqueue_script('custom', '/wp-content/thesis/skins/heroic/js/custom.js', array('jquery', 'flexslider'), false);
}
}
function wpdocs_theme_setup() {
add_image_size( 'carrousel-thumb', 320, 252, true );
add_image_size( 'iso-thumb', 314, 167, true );
}
function add_logo() { ?>
<img src="wp-content/thesis/skins/heroic/images/logo.png" alt="logo">
<?php }
function add_carrousel() {
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'post_per_page' => 10
);
$carrousel_query = new WP_Query($args);
if($carrousel_query->have_posts()) { ?>
<div class="carrousel">
<div class="custom-navigation">
<a href="#" class="flex-prev fa fa-angle-left"></a>
<a href="#" class="flex-next fa fa-angle-right"></a>
</div>
<ul class="slides">
<?php while($carrousel_query->have_posts()) {
$carrousel_query->the_post();
$date = get_the_date( $carrousel_query->ID ); ?>
<li>
<?php if(has_post_thumbnail($carrousel_query->ID)) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id($carrousel_query->ID), 'carrousel-thumb'); ?>
<div class="carrousel-img">
<img src="<?php echo $image[0]; ?>" />
</div>
<div class="carrousel-title"><?php the_title(); ?>
<div class="carrousel-byline"><span><i class="fa fa-clock-o"></i></span><?php echo $date; ?></div>
</div>
<?php } ?>
</li>
<?php
} ?>
</ul>
</div>
<?php wp_reset_postdata(); ?>
<script>
// Can also be used with $(document).ready()
jQuery(window).load(function() {
jQuery('.carrousel').flexslider({
animation: "slide",
animationLoop: false,
itemWidth: 320,
itemMargin: 5,
minItems: 3,
maxItems: 3,
customDirectionNav: jQuery(".custom-navigation a"),
controlNav: false
});
jQuery(".custom-navigation").prependTo(".flex-viewport");
});
</script>
<?php }
}
function add_hero_filters() { ?>
<div id="iso-filter">
<ul id="filters" class="filter designer-filter">
<?php $terms = get_terms('category'); ?>
<li><a href="#" class="category_filter">All</a></li>
<?php
if ($terms) {
foreach($terms as $term ) { ?>
<li><a href="#<?php echo $term->slug; ?>" class="category_filter"><?php echo $term->name; ?></a></li>
<?php }
} else {
echo "error!!!";
}?>
</ul>
</div>
<div class="designer-grid isotope" id="isodesigner">
<?php
global $post;
$port_args = array(
'post_type' => 'post',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page'=> -1,
'taxonomy' => 'category'
);
$get_hero_posts = new WP_Query($port_args);
while($get_hero_posts->have_posts()) {
$get_hero_posts->the_post();
$terms = get_the_terms( $post->ID, 'category' );
if ( $terms && ! is_wp_error( $terms ) ) {
$links = array();
foreach ( $terms as $term ) {
$links[] = $term->slug;
}
$tax_links = join( " ", str_replace(' ', '-', $links));
$tax = strtolower($tax_links);
}
else {
$tax = '';
}
if (strlen(the_title('','',FALSE)) > 34) { //Character length
$title_short = substr(the_title('','',FALSE), 0, 34); // Character length
preg_match('/^(.*)\s/s', $title_short, $matches);
if ($matches[1]) $title_short = $matches[1];
$title_short = $title_short.' ...'; // Ellipsis
} else {
$title_short = the_title('','',FALSE);
}
/* Insert category name into hero-item class */
echo '<div class="all hero-item '. $tax .' isotope-item">';
echo '<div class="port-pad">';
if(has_post_thumbnail($post->ID)) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'iso-thumb'); ?>
<a class="thumb-link" href="<?php the_permalink();?>"><img src="<?php echo $image[0]; ?>" alt"" /></a>
<h2><a href="<?php the_permalink(); ?>"><?php echo $title_short; ?></a></h2>
<?php }
echo '</div>';
echo '</div>';
} ?>
</div>
<script type="text/javascript">
jQuery(document).ready(function(){
//ISOTOPE FILTERING
// cache container
var $container = jQuery('#isodesigner');
// initiaze imagesLoaded
$container.imagesLoaded( function(){
// initialize isotope
$container.isotope({
resizable: false,
masonry: { columnWidth: $container.width() / 2 }
});
});
/*jQuery(window).smartresize(function(){
$container.isotope({
// update columnWidth to a percentage of container width
masonry: { columnWidth: $container.width() / 3 }
});
});*/
// filter items when filter link is clicked
jQuery('.category_filter').click(function(event){
event.preventDefault();
if ( !jQuery(this).hasClass('selected') ) {
changeItemHighlight(jQuery(this));
var selector = jQuery(this).attr('href').split('#')[1];
if(selector === "all") {
selector = "";
}
var isoSelector = selector ? "."+selector : "";
//if($(this).find(".extraFilters").text()) {
// isoSelector = isoSelector + $(this).find(".extraFilters").text();
//}
$container.isotope({ filter: isoSelector });
if(window.history) {
history.pushState(null, null, "?filter="+selector);
}
//window.location.hash = selector;
}
return false;
});
var changeItemHighlight = function(node) {
var $optionSet = node.parents('.designer-filter');
$optionSet.find('.selected').removeClass('selected');
node.addClass('selected');
};
var checkForFilterOnPageLoad = function() {
var pageFilter = String(window.location);
if(pageFilter.indexOf("?filter=") !== -1) {
var filter = pageFilter.split("?filter=");
jQuery(".category_filter[href$='"+filter[1]+"']").click();
}
};
checkForFilterOnPageLoad();
});
</script>
<?php }
function add_ticker() {
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'post_per_page' => 10
);
$ticker_query = new WP_Query($args);
if ($ticker_query->have_posts()) { ?>
<ul id="ticker">
<?php while ($ticker_query->have_posts()) {
$ticker_query->the_post(); ?>
<li class="ticker-item">
<a href="#"><?php the_title(); ?></a>
</li>
<?php
}
wp_reset_postdata(); ?>
</ul>
<script type="text/javascript">
jQuery(function () {
jQuery('#ticker').ticker({
speed: 0.10,
controls: false,
titleText: 'Trending:',
displayType: 'fade'
}
);
});
</script>
<?php }
}
function add_adbox_top() {
}
function add_adbox_bottom() {
}
// Sidebar functions
function add_follow() { ?>
<p class="sidebar-title">Follow Us</p>
<div class="widget-wrapper">
<ul class="social-follow">
<li><a href=""><i class="fa fa-twitter"></i></a></li>
<li><a href=""><i class="fa fa-facebook"></i></a></li>
<li><a href=""><i class="fa fa-youtube-play"></i></a></li>
<li><a href=""><i class="fa fa-rss"></i></a></li>
<li><a href=""><i class="fa fa-instagram"></i></a></li>
</ul>
</div>
<?php }
function add_newsletter() { ?>
<p class="sidebar-title">Newsletter</p>
<div class="widget-wrapper">
<div id="mc_embed_signup">
<form action="//heroichollywood.us10.list-manage.com/subscribe/post?u=85665576759006ec6cbaf044b&amp;id=365dbacbaf" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<div class="mc-field-group">
<input type="email" placeholder="Your Email Address" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div> <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
<div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_85665576759006ec6cbaf044b_365dbacbaf" tabindex="-1" value=""></div>
<div class="clear"><input type="submit" value="Sign Up" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
</div>
</form>
</div>
<!--End mc_embed_signup-->
</div>
<?php }
function add_adbox_sidebar_1() {
}
function add_popular_stories() { ?>
<p class="sidebar-title">Popular Stories</p>
<?php }
function add_adbox_sidebar_2() {
}
function add_recent_stories() { ?>
<p class="sidebar-title">Recent Stories</p>
<?php }
/*---:[ Implement non-standard display options ]:---*/
/*
The following is a special filter to prevent the prev/next container from showing if the query only has 1 page of results.
*/
public function prev_next() {
global $wp_query;
return (($wp_query->is_home || $wp_query->is_archive || $wp_query->is_search) && $wp_query->max_num_pages > 1) || ($wp_query->is_single && !empty($this->display['misc']['display']['prev_next'])) ? true : false;
}
public function num_comments($content) {
return "<span class=\"bracket\">{</span> $content <span class=\"bracket\">}</span>";
}
public function comments_intro($text) {
return "<span class=\"bracket\">{</span> $text <span class=\"bracket\">}</span>";
}
/*---:[ Implement a user-added Header Image ]:---*/
/*
Output user header image by referencing the Skin API header image object and its associated html() method.
— (documentation link needed)
*/
public function header_image() {
$this->header_image->html();
}
/*
Skin API method for filtering the CSS output whenever the stylesheet is rewritten.
In this case, we are adding some CSS if the user has selected a header image.
— http://diythemes.com/thesis/rtfm/api/skin/#section-filter-css
*/
public function filter_css($css) {
return $css. (!empty($this->header_image->image) ?
"\n#header {\n".
"\tpadding: 0;\n".
"}\n".
"#header #site_title a, #header #site_tagline {\n".
"\tdisplay: none;\n".
"}\n" : '');
}
/*---:[ Skin Display Options ]:---*/
/*
Skin API method for initiating display options; return an array in Thesis Options API array format.
— Display options: http://diythemes.com/thesis/rtfm/api/skin/#section-display
— Options API array format: http://diythemes.com/thesis/rtfm/api/options/array-format/
*/
protected function display() {
return array( // use an options object set for simplified display controls
'display' => array(
'type' => 'object_set',
'select' => __('Select content to display:', 'thesis_heroic'),
'objects' => array(
'site' => array(
'type' => 'object',
'label' => __('Site Title &amp; Tagline', 'thesis_heroic'),
'fields' => array(
'display' => array(
'type' => 'checkbox',
'options' => array(
'title' => __('Site title', 'thesis_heroic'),
'tagline' => __('Site tagline', 'thesis_heroic')),
'default' => array(
'title' => true,
'tagline' => true)))),
'loop' => array(
'type' => 'object',
'label' => __('Post/Page Output', 'thesis_heroic'),
'fields' => array(
'display' => array(
'type' => 'checkbox',
'options' => array(
'author' => __('Author', 'thesis_heroic'),
'avatar' => __('Author avatar', 'thesis_heroic'),
'description' => __('Author description (Single template)', 'thesis_heroic'),
'date' => __('Date', 'thesis_heroic'),
'wp_featured_image' => __('WP featured image', 'thesis_heroic'),
'image' => __('Thesis post image (Single, Page, and Landing Page templates)', 'thesis_heroic'),
'thumbnail' => __('Thesis thumbnail image (Home template)', 'thesis_heroic'),
'num_comments' => __('Number of comments (Home and Archive templates)', 'thesis_heroic'),
'cats' => __('Categories', 'thesis_heroic'),
'tags' => __('Tags', 'thesis_heroic')),
'default' => array(
'author' => true,
'date' => true,
'wp_featured_image' => true,
'num_comments' => true)))),
'comments' => array(
'type' => 'object',
'label' => __('Comments', 'thesis_heroic'),
'fields' => array(
'display' => array(
'type' => 'checkbox',
'options' => array(
'post' => __('Comments on posts', 'thesis_heroic'),
'page' => __('Comments on pages', 'thesis_heroic'),
'date' => __('Comment date', 'thesis_heroic'),
'avatar' => __('Comment avatar', 'thesis_heroic')),
'default' => array(
'post' => true,
'date' => true,
'avatar' => true)))),
'sidebar' => array(
'type' => 'object',
'label' => __('Sidebar', 'thesis_heroic'),
'fields' => array(
'display' => array(
'type' => 'checkbox',
'options' => array(
'sidebar' => __('Sidebar', 'thesis_heroic'),
'text' => __('Sidebar Text Box', 'thesis_heroic'),
'widgets' => __('Sidebar Widgets', 'thesis_heroic')),
'default' => array(
'sidebar' => true,
'text' => true,
'widgets' => true)))),
'misc' => array(
'type' => 'object',
'label' => __('Miscellaneous', 'thesis_heroic'),
'fields' => array(
'display' => array(
'type' => 'checkbox',
'options' => array(
'braces' => __('Iconic Classic Responsive Skin curly braces', 'thesis_heroic'),
'prev_next' => __('Previous/next post links (single template)', 'thesis_heroic'),
'attribution' => __('Skin attribution', 'thesis_heroic'),
'wp_admin' => __('WP admin link', 'thesis_heroic')),
'default' => array(
'braces' => true,
'prev_next' => true,
'attribution' => true,
'wp_admin' => true)))))));
}
/*
Skin API method for automatic show/hide handling of elements with display options.
Display options are defined in the display() method below.
— (documentation link needed)
*/
public function display_elements() {
return array( // Display options with filter references
'site' => array(
'title' => 'thesis_site_title',
'tagline' => 'thesis_site_tagline'),
'loop' => array( // 'loop' has been added as a programmatic ID to these Boxes
'author' => 'thesis_post_author_loop',
'avatar' => 'thesis_post_author_avatar_loop',
'description' => 'thesis_post_author_description_loop',
'date' => 'thesis_post_date_loop',
'wp_featured_image' => 'thesis_wp_featured_image_loop',
'cats' => 'thesis_post_categories_loop',
'tags' => 'thesis_post_tags_loop',
'num_comments' => 'thesis_post_num_comments_loop',
'image' => 'thesis_post_image_loop',
'thumbnail' => 'thesis_post_thumbnail_loop'),
'comments' => array( // 'comments' has been added as a programmatic ID to the date and avatar Boxes
'post' => 'thesis_html_container_post_comments',
'page' => 'thesis_html_container_page_comments',
'date' => 'thesis_comment_date_comments',
'avatar' => 'thesis_comment_avatar_comments'),
'sidebar' => array( // 'sidebar' is the hook name for 'sidebar' and the programmatic ID for text and widgets
'sidebar' => 'thesis_html_container_sidebar',
'text' => 'thesis_text_box_sidebar',
'widgets' => 'thesis_wp_widgets_sidebar'),
'misc' => array(
'attribution' => 'thesis_attribution',
'wp_admin' => 'thesis_wp_admin'));
}
/*---:[ Skin Design Options ]:---*/
/*
Skin API method for initiating design options; return an array in Thesis Options API array format.
— Design options: http://diythemes.com/thesis/rtfm/api/skin/#section-design
— Options API array format: http://diythemes.com/thesis/rtfm/api/options/array-format/
*/
protected function design() {
$css = $this->css_tools->options; // shorthand for all options available in the CSS API
$fsc = $nav = $this->css_tools->font_size_color(); // the CSS API contains shorthand for font, size, and color options
unset($nav['color']); // remove nav text color control
$links['default'] = 'DD0000'; // default link color
$links['gray'] = $this->color->gray($links['default']); // array of 'hex' and 'rgb' values
return array(
'colors' => $this->color_scheme(array( // the Skin API contains a color_scheme() method for easy implementation
'id' => 'colors',
'colors' => array(
'text1' => __('Primary Text', 'thesis_heroic'),
'text2' => __('Secondary Text', 'thesis_heroic'),
'links' => __('Links', 'thesis_heroic'),
'color1' => __('Borders &amp; Highlights', 'thesis_heroic'),
'color2' => __('Interior <abbr title="background">BG</abbr>s', 'thesis_heroic'),
'color3' => __('Site <abbr title="background">BG</abbr>', 'thesis_heroic')),
'default' => array(
'text1' => '111111',
'text2' => '888888',
'links' => $links['default'],
'color1' => 'DDDDDD',
'color2' => 'EEEEEE',
'color3' => 'FFFFFF'),
'scale' => array(
'links' => $links['gray']['hex'],
'color1' => 'DDDDDD',
'color2' => 'EEEEEE',
'color3' => 'FFFFFF'))),
'elements' => array( // this is an object set containing all other design options for this Skin
'type' => 'object_set',
'label' => __('Layout, Fonts, Sizes, and Colors', 'thesis_heroic'),
'select' => __('Select a design element to edit:', 'thesis_heroic'),
'objects' => array(
'layout' => array(
'type' => 'object',
'label' => __('Layout &amp; Dimensions', 'thesis_heroic'),
'fields' => array(
'columns' => array(
'type' => 'select',
'label' => __('Layout', 'thesis_heroic'),
'options' => array(
1 => __('1 column', 'thesis_heroic'),
2 => __('2 columns', 'thesis_heroic')),
'default' => 2,
'dependents' => array(2)),
'order' => array(
'type' => 'radio',
'options' => array(
'' => __('Content on the left', 'thesis_heroic'),
'right' => __('Content on the right', 'thesis_heroic')),
'parent' => array(
'columns' => 2)),
'width-content' => array(
'type' => 'text',
'width' => 'tiny',
'label' => __('Content Width', 'thesis_heroic'),
'tooltip' => __('The default content column width is 617px. The value you enter here is the entire width of the column, including padding and borders. The resulting width of your text in this column is based on your selected font and font size. We recommend using Chrome Developer Tools or Firebug for Firefox to inspect the text width if you need to achieve a precise value.', 'thesis_heroic'),
'description' => 'px',
'default' => 617),
'width-sidebar' => array(
'type' => 'text',
'width' => 'tiny',
'label' => __('Sidebar Width', 'thesis_heroic'),
'tooltip' => __('The default sidebar column width is 280px. The value you enter here is the entire width of the column, including padding. The resulting width of your text in this column is based on your selected font and font size. We recommend using Chrome Developer Tools or Firebug for Firefox to inspect the text width if you need to achieve a precise value.', 'thesis_heroic'),
'description' => 'px',
'default' => 280,
'parent' => array(
'columns' => 2)))),
'font' => array(
'type' => 'object',
'label' => __('Font &amp; Size (Primary)', 'thesis_heroic'),
'fields' => array(
'family' => array_merge($css['font']['fields']['font-family'], array('default' => 'georgia')),
'size' => array_merge($css['font']['fields']['font-size'], array('default' => 16)))),
'headline' => array(
'type' => 'group',
'label' => __('Headlines', 'thesis_heroic'),
'fields' => $fsc),
'subhead' => array(
'type' => 'group',
'label' => __('Sub-headlines', 'thesis_heroic'),
'fields' => $fsc),
'blockquote' => array(
'type' => 'group',
'label' => __('Blockquotes', 'thesis_heroic'),
'fields' => $fsc),
'code' => array(
'type' => 'group',
'label' => __('Code: Inline &lt;code&gt;', 'thesis_heroic'),
'fields' => $fsc),
'pre' => array(
'type' => 'group',
'label' => __('Code: Pre-formatted &lt;pre&gt;', 'thesis_heroic'),
'fields' => $fsc),
'title' => array(
'type' => 'object',
'label' => __('Site Title', 'thesis_heroic'),
'fields' => $fsc),
'tagline' => array(
'type' => 'group',
'label' => __('Site Tagline', 'thesis_heroic'),
'fields' => $fsc),
'menu' => array(
'type' => 'object',
'label' => __('Nav Menu', 'thesis_heroic'),
'fields' => $nav),
'sidebar' => array(
'type' => 'group',
'label' => __('Sidebar', 'thesis_heroic'),
'fields' => $fsc),
'sidebar_heading' => array(
'type' => 'group',
'label' => __('Sidebar Headings', 'thesis_heroic'),
'fields' => $fsc))));
}
/*
Skin API method for modifying CSS variables each time CSS is saved.
Return an array of CSS variables, including units (if necessary), with their new values.
Any variables not included in the return array will not be modified.
— http://diythemes.com/thesis/rtfm/api/skin/#section-variables
*/
public function css_variables() {
global $thesis;
$columns = !empty($this->design['layout']['columns']) && is_numeric($this->design['layout']['columns']) ?
$this->design['layout']['columns'] : 2;
$order = !empty($this->design['layout']['order']) && $this->design['layout']['order'] == 'right' ? true : false;
$px['w_content'] = !empty($this->design['layout']['width-content']) && is_numeric($this->design['layout']['width-content']) ?
abs($this->design['layout']['width-content']) : 617;
$px['w_sidebar'] = !empty($this->design['layout']['width-sidebar']) && is_numeric($this->design['layout']['width-sidebar']) ?
abs($this->design['layout']['width-sidebar']) : 280;
$px['w_total'] = $px['w_content'] + ($columns == 2 ? $px['w_sidebar'] : 0);
$vars['font'] = $this->fonts->family($font = !empty($this->design['font']['family']) ? $this->design['font']['family'] : 'georgia');
$s['content'] = !empty($this->design['font']['size']) ? $this->design['font']['size'] : 16;
// Determine typographical scale based on primary font size
$f['content'] = $this->typography->scale($s['content']);
/*
The final line height, $h['content'], is calculated in 3 iterations:
1. Get the optimal line height for the current font and size
2. Get an adjusted line height using optimal spacing for the current font and size
3. Adjust the line height a final time with adjusted spacing for the current font and size
Both the line height, $h['content'], and layout spacing, $x['content'], are calculated below:
*/
$x['content'] = $this->typography->space($h['content'] = $this->typography->height($s['content'], ($w['content'] = $px['w_content'] - ($adjust = round(2 * $this->typography->height($s['content'], $px['w_content'] - ($first = round(2 * $this->typography->height($s['content'], false, $font), 0)) - 1, $font), 0)) - 1), $font));
// Determine sidebar font, size, typographical scale, and spacing
$sidebar_font = !empty($this->design['sidebar']['font']) ? $this->design['sidebar']['font'] : $font;
$s['sidebar'] = !empty($this->design['sidebar']['font-size']) && is_numeric($this->design['sidebar']['font-size']) ?
$this->design['sidebar']['font-size'] : $f['content']['f6'];
$f['sidebar'] = $this->typography->scale($s['sidebar']);
$x['sidebar'] = $this->typography->space($h['sidebar'] = $this->typography->height($s['sidebar'], ($w['sidebar'] = $px['w_sidebar'] - 2 * $x['content']['x1']), $sidebar_font));
// Set up an array containing numerical values that require a unit for CSS output
$px['f_text'] = $f['content']['f5'];
$px['f_aux'] = $f['content']['f6'];
$px['f_subhead'] = $f['content']['f4'];
$px['h_text'] = round($h['content'], 0);
$px['h_aux'] = round($this->typography->height($f['content']['f6'], $w['content'], $font), 0);
foreach ($x['content'] as $dim => $value)
$px["x_$dim"] = $value;
foreach ($x['sidebar'] as $dim => $value)
$px["s_x_$dim"] = $value;
// Add the 'px' unit to the $px array constructed above
$vars = is_array($px) ? array_merge($vars, $this->css_tools->unit($px)) : $vars;
// Use the Colors API to set up proper CSS color references
foreach (array('text1', 'text2', 'links', 'color1', 'color2', 'color3') as $color)
$vars[$color] = !empty($this->design[$color]) ? $this->color->css($this->design[$color]) : false;
// Set up a modification array for individual typograhical overrides
$elements = array(
'menu' => array(
'font-family' => false,
'font-size' => $f['content']['f6']),
'title' => array(
'font-family' => false,
'font-size' => $f['content']['f1']),
'tagline' => array(
'font-family' => false,
'font-size' => $f['content']['f5'],
'color' => !empty($vars['text2']) ? $vars['text2'] : false),
'headline' => array(
'font-family' => false,
'font-size' => $f['content']['f3']),
'subhead' => array(
'font-family' => false,
'font-size' => $f['content']['f4']),
'blockquote' => array(
'font-family' => false,
'font-size' => false,
'color' => !empty($vars['text2']) ? $vars['text2'] : false),
'code' => array(
'font-family' => 'consolas',
'font-size' => false,
'color' => false),
'pre' => array(
'font-family' => 'consolas',
'font-size' => false,
'color' => false),
'sidebar' => array(
'font-family' => false,
'font-size' => $f['sidebar']['f5'],
'color' => false),
'sidebar_heading' => array(
'font-family' => false,
'font-size' => $f['sidebar']['f3'],
'color' => false));
// Loop through the modification array to see if any fonts, sizes, or colors need to be overridden
foreach ($elements as $name => $element) {
foreach ($element as $p => $def)
$e[$name][$p] = $p == 'font-family' ?
(!empty($this->design[$name][$p]) ?
"$p: ". $this->fonts->family($family[$name] = $this->design[$name][$p]). ';' : (!empty($def) ?
"$p: ". $this->fonts->family($family[$name] = $def). ';' : false)) : ($p == 'font-size' ?
(!empty($this->design[$name][$p]) && is_numeric($this->design[$name][$p]) ?
"$p: ". ($size[$name] = $this->design[$name][$p]). "px;" : (!empty($def) ?
"$p: ". ($size[$name] = $def). "px;" : false)) : ($p == 'color' ?
(!empty($this->design[$name][$p]) ?
"$p: ". $this->color->css($this->design[$name][$p]). ';' : (!empty($def) ?
"$p: $def;" : false)) : false));
$e[$name] = array_filter($e[$name]);
}
foreach (array_filter($e) as $name => $element)
$vars[$name] = implode("\n\t", $element);
// Override content elements
foreach (array('headline', 'subhead', 'blockquote', 'pre') as $name)
if (!empty($size[$name]))
$vars[$name] .= "\n\tline-height: ". ($line[$name] = round($this->typography->height($size[$name], $w['content'], !empty($family[$name]) ? $family[$name] : $font), 0)). "px;";
// Override sidebar elements
foreach (array('sidebar', 'sidebar_heading') as $name)
if (!empty($size[$name]))
$vars[$name] .= "\n\tline-height: ". round($this->typography->height($size[$name], $w['sidebar'], !empty($family[$name]) ? $family[$name] : $sidebar_font), 0). "px;";
// Determine multi-use color variables
foreach (array('title', 'headline', 'subhead') as $name)
$vars["{$name}_color"] = !empty($this->design[$name]['color']) ?
$this->color->css($this->design[$name]['color']) : (!empty($vars['text1']) ? $vars['text1'] : false);
// Set up property-value variables, which, unlike the other variables above, contain more than just a CSS value
$vars['column1'] =
"float: ". ($columns == 2 ? ($order ? 'right' : 'left') : 'none'). ";\n\t".
"border-width: ". ($columns == 2 ? ($order ? '0 0 0 1px' : '0 1px 0 0') : '0'). ";";
$vars['column2'] =
"width: ". ($columns == 2 ? '$w_sidebar' : '100%'). ";\n\t".
"float: ". ($columns == 2 ? ($order ? 'left' : 'right') : 'none'). ';'. ($columns == 1 ?
"\n\tborder-top: 3px double \$color1;" : '');
$vars['submenu'] = ($w_submenu = ((!empty($size['menu']) ? $size['menu'] : $px['f_aux']) * 14)). "px";
$vars['menu'] .= "\n\tline-height: ". round($this->typography->height((!empty($size['menu']) ? $size['menu'] : $px['f_aux']), $w_submenu, !empty($family['menu']) ? $family['menu'] : $font)). "px;";
$vars['pullquote'] =
"font-size: ". $f['content']['f3']. "px;\n\t".
"line-height: ". round($this->typography->height($f['content']['f3'], round(0.45 * $w['content'], 0), !empty($family['blockquote']) ? $family['blockquote'] : $font), 0). "px;";
$vars['avatar'] =
"width: ". ($avatar = $line['headline'] + $px['h_aux']). "px;\n\t".
"height: {$avatar}px;";
$vars['comment_avatar'] =
"width: ". (2 * $px['h_text']). "px;\n\t".
"height: ". (2 * $px['h_text']). "px;";
foreach (array(2, 3, 4) as $factor)
if (($bio_size = $factor * $px['h_text']) <= 96)
$bio = $bio_size;
$vars['bio_avatar'] =
"width: {$bio}px;\n\t".
"height: {$bio}px;";
return array_filter($vars); // Filter the array to remove any null elements
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment