PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_hwdvideoshare/libraries/maintenance_fixerrors.class.php

https://github.com/Shigaru/shigaru
PHP | 153 lines | 72 code | 20 blank | 61 comment | 12 complexity | 9c489755d64fe47861de939de3e93ea0 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. if (!defined('HWDVS_ADMIN_PATH')) { define('HWDVS_ADMIN_PATH', dirname(__FILE__).'/../'); }
  23. /**
  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.4 Alpha RC3.5
  29. */
  30. class hwd_vs_fixerrors {
  31. /**
  32. * Outputs frontpage HTML
  33. *
  34. * @param string $option the joomla component name
  35. * @param array $rows array of video data
  36. * @param array $rowsfeatured array of featured video data
  37. * @param object $pageNav page navigation object
  38. * @param int $total the total video count
  39. * @return Nothing
  40. */
  41. function initiate($override) {
  42. $app = & JFactory::getApplication();
  43. // set cache variables
  44. $cachedir = JPATH_SITE.'/administrator/cache/'; // Directory to cache files in (keep outside web root)
  45. $cachetime = 86400; // Seconds to cache files for
  46. $cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
  47. $page = 'http://fixerrorfile'; // Requested page
  48. $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
  49. $cachefile_created = (@file_exists($cachefile)) ? @filemtime($cachefile) : 0;
  50. @clearstatcache();
  51. if ($override == 2) {
  52. // Show file from cache if still valid
  53. if (time() - $cachetime < $cachefile_created) {
  54. $app->enqueueMessage(_HWDVIDS_M_FIX_RUN);
  55. return;
  56. }
  57. }
  58. // Now the script has run, generate a new cache file
  59. $fp = @fopen($cachefile, 'w');
  60. // save the contents of output buffer to the file
  61. @fwrite($fp, ob_get_contents());
  62. @fclose($fp);
  63. hwd_vs_fixerrors::fixVideoDataFormat();
  64. hwd_vs_fixerrors::cleanAntileech();
  65. return true;
  66. }
  67. /**
  68. * Outputs frontpage HTML
  69. *
  70. * @param string $option the joomla component name
  71. * @param array $rows array of video data
  72. * @param array $rowsfeatured array of featured video data
  73. * @param object $pageNav page navigation object
  74. * @param int $total the total video count
  75. * @return Nothing
  76. */
  77. function fixVideoDataFormat($videoid=null) {
  78. $db = & JFactory::getDBO();
  79. if (isset($videoid)) {
  80. $query = 'SELECT id, title, description, tags'
  81. . ' FROM #__hwdvidsvideos'
  82. . ' WHERE id = '.$videoid
  83. ;
  84. $db->SetQuery($query);
  85. $rows = $db->loadObjectList();
  86. } else {
  87. $query = 'SELECT *'
  88. . ' FROM #__hwdvidsvideos'
  89. ;
  90. $db->SetQuery($query);
  91. $rows = $db->loadObjectList();
  92. }
  93. for ($i=0, $n=count($rows); $i < $n; $i++) {
  94. $row = $rows[$i];
  95. $title = hwd_vs_tools::generatePostTitle($row->title);
  96. $description = hwd_vs_tools::generatePostDescription($row->description);
  97. $tags = hwd_vs_tools::generatePostTags($row->tags);
  98. $thumb_snap = $row->thumb_snap;
  99. if ($row->thumb_snap == "0:00:00") {
  100. $sec = intval(hwd_vs_tools::hms2sec($row->video_length));
  101. if ($sec < 2) {
  102. $thumb_snap = "0:00:02";
  103. } else {
  104. $thumb_snap = hwd_vs_tools::sec2hms($sec/2);
  105. }
  106. }
  107. // update sql
  108. $db->SetQuery("UPDATE #__hwdvidsvideos SET title = \"$title\", description = \"$description\", tags = \"$tags\", thumb_snap = \"$thumb_snap\" WHERE id = $row->id");
  109. $db->Query();
  110. if ( !$db->query() ) {
  111. echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
  112. exit();
  113. }
  114. }
  115. return true;
  116. }
  117. /**
  118. * Outputs frontpage HTML
  119. *
  120. * @param string $option the joomla component name
  121. * @param array $rows array of video data
  122. * @param array $rowsfeatured array of featured video data
  123. * @param object $pageNav page navigation object
  124. * @param int $total the total video count
  125. * @return Nothing
  126. */
  127. function cleanAntileech() {
  128. $db = & JFactory::getDBO();
  129. $db->SetQuery('TRUNCATE #__hwdvidsantileech');
  130. $db->query();
  131. return true;
  132. }
  133. }