installscript.php ➔ xoops_module_install_xyp_base()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 2
nop 1
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
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 52 and the first side effect is on line 31.

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
/* Donations - Paypal financial management module for Xoops 2           */
4
/* Copyright (c) 2016 XOOPS Project                                     */
5
/* http://dev.xoops.org/modules/xfmod/project/?group_id=1060            */
6
/* 
7
/************************************************************************/
8
/*                                                                      */
9
/* Based on NukeTreasury for PHP-Nuke - by Dave Lawrence AKA Thrash     */
10
/* NukeTreasury - Financial management for PHP-Nuke                     */
11
/* Copyright (c) 2004 by Dave Lawrence AKA Thrash                       */
12
/*                       [email protected]                         */
13
/*                       [email protected]                          */
14
/*                                                                      */
15
/************************************************************************/
16
/*                                                                      */
17
/* This program is free software; you can redistribute it and/or modify */
18
/* it under the terms of the GNU General Public License as published by */
19
/* the Free Software Foundation; either version 2 of the License.       */
20
/*                                                                      */
21
/* This program is distributed in the hope that it will be useful, but  */
22
/* WITHOUT ANY WARRANTY; without even the implied warranty of           */
23
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU     */
24
/* General Public License for more details.                             */
25
/*                                                                      */
26
/* You should have received a copy of the GNU General Public License    */
27
/* along with this program; if not, write to the Free Software          */
28
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  */
29
/* USA                                                                  */
30
/************************************************************************/
31
include_once XOOPS_ROOT_PATH . '/include/cp_functions.php';
32
33
$moduleDirName = basename(dirname(__DIR__));
34
global $xoopsConfig, $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
35
36
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
37
38
echo "<hr>language: {$xoopsConfig['language']}<hr>";
39
40
$n = '_AD_DON_z_test';  if (defined($n)) {echo $n . " = " . constant($n)."<br>";} else {echo $n . " = ?<br>";}
41
$n = '_MD_DON_z_test';  if (defined($n)) {echo $n . " = " . constant($n)."<br>";} else {echo $n . " = ?<br>";}
42
$n = '_MI_DON_z_test';  if (defined($n)) {echo $n . " = " . constant($n)."<br>";} else {echo $n . " = ?<br>";}
43
$n = '_MB_DON_z_test';  if (defined($n)) {echo $n . " = " . constant($n)."<br>";} else {echo $n . " = ?<br>";}
44
*/
45
46
xoops_loadLanguage('main', $moduleDirName);
47
48
/**
49
 * @param XoopsObject|null $module
50
 * @return bool
51
 */
52
function xoops_module_install_xyp_base($module=null)
0 ignored issues
show
Unused Code introduced by
The parameter $module is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
{
54
    global $xoopsDB, $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
55
    $moduleDirName = basename(dirname(__DIR__));
56
57
    //----------------------------------------------------------------
58
    //patch JJD pour francisation ou autre langue
59
    //----------------------------------------------------------------
60
    update_lg();
61
    //----------------------------------------------------------------
62
63
    $sql1 = 'UPDATE ' . $xoopsDB->prefix('donations_config') . ' SET `value` = "' . XOOPS_URL . '/modules/' . $moduleDirName . '/success.php" WHERE `name` = "ty_url"';
64
    $sql2 = 'UPDATE ' . $xoopsDB->prefix('donations_config') . ' SET `value` = "' . XOOPS_URL . '/modules/' . $moduleDirName . '/cancel.php" WHERE `name` = "pp_cancel_url"';
65
66
    $retVal = false;
67
    if ($xoopsUser && $xoopsDB->query($sql1) && $xoopsDB->query($sql2)) {
68
            $retVal = true;
69
    }
70
71
    return $retVal;
72
}
73
74
/************************************************************************
75
 *
76
 ************************************************************************/
