예제 #1
0
   /**
	* Save editted video details
	*/
	function removeVideoFromPlaylist()
	  {
	    global $Itemid, $mainframe;
	    $db =& JFactory::getDBO();
	    $my = & JFactory::getUser();

	    $playlist_id  = JRequest::getInt( 'playlist_id', 0 );
	    $video_id  = JRequest::getInt( 'video_id', 0 );

		$row = new hwdvids_playlist($db);
		$row->load( $playlist_id );

		if ( $row->user_id !== $my->id )
		{
			$msg = "You do not have permission to remove videos from this playlist";
			$mainframe->enqueueMessage($msg);
			$mainframe->redirect( JURI::root( true ) . '/index.php?option=com_hwdvideoshare&task=editPlaylist&playlistid='.$playlist_id.'&Itemid='.$Itemid );
		}

		if (!empty($row->playlist_data))
		{
			$playlist = explode(",", $row->playlist_data);
			$playlist = preg_replace("/[^0-9]/", "", $playlist);

			$pl_videos = array();
			for ($i=0, $n=count($playlist); $i < $n; $i++)
			{
				if ($playlist[$i] !== $video_id)
				{
					$pl_videos[] = $playlist[$i];
				}
			}
		}

		$newData = implode(",", $pl_videos);

		$db->SetQuery("UPDATE #__hwdvidsplaylists SET playlist_data = \"$newData\" WHERE id = $playlist_id");
		if ( !$db->query() ) { echo "<script language=\"javascript\" type=\"text/javascript\"> alert('".addslashes($db->getErrorMsg())."'); window.history.go(-1); </script>\n"; exit(); }

		// perform maintenance
		require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'maintenance_recount.class.php');
		hwd_vs_recount::recountVideosInPlaylist($playlist_id);

		$row = new hwdvids_playlist($db);
		$row->load( $playlist_id );
		if (!empty($row->playlist_data))
		{
			$playlist = explode(",", $row->playlist_data);
			$playlist = preg_replace("/[^0-9]/", "", $playlist);

			$counter = 0;
			$pl_videos = array();
			for ($i=0, $n=count($playlist); $i < $n; $i++)
			{
				$db->SetQuery('SELECT * FROM #__hwdvidsvideos WHERE id = '.$playlist[$i]);
				$video = $db->loadObject();
				if (isset($video->id))
				{
					$pl_videos[$counter] = $video;
					$counter++;
				}
			}
		}

		require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'helpers'.DS.'draw.php');
		hwdvsDrawFile::XMLDataFile($pl_videos, "pl_$playlist_id");
		hwdvsDrawFile::XMLPlaylistFile($pl_videos, "pl_$playlist_id");

	    $msg = _HWDPS_ALERT_AREORGANISED;
	    $mainframe->enqueueMessage($msg);
		$mainframe->redirect( JURI::root( true ) . '/index.php?option=com_hwdvideoshare&task=editPlaylist&playlistid='.$playlist_id.'&Itemid='.$Itemid );
	}
예제 #2
0
    /**
     * Outputs frontpage HTML
     *
     * @return       Nothing
     */

    function addVideoToPlaylist()
	{
		header('Content-type: text/html; charset=utf-8');
		echo "<META NAME=\"ROBOTS\" CONTENT=\"NOINDEX, NOFOLLOW\">";

		$c = hwd_vs_Config::get_instance();
		$db = & JFactory::getDBO();
		$my = & JFactory::getUser();

		if (!$my->id) {
			echo _HWDVIDS_AJAX_LOG2ADD2PL;
			exit;
		}

		$user_id = $my->id;
		$videoid = JRequest::getInt( 'videoid', 0, 'request' );
		$playlistid = JRequest::getInt( 'playlistid', 0, 'request' );
		$date = date('Y-m-d H:i:s');
		$published = 1;

		if ($playlistid == 0) {
			echo _HWDVIDS_SELPL;
			exit;
		}

		$row = new hwdvids_playlist($db);
		$row->load( $playlistid );

		if (empty($row->playlist_data)) {
			$playlist_data = $videoid;
		} else {
			$playlist_data = $row->playlist_data.",".$videoid;
		}

		$_POST['id'] 	   			   = $playlistid;
		$_POST['playlist_data']        = $playlist_data;

		// bind it to the table
		if (!$row -> bind($_POST)) {
			echo "<script> alert('"
				.$row -> getError()
				."'); window.history.go(-1); </script>\n";
			exit();
		}

		// store it in the db
		if (!$row -> store()) {
			echo "<script> alert('"
				.$row -> getError()
				."'); window.history.go(-1); </script>\n";
			exit();
		}

		// perform maintenance
		require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'maintenance_recount.class.php');
		hwd_vs_recount::recountVideosInPlaylist($playlistid);

		$row = new hwdvids_playlist($db);
		$row->load( $playlistid );
		if (!empty($row->playlist_data))
		{
			$playlist = explode(",", $row->playlist_data);
			$playlist = preg_replace("/[^0-9]/", "", $playlist);

			$counter = 0;
			$pl_videos = array();
			for ($i=0, $n=count($playlist); $i < $n; $i++)
			{
				$db->SetQuery('SELECT * FROM #__hwdvidsvideos WHERE id = '.$playlist[$i]);
				$video = $db->loadObject();
				if (isset($video->id))
				{
					$pl_videos[$counter] = $video;
					$counter++;
				}
			}
		}

		require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'helpers'.DS.'draw.php');
		hwdvsDrawFile::XMLDataFile($pl_videos, "pl_$playlistid");
		hwdvsDrawFile::XMLPlaylistFile($pl_videos, "pl_$playlistid");

		echo _HWDVIDS_ALERT_SUCAV2PL;
		exit;
	}
