Ejemplo n.º 1
0
   /**
    * Save editted video details
    */
	function saveVideoInfo()
	{
		global $Itemid, $mainframe;
		$db = & JFactory::getDBO();
		$my = & JFactory::getUser();
		$c = hwd_vs_Config::get_instance();
		$app = & JFactory::getApplication();

		$row = new hwdvids_video($db);

		$uid = JRequest::getInt( 'owner', 0, 'post' );
		$rowid = JRequest::getInt( 'id', 0, 'post' );
		$referrer = JRequest::getVar( 'referrer', JURI::root( true ) . '/index.php?option=com_hwdvideoshare&Itemid='.$Itemid );

		// check component access settings and deny those without privileges
		if (!hwd_vs_access::allowAccess( $c->gtree_mdrt, $c->gtree_mdrt_child, hwd_vs_access::userGID( $my->id ))) {
			if ($my->id == $uid) {
				if ($my->id == "0") {
					$app->enqueueMessage(_HWDVIDS_ALERT_NOPERM);
					$app->redirect( $referrer );
				}
				if ($c->allowvidedit == "0") {
					$app->enqueueMessage(_HWDVIDS_ALERT_NOPERM);
					$app->redirect( $referrer );
				}
				// continue
			} else {
				$app->enqueueMessage(_HWDVIDS_ALERT_NOPERM);
				$app->redirect( $referrer );
			}
		}

		$row->load( $rowid );
		$old_category = $row->category_id;

		$file_name_org   = $_FILES['thumbnail_file']['name'];
		$file_ext        = substr($file_name_org, strrpos($file_name_org, '.') + 1);

		$thumbnail = '';
		if ($_FILES['thumbnail_file']['tmp_name'] !== "") {

			if ($row->video_type == "local" || $row->video_type == "swf" || $row->video_type == "mp4")
			{
				$videocode = $row->video_id;
				$thumbnail = $file_ext;
			}
			else
			{
				$videocode = "tp-".$row->id;
				$thumbnail = "tp-".$row->id.".".$file_ext;
			}

			$base_Dir = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS;
			$upload_result = hwd_vs_tools::uploadFile("thumbnail_file", $videocode, $base_Dir, 2, "jpg,jpeg", 1);

			if ($upload_result[0] == "0")
			{
				$msg = $upload_result[1];
				$app->enqueueMessage($msg);
				$app->redirect( JURI::root( true ) . '/index.php?option=com_hwdvideoshare&Itemid='.$Itemid.'&task=editvideo&video_id='.$row->id );
			}
			else
			{
				require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'thumbnail.inc.php');

				$thumb_path_s = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS.$videocode.'.'.$file_ext;
				$thumb_path_l = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS.'l_'.$videocode.'.'.$file_ext;

				$twidth_s = round($c->con_thumb_n);
				$theight_s = round($c->con_thumb_n*$c->tar_fb);
				$twidth_l = round($c->con_thumb_l);
				$theight_l = round($c->con_thumb_l*$c->tar_fb);

				list($width, $height, $type, $attr) = @getimagesize($thumb_path_s);
				$ratio = $width/$height;

				//echo $thumb_path_s."<br />".$ratio."<br />".$width."<br />".$height."<br />".$c->tar_fb."<br />".$twidth_s."<br />".$theight_s;

				if ($ratio > 1)
				{
					$resized_l = new Thumbnail($thumb_path_s);
					$resized_l->resize($twidth_l,$twidth_l);
					$resized_l->cropFromCenter($twidth_l, $theight_l);
					$resized_l->save($thumb_path_l);
					$resized_l->destruct();

					$resized_s = new Thumbnail($thumb_path_s);
					$resized_s->resize($twidth_s,$twidth_s);
					$resized_s->cropFromCenter($twidth_s, $theight_s);
					$resized_s->save($thumb_path_s);
					$resized_s->destruct();
				}
				else
				{
					$resized_l = new Thumbnail($thumb_path_s);
					$resized_l->resize($twidth_l,2000);
					$resized_l->cropFromCenter($twidth_l, $theight_l);
					$resized_l->save($thumb_path_l);
					$resized_l->destruct();

					$resized_s = new Thumbnail($thumb_path_s);
					$resized_s->resize($twidth_s,1000);
					$resized_s->cropFromCenter($twidth_s, $theight_s);
					$resized_s->save($thumb_path_s);
					$resized_s->destruct();
				}
			}
		}
		else
		{
			//echo "No thumbnail uploaded";
		}

		$title = hwd_vs_tools::generatePostTitle();
		$description = hwd_vs_tools::generatePostDescription();
		$tags = hwd_vs_tools::generatePostTags();

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

		$_POST['id'] 				= $rowid;
		$_POST['title'] 			= $title;
		$_POST['description'] 		= $description;
		$_POST['category_id'] 		= JRequest::getInt( 'category_id', 0 );
		$_POST['tags'] 				= $tags;
		if (!empty($thumbnail))
		{
			$_POST['thumbnail'] 	= $thumbnail;
		}

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

		// Make sure the record is valid
   		if (!$row->check())
   		{
        	$this->setError($this->_db->getErrorMsg());
			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();
		}

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

		$msg = _HWDVIDS_ALERT_VIDEDITSAVED;
		$app->enqueueMessage($msg);
		$app->redirect( $referrer );
	}
