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

singlefile.php (3 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_singlefile.html';
20
include_once XOOPS_ROOT_PATH.'/header.php';
21
$xoTheme->addStylesheet( XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/css/styles.css', null );
22
23
$lid = TDMDownloads_CleanVars($_REQUEST, 'lid', 0, 'int');
24
25
//information du t�l�chargement
26
$view_downloads = $downloads_Handler->get($lid);
27
28
// redirection si le t�l�chargement n'existe pas ou n'est pas activ�
29 View Code Duplication
if (count($view_downloads) == 0 || $view_downloads->getVar('status') == 0) {
30
    redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT);
31
    exit();
32
}
33
34
// pour les permissions
35
$categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads');
36 View Code Duplication
if (!in_array($view_downloads->getVar('cid'), $categories)) {
37
    redirect_header(XOOPS_URL, 2, _NOPERM);
38
    exit();
39
}
40
41
//tableau des cat�gories
42
$criteria = new CriteriaCompo();
43
$criteria->setSort('cat_weight ASC, cat_title');
44
$criteria->setOrder('ASC');
45
$criteria->add(new Criteria('cat_cid', '(' . implode(',', $categories) . ')','IN'));
46
$downloadscat_arr = $downloadscat_Handler->getall($criteria);
47
$mytree = new XoopsObjectTree($downloadscat_arr, 'cat_cid', 'cat_pid');
48
49
//navigation
50
$navigation = TDMDownloads_PathTreeUrl($mytree, $view_downloads->getVar('cid'), $downloadscat_arr, 'cat_title', $prefix = ' <img src="images/deco/arrow.gif" alt="arrow" /> ', true, 'ASC', true);
51
$navigation = $navigation . ' <img src="images/deco/arrow.gif" alt="arrow" /> ' . $view_downloads->getVar('title');
52
$xoopsTpl->assign('navigation', $navigation);
53
54
// sortie des informations
55
//Utilisation d'une copie d'�cran avec la largeur selon les pr�f�rences
56 View Code Duplication
if ($xoopsModuleConfig['useshots'] == 1) {
57
    $xoopsTpl->assign('shotwidth', $xoopsModuleConfig['shotwidth']);
58
    $xoopsTpl->assign('show_screenshot', true);
59
    $xoopsTpl->assign('img_float' , $xoopsModuleConfig['img_float']);
60
}
61
62
if ($xoopsModuleConfig['download_float'] == 'ltr') {
63
     $xoopsTpl->assign('textfloat', 'floatleft');
64
     $xoopsTpl->assign('infofloat', 'floatright');
65
} else {
66
     $xoopsTpl->assign('textfloat', 'floatright');
67
     $xoopsTpl->assign('infofloat', 'floatleft');
68
}
69
70
// sortie des informations
71
if ($view_downloads->getVar('logourl') == 'blank.gif') {
72
    $logourl = '';
73
} else {
74
    $logourl = $view_downloads->getVar('logourl');
75
    $logourl = $uploadurl_shots . $logourl;
76
}
77
// D�fini si la personne est un admin
78 View Code Duplication
if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
79
    $adminlink = '<a href="' . XOOPS_URL . '/modules/TDMDownloads/admin/downloads.php?op=view_downloads&amp;downloads_lid=' . $_REQUEST['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>';
80
} else {
81
    $adminlink = '';
82
}
83
84
$description = $view_downloads->getVar('description');
85
$xoopsTpl->assign('description' , str_replace('[pagebreak]','',$description));
86
$xoopsTpl->assign('lid' , $lid);
87
$xoopsTpl->assign('cid' , $view_downloads->getVar('cid'));
88
$xoopsTpl->assign('logourl' , $logourl);
89
// pour les vignettes "new" et "mis � jour"
90
$new = TDMDownloads_Thumbnail($view_downloads->getVar('date'), $view_downloads->getVar('status'));
91
$pop = TDMDownloads_Popular($view_downloads->getVar('hits'));
92
$xoopsTpl->assign('title' , $view_downloads->getVar('title'));
93
$xoopsTpl->assign('new' , $new);
94
$xoopsTpl->assign('pop' , $pop);
95
$xoopsTpl->assign('adminlink' , $adminlink);
96
$xoopsTpl->assign('date' , formatTimestamp($view_downloads->getVar('date'),'s'));
97
$xoopsTpl->assign('author' , XoopsUser::getUnameFromId($view_downloads->getVar('submitter')));
98
$xoopsTpl->assign('hits', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_NBTELECH,$view_downloads->getVar('hits')));
99
$xoopsTpl->assign('rating', number_format($view_downloads->getVar('rating'),1));
100
$xoopsTpl->assign('votes', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_VOTES,$view_downloads->getVar('votes')));
101
$xoopsTpl->assign('nb_comments', sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_COMMENTS,$view_downloads->getVar('comments')));
102
$xoopsTpl->assign('show_bookmark' , $xoopsModuleConfig['show_bookmark']);
103
$xoopsTpl->assign('show_social' , $xoopsModuleConfig['show_social']);
104
105
//paypal
106
if ( $view_downloads->getVar('paypal') != '' && $xoopsModuleConfig['use_paypal'] == true) {
107
    $paypal = '<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
108
    <input type="hidden" name="cmd" value="_xclick">
109
    <input type="hidden" name="business" value="'.$view_downloads->getVar('paypal').'">
110
    <input type="hidden" name="item_name" value="' . sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_PAYPAL, $view_downloads->getVar('title')) . ' (' . XoopsUser::getUnameFromId(!empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0) . ')">
111
    <input type="hidden" name="currency_code" value="' . $xoopsModuleConfig['currency_paypal'] . '">
112
    <input type="image" src="' . $xoopsModuleConfig['image_paypal'] . '" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
113
    </form>';
114
} else {
115
    $paypal = false;
116
}
117
$xoopsTpl->assign('paypal', $paypal);
118
119
// pour les champs suppl�mentaires
120
$criteria = new CriteriaCompo();
121
$criteria->setSort('weight ASC, title');
122
$criteria->setOrder('ASC');
123
$criteria->add(new Criteria('status', 1));
124
$downloads_field = $downloadsfield_Handler->getall($criteria);
125
$nb_champ = count($downloads_field);
126
$champ_sup ='';
127
$champ_sup_vide = 0;
128
foreach (array_keys($downloads_field) as $i) {
129
    if ($downloads_field[$i]->getVar('status_def') == 1) {
130
        if ($downloads_field[$i]->getVar('fid') == 1) {
131
            //page d'accueil
132
            if ($view_downloads->getVar('homepage') != '') {
133
                $champ_sup = '&nbsp;' . _AM_TDMDOWNLOADS_FORMHOMEPAGE . ':&nbsp;<a href="' . $view_downloads->getVar('homepage') . '">' . _MD_TDMDOWNLOADS_SINGLEFILE_ICI . '</a>';
134
                $champ_sup_vide++;
135
            }
136
        }
137 View Code Duplication
        if ($downloads_field[$i]->getVar('fid') == 2) {
138
            //version
139
            if ($view_downloads->getVar('version') != '') {
140
                $champ_sup = '&nbsp;' . _AM_TDMDOWNLOADS_FORMVERSION . ':&nbsp;' . $view_downloads->getVar('version');
141
                $champ_sup_vide++;
142
            }
143
        }
144
        if ($downloads_field[$i]->getVar('fid') == 3) {
145
            //taille du fichier
146
            $size_value_arr = explode(' ', $view_downloads->getVar('size'));
147
            if ($size_value_arr[0] != '') {
148
                $champ_sup = '&nbsp;' . _AM_TDMDOWNLOADS_FORMSIZE . ':&nbsp;' . $view_downloads->getVar('size');
149
                $champ_sup_vide++;
150
            }
151
        }
152 View Code Duplication
        if ($downloads_field[$i]->getVar('fid') == 4) {
153
            //plateforme
154
            if ($view_downloads->getVar('platform') != '') {
155
                $champ_sup = '&nbsp;' . _AM_TDMDOWNLOADS_FORMPLATFORM . $view_downloads->getVar('platform');
156
                $champ_sup_vide++;
157
            }
158
        }
159
    } else {
160
        $view_data = $downloadsfielddata_Handler->get();
161
        $criteria = new CriteriaCompo();
162
        $criteria->add(new Criteria('lid', $_REQUEST['lid']));
163
        $criteria->add(new Criteria('fid', $downloads_field[$i]->getVar('fid')));
164
        $downloadsfielddata = $downloadsfielddata_Handler->getall($criteria);
165
        $contenu = '';
166
        foreach (array_keys($downloadsfielddata) as $j) {
167
            $contenu = $downloadsfielddata[$j]->getVar('data', 'n');
168
        }
169
        if ($contenu != '') {
170
            $champ_sup = '&nbsp;' . $downloads_field[$i]->getVar('title') . ':&nbsp;' . $contenu;
171
            $champ_sup_vide++;
172
        }
173
    }
174
    if ($champ_sup != '') {
175
        $xoopsTpl->append('champ_sup', array('image' => $uploadurl_field . $downloads_field[$i]->getVar('img'), 'data' => $champ_sup));
176
    }
177
    $champ_sup ='';
178
}
179
if ($nb_champ > 0 && $champ_sup_vide > 0) {
180
    $xoopsTpl->assign('sup_aff', true);
181
} else {
182
    $xoopsTpl->assign('sup_aff', false);
183
}
184
//permission
185
$xoopsTpl->assign('perm_vote', $perm_vote);
186
$xoopsTpl->assign('perm_modif', $perm_modif);
187
$categories = TDMDownloads_MygetItemIds('tdmdownloads_download', 'TDMDownloads');
188
$item = TDMDownloads_MygetItemIds('tdmdownloads_download_item', 'TDMDownloads');
189
if ($xoopsModuleConfig['permission_download'] == 1) {
190 View Code Duplication
    if (!in_array($view_downloads->getVar('cid'), $categories)) {
191
        $xoopsTpl->assign('perm_download', false);
192
    } else {
193
        $xoopsTpl->assign('perm_download', true);
194
    }
195 View Code Duplication
} else {
196
    if (!in_array($view_downloads->getVar('lid'), $item)) {
197
        $xoopsTpl->assign('perm_download', false);
198
    } else {
199
        $xoopsTpl->assign('perm_download', true);
200
    }
201
}
202
203
// pour utiliser tellafriend.
204
if (($xoopsModuleConfig['usetellafriend'] == 1) and (is_dir('../tellafriend'))) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning 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 have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces 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 with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
205
    $string = sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND,$xoopsConfig['sitename'].':  '.XOOPS_URL.'/modules/TDMDownloads/singlefile.php?lid=' . $_REQUEST['lid']);