77
function update_lg()
78
{
79
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
80
81
    //    $moduleDirName = basename ( dirname( __DIR__ ) ) ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
82
83
    if (defined('_AD_DON_DONATIONS')) {
84
        $prefixV = '_AD_DON_V_';
85
        $prefixT = '_AD_DON_T_';
86
    } else {
87
        $prefixV = '_MI_DON_V_';
88
        $prefixT = '_MI_DON_T_';
89
    }
90
91
    $lstName = 'receiver_email_;paypal_url_array;use_goal_array;' . 'week_goal_1st;week_goal_2nd;week_goal_3rd;week_goal_4th;' . 'month_goal_Jan;month_goal_Feb;month_goal_Mar;month_goal_Apr;' . 'month_goal_May;month_goal_Jun;month_goal_Jul;' . 'month_goal_Aug;month_goal_Sep;month_goal_Oct;' . 'month_goal_Nov;month_goal_Dec;quarter_goal_1st;quarter_goal_2nd;' . 'quarter_goal_3rd;quarter_goal_4th;swing_day_;ty_url_;' . 'pp_itemname_;don_button_submit_;don_button_top_;pp_image_url_;' . 'pp_cancel_url_;pp_get_addr_;pp_curr_code_array;don_amount_1;' . 'don_amount_2;don_amount_3;don_amount_4;don_amount_5;' . 'don_amount_6;don_amount_7;don_amt_checked_;pp_item_num_;' . 'don_top_img_width_;don_top_img_height_;don_sub_img_width_;' . 'don_sub_img_height_;don_text_rawtext;don_name_prompt_;' . 'don_name_yes_;don_name_no_;don_forceadd_;ipn_dbg_lvl_;ipn_log_entries_;' . 'assign_group_;assign_rank_';
92
93
    $table = $xoopsDB->prefix('donations_config');
94
    $sql0  = "INSERT INTO `{$table}` (`name`, `subtype`, `value`, `text`) " . "VALUES ('%1\$s', '%2\$s', '%3\$s', '%4\$s')";
95
96
    $sql = "DELETE FROM {$table}";
97
    $xoopsDB->queryF($sql);
98
    //echo "{$sql}<br>";
99
    $t = explode(';', $lstName);
100
101
    for ($h = 0, $hMax = count($t); $h < $hMax; ++$h) {
102
        //echo "<hr>{$t[$h]}<br>";
103
        $tc = explode('_', $t[$h]);
104
        //echo "<hr>{$t[$h]}-".count($tc)."-".count($tn)."<br>";
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...
105
106
        //$tc = array_shift($tc);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
107
        $subType = $tc[count($tc) - 1];
108
109
        $cstV = $prefixV . $t[$h];
110
        $cstT = $prefixT . $t[$h];
111
112
        //$tc = array_shift($tc);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
113
        $tn   = array_pop($tc);
0 ignored issues
show
Unused Code introduced by
$tn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
114
        $tn   = $tc;
115
        $name = implode('_', $tn);
116
        //echo "{$t[$h]}-".count($tc)."-".count($tn)."-{$tc[0]}-{$tn[0]}-{$name}<br>";
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...
117
118
        $value = constant($cstV);
119
        $text  = constant($cstT);
120
        $text  = str_replace("'", "\'", $text);
121
        $text  = html_entity_decode($text);
122
        $text  = str_replace('<br>', "\r\n", $text);
123
        $text  = str_replace('<br />', "\r\n", $text);
124
125
        $sql = sprintf($sql0, $name, $subType, $value, $text);
126
        //        echo "{$sql}<br>";
127
        $xoopsDB->queryF($sql);
128
    }
129
}
130
131
eval('function xoops_module_install_' . $moduleDirName . '(&$module=NULL)
132
        {
133
        return xoops_module_install_xyp_base($module);
134
        }
135
    ');
136
137
/************************************************************************
138
 *
139
 * http://localhost/xoops2018a/modules/xdonations/include/installscript.php?op=update_lg
140
 * http://localhost/xoops2018a/modules/xdonations/include/installscript.php?op=update_lg
141
 * https://www.paypal.com/fr_FR/FR/i/btn/btn_donate_LG.gif
142
 ************************************************************************/
143
144
$op = isset($_GET['op']) ? $_GET['op'] : '';
145
146
switch ($op) {
147
    case 'update_lg':
148
        update_lg();
149
        break;
150
    default:
151
        break;
152
}
153