Ejemplo n.º 2
0
   /**
	* Import Data
	*/
	function csvImport()
	{
		global $option;
		$db = & JFactory::getDBO();
		$app = & JFactory::getApplication();
		$c = hwd_vs_Config::get_instance();

		$mediatype = JRequest::getWord( 'mediatype' );
		$delimiter = JRequest::getWord( 'delimiter' );
		$maxerrors = JRequest::getInt( 'maxerrors', 1, 'post' );

		$base_Dir = JPATH_SITE.DS.'media'.DS;
		$base_Name = "csv_import";

		$upload_result = hwd_vs_tools::uploadFile( "upfile_0", $base_Name, $base_Dir, 2, 'csv', 1 );
		if ($upload_result[0] == "0") {
			$msg = $upload_result[1];
			$app->enqueueMessage($msg);
			$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=import' );
		}

		if ($delimiter == "comma") {
			$delimiter = ",";
		} else if ($delimiter == "tab") {
			$delimiter = "|";
		} else if ($delimiter == "pipe") {
			$delimiter = "	";
		}

		include(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'csv_iterator.class.php');
		$csvIterator = new CsvIterator(JPATH_SITE.DS.'media'.DS.$base_Name.'.csv', true, $delimiter, "\"");

		$counter=0;
		$errors=0;
		while ($csvIterator->next())
		{
			$row = $csvIterator->current();

			if ($errors > $maxerrors)
			{
				$msg = "Import stopped! Maximum allowed errors exceeded.";
				$app->enqueueMessage($msg);
				$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=import' );
			}

			if (!isset($row['Type']) || empty($row['Type'])) { $row['Type'] = null; $errors++; $app->enqueueMessage("Null Type"); continue; }
			if (!isset($row['Code']) || empty($row['Code'])) { $row['Code'] = null; $errors++; $app->enqueueMessage("Null Code"); continue; }
			if (!isset($row['Extension']) || empty($row['Extension'])) { $row['Extension'] = "flv"; }
			if (!isset($row['Thumbnail']) || empty($row['Thumbnail'])) { $row['Thumbnail'] = null; $errors++; $app->enqueueMessage("Null Thumbnail"); continue; }
			if (!isset($row['Title']) || empty($row['Title'])) { $row['Title'] = _HWDVIDS_UNKNOWN; }
			if (!isset($row['Description']) || empty($row['Description'])) { $row['Description'] = _HWDVIDS_UNKNOWN; }
			if (!isset($row['Tags']) || empty($row['Tags'])) { $row['Tags'] = _HWDVIDS_UNKNOWN; }
			if (!isset($row['Category ID']) || empty($row['Category ID'])) { $row['Category ID']= "0"; }
			if (!isset($row['Duration']) || empty($row['Duration'])) { $row['Duration'] = "00:00:00"; }
			if (!isset($row['Allow Comments']) || empty($row['Allow Comments'])) { $row['Allow Comments'] = "1"; }
			if (!isset($row['Allow Embedding']) || empty($row['Allow Embedding'])) { $row['Allow Embedding'] = "1"; }
			if (!isset($row['Allow Ratings']) || empty($row['Allow Ratings'])) { $row['Allow Ratings'] = "1"; }
			if (!isset($row['Access']) || empty($row['Access'])) { $row['Access'] = "public"; }
			if (!isset($row['Number Of Views']) || empty($row['Number Of Views'])) { $row['Number Of Views'] = "0"; }
			if (!isset($row['User ID']) || empty($row['User ID'])) { $row['User ID'] = "0"; }
			if (!isset($row['Featured']) || empty($row['Featured'])) { $row['Featured'] = "0"; }
			if (!isset($row['Published']) || empty($row['Published'])) { $row['Published'] = "1"; }
			if (!isset($row['Upload Date']) || empty($row['Upload Date'])) { $row['Upload Date'] = date('Y-m-d H:i:s'); }
			if (!isset($row['Thumbnail Capture Time']) || empty($row['Thumbnail Capture Time'])) { $row['Thumbnail Capture Time'] = "00:00:02"; }

			// Sanitise
			$row['Type'] = preg_replace("/[^a-zA-Z0-9s_.-]/", "", $row['Type']);
			$row['Code'] = preg_replace("/[^a-zA-Z0-9s_:=?.\/&-]/", "", $row['Code']);
			$row['Extension'] = preg_replace("/[^a-zA-Z0-9s_-]/", "", $row['Extension']);
			$row['Thumbnail'] = $row['Thumbnail'];
			$row['Title'] = addslashes($row['Title']);
			$row['Description'] = addslashes($row['Description']);
			$row['Tags'] = addslashes($row['Tags']);
			$row['Category ID'] = intval($row['Category ID']);
			$row['Duration'] = addslashes($row['Duration']);
			$row['Allow Comments'] = intval($row['Allow Comments']);
			$row['Allow Embedding'] = intval($row['Allow Embedding']);
			$row['Allow Ratings'] = intval($row['Allow Ratings']);
			$row['Access'] = preg_replace("/[^a-zA-Z0-9s]/", "", $row['Access']);
			$row['Number Of Views'] = intval($row['Number Of Views']);
			$row['User ID'] = intval($row['User ID']);
			$row['Featured'] = intval($row['Featured']);
			$row['Published'] = intval($row['Published']);
			$row['Upload Date'] = addslashes($row['Upload Date']);
			$row['Thumbnail Capture Time'] = addslashes($row['Thumbnail Capture Time']);

			if ($row['Type'] == "local") {

				//search for duplications
				$db->SetQuery( 'SELECT count(*)'
							 . ' FROM #__hwdvidsvideos'
							 . ' WHERE video_id = "'.$row['Code'].'"'
							 );
				$total = $db->loadResult();
				echo $db->getErrorMsg();

				if ($total > 0) {
					$errors++;
					$app->enqueueMessage("Already Exists");
					continue;
				}

				if ($c->requiredins) {
					$_POST['video_id'] 		= $row['Code'].".".$row['Extension'];
					if ($row['Extension'] == "flv") {
						$_POST['approved'] 		= "queuedforthumbnail";
					} else {
						$_POST['approved'] 		= "queuedforconversion";
					}
				} else {
					$_POST['video_id'] 		= $row['Code'];
					if ($c->aav == 1) {
						$_POST['approved'] = "yes";
					} else {
						$_POST['approved'] = "pending";
					}
				}

				$_POST['video_type'] 		= "local";

			} else {

				//search for duplications
				$db->SetQuery( 'SELECT count(*)'
							 . ' FROM #__hwdvidsvideos'
							 . ' WHERE video_id = "'.$row['Code'].','.$row['Thumbnail'].'"'
							 );
				$total = $db->loadResult();
				echo $db->getErrorMsg();

				if ($total > 0) {
					$errors++;
					$app->enqueueMessage("Already Exists");
					continue;
				}

				$_POST['video_id'] 		= $row['Code'].','.$row['Thumbnail'];
				$_POST['approved'] 		= "yes";
				$_POST['video_type'] 	= $row['Type'];

			}

			$row_new = new hwdvids_video($db);

			$_POST['title'] 			= $row['Title'];
			$_POST['description'] 		= $row['Description'];
			$_POST['tags'] 				= $row['Tags'];
			$_POST['category_id'] 		= $row['Category ID'];
			$_POST['date_uploaded'] 	= $row['Upload Date'];
			$_POST['video_length'] 		= $row['Duration'];
			$_POST['allow_comments'] 	= $row['Allow Comments'];
			$_POST['allow_embedding'] 	= $row['Allow Embedding'];
			$_POST['allow_ratings'] 	= $row['Allow Ratings'];
			$_POST['public_private'] 	= $row['Access'];
			$_POST['number_of_views'] 	= $row['Number Of Views'];
			$_POST['user_id'] 			= $row['User ID'];
			$_POST['featured'] 		    = $row['Featured'];
			$_POST['published'] 		= $row['Published'];
			$_POST['date_uploaded'] 	= $row['Upload Date'];
			$_POST['thumb_snap'] 		= $row['Thumbnail Capture Time'];

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

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

			$counter++;
		}

		unlink(JPATH_SITE.DS.'media'.DS.$base_Name.'.csv');
		$msg = "CSV Import has been executed and ".$counter." video have been imported, please check import was successful. (".$errors." Errors Reported)";
		$app->enqueueMessage($msg);
		$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=import' );
	}
