Skip to content

Instantly share code, notes, and snippets.

@chrisjdavis
Created January 31, 2012 15:48
Show Gist options
  • Save chrisjdavis/1711183 to your computer and use it in GitHub Desktop.
Save chrisjdavis/1711183 to your computer and use it in GitHub Desktop.
Feasts Plugin
<?php
class Feasts extends Plugins
{
public function action_init() {
DB::register_table( 'saints' );
self::setup_db();
}
/**
* setup_db function.
*
* @access private
* @return void
*/
private function setup_db() {
$q = "CREATE TABLE " . DB::table('saints') . " (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
user_id int(11) DEFAULT NULL,
title varchar(255) DEFAULT NULL,
slug varchar(255) DEFAULT NULL,
description text DEFAULT NULL,
icon varchar(255),
kontakion text DEFAULT NULL,
troparion text DEFAULT NULL,
week int(11) DEFAULT NULL,
type int(11) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
return $sql = DB::dbdelta( $q );
}
public function filter_default_rewrite_rules( $rules ) {
$rules[] = array(
'name' => 'display_saint',
'parse_regex' => '%^saint/(?P<slug>[^/]*)?/?$%i',
'build_str' => 'saint/{$slug}',
'handler' => 'UserThemeHandler',
'action' => 'display_saint',
'priority' => 1,
'description' => 'Display a given saint',
);
$rules[] = array(
'name' => 'display_feast',
'parse_regex' => '%^feast/(?P<slug>[^/]*)?/?$%i',
'build_str' => 'feast/{$slug}',
'handler' => 'UserThemeHandler',
'action' => 'display_feast',
'priority' => 1,
'description' => 'Display a given feast',
);
return $rules;
}
public function filter_theme_act_display_saint($handler, $theme) {
$paramarray = array();
$paramarray['fallback'] = array(
'saint.single',
'home'
);
$saint = self::get_by_slug( array('slug' => $theme->matched_rule->named_arg_values['slug'], 'type' => 1) );
$theme->assign( 'saint', $saint );
$paramarray['user_filters'] = array();
$theme->act_display( $paramarray );
}
public function filter_theme_act_display_feast($handler, $theme) {
$paramarray = array();
$paramarray['fallback'] = array(
'saint.single',
'home'
);
$feast = self::get_by_slug( array('slug' => $theme->matched_rule->named_arg_values['slug'], 'type' => 2) );
$theme->assign( 'feast', $feast );
$paramarray['user_filters'] = array();
$theme->act_display( $paramarray );
}
private static function find_week() {
$now = date('W');
return $now;
}
public static function record_activity(array $data) {
DB::insert( DB::table( 'saints' ), $data );
}
public static function display_saint() {
$week = self::find_week();
$saint = DB::get_row( "SELECT id, user_id, title, slug, description, icon, kontakion, troparion, week, type FROM " . DB::table('saints') . " WHERE week = $week" );
return $saint;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment