Skip to content

Commit

Permalink
fix up things, improve blog
Browse files Browse the repository at this point in the history
  • Loading branch information
goFrendiAsgard committed Aug 23, 2015
1 parent 9aeeab9 commit c68de72
Show file tree
Hide file tree
Showing 47 changed files with 817 additions and 234 deletions.
6 changes: 3 additions & 3 deletions application/core/CMS_AutoUpdate_Model.php
Expand Up @@ -36,9 +36,9 @@ private function __update_module(){
$active = $module['active'];
$upgrade_link = $module['upgrade_link'];
if($active && $old_version != $current_version){
$url = str_replace(site_url(), '', $upgrade_link);
$url = trim($url, '/');
$response = @Modules::run($url, $bypass);
$url = str_replace(site_url(), '', $upgrade_link);
$url = trim($url, '/');
$response = Modules::run($url, $bypass);
}
}
}
Expand Down
118 changes: 66 additions & 52 deletions application/core/CMS_Controller.php

Large diffs are not rendered by default.

100 changes: 71 additions & 29 deletions application/core/CMS_Model.php
Expand Up @@ -62,7 +62,11 @@ public function __construct()
'quicklink' => array(), // cache already built quicklink
'widget' => array(), // cache raw query
'super_admin' => NULL,
'group_name' => array(),
'group_id' => array(),
'properties' => array(),
'route' => array(),
'is_super_admin' => FALSE,
'is_config_cached' => FALSE,
'is_module_name_cached' => FALSE,
'is_module_path_cached' => FALSE,
Expand All @@ -72,6 +76,10 @@ public function __construct()
'is_quicklink_cached' => FALSE,
'is_widget_cached' => FALSE,
'is_language_dictionary_cached' => FALSE,
'is_group_name_cached' => FALSE,
'is_group_id_cached' => FALSE,
'is_super_admin_cached' => FALSE,
'is_route_cached' => FALSE,
);
foreach($default_properties as $key=>$val){
if(!array_key_exists($key, self::$__cms_model_properties)){
Expand Down Expand Up @@ -397,43 +405,50 @@ public function cms_user_id($user_id = NULL)
return $this->cms_ci_session('cms_user_id', $user_id);
}

/**
* @author goFrendiAsgard
* @return array
* @desc get group list of current user
*/
public function cms_user_group(){
private function cms_adjust_group(){
$group_id = array();
$group_name = array();
if($this->cms_user_id() != NULL){
$query = $this->db->select('group_name')
->from(cms_table_name('main_group'))
->join(cms_table_name('main_group_user'), cms_table_name('main_group_user').'.group_id = '.cms_table_name('main_group').'.group_id')
$t_group_user = cms_table_name('main_group_user');
$t_group = cms_table_name('main_group');
$query = $this->db->select($t_group_user.'.group_id, group_name')
->from($t_group_user)
->join($t_group, $t_group.'.group_id = '.$t_group_user.'.group_id')
->where(cms_table_name('main_group_user').'.user_id', $this->cms_user_id())
->get();
foreach($query->result() as $row){
$group_name[] = $row->group_name;
$group_id[] = $row->group_id;
$group_name[] = $row->group_name;
}
}
return $group_name;
self::$__cms_model_properties['group_id'] = $group_id;
self::$__cms_model_properties['group_name'] = $group_name;
self::$__cms_model_properties['is_group_id_cached'] = TRUE;
self::$__cms_model_properties['is_group_name_cached'] = TRUE;
}

/**
* @author goFrendiAsgard
* @return array
* @desc get group list of current user
*/
public function cms_user_group_id(){
$group_id = array();
if($this->cms_user_id() != NULL){
$query = $this->db->select('group_id')
->from(cms_table_name('main_group_user'))
->where(cms_table_name('main_group_user').'.user_id', $this->cms_user_id())
->get();
foreach($query->result() as $row){
$group_id[] = $row->group_id;
}
public function cms_user_group(){
if (!self::$__cms_model_properties['is_group_name_cached']) {
$this->cms_adjust_group();
}
return $group_id;
return self::$__cms_model_properties['group_name'];
}

/**
* @author goFrendiAsgard
* @return array
* @desc get group list of current user
*/
public function cms_user_group_id(){
if (!self::$__cms_model_properties['is_group_id_cached']) {
$this->cms_adjust_group();
}
return self::$__cms_model_properties['group_id'];
}

/**
Expand Down Expand Up @@ -490,14 +505,9 @@ public function cms_user_is_super_admin(){
}
}
}

// normal flow
$query = $this->db->select('group_name')
->from(cms_table_name('main_group'))
->join(cms_table_name('main_group_user'), cms_table_name('main_group_user').'.group_id = '.cms_table_name('main_group').'.group_id')
->where(cms_table_name('main_group_user').'.user_id', $this->cms_user_id())
->where(cms_table_name('main_group').'.group_id', 1)
->get();
return $query->num_rows()>0;
return in_array(1, $this->cms_user_group_id());
}

/**
Expand Down Expand Up @@ -1072,6 +1082,20 @@ public function cms_have_privilege($privilege_name)
}
}

public function cms_route_key_exists($route_key)
{
if(!self::$__cms_model_properties['is_route_cached']){
$query = $this->db->select('key, value')
->from(cms_table_name('main_route'))
->get();
self::$__cms_model_properties['route'] = array();
foreach($query->result() as $row){
self::$__cms_model_properties['route'][$row->key] = $row->value;
}
}
return array_key_exists($route_key, self::$__cms_model_properties['route']);
}

/**
* @author goFrendiAsgard
* @param string identity
Expand Down Expand Up @@ -3466,6 +3490,24 @@ public final function cms_remove_route($key){
$this->cms_reconfig_route();
}

public final function cms_add_config($config_name, $value, $description = NULL){
$query = $this->db->select('config_id')
->from(cms_table_name('main_config'))
->where('config_name', $config_name)
->get();
$data = array('config_name' => $config_name, 'value' => $value, 'description' => $description);
if($query->num_rows() > 0){
$config_id = $query->row()->config_id;
$this->db->update(cms_table_name('main_config'), $data, array('config_id' => $config_id));
}else{
$this->db->insert(cms_table_name('main_config'), $data);
}
}

public final function cms_remove_config($config_name){
$this->db->delete(cms_table_name('main_config'), array('config_name' => $config_name));
}

public final function cms_assign_navigation($navigation_name, $group_name){
$query = $this->db->select('group_id')
->from(cms_table_name('main_group'))
Expand Down
2 changes: 1 addition & 1 deletion application/core/CMS_Module.php
Expand Up @@ -195,7 +195,7 @@ public final function activate($bypass = NULL)
$result['message'] = ul($result['message']);

// show result
if($bypass !== NULL){
if($bypass){
echo json_encode($result);
} else if($result['success']) {
$module_management_url = $this->cms_navigation_url('main_module_management');
Expand Down
12 changes: 12 additions & 0 deletions application/libraries/Extended_grocery_crud.php
Expand Up @@ -29,6 +29,7 @@ class Extended_grocery_crud extends grocery_crud{

protected $outside_tab = 0;
protected $tabs = NULL;
protected $tab_glyphicons = array();
protected $field_half_width = array();
protected $field_one_third_width = array();
protected $field_two_third_width = array();
Expand Down Expand Up @@ -72,6 +73,10 @@ public function set_tabs($data){
$this->tabs = $data;
}

public function set_tab_glyphicons($data){
$this->tab_glyphicons = $data;
}

public function set_outside_tab($data){
$this->outside_tab = $data;
}
Expand Down Expand Up @@ -103,6 +108,13 @@ public function add_tab($caption, $count){
$this->tabs[$key] = $count;
}

public function add_tab_glyphicon($glyphicon){
if($this->tab_glyphicons == NULL){
$this->tab_glyphicons = array();
}
$this->tab_glyphicons[$key] = $glyphicon;
}

protected function set_default_Model()
{
$db_driver = $this->_ci->db->platform();
Expand Down
7 changes: 6 additions & 1 deletion assets/grocery_crud/themes/no-flexigrid/views/add.php
Expand Up @@ -23,6 +23,7 @@
<div class='form-div form-horizontal row'>
<?php
$this->tabs = isset($this->tabs)? $this->tabs : NULL;
$this->tab_glyphicons = isset($this->tab_glyphicons)? $this->tab_glyphicons : NULL;
$this->outside_tab = isset($this->outside_tab)? $this->outside_tab : 0;
$counter = 0;
$tab_index=-1;
Expand All @@ -44,7 +45,11 @@
echo '<ul class="nav nav-tabs" role="tablist">';
$active = 'active';
foreach($this->tabs as $key=>$val){
echo '<li class="'.$active.'"><a href="#'.str_replace(' ','',$key).'" role="tab" data-toggle="tab">'.$key.'</a></li>';
$caption = $key;
if(array_key_exists($key, $this->tab_glyphicons)){
$caption = '<i class ="glyphicon ' . $this->tab_glyphicons[$key] . '"></i>&nbsp;' . $key;
}
echo '<li class="'.$active.'"><a href="#'.str_replace(' ','',$key).'" role="tab" data-toggle="tab">'.$caption.'</a></li>';
$active = '';
}
echo '</ul>';
Expand Down
7 changes: 6 additions & 1 deletion assets/grocery_crud/themes/no-flexigrid/views/edit.php
Expand Up @@ -23,6 +23,7 @@
<div class='form-div form-horizontal row'>
<?php
$this->tabs = isset($this->tabs)? $this->tabs : NULL;
$this->tab_glyphicons = isset($this->tab_glyphicons)? $this->tab_glyphicons : NULL;
$this->outside_tab = isset($this->outside_tab)? $this->outside_tab : 0;
$counter = 0;
$tab_index=-1;
Expand All @@ -44,7 +45,11 @@
echo '<ul class="nav nav-tabs" role="tablist">';
$active = 'active';
foreach($this->tabs as $key=>$val){
echo '<li class="'.$active.'"><a href="#'.str_replace(' ','',$key).'" role="tab" data-toggle="tab">'.$key.'</a></li>';
$caption = $key;
if(array_key_exists($key, $this->tab_glyphicons)){
$caption = '<i class ="glyphicon ' . $this->tab_glyphicons[$key] . '"></i>&nbsp;' . $key;
}
echo '<li class="'.$active.'"><a href="#'.str_replace(' ','',$key).'" role="tab" data-toggle="tab">'.$caption.'</a></li>';
$active = '';
}
echo '</ul>';
Expand Down
3 changes: 3 additions & 0 deletions doc/changelog.md
Expand Up @@ -213,3 +213,6 @@ v1.0.0 (inner: 0.7.5)
+ (done, tested) Route management
+ (done, tested) Hide navigation
+ (done, tested) One user table to avoid duplication and complication
+ (done, tested) Create routes for blog to make url cleaner
+ (done, tested) Add caption to blog's photo
+ (done, tested) Add moderation setting
Binary file added modules/blog/assets/images/user.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/navigation_icon/setting.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/blog/assets/uploads/01.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/blog/assets/uploads/05.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/06.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/07.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/08.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/blog/assets/uploads/main_01.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/blog/assets/uploads/main_05.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/main_06.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/main_07.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/main_08.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/blog/assets/uploads/thumb_main_01.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/blog/assets/uploads/thumb_main_05.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/thumb_main_06.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/thumb_main_07.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/blog/assets/uploads/thumb_main_08.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 25 additions & 14 deletions modules/blog/controllers/Blog.php
Expand Up @@ -26,10 +26,22 @@ private function __random_string($length=10){
return $str;
}

public function index($article_url = NULL){
public function index($article_url = NULL, $filter_category = NULL, $filter_archive = NULL, $filter_keyword = NULL){
$module_path = $this->cms_module_path();
$this->load->model($module_path.'/article_model');

$article_url = $article_url == ''? NULL : $article_url;
$filter_category = $this->input->get('category') == NULL?
$filter_category : $this->input->get('category');
$filter_archive = $this->input->get('archive') == NULL?
$filter_archive : $this->input->get('archive');
$filter_keyword = $this->input->get('keyword') == NULL?
$filter_keyword : $this->input->get('keyword');
$filter_category = $filter_category == ''? NULL : $filter_category;
$filter_archive = $filter_archive == ''? NULL : $filter_archive;
$filter_keyword = $filter_keyword == ''? NULL : $filter_keyword;


// the honey_pot, every fake input should be empty
$honey_pot_pass = (strlen($this->input->post('name', ''))==0) &&
(strlen($this->input->post('email', ''))==0) &&
Expand Down Expand Up @@ -83,10 +95,10 @@ public function index($article_url = NULL){
$first_data = NULL;
if($article_url === NULL){
$first_data = Modules::run($module_path.'/blog/get_data',
$this->input->get('keyword'),
$filter_keyword,
0,
$this->input->get('category'),
$this->input->get('archive')
$filter_category,
$filter_archive
);
}

Expand All @@ -96,9 +108,9 @@ public function index($article_url = NULL){
'backend_url' => site_url($this->cms_module_path().'/manage_article/index'),
'first_data'=> $first_data,
'categories'=>$this->article_model->get_available_category(),
'chosen_category' => $this->input->get('category'),
'archive' => $this->input->get('archive'),
'keyword' => $this->input->get('keyword'),
'chosen_category' => $filter_category,
'archive' => $filter_archive,
'keyword' => $filter_keyword,
'module_path' => $this->cms_module_path(),
'is_user_login' => $this->cms_user_id()>0,
'secret_code' => $secret_code,
Expand All @@ -115,23 +127,20 @@ public function index($article_url = NULL){
'form_url'=> $this->cms_module_path() == 'blog'?
site_url($this->cms_module_path().'/index/'.$article_url.'/#comment-form') :
site_url($this->cms_module_path().'/blog/index/'.$article_url.'/#comment-form'),
'category_route_exists' => $this->cms_route_key_exists('blog/category/(:any)'),
);

$config = array();
if(isset($article_url)){
if(isset($article_url) && $article_url != ''){
$article = $this->article_model->get_single_article($article_url);
$data['article'] = $article;
$config['title'] = $article['title'];
$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;
$visited = $article['visited'];
if($visited === NULL || $visited == ''){
$visited = 0;
}
Expand Down Expand Up @@ -167,6 +176,8 @@ public function get_data($keyword = '', $page = 0, $category = '', $archive = ''
'is_super_admin' => $this->cms_user_id() == 1 || in_array(1, $this->cms_user_group_id()),
'module_path' => $this->cms_module_path(),
'user_id' => $this->cms_user_id(),
'article_route_exists'=>$this->cms_route_key_exists('blog/(:any)\.html'),
'category_route_exists' => $this->cms_route_key_exists('blog/category/(:any)'),
);
$config = array('only_content'=>TRUE);
$this->view($this->cms_module_path().'/browse_article_partial_view',$data,
Expand Down
6 changes: 6 additions & 0 deletions modules/blog/controllers/Blog_widget.php
Expand Up @@ -15,6 +15,7 @@ public function newest($how_many=5){
$data['articles'] = $this->article_model->get_articles(0, $how_many,
NULL, NULL);
$data['module_path'] = $this->cms_module_path();
$data['article_route_exists'] = $this->cms_route_key_exists('blog/(:any)\.html');
$this->view($this->cms_module_path().'/widget_newest', $data);
}

Expand All @@ -23,6 +24,7 @@ public function popular($how_many=5){
$data['articles'] = $this->article_model->get_articles(0, $how_many,
NULL, NULL, NULL, FALSE, 'visited');
$data['module_path'] = $this->cms_module_path();
$data['article_route_exists'] = $this->cms_route_key_exists('blog/(:any)\.html');
$this->view($this->cms_module_path().'/widget_popular', $data);
}

Expand All @@ -31,20 +33,24 @@ public function featured($how_many=5){
$data['articles'] = $this->article_model->get_articles(0, $how_many,
NULL, NULL, NULL, TRUE);
$data['module_path'] = $this->cms_module_path();
$data['article_route_exists'] = $this->cms_route_key_exists('blog/(:any)\.html');
$this->view($this->cms_module_path().'/widget_featured', $data);
}

public function category(){
$data = array();
$data['categories'] = $this->article_model->get_available_category();
$data['module_path'] = $this->cms_module_path();
$data['article_route_exists'] = $this->cms_route_key_exists('blog/(:any)\.html');
$data['category_route_exists'] = $this->cms_route_key_exists('blog/category/(:any)');
$this->view($this->cms_module_path().'/widget_category', $data);
}

public function archive(){
$data = array();
$data['archives'] = $this->article_model->get_archive();
$data['module_path'] = $this->cms_module_path();
$data['archive_route_exists'] = $this->cms_route_key_exists('blog/category/(:any)');
$this->view($this->cms_module_path().'/widget_archive', $data);
}
}

0 comments on commit c68de72

Please sign in to comment.