Code Duplication    Length = 28-30 lines in 3 locations

class/Common/FilesManagement.php 1 location

@@ 262-290 (lines=29) @@
259
     *
260
     * @uses \Xmf\Module\Helper::getHelper()
261
     */
262
    public static function rcopy($src, $dest)
263
    {
264
        // Only continue if user is a 'global' Admin
265
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
266
            return false;
267
        }
268
269
        // If source is not a directory stop processing
270
        if (!is_dir($src)) {
271
            return false;
272
        }
273
274
        // If the destination directory does not exist and could not be created stop processing
275
        if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) {
276
            return false;
277
        }
278
279
        // Open the source directory to read in files
280
        $iterator = new \DirectoryIterator($src);
281
        foreach ($iterator as $fObj) {
282
            if ($fObj->isFile()) {
283
                copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
284
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
285
                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
286
            }
287
        }
288
289
        return true;
290
    }
291
}
292

class/utility.php 2 locations

@@ 185-214 (lines=30) @@
182
     *
183
     * @return bool true on success
184
     */
185
    public static function rmove($src, $dest)
186
    {
187
        // Only continue if user is a 'global' Admin
188
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
189
            return false;
190
        }
191
192
        // If source is not a directory stop processing
193
        if (!is_dir($src)) {
194
            return false;
195
        }
196
197
        // If the destination directory does not exist and could not be created stop processing
198
        if (!is_dir($dest) && !mkdir($dest, 0755)) {
199
            return false;
200
        }
201
202
        // Open the source directory to read in files
203
        $iterator = new \DirectoryIterator($src);
204
        foreach ($iterator as $fObj) {
205
            if ($fObj->isFile()) {
206
                rename($fObj->getPathname(), $dest . '/' . $fObj->getFilename());
207
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
208
                // Try recursively on directory
209
                static::rmove($fObj->getPathname(), $dest . '/' . $fObj->getFilename());
210
            }
211
        }
212
        $iterator = null;   // clear iterator Obj to close file/directory
213
        return rmdir($src); // remove the directory & return results
214
    }
215
216
    /**
217
     * Recursively copy directories and files from one directory to another
@@ 227-254 (lines=28) @@
224
     *
225
     * @see \XoopsModules\Xoopsfaq\Helper::getHelper()
226
     */
227
    public static function rcopy($src, $dest)
228
    {
229
        // Only continue if user is a 'global' Admin
230
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
231
            return false;
232
        }
233
234
        // If source is not a directory stop processing
235
        if (!is_dir($src)) {
236
            return false;
237
        }
238
239
        // If the destination directory does not exist and could not be created stop processing
240
        if (!is_dir($dest) && !mkdir($dest, 0755)) {
241
            return false;
242
        }
243
244
        // Open the source directory to read in files
245
        $iterator = new \DirectoryIterator($src);
246
        foreach ($iterator as $fObj) {
247
            if ($fObj->isFile()) {
248
                copy($fObj->getPathname(), $dest . '/' . $fObj->getFilename());
249
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
250
                static::rcopy($fObj->getPathname(), $dest . '/' . $fObj->getFilename());
251
            }
252
        }
253
        return true;
254
    }
255
256
    /**
257
     * Render the icon links