PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/components/com_easyblog/helpers/audio.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 150 lines | 114 code | 20 blank | 16 comment | 4 complexity | 791fd8f96818faa5502340d5c352c5da MD5 | raw file
  1. <?php
  2. /**
  3. * @package EasyBlog
  4. * @copyright Copyright (C) 2010 Stack Ideas Private Limited. All rights reserved.
  5. * @license GNU/GPL, see LICENSE.php
  6. *
  7. * EasyBlog is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. defined('_JEXEC') or die('Restricted access');
  14. require_once( EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'json.php' );
  15. class EasyBlogAudioHelper
  16. {
  17. public function strip( $content )
  18. {
  19. // In case Joomla tries to entity the contents, we need to replace accordingly.
  20. $content = str_ireplace( '&quot;' , '"' , $content );
  21. $pattern = array('/\[embed=audio\](.*)\[\/embed\]/i');
  22. $replace = array('');
  23. return preg_replace( $pattern , $replace , $content );
  24. }
  25. public function getHTMLArray( $content )
  26. {
  27. $pattern = '/\[embed=audio\](.*)\[\/embed\]/i';
  28. $result = array();
  29. preg_match_all( $pattern , $content , $matches , PREG_SET_ORDER );
  30. if( !empty( $matches ) )
  31. {
  32. $cfg = EasyBlogHelper::getConfig();
  33. $json = new Services_JSON();
  34. foreach( $matches as $match )
  35. {
  36. // The full text of the matched content.
  37. $text = $match[ 0 ];
  38. // The json string
  39. $jsonString = $match[ 1 ];
  40. $obj = $json->decode( $jsonString );
  41. // If there's nothing, let's just remove the tag.
  42. if( !$obj )
  43. {
  44. continue;
  45. }
  46. $file = $obj->file;
  47. $autoplay = ( isset( $obj->autostart ) ) ? $obj->autostart : '0';
  48. $place = $obj->place;
  49. if( $place == 'shared' )
  50. {
  51. $url = rtrim( JURI::root() , '/' ) . '/' . trim( str_ireplace( '\\' , '/' , $cfg->get( 'main_shared_path' ) ) , '/\\') . '/' . $file;
  52. }
  53. else
  54. {
  55. $place = explode( ':' , $place );
  56. $url = rtrim( JURI::root() , '/' ) . '/' . trim( $cfg->get( 'main_image_path' ) , '/\\') . '/' . $place[1] . '/' . $file;
  57. }
  58. $theme = new CodeThemes();
  59. $theme->set( 'uid' , uniqid() );
  60. $theme->set( 'url' , $url );
  61. $theme->set( 'autoplay' , $autoplay );
  62. $result[] = $theme->fetch( 'blog.audio.php' );
  63. }
  64. }
  65. return $result;
  66. }
  67. /**
  68. * Processes an audio tag and replaces it with the necessary embed codes.
  69. *
  70. * @param string $content The content that should be looked up on.
  71. */
  72. public function process( $content )
  73. {
  74. $pattern = '/\[embed=audio\](.*)\[\/embed\]/i';
  75. preg_match_all( $pattern , $content , $matches , PREG_SET_ORDER );
  76. if( !empty( $matches ) )
  77. {
  78. $cfg = EasyBlogHelper::getConfig();
  79. $json = new Services_JSON();
  80. foreach( $matches as $match )
  81. {
  82. // The full text of the matched content.
  83. $text = $match[ 0 ];
  84. // The json string
  85. $jsonString = $match[ 1 ];
  86. $obj = $json->decode( $jsonString );
  87. // If there's nothing, let's just remove the tag.
  88. if( !$obj )
  89. {
  90. $content = str_ireplace( $text , '' , $content );
  91. return $content;
  92. }
  93. $file = $obj->file;
  94. $autoplay = ( isset( $obj->autostart ) ) ? $obj->autostart : '0';
  95. $place = $obj->place;
  96. if( $place == 'shared' )
  97. {
  98. $url = rtrim( JURI::root() , '/' ) . '/' . trim( str_ireplace( '\\' , '/' , $cfg->get( 'main_shared_path' ) ) , '/\\') . '/' . $file;
  99. }
  100. else
  101. {
  102. $place = explode( ':' , $place );
  103. $url = rtrim( JURI::root() , '/' ) . '/' . trim( $cfg->get( 'main_image_path' ) , '/\\') . '/' . $place[1] . '/' . $file;
  104. }
  105. $theme = new CodeThemes();
  106. $theme->set( 'uid' , uniqid() );
  107. $theme->set( 'url' , $url );
  108. $theme->set( 'autoplay' , $autoplay );
  109. $result = $theme->fetch( 'blog.audio.php' );
  110. // Now, we'll need to alter the original contents.
  111. $content = str_ireplace( $text , $result , $content );
  112. }
  113. }
  114. return $content;
  115. }
  116. }