PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/products/photocrati_nextgen/modules/ngglegacy/lib/shortcodes.php

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