Skip to content
Permalink
Browse files

initial commit

  • Loading branch information...
jacobemerick committed Nov 25, 2015
0 parents commit e6d0f26ee139c95f81742b0f0e3d47aad0a0ea80
Showing 351 changed files with 27,041 additions and 0 deletions.
BIN +8 KB .DS_Store
Binary file not shown.
@@ -0,0 +1,3 @@
/vendor/
composer.phar
config.json
@@ -0,0 +1,8 @@
# jakemvc
A simple, custom MVC that powers several of my personal sites, including a [blog](http://blog.jacobemerick.com/), [lifestream](http://lifestream.jacobemerick.com/), and [waterfall directory](http://www.waterfallsofthekeweenaw.com/).

### Overview
This is an ancient codebase (started back in 2008) that has somehow survived multiple half-rewrites and changing coding preferences. The original intent was to send all requests - static, dynamic, and server-side - through a single point to make easy bootstrapping. Oh, and to support many different types of websites through a single MVC directory.

### But Why Publish This?
Shame-driven development. Blog post coming soon.
@@ -0,0 +1,33 @@
<?
Loader::loadInstance('utility', 'Database');
abstract class Collector
{
protected static function run_query($query)
{
return Database::select($query);
}
protected static function run_row_query($query)
{
return Database::selectRow($query);
}
protected static function get_count($query)
{
return Database::selectRow($query)->count;
}
protected static function check_exists($query)
{
return Database::selectRow($query) !== null;
}
protected static function escape($string)
{
return Database::escape($string);
}
}
@@ -0,0 +1,20 @@
<?
Loader::load('collector', 'Collector');
final class SiteCollector extends Collector
{
public static function getSitesForHomePage()
{
$query = "SELECT * FROM `jpemeric_system`.`site` WHERE `level` = '2' && `public` = '1' ORDER BY `name`";
return self::run_query($query);
}
public static function getSitesForMenu()
{
$query = "SELECT * FROM `jpemeric_system`.`site` WHERE `public` = '1' ORDER BY `level`, `name`";
return self::run_query($query);
}
}
@@ -0,0 +1,14 @@
<?
Loader::load('collector', 'Collector');
final class SocialSiteCollector extends Collector
{
public static function getSitesForHomePage()
{
$query = "SELECT * FROM `jpemeric_system`.`social_site` ORDER BY `name`";
return self::run_query($query);
}
}
@@ -0,0 +1,14 @@
<?
Loader::load('collector', 'Collector');
final class IntroductionCollector extends Collector
{
public static function getRow($type, $value = '')
{
$query = "SELECT `title`,`content`,`image` FROM `jpemeric_blog`.`introduction` WHERE `type` = '{$type}' && `value` = '{$value}' LIMIT 1";
return self::run_row_query($query);
}
}
@@ -0,0 +1,94 @@
<?
Loader::load('collector', 'Collector');
final class PostCollector extends Collector
{
public static function getPostedDates()
{
$query = "SELECT `date` FROM `jpemeric_blog`.`post` WHERE `display` = '1' ORDER BY `date` DESC";
return self::run_query($query);
}
public static function getRecentPosts($total = 3)
{
$query = "SELECT `title`, `path`, `date`, `body`, `category` FROM `jpemeric_blog`.`post` WHERE `display` = '1' ORDER BY `date` DESC LIMIT 0, {$total}";
return self::run_query($query);
}
public static function getMainList($total, $offset = 0)
{
$query = "SELECT `post`.`id` AS `id`, `title`, `path`, `date`, `body`, `category` FROM `jpemeric_blog`.`post` WHERE `display` = '1' ORDER BY `date` DESC LIMIT {$offset}, {$total}";
return self::run_query($query);
}
public static function getMainPostCount()
{
$query = "SELECT COUNT(1) AS `count` FROM `jpemeric_blog`.`post` WHERE `display` = '1'";
return self::get_count($query);
}
public static function getPostsForTag($tag_id, $total, $offset = 0)
{
$query = "SELECT `post`.`id` AS `id`, `title`, `path`, `date`, `body`, `category` FROM `jpemeric_blog`.`post`,`jpemeric_blog`.`ptlink` WHERE `display` = '1' && `post`.`id` = `ptlink`.`post_id` && `ptlink`.`tag_id` = '{$tag_id}' ORDER BY `date` DESC LIMIT {$offset}, {$total}";
return self::run_query($query);
}
public static function getPostCountForTag($tag_id)
{
$query = "SELECT COUNT(1) AS `count` FROM `jpemeric_blog`.`post`, `jpemeric_blog`.`ptlink` WHERE `post`.`id` = `ptlink`.`post_id` && `ptlink`.`tag_id` = '{$tag_id}' && `display` = '1'";
return self::get_count($query);
}
public static function getPostsForCategory($category, $total, $offset = 0)
{
$category = self::escape($category);
$query = "SELECT `post`.`id` AS `id`, `title`, `path`, `date`, `body`, `category` FROM `jpemeric_blog`.`post` WHERE `display` = '1' && `category` = '{$category}' ORDER BY `date` DESC LIMIT {$offset}, {$total}";
return self::run_query($query);
}
public static function getPostCountForCategory($category)
{
$category = self::escape($category);
$query = "SELECT COUNT(1) AS `count` FROM `jpemeric_blog`.`post` WHERE `category` = '{$category}' && `display` = '1'";
return self::get_count($query);
}
public static function getPostsForMonth($min_date, $max_date, $total, $offset = 0)
{
$query = "SELECT `post`.`id` AS `id`, `title`, `path`, `date`, `body`, `category` FROM `jpemeric_blog`.`post` WHERE `display` = '1' && `date` >= '{$min_date}' && `date` <= '{$max_date}' ORDER BY `date` DESC LIMIT {$offset}, {$total}";
return self::run_query($query);
}
public static function getPostCountForMonth($min_date, $max_date)
{
$query = "SELECT COUNT(1) AS `count` FROM `jpemeric_blog`.`post` WHERE `date` >= '{$min_date}' && `date` <= '{$max_date}' && `display` = '1'";
return self::get_count($query);
}
public static function getPostByURI($uri)
{
$uri = self::escape($uri);
$query = "SELECT `post`.`id` AS `id`, `title`, `path`, `date`, `body`, `category` FROM `jpemeric_blog`.`post` WHERE `path` = '{$uri}' && `display` = '1' LIMIT 1";
return self::run_row_query($query);
}
public static function getRelatedPosts($id, $tags, $exclude_posts = array(), $limit = 4)
{
$tag_clause = implode("', '", $tags);
$tag_clause = "'{$tag_clause}'";
$exclude_clause = '';
if(count($exclude_posts) > 0)
{
$exclude_clause .= " && `ptlink`.`post_id` NOT IN ('";
$exclude_clause .= implode("', '", $exclude_posts);
$exclude_clause .= "')";
}
$query = "SELECT `title`, `path`, `category`, `body` FROM `jpemeric_blog`.`post`, `jpemeric_blog`.`ptlink` WHERE `ptlink`.`post_id` = `post`.`id` && `tag_id` IN ({$tag_clause}) && `post_id` <> '{$id}'{$exclude_clause} GROUP BY `post_id` ORDER BY COUNT(1) DESC LIMIT {$limit}";
return self::run_query($query);
}
}
@@ -0,0 +1,38 @@
<?
Loader::load('collector', 'Collector');
final class SeriesCollector extends Collector
{
public static function getSeriesForPost($post)
{
$query = "
SELECT
`post`.`id` AS post,
`post`.`title`,
`post`.`category`,
`post`.`path`,
`series`.`title` AS `series_title`,
`series`.`description`
FROM
`jpemeric_blog`.`series`,
`jpemeric_blog`.`series_post`,
`jpemeric_blog`.`post`
WHERE
`series`.`id` = `series_post`.`series` &&
`post`.`id` = `series_post`.`post` &&
`post`.`display` = '1' &&
`series`.`id` = (
SELECT
`series`
FROM
`jpemeric_blog`.`series_post`
WHERE
`post` = '{$post}')
ORDER BY
`series_post`.`order`";
return self::run_query($query);
}
}
@@ -0,0 +1,33 @@
<?
Loader::load('collector', 'Collector');
final class TagCollector extends Collector
{
public static function getTagCloudGroup()
{
$query = "SELECT COUNT(1) AS `tag_count`,`tag` FROM `jpemeric_blog`.`tag`,`jpemeric_blog`.`post`,`jpemeric_blog`.`ptlink` WHERE `post`.`display` = 1 && `post`.`id` = `ptlink`.`post_id` && `tag`.`id` = `ptlink`.`tag_id` GROUP BY `tag`";
return self::run_query($query);
}
public static function getTagsForPost($post_id)
{
$query = "SELECT * FROM `jpemeric_blog`.`tag`, `jpemeric_blog`.`ptlink` WHERE `tag`.`id` = `tag_id` && `post_id` = '{$post_id}' ORDER BY `tag`";
return self::run_query($query);
}
public static function getSingleTag($tag)
{
$tag = self::escape($tag);
$query = "SELECT * FROM `jpemeric_blog`.`tag` WHERE `tag` = '{$tag}' LIMIT 1";
return self::run_row_query($query);
}
public static function getAllTags()
{
$query = "SELECT * FROM `jpemeric_blog`.`tag` ORDER BY `tag`";
return self::run_query($query);
}
}

0 comments on commit e6d0f26

Please sign in to comment.
You can’t perform that action at this time.