XoopsModules25x /
tdmdownloads
| 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 | * @param $options |
||||||
| 16 | * @return array |
||||||
| 17 | */ |
||||||
| 18 | |||||||
| 19 | use XoopsModules\Tdmdownloads; |
||||||
| 20 | |||||||
| 21 | /** |
||||||
| 22 | * @param $options |
||||||
| 23 | * @return array |
||||||
| 24 | */ |
||||||
| 25 | function b_tdmdownloads_top_show($options) |
||||||
| 26 | { |
||||||
| 27 | require dirname(__DIR__) . '/include/common.php'; |
||||||
| 28 | /** @var \XoopsModuleHandler $moduleHandler */ |
||||||
| 29 | $moduleHandler = xoops_getHandler('module'); |
||||||
| 30 | // get the name of the file's directory to get the "owner" of the block, i.e. its module, and not the "user", where it is currently |
||||||
| 31 | //$mydir = basename(dirname(__DIR__)); |
||||||
| 32 | $moduleDirName = basename(dirname(__DIR__)); |
||||||
| 33 | $mymodule = $moduleHandler->getByDirname($moduleDirName); |
||||||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||||||
| 34 | //appel de la class |
||||||
| 35 | /** @var \XoopsModules\Tdmdownloads\DownloadsHandler $downloadsHandler */ |
||||||
| 36 | $downloadsHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Downloads'); |
||||||
| 37 | $block = []; |
||||||
| 38 | $type_block = $options[0]; |
||||||
| 39 | $nb_entree = $options[1]; |
||||||
| 40 | $lenght_title = $options[2]; |
||||||
| 41 | $use_logo = $options[3]; |
||||||
| 42 | $use_description = $options[4]; |
||||||
| 43 | $show_inforation = $options[5]; |
||||||
| 44 | $logo_float = $options[6]; |
||||||
| 45 | $logo_white = $options[7]; |
||||||
| 46 | $lenght_description = $options[8]; |
||||||
| 47 | |||||||
| 48 | array_shift($options); |
||||||
| 49 | array_shift($options); |
||||||
| 50 | array_shift($options); |
||||||
| 51 | array_shift($options); |
||||||
| 52 | array_shift($options); |
||||||
| 53 | array_shift($options); |
||||||
| 54 | array_shift($options); |
||||||
| 55 | array_shift($options); |
||||||
| 56 | array_shift($options); |
||||||
| 57 | |||||||
| 58 | // Add styles |
||||||
| 59 | global $xoTheme; |
||||||
| 60 | $db = null; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 61 | |||||||
| 62 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/blocks.css', null); |
||||||
| 63 | /** @var \XoopsModules\Tdmdownloads\Utility $utility */ |
||||||
| 64 | $utility = new \XoopsModules\Tdmdownloads\Utility(); |
||||||
| 65 | |||||||
| 66 | $categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName); |
||||||
| 67 | $criteria = new \CriteriaCompo(); |
||||||
| 68 | $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN')); |
||||||
| 69 | if (!(0 == $options[0] && 1 === count($options))) { |
||||||
| 70 | $criteria->add(new \Criteria('cid', '(' . implode(',', $options) . ')', 'IN')); |
||||||
| 71 | } |
||||||
| 72 | $criteria->add(new \Criteria('status', 0, '!=')); |
||||||
| 73 | switch ($type_block) { // pour le bloc: dernier fichier |
||||||
| 74 | case 'date': |
||||||
| 75 | $criteria->setSort('date'); |
||||||
| 76 | $criteria->setOrder('DESC'); |
||||||
| 77 | break; |
||||||
| 78 | // pour le bloc: plus téléchargé |
||||||
| 79 | case 'hits': |
||||||
| 80 | $criteria->setSort('hits'); |
||||||
| 81 | $criteria->setOrder('DESC'); |
||||||
| 82 | break; |
||||||
| 83 | // pour le bloc: mieux noté |
||||||
| 84 | case 'rating': |
||||||
| 85 | $criteria->setSort('rating'); |
||||||
| 86 | $criteria->setOrder('DESC'); |
||||||
| 87 | break; |
||||||
| 88 | // pour le bloc: aléatoire |
||||||
| 89 | case 'random': |
||||||
| 90 | $criteria->setSort('RAND()'); |
||||||
| 91 | break; |
||||||
| 92 | } |
||||||
| 93 | $criteria->setLimit($nb_entree); |
||||||
| 94 | $downloads_arr = $downloadsHandler->getAll($criteria); |
||||||
| 95 | foreach (array_keys($downloads_arr) as $i) { |
||||||
| 96 | $block[$i]['lid'] = $downloads_arr[$i]->getVar('lid'); |
||||||
| 97 | $block[$i]['title'] = mb_strlen($downloads_arr[$i]->getVar('title')) > $lenght_title ? mb_substr($downloads_arr[$i]->getVar('title'), 0, $lenght_title) . '...' : $downloads_arr[$i]->getVar('title'); |
||||||
| 98 | $description_short = ''; |
||||||
| 99 | if (true === $use_description) { |
||||||
| 100 | $description = $downloads_arr[$i]->getVar('description'); |
||||||
| 101 | //permet d'afficher uniquement la description courte |
||||||
| 102 | if (false === mb_strpos($description, '[pagebreak]')) { |
||||||
| 103 | $description_short = mb_substr($description, 0, $lenght_description) . ' ...'; |
||||||
| 104 | } else { |
||||||
| 105 | $description_short = mb_substr($description, 0, mb_strpos($description, '[pagebreak]')) . ' ...'; |
||||||
| 106 | } |
||||||
| 107 | } |
||||||
| 108 | $block[$i]['description'] = $description_short; |
||||||
| 109 | $logourl = ''; |
||||||
| 110 | if (true === $use_logo) { |
||||||
| 111 | if ('blank.gif' === $downloads_arr[$i]->getVar('logourl')) { |
||||||
| 112 | $logourl = ''; |
||||||
| 113 | } else { |
||||||
| 114 | $logourl = XOOPS_URL . '/uploads/' . $moduleDirName . '/images/shots/' . $downloads_arr[$i]->getVar('logourl'); |
||||||
| 115 | } |
||||||
| 116 | } |
||||||
| 117 | $block[$i]['logourl'] = $logourl; |
||||||
| 118 | $block[$i]['logourl_class'] = $logo_float; |
||||||
| 119 | $block[$i]['logourl_width'] = $logo_white; |
||||||
| 120 | $block[$i]['hits'] = $downloads_arr[$i]->getVar('hits'); |
||||||
| 121 | $block[$i]['rating'] = number_format($downloads_arr[$i]->getVar('rating'), 1); |
||||||
| 122 | $block[$i]['date'] = formatTimestamp($downloads_arr[$i]->getVar('date'), 's'); |
||||||
| 123 | $block[$i]['submitter'] = \XoopsUser::getUnameFromId($downloads_arr[$i]->getVar('submitter')); |
||||||
| 124 | $block[$i]['inforation'] = $show_inforation; |
||||||
| 125 | } |
||||||
| 126 | |||||||
| 127 | return $block; |
||||||
| 128 | } |
||||||
| 129 | |||||||
| 130 | /** |
||||||
| 131 | * @param $options |
||||||
| 132 | * |
||||||
| 133 | * @return string |
||||||
| 134 | */ |
||||||
| 135 | function b_tdmdownloads_top_edit($options) |
||||||
| 136 | { |
||||||
| 137 | //appel de la class |
||||||
| 138 | $moduleDirName = basename(dirname(__DIR__)); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 139 | $categoryHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Category'); |
||||||
| 140 | $criteria = new \CriteriaCompo(); |
||||||
| 141 | $criteria = new \CriteriaCompo(); |
||||||
| 142 | $criteria->setSort('cat_weight ASC, cat_title'); |
||||||
| 143 | $criteria->setOrder('ASC'); |
||||||
| 144 | $downloadscatArray = $categoryHandler->getAll($criteria); |
||||||
|
0 ignored issues
–
show
The method
getAll() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoUserHandler or XoopsPersistableObjectHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 145 | $form = _MB_TDMDOWNLOADS_DISP . " \n"; |
||||||
| 146 | $form .= '<input type="hidden" name="options[0]" value="' . $options[0] . "\">\n"; |
||||||
| 147 | $form .= '<input name="options[1]" size="5" maxlength="255" value="' . $options[1] . '" type="text"> ' . _MB_TDMDOWNLOADS_FILES . "<br>\n"; |
||||||
| 148 | $form .= _MB_TDMDOWNLOADS_CHARS . ' : <input name="options[2]" size="5" maxlength="255" value="' . $options[2] . "\" type=\"text\"><br>\n"; |
||||||
| 149 | if (false === $options[3]) { |
||||||
| 150 | $checked_yes = ''; |
||||||
| 151 | $checked_no = 'checked'; |
||||||
| 152 | } else { |
||||||
| 153 | $checked_yes = 'checked'; |
||||||
| 154 | $checked_no = ''; |
||||||
| 155 | } |
||||||
| 156 | $form .= _MB_TDMDOWNLOADS_LOGO . ' : <input name="options[3]" value="1" type="radio" ' . $checked_yes . '>' . _YES . " \n"; |
||||||
| 157 | $form .= '<input name="options[3]" value="0" type="radio" ' . $checked_no . '>' . _NO . "<br>\n"; |
||||||
| 158 | if (false === $options[4]) { |
||||||
| 159 | $checked_yes = ''; |
||||||
| 160 | $checked_no = 'checked'; |
||||||
| 161 | } else { |
||||||
| 162 | $checked_yes = 'checked'; |
||||||
| 163 | $checked_no = ''; |
||||||
| 164 | } |
||||||
| 165 | $form .= _MB_TDMDOWNLOADS_DESCRIPTION . ' : <input name="options[4]" value="1" type="radio" ' . $checked_yes . '>' . _YES . " \n"; |
||||||
| 166 | $form .= '<input name="options[4]" value="0" type="radio" ' . $checked_no . '>' . _NO . "<br>\n"; |
||||||
| 167 | if (false === $options[5]) { |
||||||
| 168 | $checked_yes = ''; |
||||||
| 169 | $checked_no = 'checked'; |
||||||
| 170 | } else { |
||||||
| 171 | $checked_yes = 'checked'; |
||||||
| 172 | $checked_no = ''; |
||||||
| 173 | } |
||||||
| 174 | $form .= _MB_TDMDOWNLOADS_INFORMATIONS . ' : <input name="options[5]" value="1" type="radio" ' . $checked_yes . '>' . _YES . " \n"; |
||||||
| 175 | $form .= '<input name="options[5]" value="0" type="radio" ' . $checked_no . '>' . _NO . "<br><br>\n"; |
||||||
| 176 | $floatelect = new \XoopsFormSelect(_MB_TDMDOWNLOADS_FLOAT, 'options[6]', $options[6]); |
||||||
| 177 | $floatelect->addOption('left', _MB_TDMDOWNLOADS_FLOAT_LEFT); |
||||||
| 178 | $floatelect->addOption('right', _MB_TDMDOWNLOADS_FLOAT_RIGHT); |
||||||
| 179 | $form .= _MB_TDMDOWNLOADS_FLOAT . ' : ' . $floatelect->render() . '<br>'; |
||||||
| 180 | $form .= _MB_TDMDOWNLOADS_WHITE . ' : <input name="options[7]" size="5" maxlength="255" value="' . $options[7] . "\" type=\"text\"><br>\n"; |
||||||
| 181 | $form .= _MB_TDMDOWNLOADS_CHARSDSC . ' : <input name="options[8]" size="5" maxlength="255" value="' . $options[8] . "\" type=\"text\"><br>\n"; |
||||||
| 182 | array_shift($options); |
||||||
| 183 | array_shift($options); |
||||||
| 184 | array_shift($options); |
||||||
| 185 | array_shift($options); |
||||||
| 186 | array_shift($options); |
||||||
| 187 | array_shift($options); |
||||||
| 188 | array_shift($options); |
||||||
| 189 | array_shift($options); |
||||||
| 190 | array_shift($options); |
||||||
| 191 | $form .= _MB_TDMDOWNLOADS_CATTODISPLAY . "<br><select name=\"options[]\" multiple=\"multiple\" size=\"5\">\n"; |
||||||
| 192 | $form .= '<option value="0" ' . (!in_array(0, $options, true) ? '' : 'selected="selected"') . '>' . _MB_TDMDOWNLOADS_ALLCAT . "</option>\n"; |
||||||
| 193 | foreach (array_keys($downloadscatArray) as $i) { |
||||||
| 194 | $form .= '<option value="' . $downloadscatArray[$i]->getVar('cat_cid') . '" ' . (!in_array($downloadscatArray[$i]->getVar('cat_cid'), $options, true) ? '' : 'selected') . '>' . $downloadscatArray[$i]->getVar('cat_title') . "</option>\n"; |
||||||
| 195 | } |
||||||
| 196 | $form .= "</select>\n"; |
||||||
| 197 | |||||||
| 198 | return $form; |
||||||
| 199 | } |
||||||
| 200 |