Skip to content

Instantly share code, notes, and snippets.

View erkattak's full-sized avatar

Erik Straub erkattak

View GitHub Profile
<?php
// controller
function wutangclan() {
$this->load->model('odb');
$data['killerbees'] = $this->odb->getThatPaper();
$data['main_content'] = 'report/dashboard'; // main body view, can be whatever
$this->load->view('includes/template', $data);
?>
============
@erkattak
erkattak / JR's CodeIgniter Image Thumb Helper
Created March 2, 2011 19:25
Image thumb helper that keeps the thumbnail once it's created. Must mod Image_lib to account for transparent PNGs.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('image_thumb_helper')){
function image_thumb($image_path, $filename, $height, $width){
$filename = preg_replace('/\.png/','_',$filename);
// Get the CodeIgniter super object
$CI =& get_instance();
// Path to image thumbnail
$image_thumb = dirname($image_path) . '/'.$filename . $height . '_' . $width . '.png';
if( ! file_exists($image_thumb)){
// LOAD LIBRARY
@erkattak
erkattak / RegExTimeRange
Created April 28, 2011 18:16
RegEx for Time Range (1-5pm, 11:45am-5pm, 1 - 5:15pm, etc.)
\b((?:(?<!:)(?:1?[0-9])(?::(?<!\d)[0-5]\d)?(?:\s?[ap][m]?)?)(?:\s?-\s?)(?<=-|\s)(?:(?:1?[0-9])(?::(?<!\d)[0-5]\d)?(?:\s?[ap][m]?)))\b
@erkattak
erkattak / NextGEN-Cover-Image.php
Created May 30, 2011 21:40
WordPress - Pull NextGEN Gallery Preview Image using Gallery ID
<?php
$gallery_id = 1; // Use the PODS column, custom post field or however you would get this ID
$results = $wpdb->get_results("SELECT ng.path, np.filename FROM wp_ngg_pictures np, wp_ngg_gallery ng WHERE np.galleryid=ng.gid AND np.galleryid=".$gallery_id." AND np.pid=ng.previewpic",ARRAY_A);
if(!empty($results[0]['path']) && !empty($results[0]['filename'])) :
$imgpath = $results[0]['path'].'/'.$results[0]['filename'];
endif;
@erkattak
erkattak / SQL_Loop.php
Created June 9, 2011 13:40
Looping SQL results
<?php
// get your sql results, etc
$results = mysql_query('SELECT * FROM table');
?>
<form>
<fieldset>
<legend>Your Legend</legend>
<select name="editlist">
<?php while($row = mysql_fetch_result($results, MYSQL_ASSOC) : ?>
<option value="<?php echo $row['companyname']; ?>"><?php echo $row['companyname']; ?></option>
@erkattak
erkattak / MY_Router.php
Created June 17, 2011 05:10
Using nested controllers in CodeIgniter 2.0
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* MY_Router allows the existence of controllers and controller sub directories of the same name
*
* @author Erik Straub
*/
class MY_Router extends CI_Router {
function __construct(){
parent::__construct();
Array
(
[0] => Array
(
[id] => 14735
[name] => Biotechnology and Related Specialties
[displaytype] => default
[parent_id] => 0
[children] => Array
(
Array
(
[0] => Array
(
[id] => 14735
[name] => Biotechnology and Related Specialties
[displaytype] => default
[parent_id] => 0
[children] => Array
(
function checkbox_list ($data, $name = 'list', $parent = 0, &$label = null) {
if (!empty($data)) {
echo '<div class="categories sub">';
foreach ($data as $item) {
if (isset($item['children']) && !empty($item['children'])){
$label .= (isset($label)) ? ' ' . $item['name'].' &raquo;' : $item['name'].' &raquo;';
checkbox_list($item['children'], $name, $item['id'],$label);
}else{
echo (isset($label)) ? '<h3>'.$label.'</h3>' : false;
echo '<label for="'.$name.'_'.$item['id'].'"><input type="checkbox" name="'.$name.'[]" value="'.$item['id'].'" id="'.$name.'_'.$item['id'].'" />'.$item['name'].'</label>';
@erkattak
erkattak / add-business-pod-page.php
Created November 16, 2011 23:52
Add a business via publicForm
<div id="content">
<span class="breadcrumbs"><a href="<?php bloginfo('url'); ?>">Home</a> &raquo; <a href="<?php bloginfo('url'); ?>/businesses">Businesses</a> &raquo; Add a Listing</span>
<h2 class="title">Add a Business Listing</h2>
<div class="entry clearfloat">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Hoc est non modo cor non habere, sed ne palatum quidem. Cum audissem Antiochum, Brute, ut solebam, cum M. Sed ut iis bonis erigimur, quae expectamus, sic laetamur iis, quae recordamur. Sed ne, dum huic obsequor, vobis molestus sim. An hoc usque quaque, aliter in vita? Haec para/doca illi, nos admirabilia dicamus. Quod equidem non reprehendo;</p>
<?php
$pod = new Pod('businesses');
$fields = array('name','business_type','content','excerpt','www','address','city','state','zip','email','phone','facebook','twitter','slug'=>array('hidden'=>true));
$pod->publicForm($fields,'Submit Business Listing',get_bloginfo('url').'/businesses/thank-you');
?>