Skip to content

Commit

Permalink
renamed and organized skin templates. added fallback techniquewhen vi…
Browse files Browse the repository at this point in the history
…ews are not found.
  • Loading branch information
jordan-wilson committed May 18, 2012
1 parent 3b7c35f commit b7bd88a
Show file tree
Hide file tree
Showing 41 changed files with 652 additions and 157 deletions.
78 changes: 77 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
CMS driven by MVC framework written in PHP
CMS driven by MVC framework written in PHP




LAYOUTS
Layouts are retreived from the "layouts.model.php". The values returned are used to find the layout file to use.
The string is created in the base "controller" class, by the public "parse_page_layout()" method.

Page layouts have two parameters:
1) controller defaults to the named constant "DEFAULT_CONTROLLER"
2) skin defaults to the string literal "default"

examples:
pages.default.layout.php, pages.home.layout.php
blogs.default.layout.php, blogs.post.layout.php




TEMPLATES
Templates are hard coded into the actual controller so there is no real naming convention.

There are two types of templates:
1) Content templates
overrides the pages default [content] block
loaded through the controller's public "index()" method
examples:
pages.content.template.php,
blogs.index.template.php, blogs.view.template.php

2) Block tempates
block content added to the layout
loaded through the controller's public "get_block()" method
examples:
blocks.default.block.php, blocks.blue.block.php,
blogs.subscribe.default.block.php, blogs.recent.default.block.php, blogs.recent.green.block.php



BLOCKS
Block data is retreived from the "layouts.model.php" within the cells array.
The data is retreived in the base "controller" class, by the public "parse_page_layout()" method.
It's used to find and load the appropriate controller that'll load and return the block template.

Blocks have two parameters:
1) controller controller to load - the method "get_block()" is always called
2) arguments a string to pass to "get_block()"

examples:
'[blocks:6]',
'[forms:2]',
'[blogs:subscribe]', '[blogs:recent]', '[blogs:recent.green]',

The first parameter in the file name is the controller to load. Everything else is a parameter that gets
passed to the controller's public "get_block()" method.

The block '[blogs:recent]' will load the "blogs" controller and call the "blogs->get_block()" method
which knows it needs to call the "blogs->_get_recent_block()" method. Then it'll load and return the
"blogs.recent.default.block.php" template file. The block '[blogs:recent.green]' will do the same
but load and return the "blogs.recent.green.block.php" template file.





LOAD_VIEW()
The following is an example of how the "load_view()" will attempt to locate a template file.
load_view: 'blocks.default.block.php'
1st attempt: '/skins/APP/SKIN/blocks.default.block.php'
2nd attempt: '/skins/APP/SKIN/templates/blocks.default.block.php'
3rd attempt: '/skins/APP/SKIN/templates/blocks/default.block.php'

Some modules have a lot of extra content and block templates so this just makes it easy to organize them
by allowing anyone to just grab them all and throw them into their own folder. Remember to remove the
module name from the beginning of the template file name if they are in their own folder (3rd attempt).

41 changes: 20 additions & 21 deletions app/front/controllers/blocks.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@
class blocks extends controller
{

public function get_block( $arg = '' )
public function get_block( $id = 0 )
{
if (is_numeric($arg))
if ( ! is_numeric($id)) return '';

// get block info
$blocks_model = load_model('blocks');
$data = $blocks_model->get_block($id);

// if blog not found
if ( ! count($data)) return '';

// the default template
$default = 'blocks.default.block.php';

// if using custom template
if ($data['skin'] != '')
{
// get block info
$blocks_model = load_model('blocks');
$data = $blocks_model->get_block($arg);

if ( ! count($data)) return '';

// the template to use for the block
$template = 'blocks.default.template.php';
if ($data['skin'] != '')
{
$skin = 'blocks.' . $data['skin'] . '.template.php';
$path = SITE_ROOT . '/skins/' . APP . '/' . $this->registry->skin . '/' . $skin;
if (file_exists($path))
$template = $skin;
}

// load block
return load_view($template, $data);
// load the custom template
$template = 'blocks.' . $data['skin'] . '.block.php';
return load_view($template, $data, $default);
}

return '';
// load the default template
return load_view($default, $data);
}

}
99 changes: 75 additions & 24 deletions app/front/controllers/blogs.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ class blogs extends controller

