6ecf5299be3f4988e02a7cd63abfb69d01254a91

Author: Jeff Loiselle

Date: 2008-12-22 18:26:10 -0500

forgot to commit some stuff last round

diff --git a/TODO b/TODO index 3ba056f..4e3207e 100644 --- a/TODO +++ b/TODO @@ -4,35 +4,12 @@ * refactor CSS * make sure everything is comments * write tests - * FeedBurner Support * Twitter Support - -* serve as an OpenID auth server -* talk to OpenID auth servers - -* navigate away confirmation for forms - -CONTENT FEATURES -* 301 redirects -* add RSS feed to header -* download vcard - -TOOLS -* import from WordPress - -TEMPLATES -* themes -* compatible with WordPress templates - ARCHITECTURE * move configs to key/value pair table for easy upgrades -COMMENTS -* highlight admin posts -* remember me when leaving comments - * Why a new CMS - Built on a framework you can live with CakePHP diff --git a/app_controller.php b/app_controller.php index 0151d20..63d8e12 100755 --- a/app_controller.php +++ b/app_controller.php @@ -37,8 +37,8 @@ class AppController extends Controller { var $components = array('Auth', 'Cookie'); - var $helpers = array('Javascript', 'Form'); - var $uses = array('Config', 'User'); + var $helpers = array('Javascript', 'Form', 'Paginator'); + var $uses = array('User'); #var $view = 'Theme'; #var $theme = 'pressmate'; @@ -112,15 +112,20 @@ class AppController extends Controller { } /** + * determines which area is being requested + */ + function __determineArea() { + // will determine area to write to config, will run domains/subdomains + } + + /** * loads configuration from database */ - function __loadConfig() { - $config = $this->Config->findById(1); - Configure::write('Config', $config['Config']); - + function __loadConfig() { + // $area = $this->__determineArea(); + // Configure::write('Area', $area); $user = $this->User->findById($this->Session->read('Auth.User.id')); - $user = $user['User']; - Configure::write('User', $user); + Configure::write('User', $user['User']); } } diff --git a/app_model.php b/app_model.php index f439ff0..6158641 100755 --- a/app_model.php +++ b/app_model.php @@ -37,5 +37,23 @@ * @subpackage cake.app */ class AppModel extends Model { + + function beforeSave() { + $this->__injectUser(); + return true; + } + + /** + * make sure record is tagged with user_id + */ + function __injectUser() { + $user_id = $_SESSION['Auth']['User']['id']; + if (!isset($this->_schema['user_id'])) { + throw new Exception($this->alias . ' is not being tagged with user_id'); + } + if (empty($this->data[$this->alias]['user_id'])) { + $this->data[$this->alias]['user_id'] = $user_id; + } + } } ?> \ No newline at end of file diff --git a/config/core.php b/config/core.php index 9aa27ea..9219dfd 100755 --- a/config/core.php +++ b/config/core.php @@ -43,6 +43,12 @@ } else { Configure::write('debug', 0); } + + set_exception_handler('pm_exception_handler'); + function pm_exception_handler($exception) { + debug($exception); + } + /** * Application wide charset encoding */ diff --git a/config/sql/data.php b/config/sql/data.php index e4ad0fb..7eaf76e 100644 --- a/config/sql/data.php +++ b/config/sql/data.php @@ -1,6 +1,6 @@ <?php -$data['Status'] = array( +$data['ContentStatus'] = array( array('id' => 1, 'name' => 'Published'), array('id' => 2, 'name' => 'Draft') ); diff --git a/config/sql/schema.php b/config/sql/schema.php index e556735..c8e5446 100644 --- a/config/sql/schema.php +++ b/config/sql/schema.php @@ -1,6 +1,6 @@ <?php /* SVN FILE: $Id$ */ -/* Pressmate schema generated on: 2008-12-17 14:12:25 : 1229541085*/ +/* Pressmate schema generated on: 2008-12-22 18:12:42 : 1229987442*/ class PressmateSchema extends CakeSchema { var $name = 'Pressmate'; @@ -19,6 +19,17 @@ class PressmateSchema extends CakeSchema { 'alias' => array('type' => 'string', 'null' => true, 'default' => NULL), 'lft' => array('type' => 'integer', 'null' => true, 'default' => NULL, 'length' => 10), 'rght' => array('type' => 'integer', 'null' => true, 'default' => NULL, 'length' => 10), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) + ); + var $areas = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); var $aros = array( @@ -29,6 +40,9 @@ class PressmateSchema extends CakeSchema { 'alias' => array('type' => 'string', 'null' => true, 'default' => NULL), 'lft' => array('type' => 'integer', 'null' => true, 'default' => NULL, 'length' => 10), 'rght' => array('type' => 'integer', 'null' => true, 'default' => NULL, 'length' => 10), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); var $aros_acos = array( @@ -46,12 +60,20 @@ class PressmateSchema extends CakeSchema { 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), 'lft' => array('type' => 'integer', 'null' => true, 'default' => NULL), 'rght' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'area_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); var $categories_contents = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'content_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), 'category_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'area_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); var $comments = array( @@ -63,26 +85,40 @@ class PressmateSchema extends CakeSchema { 'url' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); - var $configs = array( + var $content_statuses = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), - 'site_name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), - 'avatar_url' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), - 'google_analytics' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 50), - 'image_path' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), + 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 50), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) + ); + var $content_types = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 100), + 'area_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'integer', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); var $contents = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'title' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), 'body' => array('type' => 'text', 'null' => true, 'default' => NULL), - 'status_id' => array('type' => 'integer', 'null' => true, 'default' => NULL, 'length' => 1), + 'content_status_id' => array('type' => 'integer', 'null' => true, 'default' => NULL, 'length' => 1), 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'updated' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'slug' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), 'commentable' => array('type' => 'integer', 'null' => true, 'default' => NULL), 'redirect_code' => array('type' => 'integer', 'null' => true, 'default' => NULL, 'length' => 3), - 'redirecet_url' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), + 'redirect_url' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), + 'parent_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'lft' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'rght' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'area_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'content_type_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); var $contents_tags = array( @@ -96,26 +132,24 @@ class PressmateSchema extends CakeSchema { 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 100), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); - var $links = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), - 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 100), - 'url' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), - 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) - ); var $redirects = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'from' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), 'to' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); - var $statuses = array( + var $tags = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), - 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 50), + 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 100), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); - var $tags = array( + var $urls = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), - 'name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 100), + 'area_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'url' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); var $users = array( @@ -126,6 +160,10 @@ class PressmateSchema extends CakeSchema { 'last_name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 100), 'email' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200, 'key' => 'unique'), 'avatar_url' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 200), + 'area_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'user_id' => array('type' => 'integer', 'null' => true, 'default' => NULL), + 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'uk_username' => array('column' => 'username', 'unique' => 1), 'uk_email' => array('column' => 'email', 'unique' => 1)) ); } diff --git a/controllers/content_controller.php b/controllers/content_controller.php index e020e3b..b2233dc 100644 --- a/controllers/content_controller.php +++ b/controllers/content_controller.php @@ -4,13 +4,13 @@ class ContentController extends AppController { var $name = 'Content'; var $helpers = array('Html', 'Form', 'Javascript', 'Rss', 'Time', 'Text'); var $components = array('RequestHandler'); - var $uses = array('Content', 'Link'); + var $uses = array('Content'); function beforeFilter() { parent::beforeFilter(); $this->Auth->allow('index'); } - + /** * Dashboard stub */ @@ -24,9 +24,8 @@ class ContentController extends AppController { $contents = $this->Content->findAllBySlug($slug); } else { $this->Content->recursive = 1; - $contents = $this->paginate(array('Content.status_id' => 1)); + $contents = $this->paginate(array('Content.content_status_id' => 1)); } - $links = $this->Link->find('all'); $categories = $this->Content->Category->find('all'); $comments_recent = $this->Content->Comment->find('all'); $this->set(compact('contents', 'categories', 'links', 'comments_recent')); @@ -65,11 +64,13 @@ class ContentController extends AppController { } else { } } + $areas = $this->Content->Area->find('list'); + $content_types = $this->Content->ContentType->find('list'); $categories = $this->Content->Category->find('list'); $tags = $this->Content->Tag->find('list'); - $statuses = $this->Content->Status->find('list'); + $content_statuses = $this->Content->ContentStatus->find('list'); $commentables = array(1 => 'Yes', 0 => 'No'); - $this->set(compact('categories', 'statuses', 'commentables', 'tags')); + $this->set(compact('areas', 'content_types', 'categories', 'content_statuses', 'commentables', 'tags')); } function admin_edit($id = null) { @@ -88,11 +89,13 @@ class ContentController extends AppController { if (empty($this->data)) { $this->data = $this->Content->read(null, $id); } + $areas = $this->Content->Area->find('list'); + $content_types = $this->Content->ContentType->find('list'); $categories = $this->Content->Category->find('list'); $tags = $this->Content->Tag->find('list'); $statuses = $this->Content->Status->find('list'); $commentables = array(1 => 'Yes', 0 => 'No'); - $this->set(compact('categories', 'statuses', 'commentables', 'tags')); + $this->set(compact('areas', 'content_types', 'categories', 'statuses', 'commentables', 'tags')); } function admin_delete($id = null) { diff --git a/controllers/install_controller.php b/controllers/install_controller.php index b05ead3..64ddb2c 100644 --- a/controllers/install_controller.php +++ b/controllers/install_controller.php @@ -1,5 +1,7 @@ <?php +class InstallerException extends Exception {} + class InstallController extends AppController { var $uses = null; @@ -24,18 +26,25 @@ class InstallController extends AppController { if (!empty($this->data)) { - $this->Config = ClassRegistry::init('Config'); + $this->Area = ClassRegistry::init('Area'); $this->Content = ClassRegistry::init('Content'); $this->User = ClassRegistry::init('User'); - if ($this->Config->save($this->data)) { + if ($this->Area->saveAll($this->data, array('validate' => 'first'))) { // mark as installed $this->Session->setFlash(__('Successfully configured system', true)); $file = new File(APP . 'config/INSTALLED'); $file->write(time()); // create initital user + $this->data['User']['area_id'] = $this->Area->id; $this->User->save($this->data['User'], false); + $this->User->saveField('user_id', $this->User->id); + + // update area + $this->Area->saveField('user_id', $this->User->id); + $this->Area->Url->saveField('user_id', $this->User->id); + $this->redirect('/'); } else { $this->Session->setFlash(__('Failed to configure system', true)); @@ -69,12 +78,12 @@ END; $dir = APP . 'webroot/upload/'; if (!is_writable($dir)) { $this->Session->setFlash(__('Please make sure /webroot/upload is writable by the webserver', true), null, null, 'error'); - throw new Exception(); + throw new InstallerException(); } $dir = APP . 'config/'; if (!is_writable($dir)) { $this->Session->setFlash(__('Please make sure /config is writable by the webserver', true), null, null, 'error'); - throw new Exception(); + throw new InstallerException(); } else { $file = new File($dir . 'database.php'); if (!$file->write('<?php '.$config.' ?>')) { @@ -91,7 +100,7 @@ END; $this->Session->setFlash(__('Failed to drop old database', true), null, null, 'error'); throw new Exception(); } - + if (!$db->execute('CREATE DATABASE '.$database)) { $this->Session->setFlash(__('Failed to create database', true), null, null, 'error'); throw new Exception(); @@ -116,10 +125,12 @@ END; $model->save($r); } } - + $this->redirect('/install/configure'); - } catch (Exception $e) {} + } catch (InstallerException $e) { + + } } } diff --git a/controllers/redirects_controller.php b/controllers/redirects_controller.php index 7521a2d..b835e77 100644 --- a/controllers/redirects_controller.php +++ b/controllers/redirects_controller.php @@ -1,7 +1,7 @@ <?php class RedirectsController extends AppController { - + var $layout = 'admin'; var $scaffold; } diff --git a/models/content.php b/models/content.php index 126a851..2618ea7 100644 --- a/models/content.php +++ b/models/content.php @@ -4,7 +4,7 @@ class Content extends AppModel { var $actsAs = array('Sluggable'); var $hasMany = array('Comment'); - var $belongsTo = array('Status', 'User'); + var $belongsTo = array('Area', 'User', 'ContentType', 'ContentStatus'); var $hasAndBelongsToMany = array('Category', 'Tag'); var $validate = array( @@ -13,8 +13,7 @@ class Content extends AppModel { 'message' => 'Only letters, numbers, spaces, commas, periods, and hyphens allowed' ) ); - - + } ?> \ No newline at end of file diff --git a/models/content_status.php b/models/content_status.php index 4808edb..1efa452 100644 --- a/models/content_status.php +++ b/models/content_status.php @@ -1,6 +1,6 @@ <?php -class Status extends AppModel { +class ContentStatus extends AppModel { } diff --git a/views/content/admin_add.ctp b/views/content/admin_add.ctp index 09aab3a..83cc3c1 100644 --- a/views/content/admin_add.ctp +++ b/views/content/admin_add.ctp @@ -41,7 +41,9 @@ <?php echo $form->input('title'); echo $form->input('body'); - echo $form->input('status_id'); + echo $form->input('area_id'); + echo $form->input('content_type_id'); + echo $form->input('content_status_id'); echo $form->input('commentable'); echo $form->input('redirect_code'); echo $form->input('redirect_url'); diff --git a/views/content/admin_edit.ctp b/views/content/admin_edit.ctp index 6f8f3ac..0aa83b1 100644 --- a/views/content/admin_edit.ctp +++ b/views/content/admin_edit.ctp @@ -42,7 +42,9 @@ echo $form->input('id'); echo $form->input('title'); echo $form->input('body'); - echo $form->input('status_id'); + echo $form->input('area_id'); + echo $form->input('content_type_id'); + echo $form->input('content_status_id'); echo $form->input('commentable'); echo $form->input('redirect_code'); echo $form->input('redirect_url'); diff --git a/views/content/index.ctp b/views/content/index.ctp index a90c53e..b0aec32 100644 --- a/views/content/index.ctp +++ b/views/content/index.ctp @@ -1,6 +1,6 @@ <div id="column_right"> <?php if (!$session->read('Auth')) print $this->renderElement('login')?> - <?php print $this->renderElement('links', compact('links')) ?> + <?php #print $this->renderElement('links', compact('links')) ?> <?php print $this->renderElement('categories', compact('categories')) ?> <?php print $this->renderElement('comments_recent', compact('comments_recent')) ?> </div> diff --git a/views/install/configure.ctp b/views/install/configure.ctp index b0f0ec8..5547442 100644 --- a/views/install/configure.ctp +++ b/views/install/configure.ctp @@ -1,11 +1,17 @@ +<script> +$(document).ready(function(){ + $("#AreaName").focus(); + }); +</script> + <h1><?php __('PressMate Installation') ?></h1> <fieldset> <legend><?php __('Configuration') ?></legend> -<?php print $form->create('Config', array('url' => '/install/configure')) ?> -<?php print $form->hidden('id', array('value' => 1))?> -<?php print $form->input('site_name') ?> -<?php print $form->input('image_path', array('value' => 'upload/'))?> +<?php print $form->create('Area', array('url' => '/install/configure')) ?> +<?php print $form->hidden('Area.id', array('value' => 1))?> +<?php print $form->input('Area.name') ?> +<?php print $form->input('Url.0.url') ?> <?php print $form->input('User.first_name') ?> <?php print $form->input('User.last_name') ?> <?php print $form->input('User.email') ?> diff --git a/views/layouts/admin.ctp b/views/layouts/admin.ctp index cc4ea86..dca6815 100644 --- a/views/layouts/admin.ctp +++ b/views/layouts/admin.ctp @@ -140,13 +140,21 @@ </ul> </div> </div> - + </li> + <li class="yuimenubaritem"><a class="yuimenubaritemlabel" href="<?php print Router::url('/areas') ?>">Areas</a> + <div id="areas" class="yuimenu"> + <div class="bd"> + <ul> + <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<?php print Router::url('/admin/areas/add') ?>">Create Area</a></li> + <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<?php print Router::url('/admin/areas/') ?>">Manage Area</a></li> + </ul> + </div> + </div> </li> <li class="yuimenubaritem"><a class="yuimenubaritemlabel" href="<?php print Router::url('/admin/config') ?>">Options</a> <div id="entertainment" class="yuimenu"> <div class="bd"> <ul> - <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<?php print Router::url('/admin/config') ?>">Configuration</a></li> <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<?php print Router::url('/redirects') ?>">Redirect Manager</a></li> </ul> </div>