PageRenderTime 55ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_hwdvideoshare/helpers/draw.php

https://github.com/Shigaru/shigaru
PHP | 423 lines | 326 code | 44 blank | 53 comment | 73 complexity | f1199b50e8f12d77b2e834ce90f75ff7 MD5 | raw file
  1. <?php
  2. /**
  3. * @version [ Nightly Build ]
  4. * @package hwdVideoShare
  5. * @copyright (C) 2007 - 2011 Highwood Design
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. ***
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. defined( '_JEXEC' ) or die( 'Direct Access to this location is not allowed.' );
  22. /**
  23. * Process character encoding
  24. * @package hwdVideoShare
  25. * @author Dave Horsfall <info@highwooddesign.co.uk>
  26. * @copyright 2008 Highwood Design
  27. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  28. * @version 1.1.3
  29. */
  30. class hwdvsDrawFile {
  31. function generalConfig()
  32. {
  33. $db =& JFactory::getDBO();
  34. jimport('joomla.filesystem.file');
  35. $config = "<?php\n";
  36. $config .= "class hwd_vs_Config{ \n\n";
  37. $config .= " var \$instanceConfig = null;\n\n";
  38. $config .= " // Member variables\n";
  39. // print out config
  40. $query = 'SELECT *'
  41. . ' FROM #__hwdvidsgs'
  42. ;
  43. $db->setQuery($query);
  44. $rows = $db->loadObjectList();
  45. for ($i=0, $n=count($rows); $i < $n; $i++) {
  46. $row = $rows[$i];
  47. if ($row->setting == "flvplay_width" && empty($row->value)) { $row->value = "450"; }
  48. if ($row->setting == "customencode") { $row->value = addslashes($row->value); }
  49. $config .= " var \$".$row->setting." = '".$row->value."';\n";
  50. }
  51. $config .= "\n function get_instance(){\n";
  52. $config .= " \$instanceConfig = new hwd_vs_Config;\n";
  53. $config .= " return \$instanceConfig;\n";
  54. $config .= " }\n\n";
  55. $config .= "}\n";
  56. $config .= "?>";
  57. $configFile = JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'config.hwdvideoshare.php';
  58. if (!JFile::write($configFile, $config)) {
  59. return false;
  60. }
  61. return true;
  62. }
  63. function serverConfig()
  64. {
  65. $db =& JFactory::getDBO();
  66. jimport('joomla.filesystem.file');
  67. $config = "<?php\n";
  68. $config .= "class hwd_vs_SConfig{ \n\n";
  69. $config .= " var \$instanceConfig = null;\n\n";
  70. $config .= " // Member variables\n";
  71. // print out config
  72. $query = 'SELECT *'
  73. . ' FROM #__hwdvidsss'
  74. ;
  75. $db->setQuery($query);
  76. $rows = $db->loadObjectList();
  77. for ($i=0, $n=count($rows); $i < $n; $i++) {
  78. $row = $rows[$i];
  79. $config .= " var \$".$row->setting." = '".$row->value."';\n";
  80. }
  81. $config .= "\n function get_instance(){\n";
  82. $config .= " \$instanceConfig = new hwd_vs_SConfig;\n";
  83. $config .= " return \$instanceConfig;\n";
  84. $config .= " }\n\n";
  85. $config .= "}\n";
  86. $config .= "?>";
  87. $configFile = JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'serverconfig.hwdvideoshare.php';
  88. if (!JFile::write($configFile, $config)) {
  89. return false;
  90. }
  91. return true;
  92. }
  93. /**
  94. * Make xml playlist datafile
  95. *
  96. * @return True
  97. */
  98. function XMLDataFile($rows, $filename)
  99. {
  100. $db =& JFactory::getDBO();
  101. $c = hwd_vs_Config::get_instance();
  102. jimport('joomla.filesystem.file');
  103. $config = null;
  104. $config .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  105. $config .= "<playlist version=\"1\">\n";
  106. $config .= "<title>hwdVideoShare ".$filename." Playlist</title>\n";
  107. $config .= "<info>http:/xspf.org/xspf-v1.html</info>\n";
  108. $config .= "<date>".date('Y-m-d H:i:s')."</date>\n";
  109. $config .= "<trackList>\n";
  110. $config .= "\n";
  111. for ($i=0, $n=count($rows); $i < $n; $i++)
  112. {
  113. $row = $rows[$i];
  114. $row->title = hwdEncoding::charset_decode_utf_8($row->title);
  115. $row->title = hwdEncoding::XMLEntities($row->title);
  116. $row->description = hwdEncoding::charset_decode_utf_8($row->description);
  117. $row->description = hwdEncoding::XMLEntities($row->description);
  118. $row->description = hwd_vs_tools::truncateText($row->description, 1000);
  119. $video_code = explode(",", $row->video_id);
  120. if (empty($video_code[1]))
  121. {
  122. $row->video_id = hwdEncoding::XMLEntities($row->video_id);
  123. }
  124. else
  125. {
  126. $video_code[0] = hwdEncoding::XMLEntities($video_code[0]);
  127. $video_code[1] = urlencode($video_code[1]);
  128. $row->video_id = implode(",", $video_code);
  129. }
  130. if (empty($row->video_length))
  131. {
  132. $row->video_length = "0:00:00";
  133. }
  134. if (!isset($row->username) || empty($row->username))
  135. {
  136. $row->username = "_HWDVIDS_INFO_GUEST";
  137. }
  138. if (!isset($row->name) || empty($row->name))
  139. {
  140. $row->name = "_HWDVIDS_INFO_GUEST";
  141. }
  142. if ($row->user_id == 0 || !isset($row->username) || !isset($row->name))
  143. {
  144. $row->username = "_HWDVIDS_INFO_GUEST";
  145. $row->name = "_HWDVIDS_INFO_GUEST";
  146. }
  147. $config .= " <track>\n";
  148. $config .= " <id><![CDATA[".$row->id."]]></id>\n";
  149. $config .= " <videotitle><![CDATA[".$row->title."]]></videotitle>\n";
  150. $config .= " <videocode><![CDATA[".$row->video_id."]]></videocode>\n";
  151. $config .= " <videotype><![CDATA[".$row->video_type."]]></videotype>\n";
  152. $config .= " <thumbnail><![CDATA[".$row->thumbnail."]]></thumbnail>\n";
  153. $config .= " <category><![CDATA[]]></category>\n";
  154. $config .= " <category_id><![CDATA[".$row->category_id."]]></category_id>\n";
  155. $config .= " <description><![CDATA[".$row->description."]]></description>\n";
  156. $config .= " <views><![CDATA[".$row->number_of_views."]]></views>\n";
  157. if($row->counts)
  158. $config .= " <numfavoured><![CDATA[".$row->counts."]]></numfavoured>\n";
  159. $config .= " <views><![CDATA[".$row->number_of_views."]]></views>\n";
  160. $config .= " <date><![CDATA[".$row->date_uploaded."]]></date>\n";
  161. $config .= " <duration><![CDATA[".$row->video_length."]]></duration>\n";
  162. $config .= " <rating><![CDATA[".$row->updated_rating."]]></rating>\n";
  163. if ($c->userdisplay == 1) {
  164. $config .= " <uploader><![CDATA[".$row->username."]]></uploader>\n";
  165. } else {
  166. $config .= " <uploader><![CDATA[".$row->name."]]></uploader>\n";
  167. }
  168. $config .= " <uploader_id><![CDATA[".$row->user_id."]]></uploader_id>\n";
  169. if ($c->cbint !== "0" && !empty($row->avatar)) {
  170. $avatar = $row->avatar;
  171. } else {
  172. $avatar = "";
  173. }
  174. $config .= " <avatar><![CDATA[".$avatar."]]></avatar>\n";
  175. $config .= " <comments><![CDATA[".$row->number_of_comments."]]></comments>\n";
  176. $config .= " <tags><![CDATA[".addslashes($row->tags)."]]></tags>\n";
  177. $config .= " </track>\n";
  178. $config .= "\n";
  179. }
  180. $config .= "</trackList>\n";
  181. $config .= "</playlist>\n";
  182. $configFile = JPATH_SITE.DS.'components'.DS.'com_hwdvideoshare'.DS.'xml'.DS.$filename.'.xml';
  183. if (!JFile::write($configFile, $config)) {
  184. return false;
  185. }
  186. return true;
  187. }
  188. /**
  189. * Make xml playlist file
  190. *
  191. * @return True
  192. */
  193. function XMLPlaylistFile($rows, $filename)
  194. {
  195. $db =& JFactory::getDBO();
  196. $c = hwd_vs_Config::get_instance();
  197. jimport('joomla.filesystem.file');
  198. $config = null;
  199. $config .= "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\" xmlns:jwplayer=\"http://developer.longtailvideo.com/ns/1\">\n";
  200. $config .= "<title>hwdVideoShare Playlist</title>\n";
  201. $config .= "<info>http:/xspf.org/xspf-v1.html</info>\n";
  202. $config .= "<date>".date('Y-m-d H:i:s')."</date>\n";
  203. $config .= "<trackList>\n";
  204. $config .= "\n";
  205. // print out playlist
  206. for ($i=0, $n=count($rows); $i < $n; $i++)
  207. {
  208. $row = $rows[$i];
  209. $type = "video";
  210. $title = strip_tags(hwdEncoding::UNXMLEntities($row->title));
  211. $annotation = strip_tags(hwdEncoding::UNXMLEntities($row->description));
  212. $image = hwd_vs_tools::generatePlayerThumbnail($row);
  213. $image = urldecode($image);
  214. if ($row->video_type == "rtmp")
  215. {
  216. $parsed_url = parse_url($row->video_id);
  217. $rtmp_file_temp = $parsed_url['path'];
  218. $rtmp_file_temp = explode(":", $rtmp_file_temp, 2);
  219. if (!empty($rtmp_file_temp[1]))
  220. {
  221. $rtmp_file = $rtmp_file_temp[1];
  222. if (substr($rtmp_file, 0, 1) == "/")
  223. {
  224. $rtmp_file = substr($rtmp_file, 1);
  225. }
  226. $rtmp_streamer_temp = $rtmp_file_temp[0];
  227. $rtmp_streamer_temp = explode("/", $rtmp_streamer_temp);;
  228. $rtmp_path = implode("/", $rtmp_streamer_temp);
  229. $rtmp_streamer = $parsed_url['scheme']."://".$parsed_url['host'].$rtmp_path;
  230. }
  231. else
  232. {
  233. $rtmp_file = null;
  234. $rtmp_streamer = null;
  235. }
  236. $type = "rtmp";
  237. $config .= " <track>\n";
  238. $config .= " <jwplayer:streamer><![CDATA[".$rtmp_streamer."]]></jwplayer:streamer>\n";
  239. $config .= " <jwplayer:file><![CDATA[".$rtmp_file."]]></jwplayer:file>\n";
  240. $config .= " <image><![CDATA[".$image."]]></image>\n";
  241. $config .= " <title><![CDATA[".$title."]]></title>\n";
  242. $config .= " <annotation><![CDATA[".$annotation."]]></annotation>\n";
  243. $config .= " <meta rel='type'>".$type."</meta>\n";
  244. $config .= " </track>\n";
  245. }
  246. else if (($row->video_type == "youtube.com" || ($row->video_type == "seyret" && substr($row->video_id, 0, 7) == "youtube")) && ($c->hwdvids_videoplayer_file == "jwflv" || $c->hwdvids_videoplayer_file == "jwflv_v5" || $c->hwdvids_videoplayer_file == "jwflv_html5"))
  247. {
  248. $data = @explode(",", $row->video_id);
  249. if ($row->video_type == "seyret")
  250. {
  251. $YTID = $data[1];
  252. }
  253. else
  254. {
  255. $YTID = $data[0];
  256. }
  257. $location = "http://www.youtube.com/watch?v=".$YTID;
  258. $type = "youtube";
  259. if (empty($location)) continue;
  260. $config .= " <track>\n";
  261. $config .= " <location><![CDATA[".$location."]]></location>\n";
  262. $config .= " <image><![CDATA[".$image."]]></image>\n";
  263. $config .= " <title><![CDATA[".$title."]]></title>\n";
  264. $config .= " <annotation><![CDATA[".$annotation."]]></annotation>\n";
  265. $config .= " <meta rel='type'>".$type."</meta>\n";
  266. $config .= " </track>\n";
  267. }
  268. else
  269. {
  270. $locations = hwd_vs_tools::generateVideoLocations($row);
  271. $location = $locations['url'];
  272. if (empty($location)) continue;
  273. jimport( 'joomla.html.parameter' );
  274. $useStreamer = false;
  275. $pluginPlayer =& JPluginHelper::getPlugin("hwdvs-videoplayer", "$c->hwdvids_videoplayer_file");
  276. $pluginPlayerParams = new JParameter( $pluginPlayer->params );
  277. $pluginPlayerStreamer = $pluginPlayerParams->get('pseudostreaming', 0);
  278. if ($pluginPlayerStreamer == "1" && ($c->hwdvids_videoplayer_file == "jwflv" || $c->hwdvids_videoplayer_file == "jwflv_v5"))
  279. {
  280. $type = "http";
  281. if ($locations['use_xMoovphp'])
  282. {
  283. if ($pluginPlayerStreamer == "1" && ($c->hwdvids_videoplayer_file == "jwflv" || $c->hwdvids_videoplayer_file == "jwflv_v5"))
  284. {
  285. $dlink = $row->video_id.".flv";
  286. $useStreamer = true;
  287. $streamer = "http://".$_SERVER['HTTP_HOST'].JURI::root( true )."/plugins/hwdvs-videoplayer/".$c->hwdvids_videoplayer_file."/streamer.php";
  288. }
  289. }
  290. }
  291. $config .= " <track>\n";
  292. if ($useStreamer)
  293. {
  294. $config .= " <jwplayer:streamer><![CDATA[".$streamer."]]></jwplayer:streamer>\n";
  295. $config .= " <jwplayer:file><![CDATA[".$dlink."]]></jwplayer:file>\n";
  296. $config .= " <jwplayer:provider>http</jwplayer:provider>\n";
  297. }
  298. else
  299. {
  300. $config .= " <location><![CDATA[".$location."]]></location>\n";
  301. }
  302. $config .= " <image><![CDATA[".$image."]]></image>\n";
  303. $config .= " <title><![CDATA[".$title."]]></title>\n";
  304. $config .= " <annotation><![CDATA[".$annotation."]]></annotation>\n";
  305. $config .= " <meta rel='type'>http</meta>\n";
  306. $config .= " </track>\n";
  307. }
  308. $config .= "\n";
  309. }
  310. $config .= "</trackList>\n";
  311. $config .= "</playlist>\n";
  312. $configFile = JPATH_SITE.DS.'components'.DS.'com_hwdvideoshare'.DS.'xml'.DS.'xspf'.DS.$filename.'.xml';
  313. if (!JFile::write($configFile, $config)) {
  314. return false;
  315. }
  316. return true;
  317. }
  318. /**
  319. * Make xml playlist file
  320. *
  321. * @return True
  322. */
  323. function processDynamicCSS($css, $firstWrite=false)
  324. {
  325. global $option, $task, $Itemid;
  326. $db =& JFactory::getDBO();
  327. $doc = & JFactory::getDocument();
  328. $app = & JFactory::getApplication();
  329. $c = hwd_vs_Config::get_instance();
  330. jimport('joomla.filesystem.file');
  331. if($doc->getType() == 'html')
  332. {
  333. $template_element = $app->getUserState( "com_hwdvideoshare.template_element", "default" );
  334. if (!empty($template_element))
  335. {
  336. $c->hwdvids_template_file = $template_element;
  337. }
  338. $view = JRequest::getCmd( 'view', '' );
  339. $userid = JRequest::getInt( 'userid', '' );
  340. $dynamicCssFile = JPATH_SITE.DS."cache".DS."hwdvs".$c->hwdvids_template_file.DS."hwdvs_".$option."_".$task."_".$view."_".$userid."_".$Itemid.".css";
  341. if ($firstWrite)
  342. {
  343. /**
  344. * $dynamicCssContentWithHeaders = "<?php
  345. * header('Content-type: text/css');
  346. * header('Cache-Control: no-cache, must-revalidate');
  347. * header('Pragma: no-cache');
  348. * ?>
  349. * $css";
  350. */
  351. if (!JFile::write($dynamicCssFile, $css))
  352. {
  353. $doc->addCustomTag("<style type=\"text/css\">$css</style>");
  354. }
  355. else
  356. {
  357. $doc->addCustomTag("<link rel=\"stylesheet\" href=\"".JURI::root( true )."/cache/hwdvs".$c->hwdvids_template_file."/hwdvs_".$option."_".$task."_".$view."_".$userid."_".$Itemid.".css\" type=\"text/css\" />");
  358. }
  359. }
  360. else
  361. {
  362. if (file_exists($dynamicCssFile))
  363. {
  364. $dynamicCssContent = JFile::read($dynamicCssFile);
  365. $dynamicCssContent.= $css;
  366. if (!JFile::write($dynamicCssFile, $dynamicCssContent))
  367. {
  368. $doc->addCustomTag("<style type=\"text/css\">$css</style>");
  369. }
  370. }
  371. else
  372. {
  373. $doc->addCustomTag("<style type=\"text/css\">$css</style>");
  374. }
  375. }
  376. }
  377. }
  378. }
  379. ?>