PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/hwdvs-thirdparty/google.view.php

https://github.com/Shigaru/shigaru
PHP | 282 lines | 182 code | 39 blank | 61 comment | 60 complexity | 1cb485de542a040f82b6ffbb3a7136ab MD5 | raw file
  1. <?php
  2. /**
  3. * @version [ Nightly Build ]
  4. * @package hwdVideoShare
  5. * @copyright (C) 2007 - 2011 Highwood Design
  6. * @license Creative Commons Attribution-Non-Commercial-No Derivative Works 3.0 Unported Licence
  7. * @license http://creativecommons.org/licenses/by-nc-nd/3.0/
  8. */
  9. defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
  10. /**
  11. * Prepares the code to insert the third party video
  12. *
  13. * @param string $option the $video_id output containing video paramters
  14. * @param int $flv_width the video width
  15. * @param int $flv_height the video height
  16. * @return $code the third party embed code
  17. */
  18. function googleComPrepareVideo($row, $flv_width=null, $flv_height=null, $autostart=null)
  19. {
  20. global $smartyvs, $task, $show_video_ad, $pre_url, $post_url;
  21. if (!defined('HWDVIDSPATH')) { define('HWDVIDSPATH', dirname(__FILE__).'/../../'); }
  22. $c = hwd_vs_Config::get_instance();
  23. $code=null;
  24. if (@explode(",", $row->video_id)) {
  25. $data = explode(",", $row->video_id);
  26. $videocode = $data[0];
  27. } else {
  28. return $code;
  29. }
  30. if ($c->playlocal == "1") {
  31. $truepath = googleComPrepareFlvURL($row->video_id);
  32. } else {
  33. $truepath = '';
  34. }
  35. $file_ext = substr($row->thumbnail, strrpos($row->thumbnail, '.') + 1);
  36. $thumb_url = hwd_vs_tools::generatePlayerThumbnail($row);
  37. //$thumb_url = hwd_vs_tools::get_final_url( $thumb_url );
  38. //$thumb_url = urlencode( $thumb_url );
  39. if ($c->hwdvids_videoplayer_file == "flow") {
  40. // temp fix for problem with Google thumbs in flow player
  41. $thumb_url = null;
  42. }
  43. if (!empty($truepath) && $c->playlocal == "1") {
  44. $player = new hwd_vs_videoplayer();
  45. if ($show_video_ad == 1) {
  46. if ($c->hwdvids_videoplayer_file == "flow") {
  47. $flv_tracks = array();
  48. $flv_tracks[0] = $pre_url;
  49. $flv_tracks[1] = $truepath;
  50. $flv_tracks[2] = $post_url;
  51. $code.= $player->prepareEmbeddedPlayer($flv_tracks, $flv_width, $flv_height, rand(100, 999), "playlist", null, null, null);
  52. return $code;
  53. } else {
  54. $xspf_playlist = JPATH_SITE."/components/com_hwdvideoshare/xml/xspf/".$row->id.".xml";
  55. @unlink($xspf_playlist);
  56. require_once(HWDVIDSPATH.'/../../administrator/components/com_hwdrevenuemanager/redrawplaylist.class.php');
  57. hwd_rm_playlist::writeFile($row, $truepath, $pre_url, $post_url, $thumb_url);
  58. if (file_exists($xspf_playlist)) {
  59. $flv_url = JURI::root(true)."/components/com_hwdvideoshare/xml/xspf/".$row->id.".xml";
  60. $flv_path = HWDVIDSPATH.'/xml/xspf/'.$row->id.'.xml';
  61. if ($c->loadswfobject == "on" && $task !=="grabjomsocialplayer") {
  62. $code.= $player->prepareplayer($flv_url, $flv_width, $flv_height, rand(100, 999), "playlist", $flv_path, null, $autostart);
  63. } else {
  64. $code.= $player->prepareEmbeddedPlayer($flv_url, $flv_width, $flv_height, rand(100, 999), "playlist", $flv_path, null, $autostart);
  65. }
  66. return $code;
  67. }
  68. }
  69. }
  70. if ($c->loadswfobject == "on") {
  71. $code.= $player->prepareplayer($truepath, $flv_width, $flv_height, rand(100, 999), "video", null, $thumb_url, $autostart);
  72. } else {
  73. $code.= $player->prepareEmbeddedPlayer($truepath, $flv_width, $flv_height, rand(100, 999), "video", null, $thumb_url, $autostart);
  74. }
  75. return $code;
  76. } else {
  77. if ($flv_width==null) {
  78. $smartyvs->assign("player_width", $c->flvplay_width);
  79. $flv_width = $c->flvplay_width."px";
  80. } else {
  81. $smartyvs->assign("player_width", $flv_width);
  82. if (preg_match("/%/", $flv_width)) {
  83. $flv_width = $flv_width;
  84. } else {
  85. $flv_width = $flv_width."px";
  86. }
  87. }
  88. if ($flv_height==null) {
  89. $flv_height = intval ($flv_width*$c->var_fb);
  90. $flv_height = $flv_height+27;
  91. $flv_height = $flv_height."px";
  92. } else {
  93. if (preg_match("/%/", $flv_height)) {
  94. $flv_height = $flv_height;
  95. } else {
  96. $flv_height = $flv_height."px";
  97. }
  98. }
  99. $code = "<embed id=\"VideoPlayback\" src=\"http://video.google.com/googleplayer.swf?docid=".$videocode."&hl=en&fs=true\" style=\"width:".$flv_width.";height:".$flv_height."\" allowFullScreen=\"true\" allowScriptAccess=\"always\" wmode=\"transparent\" type=\"application/x-shockwave-flash\"></embed>";
  100. return $code;
  101. }
  102. return $code;
  103. }
  104. /**
  105. * Prepares the code to insert the third party thumbnail image
  106. *
  107. * @param string $option the $video_id output containing video paramters
  108. * @param int $vid the video database id
  109. * @param int $Itemid the joomla menu id
  110. * @param int $k the alternating CSS integer
  111. * @return $code the full third party thumbnail image tag
  112. */
  113. function googleComPrepareThumb($option, $vid, $Itemid, $k, $width=null, $height=null, $class=null, $tooltip_data=null)
  114. {
  115. if (!isset($width)) {
  116. $width = $c->thumbwidth;
  117. }
  118. if (!isset($height)) {
  119. $height = $width*$c->tar_fb;
  120. }
  121. $code = "<img src=\"".googleComPrepareThumbURL($option, $vid)."\" border=\"0\" width=\"".$width."\" height=\"".$height."\" title=\"".$tooltip_data[1]." :: ".$tooltip_data[2]."\" class=\"".$class."\" />";
  122. return $code;
  123. }
  124. /**
  125. * Prepares the code to insert the third party thumbnail image
  126. *
  127. * @param string $option the $video_id output containing video paramters
  128. * @param int $vid the video database id
  129. * @param int $Itemid the joomla menu id
  130. * @param int $k the alternating CSS integer
  131. * @return $code the full third party thumbnail image tag
  132. */
  133. function googleComPrepareThumbURL($option, $vid)
  134. {
  135. $data = explode(",", $option);
  136. $thumbnail = @$data[1];
  137. if (!$thumbnail) {
  138. $code = URL_HWDVS_IMAGES.'default_thumb.jpg';
  139. } else {
  140. $code = $thumbnail;
  141. }
  142. return $code;
  143. }
  144. /**
  145. * Prepares the third party video link
  146. *
  147. * @param string $option the $video_id output containing video paramters
  148. * @param int $vid the video database id
  149. * @param int $Itemid the joomla menu id
  150. * @return $code the full third party thumbnail image tag
  151. */
  152. function googleComPrepareVideoURL($option)
  153. {
  154. if (@explode(",", $option)) {
  155. $data = explode(",", $option);
  156. $videocode = $data[0];
  157. } else { $videocode = "ERROR"; }
  158. $code = "http://video.google.com/videoplay?docid=".$videocode;
  159. return $code;
  160. }
  161. /**
  162. * Prepares the third party video embed code
  163. *
  164. * @param string $option the $video_id output containing video paramters
  165. * @param int $vid the video database id
  166. * @param int $Itemid the joomla menu id
  167. * @return $code the full third party thumbnail image tag
  168. */
  169. function googleComPrepareVideoEmbed($option, $vid, $Itemid)
  170. {
  171. global $mosConfig_sitename, $mosConfig_live_site;
  172. $c = hwd_vs_Config::get_instance();
  173. if (@explode(",", $option)) {
  174. $data = explode(",", $option);
  175. $videocode = $data[0];
  176. } else { $videocode = "ERROR"; }
  177. $code = null;
  178. if ($c->embedreturnlink == 1) {
  179. $code.='<div><center>';
  180. }
  181. $code.= "<embed style=&#34;width:400px; height:326px;&#34; id=&#34;VideoPlayback&#34; type=&#34;application/x-shockwave-flash&#34; src=&#34;http://video.google.com/googleplayer.swf?docId=".$videocode."&hl=en&#34; flashvars=&#34;&#34;> </embed>";
  182. if ($c->embedreturnlink == 1) {
  183. $jconfig = new jconfig();
  184. $code.='<br /><a href=&#34;'.JURI::root().'index.php?option=com_hwdvideoshare&Itemid='.$Itemid.'&#34; title=&#34;'.$jconfig->sitename.'&#34;>'.$jconfig->sitename.'</a></center></div>';
  185. }
  186. return $code;
  187. }
  188. /**
  189. * Prepares the third party video embed code
  190. *
  191. * @param string $option the $video_id output containing video paramters
  192. * @param int $vid the video database id
  193. * @param int $Itemid the joomla menu id
  194. * @return $code the full third party thumbnail image tag
  195. */
  196. function googleComPrepareFlvURL($option)
  197. {
  198. global $mosConfig_sitename, $mosConfig_live_site;
  199. $c = hwd_vs_Config::get_instance();
  200. if (@explode(",", $option)) {
  201. $data = explode(",", $option);
  202. $videocode = $data[0];
  203. } else { $videocode = "ERROR"; }
  204. $code=null;
  205. $truepath = '';
  206. $feedurl = "http://video.google.com/videofeed?docid=".$data[0];
  207. if (function_exists('curl_init')) {
  208. // get thumbnail URL with CURL
  209. $curl_handle=curl_init();
  210. curl_setopt($curl_handle,CURLOPT_URL,$feedurl);
  211. curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
  212. curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
  213. $buffer = curl_exec($curl_handle);
  214. curl_close($curl_handle);
  215. if (empty($buffer)) {
  216. $truepath = '';
  217. } else {
  218. preg_match_all('/<media:content url="([^"]+)/',$buffer,$matches, PREG_PATTERN_ORDER);
  219. if (!empty($matches[1][1])) {
  220. foreach ($matches[1] as $url) {
  221. if (!preg_match("/googleplayer.swf/i", $url) && !preg_match("/videofeed/i", $url)) {
  222. $truepath = $url;
  223. $truepath = str_replace('amp;','',$truepath);
  224. }
  225. }
  226. } else {
  227. $truepath = '';
  228. }
  229. }
  230. }
  231. if (isset($truepath) && !empty($truepath)) {
  232. $truepath = hwd_vs_tools::get_final_url( $truepath );
  233. $filegrab = @file_get_contents($truepath, null, null, 0, 16);
  234. $filecheck = @stripos($filegrab, "flv");
  235. if (isset($truepath) && !empty($truepath) && $filecheck !== false) {
  236. $truepath = urlencode( $truepath );
  237. } else {
  238. return false;
  239. }
  240. }
  241. return $truepath;
  242. }
  243. ?>