Issues (44)

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/model/ChimpifyCampaign.php (6 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
use \DrewM\MailChimp\MailChimp;
4
5
class ChimpifyCampaign extends DataObject
6
{
7
    private static $api_key;
0 ignored issues
show
The property $api_key is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
8
9
    private static $db = [
0 ignored issues
show
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
        'Title' => 'Varchar',
11
        'FromName' => 'Varchar',
12
        'ReplyTo' => 'Varchar',
13
        'TemplateID' => 'Int',
14
        'Intro' => 'Text',
15
        'ItemLimit' => 'Int',
16
    ];
17
18
    private static $many_many = [
0 ignored issues
show
The property $many_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'ContentSources' => 'Blog',
20
    ];
21
22
    private static $defaults = [
0 ignored issues
show
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
        'ItemLimit' => 3,
24
    ];
25
26
    private static $singular_name = 'MailChimp Campaign';
0 ignored issues
show
The property $singular_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
27
28
    private static $plural_name = 'MailChimp Campaigns';
0 ignored issues
show
The property $plural_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
29
30
    public function getCMSFields()
31
    {
32
        if (!$api_key = $this->config()->get('api_key')) {
33
            user_error(
34
                'Add a MailChimp API key to config (ChimpifyCampaign::api_key)',
35
                E_USER_ERROR
36
            );
37
        }
38
39
        $fields = parent::getCMSFields();
40
41
        $fields->removeByName('ItemLimit');
42
        $fields->removeByName('ContentSources');
43
44
        $mailChimp = new MailChimp($api_key);
45
46
        $fields->addFieldsToTab(
47
            'Root.Main',
48
            [
49
                TextField::create(
50
                    'Title',
51
                    _t('Chimpify.FieldLabelSubjectLine', 'Subject line')
52
                ),
53
                TextField::create(
54
                    'FromName',
55
                    _t('Chimpify.FieldLabelFromName', 'From name')
56
                ),
57
                EmailField::create(
58
                    'ReplyTo',
59
                    _t('Chimpify.FieldLabelReplyTo', 'Reply to email address')
60
                ),
61
                DropdownField::create(
62
                    'TemplateID',
63
                    _t('Chimpify.FieldLabelMailChimpTemplate', 'MailChimp template'),
64
                    $this->getMailChimpTemplates($mailChimp)->map('id', 'name'))
65
                    ->setEmptyString(
66
                        _t('Chimpify.FieldPlaceholderMailChimpTemplate', 'Select...')
67
                    ),
68
                TextareaField::create(
69
                    'Intro',
70
                    _t('Chimpify.FieldLabelIntro', 'Introduction'))
71
                    ->setDescription(_t(
72
                        'Chimpify.FieldDescriptionIntro',
73
                        'Dispayled above the list of Blog posts.'
74
                    )),
75
            ]
76
        );
77
78
        if ($this->ID) {
79
            $sourcesConfig = GridFieldConfig_RelationEditor::create();
80
            $sourcesConfig->removeComponentsByType('GridFieldEditButton');
81
            $sourcesConfig->removeComponentsByType('GridFieldAddNewButton');
82
83
            $fields->addFieldsToTab(
84
                'Root.Main',
85
                [
86
                    GridField::create(
87
                        'ContentSources',
88
                        _t('Chimpify.FieldLabelContentSources', 'Content sources'),
89
                        $this->ContentSources(),
90
                        $sourcesConfig
91
                    ),
92
                    NumericField::create(
93
                        'ItemLimit',
94
                        _t('Chimpify.FieldLabelItemLimit', 'Number of posts'))
95
                        ->setDescription(_t(
96
                            'Chimpify.FieldDescriptionItemLimit',
97
                            'The number of posts to display from each content source.'
98
                        )),
99
                ]
100
            );
101
        }
102
103
        $this->extend('updateCMSFields', $fields);
104
105
        return $fields;
106
    }
107
108
    public function getCMSActions()
109
    {
110
        $actions = parent::getCMSActions();
111
112
        $actions->push(
113
            FormAction::create(
114
                'doGenerateCampaign',
115
                _t('Chimpify.ButtonLabelGenerateCampaign', 'Create in MailChimp')
116
            )
117
        );
118
119
        $this->extend('updateCMSActions', $actions);
120
121
        return $actions;
122
    }
123
124
    public function getCMSValidator()
125
    {
126
        return new RequiredFields(
127
            'Title', 'FromName', 'ReplyTo', 'TemplateID', 'Intro', 'ItemLimit'
128
        );
129
    }
130
131
    /**
132
     * Fetches a list of email templates from MailChimp.
133
     *
134
     * @param MailChimp $mailChimp
135
     * @return ArrayList
136
     */
137 1
    public function getMailChimpTemplates($mailChimp)
138
    {
139 1
        $templates = ArrayList::create();
140 1
        $response = $mailChimp->get('templates');
141
142 1 View Code Duplication
        if (!$mailChimp->success()) {
143 1
            $message = $response && array_key_exists($response['errors'])
144 1
                ? $response['errors'][0]['message']
145 1
                : 'Error connecting to MailChimp API';
146
147 1
            user_error($message, E_USER_ERROR);
148
        }
149
150 1
        foreach ($response['templates'] as $template) {
151 1
            if ($template['type'] == 'user') {
152 1
                $templates->push(ArrayData::create($template));
153 1
            }
154 1
        }
155
156 1
        $this->extend('updateMailChimpTemplates', $templates);
157
158 1
        return $templates;
159
    }
160
161
    /**
162
     * Generates HTML from ContentSources.
163
     *
164
     * @return String
165
     */
166
    public function getCampaignContent()
167
    {
168
        return $this->renderWith('ChimpifyCampaignContent')->Value;
169
    }
170
}
171