Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Frontend mostly working

  • Loading branch information...
commit af977e0b7aa580d4f6711ec0ebac509bb381cec6 1 parent 219d228
@deepwinter deepwinter authored
View
7 modules/mopcms/classes/model/page.php
@@ -597,14 +597,15 @@ public function parentFilter($parentid){
}
public function noContainerObjects(){
- $db = new Database();
- $res = $db->query("Select id from templates where nodeType = 'container'");
+ $res = ORM::Factory('template')
+ ->where('nodeType', '=', 'container')
+ ->find_all();
$tIds = array();
foreach($res as $container){
$tIds[] = $container->id;
}
if(count($tIds)){
- $this->notin('template_id', $tIds);
+ $this->where('template_id', 'NOT IN', DB::Expr('('. implode(',', $tIds).')' ) );
}
return $this;
}
View
13 modules/mopcore/classes/controller/layout.php
@@ -1,11 +1,15 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Layout extends Controller_MOP {
+
+
+ protected $subRequest;
- public function action_htmlLayout($controller, $action=null, $arguments=null)
+ public function action_htmlLayout($uri)
{
- $subRequest = Request::Factory($controller.'/'.$action.'/'.$arguments);
- $this->response->body($subRequest->execute()->body());
+
+ $this->subRequest = Request::Factory($uri);
+ $this->response->body($this->subRequest->execute()->body());
$this->outputLayout();
}
@@ -15,7 +19,8 @@ public function action_htmlLayout($controller, $action=null, $arguments=null)
*/
public function outputLayout(){
//set layout - read from config file
- $layout = 'LayoutAdmin';
+ $layout = Kohana::config($this->subRequest->controller() . '.layout');
+ echo $layout;
$layoutView = View::Factory($layout);
//get js and css for this layout .. ??? not the way to do this
View
60 modules/mopcore/classes/mop.php
@@ -159,8 +159,8 @@ public static function buildModule($module, $constructorArguments=array() ){
if(!Kohana::find_file('controllers', $module['modulename'] ) ){
if(!isset($module['controllertype'])){
$view = new View($module['modulename']);
- $object = ORM::Factory('page', $module['modulename']);
- if($object->loaded){ // in this case it's a slug for a specific object
+ $object = ORM::Factory('page')->where('slug', '=', $module['modulename'])->find();
+ if($object->loaded()){ // in this case it's a slug for a specific object
foreach(mop::getViewContent($object->id, $object->template->templatename) as $key=>$content){
$view->$key = $content;
}
@@ -205,63 +205,63 @@ public static function buildModule($module, $constructorArguments=array() ){
}
}
- public static function getViewContent($view, $slug=null){
+ public static function getViewContent($view, $slug=null) {
$data = array();
- if($view == 'default'){
- $object = ORM::Factory('page', $slug);
- if(!$object->loaded){
- die('mop::getViewContent : Default view callled with no slug');
+ if ($view == 'default') {
+ $object = ORM::Factory('page')->where('slug', '=', $slug)->find();
+ if (!$object->loaded()) {
+ throw new Koahan_Exception('mop::getViewContent : Default view callled with no slug');
}
$data['content']['main'] = $object->getPageContent();
- return $data;
- }
+ return $data;
+ }
$viewConfig = mop::config('frontend', "//view[@name=\"$view\"]")->item(0);
- if(!$viewConfig){
+ if (!$viewConfig) {
die("No View setup in frontend.xml by that name: $view");
}
- if($viewConfig->getAttribute('loadPage')){
- $object = ORM::Factory('page', $slug);
- if(!$object->loaded){
- die('mop::getViewContent : View specifies loadPage but no page to load');
+ if ($viewConfig->getAttribute('loadPage')) {
+ $object = ORM::Factory('page')->where('slug', '=', $slug)->find();
+ if (!$object->loaded()) {
+ throw new Kohana_Exception('mop::getViewContent : View specifies loadPage but no page to load');
}
$data['content']['main'] = $object->getPageContent();
- }
+ }
- $includeContent = mop::getIncludeContent($viewConfig, $object->id);
- foreach($includeContent as $key=>$values){
- $data['content'][$key] = $values;
- }
+ $includeContent = mop::getIncludeContent($viewConfig, $object->id);
+ foreach ($includeContent as $key => $values) {
+ $data['content'][$key] = $values;
+ }
- if($subViews = mop::config('frontend',"subView", $viewConfig)){
- foreach($subViews as $subview){
+ if ($subViews = mop::config('frontend', "subView", $viewConfig)) {
+ foreach ($subViews as $subview) {
$view = $subview->getAttribute('view');
$slug = $subview->getAttribute('slug');
$label = $subview->getAttribute('label');
- if(mop::config('frontend', "//view[@name=\"$view\"]")){
+ if (mop::config('frontend', "//view[@name=\"$view\"]")) {
- if($view && $slug){
+ if ($view && $slug) {
$subViewContent = mop::getViewContent($view, $slug);
- } else if($slug){
- $object = ORM::Factory('page', $slug);
+ } else if ($slug) {
+ $object = ORM::Factory('page')->where('slug', '=', $slug)->find();
$view = $object->template->templatename;
$subViewContent = mop::getViewContent($view, $slug);
- } else if($view){
+ } else if ($view) {
$subViewContent = mop::getViewContent($view);
} else {
die("subview $label must have either view or slug");
}
$subView = new View($view);
- foreach($subViewContent as $key=>$content){
+ foreach ($subViewContent as $key => $content) {
$subView->$key = $content;
}
$data[$label] = $subView->render();
} else {
//assume it's a module
- $data[$label] = mop::buildModule(array('modulename'=>$view/*, 'controllertype'=>'object'*/), $subview->getAttribute('label'));
+ $data[$label] = mop::buildModule(array('modulename' => $view/* , 'controllertype'=>'object' */), $subview->getAttribute('label'));
}
}
}
@@ -269,7 +269,7 @@ public static function getViewContent($view, $slug=null){
return $data;
}
- function getIncludeContent($includeTier, $parentid){
+ public static function getIncludeContent($includeTier, $parentid){
$content = array();
if($eDataNodes = mop::config('frontend',"includeData", $includeTier)){
foreach($eDataNodes as $eDataConfig){
@@ -281,7 +281,7 @@ function getIncludeContent($includeTier, $parentid){
if($from=='parent'){
$objects->where('parentid', '=', $parentid);
} else {
- $from = ORM::Factory('page', $from);
+ $from = ORM::Factory('page')->where('id', '=', $from)->find();
$objects->where('parentid', '=', $from->id);
}
}
View
11 modules/mopcore/init.php
@@ -36,13 +36,16 @@
)
);
-Route::set('layout', 'mop:(<request>)')
+Route::set('layout', 'mop:(<request>)', array(
+ 'request' => '[A-z\/0-9\-]++'
+ )
+ )
->defaults(
array(
- 'controller'=>'layout',
- 'action'=>'htmlLayout'
+ 'controller' => 'layout',
+ 'action' => 'htmlLayout'
)
- );
+);
//using the framework means that other controllers aren't going to automatically load via the default
View
32 modules/mopcore/views/LayoutPublic.php
@@ -1,5 +1,33 @@
-<?=$header;?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <meta http-equiv="content-script-type" content="text/javascript">
+
+ <title>MoPCMS &ldquo;It's Made of People!&rdquo;</title>
+
+<!--
+This needs to be taken out
+-->
+ <base href="<?=Request::initial()->protocol();?>://<?=$_SERVER['HTTP_HOST'];?><?=substr($_SERVER['SCRIPT_NAME'],0,-9);?>" />
+
+ <?=$stylesheet;?>
+ <?=$javascript;?>
+
+</head>
+<body class="">
+ <div id="container" class="container_12">
+
+<?=Request::Factory('header/public')->execute()->body();?>
+<?=Request::Factory('publicmenu')->execute()->body();?>
<?=$body;?>
-<?=$footer;?>
+<?=Request::Factory('footer/public')->execute()->body();?>
+
+ </div>
+</body>
+</html>
View
88 modules/mopfrontend/classes/controller/mopfrontend.php
@@ -0,0 +1,88 @@
+<?
+/*
+ * Class: Site_Controller
+ * Responsible for handing default behaviour of CMS driven sites,
+ * using slugs or ids to navigate between pages. Works hand in
+ * hand with the slugs hook
+ */
+Class Controller_MopFrontend extends Controller_Layout{
+
+ public static $slug;
+
+ /*
+ * Variable: $content
+ * Holds the content for a page
+ */
+ protected $content = array();
+
+ /*
+ * Function: index
+ * Wrapper to page that uses the controller as the slug
+ */
+ public function action_index(){
+ $this->action_page(substr(get_class($this), 0, -11));
+ }
+
+ public function validSlug($uri){
+
+ echo 'made it here!!!';
+ }
+
+
+
+ /*
+ * Function: page($pageidorslug)
+ * By default called after a rewrite of routing by slugs hooks, gets all content
+ * for an object and loads
+ * Parameters:
+ * $pageidorslug - the id or slug of the object to display, null is allowed but causes exception
+ * Returns: nothing, renders full webpage to browser or sents html if AJAX request
+ */
+
+ public function action_page($pageidorslug=null) {
+
+ self::$slug = $pageidorslug;
+
+ $page = ORM::Factory('page')->where('slug', '=', $pageidorslug)->find();
+ //some access control
+ $viewName = null;
+ if ($page->loaded()) {
+ if ($page->published == false || $page->activity != null) {
+ throw new Kohana_User_Exception('Page not availabled', 'The page with identifier ' . $id . ' is does not exist or is not available');
+ }
+ //look for the template, if it's not there just print out all the data raw
+ $viewName = $page->template->templatename;
+ $viewPath = $viewName;
+ if (file_exists('application/views/frontend/' . $viewName . '.php')) {
+ $viewPath = 'frontend/'.$viewPath;
+ } else if(file_exists('application/views/generated/' . $viewPath . '.php')) {
+ $viewPath = 'generated/'.$viewPath;
+ } else {
+ $viewPath = 'default';
+ }
+ $this->view = new View($viewPath);
+ } else {
+ //check for a virtual page specified in frontend.xml
+ //a virtual page will be one that does not match a template
+ $viewname = $pageidorslug;
+ $this->view = new View($viewname);
+ }
+
+ //call this->view load data
+ //get all the data for the page
+ $viewContent = mop::getViewContent($viewName, $pageidorslug);
+ foreach ($viewContent as $key => $value) {
+ $this->view->$key = $value;
+ }
+
+ //possible hook for processing content
+
+ $this->response->body($this->view->render());
+
+
+ }
+
+
+
+
+}
View
53 modules/mopfrontend/classes/controller/publicmenu.php
@@ -0,0 +1,53 @@
+<?
+
+Class Controller_PublicMenu extends Controller_MOP {
+
+
+ public function action_index(){
+ $this->view = new View('publicnav');
+
+ $topLevel = ORM::Factory('page')
+ ->where('parentid', '=', 0)
+ ->publishedFilter()
+ ->noContainerObjects()
+ ->find_all();
+ //need ignores
+
+ $navi = array();
+ foreach($topLevel as $object){
+ $entry = array();
+ $entry['title'] = $object->contenttable->title;
+ $entry['slug'] = $object->slug;
+ $entry['path'] = $object->slug;
+
+ $navi[$object->slug] = $entry;
+ }
+
+ //check for children
+ foreach($navi as $slug => $entry){
+
+ $object = ORM::Factory('page', $slug);
+ $children = ORM::Factory('page')
+ ->where('parentid', '=', $object->id)
+ ->publishedFilter()
+ ->noContainerObjects()
+ ->find_all();
+ if(count($children)){
+ $entry['children'] = array();
+ foreach($children as $child){
+ $childEntry = array();
+ $childEntry['title'] = $child->contenttable->title;
+ $childEntry['slug'] = $child->slug;
+ $childEntry['path'] = $object->slug.'/'.$child->slug;
+ $navi[$slug]['children'][] = $childEntry;
+ }
+ }
+ }
+
+
+ $this->view->navi = $navi;
+ $this->response->body($this->view->render());
+
+ }
+
+}
View
8 modules/mopfrontend/config/mopfrontend.php
@@ -0,0 +1,8 @@
+<?
+
+$config['navigationRequest'] = 'navigation';
+
+$config['layout'] = 'LayoutPublic';
+//$config['authrole'] = 'admin';
+
+return $config;
View
12 modules/mopfrontend/init.php
@@ -0,0 +1,12 @@
+<?
+
+Route::set('mopCmsSlugs', '<uri>',
+ array(
+ 'uri'=>'mopfrontend/validSlug',
+ )
+)
+->defaults(
+ array(
+ 'controller'=>'mopsite',
+ 'action'=>'page'
+ ));
View
13 modules/mopfrontend/views/publicnav.php
@@ -0,0 +1,13 @@
+<ul>
+<?foreach($navi as $page):?>
+ <li id="<?=$page['slug'];?>"><a href="<?=$page['path'];?>"><?=$page['title'];?></a></li>
+ <?if(isset($page['children'])):?>
+ <ul>
+ <?foreach($page['children'] as $child):?>
+ <li id="<?=$child['slug'];?>"><a href="<?=$child['path'];?>"><?=$child['title'];?></a></li>
+ <?endforeach;?>
+ </ul>
+ <?endif;?>
+<?endforeach;?>
+</ul>
+
Please sign in to comment.
Something went wrong with that request. Please try again.