Skip to content

Commit

Permalink
Merge pull request #25 from Clidus/dev
Browse files Browse the repository at this point in the history
Version 0.5.0
  • Loading branch information
Clidus committed Aug 21, 2016
2 parents 95b8c11 + f0a814b commit 36321c0
Show file tree
Hide file tree
Showing 38 changed files with 3,748 additions and 312 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,3 +1,4 @@
*.scssc

node_modules/
.vscode
node_modules/
images/blog
5 changes: 3 additions & 2 deletions Gulpfile.js
Expand Up @@ -16,14 +16,15 @@ gulp.task('scss', function () {
});

gulp.task('css', function () {
return gulp.src(['./style/css/bootstrap.min.css','./style/css/ignition.css'])
return gulp.src(['./style/css/bootstrap.min.css','./style/css/bootstrap-markdown.min.css','./style/css/ignition.css'])
.pipe(concat('ignition.css'))
.pipe(gulp.dest('./style/crushed'));
});

gulp.task('js', function () {
return gulp.src(['./script/js/jquery-2.0.3.min.js','./script/js/jquery.autogrow-textarea.js','./script/js/bootstrap.min.js',
'./script/js/admin.js','./script/js/comments.js','./script/js/global.js'])
'./script/js/markdown.js','./script/js/bootstrap-markdown.js','./script/js/admin.js','./script/js/comments.js',
'./script/js/global.js'])
.pipe(uglify())
.pipe(concat('ignition.js'))
.pipe(gulp.dest('./script/crushed'))
Expand Down
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -33,7 +33,9 @@ This software uses the following software and services, for which we are thankfu
* [CodeIgniter](http://www.codeigniter.com/)
* [PHP Markdown](http://michelf.ca/projects/php-markdown/)
* [Markdown library for CodeIgniter](http://blog.gauntface.co.uk/2014/03/17/codeigniter-markdown-libraries-hell/)
* [markdown-js](https://github.com/evilstreak/markdown-js)
* [Bootstrap](http://getbootstrap.com/)
* [Bootstrap Markdown](http://www.codingdrama.com/bootstrap-markdown/)
* [jQuery](http://jquery.com/)
* [jQuery autogrow textarea](https://github.com/jaz303/jquery-grab-bag)

Expand All @@ -60,7 +62,11 @@ In the `ignition_application/config/` folder:
* Set `base_url` and `encryption_key` in `config.php`
* Set `hostname`, `username`, `password` and `database` in `database.php`

### Upgrade:

When upgrading between versions, follow the instructions in [migration.md](https://github.com/Clidus/ignition/blob/master/migration.md).

## License

* Copyright 2015 [Joshua Marketis](http://www.clidus.com)
* Copyright 2016 [Joshua Marketis](http://www.clidus.com)
* Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
2 changes: 2 additions & 0 deletions database.txt
Expand Up @@ -8,8 +8,10 @@ CREATE TABLE `blog` (
`Post` text NOT NULL,
`UserID` int(11) NOT NULL,
`Date` date NOT NULL,
`Time` time NOT NULL,
`Deck` varchar(155) DEFAULT NULL,
`Image` varchar(100) DEFAULT NULL,
`Published` tinyint(1) NOT NULL DEFAULT '0'
PRIMARY KEY (`PostID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Expand Down
2 changes: 1 addition & 1 deletion ignition_application/config/config.php
Expand Up @@ -245,7 +245,7 @@
|
*/
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
Expand Down
8 changes: 5 additions & 3 deletions ignition_application/config/routes.php
Expand Up @@ -42,6 +42,7 @@
$route['feed/(:num)'] = 'home/view/$1';

$route['blog'] = 'blogs/home';
$route['blog/page/(:any)'] = 'blogs/home/$1';
$route['blog/archive'] = 'blogs/archive';
$route['blog/archive/(:num)/(:num)'] = 'blogs/month/$1/$2';
$route['blog/(:any)'] = 'blogs/post/$1';
Expand Down Expand Up @@ -72,9 +73,10 @@
$route['user/(:any)/(:any)'] = 'users/view/$1/$2';

$route['admin'] = 'admin/home';
$route['admin/blog/new'] = 'admin/newBlogPost';
$route['admin/blog/edit'] = 'admin/blogPostList';
$route['admin/blog/edit/(:any)'] = 'admin/editBlogPost/$1';
$route['admin/blog/new'] = 'admin_blog/create';
$route['admin/blog/edit/post/(:any)'] = 'admin_blog/edit/$1';
$route['admin/blog/edit/(:any)'] = 'admin_blog/get/$1';
$route['admin/blog/delete'] = 'admin_blog/delete';

$route['cron/update'] = 'cron/update';

Expand Down
17 changes: 17 additions & 0 deletions ignition_application/controllers/admin_blog.php
@@ -0,0 +1,17 @@
<?php

/*
|--------------------------------------------------------------------------
| Ignition ignitionpowered.co.uk
|--------------------------------------------------------------------------
|
| This class extends the functionality of Ignition. You can add your
| own custom logic here.
|
*/

require_once APPPATH.'/controllers/ignition/admin_blog.php';

class Admin_Blog extends IG_Admin_Blog {

}
178 changes: 4 additions & 174 deletions ignition_application/controllers/ignition/admin.php
Expand Up @@ -2,7 +2,7 @@

/*
|--------------------------------------------------------------------------
| Ignition v0.4.1 ignitionpowered.co.uk
| Ignition v0.5.0 ignitionpowered.co.uk
|--------------------------------------------------------------------------
|
| This class is a core part of Ignition. It is advised that you extend
Expand All @@ -24,183 +24,13 @@ public function home()
$this->load->model('Page');
$data = $this->Page->create("Admin", "Admin");

// load views
$this->load->view('templates/header', $data);
$this->load->view('admin/admin.php', $data);
$this->load->view('templates/footer', $data);
}

// blog post list
public function blogPostList()
{
// restricted page
if($this->session->userdata('Admin') != 1)
show_404();

// page variables
$this->load->model('Page');
$data = $this->Page->create("Edit Blog Post", "Admin");

// get blog posts
$this->load->model('Blog');
$data['posts'] = $this->Blog->getPosts(100); // get 100 most recent posts

$this->load->view('templates/header', $data);
$this->load->view('admin/blogPostList', $data);
$this->load->view('templates/footer', $data);
}
$data['posts'] = $this->Blog->getPosts(4, 0, true); // get 100 most recent posts

// new blog post
public function newBlogPost()
{
// restricted page
if($this->session->userdata('Admin') != 1)
show_404();

$this->load->helper(array('form'));
$this->load->library('form_validation');

// page variables
$this->load->model('Page');
$data = $this->Page->create("New Blog Post", "Admin");
$data['formSuccess'] = $this->form_validation->run();
$data['formType'] = "new";

// form validation
$this->form_validation->set_rules('title', 'Title', 'trim|required|xss_clean');
$this->form_validation->set_rules('post', 'Post', 'trim|required|xss_clean');
$this->form_validation->set_rules('deck', 'Deck', 'trim|required|xss_clean');
$this->form_validation->set_rules('image', 'Image', 'trim|xss_clean');
$this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '<a class="close" data-dismiss="alert" href="#">&times;</a></div>');

if ($this->form_validation->run() == TRUE)
{
// try to upload new image
$postImage = $this->uploadImage();
// if no image uploaded, use value in form
if($postImage == null) $postImage = $this->input->post('image');

// add to db
$this->load->model('Blog');
$title = $this->input->post('title');
$postID = $this->Blog->add($title, $this->getUrl($title), $this->input->post('post'), $data['sessionUserID'], $this->input->post('deck'), $postImage);

header("location: " . base_url() . "admin/blog/edit/" . $postID);
}

// empty post object required (same view used for editing post)
$post = new stdClass();
$post->PostID = 0;
$post->Title = $this->input->post('title');
$post->Post = $this->input->post('post');
$post->Deck = $this->input->post('deck');
$post->Image = $this->input->post('image');
$data['post'] = $post;

$this->load->view('templates/header', $data);
$this->load->view('admin/blogPostEditor', $data);
$this->load->view('templates/footer', $data);
}

// edit blog post
public function editBlogPost($PostID)
{
// restricted page
if($this->session->userdata('Admin') != 1)
show_404();

$this->load->helper(array('form'));
$this->load->library('form_validation');

// form validation
$this->form_validation->set_rules('title', 'Title', 'trim|required|xss_clean');
$this->form_validation->set_rules('post', 'Post', 'trim|required|xss_clean');
$this->form_validation->set_rules('deck', 'Deck', 'trim|required|xss_clean');
$this->form_validation->set_rules('image', 'Image', 'trim|xss_clean');
$this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '<a class="close" data-dismiss="alert" href="#">&times;</a></div>');

if ($this->form_validation->run() == TRUE)
{
// try to upload new image
$postImage = $this->uploadImage();
// if no image uploaded, use value in form
if($postImage == null) $postImage = $this->input->post('image');

// update db
$this->load->model('Blog');
$title = $this->input->post('title');
$this->Blog->update($PostID, $title, $this->getUrl($title), $this->input->post('post'), $this->input->post('deck'), $postImage);
}

// get blog posts
$this->load->model('Blog');
$post = $this->Blog->getPostByID($PostID);

// fail if post doesnt exist
if($post == null)
show_404();

// page variables
$this->load->model('Page');
$data = $this->Page->create("Edit \"" . $post->Title . "\"", "Admin");
$data['formSuccess'] = $this->form_validation->run();
$data['formType'] = "edit/" . $PostID;
$data['post'] = $post;

// load views
$this->load->view('templates/header', $data);
$this->load->view('admin/blogPostEditor', $data);
$this->load->view('admin/admin.php', $data);
$this->load->view('templates/footer', $data);
}

private function uploadImage()
{
// configure file upload
$config['upload_path'] = './images/blog/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$this->load->library('upload', $config);

// upload file
if ($this->upload->do_upload())
{
// if successfull, return image file name
$uploadData = $this->upload->data();
return '/images/blog/' . $uploadData["file_name"];
}
}

private function getUrl($title)
{
// build url
$url = strtolower($title); // lowercase
$url = preg_replace('/[^a-z0-9]/', ' ', $url); // remove special characters
$url = preg_replace('/ +/', ' ', $url); // replace multiple spaces with single space
$url = trim($url); // trim leading/tailing space
$url = preg_replace('/ /', '-', $url); // replace spaces with hythen

return $url;
}

public function deleteBlogPost()
{
// form validation
$this->load->library('form_validation');
$this->form_validation->set_rules('postID', 'postID', 'trim|xss_clean');

// restricted method
if($this->session->userdata('Admin') != 1)
{
$result['error'] = true;
$result['errorMessage'] = "You don't have permission to do that duder.";
echo json_encode($result);
return;
} else {
// delete blog post
$this->load->model('Blog');
$this->Blog->delete($this->input->post('postID'));

$result['error'] = false;
echo json_encode($result);
return;
}
}
}

0 comments on commit 36321c0

Please sign in to comment.