Completed
Pull Request — master (#3)
by Michael
01:28
created

viewcat.php (15 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
17
include_once 'header.php';
18
// template d'affichage
19
$xoopsOption['template_main'] = 'tdmdownloads_viewcat.tpl';
20
include_once XOOPS_ROOT_PATH.'/header.php';
21
$xoTheme->addStylesheet( XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/css/styles.css', null );
22
$cid = TDMDownloads_CleanVars($_REQUEST, 'cid', 0, 'int');
23
24
// pour les permissions
25
$categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads');
26
27
// redirection si la cat�gorie n'existe pas
28
$criteria = new CriteriaCompo();
29
$criteria->add(new Criteria('cat_cid', $cid));
30
if ($downloadscat_Handler->getCount($criteria) == 0 || $cid == 0) {
31
    redirect_header('index.php', 3, _MD_TDMDOWNLOADS_CAT_NONEXISTENT);
32
    exit();
33
}
34
// pour les permissions (si pas de droit, redirection)
35
if (!in_array(intval($cid), $categories)) {
36
    redirect_header('index.php', 2, _NOPERM);
37
    exit();
38
}
39
40
//tableau des cat�gories
41
$criteria = new CriteriaCompo();
42
$criteria->setSort('cat_weight ASC, cat_title');
43
$criteria->setOrder('ASC');
44
$criteria->add(new Criteria('cat_cid', '(' . implode(',', $categories) . ')','IN'));
45
$downloadscat_arr = $downloadscat_Handler->getall($criteria);
46
$mytree = new XoopsObjectTree($downloadscat_arr, 'cat_cid', 'cat_pid');
47
48
//tableau des t�l�chargements
49
$criteria = new CriteriaCompo();
50
$criteria->add(new Criteria('status', 0, '!='));
51
$criteria->add(new Criteria('cid', '(' . implode(',', $categories) . ')','IN'));
52
$downloads_arr = $downloads_Handler->getall($criteria);
53
$xoopsTpl->assign('lang_thereare', sprintf(_MD_TDMDOWNLOADS_INDEX_THEREARE, count($downloads_arr)));
54
55
//navigation
56
$nav_category = TDMDownloads_PathTreeUrl($mytree, $cid, $downloadscat_arr, 'cat_title', $prefix = ' <img src="images/deco/arrow.gif" alt="arrow" /> ', true, 'ASC');
57
$xoopsTpl->assign('category_path', $nav_category);
58
59
// info cat�gorie
60
$xoopsTpl->assign('category_id', $cid);
61
$cat_info = $downloadscat_Handler->get($cid);
62
$xoopsTpl->assign('cat_description', $cat_info->getVar('cat_description_main'));
63
64
//affichage des cat�gories
65
$xoopsTpl->assign('nb_catcol', $xoopsModuleConfig['nb_catcol']);
66
$count = 1;
67
$keywords = '';
68 View Code Duplication
foreach (array_keys($downloadscat_arr) as $i) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    if ($downloadscat_arr[$i]->getVar('cat_pid') == $cid) {
70
        $totaldownloads = TDMDownloads_NumbersOfEntries($mytree, $categories, $downloads_arr, $downloadscat_arr[$i]->getVar('cat_cid'));
71
        $subcategories_arr = $mytree->getFirstChild($downloadscat_arr[$i]->getVar('cat_cid'));
72
        $chcount = 0;
73
        $subcategories = '';
74
        //pour les mots clef
75
        $keywords .= $downloadscat_arr[$i]->getVar('cat_title') . ',';
76
        foreach (array_keys($subcategories_arr) as $j) {
77
                if ($chcount>=$xoopsModuleConfig['nbsouscat']) {
78
                    $subcategories .= '<li>[<a href="' . XOOPS_URL . '/modules/TDMDownloads/viewcat.php?cid=' . $downloadscat_arr[$i]->getVar('cat_cid') . '">+</a>]</li>';
79
                    break;
80
                }
81
                $subcategories .= '<li><a href="' . XOOPS_URL . '/modules/TDMDownloads/viewcat.php?cid=' . $subcategories_arr[$j]->getVar('cat_cid') . '">' . $subcategories_arr[$j]->getVar('cat_title') . '</a></li>';
82
                $keywords .= $downloadscat_arr[$i]->getVar('cat_title') . ',';
83
                $chcount++;
84
        }
85
        $xoopsTpl->append('subcategories', array('image' => $uploadurl . $downloadscat_arr[$i]->getVar('cat_imgurl'), 'id' => $downloadscat_arr[$i]->getVar('cat_cid'), 'title' => $downloadscat_arr[$i]->getVar('cat_title'), 'description_main' => $downloadscat_arr[$i]->getVar('cat_description_main'), 'infercategories' => $subcategories, 'totaldownloads' => $totaldownloads, 'count' => $count));
86
        $count++;
87
    }
88
}
89
90
//pour afficher les r�sum�s
91
//----------------------------------------------------------------------------------------------------------------------------------------------------
92
//t�l�chargements r�cents
93 View Code Duplication
if ($xoopsModuleConfig['bldate']==1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    $criteria = new CriteriaCompo();
95
    $criteria->add(new Criteria('status', 0, '!='));
96
    $criteria->add(new Criteria('cid', '(' . implode(',', $categories) . ')','IN'));
97
    $criteria->add(new Criteria('cid', intval($_REQUEST['cid'])));
98
    $criteria->setSort('date');
99
    $criteria->setOrder('DESC');
100
    $criteria->setLimit($xoopsModuleConfig['nbbl']);
101
    $downloads_arr = $downloads_Handler->getall($criteria);
102
    foreach (array_keys($downloads_arr) as $i) {
103
        $title = $downloads_arr[$i]->getVar('title');
104
        if (strlen($title) >= $xoopsModuleConfig['longbl']) {
105
                $title = substr($title,0,($xoopsModuleConfig['longbl']))."...";
106
        }
107
        $date = formatTimestamp($downloads_arr[$i]->getVar('date'),"s");
108
        $xoopsTpl->append('bl_date', array('id' => $downloads_arr[$i]->getVar('lid'),'cid' => $downloads_arr[$i]->getVar('cid'),'date' => $date,'title' => $title));
109
    }
110
}
111
//plus t�l�charg�s
112 View Code Duplication
if ($xoopsModuleConfig['blpop']==1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    $criteria = new CriteriaCompo();
114
    $criteria->add(new Criteria('status', 0, '!='));
115
    $criteria->add(new Criteria('cid', '(' . implode(',', $categories) . ')','IN'));
116
    $criteria->add(new Criteria('cid', intval($_REQUEST['cid'])));
117
    $criteria->setSort('hits');
118
    $criteria->setOrder('DESC');
119
    $criteria->setLimit($xoopsModuleConfig['nbbl']);
120
    $downloads_arr = $downloads_Handler->getall($criteria);
121
    foreach (array_keys($downloads_arr) as $i) {
122
        $title = $downloads_arr[$i]->getVar('title');
123
        if (strlen($title) >= $xoopsModuleConfig['longbl']) {
124
                $title = substr($title,0,($xoopsModuleConfig['longbl'])) . "...";
125
        }
126
        $xoopsTpl->append('bl_pop', array('id' => $downloads_arr[$i]->getVar('lid'),'cid' => $downloads_arr[$i]->getVar('cid'),'hits' => $downloads_arr[$i]->getVar('hits'),'title' => $title));
127
    }
128
}
129
//mieux not�s
130 View Code Duplication
if ($xoopsModuleConfig['blrating']==1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
131
    $criteria = new CriteriaCompo();
132
    $criteria->add(new Criteria('status', 0, '!='));
133
    $criteria->add(new Criteria('cid', '(' . implode(',', $categories) . ')','IN'));
134
    $criteria->add(new Criteria('cid', intval($_REQUEST['cid'])));
135
    $criteria->setSort('rating');
136
    $criteria->setOrder('DESC');
137
    $criteria->setLimit($xoopsModuleConfig['nbbl']);
138
    $downloads_arr = $downloads_Handler->getall($criteria);
139
    foreach (array_keys($downloads_arr) as $i) {
140
        $title = $downloads_arr[$i]->getVar('title');
141
        if (strlen($title) >= $xoopsModuleConfig['longbl']) {
142
                $title = substr($title,0,($xoopsModuleConfig['longbl']))."...";
143
        }
144
        $rating = number_format($downloads_arr[$i]->getVar('rating'),1);
145
        $xoopsTpl->append('bl_rating', array('id' => $downloads_arr[$i]->getVar('lid'),'cid' => $downloads_arr[$i]->getVar('cid'),'rating' => $rating,'title' => $title));
146
    }
147
}
148
// affichage du r�sum�
149 View Code Duplication
if ($xoopsModuleConfig['bldate']==0 and $xoopsModuleConfig['blpop']==0 and $xoopsModuleConfig['blrating']==0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
    $bl_affichage = 0;
151
} else {
152
    $bl_affichage = 1;
153
}
154
//----------------------------------------------------------------------------------------------------------------------------------------------------
155
156
// affichage des t�l�chargements
157
if ($xoopsModuleConfig['perpage'] > 0) {
158
    $xoopsTpl->assign('nb_dowcol', $xoopsModuleConfig['nb_dowcol']);
159
    //Utilisation d'une copie d'�cran avec la largeur selon les pr�f�rences
160 View Code Duplication
    if ($xoopsModuleConfig['useshots'] == 1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161
        $xoopsTpl->assign('shotwidth', $xoopsModuleConfig['shotwidth']);
162
        $xoopsTpl->assign('show_screenshot', true);
163
        $xoopsTpl->assign('img_float' , $xoopsModuleConfig['img_float']);
164
    }
165
    $criteria = new CriteriaCompo();
166
    $criteria->add(new Criteria('status', 0, '!='));
167
    $criteria->add(new Criteria('cid', '(' . implode(',', $categories) . ')','IN'));
168
    $criteria->add(new Criteria('cid', intval($_REQUEST['cid'])));
169
    $numrows = $downloads_Handler->getCount($criteria);
170
    $xoopsTpl->assign('lang_thereare', sprintf(_MD_TDMDOWNLOADS_CAT_THEREARE,$numrows));
171
172
    // Pour un affichage sur plusieurs pages
173 View Code Duplication
    if (isset($_REQUEST['limit'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
174
        $criteria->setLimit($_REQUEST['limit']);
175
        $limit = $_REQUEST['limit'];
176
    } else {
177
        $criteria->setLimit($xoopsModuleConfig['perpage']);
178
        $limit = $xoopsModuleConfig['perpage'];
179
    }
180 View Code Duplication
    if (isset($_REQUEST['start'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181
        $criteria->setStart($_REQUEST['start']);
182
        $start = $_REQUEST['start'];
183
    } else {
184
        $criteria->setStart(0);
185
        $start = 0;
186
    }
187 View Code Duplication
    if (isset($_REQUEST['sort'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
188
        $criteria->setSort($_REQUEST['sort']);
189
        $sort = $_REQUEST['sort'];
190
    } else {
191
        $criteria->setSort('date');
192
        $sort = 'date';
193
    }
194 View Code Duplication
    if (isset($_REQUEST['order'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
195
        $criteria->setOrder($_REQUEST['order']);
196
        $order = $_REQUEST['order'];
197
    } else {
198
        $criteria->setOrder('DESC');
199
        $order = 'DESC';
200
    }
201
202
    $downloads_arr = $downloads_Handler->getall($criteria);
203
    if ($numrows > $limit) {
204
        $pagenav = new XoopsPageNav($numrows, $limit, $start, 'start', 'limit=' . $limit . '&cid=' . intval($_REQUEST['cid']) . '&sort=' . $sort . '&order=' . $order);
205
        $pagenav = $pagenav->renderNav(4);
206
    } else {
207
        $pagenav = '';
208
    }
209
    $xoopsTpl->assign('pagenav', $pagenav);
210
    $summary = '';
211
    $cpt = 0;
212
    $categories = TDMDownloads_MygetItemIds('tdmdownloads_download', 'TDMDownloads');
213
    $item = TDMDownloads_MygetItemIds('tdmdownloads_download_item', 'TDMDownloads');
214
    foreach (array_keys($downloads_arr) as $i) {
215 View Code Duplication
        if ($downloads_arr[$i]->getVar('logourl') == 'blank.gif') {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
216
            $logourl = '';
217
        } else {
218
            $logourl = $downloads_arr[$i]->getVar('logourl');
219
            $logourl = $uploadurl_shots . $logourl;
220
        }
221
        $datetime = formatTimestamp($downloads_arr[$i]->getVar('date'),'s');
222
        $submitter = XoopsUser::getUnameFromId($downloads_arr[$i]->getVar('submitter'));
223
        $description = $downloads_arr[$i]->getVar('description');
224
        //permet d'afficher uniquement la description courte
225 View Code Duplication
        if (strpos($description,'[pagebreak]')==false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($description, '[pagebreak]') of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
            $description_short = $description;
227
        } else {
228
            $description_short = substr($description,0,strpos($description,'[pagebreak]'));
229
        }
230
        // pour les vignettes "new" et "mis � jour"
231
        $new = TDMDownloads_Thumbnail($downloads_arr[$i]->getVar('date'), $downloads_arr[$i]->getVar('status'));
232
        $pop = TDMDownloads_Popular($downloads_arr[$i]->getVar('hits'));
233
234
        // D�fini si la personne est un admin
235 View Code Duplication
        if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
236
            $adminlink = '<a href="' . XOOPS_URL . '/modules/TDMDownloads/admin/downloads.php?op=view_downloads&amp;downloads_lid=' . $downloads_arr[$i]->getVar('lid') . '" title="' . _MD_TDMDOWNLOADS_EDITTHISDL . '"><img src="' . XOOPS_URL . '/modules/TDMDownloads/images/icon/edit.png" width="16px" height="16px" border="0" alt="' . _MD_TDMDOWNLOADS_EDITTHISDL . '" /></a>';
237
        } else {
238
            $adminlink = '';
239
        }
240
        //permission de t�l�charger
241 View Code Duplication
        if ($xoopsModuleConfig['permission_download'] == 1) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
242
            if (!in_array($downloads_arr[$i]->getVar('cid'), $categories)) {
243
                $perm_download = false;
244
            } else {
245
                $perm_download = true;
246
            }
247
        } else {
248
            if (!in_array($downloads_arr[$i]->getVar('lid'), $item)) {
249
                $perm_download = false;
250
            } else {
251
                $perm_download = true;
252
            }
253
        }
254
        // utilisation du sommaire
255
        $cpt++;
256
        $summary = $cpt . '- <a href="#l' . $cpt . '">' . $downloads_arr[$i]->getVar('title') . '</a><br />';
257
        $xoopsTpl->append('summary', array('title' => $summary, 'count' => $cpt));
258
259
        $xoopsTpl->append('file', array('id' => $downloads_arr[$i]->getVar('lid'),'cid' => $downloads_arr[$i]->getVar('cid'), 'title' => $downloads_arr[$i]->getVar('title'), 'new' => $new, 'pop' => $pop,'logourl' => $logourl,'updated' => $datetime,'description_short' => $description_short,
260
                                        'adminlink' => $adminlink, 'submitter' => $submitter, 'perm_download' => $perm_download, 'count' => $cpt));
261
        //pour les mots clef
262
        $keywords .= $downloads_arr[$i]->getVar('title') . ',';
263
    }
264
265
    if ($numrows == 0) {
266
        $bl_affichage = 0;
267
    }
268
    $xoopsTpl->assign('bl_affichage', $bl_affichage);
269
270
    // affichage du sommaire
271
    if ($xoopsModuleConfig['autosummary']) {
272
        if ($numrows == 0) {
273
            $xoopsTpl->assign('aff_summary', false);
274
        } else {
275
            $xoopsTpl->assign('aff_summary', true);
276
        }
277
    } else {
278
        $xoopsTpl->assign('aff_summary', false);
279
    }
280
281
    // affichage du menu de tri
282
    if ($numrows>1) {
283
        $xoopsTpl->assign('navigation', true);
284
        $sortorder = $sort . $order;
285
        if ($sortorder == "hitsASC") $affichage_tri = _MD_TDMDOWNLOADS_CAT_POPULARITYLTOM;
286
        if ($sortorder == "hitsDESC") $affichage_tri = _MD_TDMDOWNLOADS_CAT_POPULARITYMTOL;
287
        if ($sortorder == "titleASC") $affichage_tri = _MD_TDMDOWNLOADS_CAT_TITLEATOZ;
288
        if ($sortorder == "titleDESC") $affichage_tri = _MD_TDMDOWNLOADS_CAT_TITLEZTOA;
289
        if ($sortorder == "dateASC") $affichage_tri = _MD_TDMDOWNLOADS_CAT_DATEOLD;
290
        if ($sortorder == "dateDESC") $affichage_tri = _MD_TDMDOWNLOADS_CAT_DATENEW;
291
        if ($sortorder == "ratingASC") $affichage_tri = _MD_TDMDOWNLOADS_CAT_RATINGLTOH;
292
        if ($sortorder == "ratingDESC") $affichage_tri = _MD_TDMDOWNLOADS_CAT_RATINGHTOL;
293
        $xoopsTpl->assign('affichage_tri', sprintf(_MD_TDMDOWNLOADS_CAT_CURSORTBY, $affichage_tri));
294
    }
295
}
296
// r�f�rencement
297
// titre de la page
298
$pagetitle = TDMDownloads_PathTreeUrl($mytree, $cid, $downloadscat_arr, 'cat_title', $prefix = ' - ', false, 'DESC');
299
$xoopsTpl->assign('xoops_pagetitle', $pagetitle);
300
//description
301
$xoTheme->addMeta( 'meta', 'description', strip_tags($downloadscat_arr[$cid]->getVar('cat_description_main')));
302
//keywords
303
$keywords = substr($keywords,0,-1);
304
$xoTheme->addMeta( 'meta', 'keywords', $keywords);
305
306
include XOOPS_ROOT_PATH.'/footer.php';
307