Issues (8)

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/SEO_Metadata_SiteConfig_DataExtension.php (2 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
 * Adds enhanced HTML SEO metadata.
4
 *
5
 * @package SEO
6
 * @subpackage Metadata
7
 * @author Andrew Gerber <[email protected]>
8
 * @version 1.0.0
9
 */
10
11
/**
12
 * Class SEO_Metadata_SiteConfig_DataExtension
13
 *
14
 * Adds additional statuses and defaults to control metadata output.
15
 */
16
class SEO_Metadata_SiteConfig_DataExtension extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
19
    /* Attributes
20
    ------------------------------------------------------------------------------*/
21
22
    //// statuses
23
24
    /**
25
     * Character set status.
26
     *
27
     * Boolean value governing whether the character set is output.
28
     *
29
     * @var bool $CharsetStatus
30
     */
31
    protected static $CharsetStatus = false;
32
33
    /**
34
     * `rel="canonical"` status.
35
     *
36
     * Boolean value governing whether canonical links are output.
37
     *
38
     * @var bool $CanonicalStatus
39
     */
40
    protected static $CanonicalStatus = false;
41
42
    /**
43
     * Title status.
44
     *
45
     * Boolean value governing whether the page title should be output.
46
     *
47
     * @var bool $TitleStatus
48
     */
49
    protected static $TitleStatus = false;
50
51
    /**
52
     * Extra metadata status.
53
     *
54
     * Boolean value governing whether additional (arbitrary) metadata can be added to pages.
55
     *
56
     * @var bool $ExtraMetaStatus
57
     */
58
    protected static $ExtraMetaStatus = false;
59
60
    //// defaults
61
62
    /**
63
     * Character set.
64
     *
65
     * The character set to be used. Should always be `UTF-8` except for fringe configurations.
66
     *
67
     * @var string
68
     */
69
    protected static $Charset = 'UTF-8';
70
71
    /**
72
     * Default title separator.
73
     *
74
     * The default title (primary) separator.
75
     *
76
     * @var string
77
     */
78
    protected static $TitleSeparatorDefault = '|';
79
80
    /**
81
     * Default tagline separator.
82
     *
83
     * The default tagline (secondary) separator.
84
     *
85
     * @var string
86
     */
87
    protected static $TaglineSeparatorDefault = '-';
88
89
    /**
90
     * Title ordering options.
91
     *
92
     * @var array
93
     */
94
    protected static $TitleOrderOptions = array(
95
        'first' => 'Page Title | Website Name - Tagline',
96
        'last' => 'Website Name - Tagline | Page Title'
97
    );
98
99
100
    /* Status Methods
101
    ------------------------------------------------------------------------------*/
102
103
    /**
104
     * Character set enabled.
105
     *
106
     * Gets whether the character set should be output.
107
     *
108
     * @return bool
109
     */
110
    public function CharsetEnabled()
111
    {
112
        return ($this->owner->config()->CharsetStatus === true) ? true : self::$CharsetStatus;
113
    }
114
115
    /**
116
     * Canonical links enabled.
117
     *
118
     * Gets whether the canonical link should be output.
119
     *
120
     * @return bool
121
     */
122
    public function CanonicalEnabled()
123
    {
124
        return ($this->owner->config()->CanonicalStatus === true) ? true : self::$CanonicalStatus;
125
    }
126
127
    /**
128
     * Title enabled.
129
     *
130
     * Gets whether the title should be output.
131
     *
132
     * @return bool
133
     */
134
    public function TitleEnabled()
135
    {
136
        return ($this->owner->config()->TitleStatus === true) ? true : self::$TitleStatus;
137
    }
138
139
    /**
140
     * Extra metadata enabled.
141
     *
142
     * Gets whether additional (arbitrary) metadata should be output.
143
     *
144
     * @return bool
145
     */
146
    public function ExtraMetaEnabled()
147
    {
148
        return ($this->owner->config()->ExtraMetaStatus === true) ? true : self::$ExtraMetaStatus;
149
    }
150
151
152
    /* Config Methods
153
    ------------------------------------------------------------------------------*/
154
155
    /**
156
     * Character set.
157
     *
158
     * Gets the character set from configuration, or uses the class-defined default.
159
     *
160
     * @return string
161
     */
162
    public function Charset()
163
    {
164
        return ($this->owner->config()->Charset) ? $this->owner->config()->Charset : self::$Charset;
165
    }
166
167
168
    /* Overload Model
169
    ------------------------------------------------------------------------------*/
170
171
    /**
172
     * Database fields.
173
     *
174
     * An associative array of database fields: `name` => `type`.
175
     *
176
     * @var array $db
177
     */
178
    private static $db = array(
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...
179
        'TitleOrder' => 'Enum(array("first", "last"), "first")',
180
        'Title' => 'Text', // redundant, but included for backwards-compatibility
181
        'TitleSeparator' => 'Varchar(1)',
182
        'Tagline' => 'Text', // redundant, but included for backwards-compatibility
183
        'TaglineSeparator' => 'Varchar(1)',
184
    );
185
186
187
    /* Overload Methods
188
    ------------------------------------------------------------------------------*/
189
190
    // @todo @inheritdoc ?? or does it happen automagically as promised?
191
    public function updateCMSFields(FieldList $fields)
192
    {
193
        // Tab Set
194
        $fields->addFieldToTab('Root', new TabSet('Metadata'), 'Access');
195
196
        // Title
197
        if ($this->TitleEnabled()) {
198
            $fields->addFieldsToTab('Root.Metadata.Title', $this->owner->getTitleFields());
199
        }
200
    }
201
202
203
    /* Custom Methods
204
    ------------------------------------------------------------------------------*/
205
206
    /**
207
     * Gets the title fields.
208
     *
209
     * This approach for getting fields for updateCMSFields is to be duplicated through all other modules to reduce complexity.
210
     *
211
     * @TODO i18n implementation
212
     *
213
     * @return array
214
     */
215
    public function getTitleFields() {
216
        return array(
217
            // Information
218
            LabelField::create('FaviconDescription', 'A title tag is the main text that describes an online document. Title elements have long been considered one of the most important on-page SEO elements (the most important being overall content), and appear in three key places: browsers, search engine results pages, and external websites.<br />@ <a href="https://moz.com/learn/seo/title-tag" target="_blank">Title Tag - Learn SEO - Mozilla</a>')
219
                ->addExtraClass('information'),
220
            // Title Order
221
            DropdownField::create('TitleOrder', 'Page Title Order', self::$TitleOrderOptions),
222
            // Title Separator
223
            TextField::create('TitleSeparator', 'Page Title Separator')
224
                ->setAttribute('placeholder', self::$TitleSeparatorDefault)
225
                ->setAttribute('size', 1)
226
                ->setMaxLength(1)
227
                ->setDescription('max 1 character'),
228
            // Title
229
            TextField::create('Title', 'Website Name'),
230
            // Tagline Separator
231
            TextField::create('TaglineSeparator', 'Tagline Separator')
232
                ->setAttribute('placeholder', self::$TaglineSeparatorDefault)
233
                ->setAttribute('size', 1)
234
                ->setMaxLength(1)
235
                ->setDescription('max 1 character'),
236
            // Tagline
237
            TextField::create('Tagline', 'Tagline')
238
                ->setDescription('optional')
239
        );
240
    }
241
242
243
    /* Custom Methods
244
    ------------------------------------------------------------------------------*/
245
246
    /**
247
     * Fetch title separator.
248
     *
249
     * Fetches the title (primary) separator, falls back to default.
250
     *
251
     * @return string
252
     */
253
    public function FetchTitleSeparator()
254
    {
255
        return ($this->owner->TitleSeparator) ? $this->owner->TitleSeparator : self::$TitleSeparatorDefault;
256
    }
257
258
    /**
259
     * Fetch tagline separator.
260
     *
261
     * Fetches the tagline (secondary) separator, falls back to default.
262
     *
263
     * @return string
264
     */
265
    public function FetchTaglineSeparator()
266
    {
267
        return ($this->owner->TaglineSeparator) ? $this->owner->TaglineSeparator : self::$TaglineSeparatorDefault;
268
    }
269
270
    /**
271
     * Generates HTML title based on configuration settings.
272
     *
273
     * @dev Override this function for any custom title functionality.
274
     *
275
     * @param string $pageTitle
276
     *
277
     * @return string
278
     */
279
    public function GenerateTitle($pageTitle = 'Title Error')
280
    {
281
        // if there is a site name
282
        if ($this->owner->Title) {
283
284
            // title parts, begin with name/title
285
            $titles = array($this->owner->Title);
286
287
            // tagline
288
            if ($this->owner->Tagline) {
289
                array_push($titles, $this->owner->FetchTaglineSeparator());
290
                array_push($titles, $this->owner->Tagline);
291
            }
292
293
            // page title
294
            if ($this->owner->TitleOrder == 'first') {
295
                // add to the beginning
296
                array_unshift($titles, $this->owner->FetchTitleSeparator());
297
                array_unshift($titles, $pageTitle);
298
            } else {
299
                // add to the end
300
                array_push($titles, $this->owner->FetchTitleSeparator());
301
                array_push($titles, $pageTitle);
302
            }
303
304
            // implode to create title
305
            $title = implode(' ', $titles);
306
307
            // removes whitespace before punctuation marks: `,.;:!?`
308
            // @todo isn't this a little bit random ?
309
            $title = preg_replace('/\s*[,.;:!?]/', '', $title);
310
311
            // return
312
            return $title;
313
314
        } else {
315
            // just return the page title if there is no site name
316
            return $pageTitle;
317
        }
318
    }
319
320
}
321