Code Duplication    Length = 102-103 lines in 2 locations

modules/sitemaps/sitemap-stylist.php 2 locations

@@ 66-168 (lines=103) @@
63
	 *
64
	 * @return string The contents of the xsl file.
65
	 */
66
	public static function sitemap_xsl() {
67
		$title          = esc_html( ent2ncr( __( 'XML Sitemap', 'jetpack' ) ) );
68
		$header_url     = esc_html( ent2ncr( __( 'URL', 'jetpack' ) ) );
69
		$header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
70
71
		$description = self::sanitize_with_links(
72
			__(
73
				'This is an XML Sitemap generated by <a href="%1$s" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" target="_blank">Google</a> or <a href="%3$s" target="_blank">Bing</a>.',
74
				'jetpack'
75
			),
76
			array(
77
				1 => 'http://jetpack.com/',
78
				2 => 'https://www.google.com/',
79
				3 => 'https://www.bing.com/',
80
			)
81
		);
82
83
		$more_info = self::sanitize_with_links(
84
			__(
85
				'You can find more information on XML sitemaps at <a href="%1$s" target="_blank">sitemaps.org</a>',
86
				'jetpack'
87
			),
88
			array(
89
				1 => 'http://sitemaps.org',
90
			)
91
		);
92
93
		$generated_by = self::sanitize_with_links(
94
			__(
95
				'Generated by <a href="%s" target="_blank">Jetpack for WordPress</a>',
96
				'jetpack'
97
			),
98
			array(
99
				1 => 'https://jetpack.com',
100
			)
101
		);
102
103
		$css = self::sitemap_xsl_css();
104
105
		return <<<XSL
106
<?xml version='1.0' encoding='UTF-8'?>
107
<xsl:stylesheet version='2.0'
108
  xmlns:html='http://www.w3.org/TR/REC-html40'
109
  xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
110
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
111
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
112
<xsl:template match="/">
113
<html xmlns="http://www.w3.org/1999/xhtml">
114
<head>
115
  <title>$title</title>
116
  <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
117
  <style type='text/css'>
118
$css
119
  </style>
120
</head>
121
<body>
122
  <div id='description'>
123
    <h1>$title</h1>
124
    <p>$description</p>
125
    <p>$more_info</p>
126
  </div>
127
  <div id='content'>
128
    <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
129
    <table>
130
      <tr>
131
        <th>#</th>
132
        <th>$header_url</th>
133
        <th>$header_lastmod</th>
134
      </tr>
135
      <xsl:for-each select="sitemap:urlset/sitemap:url">
136
        <tr>
137
          <xsl:choose>
138
            <xsl:when test='position() mod 2 != 1'>
139
              <xsl:attribute name="class">odd</xsl:attribute>
140
            </xsl:when>
141
          </xsl:choose>
142
          <td>
143
            <xsl:value-of select = "position()" />
144
          </td>
145
          <td>
146
            <xsl:variable name='itemURL'>
147
              <xsl:value-of select='sitemap:loc'/>
148
            </xsl:variable>
149
            <a href='{\$itemURL}'>
150
              <xsl:value-of select='sitemap:loc'/>
151
            </a>
152
          </td>
153
          <td>
154
            <xsl:value-of select='sitemap:lastmod'/>
155
          </td>
156
        </tr>
157
      </xsl:for-each>
158
    </table>
159
  </div>
160
  <div id='footer'>
161
    <p>$generated_by</p>
162
  </div>
163
</body>
164
</html>
165
</xsl:template>
166
</xsl:stylesheet>\n
167
XSL;
168
	}
169
170
	/**
171
	 * Returns the xsl of a sitemap index xml file as a string.
@@ 178-279 (lines=102) @@
175
	 *
176
	 * @return string The contents of the xsl file.
177
	 */
178
	public static function sitemap_index_xsl() {
179
		$title          = esc_html( ent2ncr( __( 'XML Sitemap Index', 'jetpack' ) ) );
180
		$header_url     = esc_html( ent2ncr( __( 'Sitemap URL', 'jetpack' ) ) );
181
		$header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
182
183
		$description = self::sanitize_with_links(
184
			__(
185
				'This is an XML Sitemap Index generated by <a href="%1$s" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" target="_blank">Google</a> or <a href="%3$s" target="_blank">Bing</a>.',
186
				'jetpack'
187
			),
188
			array(
189
				1 => 'http://jetpack.com/',
190
				2 => 'https://www.google.com/',
191
				3 => 'https://www.bing.com/',
192
			)
193
		);
194
195
		$more_info = self::sanitize_with_links(
196
			__(
197
				'You can find more information on XML sitemaps at <a href="%1$s" target="_blank">sitemaps.org</a>',
198
				'jetpack'
199
			),
200
			array(
201
				1 => 'http://sitemaps.org',
202
			)
203
		);
204
205
		$generated_by = self::sanitize_with_links(
206
			__(
207
				'Generated by <a href="%s" target="_blank">Jetpack for WordPress</a>',
208
				'jetpack'
209
			),
210
			array(
211
				1 => 'https://jetpack.com',
212
			)
213
		);
214
215
		$css = self::sitemap_xsl_css();
216
217
		return <<<XSL
218
<?xml version='1.0' encoding='UTF-8'?>
219
<xsl:stylesheet version='2.0'
220
  xmlns:html='http://www.w3.org/TR/REC-html40'
221
  xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
222
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
223
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
224
<xsl:template match="/">
225
<html xmlns="http://www.w3.org/1999/xhtml">
226
<head>
227
  <title>$title</title>
228
  <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
229
  <style type='text/css'>
230
$css
231
  </style>
232
</head>
233
<body>
234
  <div id='description'>
235
    <h1>$title</h1>
236
    <p>$description</p>
237
    <p>$more_info</p>
238
  </div>
239
  <div id='content'>
240
    <table>
241
      <tr>
242
        <th>#</th>
243
        <th>$header_url</th>
244
        <th>$header_lastmod</th>
245
      </tr>
246
      <xsl:for-each select='sitemap:sitemapindex/sitemap:sitemap'>
247
        <tr>
248
          <xsl:choose>
249
            <xsl:when test='position() mod 2 != 1'>
250
              <xsl:attribute name="class">odd</xsl:attribute>
251
            </xsl:when>
252
          </xsl:choose>
253
          <td>
254
            <xsl:value-of select = "position()" />
255
          </td>
256
          <td>
257
            <xsl:variable name='itemURL'>
258
              <xsl:value-of select='sitemap:loc'/>
259
            </xsl:variable>
260
            <a href='{\$itemURL}'>
261
	            <xsl:value-of select='sitemap:loc'/>
262
  	        </a>
263
          </td>
264
          <td>
265
            <xsl:value-of select='sitemap:lastmod'/>
266
          </td>
267
        </tr>
268
      </xsl:for-each>
269
    </table>
270
  </div>
271
  <div id='footer'>
272
    <p>$generated_by</p>
273
  </div>
274
</body>
275
</html>
276
</xsl:template>
277
</xsl:stylesheet>\n
278
XSL;
279
	}
280
281
	/**
282
	 * Returns the xsl of an image sitemap xml file as a string.