Completed
Push — master ( 960f7b...2a24eb )
by Andrew
02:26
created

code/SEO_Icons_SiteTree_DataExtension.php (5 issues)

Severity

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
/**
4
 * @todo Description
5
 *
6
 * @package silverstripe-seo
7
 * @subpackage icons
8
 * @author Andrew Gerber <[email protected]>
9
 * @version 1.0.0
10
 *
11
 */
12
class SEO_Icons_SiteTree_DataExtension extends DataExtension
13
{
14
15
16
    /* Overload Variable
17
    ------------------------------------------------------------------------------*/
18
19
    // none
20
21
22
    /* Overload Methods
23
    ------------------------------------------------------------------------------*/
24
25
    // CMS Fields
26
// 	public function updateCMSFields(FieldList $fields) {}
27
28
29
    /* Template Methods
30
    ------------------------------------------------------------------------------*/
31
32
    /**
33
     * Updates metadata with icons.
34
     *
35
     * @param SiteConfig $config
36
     * @param SiteTree $owner
37
     * @param $metadata
38
     *
39
     * @return void
40
     */
41
    public function updateMetadata(SiteConfig $config, SiteTree $owner, &$metadata)
42
    {
43
44
        //// HTML4 Favicon
45
46
        // @todo Perhaps create dynamic image, but just use favicon.ico for now
47
48
        //// Create Favicons
49
50
        $HTML5Favicon = $config->HTML5Favicon();
51
        $IOSPinicon = $config->IOSPinicon();
52
        $AndroidPinicon = $config->AndroidPinicon();
53
        $WindowsPinicon = $config->WindowsPinicon();
54
55
        //// iOS Pinicon
56
57
        if ($IOSPinicon->exists()) {
58
            $this->GenerateIOSPinicon($config, $owner, $metadata, $IOSPinicon);
59
        }
60
61
        //// HTML5 Favicon
62
63
        if ($HTML5Favicon->exists()) {
64
            $this->GenerateHTML5Favicon($owner, $metadata, $HTML5Favicon);
65
        }
66
67
        //// Android Pinicon Manifest
68
69
        if ($AndroidPinicon->exists()) {
70
            $this->GenerateAndroidPinicon($config, $owner, $metadata);
71
        }
72
73
        //// Windows Pinicon Manifest
74
75
        if ($WindowsPinicon->exists()) {
76
            $this->GenerateWindowsPinicon($config, $owner, $metadata, $WindowsPinicon);
77
        }
78
79
    }
80
81
    /**
82
     * Generates markup for the iOS pinicon
83
     *
84
     * @param SiteConfig $config
85
     * @param SiteTree $owner
86
     * @param string $metadata
87
     * @param Image $IOSPinicon
88
     *
89
     * @return void
90
     */
91
    protected function GenerateIOSPinicon(SiteConfig $config, SiteTree $owner, &$metadata, Image $IOSPinicon) {
92
93
        // header
94
        $metadata .= $this->owner->MarkupComment('iOS Pinned Icon');
95
96
        //// iOS Pinicon Title
97
        if ($config->fetchPiniconTitle()) {
98
            $metadata .= $owner->MarkupMeta('apple-mobile-web-app-title', $config->fetchPiniconTitle());
99
        }
100
101
        //// iOS Pinned Icon
102
103
        // For non-Retina (@1× display) iPhone, iPod Touch, and Android 2.1+ devices
104
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(57, 57)->getAbsoluteURL(), 'image/png'); // 57×57
105
106
        // @todo: What is this for ??
107
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(60, 60)->getAbsoluteURL(), 'image/png', '60x60');
108
109
        // For the iPad mini and the first- and second-generation iPad (@1× display) on iOS ≤ 6
110
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(72, 72)->getAbsoluteURL(), 'image/png', '72x72');
111
112
        // For the iPad mini and the first- and second-generation iPad (@1× display) on iOS ≥ 7
113
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(76, 76)->getAbsoluteURL(), 'image/png', '76x76');
114
115
        // For iPhone with @2× display running iOS ≤ 6
116
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(114, 114)->getAbsoluteURL(), 'image/png', '114x114');
117
118
        // For iPhone with @2× display running iOS ≥ 7
119
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(120, 120)->getAbsoluteURL(), 'image/png', '120x120');
120
121
        // For iPad with @2× display running iOS ≤ 6
122
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(144, 144)->getAbsoluteURL(), 'image/png', '144x144');
123
124
        // For iPad with @2× display running iOS ≥ 7
125
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(152, 152)->getAbsoluteURL(), 'image/png', '152x152');
126
127
        // For iPhone 6 Plus with @3× display
128
        $metadata .= $owner->MarkupLink('apple-touch-icon', $IOSPinicon->Pad(180, 180)->getAbsoluteURL(), 'image/png', '180x180');
129
130
    }
131
132
    /**
133
     * Generates markup for the HTML5 favicon
134
     *
135
     * @param SiteTree $owner
136
     * @param string $metadata
137
     * @param Image $HTML5Favicon
138
     *
139
     * @return void
140
     */