public function index()
{
// update main template
$this->main_template = 'layout.blogs.template.php';

// update page content
$request = $this->registry->request_args;
if (count($request) == 1)
Expand All @@ -21,6 +18,13 @@ public function index()
$this->registry->page_content = $this->_view($request[1]);
}
else {
/*
Right now I'm just redirecting the user to the error page since
I can't figure out how to load the error page using the pages
controller in an efficient way. I'll probably need to stick it
where everyone can call it. Like the base 'controller' or
'registry' classes.
*/
header('Location: /error');
exit();
}
Expand All @@ -44,7 +48,7 @@ private function _index()
$this->_add_css();

// return html
return load_view('blogs.landing.template.php', $data);
return load_view('blogs.index.template.php', $data);
}


Expand Down Expand Up @@ -94,95 +98,142 @@ public function get_block( $arg = '' )
if ( ! $this->registry->modules['blogs'])
return '';

// splite the argument into an array by '.'
$arg = explode('.', $arg);


// individual blog block
if (is_numeric($arg))
if (is_numeric($arg[0]))
{
return $this->_get_blog_block($arg);
}

// subscribe block
elseif ($arg == 'subscribe.block')
elseif ($arg[0] == 'subscribe')
{
return $this->_get_subscribe_block();
return $this->_get_subscribe_block($arg);
}

// recent blog post block
elseif ($arg == 'recent.block')
elseif ($arg[0] == 'recent')
{
return $this->_get_recent_block();
return $this->_get_recent_block($arg);
}

// blog categories block
elseif ($arg == 'categories.block')
elseif ($arg[0] == 'categories')
{
return $this->_get_categories_block();
return $this->_get_categories_block($arg);
}

return '';
}


// individual blog block
private function _get_blog_block( $id = 0 )
private function _get_blog_block( $arg = array() )
{
// the url of the blogs page
$data['link'] = '/' . $this->registry->modules['blogs'] . '/';

// get blog info
$blogs_model = load_model('blogs');
$data['blog'] = $blogs_model->get_blog($id);
$data['blog'] = $blogs_model->get_blog($arg[0]);

// if blog not found
if ( ! $data['blog']) return '';

// add css
$this->_add_css();

// return html
return load_view('blogs.blog.block.template.php', $data);
// the default template
$default = 'blogs.blog.default.block.php';

// if using custom template
if ($arg[1])
{
// load the custom template
$template = 'blogs.blog.' . $arg[1] . '.block.php';
return load_view($template, $data, $default);
}

// load the default template
return load_view($default, $data);
}


// subscribe block
private function _get_subscribe_block()
private function _get_subscribe_block( $arg = array() )
{
// the url of the blogs page
$data['link'] = '/' . $this->registry->modules['blogs'] . '/';

// add css
$this->_add_css();

// return html
return load_view('blogs.subscribe.block.template.php', $data);
// the default template
$default = 'blogs.subscribe.default.block.php';

// if using custom template
if ($arg[1])
{
// load the custom template
$template = 'blogs.subscribe.' . $arg[1] . '.block.php';
return load_view($template, $data, $default);
}

// load the default template
return load_view($default, $data);
}


// categories block
private function _get_categories_block()
private function _get_categories_block( $arg = array() )
{
// the url of the blogs page
$data['link'] = '/' . $this->registry->modules['blogs'] . '/';

// add css
$this->_add_css();

// the default template
$default = 'blogs.categories.default.block.php';

// return html
return load_view('blogs.categories.block.template.php', $data);
// if using custom template
if ($arg[1])
{
// load the custom template
$template = 'blogs.categories.' . $arg[1] . '.block.php';
return load_view($template, $data, $default);
}

// load the default template
return load_view($default, $data);
}


// recent blog post block
private function _get_recent_block()
private function _get_recent_block( $arg = array() )
{
// the url of the blogs page
$data['link'] = '/' . $this->registry->modules['blogs'] . '/';

// add css
$this->_add_css();

// return html
return load_view('blogs.recent.block.template.php', $data);
// the default template
$default = 'blogs.recent.default.block.php';

// if using custom template
if ($arg[1])
{
// load the custom template
$template = 'blogs.recent.' . $arg[1] . '.block.php';
return load_view($template, $data, $default);
}

// load the default template
return load_view($default, $data);
}

}
Loading

0 comments on commit b7bd88a

Please sign in to comment.