Exemple #1
0
   /**
	* Import Data
	*/
	function rtmpupload()
	{
		global $Itemid, $option;
		$db = & JFactory::getDBO();
		$my = & JFactory::getUser();
		$app = & JFactory::getApplication();

		$rtmpurl = Jrequest::getVar( 'rtmpurl', '' );
		$validated_rtmpurl = hwd_vs_tools::validateUrl($rtmpurl);

		if (empty($validated_rtmpurl))
		{
			$msg = _HWDVIDS_ALERT_VURLWRONG;
			$app->enqueueMessage($msg);
			$app->redirect( JURI::root( true ) . '/administrator/index.php?option=com_hwdvideoshare&task=import' );
		}

		$thumbnailurl = Jrequest::getVar( 'thumbnailurl', '' );
		$validated_thumbnail_url = hwd_vs_tools::validateUrl($thumbnailurl);

		if (!empty($validated_thumbnail_url) && !hwd_vs_tools::is_valid_url($validated_thumbnail_url))
		{
			$app->enqueueMessage(_HWDVIDS_ALERT_TURLWRONG);
			$app->redirect( JURI::root( true ) . '/administrator/index.php?option=com_hwdvideoshare&task=import' );
		}

		$type  		        = Jrequest::getVar( 'type', 'rtmp' );
		$video_id 		    = $validated_rtmpurl;
		$title 				= Jrequest::getVar( 'title', 'no name supplied' );
		$description 		= Jrequest::getVar( 'description', 'no name supplied' );
		$category_id 		= JRequest::getInt( 'category_id', 0, 'post' );
		$tags 				= Jrequest::getVar( 'tags', 'no name supplied' );
		$duration			= Jrequest::getVar( 'duration', 'no name supplied' );
		$public_private 	= JRequest::getWord( 'public_private' );
		$allow_comments 	= JRequest::getInt( 'allow_comments', 0, 'post' );
		$allow_embedding 	= JRequest::getInt( 'allow_embedding', 0, 'post' );
		$allow_ratings 		= JRequest::getInt( 'allow_ratings', 0, 'post' );

		$checkform = hwd_vs_tools::checkFormComplete($title, $description, $category_id, $tags, $public_private, $allow_comments, $allow_embedding, $allow_ratings);
		if (!$checkform) { return; }

		$row = new hwdvids_video($db);

		$db->SetQuery('SELECT count(*) FROM #__hwdvidsvideos WHERE video_id = "'.$video_id.'"');
		$duplicatecount = $db->loadResult();
		if ($duplicatecount > 0)
		{
			echo "<script>alert('"._HWDVIDS_ALERT_DUPLICATE."'); window.history.go(-1);</script>\n";
			return;
		}

		if ($type == "smil")
		{
			$_POST['video_type'] 		= "smil";
		}
		else
		{
			$_POST['video_type'] 		= "rtmp";
		}
		$_POST['video_id'] 			= $video_id;
		$_POST['title'] 			= $title;
		$_POST['description'] 		= $description;
		$_POST['category_id'] 		= $category_id;
		$_POST['tags'] 				= $tags;
		$_POST['video_length'] 		= $duration;
		$_POST['public_private'] 	= $public_private;
		$_POST['allow_comments'] 	= $allow_comments;
		$_POST['allow_embedding'] 	= $allow_embedding;
		$_POST['allow_ratings'] 	= $allow_ratings;
		$_POST['date_uploaded'] 	= date('Y-m-d H:i:s');
		$_POST['user_id'] 			= $my->id;
		$_POST['published'] 		= "0";
		$_POST['approved'] 			= "yes";
		$_POST['thumbnail'] 		= $thumbnailurl;

		if(empty($_POST['video_id'])) {
			$app->enqueueMessage(_HWDVIDS_ALERT_ERRREM);
			$app->redirect( JURI::root( true ) . '/administrator/index.php?option='. $option .'&task=import');
			return;
		}

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

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

		include_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'helpers'.DS.'events.php');

		$params->title = $title;
		$params->id = $row->id;
		$params->category_id = $row->category_id;
		$params->type = $row->video_type;

		hwdvsEvent::onAfterVideoUpload($params);

		$app->enqueueMessage(_HWDVIDS_ALERT_SUCREM);
		$app->redirect( JURI::root( true ) . '/administrator/index.php?option='. $option .'&task=editvidsA&hidemainmenu=1&cid='.$row->id );

	}