XoopsModules25x /
tdmdownloads
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 | error_reporting(0); |
||
| 18 | include 'header.php'; |
||
| 19 | |||
| 20 | $lid = TDMDownloads_CleanVars($_REQUEST, 'lid', 0, 'int'); |
||
| 21 | $cid = TDMDownloads_CleanVars($_REQUEST, 'cid', 0, 'int'); |
||
| 22 | // redirection si le t�l�chargement n'existe pas |
||
| 23 | $view_downloads = $downloads_Handler->get($lid); |
||
| 24 | if (count($view_downloads) == 0) { |
||
| 25 | redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT); |
||
| 26 | exit(); |
||
| 27 | } |
||
| 28 | //redirection si pas de permission (cat) |
||
| 29 | $categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads'); |
||
| 30 | View Code Duplication | if (!in_array($view_downloads->getVar('cid'), $categories)) { |
|
| 31 | redirect_header(XOOPS_URL, 2, _NOPERM); |
||
| 32 | exit(); |
||
| 33 | } |
||
| 34 | //redirection si pas de permission (t�l�charger) |
||
| 35 | if ($xoopsModuleConfig['permission_download'] == 2) { |
||
| 36 | $item = TDMDownloads_MygetItemIds('tdmdownloads_download_item', 'TDMDownloads'); |
||
| 37 | View Code Duplication | if (!in_array($view_downloads->getVar('lid'), $item)) { |
|
| 38 | redirect_header('singlefile.php?lid=' . $view_downloads->getVar('lid'), 2, _MD_TDMDOWNLOADS_SINGLEFILE_NOPERMDOWNLOAD); |
||
| 39 | exit(); |
||
| 40 | } |
||
| 41 | View Code Duplication | } else { |
|
| 42 | $categories = TDMDownloads_MygetItemIds('tdmdownloads_download', 'TDMDownloads'); |
||
| 43 | if (!in_array($view_downloads->getVar('cid'), $categories)) { |
||
| 44 | redirect_header('singlefile.php?lid=' . $view_downloads->getVar('lid'), 2, _MD_TDMDOWNLOADS_SINGLEFILE_NOPERMDOWNLOAD); |
||
| 45 | exit(); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | //check download limit option |
||
| 49 | if ($xoopsModuleConfig['downlimit'] == 1) { |
||
| 50 | $limitlid = $xoopsModuleConfig['limitlid']; |
||
| 51 | $limitglobal = $xoopsModuleConfig['limitglobal']; |
||
| 52 | $yesterday = strtotime(formatTimestamp(time()-86400)); |
||
| 53 | if ($limitlid > 0) { |
||
| 54 | $criteria = new CriteriaCompo(); |
||
| 55 | View Code Duplication | if ($xoopsUser) { |
|
| 56 | $criteria->add(new Criteria('downlimit_uid', $xoopsUser->getVar('uid') , '=')); |
||
| 57 | } else { |
||
| 58 | $criteria->add(new Criteria('downlimit_hostname', getenv("REMOTE_ADDR"), '=')); |
||
| 59 | } |
||
| 60 | $criteria->add(new Criteria('downlimit_lid', $lid , '=')); |
||
| 61 | $criteria->add(new Criteria('downlimit_date', $yesterday , '>')); |
||
| 62 | $numrows = $downloadslimit_Handler->getCount($criteria); |
||
| 63 | if ($numrows >= $limitlid) { |
||
| 64 | redirect_header('singlefile.php?lid=' . $view_downloads->getVar('lid'), 5, sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_LIMITLID, $numrows, $limitlid)); |
||
| 65 | exit(); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | if ($limitglobal > 0) { |
||
| 69 | $criteria = new CriteriaCompo(); |
||
| 70 | View Code Duplication | if ($xoopsUser) { |
|
| 71 | $criteria->add(new Criteria('downlimit_uid', $xoopsUser->getVar('uid') , '=')); |
||
| 72 | } else { |
||
| 73 | $criteria->add(new Criteria('downlimit_hostname', getenv("REMOTE_ADDR"), '=')); |
||
| 74 | } |
||
| 75 | $criteria->add(new Criteria('downlimit_date', $yesterday , '>')); |
||
| 76 | $numrows = $downloadslimit_Handler->getCount($criteria); |
||
| 77 | if ($numrows >= $limitglobal) { |
||
| 78 | redirect_header('singlefile.php?lid=' . $view_downloads->getVar('lid'), 5, sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_LIMITGLOBAL, $numrows, $limitglobal)); |
||
| 79 | exit(); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $obj =& $downloadslimit_Handler->create(); |
||
| 84 | $obj->setVar('downlimit_lid', $lid); |
||
| 85 | $obj->setVar('downlimit_uid', !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0); |
||
| 86 | $obj->setVar('downlimit_hostname', getenv("REMOTE_ADDR")); |
||
| 87 | $obj->setVar('downlimit_date', strtotime(formatTimestamp(time()))); |
||
| 88 | $downloadslimit_Handler->insert($obj) or $obj->getHtmlErrors(); |
||
|
0 ignored issues
–
show
|
|||
| 89 | // purge |
||
| 90 | $criteria = new CriteriaCompo(); |
||
| 91 | $criteria->add(new Criteria('downlimit_date', (time() - 172800) , '<')); |
||
| 92 | $numrows = $downloadslimit_Handler->getCount($criteria); |
||
| 93 | echo 'a d�truire: ' . $numrows . '<br/>'; |
||
| 94 | $downloadslimit_Handler->deleteAll($criteria); |
||
| 95 | } |
||
| 96 | |||
| 97 | @$xoopsLogger->activated = false; |
||
| 98 | error_reporting(0); |
||
| 99 | if ($xoopsModuleConfig['check_host']) { |
||
| 100 | $goodhost = 0; |
||
| 101 | $referer = parse_url(xoops_getenv('HTTP_REFERER')); |
||
| 102 | $referer_host = $referer['host']; |
||
| 103 | foreach ($xoopsModuleConfig['referers'] as $ref) { |
||
| 104 | if ( !empty($ref) && preg_match("/".$ref."/i", $referer_host) ) { |
||
| 105 | $goodhost = "1"; |
||
| 106 | break; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | if (!$goodhost) { |
||
| 110 | redirect_header(XOOPS_URL . "/modules/TDMDownloads/singlefile.php?cid=$cid&lid=$lid", 30, _MD_TDMDOWNLOADS_NOPERMISETOLINK); |
||
| 111 | exit(); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | // ajout +1 pour les hits |
||
| 116 | $sql = sprintf("UPDATE %s SET hits = hits+1 WHERE lid = %u AND status > 0", $xoopsDB->prefix("tdmdownloads_downloads"), $lid); |
||
| 117 | $xoopsDB->queryF($sql); |
||
| 118 | |||
| 119 | $url = $view_downloads->getVar('url', 'n'); |
||
| 120 | if (!preg_match("/^ed2k*:\/\//i", $url)) { |
||
| 121 | Header("Location: $url"); |
||
| 122 | } |
||
| 123 | echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=" . $url . "\"></meta></head><body></body></html>"; |
||
| 124 | exit(); |
||
| 125 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.