-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.php
245 lines (207 loc) · 9.61 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
declare(strict_types=1);
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* @copyright The XUUPS Project http://sourceforge.net/projects/xuups/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @since 1.0
* @author trabis <[email protected]>
* @author The SmartFactory <www.smartfactory.ca>
*/
use Xmf\Request;
use XoopsModules\Publisher\{Constants,
Helper,
Metagen,
Utility
};
/** @var Helper $helper */
require_once __DIR__ . '/header.php';
// At which record shall we start for the Categories
$catstart = Request::getInt('catstart', 0, 'GET');
// At which record shall we start for the ITEM
$start = Request::getInt('start', 0, 'GET');
// Number of categories at the top level
$totalCategories = $helper->getHandler('Category')->getCategoriesCount(0);
// if there ain't no category to display, let's get out of here
if (0 == $totalCategories) {
redirect_header(XOOPS_URL, 2, _MD_PUBLISHER_NO_TOP_PERMISSIONS);
}
$GLOBALS['xoopsOption']['template_main'] = 'publisher_display' . '_' . $helper->getConfig('idxcat_items_display_type') . '.tpl';
require_once $GLOBALS['xoops']->path('header.php');
require_once $helper->path('footer.php');
/** @var \XoopsGroupPermHandler $grouppermHandler */
$grouppermHandler = xoops_getHandler('groupperm');
// Creating the top categories objects
$categoriesObj = $helper->getHandler('Category')->getCategories($helper->getConfig('idxcat_cat_perpage'), $catstart);
// if no categories are found, exit
$totalCategoriesOnPage = count($categoriesObj);
if (0 == $totalCategoriesOnPage) {
redirect_header('<script>javascript:history.go(-1)</script>', 2, _MD_PUBLISHER_NO_CAT_EXISTS);
}
// Get subcats of the top categories
$subcats = $helper->getHandler('Category')->getSubCats($categoriesObj);
// Count of items within each top categories
$totalItems = $helper->getHandler('Category')->publishedItemsCount();
// real total count of items
$real_total_items = $helper->getHandler('Item')->getItemsCount(-1, [Constants::PUBLISHER_STATUS_PUBLISHED]);
if (1 == $helper->getConfig('idxcat_display_last_item')) {
// Get the last item in each category
$lastItemObj = $helper->getHandler('Item')->getLastPublishedByCat(array_merge([$categoriesObj], $subcats));
}
// Max size of the title in the last item column
$lastitemsize = (int)$helper->getConfig('idxcat_last_item_size');
// Hide sub categories in main page only - hacked by Mowaffak
if ('nomain' === $helper->getConfig('idxcat_show_subcats')) {
// $GLOBALS['xoopsModuleConfig']->setConfig('idxcat_show_subcats', 'no');
$GLOBALS['xoopsModuleConfig']['idxcat_show_subcats'] = 'no';
}
$categories = [];
foreach ($categoriesObj as $catId => $category) {
$total = 0;
// Do we display sub categories ?
if ('no' !== $helper->getConfig('idxcat_show_subcats')) {
// if this category has subcats
if (isset($subcats[$catId])) {
foreach ($subcats[$catId] as $key => $subcat) {
// Get the items count of this very category
$subcatTotalItems = $totalItems[$key] ?? 0;
// Do we display empty sub-cats ?
if (($subcatTotalItems > 0) || ('all' === $helper->getConfig('idxcat_show_subcats'))) {
$subcatId = $subcat->getVar('categoryid');
// if we retrieved the last item object for this category
if (isset($lastItemObj[$subcatId])) {
$subcat->setVar('last_itemid', $lastItemObj[$subcatId]->itemid());
$subcat->setVar('last_title_link', $lastItemObj[$subcatId]->getItemLink(false, $lastitemsize));
}
$numItems = isset($totalItems[$subcatId]) ? $totalItems[$key] : 0;
$subcat->setVar('itemcount', $numItems);
// Put this subcat in the smarty variable
$categories[$catId]['subcats'][$key] = $subcat->toArrayTable();
//$total += $numItems;
}
}
// unset($subcat);
}
}
$categories[$catId]['subcatscount'] = isset($subcats[$catId]) ? count($subcats[$catId]) : 0;
// Get the items count of this very category
if (isset($totalItems[$catId]) && $totalItems[$catId] > 0) {
$total += $totalItems[$catId];
}
// I'm commenting out this to also display empty categories...
// if ($total > 0) {
if (isset($lastItemObj[$catId])) {
$category->setVar('last_itemid', $lastItemObj[$catId]->getVar('itemid'));
$category->setVar('last_title_link', $lastItemObj[$catId]->getItemLink(false, $lastitemsize));
}
$category->setVar('itemcount', $total);
if (!isset($categories[$catId])) {
$categories[$catId] = [];
}
$categories[$catId] = $category->toArrayTable($categories[$catId]);
}
unset($categoriesObj);
if (isset($categories[$catId])) {
$categories[$catId] = $category->toArraySimple($categories[$catId]);
$categories[$catId]['categoryPath'] = $category->getCategoryPath($helper->getConfig('format_linked_path'));
}
unset($catId, $category);
$xoopsTpl->assign('categories', $categories);
if ($helper->getConfig('index_display_last_items')) {
// creating the Item objects that belong to the selected category
switch ($helper->getConfig('format_order_by')) {
case 'title':
$sort = 'title';
$order = 'ASC';
break;
case 'date':
$sort = 'datesub';
$order = 'DESC';
break;
case 'counter':
$sort = 'counter';
$order = 'DESC';
break;
case 'rating':
$sort = 'rating';
$order = 'DESC';
break;
case 'votes':
$sort = 'votes';
$order = 'DESC';
break;
case 'comments':
$sort = 'comments';
$order = 'DESC';
break;
default:
$sort = 'weight';
$order = 'ASC';
break;
}
// Creating the last ITEMs
$itemsObj = $helper->getHandler('Item')->getAllPublished($helper->getConfig('idxcat_index_perpage'), $start, -1, $sort, $order);
$itemsCount = count($itemsObj);
//todo: make config for summary size
if ($itemsCount > 0) {
foreach ($itemsObj as $itemObj) {
$xoopsTpl->append('items', $itemObj->toArraySimple($helper->getConfig('idxcat_items_display_type'), $helper->getConfig('item_title_size'), 300, true)); //if no summary truncate body to 300
}
$xoopsTpl->assign('show_subtitle', $helper->getConfig('index_disp_subtitle'));
unset($allcategories, $itemObj);
}
unset($itemsObj);
}
// Language constants
$xoopsTpl->assign('title_and_welcome', $helper->getConfig('index_title_and_welcome')); //SHINE ADDED DEBUG mainintro txt
$xoopsTpl->assign('lang_mainintro', $myts->displayTarea($helper->getConfig('index_welcome_msg'), 1));
$xoopsTpl->assign('sectionname', $helper->getModule()->getVar('name'));
$xoopsTpl->assign('whereInSection', $helper->getModule()->getVar('name'));
$xoopsTpl->assign('module_home', Utility::moduleHome(false));
$xoopsTpl->assign('indexfooter', $myts->displayTarea($helper->getConfig('index_footer'), 1));
$xoopsTpl->assign('lang_category_summary', _MD_PUBLISHER_INDEX_CATEGORIES_SUMMARY);
$xoopsTpl->assign('lang_category_summary_info', _MD_PUBLISHER_INDEX_CATEGORIES_SUMMARY_INFO);
$xoopsTpl->assign('lang_items_title', _MD_PUBLISHER_INDEX_ITEMS);
$xoopsTpl->assign('indexpage', true);
require_once $GLOBALS['xoops']->path('class/pagenav.php');
// Category Navigation Bar
$pagenav = new \XoopsPageNav($totalCategories, $helper->getConfig('idxcat_cat_perpage'), $catstart, 'catstart', '');
if (1 == $helper->getConfig('format_image_nav')) {
$xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
} else {
$xoopsTpl->assign('catnavbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
}
// ITEM Navigation Bar
$pagenav = new \XoopsPageNav($real_total_items, $helper->getConfig('idxcat_index_perpage'), $start, 'start', '');
if (1 == $helper->getConfig('format_image_nav')) {
$xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>');
} else {
$xoopsTpl->assign('navbar', '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>');
}
//show subcategories
$xoopsTpl->assign('show_subcats', $helper->getConfig('idxcat_show_subcats'));
$xoopsTpl->assign('displaylastitems', $helper->getConfig('index_display_last_items'));
/**
* Generating meta information for this page
*/
$publisherMetagen = new Metagen($helper->getModule()->getVar('name'));
$publisherMetagen->createMetaTags();
// RSS Link
if (1 == $helper->getConfig('idxcat_show_rss_link')) {
$link = sprintf("<a href='%s' title='%s'><img src='%s' border=0 alt='%s'></a>", PUBLISHER_URL . '/backend.php', _MD_PUBLISHER_RSSFEED, PUBLISHER_URL . '/assets/images/rss.gif', _MD_PUBLISHER_RSSFEED);
$xoopsTpl->assign('rssfeed_link', $link);
}
require_once $GLOBALS['xoops']->path('footer.php');
?>
<!--<script type="text/javascript">-->
<!-- $(document).ready(function () {-->
<!-- $("img").addClass("img-responsive");-->
<!-- });-->
<!--</script>-->