/htdocs/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/lib/shortcodes.php

https://github.com/Fishgate/privatecollectionswp · PHP · 141 lines · 91 code · 25 blank · 25 comment · 15 complexity · dc254c92d35983de3dc0b379506cc1de MD5 · raw file

  1. <?php
  2. /**
  3. * @author Alex Rabe, Vincent Prat
  4. *
  5. * @since 1.0.0
  6. * @description Use WordPress Shortcode API for more features
  7. * @Docs http://codex.wordpress.org/Shortcode_API
  8. * @todo This file should be merged into another file
  9. */
  10. class NextGEN_shortcodes {
  11. // register the new shortcodes
  12. function NextGEN_shortcodes() {
  13. // Long posts should require a higher limit, see http://core.trac.wordpress.org/ticket/8553
  14. $pcre_limit = 500000;
  15. if ((int)ini_get('pcre.backtrack_limit') < $pcre_limit) {
  16. @ini_set('pcre.backtrack_limit', $pcre_limit);
  17. }
  18. // convert the old shortcode
  19. add_filter('the_content', array(&$this, 'convert_shortcode'));
  20. // ngglegacy display types use globals. These globals need to be reset
  21. // at the start of every loop
  22. add_filter('loop_start', array(&$this, 'reset_globals'));
  23. }
  24. function reset_globals()
  25. {
  26. unset($GLOBALS['subalbum']);
  27. unset($GLOBALS['nggShowGallery']);
  28. }
  29. /**
  30. * NextGEN_shortcodes::convert_shortcode()
  31. * convert old shortcodes to the new WordPress core style
  32. * [gallery=1] ->> [nggallery id=1]
  33. *
  34. * @param string $content Content to search for shortcodes
  35. * @return string Content with new shortcodes.
  36. */
  37. function convert_shortcode($content) {
  38. $ngg_options = nggGallery::get_option('ngg_options');
  39. if ( stristr( $content, '[singlepic' )) {
  40. $search = "@\[singlepic=(\d+)(|,\d+|,)(|,\d+|,)(|,watermark|,web20|,)(|,right|,center|,left|,)\]@i";
  41. if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
  42. foreach ($matches as $match) {
  43. // remove the comma
  44. $match[2] = ltrim($match[2], ',');
  45. $match[3] = ltrim($match[3], ',');
  46. $match[4] = ltrim($match[4], ',');
  47. $match[5] = ltrim($match[5], ',');
  48. $replace = "[singlepic id=\"{$match[1]}\" w=\"{$match[2]}\" h=\"{$match[3]}\" mode=\"{$match[4]}\" float=\"{$match[5]}\" ]";
  49. $content = str_replace ($match[0], $replace, $content);
  50. }
  51. }
  52. }
  53. if ( stristr( $content, '[album' )) {
  54. $search = "@(?:<p>)*\s*\[album\s*=\s*(\w+|^\+)(|,extend|,compact)\]\s*(?:</p>)*@i";
  55. if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
  56. foreach ($matches as $match) {
  57. // remove the comma
  58. $match[2] = ltrim($match[2],',');
  59. $replace = "[album id=\"{$match[1]}\" template=\"{$match[2]}\"]";
  60. $content = str_replace ($match[0], $replace, $content);
  61. }
  62. }
  63. }
  64. if ( stristr( $content, '[gallery' )) {
  65. $search = "@(?:<p>)*\s*\[gallery\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
  66. if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
  67. foreach ($matches as $match) {
  68. $replace = "[nggallery id=\"{$match[1]}\"]";
  69. $content = str_replace ($match[0], $replace, $content);
  70. }
  71. }
  72. }
  73. if ( stristr( $content, '[imagebrowser' )) {
  74. $search = "@(?:<p>)*\s*\[imagebrowser\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
  75. if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
  76. foreach ($matches as $match) {
  77. $replace = "[imagebrowser id=\"{$match[1]}\"]";
  78. $content = str_replace ($match[0], $replace, $content);
  79. }
  80. }
  81. }
  82. if ( stristr( $content, '[slideshow' )) {
  83. $search = "@(?:<p>)*\s*\[slideshow\s*=\s*(\w+|^\+)(|,(\d+)|,)(|,(\d+))\]\s*(?:</p>)*@i";
  84. if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
  85. foreach ($matches as $match) {
  86. // remove the comma
  87. $match[3] = ltrim($match[3],',');
  88. $match[5] = ltrim($match[5],',');
  89. $replace = "[slideshow id=\"{$match[1]}\" w=\"{$match[3]}\" h=\"{$match[5]}\"]";
  90. $content = str_replace ($match[0], $replace, $content);
  91. }
  92. }
  93. }
  94. if ( stristr( $content, '[tags' )) {
  95. $search = "@(?:<p>)*\s*\[tags\s*=\s*(.*?)\s*\]\s*(?:</p>)*@i";
  96. if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
  97. foreach ($matches as $match) {
  98. $replace = "[nggtags gallery=\"{$match[1]}\"]";
  99. $content = str_replace ($match[0], $replace, $content);
  100. }
  101. }
  102. }
  103. if ( stristr( $content, '[albumtags' )) {
  104. $search = "@(?:<p>)*\s*\[albumtags\s*=\s*(.*?)\s*\]\s*(?:</p>)*@i";
  105. if (preg_match_all($search, $content, $matches, PREG_SET_ORDER)) {
  106. foreach ($matches as $match) {
  107. $replace = "[nggtags album=\"{$match[1]}\"]";
  108. $content = str_replace ($match[0], $replace, $content);
  109. }
  110. }
  111. }
  112. return $content;
  113. }
  114. }
  115. // let's use it
  116. $nggShortcodes = new NextGEN_Shortcodes;