Skip to content

Instantly share code, notes, and snippets.

View zanematthew's full-sized avatar

Zane Matthew zanematthew

View GitHub Profile
@zanematthew
zanematthew / bootstrap.php
Created May 3, 2012 13:39
This is a snippet from bootstrap.php which acts as an auto loader based on scan dir.
<?php
// This will auto load the following and/or create files if needed.
//
// plugin/controllers/$post_type_controller.php
// plugin/models/$post_type.php
// plugin/assets/stylesheets/$post_type.php
// plugin/assets/javascripts/$post_type.php
//
// note as of now the oder of the files is not important, we'll cross
@zanematthew
zanematthew / routes.php
Created May 3, 2012 13:40
This is the entire routes file, this is inspired by Rails routes.rb file.
<?php
/**
* Any Custom Post Type "should" automatically be routed based on the following:
*/
add_action('template_redirect', function( $params=array() ) {
$post_type = null;
$taxonomy = get_query_var('taxonomy');
@zanematthew
zanematthew / gist:2634706
Created May 8, 2012 12:56
Sample using JavaScript templating.
// The JS Template
<script id="result_event_tpl" type="text/html">
{{#result}}
<tr>
<td>
<input type="checkbox" {{checked }} class="yes_no_handle {{ css_class }}" data-action="{{ action }}" data-current_user_id="{{ current_user }}" data-post_id="{{ id }}" />
</td>
<td class="meta">{{ date }}</td>
<td>
<div class="title">
// Old js snippet, would be better to move this to the template, the thing is if there's no results this should not be displayed.
new_header = '<tr><th class="attending">Add</th><th class="date">Date</th><th class="title">Event</th><th class="track">Track</th><th class="state">State</th></tr>';
// snippet of search.js
// Start
var results_data_object = {"result":[]};
results_data_object.result.push({
id: this_result['ID'],
title: this_result['t'],
track: this_result['tr'],
@zanematthew
zanematthew / events.php
Created May 9, 2012 22:58
This the contents of our Events Post Type
<?php
// This file is located in models/events.php
$tmp_cpt = 'events';
$event = new Events();
$event->post_type = array(
array(
'name' => 'Race Event',
'type' => $tmp_cpt,
'has_one' => 'tracks', // add support 'has_many' => 'other_cpt'
@zanematthew
zanematthew / tracks_controller.php
Created May 9, 2012 23:12
Sample code from the tracks controller
<?php
// Contents of controllers/tracks_controller.php
Class Tracks extends zMCustomPostTypeBase {
/**
* @todo derive this, based on $this->post_type['type']
*/
public $cpt = 'tracks';
@zanematthew
zanematthew / gist:2720021
Created May 17, 2012 16:33
Hook into template redirect before it can redirect
<?php
add_action('template_redirect', function() {
$tmp = explode( '/', $_SERVER['REQUEST_URI'] );
$my_slug = 'feeds';
if ( isset( $tmp ) && $tmp[1] == $my_slug ) {
load_template( '/path/to/my/template/' );
// or do what ever you want
exit();
@zanematthew
zanematthew / bootstrap.php
Created June 11, 2012 20:29
Auto loading files, this is part of my bootstrapping processes
<?php
// more stuff done here
/**
* Start auto loading
*
* Everything is based on the presence of a plugin/your-plugin/controller/{$post_type}_controller.php
* file if this file is present it is read and $post_type is paresed out and used for the model, js,
* and css file. If a css or js file isn't present one will be created for you given we can write to
@zanematthew
zanematthew / index.html.php
Created June 16, 2012 15:52
Code from the home page view
<?php if ( $event ) : ?>
<h1><a href="<?= $event['link']; ?>"><?= $event['title']; ?></a></h1>
<p class="date-time"><time class="post-time"><?= $event['date']; ?></time></p>
<div style="float: left;">
<ul class="inline" style="margin: 10px 0 0;">
<li style="margin-top: -12px; float: left;"><?php load_template( VIEWS_DIR . 'shared/facebook-button.html.php' ); ?></li>
<li><?php load_template( VIEWS_DIR . 'shared/twitter-like-button.html.php' ); ?></li>
</ul>
</div>
<?php else : ?>
@zanematthew
zanematthew / home_controller.php
Created June 16, 2012 15:57
Code from the Home page controller
<?php
public function randomBanner(){
$obj_local_venues = new Tracks;
$local_venues = $obj_local_venues->getLocalVenues();
$venue_ids = array();
foreach( $local_venues as $venue ){