PageRenderTime 73ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/mambots/content/azvideobot.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 250 lines | 133 code | 57 blank | 60 comment | 27 complexity | 0cd2cc084f4d6f0bf007ee2fcf725d41 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. (defined( '_VALID_MOS' ) or defined('_JEXEC')) or die( 'Direct Access to this location is not allowed.' );
  3. if(!defined('CMSLIB_DEFINED'))
  4. include_once(dirname(dirname(dirname(__FILE__))) . '/components/libraries/cmslib/spframework.php');
  5. if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  6. global $_MAMBOTS;
  7. $_MAMBOTS->registerFunction('onPrepareContent','mb_videobot');
  8. } else {
  9. global $mainframe;
  10. $mainframe->registerEvent('onPrepareContent','mb_videobot');
  11. }
  12. function mb_videobot($published, & $row, & $params, $page=0 ){
  13. if(func_num_args() <= 3){
  14. $row =&$published;
  15. }
  16. // Use PREG_SET_ORDER so that we would be able to get the matches by
  17. // an array of [0] match 1 [1] match 2 and so on.
  18. preg_match_all('/\[video:(.*?)]/i', $row->text, $matches,PREG_SET_ORDER);
  19. #If no video is found, just exit this function, no further processing needed
  20. if(!is_array($matches) || empty($matches)){
  21. return;
  22. }
  23. $cms =& cmsInstance('CMSCore');
  24. // Get params
  25. $plugin = (cmsVersion() == _CMS_JOOMLA10) ? '#__mambots' : '#__plugins';
  26. $strSQL = "SELECT `params` FROM {$plugin} "
  27. . "WHERE `element`='azvideobot' "
  28. . "AND `folder`='content'";
  29. $cms->db->query($strSQL);
  30. $param = $cms->db->get_object_list();
  31. if(cmsVersion() == _CMS_JOOMLA10 || cmsVersion() == _CMS_MAMBO){
  32. $params =& new mosParameters($param[0]->params);
  33. } else {
  34. $params = new JParameter($param[0]->params);
  35. }
  36. foreach($matches as $match){
  37. #$match[0] = entire tag e.g [video:http://website.com/?param=param]
  38. #$match[1] = real url e.g http://website.com/?param=param
  39. $url = trim($match[1]);
  40. #Check if there is any width or height set by checking the url
  41. #if it contains a space
  42. if(eregi(' ', $url)){
  43. #Get width and height from the $url by splitting widthxheight
  44. $data = explode(' ',$url);
  45. if(eregi('x', $data[1])){
  46. #Set $url so that the widthxheight will be removed
  47. $url = $data[0];
  48. $data = explode('x',$data[1]);
  49. #Set the width from the exploded array
  50. $width = $data[0];
  51. #Set the height from the exploded array
  52. $height = $data[1];
  53. }
  54. else{
  55. # width:height Not properly inputted use default width:height
  56. $width = $params->get('width');
  57. $height = $params->get('height');
  58. }
  59. }else{
  60. $width = $params->get('width');
  61. $height = $params->get('height');
  62. }
  63. #Get the video type
  64. $type = mb_videobot_type($url);
  65. // echo '$height =' . $height . '<br />';
  66. // echo '$width =' . $width . '<br />';
  67. #Call the respective video functions to get the embedded data
  68. // Check if type exists, otherwise display invalid video type.
  69. if(function_exists('mb_videobot_' . $type)){
  70. $embed = call_user_func_array('mb_videobot_' . $type, array($width, $height,$url));
  71. #Replace the tags with the correct returned embedded tags.
  72. $row->text = str_replace($match[0], $embed, $row->text);
  73. }else{
  74. $row->text = str_replace($match[0], '[Invalid video specified]', $row->text);
  75. }
  76. }
  77. return true;
  78. }
  79. /**
  80. * Return the video type based on the url given.
  81. * Return video name
  82. */
  83. function mb_videobot_type($url){
  84. if(eregi('youtube',$url)){
  85. return 'youtube';
  86. }else if(eregi('google',$url)){
  87. return 'google';
  88. }else if(eregi('vimeo',$url)){
  89. return 'vimeo';
  90. }else if(eregi('metacafe',$url)){
  91. return 'metacafe';
  92. }else if(eregi('jumpcut',$url)){
  93. return 'jumpcut';
  94. }else if(eregi('vidiac',$url)){
  95. return 'vidiac';
  96. }else if(eregi('streetfire',$url)){
  97. return 'streetfire';
  98. }else if(eregi('stickam',$url)){
  99. return 'stickam';
  100. }else{
  101. // Return the video type specified
  102. return $url;
  103. }
  104. }
  105. function mb_videobot_youtube($width, $height,$url){
  106. #Need to split all unwanted query strings.
  107. $video = explode('&',$url);
  108. $video = explode('=',$video[0]);
  109. $video = $video[1];
  110. $replace = '<object class="embed" width="'.$width.'" height="'.$height.'" type="application/x-shockwave-flash" data="http://www.youtube.com/v/'.$video.'"><param name="movie" value="http://www.youtube.com/v/'.$video.'" /><param name="wmode" value="transparent"><em>You need to a flashplayer enabled browser to view this video</em></object>';
  111. return $replace;
  112. }
  113. function mb_videobot_vimeo($width, $height ,$url){
  114. #Need to split all unwanted query strings.
  115. $video = explode('vimeo.com/',$url);
  116. $video = $video[1];
  117. $replace = '<object type="application/x-shockwave-flash" width="' . $width . '" height="' . $height . '" data="http://vimeo.com/moogaloop.swf?clip_id=' . $video . '&server=vimeo.com&fullscreen=1&show_title=1&show_byline=1&show_portrait=0&color=01AAEA"><param name="quality" value="best" /><param name="allowfullscreen" value="true" /><param name="scale" value="showAll" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' . $video . '&server=vimeo.com&fullscreen=1&show_title=1&show_byline=1&show_portrait=0&color=01AAEA" /></object>';
  118. return $replace;
  119. }
  120. function mb_videobot_metacafe($width, $height ,$url){
  121. #Need to split all unwanted query strings.
  122. $video = explode('metacafe.com/watch/',$url);
  123. #$video[1] is now id/filename/
  124. $video = $video[1];
  125. #Need to check if the ending url contains trailing slash. If it contains
  126. #a trailing slash, will need to remove it.
  127. $video = $video{strlen($video) - 1} == '/' ? substr($video,0,strlen($video) - 2) : $video;
  128. $replace = '<embed src="http://www.metacafe.com/fplayer/' . $video . '.swf" width="' . $width . '" height="' . $height . '" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';
  129. return $replace;
  130. }
  131. /*
  132. * Function: mb_videobot_google
  133. * Returns: embedded html codes for google videos
  134. * Params: $width - width of video, $height - height of video, $url of video
  135. */
  136. function mb_videobot_google($width, $height ,$url){
  137. #Need to split all unwanted query strings.
  138. $video = explode('google.com/videoplay?docid=',$url);
  139. $video = $video[1];
  140. $replace = '<embed style="width:' . $width . 'px; height:' . $height .'px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=' . $video . '&hl=en" flashvars=""></embed>';
  141. return $replace;
  142. }
  143. /*
  144. * Function: mb_videobot_jumpcut
  145. * Returns: embedded html codes for jumpcut videos
  146. * Params: $width - width of video, $height - height of video, $url of video
  147. */
  148. function mb_videobot_jumpcut($width, $height ,$url){
  149. #Need to split all unwanted query strings.
  150. $video = explode('jumpcut.com/view?id=',$url);
  151. $video = $video[1];
  152. $replace = '<embed src="http://www.jumpcut.com/media/flash/jump.swf?id=' . $video . '&asset_type=movie&asset_id=' . $video . '&eb=1" width="' . $width . '" height="' . $height . '" type="application/x-shockwave-flash"></embed>';
  153. return $replace;
  154. }
  155. /*
  156. * Function: mb_videobot_vidiac
  157. * Returns: embedded html codes for vidiac videos
  158. * Params: $width - width of video, $height - height of video, $url of video
  159. */
  160. function mb_videobot_vidiac($width, $height ,$url){
  161. #Need to split all unwanted query strings.
  162. $video = explode('vidiac.com/video/',$url);
  163. $video = explode('.htm',$video[1]);
  164. $video = $video[0];
  165. $replace = '<embed src="http://www.vidiac.com/vidiac.swf" FlashVars="video=' . $video . '" quality="high" bgcolor="#ffffff" width="' . $width . '" height="' . $height .'" name="ePlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
  166. return $replace;
  167. }
  168. /*
  169. * Function: mb_videobot_streetfire
  170. * Returns: embedded html codes for streetfire videos
  171. * Params: $width - width of video, $height - height of video, $url of video
  172. */
  173. function mb_videobot_streetfire($width, $height ,$url){
  174. #Need to split all unwanted query strings.
  175. $video = explode('streetfire.net/video/',$url);
  176. $video = explode('.htm',$video[1]);
  177. $video = $video[0];
  178. $replace = '<embed src="http://videos.streetfire.net/vidiac.swf" FlashVars="video=' . $video . '" quality="high" bgcolor="#ffffff" width="'. $width .'" height="' . $height .'" name="ePlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
  179. return $replace;
  180. }
  181. /*
  182. * Function: mb_videobot_stickam
  183. * Returns: embedded html codes for stickam videos
  184. * Params: $width - width of video, $height - height of video, $url of video
  185. */
  186. function mb_videobot_stickam($width, $height ,$url){
  187. #Need to split all unwanted query strings.
  188. $video = explode('stickam.com/editMediaComment.do?method=load&mId=',$url);
  189. $video = $video[1];
  190. $replace = '<embed src="http://player.stickam.com/flashVarMediaPlayer/' . $video . '" type="application/x-shockwave-flash" scale="noscale" allowFullScreen="true" width="'. $width .'" height="' . $height . '" allowScriptAccess="always"></embed>';
  191. return $replace;
  192. }
  193. ?>