Changeset 109
- Timestamp:
- 07/18/07 15:04:22 (1 year ago)
- Files:
-
- branch/controllers/posts_controller.php (modified) (5 diffs)
- branch/models/post.php (modified) (5 diffs)
- branch/views/posts/add.ctp (modified) (1 diff)
- branch/views/posts/admin_edit.ctp (modified) (3 diffs)
- branch/views/posts/admin_index.ctp (modified) (1 diff)
- branch/views/posts/admin_view.ctp (modified) (1 diff)
- branch/views/posts/edit.ctp (modified) (1 diff)
- branch/views/posts/view.ctp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branch/controllers/posts_controller.php
r108 r109 5 5 var $uses = array('Post', 'Group'); 6 6 // Set the default Paginate values 7 var $paginate = array('fields'=>array('Post.id', 'Post.title', 'Post.byline', 'Post.body', 'Post.comments_count' ,'Post.user_id', 'Post.stub' ,'Post.post_date' , 'Post.access_level', 'Post.frontpage' ,'Post.published' ,'User.id', 'User.username', 'Subject.id' ,'Subject.title', 'Image.filename'),'limit'=>10, 'order'=>array('Post.post_date'=>'DESC', 'Post.created' => 'DESC')); 7 var $paginate = array('fields'=> 8 array( 'Post.id','Post.title','Post.byline','Post.body','Post.comments_count', 9 'Post.user_id','Post.slug','Post.post_date','Post.access_level', 10 'Post.frontpage','Post.published','User.id','User.username','User.posts_count', 'Subject.id', 11 'Subject.title','Image.filename'), 12 'limit'=>10, 13 'order'=>array('Post.post_date'=>'DESC', 'Post.created' => 'DESC') 14 ); 8 15 9 16 function index() { 10 17 // Increase recursion to get post tags and comments 11 18 $this->Post->recursive = 1; 12 13 19 // Check to see if RSS request instead of normal. 14 20 $isFeed = ife($this->RequestHandler->prefers('rss') == 'rss', true, false); … … 32 38 33 39 // The view function finds by Stub instead of ID for SEO. 34 function view($ id= null) {40 function view($stub = null) { 35 41 if(!$id) { 36 42 $this->Session->setFlash('Invalid Post.'); 37 43 $this->redirect(array('action'=>'index'), null, true); 38 44 } 39 $this->set('post', $this->Post->findByStub($ id));45 $this->set('post', $this->Post->findByStub($stub)); 40 46 } 41 47 42 48 function add() { 43 if(!empty($this->data)) { 44 $this->cleanUpFields(); 45 $this->Post->create(); 46 if($this->Post->save($this->data)) { 47 $this->Session->setFlash('The Post has been saved'); 48 $this->redirect(array('action'=>'index'), null, true); 49 } else { 50 $this->Session->setFlash('The Post could not be saved. Please, try again.'); 49 if ($this->level >= 500 ) { 50 if(!empty($this->data)) { 51 $this->data['Post']['user_id'] = $this->othAuth->user('id'); 52 $this->cleanUpFields(); 53 $this->Post->create(); 54 if($this->Post->save($this->data)) { 55 $this->Session->setFlash('The Post has been saved'); 56 $this->redirect(array('action'=>'index'), null, true); 57 } else { 58 $this->Session->setFlash('The Post could not be saved. Please, try again.'); 59 } 51 60 } 61 } else { 62 $this->Session->setFlash('You do not have permission to add a post. Please log in.'); 63 $this->redirect(array('controller' => 'users','action'=>'login'), null, true); 52 64 } 53 $tags = $this->Post->Tag->generateList(); 54 $users = $this->Post->User->generateList(); 55 $subjects = $this->Post->Subject->generateList(); 56 $this->set(compact('tags', 'users', 'subjects')); 65 $this->set('access_levels', $this->Group->generateList(null, 'Group.name ASC', null,'{n}.Group.level', '{n}.Group.name')); 66 $this->set('subjects', $this->Post->Subject->generateList()); 67 $this->set('images', $this->Post->Image->generateList(null,null,null,'{n}.Image.id', '{n}.Image.alt')); 57 68 } 58 69 59 70 function edit($id = null) { 60 if(!$id && empty($this->data)) { 61 $this->Session->setFlash('Invalid Post'); 62 $this->redirect(array('action'=>'index'), null, true); 63 } 64 if(!empty($this->data)) { 65 $this->cleanUpFields(); 66 if($this->Post->save($this->data)) { 67 $this->Session->setFlash('The Post saved'); 71 if ($this->othAuth->user('id') == $this->data['Post']['user_id'] || $this->level >= 900) { 72 if(!$id && empty($this->data)) { 73 $this->Session->setFlash('Invalid Post'); 68 74 $this->redirect(array('action'=>'index'), null, true); 69 } else {70 $this->Session->setFlash('The Post could not be saved. Please, try again.');71 75 } 76 if(!empty($this->data)) { 77 $this->cleanUpFields(); 78 if($this->Post->save($this->data)) { 79 $this->Session->setFlash('The Post saved'); 80 $this->redirect(array('action'=>'index'), null, true); 81 } else { 82 $this->Session->setFlash('The Post could not be saved. Please, try again.'); 83 } 84 } 85 } else { 86 $this->Session->setFlash('You do no have permission to edit this post'); 87 $this->redirect(array('controller'=>'users','action'=>'login'), null, true); 72 88 } 73 89 if(empty($this->data)) { 74 90 $this->data = $this->Post->read(null, $id); 75 91 } 76 $tags = $this->Post->Tag->generateList(); 77 $users = $this->Post->User->generateList(); 78 $subjects = $this->Post->Subject->generateList(); 79 $this->set(compact('tags','users','subjects')); 92 $this->set('access_levels', $this->Group->generateList(null, 'Group.name ASC', null,'{n}.Group.level', '{n}.Group.name')); 93 $this->set('subjects', $this->Post->Subject->generateList()); 94 $this->set('images', $this->Post->Image->generateList(null,null,null,'{n}.Image.id', '{n}.Image.alt')); 80 95 } 81 96 … … 85 100 $this->redirect(array('action'=>'index'), null, true); 86 101 } 87 if($this->Post->del($id)) { 88 $this->Session->setFlash('Post #'.$id.' deleted'); 89 $this->redirect(array('action'=>'index'), null, true); 102 if ($this->othAuth->user('id') == $this->data['Post']['user_id'] || $this->level >= 900) { 103 if($this->Post->del($id)) { 104 $this->Session->setFlash('Post #'.$id.' deleted'); 105 $this->redirect(array('action'=>'index'), null, true); 106 } 107 } else { 108 $this->Session->setFlash('You do no have permission to edit this post'); 109 $this->redirect(array('controller'=>'users','action'=>'login'), null, true); 90 110 } 91 111 } … … 93 113 94 114 function admin_index() { 115 // Increase recursion to get post tags and comments 95 116 $this->Post->recursive = 1; 96 $this->set('posts', $this->paginate()); 117 // Check to see if RSS request instead of normal. 118 $isFeed = ife($this->RequestHandler->prefers('rss') == 'rss', true, false); 119 // provide different title and a description for the feed 120 if ($isFeed) { 121 $this->set('channel', array('title' => 'Latest posts for Webrocket', 'description' => 'Webrocket RSS Feed')); 122 } 123 // Normal action 124 if (!$isFeed) { 125 // Overide paginate limit, may need to change 126 $this->cacheAction = '1 hour'; 127 $this->passedArgs['limit'] = 10; 128 $this->passedArgs['order'] = array('Post.post_date' => 'DESC', 'Post.created' => 'DESC'); 129 $this->set('posts', $this->paginate(null, array('Post.published'=>1, 'Post.frontpage' => 1 ,'Post.access_level' => '<= ' . $this->level ))); 130 $this->set('postcount', $this->Post->postCount()); 131 } else { 132 // RSS Feed 133 $this->set('posts', $this->Post->findAll(null, null, array('Post.created' => 'DESC'), 20)); 134 } 97 135 } 98 136 … … 141 179 $this->set('access_levels', $this->Group->generateList(null, 'Group.name ASC', null,'{n}.Group.level', '{n}.Group.name')); 142 180 $this->set('subjects', $this->Post->Subject->generateList()); 181 $this->set('images', $this->Post->Image->generateList(null,null,null,'{n}.Image.id', '{n}.Image.alt')); 143 182 } 144 183 branch/models/post.php
r89 r109 20 20 //The Associations below have been created with all possible keys, those that are not needed can be removed 21 21 var $belongsTo = array( 22 'User' => array('className' => 'User', 23 'foreignKey' => 'user_id', 24 'conditions' => '', 25 'fields' => '', 26 'order' => '', 27 'counterCache' => ''), 28 'Subject' => array('className' => 'Subject', 29 'foreignKey' => 'subject_id', 30 'conditions' => '', 31 'fields' => '', 32 'order' => '', 33 'counterCache' => ''), 22 'User' => array('className' => 'User'), 23 'Subject' => array('className' => 'Subject'), 34 24 'Image' => array('className' => 'Image') 35 25 ); … … 37 27 var $hasMany = array( 38 28 'Comment' => array('className' => 'Comment', 39 'foreignKey' => 'post_id', 40 'conditions' => '', 41 'fields' => '', 42 'order' => '', 43 'limit' => '', 44 'offset' => '', 45 'dependent' => '', 46 'exclusive' => '', 47 'finderQuery' => '', 48 'counterQuery' => ''), 29 'foreignKey' => 'post_id'), 49 30 ); 50 31 … … 54 35 'foreignKey' => 'post_id', 55 36 'associationForeignKey' => 'tag_id', 56 'conditions' => '',57 'fields' => '',58 37 'order' => 'Tag.tag ASC', 59 'limit' => '', 60 'offset' => '', 61 'unique' => true, 62 'finderQuery' => '', 63 'deleteQuery' => '', 64 'insertQuery' => ''), 38 'unique' => true), 65 39 ); 66 40 … … 69 43 if (empty($this->id)) 70 44 { 71 $this->data[$this->name]['s tub'] = $this->getUniqueUrl($this->data[$this->name]['title'], 'stub');45 $this->data[$this->name]['slug'] = $this->getUniqueUrl($this->data[$this->name]['title'], 'slug'); 72 46 } 73 47 … … 86 60 $this->savefield('published', 0); 87 61 } 62 63 function postCount() 64 { 65 $postcount = $this->findCount(); 66 return $postcount; 67 } 88 68 } 89 69 ?> branch/views/posts/add.ctp
r55 r109 1 <?php //e($javascript->codeBlock('$j.ready(function() {$("#PostAddForm").ajaxSubmit(function() { var options = { target: ".post" }; });});'));?> 2 3 <div class="success" style="display:none;"> 4 <h2>Post has successfuly saved.</h2> 5 </div> 6 1 7 <div class="post"> 2 8 <h2>New Post</h2> 3 9 <?php echo $form->create('Post');?> 4 <?php echo $form->input('title', array('class' => 'required'));?> 5 <?php echo $form->input('byline', array('class' => 'required'));?> 6 <?php echo $form->input('body', array('class' => 'required'));?> 7 <?php echo $form->input('post_date', array('class' => 'required'));?> 8 <?php echo $form->input('comments_count', array('class' => 'required'));?> 9 <?php echo $form->input('user_id', array('class' => 'required', 'options' => $users));?> 10 <?php echo $form->input('subject_id', array('class' => 'required', 'options' => $subjects));?> 11 <?php echo $form->input('access_level', array('class' => 'required'));?> 12 <?php echo $form->input('stub', array('class' => 'required'));?> 13 <?php echo $form->input('tags', array('class' => 'required'));?> 14 <?php echo $form->input('frontpage');?> 15 <?php echo $form->input('published', array('class' => 'required'));?> 16 <?php echo $form->input('Tag/Tag', array('options' => $tags, 'multiple' => 'multiple'));?> 17 <?php echo $form->submit('Add');?> 10 <fieldset id="main-content"> 11 <legend>Main Content</legend> 12 <?php echo $form->input('title', array('class' => 'required'));?> 13 <?php echo $form->input('byline', array('class' => 'required'));?> 14 <?php echo $form->input('body',array('class'=>'wymeditor'));?> 15 <?php e($form->input('image_id', array('options'=>$images)));?> 16 <a href="/admin/images/add?KeepThis=true&TB_iframe=true&height=400&width=600" id="add-image" class="thickbox">Upload New Image</a> 17 </fieldset> 18 19 <fieldset id="meta-content"> 20 <legend>Meta Data</legend> 21 <?php echo $form->input('subject_id', array('class' => 'required', 'options' => $subjects));?> 22 <?php echo $form->input('tags', array('class' => 'tags', 'type'=>'text'));?> 23 </fieldset> 24 25 <fieldset id="publishing-options"> 26 <legend>Publishing Options</legend> 27 <?php echo $form->input('post_date', array('class' => 'required'));?> 28 <?php echo $form->input('access_level', array('class' => 'required', 'options'=>$access_levels));?> 29 <?php echo $form->input('frontpage');?> 30 <?php echo $form->input('published', array('class' => 'required'));?> 31 </fieldset> 32 33 <?php echo $form->submit('Add', array('class'=>'wymupdate'));?> 18 34 </form> 19 35 </div> 20 <div class="actions">21 <ul>22 <li><?php echo $html->link('List Posts', array('action'=>'index')); ?></li>23 <li><?php echo $html->link('View Users', array('controller'=> 'users', 'action'=>'view'));?></li>24 <li><?php echo $html->link('Add Users', array('controller'=> 'users', 'action'=>'add')); ?></li>25 <li><?php echo $html->link('View Subjects', array('controller'=> 'subjects', 'action'=>'view'));?></li>26 <li><?php echo $html->link('Add Subjects', array('controller'=> 'subjects', 'action'=>'add')); ?></li>27 </ul>28 </div>branch/views/posts/admin_edit.ctp
r68 r109 1 <?php //e($javascript->codeBlock('$j.ready(function() {$("#PostAddForm").ajaxSubmit(function() { var options = { target: ".post" }; });});'));?> 2 3 <div class="success" style="display:none;"> 4 <h2>Post has successfuly saved.</h2> 5 </div> 6 1 7 <div class="post"> 2 <h2> NewPost</h2>8 <h2>Edit Post</h2> 3 9 <?php echo $form->create('Post');?> 4 10 <fieldset id="main-content"> … … 7 13 <?php echo $form->input('title', array('class' => 'required'));?> 8 14 <?php echo $form->input('byline', array('class' => 'required'));?> 9 <?php echo $form->input('body', array('class'=>'wymeditor'));?> 10 <?php echo $form->input('user_id', array('class' => 'required'));?> 15 <?php echo $form->input('body',array('class'=>'wymeditor'));?> 16 <?php e($form->input('image_id', array('options'=>$images)));?> 17 <a href="/admin/images/add?KeepThis=true&TB_iframe=true&height=400&width=600" id="add-image" class="thickbox">Upload New Image</a> 11 18 </fieldset> 12 19 … … 25 32 </fieldset> 26 33 27 <?php echo $form->submit('Update', array('class'=>'wymupdate'));?> 28 <li><?php echo $html->link('Delete', array('action'=>'delete', $html->tagValue('Post/id')), null, 'Are you sure you want to delete #' . $html->tagValue('Post/id')); ?> 34 <?php echo $form->submit('Add', array('class'=>'wymupdate'));?> 29 35 </form> 30 36 </div> branch/views/posts/admin_index.ctp
r108 r109 2 2 <div class="posts"> 3 3 <h2>List Posts</h2> 4 <div> 5 Overall there are <?php e($postcount);?> posts on this site.<br /> 6 From these posts, <?php e($posts[0]['User']['posts_count']);?> are yours. 7 </div> 4 8 5 9 <table cellpadding="0" cellspacing="0"> branch/views/posts/admin_view.ctp
r57 r109 1 1 <div class="hentry"> 2 <h2 class="entry-title"><?php e($html->link($post['Post']['title'], array('controller'=>'posts', 'action'=>'view', $post['Post']['stub']))); ?></h2> 3 <?php echo $html->link('Edit', array('action'=>'edit', $post['Post']['id'])); ?> 4 <abbr class="updated" title=""><?php echo $post['Post']['post_date']; ?></abbr> 5 <span class="vcard author"><?php echo $html->link($post['User']['username'], array('controller'=> 'users', 'action'=>'view', $post['User']['id'])); ?></span> 6 <div class="entry-content"> 7 <?php echo $post['Post']['body']; ?> 8 </div> 9 10 <div class="meta"> 11 Comments: <?php echo $post['Post']['comments_count']; ?><br /> 12 Tags: <?php foreach ($post['Tag'] as $tag) : 13 e($html->link($tag['tag'], 'http://technorati.com/tag/' . $tag['tag'], array('rel'=>'tag', 'class'=>'tag'))); 14 endforeach; 2 <h2 class="entry-title"><?php e($html->link($post['Post']['title'], array('controller'=>'posts', 'action'=>'view', $post['Post']['stub']))); ?></h2> 3 <?php echo $html->link('Edit', array('action'=>'edit', $post['Post']['id'])); ?> 4 <abbr class="updated" title=""><?php echo $post['Post']['post_date']; ?></abbr> 5 <span class="vcard author"><?php echo $html->link($post['User']['username'], array('controller'=> 'users', 'action'=>'view', $post['User']['id'])); ?></span> 6 <div class="entry-content"> 7 <?php echo $post['Post']['body']; ?> 8 </div> 9 <div class="meta"> 10 Comments: <?php echo $post['Post']['comments_count']; ?><br /> 11 Tags: <?php foreach ($post['Tag'] as $tag) : 12 e($html->link($tag['tag'], 'http://technorati.com/tag/' . $tag['tag'], array('rel'=>'tag', 'class'=>'tag'))); 13 endforeach; 15 14 ?> 16 </div>17 18 <span class="version" style="display: none;">0.3</span>19 15 </div> 16 <span class="version" style="display: none;">0.3</span> 17 </div> branch/views/posts/edit.ctp
r55 r109 1 <?php //e($javascript->codeBlock('$j.ready(function() {$("#PostAddForm").ajaxSubmit(function() { var options = { target: ".post" }; });});'));?> 2 3 <div class="success" style="display:none;"> 4 <h2>Post has successfuly saved.</h2> 5 </div> 6 1 7 <div class="post"> 2 8 <h2>Edit Post</h2> 3 9 <?php echo $form->create('Post');?> 4 <?php echo $form->input('id');?> 5 <?php echo $form->input('title', array('class' => 'required'));?> 6 <?php echo $form->input('byline', array('class' => 'required'));?> 7 <?php echo $form->input('body', array('class' => 'required'));?> 8 <?php echo $form->input('post_date', array('class' => 'required'));?> 9 <?php echo $form->input('comments_count', array('class' => 'required'));?> 10 <?php echo $form->input('user_id', array('class' => 'required', 'options' => $users));?> 11 <?php echo $form->input('subject_id', array('class' => 'required', 'options' => $subjects));?> 12 <?php echo $form->input('access_level', array('class' => 'required'));?> 13 <?php echo $form->input('stub', array('class' => 'required'));?> 14 <?php echo $form->input('tags', array('class' => 'required'));?> 15 <?php echo $form->input('frontpage');?> 16 <?php echo $form->input('published', array('class' => 'required'));?> 17 <?php echo $form->input('Tag/Tag', array('options' => $tags, 'multiple' => 'multiple'));?> 18 <?php echo $form->submit('Update');?> 10 <fieldset id="main-content"> 11 <legend>Main Content</legend> 12 <?php echo $form->input('id');?> 13 <?php echo $form->input('title', array('class' => 'required'));?> 14 <?php echo $form->input('byline', array('class' => 'required'));?> 15 <?php echo $form->input('body',array('class'=>'wymeditor'));?> 16 <?php e($form->input('image_id', array('options'=>$images)));?> 17 <a href="/admin/images/add?KeepThis=true&TB_iframe=true&height=400&width=600" id="add-image" class="thickbox">Upload New Image</a> 18 </fieldset> 19 20 <fieldset id="meta-content"> 21 <legend>Meta Data</legend> 22 <?php echo $form->input('subject_id', array('class' => 'required', 'options' => $subjects));?> 23 <?php echo $form->input('tags', array('class' => 'tags', 'type'=>'text'));?> 24 </fieldset> 25 26 <fieldset id="publishing-options"> 27 <legend>Publishing Options</legend> 28 <?php echo $form->input('post_date', array('class' => 'required'));?> 29 <?php echo $form->input('access_level', array('class' => 'required', 'options'=>$access_levels));?> 30 <?php echo $form->input('frontpage');?> 31 <?php echo $form->input('published', array('class' => 'required'));?> 32 </fieldset> 33 34 <?php echo $form->submit('Add', array('class'=>'wymupdate'));?> 19 35 </form> 20 36 </div> 21 <div class="actions">22 <ul>23 <li><?php echo $html->link('Delete', array('action'=>'delete', $html->tagValue('Post/id')), null, 'Are you sure you want to delete #' . $html->tagValue('Post/id')); ?>24 <li><?php echo $html->link('List Posts', array('action'=>'index')); ?></li>25 <li><?php echo $html->link('View Users', array('controller'=> 'users', 'action'=>'view')); ?></li>26 <li><?php echo $html->link('Add Users', array('controller'=> 'users', 'action'=>'add')); ?></li>27 <li><?php echo $html->link('View Subjects', array('controller'=> 'subjects', 'action'=>'view')); ?></li>28 <li><?php echo $html->link('Add Subjects', array('controller'=> 'subjects', 'action'=>'add')); ?></li>29 </ul>30 </div>branch/views/posts/view.ctp
r72 r109 1 1 <div class="hentry"> 2 <h2 class="entry-title"><?php e($html->link($post['Post']['title'], array('controller'=>'posts', 'action'=>'view', $post['Post']['stub']))); ?></h2> 3 <?php echo $html->link('Edit', array('action'=>'edit', $post['Post']['id'])); ?> 4 <abbr class="updated" title=""><?php echo $post['Post']['post_date']; ?></abbr> 5 <span class="vcard author"><?php echo $html->link($post['User']['username'], array('controller'=> 'users', 'action'=>'view', $post['User']['id'])); ?></span> 6 7 <div class="entry-content"> 8 <?php echo $post['Post']['body']; ?> 9 </div> 10 11 <div class="meta"> 12 Comments: <?php echo $post['Post']['comments_count']; ?><br /> 13 Tags: <?php foreach ($post['Tag'] as $tag) : 14 e($html->link($tag['tag'], 'http://technorati.com/tag/' . $tag['tag'], array('rel'=>'tag', 'class'=>'tag'))); 15 endforeach; 2 <h2 class="entry-title"><?php e($html->link($post['Post']['title'], array('controller'=>'posts', 'action'=>'view', $post['Post']['stub']))); ?></h2> 3 <?php echo $html->link('Edit', array('action'=>'edit', $post['Post']['id'])); ?> 4 <abbr class="updated" title=""><?php echo $post['Post']['post_date']; ?></abbr> 5 <span class="vcard author"><?php echo $html->link($post['User']['username'], array('controller'=> 'users', 'action'=>'view', $post['User']['id'])); ?></span> 6 <div class="entry-content"> 7 <?php echo $post['Post']['body']; ?> 8 </div> 9 <div class="meta"> 10 Comments: <?php echo $post['Post']['comments_count']; ?><br /> 11 Tags: <?php foreach ($post['Tag'] as $tag) : 12 e($html->link($tag['tag'], 'http://technorati.com/tag/' . $tag['tag'], array('rel'=>'tag', 'class'=>'tag'))); 13 endforeach; 16 14 ?> 17 </div>18 19 <span class="version" style="display: none;">0.3</span>20 15 </div> 16 <span class="version" style="display: none;">0.3</span> 17 </div>