Ejemplo n.º 3
0
   /**
	* edit videos
	*/
	function editvideos($cid)
	{
		global $option;
  		$db =& JFactory::getDBO();
		$my = & JFactory::getUser();
		$app = & JFactory::getApplication();

		$row = new hwdvids_video( $db );
		$row->load( $cid );
		$c = hwd_vs_Config::get_instance();

        // get view count
        require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'maintenance_recount.class.php');
        hwd_vs_recount::recountVideoViews($row->id);

		$db->SetQuery("SELECT *"
							. "\n FROM #__hwdvidsvideos"
							. "\n WHERE id = $cid");
		$row = $db->loadObject();

		$db->SetQuery("SELECT category_name"
							. "\n FROM #__hwdvidscategories"
							. "\n WHERE id = $row->category_id");
		$cat = $db->loadObject();

		if ($row->user_id == 0) {
			$usr->username = "******";
		} else {
			$db->SetQuery("SELECT username"
								. "\n FROM #__users"
								. "\n WHERE id = $row->user_id");
			$usr = $db->loadObject();
		}

		$db->SetQuery( "SELECT count(*)"
							. "\nFROM #__hwdvidsfavorites"
							. "\nWHERE videoid = $cid"
							);
		$favs = $db->loadResult();
		echo $db->getErrorMsg();
		if (empty($favs)) {$favs = 0;}

		$db->SetQuery( "SELECT count(*)"
							. "\nFROM #__hwdvidsflagged_videos"
							. "\nWHERE videoid = $cid"
							);
		$flagged = $db->loadResult();
		echo $db->getErrorMsg();
		if (empty($flagged)) {$flagged = 0;}

		$upld_thumbnail = JRequest::getInt( 'upld_thumbnail', 0, 'post' );
		if ($upld_thumbnail == "1") {

			$file_name_org   = $_FILES['thumbnail_file']['name'];
			$file_ext        = substr($file_name_org, strrpos($file_name_org, '.') + 1);

			if ($row->video_type == "local" || $row->video_type == "swf" || $row->video_type == "mp4")
			{
				$videocode = $row->video_id;
				$thumbnail = $file_ext;
			}
			else
			{
				$videocode = "tp-".$row->id;
				$thumbnail = "tp-".$row->id.".".$file_ext;
			}

			$base_Dir = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS;
			$upload_result = hwd_vs_tools::uploadFile("thumbnail_file", $videocode, $base_Dir, 2, "jpg,jpeg", 1);

			if ($upload_result[0] == "0")
			{
				$msg = $upload_result[1];
				$app->enqueueMessage($msg);
				$app->redirect( 'index.php?option=com_hwdvideoshare&Itemid='.$Itemid.'&task=editvidsA&hidemainmenu=1&cid='.$row->id );
			}
			else
			{
				include_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'thumbnail.inc.php');

				$thumb_path_s = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS.$videocode.'.'.$file_ext;
				$thumb_path_l = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS.'l_'.$videocode.'.'.$file_ext;

				$twidth_s = round($c->con_thumb_n);
				$theight_s = round($c->con_thumb_n*$c->tar_fb);
				$twidth_l = round($c->con_thumb_l);
				$theight_l = round($c->con_thumb_l*$c->tar_fb);

				list($width, $height, $type, $attr) = @getimagesize($thumb_path_s);
				$ratio = $width/$height;

				//echo $thumb_path_s."<br />".$ratio."<br />".$width."<br />".$height."<br />".$c->tar_fb."<br />".$twidth_s."<br />".$theight_s;

				if ($ratio > 1)
				{
					$resized_l = new Thumbnail($thumb_path_s);
					$resized_l->resize($twidth_l,$twidth_l);
					$resized_l->cropFromCenter($twidth_l, $theight_l);
					$resized_l->save($thumb_path_l);
					$resized_l->destruct();

					$resized_s = new Thumbnail($thumb_path_s);
					$resized_s->resize($twidth_s,$twidth_s);
					$resized_s->cropFromCenter($twidth_s, $theight_s);
					$resized_s->save($thumb_path_s);
					$resized_s->destruct();
				}
				else
				{
					$resized_l = new Thumbnail($thumb_path_s);
					$resized_l->resize($twidth_l,2000);
					$resized_l->cropFromCenter($twidth_l, $theight_l);
					$resized_l->save($thumb_path_l);
					$resized_l->destruct();

					$resized_s = new Thumbnail($thumb_path_s);
					$resized_s->resize($twidth_s,1000);
					$resized_s->cropFromCenter($twidth_s, $theight_s);
					$resized_s->save($thumb_path_s);
					$resized_s->destruct();
				}
			}

			// update db with new thumbnail
			$db->SetQuery("UPDATE #__hwdvidsvideos SET thumbnail = '$thumbnail' WHERE id = $row->id");
			$db->Query();
			if ( !$db->query() ) {
				echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
				exit();
			}

			$msg = "Thumbnail was successfully uploaded";
			$app->enqueueMessage($msg);
			$app->redirect( 'index.php?option=com_hwdvideoshare&Itemid='.$Itemid.'&task=editvidsA&hidemainmenu=1&cid='.$row->id );
		}

		hwdvids_HTML::editvideos($row, $cat, $usr, $favs, $flagged);
	}
