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

/administrator/components/com_hwdvideoshare/models/maintenance.php

https://github.com/Shigaru/shigaru
PHP | 353 lines | 240 code | 52 blank | 61 comment | 18 complexity | 5f49cc3f3c8e3993dbea53bfa923938c 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. class hwdvids_BE_maintenance
  23. {
  24. /**
  25. * system cleanup
  26. */
  27. function maintenance()
  28. {
  29. global $limit, $limitstart;
  30. $db =& JFactory::getDBO();
  31. $db->SetQuery( "SELECT count(*)"
  32. . "\nFROM #__hwdvidsvideos AS a"
  33. . "\nWHERE a.approved = \"deleted\""
  34. );
  35. $total = $db->loadResult();
  36. echo $db->getErrorMsg();
  37. $permdelete_report = null;
  38. $fixerrors_report = null;
  39. $recount_report = null;
  40. $archivelogs_report = null;
  41. // set fixerror cache variables
  42. $cachedir = JPATH_SITE.'/administrator/cache/'; // Directory to cache files in (keep outside web root)
  43. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  44. $page = 'http://fixerrorfile'; // Requested page
  45. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  46. $fixerror_cache = (@file_exists($cachefile)) ? @date ("F d Y H:i:s.", filemtime($cachefile)) : "Never";
  47. // set recount cache variables
  48. $cachedir = JPATH_SITE.'/administrator/cache/'; // Directory to cache files in (keep outside web root)
  49. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  50. $page = 'http://recountfile'; // Requested page
  51. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  52. $recount_cache = (@file_exists($cachefile)) ? @date ("F d Y H:i:s.", filemtime($cachefile)) : "Never";
  53. // set archive cache variables
  54. $cachedir = JPATH_SITE.'/administrator/cache/'; // Directory to cache files in (keep outside web root)
  55. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  56. $page = 'http://archivefile'; // Requested page
  57. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  58. $archive_cache = (@file_exists($cachefile)) ? @date ("F d Y H:i:s.", filemtime($cachefile)) : "Never";
  59. hwdvids_HTML::maintenance($permdelete_report, $total, $fixerrors_report, $recount_report, $archivelogs_report, $fixerror_cache, $recount_cache, $archive_cache);
  60. }
  61. /**
  62. * system cleanup
  63. */
  64. function runmaintenance()
  65. {
  66. global $limit, $limitstart;
  67. $db =& JFactory::getDBO();
  68. $run_permdel = JRequest::getInt( 'run_permdel', 0 );
  69. $run_fixerrors = JRequest::getInt( 'run_fixerrors', 0 );
  70. $run_recount = JRequest::getInt( 'run_recount', 0 );
  71. $run_archivelogs = JRequest::getInt( 'run_archivelogs', 0 );
  72. $permdelete_report = null;
  73. $fixerrors_report = null;
  74. $recount_report = null;
  75. $archivelogs_report = null;
  76. if ($run_permdel == 1) {
  77. // permenantly delete
  78. $query = "SELECT a.*"
  79. . "\nFROM #__hwdvidsvideos AS a"
  80. . "\nWHERE a.approved = \"deleted\""
  81. ;
  82. $db->SetQuery( $query );
  83. $rows = $db->loadObjectList();
  84. for($i=0, $n=count( $rows ); $i < $n; $i++) {
  85. $row = &$rows[$i];
  86. $files = array();
  87. $files[] = JPATH_SITE."/hwdvideos/uploads/".$row->video_id.".flv";
  88. $files[] = JPATH_SITE."/hwdvideos/uploads/".$row->video_id.".mp4";
  89. $files[] = JPATH_SITE."/hwdvideos/thumbs/".$row->video_id.".jpg";
  90. $files[] = JPATH_SITE."/hwdvideos/thumbs/".$row->video_id.".gif";
  91. $files[] = JPATH_SITE."/hwdvideos/thumbs/l_".$row->video_id.".jpg";
  92. for($j=0, $m=count( $files ); $j < $m; $j++)
  93. {
  94. $file = &$files[$j];
  95. if (@file_exists($file))
  96. {
  97. @unlink($file);
  98. }
  99. }
  100. }
  101. $db->SetQuery("DELETE FROM #__hwdvidsvideos WHERE approved = \"deleted\"");
  102. $db->Query();
  103. if ( !$db->query() ) {
  104. echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
  105. exit();
  106. }
  107. $permdelete_report = true;
  108. }
  109. if ($run_fixerrors !== 0) {
  110. // perform 'fix errors' maintenance
  111. require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'maintenance_fixerrors.class.php');
  112. $fixerrors_report = hwd_vs_fixerrors::initiate($run_fixerrors);
  113. }
  114. if ($run_recount !== 0) {
  115. // perform 'recount' maintenance
  116. require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'maintenance_recount.class.php');
  117. $recount_report = hwd_vs_recount::initiate($run_recount);
  118. }
  119. // set fixerror cache variables
  120. $cachedir = JPATH_SITE.'/administrator/cache/'; // Directory to cache files in (keep outside web root)
  121. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  122. $page = 'http://fixerrorfile'; // Requested page
  123. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  124. $fixerror_cache = (@file_exists($cachefile)) ? @date ("F d Y H:i:s.", filemtime($cachefile)) : "Never";
  125. // set recount cache variables
  126. $cachedir = JPATH_SITE.'/administrator/cache/'; // Directory to cache files in (keep outside web root)
  127. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  128. $page = 'http://recountfile'; // Requested page
  129. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  130. $recount_cache = (@file_exists($cachefile)) ? @date ("F d Y H:i:s.", filemtime($cachefile)) : "Never";
  131. // set archive cache variables
  132. $cachedir = JPATH_SITE.'/administrator/cache/'; // Directory to cache files in (keep outside web root)
  133. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  134. $page = 'http://archivefile'; // Requested page
  135. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  136. $archive_cache = (@file_exists($cachefile)) ? @date ("F d Y H:i:s.", filemtime($cachefile)) : "Never";
  137. $db->SetQuery( "SELECT count(*)"
  138. . "\nFROM #__hwdvidsvideos AS a"
  139. . "\nWHERE a.approved = \"deleted\""
  140. );
  141. $total = $db->loadResult();
  142. echo $db->getErrorMsg();
  143. hwdvids_HTML::maintenance($permdelete_report, $total, $fixerrors_report, $recount_report, $archivelogs_report, $fixerror_cache, $recount_cache, $archive_cache);
  144. }
  145. /**
  146. * system cleanup
  147. */
  148. function clearPlaylistCache()
  149. {
  150. // set cache variables
  151. $cachedir = JPATH_SITE.'/cache/'; // Directory to cache files in (keep outside web root)
  152. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  153. $page_today = 'http://xmlplaylists_today';
  154. $cachefile_today = $cachedir . md5($page_today) . '.' . $cacheext;
  155. $page_thisweek = 'http://xmlplaylists_thisweek';
  156. $cachefile_thisweek = $cachedir . md5($page_thisweek) . '.' . $cacheext;
  157. $page_thismonth = 'http://xmlplaylists_thismonth';
  158. $cachefile_thismonth = $cachedir . md5($page_thismonth) . '.' . $cacheext;
  159. $page_alltime = 'http://xmlplaylists_alltime';
  160. $cachefile_alltime = $cachedir . md5($page_alltime) . '.' . $cacheext;
  161. if (file_exists($cachefile_today)) { unlink($cachefile_today); }
  162. if (file_exists($cachefile_thisweek)) { unlink($cachefile_thisweek); }
  163. if (file_exists($cachefile_thismonth)) { unlink($cachefile_thismonth); }
  164. if (file_exists($cachefile_alltime)) { unlink($cachefile_alltime); }
  165. echo "Playlist Cache Successfully Cleared";
  166. exit;
  167. }
  168. /**
  169. * system cleanup
  170. */
  171. function clearTemplateCache()
  172. {
  173. global $smartyvs;
  174. $c = hwd_vs_Config::get_instance();
  175. $smartyvs->clear_compiled_tpl();
  176. $vs_temp_cache = JPATH_SITE.'/cache/hwdvs'.$c->hwdvids_template_file;
  177. $smartyvs->compile_dir = $vs_temp_cache;
  178. $smartyvs->clear_compiled_tpl();
  179. echo "Template Cache Successfully Cleared";
  180. exit;
  181. }
  182. /**
  183. * system cleanup
  184. */
  185. function regenerateThumbnails()
  186. {
  187. global $option;
  188. $db =& JFactory::getDBO();
  189. $app = & JFactory::getApplication();
  190. $db->SetQuery("UPDATE #__hwdvidsvideos SET approved = 're-generate_thumb' WHERE video_type IN ('local','mp4') AND approved = 'yes'");
  191. $db->Query();
  192. if ( !$db->query() ) {
  193. echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
  194. exit();
  195. }
  196. $app->enqueueMessage(_HWDVIDS_RUNCON);
  197. $app->redirect( JURI::root( true ) . '/administrator/index.php?option=com_hwdvideoshare&task=converter' );
  198. }
  199. /**
  200. * system cleanup
  201. */
  202. function recalculateDurations()
  203. {
  204. global $option;
  205. $db =& JFactory::getDBO();
  206. $app = & JFactory::getApplication();
  207. $db->SetQuery("UPDATE #__hwdvidsvideos SET approved = 're-calculate_duration' WHERE approved = 'yes'");
  208. $db->Query();
  209. if ( !$db->query() ) {
  210. echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
  211. exit();
  212. }
  213. $app->enqueueMessage(_HWDVIDS_RUNCON);
  214. $app->redirect( JURI::root( true ) . '/administrator/index.php?option=com_hwdvideoshare&task=converter' );
  215. }
  216. /**
  217. * system cleanup
  218. */
  219. function cancelThumbnailRegeneration()
  220. {
  221. global $option;
  222. $db =& JFactory::getDBO();
  223. $app = & JFactory::getApplication();
  224. $db->SetQuery("UPDATE #__hwdvidsvideos SET approved = 'yes' WHERE video_type IN ('local','mp4') AND approved = 're-generate_thumb'");
  225. $db->Query();
  226. if ( !$db->query() ) {
  227. echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
  228. exit();
  229. }
  230. $app->redirect( JURI::root( true ) . '/administrator/index.php?option=com_hwdvideoshare&task=converter' );
  231. }
  232. /**
  233. * system cleanup
  234. */
  235. function cancelDurationRecalculation()
  236. {
  237. global $option;
  238. $db =& JFactory::getDBO();
  239. $app = & JFactory::getApplication();
  240. $db->SetQuery("UPDATE #__hwdvidsvideos SET approved = 'yes' WHERE approved = 're-calculate_duration'");
  241. $db->Query();
  242. if ( !$db->query() ) {
  243. echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
  244. exit();
  245. }
  246. $app->redirect( JURI::root( true ) . '/administrator/index.php?option=com_hwdvideoshare&task=converter' );
  247. }
  248. /**
  249. * system cleanup
  250. */
  251. function ajax_ArchiveLogs()
  252. {
  253. global $smartyvs;
  254. $c = hwd_vs_Config::get_instance();
  255. // perform 'archivelogs' maintenance
  256. require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'maintenance_archivelogs.class.php');
  257. $archivelogs_report = hwd_vs_logs::initiate();
  258. $text = '<textarea cols="50" rows="4">';
  259. $text.= $archivelogs_report;
  260. $text.= '</textarea>';
  261. echo $text;
  262. // set archive cache variables
  263. $cachedir = JPATH_SITE.'/administrator/cache/'; // Directory to cache files in (keep outside web root)
  264. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  265. $page = 'http://archivefile'; // Requested page
  266. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  267. $archive_cache = (@file_exists($cachefile)) ? @date ("F d Y H:i:s.", filemtime($cachefile)) : "Never";
  268. exit;
  269. }
  270. /**
  271. * system cleanup
  272. */
  273. function ajax_WarpHdSync()
  274. {
  275. global $smartyvs;
  276. $db = & JFactory::getDBO();
  277. $c = hwd_vs_Config::get_instance();
  278. require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'warp'.DS.'infin-lib.php');
  279. $accountKey = $c->warpAccountKey;
  280. $secretKey = $c->warpSecretKey;
  281. $query = 'SELECT * FROM #__hwdvidsvideos WHERE video_type = "warphd"';
  282. $db->SetQuery($query);
  283. $rows = $db->loadObjectList();
  284. for ($i=0, $n=count($rows); $i < $n; $i++)
  285. {
  286. $row = $rows[$i];
  287. $infinVideo = new InfinovationVideo($accountKey, $secretKey);
  288. $videoInfo = $infinVideo->getVideoInfo($row->video_id);
  289. $duration = hwd_vs_tools::sec2hms($videoInfo->duration);
  290. $db->SetQuery("UPDATE #__hwdvidsvideos SET video_length = \"$duration\" WHERE id = $row->id");
  291. if ( !$db->query() )
  292. {
  293. echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
  294. exit();
  295. }
  296. }
  297. echo "Synchronised ".count($rows)." WarpHD videos";
  298. exit;
  299. }
  300. }
  301. ?>