206
    $subject = sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND,$xoopsConfig['sitename']);
207
    if( stristr( $subject , '%' ) ) $subject = rawurldecode( $subject ) ;
208
    if( stristr( $string , '%3F' ) ) $string = rawurldecode( $string ) ;
209
    if ( preg_match( '/('.preg_quote(XOOPS_URL,'/').'.*)$/i' , $string , $matches ) ) {
210
        $target_uri = str_replace( '&amp;' , '&' , $matches[1] ) ;
211
    } else {
212
        $target_uri = XOOPS_URL . $_SERVER['REQUEST_URI'] ;
213
    }
214
    $tellafriend_texte = '<a target="_top" href="' . XOOPS_URL . '/modules/tellafriend/index.php?target_uri=' . rawurlencode( $target_uri ) . '&amp;subject='.rawurlencode( $subject ) . '">' . _MD_TDMDOWNLOADS_SINGLEFILE_TELLAFRIEND . '</a>';
215
} else {
216
    $tellafriend_texte = '<a target="_top" href="mailto:?subject=' . rawurlencode(sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND,$xoopsConfig['sitename'])) . '&amp;body=' . rawurlencode(sprintf(_MD_TDMDOWNLOADS_SINGLEFILE_INTFILEFOUND,$xoopsConfig['sitename']).':  ' . XOOPS_URL.'/modules/TDMDownloads/singlefile.php?lid=' . $_REQUEST['lid']) . '">' . _MD_TDMDOWNLOADS_SINGLEFILE_TELLAFRIEND . '</a>';
217
}
218
$xoopsTpl->assign('tellafriend_texte', $tellafriend_texte);
219
220
// r�f�rencement
221
// tags
222
if (($xoopsModuleConfig['usetag'] == 1) and (is_dir('../tag'))) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning 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 have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces 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 with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
223
    require_once XOOPS_ROOT_PATH.'/modules/tag/include/tagbar.php';
224
    $xoopsTpl->assign('tags', true);
225
    $xoopsTpl->assign('tagbar', tagBar($_REQUEST['lid'], 0));
226
} else {
227
    $xoopsTpl->assign('tags', false);
228
}
229
230
// titre de la page
231
$pagetitle = $view_downloads->getVar('title') . ' - ';
232
$pagetitle .= TDMDownloads_PathTreeUrl($mytree, $view_downloads->getVar('cid'), $downloadscat_arr, 'cat_title', $prefix = ' - ', false, 'DESC', true);
233
$xoopsTpl->assign('xoops_pagetitle', $pagetitle);
234
//version for title
235
$xoopsTpl->assign('version', $view_downloads->getVar('version'));
236
//description
237 View Code Duplication
if (strpos($description,'[pagebreak]')==false) {
238
    $description_short = substr($description,0,400);
239
} else {
240
    $description_short = substr($description,0,strpos($description,'[pagebreak]'));
241
}
242
$xoTheme->addMeta( 'meta', 'description', strip_tags($description_short));
243
//keywords
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
244
/*$keywords = substr($keywords,0,-1);
245
$xoTheme->addMeta( 'meta', 'keywords', $keywords);*/
246
include XOOPS_ROOT_PATH.'/include/comment_view.php';
247
include XOOPS_ROOT_PATH.'/footer.php';
248