Issues (56)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/SmartChimpSignupPage.php (28 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
class SmartChimpSignupPage extends Page
4
{
5
    public static $icon = "smartchimp/images/treeicons/SmartChimpSignupPage";
6
7
    public static $db = array(
8
        //	@todo:	provide optional dropdown for entering username/password??
9
        'MCApiKey' => 'Varchar(50)',    //	api_key
10
        'MCListKey' => 'Varchar(50)',    //	list_unique_id
11
        'MCSuccessContent'    => 'HTMLText',
12
        "DoubleOptin" => "Boolean",
13
        "SendWelcomeMail" => "Boolean",
14
        "SendGoodbey" => "Boolean",
15
        "SendDeleteNotification" => "Boolean",
16
        "IsDefaultList" => "Boolean",
17
        "FirstFieldRequired" => "Boolean",
18
        "LastFieldRequired" => "Boolean"
19
    );
20
21
    public static $has_many = array(
22
        "SmartChimpNewsletters" => "SmartChimpNewsletter"
23
    );
24
25
    public static $defaults = array(
26
        "DoubleOptin" => 1,
27
        "SendWelcomeMail" => 0,
28
        "SendGoodbey" => 0,
29
        "IsDefaultList" => 1
30
    );
31
32
    public static $mc_api_version = '1.2.1';
33
34
    protected static $api = null;
35
36
    public function getAPI()
37
    {
38
        if ($this->MCApiKey && $this->MCListKey) {
39
            if (!(self::$api instanceof MCAPI)) {
40
                require_once(Director::baseFolder().'/smartchimp/thirdparty/mcapi/'.self::$mc_api_version.'/MCAPI.class.php');
41
                self::$api = new MCAPI("$this->MCApiKey");
42
            }
43
            return self::$api;
44
        }
45
    }
46
47
48
    public function getCMSFields()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
49
    {
50
        $fields = parent::getCMSFields();
51
52
        $fields->addFieldsToTab('Root.Content.SentNewsletters', array(
53
            new LiteralField('HowToRetrieve', '<p>To retrieve sent newsletters, simply save this page or <a href="'.$this->Link("update").'?flush=1">click here</a>.</p>'),
54
            $this->SmartChimpNewslettersTable()
55
        ));
56
        $fields->addFieldsToTab('Root.Content.MailChimpConfig', array(
57
            new CheckboxField('IsDefaultList', 'This is the default newsletter'),
0 ignored issues
show
'IsDefaultList' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'This is the default newsletter' is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
            new TextField('MCApiKey', _t('SmartChimp.MCAPIKEY', 'API Key')),
59
            new TextField('MCListKey', _t('SmartChimp.MCLISTKEY', 'Unique ID for List')),
60
            new HTMLEditorField('MCSuccessContent', _t('SmartChimp.MCSuccessContent', 'Signup Success Content'))
61
        ));
62
        $fields->addFieldsToTab('Root.Content.Subscribe', array(
63
            new CheckboxField('DoubleOptin', "Double Opt-In Process (send email to confirm registration)"),
0 ignored issues
show
'DoubleOptin' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'Double Opt-In Process (... confirm registration)' is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
            new CheckboxField('SendWelcomeMail', "Send Welcome Mail")
0 ignored issues
show
'SendWelcomeMail' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'Send Welcome Mail' is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
        ));
66
        $fields->addFieldsToTab('Root.Content.Unsubscribe', array(
67
            new CheckboxField('SendGoodbey', "Send Goodbey Email"),
0 ignored issues
show
'SendGoodbey' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'Send Goodbey Email' is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
            new CheckboxField('SendDeleteNotification', "Send notification of unsubscribe")
0 ignored issues
show
'SendDeleteNotification' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'Send notification of unsubscribe' is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
        ));
70
        $fields->addFieldsToTab("Root.Content.RequiredFields", array(
71
            new CheckboxField('FirstRequired', "First name is required"),
0 ignored issues
show
'FirstRequired' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'First name is required' is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
            new CheckboxField('LastRequired', "Last name is required")
0 ignored issues
show
'LastRequired' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'Last name is required' is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73
        ));
74
        $this->extend('updateSmartChimpCMSFields');
75
76
        return $fields;
77
    }
78
79
    public function SmartChimpNewslettersTable()
80
    {
81
        $table = new HasManyComplexTableField(
82
            $controller = $this,
83
            $name = "SmartChimpNewsletters",
84
            $sourceClass = "SmartChimpNewsletter",
85
            $fieldList = null,
86
            $detailFormFields = null,
87
            $sourceFilter = "ParentID = ".$this->ID
88
        );
89
        $table->setPageSize(100);
90
        $table->setPermissions(array('export', 'show', 'edit', 'delete'));
91
        return $table;
92
    }
93
94
    public function SmartChimpNewslettersShow()
95
    {
96
        return DataObject::get("SmartChimpNewsletter", "\"ParentID\" = ".$this->ID." AND \"Hide\" <> 1");
97
    }
98
99
    public function RetrieveCampaigns()
100
    {
101
        $dos = new DataObjectSet();
102
        SmartChimpNewsletter::clean_up_characters();
103
        $api = $this->getAPI();
104
        if ($api && $this->ID) {
105
            $campaignArray = $api->campaigns(array("list_id" => $this->MCListKey));
106
            if (is_array($campaignArray) && count($campaignArray)) {
107
                foreach ($campaignArray as $key => $campaign) {
108
                    if ($campaign["status"] == "sent") {
109
                        $obj = DataObject::get_one("SmartChimpNewsletter", "`ParentID` = ".$this->ID." AND `CampaignID` = '".$campaign["id"]."'");
110
                        if ($obj) {
111
                            //do nothing
112
                        } else {
113
                            $content =  $api->campaignContent($campaign["id"]);
114
                            if ($content) {
115
                                $obj = new SmartChimpNewsletter();
116
                                $obj->ParentID = $this->ID;
0 ignored issues
show
The property ParentID does not exist on object<SmartChimpNewsletter>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
117
                                $obj->Date = $campaign["send_time"];//
0 ignored issues
show
The property Date does not exist on object<SmartChimpNewsletter>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
118
                                $obj->Title = $campaign["title"];//
0 ignored issues
show
The property Title does not exist on object<SmartChimpNewsletter>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
119
                                $obj->Subject = $campaign["subject"];//
0 ignored issues
show
The property Subject does not exist on object<SmartChimpNewsletter>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
120
                                $obj->PermaLink = $campaign["archive_url"];//
0 ignored issues
show
The property PermaLink does not exist on object<SmartChimpNewsletter>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
121
                                $obj->CampaignID = $campaign["id"];//
0 ignored issues
show
The property CampaignID does not exist on object<SmartChimpNewsletter>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
122
                                $obj->WebID = $campaign["web_id"];//
0 ignored issues
show
The property WebID does not exist on object<SmartChimpNewsletter>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
123
                                $obj->Status = $campaign["status"];//should be sent!
0 ignored issues
show
The property Status does not exist on object<SmartChimpNewsletter>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
124
                                //$obj->TextContent = $content["text"] ;//html
125
                                //$obj->HTMLContent = $content["html"];//text
126
                            } else {
127
                                user_error(" could not retrieve content for newsletter with subject: ".$campaign["subject"]." AND ID".$campaign["id"], E_USER_NOTICE);
128
                            }
129
                            $obj->write();
130
                        }
131
                    }
132
                }
133
            }
134
        }
135
    }
136
137
138
    public function subscribe($email, $firstname, $lastname)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
139
    {
140
        $api = $this->getAPI();
141
        if ($api) {
142
            $mergeVars = array(
143
                'FNAME'    => $firstname,
144
                'LNAME'    => $lastname
145
            );
146
            //NOTE: update existing is set to false to not accidentally resubscribe someone.
147
            if (true === $api->listSubscribe($id = $this->MCListKey, $email, $mergeVars, $email_type='html', $this->DoubleOptin, $update_existing=false, $replace_interests=true, $this->SendWelcomeMail)) {
148
                return true;
149
            } else {
150
                return $api->errorMessage;
151
            }
152
        }
153
    }
154
155
    public function unsubscribe($email)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
156
    {
157
        $api = $this->getAPI();
158
        if ($api) {
159
            if (true === $api->listUnsubscribe($id = $this->MCListKey, $email, $delete_member=false, $this->SendGoodbey, $this->SendDeleteNotification)) {
160
                return true;
161
            } else {
162
                return $api->errorMessage;
163
            }
164
        }
165
    }
166
167
    public function onBeforeWrite()
168
    {
169
        parent::onBeforeWrite();
170
        if ($this->IsDefaultList && $this->ID) {
171
            $others = DataObject::get("SmartChimpSignupPage", "`SmartChimpSignupPage`.`ID` <> ".intval($this->ID)." AND `SmartChimpSignupPage`.`IsDefaultList` = 1");
172
            if ($others) {
173
                foreach ($others as $other) {
174
                    $other->IsDefaultList = 0;
175
                    $other->writeToStage('Stage');
176
                    $other->publish('Stage', 'Live');
177
                }
178
            }
179
        }
180
    }
181
182
    public function onAfterWrite()
183
    {
184
        parent::onAfterWrite();
185
        $this->RetrieveCampaigns();
186
    }
187
188
189
190
    public function requireDefaultRecords()
191
    {
192
        parent::requireDefaultRecords();
193
        $pages = DataObject::get("SmartChimpSignupPage");
194
        if ($pages) {
195
            if ($pages->count() == 1) {
196
                foreach ($pages as $page) {
197
                    if (!$page->IsDefaultList) {
198
                        $page->IsDefaultList = 1;
199
                        $page->writeToStage('Stage');
200
                        $page->publish('Stage', 'Live');
201
                        Database::alteration_message($page->ClassName.' created/updated: added IsDefaultList = true setting as there is only one SmartChimpSignupPage', 'edited');
202
                    }
203
                }
204
            }
205
        }
206
    }
207
}
208
209
210
class SmartChimpSignupPage_Controller extends Page_Controller
211
{
212
    public static $allowed_actions = array("Form", "update");
213
214
    public function init()
215
    {
216
        parent::init();
217
    }
218
219
220
    public function update()
221
    {
222
        $this->RetrieveCampaigns();
223
        return array();
224
    }
225
226
    public function Form()
227
    {
228
        if (Session::get('SmartChimp.SUCCESS')) {
229
            Session::clear('SmartChimp.SUCCESS');
230
            return false;
231
        }
232
        $requiredFields = new RequiredFields('email');
233
        if ($this->FirstFieldRequired) {
234
            $requiredFields->appendRequiredFields(array('fname'));
235
        }
236
        if ($this->LastFieldRequired) {
237
            $requiredFields->appendRequiredFields(array('lname'));
238
        }
239
        $form = new Form($this, 'Form',
240
            new FieldSet(
241
                new TextField('fname', 'First name'),
242
                new TextField('lname', 'Last name'),
243
                new TextField('email', 'Email address')
244
            ),
245
            new FieldSet(
246
                new FormAction('SignupAction', 'Sign up')
0 ignored issues
show
'SignupAction' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
247
            ),
248
            $requiredFields
249
        );
250
        $this->extend('updateSmartChimpForm', $form);
251
        return $form;
252
    }
253
254
    public function ShortForm()
255
    {
256
        if (Session::get('SmartChimp.SUCCESS')) {
257
            Session::clear('SmartChimp.SUCCESS');
258
            return false;
259
        }
260
        $form = new Form($this, 'Form',
261
            new FieldSet(
262
                new TextField('email', 'Email Address')
263
            ),
264
            new FieldSet(
265
                new FormAction('SignupAction', 'Sign up')
0 ignored issues
show
'SignupAction' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
266
            ),
267
            new RequiredFields('email')
268
        );
269
270
        $this->extend('updateSmartChimpForm', $form);
271
272
        return $form;
273
    }
274
275
    public function mcsuccess()
276
    {
277
        if (Session::get('SmartChimp.SUCCESS')) {
278
            $this->Content = $this->MCSuccessContent;
279
        }
280
        return array();
281
    }
282
283
    public function SignupAction($raw_data, $form)
284
    {
285
        $data = Convert::raw2sql($raw_data);
286
        $outcome = $this->subscribe($data['email'], $data['fname'],  $data['lname']);
287
        if (true === $outcome) {
288
            Session::set('SmartChimp.SUCCESS', true);
0 ignored issues
show
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
289
            return $this->mcsuccess();
290
        } else {
291
            $form->sessionMessage($outcome, 'warning');
292
            Director::redirectBack();
293
        }
294
    }
295
}
296