예제 #3
0
    /**
     *
     */
    function checkCacheThenWrite()
    {
		$c = hwd_vs_Config::get_instance();
  		$db =& JFactory::getDBO();
		$my = & JFactory::getUser();

		require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'helpers'.DS.'draw.php');

		$cpl = JRequest::getCmd( 'cpl', null );
		if ($cpl == 1)
		{
			if (!empty($c->xmlcustom01))
			{
				$playlist = explode(",", $c->xmlcustom01);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom01 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT * FROM #__hwdvidsvideos WHERE id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom01[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom01, 'custom01');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom01, 'custom01');
			}
			return;
		}
		else if ($cpl == 2)
		{
			if (!empty($c->xmlcustom02))
			{
				$playlist = explode(",", $c->xmlcustom02);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom02 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT * FROM #__hwdvidsvideos WHERE id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom02[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom02, 'custom02');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom02, 'custom02');
			}
			return;
		}
		else if ($cpl == 3)
		{
			if (!empty($c->xmlcustom03))
			{
				$playlist = explode(",", $c->xmlcustom03);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom03 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT * FROM #__hwdvidsvideos WHERE id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom03[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom03, 'custom03');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom03, 'custom03');
			}
			return;
		}
		else if ($cpl == 4)
		{
			if (!empty($c->xmlcustom04))
			{
				$playlist = explode(",", $c->xmlcustom04);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom04 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT * FROM #__hwdvidsvideos WHERE id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom04[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom04, 'custom04');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom04, 'custom04');
			}
			return;
		}
		else if ($cpl == 5)
		{
			if (!empty($c->xmlcustom05))
			{
				$playlist = explode(",", $c->xmlcustom05);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom05 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT * FROM #__hwdvidsvideos WHERE id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom05[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom05, 'custom05');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom05, 'custom05');
			}
			return;
		}

		// set cache variables
		$cachedir = JPATH_SITE.'/cache/'; // Directory to cache files in (keep outside web root)
		$cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)

		/**
		 * Generate Today's Playlists
		 */
		$cachetime = $c->xmlcache_today; // Seconds to cache files for
		$page = 'http://xmlplaylists_today'; // Requested page
		$cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
		$cachefile_created = (@file_exists($cachefile)) ? @filemtime($cachefile) : 0;
		@clearstatcache();

		// Show file from cache if still valid
		if (time() - $cachetime < $cachefile_created)
		{
			echo "Already cached today's playlists... aborting<br />";
		}
		else
		{
			 // Now the script has run, generate a new cache file
			$fp = fopen($cachefile, 'w');

			// save the contents of output buffer to the file
			@fwrite($fp, ob_get_contents());
			@fclose($fp);

			$join     = ' LEFT JOIN #__users ON #__users.id = #__hwdvidsvideos.user_id';
			if ($c->userdisplay == 1)
			{
				$select   = '#__users.username,';
				$select_f = '#__users.username,';
			}
			else
			{
				$select   = '#__users.name,';
				$select_f = '#__users.name,';
			}
			if ($c->cbint == "2")
			{
				$join.= ' LEFT JOIN #__community_users ON #__community_users.userid = #__hwdvidsvideos.user_id';
				$select  .= ' #__community_users.*,';
				$select_f.= ' #__community_users.*';
			}
			else if ($c->cbint == "1")
			{
				$join.= ' LEFT JOIN #__comprofiler ON #__comprofiler.user_id = #__hwdvidsvideos.user_id';
				$select  .= ' #__comprofiler.avatar,';
				$select_f.= ' #__comprofiler.avatar';
			}
			else
			{
				if ($c->userdisplay == 1)
				{
					$select_f = '#__users.username';
				}
				else
				{
					$select_f = '#__users.name';
				}
			}

			// query SQL for today's data
			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' COUNT(#__hwdvidslogs_views.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_views ON #__hwdvidsvideos.id = #__hwdvidslogs_views.videoid '.$join.' WHERE #__hwdvidslogs_views.date >= DATE_SUB(NOW(),INTERVAL 1 DAY) AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY counts DESC LIMIT 0, 10');
			$rowsmostviewed_today = $db->loadObjectList();
			if (count($rowsmostviewed_today) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostviewed_today, 'mostviewed_today');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostviewed_today, 'mostviewed_today');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' COUNT(#__hwdvidslogs_favours.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_favours ON #__hwdvidsvideos.id = #__hwdvidslogs_favours.videoid '.$join.' WHERE #__hwdvidslogs_favours.date >= DATE_SUB(NOW(),INTERVAL 1 DAY) AND favour = 1 AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY counts DESC LIMIT 0, 10');
			$rowsmostfavoured_today = $db->loadObjectList();
			if (count($rowsmostfavoured_today) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostfavoured_today, 'mostfavoured_today');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostfavoured_today, 'mostfavoured_today');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' SUM(#__hwdvidslogs_votes.vote)/COUNT(#__hwdvidslogs_votes.videoid) AS sums, COUNT(#__hwdvidslogs_votes.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_votes ON #__hwdvidsvideos.id = #__hwdvidslogs_votes.videoid '.$join.' WHERE #__hwdvidslogs_votes.date >= DATE_SUB(NOW(),INTERVAL 1 DAY) AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY sums DESC LIMIT 0, 10');
			$rowsmostpopular_today = $db->loadObjectList();
			if (count($rowsmostpopular_today) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostpopular_today, 'mostpopular_today');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostpopular_today, 'mostpopular_today');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 AND #__hwdvidsvideos.featured = 1 ORDER BY #__hwdvidsvideos.ordering ASC LIMIT 0, 25');
			$rows_featured = $db->loadObjectList();
			hwdvsDrawFile::XMLDataFile($rows_featured, 'featured');
			hwdvsDrawFile::XMLPlaylistFile($rows_featured, 'featured');

			$db->SetQuery('SELECT DISTINCT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' LEFT JOIN #__hwdvidslogs_views ON #__hwdvidslogs_views.videoid = #__hwdvidsvideos.id WHERE #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 AND #__hwdvidslogs_views.date > NOW() - INTERVAL 1440 MINUTE ORDER BY #__hwdvidslogs_views.date DESC LIMIT 0, 10');
			$rows_bwn = $db->loadObjectList();
			hwdvsDrawFile::XMLDataFile($rows_bwn, 'bwn');
			hwdvsDrawFile::XMLPlaylistFile($rows_bwn, 'bwn');

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 ORDER BY #__hwdvidsvideos.date_uploaded ASC LIMIT 0, 10');
			$rows_recent = $db->loadObjectList();
			hwdvsDrawFile::XMLDataFile($rows_recent, 'recent');
			hwdvsDrawFile::XMLPlaylistFile($rows_recent, 'recent');
		}

		/**
		 * Generate This Weeks's Playlists
		 */
		$cachetime = $c->xmlcache_thisweek; // Seconds to cache files for
		$page = 'http://xmlplaylists_thisweek'; // Requested page
		$cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
		$cachefile_created = (@file_exists($cachefile)) ? @filemtime($cachefile) : 0;
		@clearstatcache();

		// Show file from cache if still valid
		if (time() - $cachetime < $cachefile_created)
		{
			echo "Already cached this week's playlists... aborting<br />";
		}
		else
		{
			 // Now the script has run, generate a new cache file
			$fp = @fopen($cachefile, 'w');

			// save the contents of output buffer to the file
			@fwrite($fp, ob_get_contents());
			@fclose($fp);

			// sql search filters
			$where = ' WHERE published = 1';
			$where .= ' AND approved = "yes"';

			$join = ' LEFT JOIN #__users ON #__users.id = #__hwdvidsvideos.user_id';
			if ($c->userdisplay == 1) {
				$select   = '#__users.username,';
				$select_f = '#__users.username,';
			} else {
				$select   = '#__users.name,';
				$select_f = '#__users.name,';
			}
			if ($c->cbint == "2") {
				$join.= ' LEFT JOIN #__community_users ON #__community_users.userid = #__hwdvidsvideos.user_id';
				$select  .= ' #__community_users.*,';
				$select_f.= ' #__community_users.*';
			} else if ($c->cbint == "1") {
				$join.= ' LEFT JOIN #__comprofiler ON #__comprofiler.user_id = #__hwdvidsvideos.user_id';
				$select  .= ' #__comprofiler.avatar,';
				$select_f.= ' #__comprofiler.avatar';
			} else {
				if ($c->userdisplay == 1) {
					$select_f = '#__users.username';
				} else {
					$select_f = '#__users.name';
				}
			}

			// query SQL for this week's data
			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' COUNT(#__hwdvidslogs_views.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_views ON #__hwdvidsvideos.id = #__hwdvidslogs_views.videoid '.$join.' WHERE #__hwdvidslogs_views.date >= DATE_SUB(NOW(),INTERVAL 7 DAY) AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY counts DESC LIMIT 0, 10');
			$rowsmostviewed_thisweek = $db->loadObjectList();
			if (count($rowsmostviewed_thisweek) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostviewed_thisweek, 'mostviewed_thisweek');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostviewed_thisweek, 'mostviewed_thisweek');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' COUNT(#__hwdvidslogs_favours.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_favours ON #__hwdvidsvideos.id = #__hwdvidslogs_favours.videoid '.$join.' WHERE #__hwdvidslogs_favours.date >= DATE_SUB(NOW(),INTERVAL 7 DAY) AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY counts DESC LIMIT 0, 10');
			$rowsmostfavoured_thisweek = $db->loadObjectList();
			if (count($rowsmostfavoured_thisweek) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostfavoured_thisweek, 'mostfavoured_thisweek');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostfavoured_thisweek, 'mostfavoured_thisweek');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' SUM(#__hwdvidslogs_votes.vote)/COUNT(#__hwdvidslogs_votes.videoid) AS sums, COUNT(#__hwdvidslogs_votes.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_votes ON #__hwdvidsvideos.id = #__hwdvidslogs_votes.videoid '.$join.' WHERE #__hwdvidslogs_votes.date >= DATE_SUB(NOW(),INTERVAL 7 DAY) AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY sums DESC LIMIT 0, 10');
			$rowsmostpopular_thisweek = $db->loadObjectList();
			if (count($rowsmostfavoured_thisweek) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostpopular_thisweek, 'mostpopular_thisweek');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostpopular_thisweek, 'mostpopular_thisweek');
			}

			if (!empty($c->xmlcustom01))
			{
				$playlist = explode(",", $c->xmlcustom01);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom01 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom01[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom01, 'custom01');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom01, 'custom01');
			}

			if (!empty($c->xmlcustom02))
			{
				$playlist = explode(",", $c->xmlcustom02);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom02 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom02[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom02, 'custom02');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom02, 'custom02');
			}

			if (!empty($c->xmlcustom03))
			{
				$playlist = explode(",", $c->xmlcustom03);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom03 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom03[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom03, 'custom03');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom03, 'custom03');
			}

			if (!empty($c->xmlcustom04))
			{
				$playlist = explode(",", $c->xmlcustom04);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom04 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom04[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom04, 'custom04');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom04, 'custom04');
			}

			if (!empty($c->xmlcustom05))
			{
				$playlist = explode(",", $c->xmlcustom05);
				$playlist = preg_replace("/[^0-9]/", "", $playlist);

				$counter = 0;
				$rows_custom05 = array();
				for ($i=0, $n=count($playlist); $i < $n; $i++)
				{
					$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.id = '.$playlist[$i]);
					$row = $db->loadObject();
					if (isset($row->id))
					{
						$rows_custom05[$counter] = $row;
						$counter++;
					}
				}

				hwdvsDrawFile::XMLDataFile($rows_custom05, 'custom05');
				hwdvsDrawFile::XMLPlaylistFile($rows_custom05, 'custom05');
			}
		}

		/**
		 * Generate This Month's Playlists
		 */
		$cachetime = $c->xmlcache_thismonth; // Seconds to cache files for
		$page = 'http://xmlplaylists_thismonth'; // Requested page
		$cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
		$cachefile_created = (@file_exists($cachefile)) ? @filemtime($cachefile) : 0;
		@clearstatcache();

		// Show file from cache if still valid
		if (time() - $cachetime < $cachefile_created)
		{
			echo "Already cached this months's playlists... aborting<br />";
		}
		else
		{
			 // Now the script has run, generate a new cache file
			$fp = @fopen($cachefile, 'w');

			// save the contents of output buffer to the file
			@fwrite($fp, ob_get_contents());
			@fclose($fp);

			$join = ' LEFT JOIN #__users ON #__users.id = #__hwdvidsvideos.user_id';
			if ($c->userdisplay == 1)
			{
				$select = '#__users.username,';
			}
			else
			{
				$select = '#__users.name,';
			}
			if ($c->cbint == "2")
			{
				$join.= ' LEFT JOIN #__community_users ON #__community_users.userid = #__hwdvidsvideos.user_id';
				$select.= ' #__community_users.*,';
			}
			else if ($c->cbint == "1")
			{
				$join.= ' LEFT JOIN #__comprofiler ON #__comprofiler.user_id = #__hwdvidsvideos.user_id';
				$select.= ' #__comprofiler.avatar,';
			}

			// sql search filters
			$where = ' WHERE published = 1';
			$where .= ' AND approved = "yes"';

			// query SQL for this month's data
			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' COUNT(#__hwdvidslogs_views.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_views ON #__hwdvidsvideos.id = #__hwdvidslogs_views.videoid '.$join.' WHERE #__hwdvidslogs_views.date >= DATE_SUB(NOW(),INTERVAL 30 DAY) AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY counts DESC LIMIT 0, 10');
			$rowsmostviewed_thismonth = $db->loadObjectList();
			if (count($rowsmostviewed_thismonth) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostviewed_thismonth, 'mostviewed_thismonth');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostviewed_thismonth, 'mostviewed_thismonth');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' COUNT(#__hwdvidslogs_favours.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_favours ON #__hwdvidsvideos.id = #__hwdvidslogs_favours.videoid '.$join.' WHERE #__hwdvidslogs_favours.date >= DATE_SUB(NOW(),INTERVAL 30 DAY) AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY counts DESC LIMIT 0, 10');
			$rowsmostfavoured_thismonth = $db->loadObjectList();
			if (count($rowsmostfavoured_thismonth) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostfavoured_thismonth, 'mostfavoured_thismonth');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostfavoured_thismonth, 'mostfavoured_thismonth');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' SUM(#__hwdvidslogs_votes.vote)/COUNT(#__hwdvidslogs_votes.videoid) AS sums, COUNT(#__hwdvidslogs_votes.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidslogs_votes ON #__hwdvidsvideos.id = #__hwdvidslogs_votes.videoid '.$join.' WHERE #__hwdvidslogs_votes.date >= DATE_SUB(NOW(),INTERVAL 30 DAY) AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY sums DESC LIMIT 0, 10');
			$rowsmostpopular_thismonth = $db->loadObjectList();
			if (count($rowsmostpopular_thismonth) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostpopular_thismonth, 'mostpopular_thismonth');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostpopular_thismonth, 'mostpopular_thismonth');
			}

		}

		/**
		 * Generate All Time Playlists
		 */
		$cachetime = $c->xmlcache_thismonth; // Seconds to cache files for
		$page = 'http://xmlplaylists_alltime'; // Requested page
		$cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create
		$cachefile_created = (@file_exists($cachefile)) ? @filemtime($cachefile) : 0;
		@clearstatcache();

		// Show file from cache if still valid
		if (time() - $cachetime < $cachefile_created)
		{
			echo "Already cached full playlists... aborting<br />";
		}
		else
		{
			 // Now the script has run, generate a new cache file
			$fp = @fopen($cachefile, 'w');

			// save the contents of output buffer to the file
			@fwrite($fp, ob_get_contents());
			@fclose($fp);

			// sql search filters
			$where = ' WHERE published = 1';
			$where .= ' AND approved = "yes"';

			$join     = ' LEFT JOIN #__users ON #__users.id = #__hwdvidsvideos.user_id';
			if ($c->userdisplay == 1)
			{
				$select   = '#__users.username,';
				$select_f = '#__users.username,';
			}
			else
			{
				$select   = '#__users.name,';
				$select_f = '#__users.name,';
			}
			if ($c->cbint == "2")
			{
				$join.= ' LEFT JOIN #__community_users ON #__community_users.userid = #__hwdvidsvideos.user_id';
				$select  .= ' #__community_users.*,';
				$select_f.= ' #__community_users.*';
			}
			else if ($c->cbint == "1")
			{
				$join.= ' LEFT JOIN #__comprofiler ON #__comprofiler.user_id = #__hwdvidsvideos.user_id';
				$select  .= ' #__comprofiler.avatar,';
				$select_f.= ' #__comprofiler.avatar';
			}
			else
			{
				if ($c->userdisplay == 1)
				{
					$select_f = '#__users.username';
				}
				else
				{
					$select_f = '#__users.name';
				}
			}

			// query SQL for all data
			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 ORDER BY #__hwdvidsvideos.number_of_views DESC LIMIT 0, 10');
			$rowsmostviewed_alltime = $db->loadObjectList();
			if (count($rowsmostviewed_alltime) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostviewed_alltime, 'mostviewed_alltime');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostviewed_alltime, 'mostviewed_alltime');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select.' COUNT(#__hwdvidsfavorites.videoid) AS counts FROM #__hwdvidsvideos LEFT JOIN #__hwdvidsfavorites ON #__hwdvidsvideos.id = #__hwdvidsfavorites.videoid '.$join.' WHERE #__hwdvidsfavorites.videoid IS NOT NULL AND #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 GROUP BY #__hwdvidsvideos.id ORDER BY counts DESC LIMIT 0, 10');
			$rowsmostfavoured_alltime = $db->loadObjectList();
			if (count($rowsmostfavoured_alltime) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostfavoured_alltime, 'mostfavoured_alltime');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostfavoured_alltime, 'mostfavoured_alltime');
			}

			$db->SetQuery('SELECT #__hwdvidsvideos.*, '.$select_f.' FROM #__hwdvidsvideos '.$join.' WHERE #__hwdvidsvideos.approved = "yes" AND #__hwdvidsvideos.published = 1 ORDER BY #__hwdvidsvideos.updated_rating DESC LIMIT 0, 10');
			$rowsmostpopular_alltime = $db->loadObjectList();
			if (count($rowsmostpopular_alltime) > 0) {
				hwdvsDrawFile::XMLDataFile($rowsmostpopular_alltime, 'mostpopular_alltime');
				hwdvsDrawFile::XMLPlaylistFile($rowsmostpopular_alltime, 'mostpopular_alltime');
			}

		}
		return;
	}