Exemplo n.º 1
0
	/**
	* Import Data
	*/
	function thirdPartyImport()
	{
		global $option;
		$db = & JFactory::getDBO();
		$app = & JFactory::getApplication();
		$c = hwd_vs_Config::get_instance();

		$video_type	= Jrequest::getVar( 'videotype', '5' );
		$intCount = 0;
		$admin_import = true;
		require_once(JPATH_SITE.DS.'components'.DS.'com_hwdvideoshare'.DS.'models'.DS.'uploads.php');

		if ($video_type == 1 || $video_type == 5)
		{
			$requestarray = JRequest::get( 'default', 2 );
			$data = explode("\n", $requestarray['embeddump']);
			$counter = 0;

			for ($i=0, $n=count($data); $i < $n; $i++)
			{
				unset ($_REQUEST['embeddump']);
				$_REQUEST['embeddump'] = trim($data[$i]);

				if (hwd_vs_uploads::addConfirm($option, $admin_import))
				{
					$counter++;
				}
				else
				{
					// error
				}
			}
			$app->enqueueMessage($counter." video(s) successfully imported");
		}
		else if ($video_type == 2)
		{

			// youtube playlist

			$requestarray = JRequest::get( 'default', 2 );
			$data = explode("\n", $requestarray['embeddump']);
			$embeddump_original = $data[0];
			$embeddump = $data[0];

			$pos = strpos($embeddump, "p=");

			if ($pos === false) {

				$app->enqueueMessage("This is not a Youtube Playlist URL. Check if the URL is for a User list or an RSS feed, then use the correct import tool.");
				$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=import' );

			} else if ($pos) {

				$pos_srt = $pos + 2;
				$pos_end = strpos($embeddump, '&', $pos_srt);
				if ($pos_end === false) {

					$playlist_no =  substr($embeddump, $pos_srt);

				} else {

					$length = $pos_end - $pos_srt;
					$playlist_no =  substr($embeddump, $pos_srt, $length);

				}

				$playlist_no = strip_tags($playlist_no);
				$playlist_no = preg_replace("/[^a-zA-Z0-9s_-]/", "", $playlist_no);

			}

			for ($i = 0; $i <= 4; $i++) {

				$playlist_url = "http://www.youtube.com/view_play_list?p=".$playlist_no."&page=".$i;
				$playlist_url = hwd_vs_tools::get_final_url( $playlist_url );

				$msg = 'Searching page: '.$playlist_url;
				$app->enqueueMessage($msg);

				$curl_handle=curl_init();
				curl_setopt($curl_handle,CURLOPT_URL,$playlist_url);
				curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
				curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
				$buffer = curl_exec($curl_handle);
				curl_close($curl_handle);

				if (empty($buffer))	{

					return null;

				} else {

					hwdvids_BE_imports::scanYoutubePage($buffer);

				}

			}

		} else if ($video_type == 3) {

			// youtube userlist

			$requestarray = JRequest::get( 'default', 2 );
			$data = explode("\n", $requestarray['embeddump']);
			$embeddump_original = $data[0];
			$embeddump = $data[0];

			$pos = strpos($embeddump, "user="******"user/");

				if ($pos === false) {

					$app->enqueueMessage("This is not a Youtube User URL. Check if the URL is for a Playlist or an RSS feed, then use the correct import tool.");
					$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=import' );

				} else if ($pos) {

					$pos_srt = $pos + 5;
					$pos_end = strpos($embeddump, '&', $pos_srt);
					if ($pos_end === false) {

						$pos_end = strpos($embeddump, '#', $pos_srt);
						if ($pos_end === false) {

							$username =  substr($embeddump, $pos_srt);

						} else {

							$length = $pos_end - $pos_srt;
							$username =  substr($embeddump, $pos_srt, $length);

						}

					} else {

						$length = $pos_end - $pos_srt;
						$username =  substr($embeddump, $pos_srt, $length);

					}

					$username = strip_tags($username);
					$username = preg_replace("/[^a-zA-Z0-9s_-]/", "", $username);

				}

			} else if ($pos) {

				$pos_srt = $pos + 5;

				$pos_end = strpos($embeddump, '&', $pos_srt);

				if ($pos_end === false) {

					$pos_end = strpos($embeddump, '#', $pos_srt);

					if ($pos_end === false) {

						$username =  substr($embeddump, $pos_srt);

					} else {

						$length = $pos_end - $pos_srt;
						$username =  substr($embeddump, $pos_srt, $length);

					}

				} else {

					$length = $pos_end - $pos_srt;
					$username =  substr($embeddump, $pos_srt, $length);

				}

				$username = strip_tags($username);
				$username = preg_replace("/[^a-zA-Z0-9s_-]/", "", $username);

			}

			//$username_url = "http://www.youtube.com/profile?user="******"#g/u";
			$username_url = "http://gdata.youtube.com/feeds/videos?author=".$username."&start-index=1&max-results=50";
			$username_url = hwd_vs_tools::get_final_url( $username_url );

			$msg = 'Searching page: '.$username_url;
			$app->enqueueMessage($msg);

			$curl_handle=curl_init();
			curl_setopt($curl_handle,CURLOPT_URL,$username_url);
			curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
			curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
			$buffer = curl_exec($curl_handle);
			curl_close($curl_handle);

			if (empty($buffer))	{

				return null;

			} else {

				hwdvids_BE_imports::scanYoutubePage($buffer);

			}

		} else if ($video_type == 4) {

			// youtube rss

			$requestarray = JRequest::get( 'default', 2 );
			$data = explode("\n", $requestarray['embeddump']);
			$embeddump_original = $data[0];
			$embeddump = $data[0];

			$pos = strpos($embeddump, "http");

			if ($pos === false) {
				$embeddump = 'http://'.$embeddump;
			}

			$pos = strpos($embeddump, "gdata");

			if ($pos === false) {
				$feedurl = "http://www.youtube.com".parse_url($embeddump, PHP_URL_PATH)."?".parse_url($embeddump, PHP_URL_QUERY);
			} else {
				$feedurl = "http://gdata.youtube.com".parse_url($embeddump, PHP_URL_PATH)."?".parse_url($embeddump, PHP_URL_QUERY);
			}

			$curl_handle=curl_init();
			curl_setopt($curl_handle,CURLOPT_URL,$feedurl);
			curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
			curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
			$buffer = curl_exec($curl_handle);
			curl_close($curl_handle);

			if (empty($buffer))	{

				return null;

			} else {

				hwdvids_BE_imports::scanYoutubePage($buffer);

			}

		}


		if ($video_type == 1 || $video_type == 5) {

			$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=import' );

		} else {

			$embeddump 			= urlencode($embeddump_original);
			$videotype 			= JRequest::getInt( 'videotype', 0 );
			$category_id 		= JRequest::getInt( 'category_id', 0 );
			$public_private 	= JRequest::getWord( 'public_private', 'public' );
			$allow_comments 	= JRequest::getInt( 'allow_comments', 0 );
			$allow_embedding 	= JRequest::getInt( 'allow_embedding', 0 );
			$allow_ratings 		= JRequest::getInt( 'allow_ratings', 0 );

			$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=redoListImport&embeddump='.$embeddump.'&videotype='.$videotype.'&category_id='.$category_id.'&public_private='.$public_private.'&allow_comments='.$allow_comments.'&allow_embedding='.$allow_embedding.'&allow_ratings='.$allow_ratings );

		}

	}
Exemplo n.º 2
0
	function redoListImport()
	{
		require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'models'.DS.'imports.php');
		hwdvids_BE_imports::redoListImport();
		return;
	}