Exemplo n.º 1
0
	/**
	* Import Data
	*/
	function seyretImport()
	{
		global $Itemid, $option;
		$db = & JFactory::getDBO();
		$app = & JFactory::getApplication();

		$seyretcid = JRequest::getInt( 'seyretcid', -1 );
		$category_id = JRequest::getInt( 'category_id', 0 );
		$counter = 0;

		$db->SetQuery( 'SELECT count(*) FROM #__seyret_items' );
		$seyret_old = $db->loadResult();

		$db->SetQuery( 'SELECT count(*) FROM #__seyret_video' );
		$seyret_new = $db->loadResult();

		if ($seyret_old > 1)
		{
			if (!empty($seyretcid) && ($seyretcid !== -1))
			{
				$where = " WHERE `catid` LIKE '%*".$seyretcid."*#%'";
			}
			else
			{
				$where = "";
			}

			// import categories
			$db->setQuery( "SELECT * FROM #__seyret_items".$where );
			if ( !$db->query() )
			{
				echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
				exit();
			}
			$rows_seyret = $db->loadObjectList();

			for ($i=0, $n=count($rows_seyret); $i < $n; $i++)
			{
				$row_seyret = $rows_seyret[$i];

				$row = new hwdvids_video($db);

				if ($row_seyret->videoservertype == "localfile")
				{
					$_POST['video_id'] 	    = "local,".$row_seyret->videoservercode.",".$row_seyret->picturelink;
				}
				else if ($row_seyret->videoservertype == "youtube")
				{
					$thumbnail = "http://img.youtube.com/vi/".$row_seyret->videoservercode."/default.jpg";
					$_POST['video_id'] 	    = "youtube.com,".$row_seyret->videoservercode.",".$thumbnail;
				}
				else if ($row_seyret->videoservertype == "dailymotion")
				{
					if (file_exists(JPATH_SITE.'/plugins/hwdvs-thirdparty/dailymotion.com.php'))
					{
						require_once(JPATH_SITE.'/plugins/hwdvs-thirdparty/dailymotion.com.php');
						$url = hwd_vs_tools::get_final_url( $row_seyret->videourl );
						$pos_http = strpos($url, "http");
						if ($pos_http === false)
						{
							$url = 'http://www.dailymotion.com'.$url;
						}
						$tp = new hwd_vs_tp_dailymotionCom();
						$result  = $tp->dailymotionComProcessCode($url);
						$video_code  = $result[1];
					}
					else
					{
						continue;
					}

					$_POST['video_id'] 	    = 'dailymotion.com,'.$video_code;
				}
				else if ($row_seyret->videoservertype == "blip.tv") {

					if (file_exists(JPATH_SITE.'/plugins/hwdvs-thirdparty/blip.tv.php')) {
						require_once(JPATH_SITE.'/plugins/hwdvs-thirdparty/blip.tv.php');
						$url = hwd_vs_tools::get_final_url( $row_seyret->videourl );
						$pos_http = strpos($url, "http");
						if ($pos_http === false) {
							$url = 'http://blip.tv'.$url;
						}
						$tp = new hwd_vs_tp_blipTv();
						$result  = $tp->blipTvProcessCode($row_seyret->videourl);
						$video_code  = $result[1];
					} else {
						continue;
					}

					$_POST['video_id'] 	    = 'blip.tv,'.$video_code;


				} else if ($row_seyret->videoservertype == "google") {

					if (file_exists(JPATH_SITE.'/plugins/hwdvs-thirdparty/google.php')) {
						require_once(JPATH_SITE.'/plugins/hwdvs-thirdparty/google.php');
						$url = hwd_vs_tools::get_final_url( $row_seyret->videourl );
						$pos_http = strpos($url, "http");
						if ($pos_http === false) {
							$url = 'http://video.google.com'.$url;
						}
						$tp = new hwd_vs_tp_googleCom();
						$result  = $tp->googleComProcessCode($row_seyret->videourl);
						$video_code  = $result[1];
					} else {
						continue;
					}

					$_POST['video_id'] 	    = 'google.com,'.$video_code;

				} else if ($row_seyret->videoservertype == "vimeo.com") {

					if (file_exists(JPATH_SITE.'/plugins/hwdvs-thirdparty/vimeo.com.php')) {
						require_once(JPATH_SITE.'/plugins/hwdvs-thirdparty/vimeo.com.php');
						$url = hwd_vs_tools::get_final_url( $row_seyret->videourl );
						$pos_http = strpos($url, "http");
						if ($pos_http === false) {
							$url = 'http://vimeo.com'.$url;
						}
						$tp = new hwd_vs_tp_vimeoCom();
						$result  = $tp->vimeoComProcessCode($row_seyret->videourl);
						$video_code  = $result[1];
					} else {
						continue;
					}

					$_POST['video_id'] 	    = 'vimeo.com,'.$video_code;

				} else {
					continue;
				}

				if (empty($row_seyret->playtime)) { $row_seyret->playtime = "00:00"; }

				$_POST['video_type']        = "seyret";
				$_POST['title'] 			= $row_seyret->title;
				$_POST['description'] 		= $row_seyret->itemcomment;
				$_POST['category_id'] 		= $category_id;
				$_POST['tags'] 				= $row_seyret->videotags;
				$_POST['public_private'] 	= "public";
				$_POST['allow_comments'] 	= 1;
				$_POST['allow_embedding'] 	= 1;
				$_POST['allow_ratings'] 	= 1;
				$_POST['video_length'] 		= $row_seyret->playtime;
				$_POST['date_uploaded'] 	= $row_seyret->addeddate;
				$_POST['approved'] 			= "yes";
				$_POST['number_of_views'] 	= $row_seyret->hit;
				$_POST['user_id'] 			= $row_seyret->addedby;
				$_POST['published'] 		= $row_seyret->published;

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

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

				$counter++;

				// fix for view archive
				if ($row_seyret->hit > 0) {
					$views = new hwdvidslogs_archive($db);

					$_POST['videoid']           = $row->id;
					$_POST['views'] 			= $row->number_of_views;

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

					// store it in the db
					if (!$views->store()) {
						echo "<script> alert('".$views -> getError()."'); window.history.go(-1); </script>\n";
						exit();
					}
				}
			}
		}
		else
		{
			if (!empty($seyretcid) && ($seyretcid !== -1))
			{
				$where = " WHERE `parentcat` LIKE '%*".$seyretcid."*#%'";
			}
			else
			{
				$where = "";
			}

			// import categories
			$db->setQuery( "SELECT * FROM #__seyret_video".$where );
			if ( !$db->query() )
			{
				echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
				exit();
			}
			$rows_seyret = $db->loadObjectList();

			for ($i=0, $n=count($rows_seyret); $i < $n; $i++)
			{
				$row_seyret = $rows_seyret[$i];

				$row = new hwdvids_video($db);

				if ($row_seyret->videoservertype == "localfile")
				{
					continue;
					$_POST['video_id'] 	    = "local,".$row_seyret->videoservercode.",".$row_seyret->picturelink;
				}
				else if ($row_seyret->videoservertype == "youtube")
				{
					if (file_exists(JPATH_SITE.'/plugins/hwdvs-thirdparty/youtube.php'))
					{
						require_once(JPATH_SITE.'/plugins/hwdvs-thirdparty/youtube.php');
						$url = $row_seyret->videourl;
						$tp = new hwd_vs_tp_YoutubeCom();
						$result  = $tp->YoutubeComProcessCode($url);
						$video_code  = $result[1];
						$video_thumbnail  = $tp->YoutubeComGetThumbnail($result);
					}
					else
					{
						continue;
					}

					$_POST['video_id'] 	    = "youtube.com,$video_code,$video_thumbnail";
				}
				else
				{
					continue;
				}

				if (empty($row_seyret->duration)) { $row_seyret->duration = "00:00"; }

				$_POST['video_type']        = "seyret";
				$_POST['title'] 			= $row_seyret->videotitle;
				$_POST['description'] 		= $row_seyret->videodescription;
				$_POST['category_id'] 		= $category_id;
				$_POST['tags'] 				= $row_seyret->videotags;
				$_POST['public_private'] 	= "public";
				$_POST['allow_comments'] 	= 1;
				$_POST['allow_embedding'] 	= 1;
				$_POST['allow_ratings'] 	= 1;
				$_POST['video_length'] 		= $row_seyret->duration;
				$_POST['date_uploaded'] 	= $row_seyret->addeddate;
				$_POST['approved'] 			= "yes";
				$_POST['number_of_views'] 	= $row_seyret->hit;
				$_POST['user_id'] 			= $row_seyret->addedby;
				$_POST['published'] 		= $row_seyret->published;

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

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

				$counter++;

				// fix for view archive
				if ($row_seyret->hit > 0)
				{
					$views = new hwdvidslogs_archive($db);

					$_POST['videoid']           = $row->id;
					$_POST['views'] 			= $row->number_of_views;

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

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

		$msg = "Successully imported ".$counter." videos";
		$app->enqueueMessage($msg);
		$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=import' );
	}
    /**
     * Outputs frontpage HTML
     *
     * @param string $option  the joomla component name
     * @param array  $rows  array of video data
     * @param array  $rowsfeatured  array of featured video data
     * @param object $pageNav  page navigation object
     * @param int    $total  the total video count
     * @return       Nothing
     */
	function archiveVotes()
	{
		$db = & JFactory::getDBO();

		$db->SetQuery("SELECT count(*) FROM #__hwdvidslogs_votes WHERE date <= DATE_SUB(NOW(),INTERVAL 30 DAY)");
		$count = $db->loadResult();
		$text = $count." vote logs need to be archived\n";
		if ( $count == 0 ) { return $text; }

		$db->SetQuery("SELECT * FROM #__hwdvidslogs_votes WHERE date <= DATE_SUB(NOW(),INTERVAL 30 DAY) LIMIT 0, 1000");
		$rows = $db->loadObjectList();

		if (count($rows) > 0)
		{
			for ($i=0, $n=count($rows); $i < $n; $i++)
			{
				$row = $rows[$i];

				$db->SetQuery("SELECT count(*) FROM #__hwdvidslogs_archive WHERE videoid = ".$row->videoid);
				$total = $db->loadResult();

				if ($total > 0)
				{
					$db->SetQuery("SELECT number_of_votes, sum_of_votes FROM #__hwdvidslogs_archive WHERE videoid = ".$row->videoid);
					$data = $db->loadObject();
					$number_of_votes = $data->number_of_votes + 1;
					$sum_of_votes    = $data->sum_of_votes    + $row->vote;
					$rating          = $sum_of_votes/$number_of_votes;

					$db->SetQuery("UPDATE #__hwdvidslogs_archive SET number_of_votes=".$number_of_votes.", sum_of_votes=".$sum_of_votes.", rating=".$rating." WHERE videoid = $row->videoid");
					if ( !$db->query() )
					{
						echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
						exit();
					}
				}
				else
				{
					$row_new = new hwdvidslogs_archive($db);

					$_POST['videoid'] 			= $row->videoid;
					$_POST['number_of_votes'] 	= 1;
					$_POST['sum_of_votes'] 		= $row->vote;
					$_POST['rating'] 			= $row->vote;

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

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

				$db->SetQuery("DELETE FROM #__hwdvidslogs_votes WHERE id = ".$row->id." AND date <= DATE_SUB(NOW(),INTERVAL 30 DAY)" );
				if ( !$db->query() )
				{
					echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
					exit();
				}
			}
		}

		$text = "Successfully archived ".count($rows)." votes\n";

		$db->SetQuery("SELECT count(*) FROM #__hwdvidslogs_votes WHERE date <= DATE_SUB(NOW(),INTERVAL 30 DAY)");
		$count = $db->loadResult();
		$text.= $count." vote logs need to be archived\n";

		return $text;
    }
Exemplo n.º 3
0
   /**
	* save videos
	*/
	function savevideo()
	{
		global $option, $task;
		$app = & JFactory::getApplication();

		$db = & JFactory::getDBO();
		$row = new hwdvids_video($db);

		$requestarray = JRequest::get( 'default', 2 );
		$rawDescription = trim($requestarray['description']);

		$id 				= Jrequest::getInt( 'id', '' );
		$title 				= hwd_vs_tools::generatePostTitle();
		$description 		= hwd_vs_tools::generatePostDescription($rawDescription);
		$tags 				= hwd_vs_tools::generatePostTags();
		$views 				= Jrequest::getInt( 'views', '' );

		if (!empty($views))
		{
			$db->SetQuery("SELECT count(*) FROM #__hwdvidslogs_views WHERE videoid = ".$id);
			$unarchived_count = $db->loadResult();
			$archived_count = $views - $unarchived_count;

			$db->SetQuery("SELECT count(*) FROM #__hwdvidslogs_archive WHERE videoid = ".$id);
			$total = $db->loadResult();

			if ($total > 0)
			{
				$db->SetQuery("UPDATE #__hwdvidslogs_archive SET views = $archived_count WHERE videoid = ".$id);
				if ( !$db->query() )
				{
					echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
					exit();
				}
			}
			else
			{
				$row_new = new hwdvidslogs_archive($db);

				$_POST['id'] 			= null;
				$_POST['videoid'] 		= $id;
				$_POST['views'] 		= $archived_count;

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

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

				$_POST['id'] 			= $id;
			}
		}

		$password = Jrequest::getVar( 'hwdvspassword', '' );
		if (!empty($password))
		{
			$password = md5($password);
			$_POST['password'] 		= $password;
		}

		if ($_POST['public_private'] == "group")
		{
			$gtree_video = Jrequest::getVar( 'gtree_video', '' );
			if (!empty($gtree_video))
			{
				$_POST['password'] 		= $gtree_video;
			}
		}

		if ($_POST['public_private'] == "level")
		{
			$jacl_video = Jrequest::getVar( 'jacl_video', '' );
			if (!empty($jacl_video))
			{
				if (isset($jacl_video) && $jacl_video !== '') { $jacl_video = @implode(",", $jacl_video); }
				$_POST['password'] 		= $jacl_video;
			}
		}

		$_POST['title'] 			= $title;
		$_POST['description'] 		= $description;
		$_POST['tags'] 				= $tags;
		$_POST['category_id'] 		= JRequest::getInt( 'category_id', 0 );

		// 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();
		}

		$row->checkin();

		include(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'maintenance_recount.class.php');
		hwd_vs_recount::recountVideosInCategory($row->category_id);

		if ($task == "apply")
		{
			$app->enqueueMessage(_HWDVIDS_ALERT_VIDSAVED);
			$app->redirect( JURI::root( true ) . '/administrator/index.php?option=com_hwdvideoshare&task=editvidsA&hidemainmenu=1&cid='.$row->id );
		}
		else
		{
			$app->enqueueMessage(_HWDVIDS_ALERT_VIDSAVED);
			$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=videos' );
		}
	}