1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
(defined('BASEPATH')) OR exit('No direct script access allowed'); |
|
|
|
|
4
|
|
|
|
5
|
|
|
if (!function_exists('get_sub_categories')) { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Short description for function |
9
|
|
|
* |
10
|
|
|
* Long description (if any) ... |
11
|
|
|
* |
12
|
|
|
* @param integer $category_id Parameter description (if any) ... |
13
|
|
|
* @return array Return description (if any) ... |
14
|
|
|
*/ |
15
|
|
|
function get_sub_categories($category_id = 0) { |
16
|
|
|
$ci = & get_instance(); |
17
|
|
|
$categories = $ci->lib_category->unsorted(); |
18
|
|
|
|
19
|
|
|
$result = []; |
20
|
|
|
|
21
|
|
|
foreach ($categories as $category) { |
22
|
|
|
if ($category['parent_id'] == $category_id) { |
23
|
|
|
$result[] = $category; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return $result; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if (!function_exists('category_list')) { |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $exclude_cats |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
function category_list($exclude_cats = '') { |
39
|
|
|
$ci = & get_instance(); |
40
|
|
|
$ci->load->helper('html'); |
41
|
|
|
$ci->load->module('core'); |
42
|
|
|
$categories = $ci->lib_category->unsorted(); |
43
|
|
|
|
44
|
|
|
$exclude_cats = explode(',', $exclude_cats); |
45
|
|
|
|
46
|
|
|
$result = []; |
47
|
|
|
|
48
|
|
|
foreach ($categories as $row) { |
49
|
|
|
if (!in_array($row['id'], $exclude_cats)) { |
50
|
|
|
$row['fetch_pages'] = unserialize($row['fetch_pages']); |
51
|
|
|
|
52
|
|
|
$total_pages = _get_category_pages($row, 0, 0, TRUE); |
53
|
|
|
$result[] = '<a href="' . site_url($row['path_url']) . '">' . $row['name'] . ' (' . $total_pages . ')</a>'; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return ul($result); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (!function_exists('sub_category_list')) { |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param integer $category_id |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
function sub_category_list($category_id = 0) { |
69
|
|
|
$ci = & get_instance(); |
70
|
|
|
$ci->load->helper('html'); |
71
|
|
|
$ci->load->module('core'); |
72
|
|
|
|
73
|
|
|
if ($category_id > 0) { |
74
|
|
|
$categories = get_sub_categories($category_id); |
75
|
|
|
|
76
|
|
|
if (count($categories) > 0) { |
77
|
|
|
foreach ($categories as $row) { |
78
|
|
|
$row['fetch_pages'] = unserialize($row['fetch_pages']); |
79
|
|
|
|
80
|
|
|
$total_pages = _get_category_pages($row, 0, 0, TRUE); |
81
|
|
|
$result[] = '<a href="' . site_url($row['path_url']) . '">' . $row['name'] . ' (' . $total_pages . ')</a>'; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return ul($result); |
85
|
|
|
} else { |
86
|
|
|
return FALSE; |
87
|
|
|
} |
88
|
|
|
} else { |
89
|
|
|
return FALSE; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if (!function_exists('get_category_name')) { |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param integer $id |
99
|
|
|
* @return mixed |
100
|
|
|
*/ |
101
|
|
|
function get_category_name($id) { |
102
|
|
|
$ci = & get_instance(); |
103
|
|
|
$c = $ci->lib_category->get_category($id); |
104
|
|
|
|
105
|
|
|
if ($c['name'] == '') { |
106
|
|
|
$c['name'] = lang('No category'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $c['name']; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if (!function_exists('_get_category_pages')) { |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Select or count pages in category |
118
|
|
|
* @param array $category |
119
|
|
|
* @param int $row_count |
120
|
|
|
* @param int $offset |
121
|
|
|
* @param bool|FALSE $count |
122
|
|
|
* @return array|string |
123
|
|
|
*/ |
124
|
|
|
function _get_category_pages(array $category = [], $row_count = 0, $offset = 0, $count = FALSE) { |
125
|
|
|
$ci = & get_instance(); |
126
|
|
|
|
127
|
|
|
$ci->db->where('post_status', 'publish'); |
128
|
|
|
$ci->db->where('publish_date <=', time()); |
129
|
|
|
$ci->db->where('lang', $ci->config->item('cur_lang')); |
130
|
|
|
if (count($category['fetch_pages']) > 0) { |
131
|
|
|
$category['fetch_pages'][] = $category['id']; |
132
|
|
|
$ci->db->where_in('category', $category['fetch_pages']); |
133
|
|
|
} else { |
134
|
|
|
$ci->db->where('category', $category['id']); |
135
|
|
|
} |
136
|
|
|
$ci->db->select('content.*'); |
137
|
|
|
$ci->db->select('IF(route.parent_url <> \'\', concat(route.parent_url, \'/\', route.url), route.url) as full_url', FALSE); |
138
|
|
|
$ci->db->order_by($category['order_by'], $category['sort_order']); |
139
|
|
|
$ci->db->join('route', 'route.id=content.route_id'); |
140
|
|
|
|
141
|
|
|
if ($count === FALSE) { |
142
|
|
|
if ($row_count > 0) { |
143
|
|
|
$query = $ci->db->get('content', (int) $row_count, (int) $offset); |
144
|
|
|
} else { |
145
|
|
|
$query = $ci->db->get('content'); |
146
|
|
|
} |
147
|
|
|
} else { |
148
|
|
|
$ci->db->from('content'); |
149
|
|
|
return $ci->db->count_all_results(); |
150
|
|
|
} |
151
|
|
|
$pages = $query->result_array(); |
152
|
|
|
|
153
|
|
|
if (count($pages) > 0 AND is_array($pages)) { |
|
|
|
|
154
|
|
|
$n = 0; |
155
|
|
|
foreach ($pages as $p) { |
156
|
|
|
$pages[$n] = $ci->cfcm->connect_fields($p, 'page'); |
157
|
|
|
$n++; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
return $pages; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/* End of file category_helper.php */ |