Ejemplo n.º 4
0
	/**
	 * save categories
	 */
	function savecategories()
	{
		global $option;
		$db = & JFactory::getDBO();
		$app = & JFactory::getApplication();
		$c = hwd_vs_Config::get_instance();

		$access_lev_u = Jrequest::getVar( 'access_lev_u', '0' );
		$access_lev_v = Jrequest::getVar( 'access_lev_v', '0' );

		$row = new hwdvids_cats($db);

		if (isset($_FILES['thumbnail_file']['error'])) {

			$file_name_org   = $_FILES['thumbnail_file']['name'];
			$file_ext        = substr($file_name_org, strrpos($file_name_org, '.') + 1);

			$thumbnail_url = JURI::root( true ).'/hwdvideos/thumbs/category'.$_POST['id'].'.'.$file_ext;
			$base_Dir = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS;
			$thumbnail_name = 'category'.$_POST['id'];

			$upload_result = hwd_vs_tools::uploadFile("thumbnail_file", $thumbnail_name, $base_Dir, 2, "jpg,jpeg", 1);

			if ($upload_result[0] == "0") {

				$msg = $upload_result[1];
				$app->enqueueMessage($msg);

			} else {

				include_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'thumbnail.inc.php');
				$thumb_path_s = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS.$thumbnail_name.'.'.$file_ext;
				$twidth_s = round($c->con_thumb_n);
				$theight_s = round($c->con_thumb_n*$c->tar_fb);

				list($width, $height, $type, $attr) = @getimagesize($thumb_path_s);
				$ratio = $height/$width;

				if ($ratio < $c->tar_fb) {

					$resized_s = new Thumbnail($thumb_path_s);
					$resized_s->resize(1000, $theight_s);
					$resized_s->cropFromCenter($twidth_s, $theight_s);
					$resized_s->save($thumb_path_s);
					$resized_s->destruct();

				} else {

					$resized_s = new Thumbnail($thumb_path_s);
					$resized_s->resize($twidth_s,1000);
					$resized_s->cropFromCenter($twidth_s, $theight_s);
					$resized_s->save($thumb_path_s);
					$resized_s->destruct();

				}
			}

			// update db with new thumbnail
			$db->SetQuery("UPDATE #__hwdvidscategories SET thumbnail = '$thumbnail_url' WHERE id = ".intval($_POST['id']));
			$db->Query();
			if ( !$db->query() ) {
				echo "<script> alert('".$db->getErrorMsg()."'); window.history.go(-1); </script>\n";
				exit();
			}

			$msg = "Thumbnail was successfully uploaded";
			$app->enqueueMessage($msg);
			$app->redirect( 'index.php?option=com_hwdvideoshare&Itemid='.$Itemid.'&task=editcatA&hidemainmenu=1&cid='.$_POST['id'] );

		} else {

			if (intval($_POST['id']) !== 0 && (intval($_POST['id']) == intval($_POST['parent']))) {
				$app->enqueueMessage(_HWDVIDS_ALERT_PARENTNOTSELF);
				$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=categories' );
			}

			$_POST['category_name'] = Jrequest::getVar( 'category_name', 'no name supplied' );
			$_POST['category_description'] = Jrequest::getVar( 'category_description', 'no name supplied' );
			$_POST['access_lev_u'] = @implode(",", $access_lev_u);
			$_POST['access_lev_v'] = @implode(",", $access_lev_v);

		}

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

		if(empty($row->category_name)) {
			$app->enqueueMessage(_HWDVIDS_NOTITLE);
			$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=categories' );
		}

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

		$row->checkin();

		// perform maintenance
		include(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'maintenance_recount.class.php');
		hwd_vs_recount::recountSubcatsInCategory();

		$app->enqueueMessage(_HWDVIDS_ALERT_CATSAVED);
		$app->redirect( JURI::root( true ) . '/administrator/index.php?option='.$option.'&task=categories' );
	}
