暫無描述

sitemap-stylist.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. <?php
  2. /**
  3. * The XSL used to style sitemaps is essentially a bunch of
  4. * static strings. This class handles the construction of
  5. * those strings.
  6. *
  7. * @package automattic/jetpack
  8. * @since 4.8.0
  9. */
  10. /**
  11. * Builds the XSL files required by Jetpack_Sitemap_Manager.
  12. *
  13. * @since 4.8.0
  14. */
  15. class Jetpack_Sitemap_Stylist {
  16. /**
  17. * Convert named entities, strip all HTML except anchor tags,
  18. * and interpolate with vsprintf. This is a helper function
  19. * for all the internationalized UI strings in this class
  20. * which have to include URLs.
  21. *
  22. * Note that $url_array should be indexed by integers like so:
  23. *
  24. * array(
  25. * 1 => 'example.com',
  26. * 2 => 'example.org',
  27. * );
  28. *
  29. * Then '%1$s' in the format string will substitute 'example.com'
  30. * and '%2$s' will substitute 'example.org'.
  31. *
  32. * @access private
  33. * @since 4.8.0
  34. * @link https://php.net/manual/en/function.vsprintf.php Format string documentation.
  35. *
  36. * @param string $format A vsprintf-style format string to be sanitized.
  37. * @param array $url_array The string substitution array to be passed to vsprintf.
  38. *
  39. * @return string The sanitized string.
  40. */
  41. private static function sanitize_with_links( $format, $url_array ) {
  42. return vsprintf(
  43. wp_kses(
  44. ent2ncr( $format ),
  45. array(
  46. 'a' => array(
  47. 'href' => true,
  48. 'title' => true,
  49. ),
  50. )
  51. ),
  52. $url_array
  53. );
  54. }
  55. /**
  56. * Returns the xsl of a sitemap xml file as a string.
  57. *
  58. * @access public
  59. * @since 4.8.0
  60. *
  61. * @return string The contents of the xsl file.
  62. */
  63. public static function sitemap_xsl() {
  64. $title = esc_html( ent2ncr( __( 'XML Sitemap', 'jetpack' ) ) );
  65. $header_url = esc_html( ent2ncr( __( 'URL', 'jetpack' ) ) );
  66. $header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
  67. $description = self::sanitize_with_links(
  68. __(
  69. 'This is an XML Sitemap generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
  70. 'jetpack'
  71. ),
  72. array(
  73. 1 => 'https://jetpack.com/',
  74. 2 => 'https://www.google.com/',
  75. 3 => 'https://www.bing.com/',
  76. )
  77. );
  78. $more_info = self::sanitize_with_links(
  79. __(
  80. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  81. 'jetpack'
  82. ),
  83. array(
  84. 1 => 'https://sitemaps.org',
  85. )
  86. );
  87. $generated_by = self::sanitize_with_links(
  88. __(
  89. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  90. 'jetpack'
  91. ),
  92. array(
  93. 1 => 'https://jetpack.com',
  94. )
  95. );
  96. $css = self::sitemap_xsl_css();
  97. return <<<XSL
  98. <?xml version='1.0' encoding='UTF-8'?>
  99. <xsl:stylesheet version='2.0'
  100. xmlns:html='http://www.w3.org/TR/REC-html40'
  101. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  102. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  103. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  104. <xsl:template match="/">
  105. <html xmlns="http://www.w3.org/1999/xhtml">
  106. <head>
  107. <title>$title</title>
  108. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  109. <style type='text/css'>
  110. $css
  111. </style>
  112. </head>
  113. <body>
  114. <div id='description'>
  115. <h1>$title</h1>
  116. <p>$description</p>
  117. <p>$more_info</p>
  118. </div>
  119. <div id='content'>
  120. <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
  121. <table>
  122. <tr>
  123. <th>#</th>
  124. <th>$header_url</th>
  125. <th>$header_lastmod</th>
  126. </tr>
  127. <xsl:for-each select="sitemap:urlset/sitemap:url">
  128. <tr>
  129. <xsl:choose>
  130. <xsl:when test='position() mod 2 != 1'>
  131. <xsl:attribute name="class">odd</xsl:attribute>
  132. </xsl:when>
  133. </xsl:choose>
  134. <td>
  135. <xsl:value-of select = "position()" />
  136. </td>
  137. <td>
  138. <xsl:variable name='itemURL'>
  139. <xsl:value-of select='sitemap:loc'/>
  140. </xsl:variable>
  141. <a href='{\$itemURL}'>
  142. <xsl:value-of select='sitemap:loc'/>
  143. </a>
  144. </td>
  145. <td>
  146. <xsl:value-of select='sitemap:lastmod'/>
  147. </td>
  148. </tr>
  149. </xsl:for-each>
  150. </table>
  151. </div>
  152. <div id='footer'>
  153. <p>$generated_by</p>
  154. </div>
  155. </body>
  156. </html>
  157. </xsl:template>
  158. </xsl:stylesheet>\n
  159. XSL;
  160. }
  161. /**
  162. * Returns the xsl of a sitemap index xml file as a string.
  163. *
  164. * @access public
  165. * @since 4.8.0
  166. *
  167. * @return string The contents of the xsl file.
  168. */
  169. public static function sitemap_index_xsl() {
  170. $title = esc_html( ent2ncr( __( 'XML Sitemap Index', 'jetpack' ) ) );
  171. $header_url = esc_html( ent2ncr( __( 'Sitemap URL', 'jetpack' ) ) );
  172. $header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
  173. $description = self::sanitize_with_links(
  174. __(
  175. 'This is an XML Sitemap Index generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
  176. 'jetpack'
  177. ),
  178. array(
  179. 1 => 'https://jetpack.com/',
  180. 2 => 'https://www.google.com/',
  181. 3 => 'https://www.bing.com/',
  182. )
  183. );
  184. if ( current_user_can( 'manage_options' ) ) {
  185. $next = human_time_diff( wp_next_scheduled( 'jp_sitemap_cron_hook' ) );
  186. /* translators: %s is a human_time_diff until next sitemap generation. */
  187. $no_nodes_warning = sprintf( __( 'No sitemap found. The system will try to build it again in %s.', 'jetpack' ), $next );
  188. } else {
  189. $no_nodes_warning = '';
  190. }
  191. $more_info = self::sanitize_with_links(
  192. __(
  193. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  194. 'jetpack'
  195. ),
  196. array(
  197. 1 => 'https://sitemaps.org',
  198. )
  199. );
  200. $generated_by = self::sanitize_with_links(
  201. __(
  202. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  203. 'jetpack'
  204. ),
  205. array(
  206. 1 => 'https://jetpack.com',
  207. )
  208. );
  209. $css = self::sitemap_xsl_css();
  210. return <<<XSL
  211. <?xml version='1.0' encoding='UTF-8'?>
  212. <xsl:stylesheet version='2.0'
  213. xmlns:html='http://www.w3.org/TR/REC-html40'
  214. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  215. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  216. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  217. <xsl:template match="/">
  218. <html xmlns="http://www.w3.org/1999/xhtml">
  219. <head>
  220. <title>$title</title>
  221. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  222. <style type='text/css'>
  223. $css
  224. </style>
  225. </head>
  226. <body>
  227. <div id='description'>
  228. <h1>$title</h1>
  229. <xsl:choose>
  230. <xsl:when test='not(sitemap:sitemapindex/sitemap:sitemap)'>
  231. <p><strong>$no_nodes_warning</strong></p>
  232. </xsl:when>
  233. </xsl:choose>
  234. <p>$description</p>
  235. <p>$more_info</p>
  236. </div>
  237. <div id='content'>
  238. <table>
  239. <tr>
  240. <th>#</th>
  241. <th>$header_url</th>
  242. <th>$header_lastmod</th>
  243. </tr>
  244. <xsl:for-each select='sitemap:sitemapindex/sitemap:sitemap'>
  245. <tr>
  246. <xsl:choose>
  247. <xsl:when test='position() mod 2 != 1'>
  248. <xsl:attribute name="class">odd</xsl:attribute>
  249. </xsl:when>
  250. </xsl:choose>
  251. <td>
  252. <xsl:value-of select = "position()" />
  253. </td>
  254. <td>
  255. <xsl:variable name='itemURL'>
  256. <xsl:value-of select='sitemap:loc'/>
  257. </xsl:variable>
  258. <a href='{\$itemURL}'>
  259. <xsl:value-of select='sitemap:loc'/>
  260. </a>
  261. </td>
  262. <td>
  263. <xsl:value-of select='sitemap:lastmod'/>
  264. </td>
  265. </tr>
  266. </xsl:for-each>
  267. </table>
  268. </div>
  269. <div id='footer'>
  270. <p>$generated_by</p>
  271. </div>
  272. </body>
  273. </html>
  274. </xsl:template>
  275. </xsl:stylesheet>\n
  276. XSL;
  277. }
  278. /**
  279. * Returns the xsl of an image sitemap xml file as a string.
  280. *
  281. * @access public
  282. * @since 4.8.0
  283. *
  284. * @return string The contents of the xsl file.
  285. */
  286. public static function image_sitemap_xsl() {
  287. $title = esc_html( ent2ncr( __( 'XML Image Sitemap', 'jetpack' ) ) );
  288. $header_url = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
  289. $header_image_url = esc_html( ent2ncr( __( 'Image URL', 'jetpack' ) ) );
  290. $header_thumbnail = esc_html( ent2ncr( __( 'Thumbnail', 'jetpack' ) ) );
  291. $header_title = esc_html( ent2ncr( __( 'Title', 'jetpack' ) ) );
  292. $header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
  293. $header_caption = esc_html( ent2ncr( __( 'Caption', 'jetpack' ) ) );
  294. $description = self::sanitize_with_links(
  295. __(
  296. 'This is an XML Image Sitemap generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
  297. 'jetpack'
  298. ),
  299. array(
  300. 1 => 'https://jetpack.com/',
  301. 2 => 'https://www.google.com/',
  302. 3 => 'https://www.bing.com/',
  303. )
  304. );
  305. $more_info = self::sanitize_with_links(
  306. __(
  307. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  308. 'jetpack'
  309. ),
  310. array(
  311. 1 => 'https://sitemaps.org',
  312. )
  313. );
  314. $generated_by = self::sanitize_with_links(
  315. __(
  316. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  317. 'jetpack'
  318. ),
  319. array(
  320. 1 => 'https://jetpack.com',
  321. )
  322. );
  323. $css = self::sitemap_xsl_css();
  324. return <<<XSL
  325. <?xml version='1.0' encoding='UTF-8'?>
  326. <xsl:stylesheet version='2.0'
  327. xmlns:html='http://www.w3.org/TR/REC-html40'
  328. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  329. xmlns:image='http://www.google.com/schemas/sitemap-image/1.1'
  330. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  331. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  332. <xsl:template match="/">
  333. <html xmlns="http://www.w3.org/1999/xhtml">
  334. <head>
  335. <title>$title</title>
  336. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  337. <style type='text/css'>
  338. $css
  339. </style>
  340. </head>
  341. <body>
  342. <div id='description'>
  343. <h1>$title</h1>
  344. <p>$description</p>
  345. <p>$more_info</p>
  346. </div>
  347. <div id='content'>
  348. <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
  349. <table>
  350. <tr>
  351. <th>#</th>
  352. <th>$header_url</th>
  353. <th>$header_image_url</th>
  354. <th>$header_title</th>
  355. <th>$header_caption</th>
  356. <th>$header_lastmod</th>
  357. <th>$header_thumbnail</th>
  358. </tr>
  359. <xsl:for-each select="sitemap:urlset/sitemap:url">
  360. <tr>
  361. <xsl:choose>
  362. <xsl:when test='position() mod 2 != 1'>
  363. <xsl:attribute name="class">odd</xsl:attribute>
  364. </xsl:when>
  365. </xsl:choose>
  366. <td>
  367. <xsl:value-of select = "position()" />
  368. </td>
  369. <td>
  370. <xsl:variable name='pageURL'>
  371. <xsl:value-of select='sitemap:loc'/>
  372. </xsl:variable>
  373. <a href='{\$pageURL}'>
  374. <xsl:value-of select='sitemap:loc'/>
  375. </a>
  376. </td>
  377. <xsl:variable name='itemURL'>
  378. <xsl:value-of select='image:image/image:loc'/>
  379. </xsl:variable>
  380. <td>
  381. <a href='{\$itemURL}'>
  382. <xsl:value-of select='image:image/image:loc'/>
  383. </a>
  384. </td>
  385. <td>
  386. <xsl:value-of select='image:image/image:title'/>
  387. </td>
  388. <td>
  389. <xsl:value-of select='image:image/image:caption'/>
  390. </td>
  391. <td>
  392. <xsl:value-of select='sitemap:lastmod'/>
  393. </td>
  394. <td>
  395. <a href='{\$itemURL}'>
  396. <img class='thumbnail' src='{\$itemURL}'/>
  397. </a>
  398. </td>
  399. </tr>
  400. </xsl:for-each>
  401. </table>
  402. </div>
  403. <div id='footer'>
  404. <p>$generated_by</p>
  405. </div>
  406. </body>
  407. </html>
  408. </xsl:template>
  409. </xsl:stylesheet>\n
  410. XSL;
  411. }
  412. /**
  413. * Returns the xsl of a video sitemap xml file as a string.
  414. *
  415. * @access public
  416. * @since 4.8.0
  417. *
  418. * @return string The contents of the xsl file.
  419. */
  420. public static function video_sitemap_xsl() {
  421. $title = esc_html( ent2ncr( __( 'XML Video Sitemap', 'jetpack' ) ) );
  422. $header_url = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
  423. $header_image_url = esc_html( ent2ncr( __( 'Video URL', 'jetpack' ) ) );
  424. $header_thumbnail = esc_html( ent2ncr( __( 'Thumbnail', 'jetpack' ) ) );
  425. $header_title = esc_html( ent2ncr( __( 'Title', 'jetpack' ) ) );
  426. $header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
  427. $header_description = esc_html( ent2ncr( __( 'Description', 'jetpack' ) ) );
  428. $description = self::sanitize_with_links(
  429. __(
  430. 'This is an XML Video Sitemap generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
  431. 'jetpack'
  432. ),
  433. array(
  434. 1 => 'https://jetpack.com/',
  435. 2 => 'https://www.google.com/',
  436. 3 => 'https://www.bing.com/',
  437. )
  438. );
  439. $more_info = self::sanitize_with_links(
  440. __(
  441. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  442. 'jetpack'
  443. ),
  444. array(
  445. 1 => 'https://sitemaps.org',
  446. )
  447. );
  448. $generated_by = self::sanitize_with_links(
  449. __(
  450. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  451. 'jetpack'
  452. ),
  453. array(
  454. 1 => 'https://jetpack.com',
  455. )
  456. );
  457. $css = self::sitemap_xsl_css();
  458. return <<<XSL
  459. <?xml version='1.0' encoding='UTF-8'?>
  460. <xsl:stylesheet version='2.0'
  461. xmlns:html='http://www.w3.org/TR/REC-html40'
  462. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  463. xmlns:video='http://www.google.com/schemas/sitemap-video/1.1'
  464. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  465. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  466. <xsl:template match="/">
  467. <html xmlns="http://www.w3.org/1999/xhtml">
  468. <head>
  469. <title>$title</title>
  470. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  471. <style type='text/css'>
  472. $css
  473. </style>
  474. </head>
  475. <body>
  476. <div id='description'>
  477. <h1>$title</h1>
  478. <p>$description</p>
  479. <p>$more_info</p>
  480. </div>
  481. <div id='content'>
  482. <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
  483. <table>
  484. <tr>
  485. <th>#</th>
  486. <th>$header_url</th>
  487. <th>$header_image_url</th>
  488. <th>$header_title</th>
  489. <th>$header_description</th>
  490. <th>$header_lastmod</th>
  491. <th>$header_thumbnail</th>
  492. </tr>
  493. <xsl:for-each select="sitemap:urlset/sitemap:url">
  494. <tr>
  495. <xsl:choose>
  496. <xsl:when test='position() mod 2 != 1'>
  497. <xsl:attribute name="class">odd</xsl:attribute>
  498. </xsl:when>
  499. </xsl:choose>
  500. <td>
  501. <xsl:value-of select = "position()" />
  502. </td>
  503. <td>
  504. <xsl:variable name='pageURL'>
  505. <xsl:value-of select='sitemap:loc'/>
  506. </xsl:variable>
  507. <a href='{\$pageURL}'>
  508. <xsl:value-of select='sitemap:loc'/>
  509. </a>
  510. </td>
  511. <xsl:variable name='itemURL'>
  512. <xsl:value-of select='video:video/video:content_loc'/>
  513. </xsl:variable>
  514. <td>
  515. <a href='{\$itemURL}'>
  516. <xsl:value-of select='video:video/video:content_loc'/>
  517. </a>
  518. </td>
  519. <td>
  520. <xsl:value-of select='video:video/video:title'/>
  521. </td>
  522. <td>
  523. <xsl:value-of select='video:video/video:description' disable-output-escaping='yes'/>
  524. </td>
  525. <td>
  526. <xsl:value-of select='sitemap:lastmod'/>
  527. </td>
  528. <td>
  529. <xsl:variable name='thumbURL'>
  530. <xsl:value-of select='video:video/video:thumbnail_loc'/>
  531. </xsl:variable>
  532. <a href='{\$thumbURL}'>
  533. <img class='thumbnail' src='{\$thumbURL}'/>
  534. </a>
  535. </td>
  536. </tr>
  537. </xsl:for-each>
  538. </table>
  539. </div>
  540. <div id='footer'>
  541. <p>$generated_by</p>
  542. </div>
  543. </body>
  544. </html>
  545. </xsl:template>
  546. </xsl:stylesheet>\n
  547. XSL;
  548. }
  549. /**
  550. * Returns the xsl of a news sitemap xml file as a string.
  551. *
  552. * @access public
  553. * @since 4.8.0
  554. *
  555. * @return string The contents of the xsl file.
  556. */
  557. public static function news_sitemap_xsl() {
  558. $title = esc_html( ent2ncr( __( 'XML News Sitemap', 'jetpack' ) ) );
  559. $header_url = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
  560. $header_title = esc_html( ent2ncr( __( 'Title', 'jetpack' ) ) );
  561. $header_pubdate = esc_html( ent2ncr( __( 'Publication Date', 'jetpack' ) ) );
  562. $description = self::sanitize_with_links(
  563. __(
  564. 'This is an XML News Sitemap generated by <a href="%1$s" rel="noopener noreferrer" target="_blank">Jetpack</a>, meant to be consumed by search engines like <a href="%2$s" rel="noopener noreferrer" target="_blank">Google</a> or <a href="%3$s" rel="noopener noreferrer" target="_blank">Bing</a>.',
  565. 'jetpack'
  566. ),
  567. array(
  568. 1 => 'https://jetpack.com/',
  569. 2 => 'https://www.google.com/',
  570. 3 => 'https://www.bing.com/',
  571. )
  572. );
  573. $more_info = self::sanitize_with_links(
  574. __(
  575. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  576. 'jetpack'
  577. ),
  578. array(
  579. 1 => 'https://sitemaps.org',
  580. )
  581. );
  582. $generated_by = self::sanitize_with_links(
  583. __(
  584. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  585. 'jetpack'
  586. ),
  587. array(
  588. 1 => 'https://jetpack.com',
  589. )
  590. );
  591. $css = self::sitemap_xsl_css();
  592. return <<<XSL
  593. <?xml version='1.0' encoding='UTF-8'?>
  594. <xsl:stylesheet version='2.0'
  595. xmlns:html='http://www.w3.org/TR/REC-html40'
  596. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  597. xmlns:news='http://www.google.com/schemas/sitemap-news/0.9'
  598. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  599. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  600. <xsl:template match="/">
  601. <html xmlns="http://www.w3.org/1999/xhtml">
  602. <head>
  603. <title>$title</title>
  604. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  605. <style type='text/css'>
  606. $css
  607. </style>
  608. </head>
  609. <body>
  610. <div id='description'>
  611. <h1>$title</h1>
  612. <p>$description</p>
  613. <p>$more_info</p>
  614. </div>
  615. <div id='content'>
  616. <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
  617. <table>
  618. <tr>
  619. <th>#</th>
  620. <th>$header_url</th>
  621. <th>$header_title</th>
  622. <th>$header_pubdate</th>
  623. </tr>
  624. <xsl:for-each select="sitemap:urlset/sitemap:url">
  625. <tr>
  626. <xsl:choose>
  627. <xsl:when test='position() mod 2 != 1'>
  628. <xsl:attribute name="class">odd</xsl:attribute>
  629. </xsl:when>
  630. </xsl:choose>
  631. <td>
  632. <xsl:value-of select = "position()" />
  633. </td>
  634. <xsl:variable name='pageURL'>
  635. <xsl:value-of select='sitemap:loc'/>
  636. </xsl:variable>
  637. <td>
  638. <a href='{\$pageURL}'>
  639. <xsl:value-of select='sitemap:loc'/>
  640. </a>
  641. </td>
  642. <td>
  643. <a href='{\$pageURL}'>
  644. <xsl:value-of select='news:news/news:title'/>
  645. </a>
  646. </td>
  647. <td>
  648. <xsl:value-of select='news:news/news:publication_date'/>
  649. </td>
  650. </tr>
  651. </xsl:for-each>
  652. </table>
  653. </div>
  654. <div id='footer'>
  655. <p>$generated_by</p>
  656. </div>
  657. </body>
  658. </html>
  659. </xsl:template>
  660. </xsl:stylesheet>\n
  661. XSL;
  662. }
  663. /**
  664. * The CSS to be included in sitemap xsl stylesheets;
  665. * factored out for uniformity.
  666. *
  667. * @access public
  668. * @since 4.8.0
  669. *
  670. * @return string The CSS.
  671. */
  672. public static function sitemap_xsl_css() {
  673. return <<<CSS
  674. body {
  675. font: 14px 'Open Sans', Helvetica, Arial, sans-serif;
  676. margin: 0;
  677. }
  678. a {
  679. color: #3498db;
  680. text-decoration: none;
  681. }
  682. h1 {
  683. margin: 0;
  684. }
  685. #description {
  686. background-color: #81a844;
  687. color: #FFF;
  688. padding: 30px 30px 20px;
  689. }
  690. #description a {
  691. color: #fff;
  692. }
  693. #content {
  694. padding: 10px 30px 30px;
  695. background: #fff;
  696. }
  697. a:hover {
  698. border-bottom: 1px solid;
  699. }
  700. th, td {
  701. font-size: 12px;
  702. }
  703. th {
  704. text-align: left;
  705. border-bottom: 1px solid #ccc;
  706. }
  707. th, td {
  708. padding: 10px 15px;
  709. }
  710. .odd {
  711. background-color: #E7F1D4;
  712. }
  713. #footer {
  714. margin: 20px 30px;
  715. font-size: 12px;
  716. color: #999;
  717. }
  718. #footer a {
  719. color: inherit;
  720. }
  721. #description a, #footer a {
  722. border-bottom: 1px solid;
  723. }
  724. #description a:hover, #footer a:hover {
  725. border-bottom: none;
  726. }
  727. img {
  728. max-height: 100px;
  729. max-width: 100px;
  730. }
  731. CSS;
  732. }
  733. }