sitemap-stylist.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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 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 http://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 => 'http://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 => 'http://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 => 'http://jetpack.com/',
  180. 2 => 'https://www.google.com/',
  181. 3 => 'https://www.bing.com/',
  182. )
  183. );
  184. $more_info = self::sanitize_with_links(
  185. __(
  186. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  187. 'jetpack'
  188. ),
  189. array(
  190. 1 => 'http://sitemaps.org',
  191. )
  192. );
  193. $generated_by = self::sanitize_with_links(
  194. __(
  195. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  196. 'jetpack'
  197. ),
  198. array(
  199. 1 => 'https://jetpack.com',
  200. )
  201. );
  202. $css = self::sitemap_xsl_css();
  203. return <<<XSL
  204. <?xml version='1.0' encoding='UTF-8'?>
  205. <xsl:stylesheet version='2.0'
  206. xmlns:html='http://www.w3.org/TR/REC-html40'
  207. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  208. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  209. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  210. <xsl:template match="/">
  211. <html xmlns="http://www.w3.org/1999/xhtml">
  212. <head>
  213. <title>$title</title>
  214. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  215. <style type='text/css'>
  216. $css
  217. </style>
  218. </head>
  219. <body>
  220. <div id='description'>
  221. <h1>$title</h1>
  222. <p>$description</p>
  223. <p>$more_info</p>
  224. </div>
  225. <div id='content'>
  226. <table>
  227. <tr>
  228. <th>#</th>
  229. <th>$header_url</th>
  230. <th>$header_lastmod</th>
  231. </tr>
  232. <xsl:for-each select='sitemap:sitemapindex/sitemap:sitemap'>
  233. <tr>
  234. <xsl:choose>
  235. <xsl:when test='position() mod 2 != 1'>
  236. <xsl:attribute name="class">odd</xsl:attribute>
  237. </xsl:when>
  238. </xsl:choose>
  239. <td>
  240. <xsl:value-of select = "position()" />
  241. </td>
  242. <td>
  243. <xsl:variable name='itemURL'>
  244. <xsl:value-of select='sitemap:loc'/>
  245. </xsl:variable>
  246. <a href='{\$itemURL}'>
  247. <xsl:value-of select='sitemap:loc'/>
  248. </a>
  249. </td>
  250. <td>
  251. <xsl:value-of select='sitemap:lastmod'/>
  252. </td>
  253. </tr>
  254. </xsl:for-each>
  255. </table>
  256. </div>
  257. <div id='footer'>
  258. <p>$generated_by</p>
  259. </div>
  260. </body>
  261. </html>
  262. </xsl:template>
  263. </xsl:stylesheet>\n
  264. XSL;
  265. }
  266. /**
  267. * Returns the xsl of an image sitemap xml file as a string.
  268. *
  269. * @access public
  270. * @since 4.8.0
  271. *
  272. * @return string The contents of the xsl file.
  273. */
  274. public static function image_sitemap_xsl() {
  275. $title = esc_html( ent2ncr( __( 'XML Image Sitemap', 'jetpack' ) ) );
  276. $header_url = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
  277. $header_image_url = esc_html( ent2ncr( __( 'Image URL', 'jetpack' ) ) );
  278. $header_thumbnail = esc_html( ent2ncr( __( 'Thumbnail', 'jetpack' ) ) );
  279. $header_title = esc_html( ent2ncr( __( 'Title', 'jetpack' ) ) );
  280. $header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
  281. $header_caption = esc_html( ent2ncr( __( 'Caption', 'jetpack' ) ) );
  282. $description = self::sanitize_with_links(
  283. __(
  284. '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>.',
  285. 'jetpack'
  286. ),
  287. array(
  288. 1 => 'http://jetpack.com/',
  289. 2 => 'https://www.google.com/',
  290. 3 => 'https://www.bing.com/',
  291. )
  292. );
  293. $more_info = self::sanitize_with_links(
  294. __(
  295. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  296. 'jetpack'
  297. ),
  298. array(
  299. 1 => 'http://sitemaps.org',
  300. )
  301. );
  302. $generated_by = self::sanitize_with_links(
  303. __(
  304. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  305. 'jetpack'
  306. ),
  307. array(
  308. 1 => 'https://jetpack.com',
  309. )
  310. );
  311. $css = self::sitemap_xsl_css();
  312. return <<<XSL
  313. <?xml version='1.0' encoding='UTF-8'?>
  314. <xsl:stylesheet version='2.0'
  315. xmlns:html='http://www.w3.org/TR/REC-html40'
  316. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  317. xmlns:image='http://www.google.com/schemas/sitemap-image/1.1'
  318. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  319. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  320. <xsl:template match="/">
  321. <html xmlns="http://www.w3.org/1999/xhtml">
  322. <head>
  323. <title>$title</title>
  324. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  325. <style type='text/css'>
  326. $css
  327. </style>
  328. </head>
  329. <body>
  330. <div id='description'>
  331. <h1>$title</h1>
  332. <p>$description</p>
  333. <p>$more_info</p>
  334. </div>
  335. <div id='content'>
  336. <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
  337. <table>
  338. <tr>
  339. <th>#</th>
  340. <th>$header_url</th>
  341. <th>$header_image_url</th>
  342. <th>$header_title</th>
  343. <th>$header_caption</th>
  344. <th>$header_lastmod</th>
  345. <th>$header_thumbnail</th>
  346. </tr>
  347. <xsl:for-each select="sitemap:urlset/sitemap:url">
  348. <tr>
  349. <xsl:choose>
  350. <xsl:when test='position() mod 2 != 1'>
  351. <xsl:attribute name="class">odd</xsl:attribute>
  352. </xsl:when>
  353. </xsl:choose>
  354. <td>
  355. <xsl:value-of select = "position()" />
  356. </td>
  357. <td>
  358. <xsl:variable name='pageURL'>
  359. <xsl:value-of select='sitemap:loc'/>
  360. </xsl:variable>
  361. <a href='{\$pageURL}'>
  362. <xsl:value-of select='sitemap:loc'/>
  363. </a>
  364. </td>
  365. <xsl:variable name='itemURL'>
  366. <xsl:value-of select='image:image/image:loc'/>
  367. </xsl:variable>
  368. <td>
  369. <a href='{\$itemURL}'>
  370. <xsl:value-of select='image:image/image:loc'/>
  371. </a>
  372. </td>
  373. <td>
  374. <xsl:value-of select='image:image/image:title'/>
  375. </td>
  376. <td>
  377. <xsl:value-of select='image:image/image:caption'/>
  378. </td>
  379. <td>
  380. <xsl:value-of select='sitemap:lastmod'/>
  381. </td>
  382. <td>
  383. <a href='{\$itemURL}'>
  384. <img class='thumbnail' src='{\$itemURL}'/>
  385. </a>
  386. </td>
  387. </tr>
  388. </xsl:for-each>
  389. </table>
  390. </div>
  391. <div id='footer'>
  392. <p>$generated_by</p>
  393. </div>
  394. </body>
  395. </html>
  396. </xsl:template>
  397. </xsl:stylesheet>\n
  398. XSL;
  399. }
  400. /**
  401. * Returns the xsl of a video sitemap xml file as a string.
  402. *
  403. * @access public
  404. * @since 4.8.0
  405. *
  406. * @return string The contents of the xsl file.
  407. */
  408. public static function video_sitemap_xsl() {
  409. $title = esc_html( ent2ncr( __( 'XML Video Sitemap', 'jetpack' ) ) );
  410. $header_url = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
  411. $header_image_url = esc_html( ent2ncr( __( 'Video URL', 'jetpack' ) ) );
  412. $header_thumbnail = esc_html( ent2ncr( __( 'Thumbnail', 'jetpack' ) ) );
  413. $header_title = esc_html( ent2ncr( __( 'Title', 'jetpack' ) ) );
  414. $header_lastmod = esc_html( ent2ncr( __( 'Last Modified', 'jetpack' ) ) );
  415. $header_description = esc_html( ent2ncr( __( 'Description', 'jetpack' ) ) );
  416. $description = self::sanitize_with_links(
  417. __(
  418. '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>.',
  419. 'jetpack'
  420. ),
  421. array(
  422. 1 => 'http://jetpack.com/',
  423. 2 => 'https://www.google.com/',
  424. 3 => 'https://www.bing.com/',
  425. )
  426. );
  427. $more_info = self::sanitize_with_links(
  428. __(
  429. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  430. 'jetpack'
  431. ),
  432. array(
  433. 1 => 'http://sitemaps.org',
  434. )
  435. );
  436. $generated_by = self::sanitize_with_links(
  437. __(
  438. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  439. 'jetpack'
  440. ),
  441. array(
  442. 1 => 'https://jetpack.com',
  443. )
  444. );
  445. $css = self::sitemap_xsl_css();
  446. return <<<XSL
  447. <?xml version='1.0' encoding='UTF-8'?>
  448. <xsl:stylesheet version='2.0'
  449. xmlns:html='http://www.w3.org/TR/REC-html40'
  450. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  451. xmlns:video='http://www.google.com/schemas/sitemap-video/1.1'
  452. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  453. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  454. <xsl:template match="/">
  455. <html xmlns="http://www.w3.org/1999/xhtml">
  456. <head>
  457. <title>$title</title>
  458. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  459. <style type='text/css'>
  460. $css
  461. </style>
  462. </head>
  463. <body>
  464. <div id='description'>
  465. <h1>$title</h1>
  466. <p>$description</p>
  467. <p>$more_info</p>
  468. </div>
  469. <div id='content'>
  470. <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
  471. <table>
  472. <tr>
  473. <th>#</th>
  474. <th>$header_url</th>
  475. <th>$header_image_url</th>
  476. <th>$header_title</th>
  477. <th>$header_description</th>
  478. <th>$header_lastmod</th>
  479. <th>$header_thumbnail</th>
  480. </tr>
  481. <xsl:for-each select="sitemap:urlset/sitemap:url">
  482. <tr>
  483. <xsl:choose>
  484. <xsl:when test='position() mod 2 != 1'>
  485. <xsl:attribute name="class">odd</xsl:attribute>
  486. </xsl:when>
  487. </xsl:choose>
  488. <td>
  489. <xsl:value-of select = "position()" />
  490. </td>
  491. <td>
  492. <xsl:variable name='pageURL'>
  493. <xsl:value-of select='sitemap:loc'/>
  494. </xsl:variable>
  495. <a href='{\$pageURL}'>
  496. <xsl:value-of select='sitemap:loc'/>
  497. </a>
  498. </td>
  499. <xsl:variable name='itemURL'>
  500. <xsl:value-of select='video:video/video:content_loc'/>
  501. </xsl:variable>
  502. <td>
  503. <a href='{\$itemURL}'>
  504. <xsl:value-of select='video:video/video:content_loc'/>
  505. </a>
  506. </td>
  507. <td>
  508. <xsl:value-of select='video:video/video:title'/>
  509. </td>
  510. <td>
  511. <xsl:value-of select='video:video/video:description'/>
  512. </td>
  513. <td>
  514. <xsl:value-of select='sitemap:lastmod'/>
  515. </td>
  516. <td>
  517. <xsl:variable name='thumbURL'>
  518. <xsl:value-of select='video:video/video:thumbnail_loc'/>
  519. </xsl:variable>
  520. <a href='{\$thumbURL}'>
  521. <img class='thumbnail' src='{\$thumbURL}'/>
  522. </a>
  523. </td>
  524. </tr>
  525. </xsl:for-each>
  526. </table>
  527. </div>
  528. <div id='footer'>
  529. <p>$generated_by</p>
  530. </div>
  531. </body>
  532. </html>
  533. </xsl:template>
  534. </xsl:stylesheet>\n
  535. XSL;
  536. }
  537. /**
  538. * Returns the xsl of a news sitemap xml file as a string.
  539. *
  540. * @access public
  541. * @since 4.8.0
  542. *
  543. * @return string The contents of the xsl file.
  544. */
  545. public static function news_sitemap_xsl() {
  546. $title = esc_html( ent2ncr( __( 'XML News Sitemap', 'jetpack' ) ) );
  547. $header_url = esc_html( ent2ncr( __( 'Page URL', 'jetpack' ) ) );
  548. $header_title = esc_html( ent2ncr( __( 'Title', 'jetpack' ) ) );
  549. $header_pubdate = esc_html( ent2ncr( __( 'Publication Date', 'jetpack' ) ) );
  550. $description = self::sanitize_with_links(
  551. __(
  552. '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>.',
  553. 'jetpack'
  554. ),
  555. array(
  556. 1 => 'http://jetpack.com/',
  557. 2 => 'https://www.google.com/',
  558. 3 => 'https://www.bing.com/',
  559. )
  560. );
  561. $more_info = self::sanitize_with_links(
  562. __(
  563. 'You can find more information on XML sitemaps at <a href="%1$s" rel="noopener noreferrer" target="_blank">sitemaps.org</a>',
  564. 'jetpack'
  565. ),
  566. array(
  567. 1 => 'http://sitemaps.org',
  568. )
  569. );
  570. $generated_by = self::sanitize_with_links(
  571. __(
  572. 'Generated by <a href="%s" rel="noopener noreferrer" target="_blank">Jetpack for WordPress</a>',
  573. 'jetpack'
  574. ),
  575. array(
  576. 1 => 'https://jetpack.com',
  577. )
  578. );
  579. $css = self::sitemap_xsl_css();
  580. return <<<XSL
  581. <?xml version='1.0' encoding='UTF-8'?>
  582. <xsl:stylesheet version='2.0'
  583. xmlns:html='http://www.w3.org/TR/REC-html40'
  584. xmlns:sitemap='http://www.sitemaps.org/schemas/sitemap/0.9'
  585. xmlns:news='http://www.google.com/schemas/sitemap-news/0.9'
  586. xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  587. <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
  588. <xsl:template match="/">
  589. <html xmlns="http://www.w3.org/1999/xhtml">
  590. <head>
  591. <title>$title</title>
  592. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  593. <style type='text/css'>
  594. $css
  595. </style>
  596. </head>
  597. <body>
  598. <div id='description'>
  599. <h1>$title</h1>
  600. <p>$description</p>
  601. <p>$more_info</p>
  602. </div>
  603. <div id='content'>
  604. <!-- <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> -->
  605. <table>
  606. <tr>
  607. <th>#</th>
  608. <th>$header_url</th>
  609. <th>$header_title</th>
  610. <th>$header_pubdate</th>
  611. </tr>
  612. <xsl:for-each select="sitemap:urlset/sitemap:url">
  613. <tr>
  614. <xsl:choose>
  615. <xsl:when test='position() mod 2 != 1'>
  616. <xsl:attribute name="class">odd</xsl:attribute>
  617. </xsl:when>
  618. </xsl:choose>
  619. <td>
  620. <xsl:value-of select = "position()" />
  621. </td>
  622. <xsl:variable name='pageURL'>
  623. <xsl:value-of select='sitemap:loc'/>
  624. </xsl:variable>
  625. <td>
  626. <a href='{\$pageURL}'>
  627. <xsl:value-of select='sitemap:loc'/>
  628. </a>
  629. </td>
  630. <td>
  631. <a href='{\$pageURL}'>
  632. <xsl:value-of select='news:news/news:title'/>
  633. </a>
  634. </td>
  635. <td>
  636. <xsl:value-of select='news:news/news:publication_date'/>
  637. </td>
  638. </tr>
  639. </xsl:for-each>
  640. </table>
  641. </div>
  642. <div id='footer'>
  643. <p>$generated_by</p>
  644. </div>
  645. </body>
  646. </html>
  647. </xsl:template>
  648. </xsl:stylesheet>\n
  649. XSL;
  650. }
  651. /**
  652. * The CSS to be included in sitemap xsl stylesheets;
  653. * factored out for uniformity.
  654. *
  655. * @access public
  656. * @since 4.8.0
  657. *
  658. * @return string The CSS.
  659. */
  660. public static function sitemap_xsl_css() {
  661. return <<<CSS
  662. body {
  663. font: 14px 'Open Sans', Helvetica, Arial, sans-serif;
  664. margin: 0;
  665. }
  666. a {
  667. color: #3498db;
  668. text-decoration: none;
  669. }
  670. h1 {
  671. margin: 0;
  672. }
  673. #description {
  674. background-color: #81a844;
  675. color: #FFF;
  676. padding: 30px 30px 20px;
  677. }
  678. #description a {
  679. color: #fff;
  680. }
  681. #content {
  682. padding: 10px 30px 30px;
  683. background: #fff;
  684. }
  685. a:hover {
  686. border-bottom: 1px solid;
  687. }
  688. th, td {
  689. font-size: 12px;
  690. }
  691. th {
  692. text-align: left;
  693. border-bottom: 1px solid #ccc;
  694. }
  695. th, td {
  696. padding: 10px 15px;
  697. }
  698. .odd {
  699. background-color: #E7F1D4;
  700. }
  701. #footer {
  702. margin: 20px 30px;
  703. font-size: 12px;
  704. color: #999;
  705. }
  706. #footer a {
  707. color: inherit;
  708. }
  709. #description a, #footer a {
  710. border-bottom: 1px solid;
  711. }
  712. #description a:hover, #footer a:hover {
  713. border-bottom: none;
  714. }
  715. img.thumbnail {
  716. max-height: 100px;
  717. max-width: 100px;
  718. }
  719. CSS;
  720. }
  721. }