Ejemplo n.º 5
0
    /**
     * 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 updateChannel()
	{
		global $Itemid, $mainframe;
		$db = & JFactory::getDBO();
		$my = & JFactory::getUser();
		$c = hwd_vs_Config::get_instance();

		$id = JRequest::getInt( 'id', 0 );
		$row = new hwdvids_channel($db);
		$row->load( $id );

		if ($row->user_id != $my->id)
		{
			$mainframe->enqueueMessage(_HWDVIDS_ALERT_NOPERM);
			$mainframe->redirect( JRoute::_("index.php?option=com_hwdvideoshare&Itemid=$Itemid&task=channels") );
		}

		$channel_description  = Jrequest::getVar( 'channel_description', _HWDVS_UNKNOWN );

		$_POST['channel_description'] = $channel_description;

		$file_name_org   = $_FILES['thumbnail_file']['name'];
		$file_ext        = substr($file_name_org, strrpos($file_name_org, '.') + 1);

		$thumbnail = '';
		if ($_FILES['thumbnail_file']['tmp_name'] !== "")
		{
			$videocode = "ch-".$row->id;

			$base_Dir = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS;
			$upload_result = hwd_vs_tools::uploadFile("thumbnail_file", $videocode, $base_Dir, 2, "jpg,jpeg,png,gif", 1);

			if ($upload_result[0] == "0")
			{
				$msg = $upload_result[1];
				$mainframe->enqueueMessage($msg);
				$mainframe->redirect( JURI::root( true ) . '/index.php?option=com_hwdvideoshare&Itemid='.$Itemid.'&task=editvideo&video_id='.$row->id );
			}
			else
			{
				require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_hwdvideoshare'.DS.'libraries'.DS.'thumbnail.inc.php');

				$thumb_path = JPATH_SITE.DS.'hwdvideos'.DS.'thumbs'.DS.$videocode.'.'.$file_ext;

				$twidth_s = round($c->con_thumb_n);
				$theight_s = round($c->con_thumb_n*$c->tar_fb);

				list($width, $height, $type, $attr) = @getimagesize($thumb_path);
				$ratio = $width/$height;

				//echo $thumb_path."<br />".$ratio."<br />".$width."<br />".$height."<br />".$c->tar_fb."<br />".$twidth_s."<br />".$theight_s;

				if ($ratio > 1)
				{
					$resized = new Thumbnail($thumb_path);
					$resized->resize($twidth_s,$twidth_s);
					$resized->cropFromCenter($twidth_s, $theight_s);
					$resized->save($thumb_path);
					$resized->destruct();
				}
				else
				{
					$resized = new Thumbnail($thumb_path);
					$resized->resize($twidth_s,1000);
					$resized->cropFromCenter($twidth_s, $theight_s);
					$resized->save($thumb_path);
					$resized->destruct();
				}
			}
			$_POST['channel_thumbnail'] = $videocode.'.'.$file_ext;
		}
		else
		{
			//echo "No thumbnail uploaded";
		}

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

		$msg = "Channel saved";
		$mainframe->enqueueMessage($msg);
		$mainframe->redirect( JRoute::_("index.php?option=com_hwdvideoshare&Itemid=$Itemid&task=viewchannel&user_id=$my->id") );
	}