Completed
Push — master ( 358680...e9acbc )
by Gino
04:15
created

functions.php ➔ TDMCreate_clearDir()   D

Complexity

Conditions 9
Paths 11

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 9
eloc 20
c 3
b 0
f 0
nc 11
nop 1
dl 0
loc 30
rs 4.909
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 32 and the first side effect is on line 23.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
/**
12
 * tdmcreate module.
13
 *
14
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
15
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
16
 *
17
 * @since           2.5.0
18
 *
19
 * @author          Txmod Xoops http://www.txmodxoops.org
20
 *
21
 * @version         $Id: functions.php 11084 2013-02-23 15:44:20Z timgno $
22
 */
23
defined('XOOPS_ROOT_PATH') or die('Restricted access');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or 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...
24
25
/**
26
 * Clear directory and its contents.
27
 *
28
 * @param string $folder The contents
29
 *
30
 * @return bool Returns true on success, false on failure
31
 */
32
function TDMCreate_clearDir($folder)
33
{
34
    $opening = @opendir($folder);
35
    if (!$opening) {
36
        return;
37
    }
38
    while ($file = readdir($opening)) {
39
        if ($file == '.' || $file == '..') {
40
            continue;
41
        }
42
        if (is_dir($folder.'/'.$file)) {
43
            $r = TDMCreate_clearDir($folder.'/'.$file);
44
            if (!$r) {
45
                return false;
46
            }
47
        } else {
48
            $r = @unlink($folder.'/'.$file);
49
            if (!$r) {
50
                return false;
51
            }
52
        }
53
    }
54
    closedir($opening);
55
    $r = @rmdir($folder);
56
    if (!$r) {
57
        return false;
58
    }
59
60
    return true;
61
}
62
63
/**
64
 * Copy a file, or a folder and its contents.
65
 *
66
 * @author      Aidan Lister <[email protected]>
67
 *
68
 * @version     1.0.0
69
 *
70
 * @param string $source The source
71
 * @param string $dest   The destination
72
 *
73
 * @return bool Returns true on success, false on failure
74
 */
75
function TDMCreate_copyr($source, $dest)
76
{
77
    // Simple copy for a file
78
    if (is_file($source)) {
79
        return copy($source, $dest);
80
    }
81
82
    // Make destination directory
83
    if (!is_dir($dest)) {
84
        mkdir($dest);
85
    }
86
87
    // Loop through the folder
88
    $dir = dir($source);
89
    while (false !== $entry = $dir->read()) {
90
        // Skip pointers
91
        if ($entry == '.' || $entry == '..') {
92
            continue;
93
        }
94
95
        // Deep copy directories
96
        if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) {
97
            TDMCreate_copyr("$source/$entry", "$dest/$entry");
98
        } else {
99
            copy("$source/$entry", "$dest/$entry");
100
        }
101
    }
102
103
    // Clean up
104
    $dir->close();
105
106
    return true;
107
}
108
// Pleace! don't remove
109
/**
110
 * @param $about
111
 * @return string
112
 */
