-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcategories.php
128 lines (110 loc) · 4.71 KB
/
categories.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
<?php
/**
* MyWords for XOOPS
*
* Copyright © 2017 Eduardo Cortés http://www.eduardocortes.mx
* -------------------------------------------------------------
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
* -------------------------------------------------------------
* @copyright Eduardo Cortés (http://www.eduardocortes.mx)
* @license GNU GPL 2
* @package mywords
* @author Eduardo Cortés (AKA bitcero) <i.bitcero@gmail.com>
* @url http://www.eduardocortes.mx
*/
$GLOBALS['xoopsOption']['template_main'] = 'mywords-cats.tpl';
$xoopsOption['module_subpage'] = 'catego';
require __DIR__ . '/header.php';
$tbl1 = $db->prefix('mod_mywords_categories');
$tbl2 = $db->prefix('mod_mywords_catpost');
$tbl3 = $db->prefix('mod_mywords_posts');
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 0;
if ($page <= 0) {
$path = explode('/', $request);
$srh = array_search('page', $path, true);
if (isset($path[$srh]) && 'page' === $path[$srh]) {
if (!isset($path[$srh])) {
$page = 0;
} else {
$page = $path[$srh + 1];
}
}
}
/**
* Antes que nada debemos buscar la categoría
* si esta ha sido pasada como una ruta
*/
if (@$categotype) {
array_shift($path);
/**
* Comprobamos si el primer indice corresponde a la id de la categoría
*/
if (is_numeric($path[0])) {
$category = $path[0];
} else {
$idp = 0; # ID de la categoria padre
foreach ($path as $k) {
if ('' == $k) {
continue;
}
$sql = "SELECT id_cat FROM $tbl1 WHERE shortname='$k' AND parent='$idp'";
$result = $db->query($sql);
if ($db->getRowsNum($result) > 0) {
list($idp) = $db->fetchRow($result);
}
}
$category = $idp;
}
}
$catego = new MWCategory($category);
if ($catego->isNew()) {
redirect_header(MWFunctions::get_url(), 2, __('Specified category could not be found', 'mywords'));
die();
}
// Datos de la Categoría
$xoopsTpl->assign('category', ['id' => $catego->id(), 'name' => $catego->getVar('name')]);
$xoopsTpl->assign('lang_postsincat', sprintf(__('Posts in ‘%s’ Category', 'mywords'), $catego->getVar('name')));
$request = mb_substr($request, 0, mb_strpos($request, 'page') > 0 ? mb_strpos($request, 'page') - 1 : mb_strlen($request));
//$request =
// Select all posts from relations table
//$sql = "SELECT post FROM ".$db->prefix("mod_mywords_catpost")." WHERE cat='$category'";
//$result = $db->query($sql);
/**
* Paginacion de Resultados
*/
$limit = $mc['posts_limit'];
list($num) = $db->fetchRow($db->query("SELECT COUNT($tbl2.post) FROM $tbl2, $tbl3 WHERE $tbl2.cat='$category'
AND $tbl3.id_post=$tbl2.post AND $tbl3.status='publish' AND
(($tbl3.visibility='public' OR $tbl3.visibility='password') OR ($tbl3.visibility='private' AND
$tbl3.author=" . ($xoopsUser ? $xoopsUser->uid() : -1) . '))'));
$page = isset($page) && $page > 0 ? $page : 1;
$limit = $xoopsModuleConfig['posts_limit'];
$tpages = ceil($num / $limit);
$page = $page > $tpages ? $tpages : $page;
$p = $page > 0 ? $page - 1 : $page;
$start = $num <= 0 ? 0 : $p * $limit;
$xoopsTpl->assign('page', $page);
$nav = new RMPageNav($num, $limit, $page, 5);
$nav->target_url($catego->permalink() . (1 == $xoopsModuleConfig['permalinks'] ? '&page={PAGE_NUM}' : 'page/{PAGE_NUM}/'));
$xoopsTpl->assign('pagenav', $nav->render(false));
$xoopsTpl->assign('lang_permalink', __('Permalink to this post', 'mywords'));
$result = $db->query("SELECT $tbl3.* FROM $tbl2, $tbl3 WHERE $tbl2.cat='$category'
AND $tbl3.id_post=$tbl2.post AND $tbl3.status='publish' AND
(($tbl3.visibility='public' OR $tbl3.visibility='password') OR ($tbl3.visibility='private' AND
$tbl3.author=" . ($xoopsUser ? $xoopsUser->uid() : -1) . ")) ORDER BY $tbl3.pubdate DESC LIMIT $start,$limit");
require __DIR__ . '/post_data.php';
$xoopsTpl->assign('xoops_pagetitle', sprintf(__('Posts published under "%s"', 'mywords'), $catego->getVar('name')));
require __DIR__ . '/footer.php';