mambax7 /
bookshop
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 | * **************************************************************************** |
||
| 4 | * bookshop - MODULE FOR XOOPS |
||
| 5 | * Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
||
| 6 | * **************************************************************************** |
||
| 7 | */ |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Displays a list of recommended books |
||
| 11 | */ |
||
| 12 | |||
| 13 | include __DIR__ . '/header.php'; |
||
| 14 | $GLOBALS['current_category'] = -1; |
||
| 15 | $xoopsOption['template_main'] = 'bookshop_recommended.tpl'; |
||
| 16 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 17 | include_once BOOKSHOP_PATH . 'class/registryfile.php'; |
||
| 18 | include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 19 | |||
| 20 | // Initialisations |
||
| 21 | $tbl_books = $tbl_categories = $tbl_lang = $tbl_users = $tbl_tmp_user = $tbl_tmp_categ = $tbl_tmp_lang = $tbl_tmp_vat = $tbl_vat = array(); |
||
| 22 | $tbl_books_id = $tbl_auteurs = $tbl_infos_auteurs = $tbl_tmp_auteurs = array(); |
||
| 23 | $tbl_tmp_related = $tbl_related = $tbl_info_related_books = array(); |
||
| 24 | $tbl_related_books = array(); |
||
| 25 | $start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
||
| 26 | $limit = bookshop_getmoduleoption('perpage'); // Maximum number of items to display in the admin |
||
| 27 | $baseurl = BOOKSHOP_URL . basename(__FILE__); // URL of the script (no name) |
||
| 28 | |||
| 29 | $registry = new bookshop_registryfile(); |
||
| 30 | |||
| 31 | // Some options for template |
||
| 32 | $xoopsTpl->assign('nostock_msg', bookshop_getmoduleoption('nostock_msg')); |
||
| 33 | $xoopsTpl->assign('mod_pref', $mod_pref); // Module Preferences |
||
| 34 | $xoopsTpl->assign('welcome_msg', nl2br($registry->getfile('bookshop_recomm.txt'))); |
||
| 35 | |||
| 36 | $itemsCount = $h_bookshop_books->getRecommendedCount(); |
||
| 37 | if ($itemsCount > $limit) { |
||
| 38 | $pagenav = new XoopsPageNav($itemsCount, $limit, $start); |
||
| 39 | $xoopsTpl->assign('pagenav', $pagenav->renderNav()); |
||
| 40 | } |
||
| 41 | |||
| 42 | View Code Duplication | if ($limit > 0) { |
|
|
0 ignored issues
–
show
|
|||
| 43 | // Get the list of recent books |
||
| 44 | $tbl_books = $h_bookshop_books->getRecentRecommendedBooks($start, $limit); |
||
| 45 | |||
| 46 | // Get ID only necessary |
||
| 47 | foreach ($tbl_books as $item) { |
||
| 48 | $tbl_tmp_user[] = $item->getVar('book_submitter'); |
||
| 49 | $tbl_tmp_categ[] = $item->getVar('book_cid'); |
||
| 50 | $tbl_tmp_lang[] = $item->getVar('book_lang_id'); |
||
| 51 | $tbl_tmp_vat[] = $item->getVar('book_vat_id'); |
||
| 52 | $tbl_books_id[] = $item->getVar('book_id'); |
||
| 53 | } |
||
| 54 | // Dedupe tables |
||
| 55 | $tbl_tmp_user = array_unique($tbl_tmp_user); |
||
| 56 | $tbl_tmp_categ = array_unique($tbl_tmp_categ); |
||
| 57 | $tbl_tmp_lang = array_unique($tbl_tmp_lang); |
||
| 58 | $tbl_tmp_vat = array_unique($tbl_tmp_vat); |
||
| 59 | |||
| 60 | sort($tbl_tmp_user); |
||
| 61 | sort($tbl_tmp_categ); |
||
| 62 | sort($tbl_tmp_lang); |
||
| 63 | sort($tbl_tmp_vat); |
||
| 64 | sort($tbl_books_id); |
||
| 65 | |||
| 66 | // Get the list of authors |
||
| 67 | // On commence en cherchant la liste de tous les auteurs et traducteurs de tous les livres |
||
| 68 | $tbl_books_auteurs = array(); |
||
| 69 | $tbl_auteurs = $h_bookshop_booksauthors->getObjects(new Criteria('ba_book_id', '(' . implode(',', $tbl_books_id) . ')', 'IN'), true); |
||
| 70 | if (count($tbl_auteurs) > 0) { |
||
| 71 | foreach ($tbl_auteurs as $item) { |
||
| 72 | $tbl_tmp_auteurs[] = $item->getVar('ba_auth_id'); |
||
| 73 | // Grouping data by book |
||
| 74 | $tbl_books_auteurs[$item->getVar('ba_book_id')][] = $item; |
||
| 75 | } |
||
| 76 | $tbl_tmp_auteurs = array_unique($tbl_tmp_auteurs); |
||
| 77 | sort($tbl_tmp_auteurs); |
||
| 78 | // Then recovered the information from these authors / translators |
||
| 79 | $tbl_infos_auteurs = $h_bookshop_authors->getObjects(new Criteria('auth_id', '(' . implode(',', $tbl_tmp_auteurs) . ')', 'IN'), true); |
||
| 80 | } |
||
| 81 | |||
| 82 | // Get a list of all related books |
||
| 83 | $tbl_related = $h_bookshop_related->getObjects(new Criteria('related_book_id', '(' . implode(',', $tbl_books_id) . ')', 'IN'), true); |
||
| 84 | foreach ($tbl_related as $item) { |
||
| 85 | $tbl_tmp_related[] = $item->getVar('related_book_related'); |
||
| 86 | $tbl_related_books[$item->getVar('related_book_id')][] = $item; |
||
| 87 | } |
||
| 88 | $tbl_tmp_related = array_unique($tbl_tmp_related); |
||
| 89 | sort($tbl_tmp_related); |
||
| 90 | |||
| 91 | // Then we grab the title and ID book |
||
| 92 | if (count($tbl_tmp_related) > 0) { |
||
| 93 | $tbl_info_related_books = $h_bookshop_books->getIdTitle(new Criteria('book_id', '(' . implode(',', $tbl_tmp_related) . ')', 'IN')); |
||
| 94 | } |
||
| 95 | |||
| 96 | // Get the list of categories |
||
| 97 | if (count($tbl_tmp_categ) > 0) { |
||
| 98 | $tbl_categories = $h_bookshop_cat->getObjects(new Criteria('cat_cid', '(' . implode(',', $tbl_tmp_categ) . ')', 'IN'), true); |
||
| 99 | } |
||
| 100 | |||
| 101 | // Get the list of languages |
||
| 102 | if (count($tbl_tmp_lang) > 0) { |
||
| 103 | $tbl_lang = $h_bookshop_lang->getObjects(new Criteria('lang_id', '(' . implode(',', $tbl_tmp_lang) . ')', 'IN'), true); |
||
| 104 | } |
||
| 105 | |||
| 106 | // Get the list of VAT |
||
| 107 | if (count($tbl_tmp_vat) > 0) { |
||
| 108 | $tbl_vat = $h_bookshop_vat->getObjects(new Criteria('vat_id', '(' . implode(',', $tbl_tmp_vat) . ')', 'IN'), true); |
||
| 109 | } |
||
| 110 | |||
| 111 | // Get the list of people who have published these recent books |
||
| 112 | if (count($tbl_tmp_user) > 0) { |
||
| 113 | $user_handler = $member_handler = xoops_getHandler('user'); |
||
| 114 | $criteria = new Criteria('uid', '(' . implode(',', $tbl_tmp_user) . ')', 'IN'); |
||
| 115 | $tbl_users = $user_handler->getObjects($criteria, true); |
||
| 116 | } |
||
| 117 | |||
| 118 | // Process books |
||
| 119 | $lastTitle = ''; |
||
| 120 | foreach ($tbl_books as $item) { |
||
| 121 | $tbl_tmp = array(); |
||
| 122 | $tbl_tmp = $item->toArray(); |
||
| 123 | if (xoops_trim($lastTitle) == '') { |
||
| 124 | $lastTitle = $item->getVar('book_title'); |
||
| 125 | } |
||
| 126 | $tbl_tmp['book_category'] = $tbl_categories[$item->getVar('book_cid')]; |
||
| 127 | $tbl_tmp['book_language'] = $tbl_lang[$item->getVar('book_lang_id')]; |
||
| 128 | $thisuser = $tbl_users[$item->getVar('book_submitter')]; |
||
| 129 | if (xoops_trim($thisuser->getVar('name')) != '') { |
||
| 130 | $name = $thisuser->getVar('name'); |
||
| 131 | } else { |
||
| 132 | $name = $thisuser->getVar('uname'); |
||
| 133 | } |
||
| 134 | $tbl_tmp['book_submiter_name'] = $name; |
||
| 135 | $linkeduser = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $thisuser->getVar('uid') . '">' . $name . '</a>'; |
||
| 136 | $tbl_tmp['book_submiter_link'] = $name; |
||
| 137 | $tbl_tmp['book_vat_rate'] = $tbl_vat[$item->getVar('book_vat_id')]; |
||
| 138 | $tbl_tmp['book_price_ttc'] = bookshop_getTTC($item->getVar('book_price'), $tbl_vat[$item->getVar('book_vat_id')]->getVar('vat_rate')); |
||
| 139 | $tbl_tmp['book_discount_price_ttc'] = bookshop_getTTC($item->getVar('book_discount_price'), $tbl_vat[$item->getVar('book_vat_id')]->getVar('vat_rate')); |
||
| 140 | |||
| 141 | // Search for authors / translators |
||
| 142 | $tbl_join1 = $tbl_join2 = array(); |
||
| 143 | if (isset($tbl_books_auteurs[$item->getVar('book_id')])) { |
||
| 144 | $tbl_tmp2 = $tbl_books_auteurs[$item->getVar('book_id')]; // Returns a list of all authors / translators of a book |
||
| 145 | } else { |
||
| 146 | $tbl_tmp2 = array(); |
||
| 147 | } |
||
| 148 | $tbl_livre_auteurs = $tbl_livre_traducteurs = array(); |
||
| 149 | foreach ($tbl_tmp2 as $oneauthor) { |
||
| 150 | $auteur = $tbl_infos_auteurs[$oneauthor->getVar('ba_auth_id')]; |
||
| 151 | if ($oneauthor->getVar('ba_type') == 1) { |
||
| 152 | $tbl_livre_auteurs[] = $auteur->toArray(); |
||
| 153 | $tbl_join1[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
||
| 154 | } else { |
||
| 155 | $tbl_livre_traducteurs[] = $auteur->toArray(); |
||
| 156 | $tbl_join2[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | if (count($tbl_join1) > 0) { |
||
| 160 | $tbl_tmp['book_joined_authors'] = implode(', ', $tbl_join1); |
||
| 161 | } |
||
| 162 | if (count($tbl_join2) > 0) { |
||
| 163 | $tbl_tmp['book_joined_translators'] = implode(', ', $tbl_join2); |
||
| 164 | } |
||
| 165 | $tbl_tmp['book_authors'] = $tbl_livre_auteurs; |
||
| 166 | $tbl_tmp['book_translators'] = $tbl_livre_traducteurs; |
||
| 167 | |||
| 168 | // Recherche des livres relatifs, s'il y en a ! |
||
| 169 | $tbl_related = $tbl_tmp2 = array(); |
||
| 170 | if (isset($tbl_related_books[$item->getVar('book_id')])) { |
||
| 171 | $tbl_tmp2 = $tbl_related_books[$item->getVar('book_id')]; // Contient la liste des livres relatifs � CE livre |
||
| 172 | foreach ($tbl_tmp2 as $onerelated) { |
||
| 173 | $book_id = $onerelated->getVar('related_book_id'); |
||
| 174 | if (isset($tbl_info_related_books[$book_id])) { |
||
| 175 | $tbl_related[] = array('related_book_id' => $book_id, 'related_book_title' => $tbl_info_related_books[$book_id]); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | } |
||
| 179 | $tbl_tmp['book_related_books'] = $tbl_related; |
||
| 180 | // Et on place le tout dans le template |
||
| 181 | $xoopsTpl->append('books', $tbl_tmp); |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | bookshop_setCSS(); |
||
| 186 | bookshop_set_metas(_BOOKSHOP_RECOMMENDED . ' - ' . bookshop_get_module_name(), bookshop_get_module_name()); |
||
| 187 | include_once(XOOPS_ROOT_PATH . '/footer.php'); |
||
| 188 |
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.