113
function TDMCreate_MakeDonationForm($about)
114
{
115
    $donationform = array(0 => '<form name="donation" id="donation" action="http://www.txmodxoops.org/modules/xdonations/" method="post" onsubmit="return xoopsFormValidate_donation();">',
116
                                1 => '<table class="outer" cellspacing="1" width="100%"><tbody><tr><th colspan="2">'._AM_TDMCREATE_ABOUT_MAKE_DONATION.'</th></tr><tr align="left" valign="top"><td class="head"><div class="xoops-form-element-caption-required"><span class="caption-text">Donation Amount</span><span class="caption-marker">*</span></div></td><td class="even"><select size="1" name="item[A][amount]" id="item[A][amount]" title="Donation Amount"><option value="5">5.00 EUR</option><option value="10">10.00 EUR</option><option value="20">20.00 EUR</option><option value="40">40.00 EUR</option><option value="60">60.00 EUR</option><option value="80">80.00 EUR</option><option value="90">90.00 EUR</option><option value="100">100.00 EUR</option><option value="200">200.00 EUR</option></select></td></tr><tr align="left" valign="top"><td class="head"></td><td class="even"><input class="formButton" name="submit" id="submit" value="'._SUBMIT.'" title="'._SUBMIT.'" type="submit"></td></tr></tbody></table>',
117
                                2 => '<input name="op" id="op" value="createinvoice" type="hidden"><input name="plugin" id="plugin" value="donations" type="hidden"><input name="donation" id="donation" value="1" type="hidden"><input name="drawfor" id="drawfor" value="Chronolabs Co-Operative" type="hidden"><input name="drawto" id="drawto" value="%s" type="hidden"><input name="drawto_email" id="drawto_email" value="%s" type="hidden"><input name="key" id="key" value="%s" type="hidden"><input name="currency" id="currency" value="EUR" type="hidden"><input name="weight_unit" id="weight_unit" value="kgs" type="hidden"><input name="item[A][cat]" id="item[A][cat]" value="XDN%s" type="hidden"><input name="item[A][name]" id="item[A][name]" value="Donation for %s" type="hidden"><input name="item[A][quantity]" id="item[A][quantity]" value="1" type="hidden"><input name="item[A][shipping]" id="item[A][shipping]" value="0" type="hidden"><input name="item[A][handling]" id="item[A][handling]" value="0" type="hidden"><input name="item[A][weight]" id="item[A][weight]" value="0" type="hidden"><input name="item[A][tax]" id="item[A][tax]" value="0" type="hidden"><input name="return" id="return" value="http://www.txmodxoops.org/modules/xdonations/success.php" type="hidden"><input name="cancel" id="cancel" value="http://www.txmodxoops.org/modules/xdonations/success.php" type="hidden"></form>', 'D' => '',
118
                                3 => '',
119
                                4 => '<!-- Start Form Validation JavaScript //-->
120
<script type="text/javascript">
121
<!--//
122
function xoopsFormValidate_donation() { var myform = window.document.donation; 
123
var hasSelected = false; var selectBox = myform.item[A][amount];for (i = 0; i < selectBox.options.length; i++ ) { if (selectBox.options[i].selected == true && selectBox.options[i].value != \'\') { hasSelected = true; break; } }if (!hasSelected) { window.alert("Please enter Donation Amount"); selectBox.focus(); return false; }return true;
124
}
125
//--></script>
126
<!-- End Form Validation JavaScript //-->', );
127
    $paypalform = array(0 => '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">',
128
                                1 => '<input name="cmd" value="_s-xclick" type="hidden">',
129
                                2 => '<input name="hosted_button_id" value="%s" type="hidden">',
130
                                3 => '<img alt="" src="https://www.paypal.com/fr_FR/i/scr/pixel.gif" height="1" border="0" width="1">',
131
                                4 => '<input src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!" border="0" type="image">',
132
                                5 => '</form>', );
133
    for ($key = 0;$key <= 4;++$key) {
134
        switch ($key) {
135
            case 2:
136
                $donationform[$key] = sprintf($donationform[$key], $GLOBALS['xoopsConfig']['sitename'].' - '.(strlen($GLOBALS['xoopsUser']->getVar('name')) > 0 ? $GLOBALS['xoopsUser']->getVar('name').' ['.$GLOBALS['xoopsUser']->getVar('uname').']' : $GLOBALS['xoopsUser']->getVar('uname')), $GLOBALS['xoopsUser']->getVar('email'), XOOPS_LICENSE_KEY, strtoupper($GLOBALS['xoopsModule']->getVar('dirname')),  strtoupper($GLOBALS['xoopsModule']->getVar('dirname')).' '.$GLOBALS['xoopsModule']->getVar('name'));
137
                break;
138
        }
139
    }
140
    $aboutRes = '';
141
    $istart = strpos($about, $paypalform[0], 1);
142
    $iend = strpos($about, $paypalform[5], $istart + 1) + strlen($paypalform[5]) - 1;
143
    $aboutRes .= substr($about, 0, $istart - 1);
144
    $aboutRes .= implode("\n", $donationform);
145
    $aboutRes .= substr($about, $iend + 1, strlen($about) - $iend - 1);
146
147
    return $aboutRes;
148
}
149
150
//
151
/**
152
 * @param $str
153
 * @return string
154
 */
155
function UcFirstAndToLower($str)
156
{
157
    return ucfirst(strtolower(trim($str)));
158
}
159