141
    protected function GenerateHTML5Favicon(SiteTree $owner, &$metadata, Image $HTML5Favicon) {
142
143
        // header
144
        $metadata .= $owner->MarkupComment('HTML5 Favicon');
145
146
//			// Android Chrome 32
147
        // @todo: Is the Android Chrome 32 196x196 px icon fully redundant ??
148
//			$metadata .= $owner->MarkupLink('icon', $HTML5Favicon->SetSize(196,196)->getAbsoluteURL(), 'image/png', '196x196');
149
150
        // Android Chrome 37+ / HTML5 spec
151
        $metadata .= $owner->MarkupLink('icon', $HTML5Favicon->SetSize(192, 192)->getAbsoluteURL(), 'image/png', '192x192');
0 ignored issues
show
Deprecated Code introduced by
The method Image::SetSize() has been deprecated with message: 4.0 Use Pad instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
152
153
        // Android Chrome 37+ / HTML5 spec
154
        $metadata .= $owner->MarkupLink('icon', $HTML5Favicon->SetSize(128, 128)->getAbsoluteURL(), 'image/png', '128x128');
0 ignored issues
show
Deprecated Code introduced by
The method Image::SetSize() has been deprecated with message: 4.0 Use Pad instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
155
156
        // For Google TV
157
        $metadata .= $owner->MarkupLink('icon', $HTML5Favicon->SetSize(96, 96)->getAbsoluteURL(), 'image/png', '96x96');
0 ignored issues
show
Deprecated Code introduced by
The method Image::SetSize() has been deprecated with message: 4.0 Use Pad instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
158
159
        // For Safari on Mac OS
160
        $metadata .= $owner->MarkupLink('icon', $HTML5Favicon->SetSize(32, 32)->getAbsoluteURL(), 'image/png', '32x32');
0 ignored issues
show
Deprecated Code introduced by
The method Image::SetSize() has been deprecated with message: 4.0 Use Pad instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
161
162
        // The classic favicon, displayed in the tabs
163
        $metadata .= $owner->MarkupLink('icon', $HTML5Favicon->SetSize(16, 16)->getAbsoluteURL(), 'image/png', '16x16');
0 ignored issues
show
Deprecated Code introduced by
The method Image::SetSize() has been deprecated with message: 4.0 Use Pad instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
164
165
    }
166
167
    /**
168
     * Generates markup for the Android pinicon
169
     *
170
     * @param SiteConfig $config
171
     * @param SiteTree $owner
172
     * @param $metadata
173
     *
174
     * @return void
175
     */
176
    protected function GenerateAndroidPinicon(SiteConfig $config, SiteTree $owner, &$metadata) {
177
178
        // header
179
        $metadata .= $owner->MarkupComment('Android Pinned Icon');
180
181
        //
182
        if ($config->fetchAndroidPiniconThemeColor()) {
183
            $metadata .= $owner->MarkupMeta('theme-color', $config->fetchAndroidPiniconThemeColor());
184
        }
185
186
        //
187
        $metadata .= $owner->MarkupLink('manifest', '/manifest.json');
188
189
    }
190
191
    /**
192
     * Generates markup for the Windows pinicon
193
     *
194
     * @param SiteConfig $config
195
     * @param SiteTree $owner
196
     * @param $metadata
197
     * @param Image $WindowsPinicon
198
     *
199
     * @return void
200
     */
201
    protected function GenerateWindowsPinicon(SiteConfig $config, SiteTree $owner, &$metadata, Image $WindowsPinicon) {
202
203
        // header
204
        $metadata .= $owner->MarkupComment('Windows Pinned Icon');
205
206
        // application name
207
        $appName = $config->fetchPiniconTitle();
208
        if (!$appName) {
209
            $appName = $config->Title;
210
        }
211
        $metadata .= $owner->MarkupMeta('application-name', $appName);
212
213
        // tile background color
214
        if ($config->fetchWindowsPiniconBackgroundColor()) {
215
            $metadata .= $owner->MarkupMeta('msapplication-TileColor', $config->fetchWindowsPiniconBackgroundColor());
216
        }
217
218
        // small tile
219
        $metadata .= $owner->MarkupMeta('msapplication-square70x70logo', $WindowsPinicon->Fill(70, 70)->getAbsoluteURL());
220
221
        // medium tile
222
        $metadata .= $owner->MarkupMeta('msapplication-square150x150logo', $WindowsPinicon->Fill(150, 150)->getAbsoluteURL());
223
224
        // @todo: Implement wide & tall tiles
225
226
        // wide tile
227
//			$metadata .= $owner->MarkupMeta('msapplication-square310x150logo', $WindowsPinicon->Fill(310,150)->getAbsoluteURL());
228
229
        // large tile
230
//			$metadata .= $owner->MarkupMeta('msapplication-square310x310logo', $WindowsPinicon->Fill(310,310)->getAbsoluteURL());
231
232
    }
233
234
}
235