This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | // ------------------------------------------------------------------------ // |
||
3 | // BOOKSHOP - MODULE FOR XOOPS 2 // |
||
4 | // Copyright (c) 2007, 2008 Instant Zero // |
||
5 | // <http://www.instant-zero.com/> // |
||
6 | // ------------------------------------------------------------------------- // |
||
7 | // This program is free software; you can redistribute it and/or modify // |
||
8 | // it under the terms of the GNU General Public License as published by // |
||
9 | // the Free Software Foundation; either version 2 of the License, or // |
||
10 | // (at your option) any later version. // |
||
11 | // // |
||
12 | // You may not change or alter any portion of this comment or credits // |
||
13 | // of supporting developers from this source code or any supporting // |
||
14 | // source code which is considered copyrighted (c) material of the // |
||
15 | // original comment or credit authors. // |
||
16 | // // |
||
17 | // This program is distributed in the hope that it will be useful, // |
||
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
20 | // GNU General Public License for more details. // |
||
21 | // // |
||
22 | // You should have received a copy of the GNU General Public License // |
||
23 | // along with this program; if not, write to the Free Software // |
||
24 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
25 | // ------------------------------------------------------------------------ // |
||
26 | /** |
||
27 | * Page d'index, liste des derniers livres parus |
||
28 | */ |
||
29 | include __DIR__ . '/header.php'; |
||
30 | $GLOBALS['current_category'] = -1; |
||
31 | $xoopsOption['template_main'] = 'bookshop_index.tpl'; |
||
32 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
33 | include_once BOOKSHOP_PATH . 'class/registryfile.php'; |
||
34 | |||
35 | // Initialisations |
||
36 | $tbl_books = $tbl_categories = $tbl_lang = $tbl_users = $tbl_tmp_user = $tbl_tmp_categ = $tbl_tmp_lang = $tbl_tmp_vat = $tbl_vat = array(); |
||
37 | $tbl_books_id = $tbl_auteurs = $tbl_infos_auteurs = $tbl_tmp_auteurs = array(); |
||
38 | $tbl_tmp_related = $tbl_related = $tbl_info_related_books = array(); |
||
39 | $tbl_related_books = array(); |
||
40 | $start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
||
41 | $limit = bookshop_getmoduleoption('newbooks'); // Maximum number of items to display in the admin |
||
42 | $baseurl = BOOKSHOP_URL . basename(__FILE__); // URL de ce script (sans son nom) |
||
43 | |||
44 | $registry = new bookshop_registryfile(); |
||
45 | |||
46 | // Some options for template |
||
47 | $xoopsTpl->assign('nostock_msg', bookshop_getmoduleoption('nostock_msg')); |
||
48 | $xoopsTpl->assign('mod_pref', $mod_pref); // Module Preferences |
||
49 | $xoopsTpl->assign('welcome_msg', nl2br($registry->getfile('bookshop_index.txt'))); |
||
50 | |||
51 | // / Get the total number of books published in the database |
||
52 | $xoopsTpl->assign('total_books_count', sprintf(_BOOKSHOP_THEREARE, $h_bookshop_books->getTotalPublishedBooksCount())); |
||
53 | |||
54 | View Code Duplication | if ($limit > 0) { |
|
0 ignored issues
–
show
|
|||
55 | // Get the list of recent books |
||
56 | $tbl_books = $h_bookshop_books->getRecentBooks($start, $limit); |
||
57 | |||
58 | // Get ID only necessary |
||
59 | foreach ($tbl_books as $item) { |
||
60 | $tbl_tmp_user[] = $item->getVar('book_submitter'); |
||
61 | $tbl_tmp_categ[] = $item->getVar('book_cid'); |
||
62 | $tbl_tmp_lang[] = $item->getVar('book_lang_id'); |
||
63 | $tbl_tmp_vat[] = $item->getVar('book_vat_id'); |
||
64 | $tbl_books_id[] = $item->getVar('book_id'); |
||
65 | } |
||
66 | // Dedupe tables |
||
67 | $tbl_tmp_user = array_unique($tbl_tmp_user); |
||
68 | $tbl_tmp_categ = array_unique($tbl_tmp_categ); |
||
69 | $tbl_tmp_lang = array_unique($tbl_tmp_lang); |
||
70 | $tbl_tmp_vat = array_unique($tbl_tmp_vat); |
||
71 | |||
72 | sort($tbl_tmp_user); |
||
73 | sort($tbl_tmp_categ); |
||
74 | sort($tbl_tmp_lang); |
||
75 | sort($tbl_tmp_vat); |
||
76 | sort($tbl_books_id); |
||
77 | |||
78 | // Get the list of authors |
||
79 | // We start by searching the list of all authors and translators of all the books |
||
80 | $tbl_books_auteurs = array(); |
||
81 | $tbl_auteurs = $h_bookshop_booksauthors->getObjects(new Criteria('ba_book_id', '(' . implode(',', $tbl_books_id) . ')', 'IN'), true); |
||
82 | if (count($tbl_auteurs) > 0) { |
||
83 | foreach ($tbl_auteurs as $item) { |
||
84 | $tbl_tmp_auteurs[] = $item->getVar('ba_auth_id'); |
||
85 | // Grouping data by book |
||
86 | $tbl_books_auteurs[$item->getVar('ba_book_id')][] = $item; |
||
87 | } |
||
88 | $tbl_tmp_auteurs = array_unique($tbl_tmp_auteurs); |
||
89 | sort($tbl_tmp_auteurs); |
||
90 | // Then recovered the information from these authors / translators |
||
91 | $tbl_infos_auteurs = $h_bookshop_authors->getObjects(new Criteria('auth_id', '(' . implode(',', $tbl_tmp_auteurs) . ')', 'IN'), true); |
||
92 | } |
||
93 | |||
94 | // Get a list of all related books |
||
95 | $tbl_related = $h_bookshop_related->getObjects(new Criteria('related_book_id', '(' . implode(',', $tbl_books_id) . ')', 'IN'), true); |
||
96 | foreach ($tbl_related as $item) { |
||
97 | $tbl_tmp_related[] = $item->getVar('related_book_related'); |
||
98 | $tbl_related_books[$item->getVar('related_book_id')][] = $item; |
||
99 | } |
||
100 | $tbl_tmp_related = array_unique($tbl_tmp_related); |
||
101 | sort($tbl_tmp_related); |
||
102 | |||
103 | // Then we grab the title and ID books |
||
104 | if (count($tbl_tmp_related) > 0) { |
||
105 | $tbl_info_related_books = $h_bookshop_books->getIdTitle(new Criteria('book_id', '(' . implode(',', $tbl_tmp_related) . ')', 'IN')); |
||
106 | } |
||
107 | |||
108 | // Get the list of categories |
||
109 | if (count($tbl_tmp_categ) > 0) { |
||
110 | $tbl_categories = $h_bookshop_cat->getObjects(new Criteria('cat_cid', '(' . implode(',', $tbl_tmp_categ) . ')', 'IN'), true); |
||
111 | } |
||
112 | |||
113 | // Get the list of languages |
||
114 | if (count($tbl_tmp_lang) > 0) { |
||
115 | $tbl_lang = $h_bookshop_lang->getObjects(new Criteria('lang_id', '(' . implode(',', $tbl_tmp_lang) . ')', 'IN'), true); |
||
116 | } |
||
117 | |||
118 | // Get the list of VAT |
||
119 | if (count($tbl_tmp_vat) > 0) { |
||
120 | $tbl_vat = $h_bookshop_vat->getObjects(new Criteria('vat_id', '(' . implode(',', $tbl_tmp_vat) . ')', 'IN'), true); |
||
121 | } |
||
122 | |||
123 | // Get the list of people who have published these recent books |
||
124 | if (count($tbl_tmp_user) > 0) { |
||
125 | $user_handler = $member_handler = xoops_getHandler('user'); |
||
126 | $criteria = new Criteria('uid', '(' . implode(',', $tbl_tmp_user) . ')', 'IN'); |
||
127 | $tbl_users = $user_handler->getObjects($criteria, true); |
||
128 | } |
||
129 | |||
130 | // Process books |
||
131 | $lastTitle = ''; |
||
132 | foreach ($tbl_books as $item) { |
||
133 | $tbl_tmp = array(); |
||
134 | $tbl_tmp = $item->toArray(); |
||
135 | if (xoops_trim($lastTitle) == '') { |
||
136 | $lastTitle = $item->getVar('book_title'); |
||
137 | } |
||
138 | $tbl_tmp['book_category'] = $tbl_categories[$item->getVar('book_cid')]; |
||
139 | $tbl_tmp['book_language'] = $tbl_lang[$item->getVar('book_lang_id')]; |
||
140 | $thisuser = $tbl_users[$item->getVar('book_submitter')]; |
||
141 | if (xoops_trim($thisuser->getVar('name')) != '') { |
||
142 | $name = $thisuser->getVar('name'); |
||
143 | } else { |
||
144 | $name = $thisuser->getVar('uname'); |
||
145 | } |
||
146 | $tbl_tmp['book_submiter_name'] = $name; |
||
147 | $linkeduser = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $thisuser->getVar('uid') . '">' . $name . '</a>'; |
||
148 | $tbl_tmp['book_submiter_link'] = $name; |
||
149 | $tbl_tmp['book_vat_rate'] = $tbl_vat[$item->getVar('book_vat_id')]; |
||
150 | $tbl_tmp['book_price_ttc'] = bookshop_getTTC($item->getVar('book_price'), $tbl_vat[$item->getVar('book_vat_id')]->getVar('vat_rate')); |
||
151 | $tbl_tmp['book_discount_price_ttc'] = bookshop_getTTC($item->getVar('book_discount_price'), $tbl_vat[$item->getVar('book_vat_id')]->getVar('vat_rate')); |
||
152 | |||
153 | // Search for authors / translators |
||
154 | $tbl_join1 = $tbl_join2 = array(); |
||
155 | if (isset($tbl_books_auteurs[$item->getVar('book_id')])) { |
||
156 | $tbl_tmp2 = $tbl_books_auteurs[$item->getVar('book_id')]; // Returns the list of all authors / translators of a book |
||
157 | } else { |
||
158 | $tbl_tmp2 = array(); |
||
159 | } |
||
160 | $tbl_livre_auteurs = $tbl_livre_traducteurs = array(); |
||
161 | foreach ($tbl_tmp2 as $oneauthor) { |
||
162 | $auteur = $tbl_infos_auteurs[$oneauthor->getVar('ba_auth_id')]; |
||
163 | if ($oneauthor->getVar('ba_type') == 1) { |
||
164 | $tbl_livre_auteurs[] = $auteur->toArray(); |
||
165 | $tbl_join1[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
||
166 | } else { |
||
167 | $tbl_livre_traducteurs[] = $auteur->toArray(); |
||
168 | $tbl_join2[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
||
169 | } |
||
170 | } |
||
171 | if (count($tbl_join1) > 0) { |
||
172 | $tbl_tmp['book_joined_authors'] = implode(', ', $tbl_join1); |
||
173 | } |
||
174 | if (count($tbl_join2) > 0) { |
||
175 | $tbl_tmp['book_joined_translators'] = implode(', ', $tbl_join2); |
||
176 | } |
||
177 | $tbl_tmp['book_authors'] = $tbl_livre_auteurs; |
||
178 | $tbl_tmp['book_translators'] = $tbl_livre_traducteurs; |
||
179 | |||
180 | // Recherche des livres relatifs, s'il y en a ! |
||
181 | $tbl_related = $tbl_tmp2 = array(); |
||
182 | if (isset($tbl_related_books[$item->getVar('book_id')])) { |
||
183 | $tbl_tmp2 = $tbl_related_books[$item->getVar('book_id')]; // Contains the list of books relating to EC book |
||
184 | foreach ($tbl_tmp2 as $onerelated) { |
||
185 | $book_id = $onerelated->getVar('related_book_id'); |
||
186 | if (isset($tbl_info_related_books[$book_id])) { |
||
187 | $tbl_related[] = array('related_book_id' => $book_id, 'related_book_title' => $tbl_info_related_books[$book_id]); |
||
188 | } |
||
189 | } |
||
190 | } |
||
191 | $tbl_tmp['book_related_books'] = $tbl_related; |
||
192 | // And we place everything into the template |
||
193 | $xoopsTpl->append('books', $tbl_tmp); |
||
194 | } |
||
195 | } |
||
196 | |||
197 | // Setup the categories of level 1 |
||
198 | $tbl_categories = array(); |
||
199 | $criteria = new Criteria('cat_pid', 0, '='); |
||
200 | $criteria->setSort('cat_title'); |
||
201 | $tbl_categories = $h_bookshop_cat->getObjects($criteria, true); |
||
202 | $count = 1; |
||
203 | foreach ($tbl_categories as $item) { |
||
204 | $tbl_tmp = $item->toArray(); |
||
205 | $tbl_tmp['count'] = $count; |
||
206 | $tbl_tmp['cat_url_rewrited'] = $h_bookshop_cat->GetCategoryLink($item->getVar('cat_cid'), $item->getVar('cat_title')); |
||
207 | $tbl_tmp['cat_href_title'] = bookshop_makeHrefTitle($item->getVar('cat_title')); |
||
208 | $xoopsTpl->append('categories', $tbl_tmp); |
||
209 | ++$count; |
||
210 | } |
||
211 | |||
212 | bookshop_setCSS(); |
||
213 | if (xoops_trim($lastTitle) != '') { |
||
214 | $lastTitle = strip_tags($lastTitle) . ' - '; |
||
215 | } |
||
216 | bookshop_set_metas($lastTitle . bookshop_get_module_name(), bookshop_get_module_name()); |
||
217 | include_once(XOOPS_ROOT_PATH . '/footer.php'); |
||
218 |
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.