Last active
November 16, 2015 00:07
-
-
Save danielpataki/5add68f88177e4786220 to your computer and use it in GitHub Desktop.
Document Diary
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 | |
if( function_exists('acf_add_local_field_group') ): | |
acf_add_local_field_group(array ( | |
'key' => 'group_56474888a8e7f', | |
'title' => 'Attachment Options', | |
'fields' => array ( | |
array ( | |
'key' => 'field_56474b42cc2ed', | |
'label' => 'Page', | |
'name' => 'page', | |
'type' => 'number', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array ( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
'readonly' => 0, | |
'disabled' => 0, | |
), | |
array ( | |
'key' => 'field_56474f714ddfd', | |
'label' => 'Google Drive Link', | |
'name' => 'google_drive_link', | |
'type' => 'url', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array ( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
), | |
), | |
'location' => array ( | |
array ( | |
array ( | |
'param' => 'attachment', | |
'operator' => '==', | |
'value' => 'all', | |
), | |
), | |
), | |
'menu_order' => 0, | |
'position' => 'normal', | |
'style' => 'default', | |
'label_placement' => 'top', | |
'instruction_placement' => 'label', | |
'hide_on_screen' => '', | |
'active' => 1, | |
'description' => '', | |
)); | |
acf_add_local_field_group(array ( | |
'key' => 'group_56474be222e71', | |
'title' => 'Document Options', | |
'fields' => array ( | |
array ( | |
'key' => 'field_564749e499720', | |
'label' => 'Document ID', | |
'name' => 'document_id', | |
'type' => 'text', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array ( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => '', | |
'maxlength' => '', | |
'readonly' => 0, | |
'disabled' => 0, | |
), | |
array ( | |
'key' => 'field_564749f399721', | |
'label' => 'Date', | |
'name' => 'date', | |
'type' => 'date_picker', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array ( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'display_format' => 'd/m/Y', | |
'return_format' => 'd/m/Y', | |
'first_day' => 1, | |
), | |
array ( | |
'key' => 'field_56474a59a8892', | |
'label' => 'Valid Until', | |
'name' => 'valid_until', | |
'type' => 'date_picker', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array ( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'display_format' => 'd/m/Y', | |
'return_format' => 'd/m/Y', | |
'first_day' => 1, | |
), | |
), | |
'location' => array ( | |
array ( | |
array ( | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'post', | |
), | |
), | |
), | |
'menu_order' => 0, | |
'position' => 'normal', | |
'style' => 'default', | |
'label_placement' => 'top', | |
'instruction_placement' => 'label', | |
'hide_on_screen' => '', | |
'active' => 1, | |
'description' => '', | |
)); | |
acf_add_local_field_group(array ( | |
'key' => 'group_56474c929cf93', | |
'title' => 'Origin', | |
'fields' => array ( | |
array ( | |
'key' => 'field_56474c9cdf17e', | |
'label' => 'Origin', | |
'name' => 'origin', | |
'type' => 'google_map', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array ( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'center_lat' => '', | |
'center_lng' => '', | |
'zoom' => '', | |
'height' => '', | |
), | |
), | |
'location' => array ( | |
array ( | |
array ( | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'post', | |
), | |
), | |
), | |
'menu_order' => 30, | |
'position' => 'normal', | |
'style' => 'default', | |
'label_placement' => 'top', | |
'instruction_placement' => 'label', | |
'hide_on_screen' => '', | |
'active' => 1, | |
'description' => '', | |
)); | |
endif; |
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
if( function_exists('acf_add_local_field_group') ): | |
acf_add_local_field_group(array ( | |
'key' => 'group_564916a4cefbc', | |
'title' => 'Gas Options', | |
'fields' => array ( | |
array ( | |
'key' => 'field_564916aa7269d', | |
'label' => 'Gas Purchased', | |
'name' => 'fuel_purchased', | |
'type' => 'number', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array ( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '', | |
'append' => 'liters', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
'readonly' => 0, | |
'disabled' => 0, | |
), | |
array ( | |
'key' => 'field_564916b27269e', | |
'label' => 'Price', | |
'name' => 'price', | |
'type' => 'number', | |
'instructions' => '', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array ( | |
'width' => '', | |
'class' => '', | |
'id' => '', | |
), | |
'default_value' => '', | |
'placeholder' => '', | |
'prepend' => '$', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
'readonly' => 0, | |
'disabled' => 0, | |
), | |
), | |
'location' => array ( | |
array ( | |
array ( | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'post', | |
), | |
), | |
array ( | |
array ( | |
'param' => 'post_taxonomy', | |
'operator' => '==', | |
'value' => 'post_tag:gas', | |
), | |
), | |
), | |
'menu_order' => 0, | |
'position' => 'side', | |
'style' => 'default', | |
'label_placement' => 'top', | |
'instruction_placement' => 'label', | |
'hide_on_screen' => '', | |
'active' => 1, | |
'description' => '', | |
)); | |
endif; |
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 | |
$args = array( | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
'posts_per_page' => -1, | |
'tag' => 'gas', | |
'order_by' => 'post_date', | |
'order' => 'DESC' | |
); | |
$gas_posts = new WP_Query( $args ); | |
if( $gas_posts->have_posts() ) { | |
$total_q = 0; | |
$total_p = 0; | |
echo '<table></thead><tr> | |
<th>Date</th> | |
<th>Quantity</th> | |
<th>Price</th> | |
<th>Unit Price</th> | |
</tr></thead><tbody>'; | |
while( $gas_posts->have_posts() ) { | |
$gas_posts->the_post(); | |
$purchased = get_field( 'fuel_purchased', $post->ID ); | |
$price = get_field( 'price', $post->ID ); | |
$total_q = $total_q + $purchased; | |
$total_p = $total_p + $price; | |
echo "<tr> | |
<td>" . date( "Y-m-d", strtotime( $post->post_date ) ) . "</td> | |
<td>" . $purchased . "</td> | |
<td>" . $price . "</td> | |
<td>" . round( $purchased/$price, 2 ) . " $/l</td> | |
</tr>"; | |
} | |
echo "<tfoot> | |
<th>Total</th> | |
<th>" . $total_q . "</th> | |
<th>" . $total_p . "</th> | |
<th>" . round( $total_q/$total_p, 2 ) . " $/l</td> | |
</tfoot>"; | |
echo "</tbody></table>"; | |
} | |
?> |
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 | |
/** | |
* Template Name: Gas Usage | |
*/ | |
?> | |
<?php | |
$pte = Page_Template_Plugin::get_instance(); | |
$locale = $pte->get_locale(); | |
get_header(); | |
?> | |
<div id="primary" class="content-area"> | |
<main id="main" class="site-main" role="main"> | |
<?php | |
// Start the loop. | |
while ( have_posts() ) : the_post(); | |
?> | |
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> | |
<?php | |
// Post thumbnail. | |
twentyfifteen_post_thumbnail(); | |
?> | |
<header class="entry-header"> | |
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> | |
</header><!-- .entry-header --> | |
<div class="entry-content"> | |
<?php the_content(); ?> | |
</div><!-- .entry-content --> | |
<?php edit_post_link( __( 'Edit', 'twentyfifteen' ), '<footer class="entry-footer"><span class="edit-link">', '</span></footer><!-- .entry-footer -->' ); ?> | |
</article><!-- #post-## --> | |
<?php | |
// If comments are open or we have at least one comment, load up the comment template. | |
if ( comments_open() || get_comments_number() ) : | |
comments_template(); | |
endif; | |
// End the loop. | |
endwhile; | |
?> | |
</main><!-- .site-main --> | |
</div><!-- .content-area --> | |
<?php get_footer() ?> |
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
add_action( 'wp_enqueue_scripts', 'plugin_scripts' ); | |
function plugin_scripts() { | |
wp_enqueue_script( | |
'google-maps', | |
'//maps.googleapis.com/maps/api/js?key=YOURKEY&callback=initMap', | |
array(), | |
'1.0', | |
true | |
); | |
} |
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
include( 'acf-options.php' ); |
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
require_once( plugin_dir_path( __FILE__ ) . 'Page_Template_Plugin.class.php' ); | |
add_action( 'plugins_loaded', array( 'Page_Template_Plugin', 'get_instance' ) ); |
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
$location = get_field( 'origin' ); | |
if( !empty( $location ) && is_single() ) { | |
$output .= "<h6>Location</h6>"; | |
$id = rand( 222, 31493 ); | |
$output .= "<div class='map' style='height:300px; margin-bottom: 1.6842em' id='map-" . $id ."'></div>"; | |
$output .= " | |
<script type='text/javascript'> | |
var map; | |
var map_center = {lat: " . $location['lat'] . ", lng: " . $location['lng'] . " }; | |
function initMap() { | |
map = new google.maps.Map(document.getElementById('map-" . $id . "'), { | |
center: map_center, | |
zoom: 15 | |
}); | |
var marker = new google.maps.Marker({ | |
position: map_center, | |
map: map | |
}); | |
} | |
</script> | |
"; | |
} |
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 | |
/* | |
Plugin Name: Document Diary | |
Plugin URI: http://danielpataki.com/ | |
Description: Our very own document diary | |
Author: Daniel Pataki | |
Version: 1.0 | |
Author URI: http://danielpataki.com/ | |
License: GPL v2 or later | |
*/ |
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
add_filter( 'the_content', 'diary_documents' ); | |
function diary_documents( $content ) { | |
global $post; | |
$output = ''; | |
$args = array( | |
'post_type' => 'attachment', | |
'post_parent' => $post->ID, | |
'post_status' => 'any', | |
'posts_per_page' => -1 | |
); | |
$attachments = get_posts( $args ); | |
if( !empty( $attachments ) ) { | |
$output .= '<h4>Attachments</h4><ul>'; | |
foreach( $attachments as $attachment ) { | |
$output .= '<li> ' . $attachment->post_content . ' Page ' . get_field( 'page', $attachment->ID ) . ' | <a href="' . wp_get_attachment_url( $attachment->ID ) . '">View</a> | <a href="' . get_field( 'google_drive_link', $attachment->ID ) . '">Google Docs</a> </li>'; | |
} | |
$output .= '</ul>'; | |
} | |
$basic_data = array(); | |
$basic_data['Document ID'] = get_field( 'document_id' ); | |
$basic_data['Date'] = get_field( 'date' ); | |
$basic_data['Valid Until'] = get_field( 'valid_until' ); | |
if( !empty( $basic_data ) ) { | |
$output .= '<h4>Basic Details</h4>'; | |
$output .= '<table><tbody>'; | |
foreach( $basic_data as $name => $value ) { | |
if( !empty( $value ) ) { | |
$output .= '<tr>'; | |
$output .= '<th>'. $name .'</th><td>' . $value . '</td>'; | |
$output .= '</tr>'; | |
} | |
} | |
$output .= '</tbody></table>'; | |
} | |
return $content . $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment