Completed
Push — master ( 76b4a1...141e43 )
by Michael
06:17 queued 02:44
created

include/functions.php (1 issue)

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
// $Id: include/functions.php,v 1.4 2006/01/01 C.Felix AKA the Cat
3
//  ------------------------------------------------------------------------ //
4
//             XF Guestbook                                                  //
5
// ------------------------------------------------------------------------- //
6
//  This program is free software; you can redistribute it and/or modify     //
7
//  it under the terms of the GNU General Public License as published by     //
8
//  the Free Software Foundation; either version 2 of the License, or        //
9
//  (at your option) any later version.                                      //
10
//                                                                           //
11
//  You may not change or alter any portion of this comment or credits       //
12
//  of supporting developers from this source code or any supporting         //
13
//  source code which is considered copyrighted (c) material of the          //
14
//  original comment or credit authors.                                      //
15
//                                                                           //
16
//  This program is distributed in the hope that it will be useful,          //
17
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
18
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
19
//  GNU General Public License for more details.                             //
20
//                                                                           //
21
//  You should have received a copy of the GNU General Public License        //
22
//  along with this program; if not, write to the Free Software              //
23
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
24
//  ------------------------------------------------------------------------ //
25
26
global $xoopsModule;
27
$cacheFolder = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
28
if (!is_dir($cacheFolder)) {
29
    mkdir($cacheFolder, 0777);
30
    file_put_contents($cacheFolder . '/index.html', '');
31
}
32
33
function xfgb_upload()
34
{
35
    global $xoopsModule, $xoopsModuleConfig, $preview_name, $msgstop;
36
    $created = time();
37
    $ext     = preg_replace("/^.+\.([^.]+)$/sU", "\\1", $_FILES['photo']['name']);
38
    include_once(XOOPS_ROOT_PATH . '/class/uploader.php');
39
    $field = $_POST['xoops_upload_file'][0];
40
    if (!empty($field) || $field !== '') {
41
        // Check if file uploaded
42
        if ($_FILES[$field]['tmp_name'] === '' || !is_readable($_FILES[$field]['tmp_name'])) {
43
            $msgstop .= sprintf(_MD_XFGB_FILEERROR, $xoopsModuleConfig['photo_maxsize']);
44
        } else {
45
            $photos_dir              = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname');
46
            $array_allowed_mimetypes = array('image/gif', 'image/pjpeg', 'image/jpeg', 'image/x-png');
47
            $uploader                =
48
                new XoopsMediaUploader($photos_dir, $array_allowed_mimetypes, $xoopsModuleConfig['photo_maxsize'], $xoopsModuleConfig['photo_maxwidth'], $xoopsModuleConfig['photo_maxheight']);
49
            if ($uploader->fetchMedia($field) && $uploader->upload()) {
50
                if (isset($preview_name)) {
51
                    @unlink("$photos_dir/" . $preview_name);
52
                }
53
                $tmp_name     = $uploader->getSavedFileName();
54
                $ext          = preg_replace("/^.+\.([^.]+)$/sU", "\\1", $tmp_name);
55
                $preview_name = 'tmp_' . $created . '.' . $ext;
56
                rename("$photos_dir/$tmp_name", "$photos_dir/$preview_name");
57
            } else {
58
                $msgstop .= $uploader->getErrors();
59
            }
60
        }
61
    }
62
}
63
64
/**
65
 * @param null $criteria
66
 * @param int  $limit
67
 * @param int  $start
68
 * @return array
69
 */
70 View Code Duplication
function xfgb_getCountry($criteria = null, $limit = 0, $start = 0)
71
{
72
    global $xoopsDB, $action;
73
    $ret = array();
74
    $sql = 'SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_country');
75
    if (isset($criteria) && $criteria !== '') {
76
        $sql .= ' WHERE ' . $criteria;
77
    }
78
    $sql .= ' ORDER BY country_code ASC';
79
    $result = $xoopsDB->query($sql, $limit, $start);
80
    while ($myrow = $xoopsDB->fetchArray($result)) {
81
        array_push($ret, $myrow);
82
    }
83
84
    return $ret;
85
}
86
87
/**
88
 * @param null $criteria
89
 * @param int  $limit
90
 * @param int  $start
91
 * @return array
92
 */
93
function xfgb_getAllCountry($criteria = null, $limit = 0, $start = 0)
94
{
95
    global $xoopsDB, $action, $xoopsModuleConfig;
96
    $ret = array();
97
    $sql = 'SELECT country_code, country_name FROM ' . $xoopsDB->prefix('xfguestbook_country');
98
    if (isset($criteria) && $criteria !== '') {
99
        $sql .= ' WHERE ' . $criteria;
100
    }
101
    $sql .= ' ORDER BY country_code ASC';
102
    $result = $xoopsDB->query($sql, $limit, $start);
103
    while ($myrow = $xoopsDB->fetchArray($result)) {
104
        //      $ret[$myrow['country_code']] = $myrow['country_name'];
105
        $ret[$xoopsModuleConfig['flagdir'] . '/' . $myrow['country_code']] = $myrow['country_name'];
106
    }
107
108
    return $ret;
109
}
110
111
/**
112
 * @param $user_id
113
 * @return bool
0 ignored issues
show
Should the return type not be false|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
114
 */
115
function xfgb_get_user_data($user_id)
116
{
117
    global $xoopsUser, $xoopsModuleConfig;
118
119
    if (!(int)$user_id) {
120
        return false;
121
    }
122
123
    $poster = new XoopsUser($user_id);
124
    if ($poster->isActive()) {
125
        $xoopsUser ? $a_poster['poster'] = "<a href='../../userinfo.php?uid=$user_id'>" . $poster->uname() . '</a>' : $a_poster['poster'] = $poster->uname();
126
        if ($xoopsModuleConfig['display_avatar']) {
127
            $rank = $poster->rank();
128
            $rank['title'] ? $a_poster['rank'] = $rank['title'] : $a_poster['rank'] = '';
129
            $rank['image'] ? $a_poster['rank_img'] = "<img src='" . XOOPS_URL . '/uploads/' . $rank['image'] . "' alt='' />" : $a_poster['rank_img'] = '';
130
            $poster->user_avatar() ? $a_poster['avatar'] = "<img src='" . XOOPS_URL . '/uploads/' . $poster->user_avatar() . "' alt='' />" : $a_poster['avatar'] = '';
131
        } else {
132
            $a_poster['rank']     = '';
133
            $a_poster['avatar']   = '';
134
            $a_poster['rank_img'] = '';
135
        }
136
137
        return $a_poster;
138
    } else {
139
        return false;
140
    }
141
}
142
143
// Effacement fichiers temporaires
144
/**
145
 * @param        $dir_path
146
 * @param string $prefix
147
 * @return int
148
 */
149
function xfgb_clear_tmp_files($dir_path, $prefix = 'tmp_')
150
{
151
    if (!($dir = @opendir($dir_path))) {
152
        return 0;
153
    }
154
    $ret        = 0;
155
    $prefix_len = strlen($prefix);
156
    while (($file = readdir($dir)) !== false) {
157
        if (strncmp($file, $prefix, $prefix_len) === 0) {
158
            if (@unlink("$dir_path/$file")) {
159
                $ret++;
160
            }
161
        }
162
    }
163
    closedir($dir);
164
165
    return $ret;
166
}
167
168
// IP bannies (modérés automatiquement)
169
/**
170
 * @param null $all
171
 * @return array
172
 */
173
function xfgb_get_badips($all = null)
174
{
175
    global $xoopsDB;
176
    $ret    = array();
177
    $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_badips');
178
    $result = $xoopsDB->query($sql);
179
    if ($all) {
180
        while ($myrow = $xoopsDB->fetchArray($result)) {
181
            array_push($ret, $myrow);
182
        }
183
    } else {
184
        while (list($ip_id, $ip_value) = $xoopsDB->fetchRow($result)) {
185
            $ret[] = $ip_value;
186
        }
187
    }
188
189
    return $ret;
190
}
191
192
/**
193
 * @param $email
194
 * @return bool
195
 */
196
function email_exist($email)
197
{
198
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
199
        return false;
200
    } elseif (!checkdnsrr(array_pop(explode('@', $email)), 'MX')) {
201
        return false;
202
    } else {
203
        return true;
204
    }
205
}
206