Created
November 17, 2011 05:37
-
-
Save whyisjake/1372455 to your computer and use it in GitHub Desktop.
kits functions
This file contains hidden or 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 | |
//error_reporting(E_ALL); | |
if ( function_exists( 'wpcom_is_vip' ) && wpcom_is_vip() ) { | |
// Load the WordPress.com dependent helper file | |
wpcom_vip_load_helper_wpcom(); // vip-helper-wpcom.php | |
} else { | |
// These two plugins are automatically loaded on WordPress.com | |
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/vip-do-not-include-on-wpcom/vip-local-development-helper/vip-local-development-helper.php' ); | |
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/vip-do-not-include-on-wpcom/vip-powered-wpcom/vip-powered-wpcom.php' ); | |
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/easy-custom-fields/easy-custom-fields.php' ); | |
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/multiple-post-thumbnails/multi-post-thumbnails.php' ); | |
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/wp-page-numbers/wp-page-numbers.php' ); | |
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/cheezcap/cheezcap.php' ); | |
require_once( WP_CONTENT_DIR . '/themes/vip/plugins/breadcrumb-navxt/breadcrumb-navxt.php' ); | |
} | |
// Load the "works everywhere" helper file | |
wpcom_vip_load_helper(); // vip-helper.php | |
wpcom_vip_load_plugin('easy-custom-fields'); | |
wpcom_vip_load_plugin('multiple-post-thumbnails'); | |
wpcom_vip_load_plugin('wp-page-numbers'); | |
wpcom_vip_load_plugin('cheezcap'); | |
wpcom_vip_load_plugin('breadcrumb-navxt'); | |
require_once( dirname( __FILE__ ) . '/includes/cheezcap-config.php' ); | |
require_once( dirname( __FILE__ ) . '/query-multiple-taxonomies/query-multiple-taxonomies.php' ); | |
function js_option( $option_name ) { | |
global $cap; | |
echo $cap->$option_name; | |
} | |
//This is deprecated. I really love the simplicity tho... | |
function js_excerpt($length){ | |
echo substr(get_the_excerpt(), 0, $length); | |
} | |
//New shorten function. Thanks @ninnypants | |
add_filter( 'get_the_excerpt', 'dont_add_review_to_excerpt', 5); | |
function dont_add_review_to_excerpt( $content ) { | |
remove_filter( 'the_content', 'js_add_review'); | |
return $content; | |
} | |
function custom_excerpt_length(){ | |
global $excerpt_length; | |
return $excerpt_length; | |
} | |
function custom_excerpt_more(){ | |
global $excerpt_more; | |
return $excerpt_more; | |
} | |
function js_truncate_post($length = 55, $more = '[...]',$echo = true){ | |
global $excerpt_length, $excerpt_more; | |
$excerpt_length = (int)$length; | |
$excerpt_more = $more; | |
add_filter('excerpt_length', 'custom_excerpt_length'); | |
add_filter('excerpt_more', 'custom_excerpt_more'); | |
$excerpt = get_the_excerpt(); | |
remove_filter('excerpt_length', 'custom_excerpt_length'); | |
remove_filter('excerpt_more', 'custom_excerpt_more'); | |
if($echo) { | |
echo $excerpt; | |
} | |
else { | |
return $excerpt; | |
} | |
} | |
if ( function_exists('register_sidebar') ) | |
register_sidebar(); | |
if ( function_exists( 'add_theme_support' ) ) { | |
add_theme_support( 'post-thumbnails' ); | |
} | |
if ( function_exists( 'add_image_size' ) ) { | |
add_image_size( 'small-thumb', 56, 56, true ); | |
add_image_size( 'small-another', 40, 40, true ); | |
add_image_size( 'feat-cat-thumb', 263, 117, true ); | |
add_image_size( 'review-large', 560, 9999 ); | |
add_image_size( 'featured-large', 352, 262 ); | |
} | |
if (class_exists('MultiPostThumbnails')) { | |
new MultiPostThumbnails(array( 'label' => 'Secondary Image', 'id' => 'secondary-image', 'post_type' => 'post' )); | |
} | |
function taxes_init() { | |
// create a new taxonomy | |
register_taxonomy( | |
'complexity', | |
'post', | |
array( | |
'label' => __( 'Complexity' ), | |
'sort' => true, | |
'args' => array( 'orderby' => 'term_order' ), | |
'rewrite' => array( 'slug' => 'complexity' ) | |
) | |
); | |
register_taxonomy( | |
'components', | |
'post', | |
array( | |
'label' => __( 'Components' ), | |
'sort' => true, | |
'args' => array( 'orderby' => 'term_order' ), | |
'rewrite' => array( 'slug' => 'components' ) | |
) | |
); | |
register_taxonomy( | |
'documentation', | |
'post', | |
array( | |
'label' => __( 'Documentation' ), | |
'sort' => true, | |
'args' => array( 'orderby' => 'term_order' ), | |
'rewrite' => array( 'slug' => 'documentation' ) | |
) | |
); | |
register_taxonomy( | |
'community', | |
'post', | |
array( | |
'label' => __( 'Community' ), | |
'sort' => true, | |
'args' => array( 'orderby' => 'term_order' ), | |
'rewrite' => array( 'slug' => 'community' ) | |
) | |
); | |
register_taxonomy( | |
'completeness', | |
'post', | |
array( | |
'label' => __( 'Completeness' ), | |
'sort' => true, | |
'args' => array( 'orderby' => 'term_order' ), | |
'rewrite' => array( 'slug' => 'completeness' ) | |
) | |
); | |
register_taxonomy( | |
'maker', | |
'post', | |
array( | |
'label' => __( 'Maker/Company' ), | |
'sort' => true, | |
'args' => array( 'orderby' => 'term_order' ), | |
'rewrite' => array( 'slug' => 'maker' ) | |
) | |
); | |
} | |
add_action( 'init', 'taxes_init' ); | |
function js_terms($terms) { | |
$terms = the_terms($post->ID, $terms); | |
$count = count($terms); | |
if ( $count > 0 ){ | |
foreach ( $terms as $term ) { | |
echo 'term'.$term->name; | |
} | |
} | |
} | |
function js_ratings_box() { | |
global $post; ?> | |
<div id="review_box"> | |
<h3><span class="red">Make:</span> Kit Reviews</h3> | |
<h5><?php echo get_the_term_list( $post->ID, 'maker', '', ', ', '' ); ?></h5> | |
<h2><?php the_title(); ?></h2> | |
<h4> | |
<?php | |
$price = get_post_custom_values('Price'); | |
if (isset($price[0])) { | |
echo $price[0]; | |
} | |
?> | |
</h4> | |
<div class="meta"> | |
<?php | |
$price = get_post_custom_values('CompanyURL'); | |
if (isset($price[0])) { | |
echo '<a href="'; | |
echo esc_url( $price[0] ); | |
echo '" class="btn primary">Company Website</a>'; | |
} | |
?> | |
<?php | |
$price = get_post_custom_values('ProductURL'); | |
if (isset($price[0])) { | |
echo '<a href="'; | |
echo esc_url( $price[0] ); | |
echo '" class="btn danger">Buy now!</a>'; | |
} | |
?> | |
<!--<p><?php the_author_posts_link(); ?></p>--> | |
</div> | |
<dl class="ratings"> | |
<dt><span class="define" rel="popover" data-content="(1=Easy, 5=Difficult) Is the kit easy, moderate, or challenging to build for its most likely target audience? Kits clearly aimed at children would, for example, be rated differently from microcontroller kits." data-original-title="Complexity">Complexity:</span> <?php echo get_the_term_list( $post->ID, 'complexity', '', ', ', '' ); ?></dt> | |
<dd class="<?php $terms_as_text = get_the_term_list( $post->ID, 'complexity', '', ', ', '' ) ; echo 'term'.strip_tags($terms_as_text); ?>"></dd> | |
<dt><span class="define" rel="popover" data-content="(5=Highest quality) How nice are the components in terms of materials, design, fit, and other qualities? Well-made circuit boards, computer-cut plastic and metal parts, and other precision components add to the experience." data-original-title="Component Quality">Components:</span> <?php echo get_the_term_list( $post->ID, 'components', '', ', ', '' ); ?></dt> | |
<dd class="<?php $terms_as_text = get_the_term_list( $post->ID, 'components', '', ', ', '' ) ; echo 'term'.strip_tags($terms_as_text); ?>"></dd> | |
<dt><span class="define" rel="popover" data-content="(5=Highest quality) How clear, complete, and polished | |
is the documentation? Some of the best instructions, like from Makey award-winner Lego, don’t use words, so they can be understood by anyone." data-original-title="Documentation Quality">Documentation:</span> <?php echo get_the_term_list( $post->ID, 'documentation', '', ', ', '' ); ?></dt> | |
<dd class="<?php $terms_as_text = get_the_term_list( $post->ID, 'documentation', '', ', ', '' ) ; echo 'term'.strip_tags($terms_as_text); ?>"></dd> | |
<dt><span class="define" rel="popover" data-content="(5=Most community) How much of a community is there around the kit? Are there builder groups, online forums, circles, and meetups? Is the kit used in class- rooms or after-school programs? Do the kit makers or builders have a presence at events like Maker Faire?" data-original-title="Community Quality">Community:</span> <?php echo get_the_term_list( $post->ID, 'community', '', ', ', '' ); ?></dt> | |
<dd class="<?php $terms_as_text = get_the_term_list( $post->ID, 'community', '', ', ', '' ) ; echo 'term'.strip_tags($terms_as_text); ?>"></dd> | |
<dt><span class="define" rel="popover" data-content="(5=Most complete) How complete is the kit? Plans only? That rates a 1. Parts bundles and kits rate 2–5, depending on whether it’s just key components, almost every- thing, or absolutely everything you need, including any unusual tools." data-original-title="Completeness">Completeness:</span> <?php echo get_the_term_list( $post->ID, 'completeness', '', ', ', '' ); ?></dt> | |
<dd class="<?php $terms_as_text = get_the_term_list( $post->ID, 'completeness', '', ', ', '' ) ; echo 'term'.strip_tags($terms_as_text); ?>"></dd> | |
</dl> | |
<p class="the_tags"> | |
<?php the_tags('<strong>TAGS:</strong> '); ?> | |
</p> | |
<p class="date">Reviewed: <?php the_date(); ?></p> | |
<iframe src="//www.facebook.com/plugins/like.php?href= <?php echo urlencode(get_permalink()); ?>&send=false&layout=button_count&width=183&show_faces=true&action=like&colorscheme=light&font&height=21&appId=171225639607468" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:183px; height:21px;" allowTransparency="true"></iframe> | |
</div> | |
<?php } | |
function js_add_review($content) { | |
global $post; | |
$original = $content; | |
$content = js_ratings_box(); | |
$content .= $original; | |
return $content; | |
} | |
//add_filter( 'the_content', 'js_add_review', 15 ); | |
//Comments | |
function js_kit_comments( $comment, $args, $depth ) { | |
$GLOBALS['comment'] = $comment; | |
switch ( $comment->comment_type ) : | |
case '' : | |
?> | |
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> | |
<div id="comment-<?php comment_ID(); ?>"> | |
<div class="comment-author vcard"> | |
<?php echo get_avatar( $comment, 50 ); ?> | |
<?php printf( __( '%s <span class="says">says:</span>', 'kit_comments' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?> | |
</div><!-- .comment-author .vcard --> | |
<?php if ( $comment->comment_approved == '0' ) : ?> | |
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'kit_comments' ); ?></em> | |
<br /> | |
<?php endif; ?> | |
<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"> | |
<?php | |
/* translators: 1: date, 2: time */ | |
printf( __( '%1$s at %2$s', 'kit_comments' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'kit_comments' ), ' ' ); | |
?> | |
</div><!-- .comment-meta .commentmetadata --> | |
<div class="comment-body"><?php comment_text(); ?></div> | |
<div class="reply"> | |
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> | |
</div><!-- .reply --> | |
</div><!-- #comment-## --> | |
<?php | |
break; | |
case 'pingback' : | |
case 'trackback' : | |
?> | |
<li class="post pingback"> | |
<p><?php _e( 'Pingback:', 'kit_comments' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'kit_comments' ), ' ' ); ?></p> | |
<?php | |
break; | |
endswitch; | |
} | |
register_nav_menu( 'primary', 'Primary Navigation' ); | |
register_nav_menu( 'primary', 'Top Bar' ); | |
//Custom Field Hacks | |
$field_data = array ( | |
'Meta' => array ( // unique group id | |
'fields' => array( // array "fields" with field definitions | |
'CompanyURL' => array(), // globally unique field id | |
'ProductURL' => array(), | |
'Price' => array(), | |
'MakeProjectsGuideNumber' => array(), | |
), | |
), | |
); | |
$easy_cf = new Easy_CF($field_data); | |
/** catch a description for the OG protocol **/ | |
function js_catch_that_desc() { | |
global $post; | |
$meta = strip_tags($post->post_content); | |
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta); | |
$meta = substr(trim($meta), 0, 200); | |
$meta= htmlentities($meta); | |
return($meta); | |
} | |
/** END **/ | |
function js_enqueue_jquery() { | |
wp_enqueue_script( 'jquery' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'js_enqueue_jquery' ); | |
//Here we go with the Make: Projects APi | |
function js_make_project($guide) { | |
global $post; | |
$guide = get_post_custom_values('MakeProjectsGuideNumber'); | |
$url = 'http://makeprojects.com/api/0.1/guide/'.$guide[0]; | |
$json = wpcom_vip_file_get_contents($url); | |
$json_output = json_decode($json); | |
// Don't print anything if we didn't get a good response | |
if ( !is_object( $json_output ) ) | |
return; | |
echo '<p class="alert-message block-message info">'; | |
echo '<a href="' . esc_url( $json_output->url ) . '"><img src="'; | |
echo bloginfo('stylesheet_directory'); | |
echo '/images/proj.jpg" class="pull-right" alt="Make: Projects" /></a>'; | |
echo 'Check out this full <a href="' . esc_url( $json_output->url ) . '">' . esc_html( $json_output->guide->title ) . '</a> build from <a href="http://makeprojects.com">Make: Projects</a>, where you can find hundreds of project how-tos, techniques, and an active community of makers.</p>'; | |
echo '<p class="summary">' . esc_html( $json_output->guide->summary ) . '</p>'; | |
echo '<p><strong>Author</strong>: ' . esc_html( $json_output->guide->author->text ); | |
echo ' <strong>Time Required</strong>: ' . esc_html( $json_output->guide->time_required ); | |
echo ' <strong>Difficulty</strong>: ' . esc_html( $json_output->guide->difficulty ) . '</p>'; ?> | |
<div class="entry-content"> | |
<img src="<?php echo esc_url( $json_output->guide->image->text ); ?>.standard" class="thumbnail" alt="<?php echo esc_attr( $json_output->guide->title ); ?>" align="right" /> | |
<?php echo '<div class="summary">' . wp_kses_post( $json_output->guide->introduction_rendered ) .'</div>' ?> | |
<div class="clear"></div> | |
</div> | |
<div class="row"> | |
<div class="span5"> | |
<strong>Build Steps</strong> | |
<ol> | |
<?php | |
$steps = $json_output->guide->steps; | |
foreach ($steps as $step) { | |
echo '<li>'; | |
echo '<a href="#' . esc_attr( $step->number ) . '">'; | |
echo esc_html( $step->title ); | |
echo '</a></li>'; | |
} | |
?> | |
</ol> | |
</div> | |
<div class="span4"> | |
<strong>Files</strong> | |
<ul> | |
<?php | |
$documents = $json_output->guide->documents; | |
foreach ($documents as $document) { | |
echo '<li>'; | |
echo '<a href="' . esc_url( $document->url ) . '">'; | |
echo esc_html( $document->text ); | |
echo '</a></li>'; | |
} | |
?> | |
</ul> | |
</div> | |
</div> | |
<div class="clear"></div> | |
<?php | |
$i = 0; | |
foreach ($steps as $step) { | |
//var_dump($step); | |
echo '<div class="project" id="' . esc_attr( $step->number ) . '">'; | |
echo '<div class="big_images">'; | |
$images = $step->images; | |
foreach ($images as $image) { | |
//var_dump($image); | |
echo '<img src="'; | |
echo esc_url( $image->text ); | |
echo '.standard" class="' . esc_attr( $image->imageid ) . ' ' . esc_attr( $image->orderby ) .'" />'; | |
} | |
echo '</div><!--.big_images-->'; | |
echo '<div class="right_column">'; | |
$images = $step->images; | |
foreach ($images as $image) { | |
//var_dump($image); | |
echo '<img src="'; | |
echo esc_url( $image->text ); | |
echo '.thumbnail" class="thumbnail span1 ' . esc_attr( $image->imageid ) . ' ' . esc_attr( $image->orderby ) . '" />'; | |
} | |
$lines = $step->lines; | |
echo '<h3 class="clear">Step #' . esc_html( $step->number ) . ' ' . esc_html( $step->title ) . '</h3>'; | |
echo '<ul>'; | |
foreach ($lines as $line) { | |
//var_dump($line); | |
echo '<li>'; | |
echo esc_html( $line->text ); | |
echo '</li>'; | |
} | |
echo '</ul>'; | |
echo '</div><!--.right_column-->'; | |
echo '<div class="clear"></div><!--.clear-->'; | |
echo '</div><!--.project - Step #' . esc_html( $step->number ) .'-->'; | |
if (++$i == 999) break; | |
} | |
echo '<div class="conclusion">'; | |
echo esc_html( $json_output->guide->conclusion ) ; | |
echo '</div>'; | |
} | |
add_filter('comment_form_defaults','js_change_reply'); | |
function js_change_reply($defaults) { | |
$defaults['title_reply'] = 'Your Thoughts?'; | |
return $defaults; | |
} | |
function new_js_add_review($content) { | |
global $post; | |
$content = js_ratings_box().$content; | |
$guide = get_post_custom_values('MakeProjectsGuideNumber'); | |
if (isset($guide[0])) { | |
$content .= js_make_project($guide); | |
} | |
return $content; | |
} | |
add_filter( 'the_content', 'new_js_add_review' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment