Skip to content

Commit

Permalink
enchance blog
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed May 14, 2015
1 parent cad2f59 commit 6d596b0
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 36 deletions.
25 changes: 4 additions & 21 deletions application/libraries/Extended_grocery_crud.php
Expand Up @@ -629,27 +629,10 @@ protected function get_text_input($field_info,$value)
{
if($field_info->extras == 'text_editor')
{
$editor = $this->config->default_text_editor;
switch ($editor) {
case 'ckeditor':
$this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js');
$this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js');
$this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js');
break;

case 'tinymce':
$this->set_js_lib($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js');
$this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js');
break;

case 'markitup':
$this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css');
$this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css');

$this->set_js_lib($this->default_texteditor_path.'/markitup/jquery.markitup.js');
$this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js');
break;
}
$editor = 'ckeditor';
$this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js');
$this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js');
$this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js');

$class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor';

Expand Down
Binary file added modules/blog/assets/images/text.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions modules/blog/controllers/Blog.php
Expand Up @@ -125,6 +125,19 @@ public function index($article_url = NULL){
$config['keyword'] = $article['keyword'];
$config['description'] = $article['description'];
$config['author'] = $article['author'];
// add visited
$query = $this->db->select('visited')
->from($this->cms_complete_table_name('article'))
->where('article_id', $article['id'])
->get();
$row = $query->row();
$visited = $row->visited;
if($visited === NULL || $visited == ''){
$visited = 0;
}
$this->db->update($this->cms_complete_table_name('article'),
array('visited'=>$visited+1),
array('article_id'=>$article['id']));
}

$this->view($this->cms_module_path().'/browse_article_view',$data,
Expand Down
16 changes: 16 additions & 0 deletions modules/blog/controllers/Blog_widget.php
Expand Up @@ -18,6 +18,22 @@ public function newest($how_many=5){
$this->view($this->cms_module_path().'/widget_newest', $data);
}

public function popular($how_many=5){
$data = array();
$data['articles'] = $this->article_model->get_articles(0, $how_many,
NULL, NULL, NULL, FALSE, 'visited');
$data['module_path'] = $this->cms_module_path();
$this->view($this->cms_module_path().'/widget_popular', $data);
}

public function featured($how_many=5){
$data = array();
$data['articles'] = $this->article_model->get_articles(0, $how_many,
NULL, NULL, NULL, TRUE);
$data['module_path'] = $this->cms_module_path();
$this->view($this->cms_module_path().'/widget_featured', $data);
}

public function category(){
$data = array();
$data['categories'] = $this->article_model->get_available_category();
Expand Down
21 changes: 21 additions & 0 deletions modules/blog/controllers/Info.php
Expand Up @@ -130,6 +130,19 @@ public function do_upgrade($old_version){
$table_name = $this->cms_complete_table_name('photo');
$this->dbforge->modify_column($table_name, $fields);
}
if($major == 0 && $minor == 0 && $build <=7){
$fields = array(
'visited' => $this->TYPE_INT_UNSIGNED_NULL,
'featured' => $this->TYPE_INT_UNSIGNED_NULL,
);
$table_name = $this->cms_complete_table_name('article');
$this->dbforge->add_column($table_name, $fields);
// add popular and featured articles widgets
$this->cms_add_widget($this->cms_complete_navigation_name('popular_article'), 'Popular Articles',
$this->PRIV_EVERYONE, $module_path.'/blog_widget/popular','sidebar');
$this->cms_add_widget($this->cms_complete_navigation_name('featured_article'), 'Featured Articles',
$this->PRIV_EVERYONE, $module_path.'/blog_widget/featured','sidebar');
}
}


Expand All @@ -143,6 +156,8 @@ private function remove_all(){

// remove widgets
$this->cms_remove_widget($this->cms_complete_navigation_name('newest_article'));
$this->cms_remove_widget($this->cms_complete_navigation_name('popular_article'));
$this->cms_remove_widget($this->cms_complete_navigation_name('featured_article'));
$this->cms_remove_widget($this->cms_complete_navigation_name('article_category'));
$this->cms_remove_widget($this->cms_complete_navigation_name('content'));
$this->cms_remove_widget($this->cms_complete_navigation_name('archive'));
Expand Down Expand Up @@ -201,6 +216,10 @@ private function build_all(){

$this->cms_add_widget($this->cms_complete_navigation_name('newest_article'), 'Newest Articles',
$this->PRIV_EVERYONE, $module_path.'/blog_widget/newest','sidebar');
$this->cms_add_widget($this->cms_complete_navigation_name('popular_article'), 'Popular Articles',
$this->PRIV_EVERYONE, $module_path.'/blog_widget/popular','sidebar');
$this->cms_add_widget($this->cms_complete_navigation_name('featured_article'), 'Featured Articles',
$this->PRIV_EVERYONE, $module_path.'/blog_widget/featured','sidebar');
$this->cms_add_widget($this->cms_complete_navigation_name('article_category'), 'Article Categories',
$this->PRIV_EVERYONE, $module_path.'/blog_widget/category','sidebar');
$this->cms_add_widget($this->cms_complete_navigation_name('content'), 'Blog Content',
Expand Down Expand Up @@ -236,6 +255,8 @@ private function build_all(){
'default' => 'draft',
'null' => FALSE,
),
'visited' => $this->TYPE_INT_UNSIGNED_NULL,
'featured' => $this->TYPE_INT_UNSIGNED_NULL,
'publish_date' => $this->TYPE_DATE_NULL,
);
$this->dbforge->add_field($fields);
Expand Down
12 changes: 7 additions & 5 deletions modules/blog/controllers/Manage_article.php
Expand Up @@ -80,23 +80,24 @@ public function index(){
$crud->set_subject('Article');

// displayed columns on list
$crud->columns('article_title','author_user_id','status','publish_date','allow_comment','categories','comments');
$crud->columns('article_title','author_user_id','status','publish_date','featured','allow_comment','categories','comments');
// displayed columns on edit operation
$crud->edit_fields('article_title','article_url','date','status','publish_date','author_user_id','content','keyword','description','allow_comment','categories','photos','comments');
$crud->edit_fields('article_title','article_url','date','status','publish_date','author_user_id','content','keyword','description','featured','allow_comment','categories','photos','comments');
// displayed columns on add operation
$crud->add_fields('article_title','article_url','date','status','publish_date','author_user_id','content','keyword','description','allow_comment','categories','photos','comments');
$crud->add_fields('article_title','article_url','date','status','publish_date','author_user_id','content','keyword','description','featured','allow_comment','categories','photos','comments');
$crud->required_fields('article_title','status');
$crud->unique_fields('article_title','article_url');
$crud->unset_read();

// caption of each columns
$crud->display_as('article_title','Article Title');
$crud->display_as('article_url','Article URL (Permalink)');
$crud->display_as('article_url','Permalink (Left blank for default)');
$crud->display_as('date','Created Date');
$crud->display_as('author_user_id','Author');
$crud->display_as('content','Content');
$crud->display_as('keyword','Keyword metadata (comma separated)');
$crud->display_as('description','Description metadata');
$crud->display_as('featured','Featured');
$crud->display_as('allow_comment','Allow Comment');
$crud->display_as('categories','Categories');
$crud->display_as('photos','Photos');
Expand Down Expand Up @@ -136,6 +137,7 @@ public function index(){
}
$crud->field_type('date', 'hidden');
$crud->field_type('allow_comment', 'true_false');
$crud->field_type('featured', 'true_false');
$crud->unset_texteditor('article_title');
$crud->unset_texteditor('article_url');
$crud->unset_texteditor('keyword');
Expand Down Expand Up @@ -385,7 +387,7 @@ public function callback_field_comments($value, $primary_key){

// change the comment status into read
$data = array('read'=>1);
$where = array('article_id', $primary_key);
$where = array('article_id'=> $primary_key);
$this->db->update($this->cms_complete_table_name('comment'), $data, $where);

$search = array('<', '>');
Expand Down
2 changes: 1 addition & 1 deletion modules/blog/description.txt
Expand Up @@ -2,7 +2,7 @@
"dependencies" : [],
"name" : "gofrendi.noCMS.blog",
"description" : "Write articles, upload photos, allow visitors to give comments, rule the world...",
"version" : "0.0.6",
"version" : "0.0.7",
"activate" : "info/activate",
"deactivate" : "info/deactivate",
"upgrade" : "info/upgrade"
Expand Down
17 changes: 13 additions & 4 deletions modules/blog/models/Article_model.php
Expand Up @@ -79,11 +79,17 @@ public function get_article_url($article_id){

public function get_available_category(){
$result = array(''=>'All Category');
$query = $this->db->select('category_name')
$query = $this->db->select('category_id, category_name')
->from($this->cms_complete_table_name('category'))
->get();
foreach($query->result() as $row){
$result[$row->category_name] = $row->category_name;
$query_article_category = $this->db->select('article_id')
->from($this->cms_complete_table_name('category_article'))
->where('category_id', $row->category_id)
->get();
if($query_article_category->num_rows()>0){
$result[$row->category_name] = $row->category_name;
}
}
return $result;
}
Expand Down Expand Up @@ -125,7 +131,7 @@ public function get_single_article($article_url){
}
}

public function get_articles($page, $limit, $category, $archive, $search){
public function get_articles($page, $limit, $category, $archive='', $search=NULL, $featured=FALSE, $order_by='date'){
$words = $search? explode(' ', $search) : array();

$data = array();
Expand All @@ -136,6 +142,8 @@ public function get_articles($page, $limit, $category, $archive, $search){
AND category_name ='".addslashes($category)."'
)" : "(1=1)";

$where_featured = $featured? 'featured=1' : '(1=1)';

if($search){
$where_search = "(FALSE ";
foreach($words as $word){
Expand All @@ -161,9 +169,10 @@ public function get_articles($page, $limit, $category, $archive, $search){
WHERE
$where_category AND
$where_search AND
$where_featured AND
date LIKE '$archive%' AND
(status = 'published' OR (status='scheduled' AND publish_date <= '".$current_date."'))
ORDER BY date DESC, article_id DESC
ORDER BY ".$order_by." DESC, article_id DESC
LIMIT $limit OFFSET $offset";

$query = $this->db->query($SQL);
Expand Down
2 changes: 1 addition & 1 deletion modules/blog/views/browse_article_view.php
Expand Up @@ -84,7 +84,7 @@
<?php
// show add record button
if($allow_navigate_backend){
echo '<a href="'.$backend_url.'/add/" class="btn btn-default add_record">Add</a>'.PHP_EOL;
echo '&nbsp;<a href="'.$backend_url.'/add/" class="btn btn-default add_record">Add</a>'.PHP_EOL;
}
?>
</div>
Expand Down
42 changes: 42 additions & 0 deletions modules/blog/views/widget_featured.php
@@ -0,0 +1,42 @@
<style type="text/css">
ul._featured_widget {
list-style-type: none; padding-left: 10px;
}
ul._featured_widget li {
border-bottom:1px solid gray;
padding-top: 5px;
padding-bottom:5px;
}
</style>
<?php
if(count($articles)==0){
echo 'Currently there is no featured article yet';
}else{
echo '<ul class="_featured_widget">';
foreach($articles as $article){
echo '<li>';
// get url
if($module_path == 'blog'){
$url = site_url('blog/index/'.$article['article_url']);
}else{
$url = site_url('{{ module_path }}/blog/index/'.$article['article_url']);
}
// get image
if(count($article['photos'])>0){
$photo = $article['photos'][0]['url'];
$photo = base_url('modules/{{ module_path }}/assets/uploads/thumb_'.$photo);
}else{
$photo = base_url('modules/{{ module_path }}/assets/images/text.jpeg');
}
echo anchor($url,
'<div class="row">'.
'<div class="col-md-4" style="min-height:50px; background-repeat: no-repeat;
background-attachment: cover; background-position: center;
background-color:black;
background-image:url(\''.$photo.'\')"></div>'.
'<div class="col-md-8" style="vertical-align:top;"><h4>'.$article['title'].'</h4></div>'.
'</div>');
echo '</li>';
}
echo '</ul>';
}
11 changes: 8 additions & 3 deletions modules/blog/views/widget_newest.php
@@ -1,6 +1,11 @@
<style type="text/css">
ul._newest_widget {
list-style-type: disc; padding-left: 20px;
list-style-type: none; padding-left: 10px;
}
ul._newest_widget li {
border-bottom:1px solid gray;
padding-top: 5px;
padding-bottom:5px;
}
</style>
<?php
Expand All @@ -11,10 +16,10 @@
foreach($articles as $article){
echo '<li>';
if($module_path == 'blog'){
echo anchor(site_url('blog/index/'.$article['article_url']),
echo '<span class="_article_date">'.$article['date'].'</span>'.br().anchor(site_url('blog/index/'.$article['article_url']),
$article['title']);
}else{
echo anchor(site_url('{{ module_path }}/blog/index/'.$article['article_url']),
echo '<span class="_article_date">'.$article['date'].'</span>'.br().anchor(site_url('{{ module_path }}/blog/index/'.$article['article_url']),
$article['title']);
}
echo '</li>';
Expand Down
28 changes: 28 additions & 0 deletions modules/blog/views/widget_popular.php
@@ -0,0 +1,28 @@
<style type="text/css">
ul._popular_widget {
list-style-type: none; padding-left: 10px;
}
ul._popular_widget li {
border-bottom:1px solid gray;
padding-top: 5px;
padding-bottom:5px;
}
</style>
<?php
if(count($articles)==0){
echo 'Currently there is no article yet';
}else{
echo '<ul class="_popular_widget">';
foreach($articles as $article){
echo '<li>';
if($module_path == 'blog'){
echo '<span class="_article_date">'.$article['date'].'</span>'.br().anchor(site_url('blog/index/'.$article['article_url']),
$article['title']);
}else{
echo '<span class="_article_date">'.$article['date'].'</span>'.br().anchor(site_url('{{ module_path }}/blog/index/'.$article['article_url']),
$article['title']);
}
echo '</li>';
}
echo '</ul>';
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -40,7 +40,7 @@ No-CMS come with several batteries included:
Release Information
===================

- v1.0.0 development, May, 08, 2015
- v1.0.0 alpha, May, 14, 2015


Server Requirements
Expand Down

0 comments on commit 6d596b0

Please sign in to comment.