Your IP : 216.73.216.46


Current Path : /home/megadansyp/www/plugins/fwgallerytype/video/
Upload File :
Current File : /home/megadansyp/www/plugins/fwgallerytype/video/video.php

<?php
/**
 * FW Super Gallery 2.4.0
 * @copyright (C) 2020 Fastw3b
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @link http://www.fastw3b.net/ Official website
 **/

defined( '_JEXEC' ) or die( 'Restricted access' );

class plgFwGalleryTypeVideo extends JPlugin {
	function __construct(&$subject, $config = array()) {
		if (!defined('FWMG_COMPONENT_SITE')) {
			define('FWMG_COMPONENT_SITE', JPATH_SITE.'/components/com_fwgallery');
		}
		if (!defined('FWMG_COMPONENT_ADMINISTRATOR')) {
			define('FWMG_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.'/components/com_fwgallery');
		}
		require_once(FWMG_COMPONENT_SITE.'/helpers/helper.php');
		JTable::addIncludePath(FWMG_COMPONENT_ADMINISTRATOR.'/tables');
		JHTML::addIncludePath(FWMG_COMPONENT_SITE.'/helpers');
		JFactory::getLanguage()->load('plg_fwgallerytype_video', JPATH_ADMINISTRATOR);
		parent::__construct($subject, $config);
		if (!class_exists('JToolbarHelper')) {
			$path = JPATH_ADMINISTRATOR.'/includes/toolbar.php';
			if (file_exists($path)) {
				require_once($path);
			}
		}
	}
	function ongetType($ext) {
		if ($ext != 'com_fwgallery') return;
		return 'video';
	}
	function onLoadMainMenu($ext, $type, $view) {
		if ($ext != 'com_fwgallery' or $type != 'file.video') return;
		if ($view->current_user->authorise('core.edit', 'com_fwgallery')) {
			fwgButtonsHelper::apply('apply', 'FWMG_DOC_ADMIN_FILEEDIT_TOOLBAR_BTN_SAVE');
		}
		fwgButtonsHelper::save('save', 'FWMG_DOC_ADMIN_FILEEDIT_TOOLBAR_BTN_SAVECLOSE');
		fwgButtonsHelper::cancel('cancel', 'FWMG_DOC_ADMIN_FILEEDIT_TOOLBAR_BTN_CANCEL');
	}
	function oncheckFileRegistration($ext, $row, &$files) {
		if ($ext != 'com_fwgallery' or $row->type != 'video') return;
		foreach ($files as $i=>$file) {
			if ($row->_video_sys_filename and strpos($file, $row->_video_sys_filename)) {
				unset($files[$i]);
				break;
			}
		}
	}
	/* batch upload */
	function ongetAffordableExts($ext, &$exts) {
		if ($ext != 'com_fwgallery') return;
		$exts = array_merge($exts, array('mp4'));
	}
	function ongetFileTypeByExt($ext, $type, &$buff) {
		if ($ext != 'com_fwgallery' or $type != 'mp4') return;
		$buff = 'video';
	}

    function getUserState($name, $def='', $type='string') {
        $app = JFactory::getApplication();
        return $app->getUserStateFromRequest('com_fwgallery.frontendmanager.'.$name, $name, $def, $type);
    }
	function onfileDownloadable($ext, $file) {
		if ($ext != 'com_fwgallery.video') return;
		return plgFwGalleryTypeVideo::isVideoExists($file);
	}
	function onfileDownloadPath($ext, $file) {
		if ($ext != 'com_fwgallery.video') return;
		if (!empty($file->_video_sys_filename)) {
			$path = fwgHelper::getImagePath($file->_video_sys_filename);
			if (file_exists($path.$file->_video_sys_filename)) {
				return array(
					'sys_filename' => $path.$file->_video_sys_filename,
					'filename' => $file->_video_filename
				);
			}
		}
	}
	static function isVideoExists($file) {
		if (!empty($file->_video_sys_filename) and $file->_video_media == 'mp4') {
			$path = fwgHelper::getImagePath($file->_video_sys_filename);
			if (file_exists($path.$file->_video_sys_filename)) {
				return true;
			}
		}
	}
	function onCheckFile($ext, $file) {
		if ($ext != 'com_fwgallery.video') return true;

		return true;
	}
	function onDeleteFile($ext, $file) {
		if ($ext != 'com_fwgallery') return;
		if (!empty($file->_video_sys_filename)) {
			$path = fwgHelper::getImagePath($file->_video_sys_filename);
			if (is_file($path.$file->_video_sys_filename)) {
				JFile::delete($path.$file->_video_sys_filename);
			}
		}

		if (!empty($file->_video_exists)) {
			$db = JFactory::getDBO();
			$db->setQuery('DELETE FROM #__fwsg_file_video WHERE file_id = '.(int)$file->id);
			$db->execute();
		}
	}
	function ongetFileExtraFields($ext) {
		if ($ext != 'com_fwgallery') return;
		return ',
	EXISTS(SELECT * FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id) AS _video_exists,
	(SELECT fv.`sys_filename` FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id LIMIT 1) AS _video_sys_filename,
	(SELECT fv.`filename` FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id LIMIT 1) AS _video_filename,
	(SELECT fv.`media` FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id LIMIT 1) AS _video_media,
	(SELECT fv.`code` FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id LIMIT 1) AS _video_code,
	(SELECT fv.`width` FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id LIMIT 1) AS _video_width,
	(SELECT fv.`height` FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id LIMIT 1) AS _video_height,
	(SELECT fv.`duration` FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id LIMIT 1) AS _video_duration,
	(SELECT fv.`size` FROM #__fwsg_file_video AS fv WHERE fv.file_id = f.id LIMIT 1	) AS _video_size';
	}
	function ongetLocalStatExtraFields($ext, &$query) {
		if ($ext != 'com_fwgallery') return;
		$query .= ',
	(SELECT COUNT(*) FROM #__fwsg_file WHERE `type` = \'video\') AS vt,
	(SELECT COUNT(*) FROM #__fwsg_file WHERE `type` = \'video\' AND published = 1) AS vp,
	(SELECT SUM(`size`) FROM #__fwsg_file_video WHERE `size` IS NOT NULL) AS `vs`';
	}
	function onshowStatExtraFields($ext, $data) {
		if ($ext != 'com_fwgallery') return;

		echo fwgHelper::loadTemplate('admin.video.show_stat_extra_fields', array(
			'view' => $this,
			'data' => $data
		), dirname(__FILE__).'/layouts/');
	}
	function onshowTagObjectsQty($ext, $row) {
		if ($ext != 'com_fwgallery' or empty($row->_videos_qty)) return;

		echo fwgHelper::loadTemplate('admin.video.show_tag_objects_qty', array(
			'view' => $this,
			'row' => $row
		), dirname(__FILE__).'/layouts/');
	}
	function onshowFileListRow($ext, $view, $num, $row) {
		if ($ext != 'com_fwgallery.video') return;

		echo fwgHelper::loadTemplate('admin.video.show_file_list_row', array(
			'view' => $view,
			'num' => $num,
			'row' => $row
		), dirname(__FILE__).'/layouts/');
	}
	function onbeforeCategoryDisplay($ext, $category) {
		if ($ext != 'com_fwgallery') return;
		JHTML::_('jquery.framework');
		JHTML::script('plugins/fwgallerytype/video/assets/js/scripts.js', array('version'=>'v=102'));
	}
	function onbeforeFileDisplay($ext, $file, &$params) {
		$this->onbeforeCategoryDisplay($ext, $file);
	}
	function onshowFileTypeOutput($ext, $displayData) {
		if ($ext != 'com_fwgallery.video') return;
		echo fwgHelper::loadTemplate('site.video.output', $displayData, dirname(__FILE__).'/layouts/');
	}
	function onshowFileListTypeOutput($ext, $displayData) {
		if ($ext != 'com_fwgallery.video') return;
		echo fwgHelper::loadTemplate('site.video.list_output', $displayData, dirname(__FILE__).'/layouts/');
	}
	function ongetFileInfo($ext, $row, $view, &$info) {
		if ($ext != 'com_fwgallery' or $row->type != 'video') return;

		$info = fwgHelper::loadTemplate('site.video.get_file_info', array(
			'view' => $this,
			'row' => $row
		), dirname(__FILE__).'/layouts/');
	}
	function ongetFileExtraTables($ext) {
		if ($ext != 'com_fwgallery') return;
		return '
	LEFT JOIN #__fwsg_file_video AS fv ON fv.file_id = f.id';
	}
	function _collectWhere() {
		static $where;
		if (!is_array($where)) {
			$app = JFactory::getApplication();

			$where = array("f.`type` = 'video'");
			if ($app->isClient('site')) {
				$user = JFactory::getUser();
				if (!$user->authorise('core.login.admin')) {
					$where[] = 'f.user_id = '.$user->id;
				}
			}

			if ($data = $this->getUserState('search') and is_string($data)) {
				$db = JFactory :: getDBO();
				$where[] = '(f.id = '.(int)$data.' OR f.name LIKE \'%'.$db->escape($data).'%\')';
			}
			if ($data = $this->getUserState('user')) {
				$where[] = 'f.user_id = '.$data;
			}
			if ($data = $this->getUserState('category')) {
				$where[] = 'f.category_id = '.$data;
			}

			$app->triggerEvent('oncollectFilesListWhere', array('com_fwgallery', $where));
		}

		return $where?('WHERE '.implode(' AND ', $where)):'';
    }
	function onloadList($ext, $model, &$list) {
		if ($ext != 'com_fwgallery.video') return;

		$app = JFactory::getApplication();
		$input = $app->input;

        $order = $input->getString('order');
        if (!$order or !in_array($order, array('ordering','name','created'))) $order = 'ordering';

        $extras = $app->triggerEvent('ongetFileExtraFields', array('com_fwgallery'));

        $db = JFactory::getDBO();
        $db->setQuery('
SELECT
    f.*,
	fi.file_id AS _image_exists,
	fi.sys_filename AS _sys_filename,
    fi.alt AS _alt,
    fi.width AS _width,
    fi.height AS _height,
    fi.size AS _size,

    u.name AS _user_name,
    p.parent AS _category_parent,
    p.name AS _category_name,
    p.params AS _category_params,
    (SELECT g.title FROM #__viewlevels AS g WHERE g.id = f.`access`) AS _group_name

    '.implode('', $extras).'
FROM
    #__fwsg_file AS f
    LEFT JOIN #__fwsg_file_image AS fi ON fi.file_id = f.id
    LEFT JOIN #__fwsg_category AS p ON f.category_id = p.id
    LEFT JOIN #__users AS u ON u.id = f.user_id
'.$this->_collectWhere().'
ORDER BY
    p.ordering,
    p.name,
    p.id,
    f.'.$order,
			$this->getUserState('limitstart', 0),
			$this->getUserState('limit', $app->getCfg('list_limit'))
		);

		if ($list = $db->loadObjectList()) {
			$ids = array();
			foreach ($list as $i=>$row) {
				$ids[] = $row->id;
				$list[$i]->_category_params = new JRegistry($row->_category_params);
			}
			$app->triggerEvent('oncalculateFileListExtraFields', array('com_fwgallery', &$list, $ids, true));
			return $list;
		}
	}
	function onloadQty($ext, $model, &$qty) {
		if ($ext != 'com_fwgallery.video') return;
		$db = JFactory::getDBO();
        $db->setQuery('
SELECT
    COUNT(*)
FROM
    #__fwsg_file AS f
    LEFT JOIN #__fwsg_category AS p ON f.category_id = p.id
'.$this->_collectWhere());
        $qty = $db->loadResult();
		return $qty;
	}
	function ongetCategoryExtraFields($ext) {
		if ($ext != 'com_fwgallery') return;
		$app = JFactory::getApplication();
		$qty_extras = $app->triggerEvent('ongetCategoryExtraCounterQuery', array('com_fwgallery', 'video'));
		return ',(SELECT COUNT(*) FROM #__fwsg_file AS f WHERE (f.category_id = c.id AND f.`type` = \'video\' AND f.published = 1)'.implode('', $qty_extras	).') AS _videos_qty';
	}
	function ongetTagExtraFields($ext) {
		if ($ext != 'com_fwgallery') return;
		$user_where = array(
			'f.category_id = c.id',
		    'ft.file_id = f.id',
		    'ft.tag_id = t.id',
		    'f.`type` = \'video\''
		);
		$user = JFactory::getUser();
		if (!$user->authorise('core.login.admin')) {
			$user_where[] = '(c.`access` = 0 OR c.access IN ('.implode(',', $user->getAuthorisedViewLevels()).'))';
			$user_where[] = '(f.`access` = 0 OR f.access IN ('.implode(',', $user->getAuthorisedViewLevels()).'))';
		}
		$app = JFactory::getApplication();
		if ($app->isClient('site')) {
		    $user_where[] = 'c.published = 1';
		    $user_where[] = 'f.published = 1';
		}

		return ',(SELECT COUNT(*) FROM #__fwsg_file_tag AS ft, #__fwsg_file AS f, #__fwsg_category AS c WHERE '.implode(' AND ', $user_where).') AS _videos_qty';
	}
/*	function oncalculateCategoryListExtraFields($ext, &$list) {
		if ($ext != 'com_fwgallery') return;
	}*/
	function ongetCategoryExtraCounters($ext, $row) {
		if ($ext != 'com_fwgallery' or empty($row->_videos_qty)) return;
		return '<i class="fal fa-video"></i> '.$row->_videos_qty;
	}
	function ongetCategoryListExtraCounters($ext, $row) {
		if ($ext != 'com_fwgallery' or empty($row->_videos_qty)) return;
		return (empty((int)$row->_videos_qty) ? '' : '<span class="fwmg-grid-item-stats-videos"><i class="fal fa-video"></i> '.$row->_videos_qty.'</span>');
	}
	function ongetCategoryAdminListExtraCounters($ext, $row) {
		if ($ext != 'com_fwgallery' or empty($row->_videos_qty)) return;
		return '<div><i class="fal fa-video"></i> '.$row->_videos_qty.'</div>';
	}
	function onStoreFile($ext, $file, $isnew, $image=null) {
		if ($ext != 'com_fwgallery.video') return;

		$input = JFactory::getApplication()->input;
		$db = JFactory::getDBO();

		$image_exists = $image_record_exists = $video_exists = $video_sys_filename = $video_uploaded = false;
		$db->setQuery('
SELECT
	(SELECT sys_filename FROM #__fwsg_file_image WHERE file_id = '.(int)$file->id.') AS _image_sys_filename,
	(SELECT sys_filename FROM #__fwsg_file_video WHERE file_id = '.(int)$file->id.' LIMIT 1) AS _video_sys_filename,
	EXISTS(SELECT * FROM #__fwsg_file_image WHERE file_id = '.(int)$file->id.') AS _image_record_exists,
	EXISTS(SELECT * FROM #__fwsg_file_video WHERE file_id = '.(int)$file->id.') AS _video_exists
');
		if ($obj = $db->loadObject()) {
			$image_exists = fwgHelper::fileExists($obj->_image_sys_filename);
			$image_record_exists = $obj->_image_record_exists;
			$video_exists = $obj->_video_exists;
			$video_sys_filename = $obj->_video_sys_filename;
		}

		$video_update = array();
		$img_update = array();

		$width = (int)$input->getInt('width');
		if ($width) {
			$video_update[] = '`width` = '.$width;
		}
		$height = (int)$input->getInt('height');
		if ($height) {
			$video_update[] = '`height` = '.$height;
		}
		$duration = $input->getString('duration');
		if ($duration and fwgHelper::checkTime($duration)) {
			$video_update[] = '`duration` = '.$db->quote($duration);
		} else {
			$duration = '';
		}

		$media = $input->getCmd('media', 'mp4');
		if (in_array($media, array('mp4'))) {
			if (is_null($image)) {
				$image = $input->files->get('file', null, 'raw');
			}
			if (!empty($image['tmp_name']) and empty($image['error'])) {
				$filename = '';
				$ext = strtolower(JFile::getExt($image['name']));
				if (in_array($ext, array('mp4'))) {
					$path = '';
					do {
						$filename = md5($image['name'].rand()).'.'.$ext;
						$path = fwgHelper::getImagePath($filename);
					} while(file_exists($path.$filename));
					if (!file_exists($path)) {
						JFile::write($path.'index.html', $buff = '<html><head><title></title></head><body></body></html>');
					}
					if (JFile::copy($image['tmp_name'], $path.$filename)) {
						$video_uploaded = true;
						$video_update[] = '`media`='.$db->quote($media);
						$video_update[] = '`filename`='.$db->quote($image['name']);
						$video_update[] = '`sys_filename`='.$db->quote($filename);
						$video_update[] = '`size`='.(int)filesize($path.$filename);
					}
				}
			}
		} elseif ($media_code = $input->getString('remote_code')) {
			$video_update[] = '`media`='.$db->quote($media);
			$filename = '';
			$ext = 'jpg';
			$path = '';

			switch ($media) {
				case 'youtube' :
					if (preg_match('/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/', $media_code, $match)) {
						$media_code = $match[5];
						if (!empty($match[6])) {
							$media_code .= $match[6];
						}
					}
					$video_update[] = '`code`='.$db->quote($media_code);
					if (!$image_exists and $buff = fwgHelper::request('https://img.youtube.com/vi/'.$media_code.'/0.jpg')) {
						do {
							$filename = md5($buff.rand()).'.'.$ext;
							$path = fwgHelper::getImagePath($filename);
						} while(file_exists($path.$filename));

						if (!JFile::write($path.$filename, $buff)) {
							$filename = '';
						}
					}
				break;
				case 'vimeo' :
					$file->media = $media;
					if (preg_match('#vimeo.com/(\d+)#i', $media_code, $m)) $media_code = $m[1];
					$video_update[] = '`code`='.$db->quote($media_code);
					if (!$image_exists and $buff = fwgHelper::request('https://vimeo.com/api/oembed.xml?url=https%3A%2F%2Fvimeo.com%2F'.$media_code) and preg_match('#<thumbnail_url>(.+)</thumbnail_url>#i', $buff, $m)) {
						if ($file_buff = fwgHelper::request($m[1])) {
							do {
								$filename = md5($file_buff.rand()).'.'.$ext;
								$path = fwgHelper::getImagePath($filename);
							} while(file_exists($path.$filename));

							if (!JFile::write($path.$filename, $file_buff)) {
								$filename = '';
							}
						}
					}
				break;
			}

			if ($filename) {
				$info = (array)getimagesize($path.$filename);
				$width = (int)JArrayHelper::getValue($info, 0);
				$height = (int)JArrayHelper::getValue($info, 1);
				$size = (int)filesize($path.$filename);

				if ($image_record_exists) {
					$db->setQuery('UPDATE #__fwsg_file_image SET width = '.$width.', height = '.$height.', size = '.(int)$size.', sys_filename = '.$db->quote($filename).', filename = '.$db->quote($media_code.'.'.$ext).' WHERE file_id = '.$file->id);
				} else {
					$db->setQuery('INSERT INTO #__fwsg_file_image SET width = '.$width.', height = '.$height.', size = '.(int)$size.', sys_filename = '.$db->quote($filename).', filename = '.$db->quote($media_code.'.'.$ext).', file_id = '.$file->id);
				}
				$db->execute();
			}
		}

		if ($video_update) {
			if ($video_uploaded and $video_sys_filename) {
				$path = fwgHelper::getImagePath($video_sys_filename);
				if (file_exists($path.$video_sys_filename)) {
					JFile::delete($path.$video_sys_filename);
				}
			}
			$query = ' #__fwsg_file_video SET '.implode(',', $video_update);
			if ($video_exists) {
				$db->setQuery('UPDATE'.$query.' WHERE file_id = '.$file->id);
			} else {
				$db->setQuery('INSERT INTO'.$query.', file_id = '.$file->id);
			}

			$db->execute();
		}

		fwgHelper::clearImageCache('f'.$file->id);
		if ($file->category_id) {
			fwgHelper::clearImageCache('с'.$file->category_id);
		}

	}
	function onAjaxVideo() {
		$data = new stdclass;
		$input = JFactory::getApplication()->input;
		switch ($input->getCmd('layout')) {
			case 'delete' :
			$data->result = $this->deleteVideo();
			break;
			case 'upload' :
			$data->result = $this->uploadVideo();
			break;
		}
		$data->msgs = fwgHelper::getMessages();
		return $data;
	}
	function deleteVideo() {
		$input = JFactory::getApplication()->input;
		$file = JTable::getInstance('File', 'Table');
		if ($id = $input->getInt('id') and $file->load($id)) {
			$file_deleted = false;
			if (!empty($file->_video_sys_filename)) {
				$path = fwgHelper::getImagePath($file->_video_sys_filename);
				if (is_file($path.$file->_video_sys_filename)) {
					$file_deleted = true;
					JFile::delete($path.$file->_video_sys_filename);
					$db = JFactory::getDBO();
					$db->setQuery('UPDATE `#__fwsg_file_video` SET sys_filename = \'\', sys_filename = \'\' WHERE file_id = '.$file->id);
					$db->execute();
					return true;
				} else fwgHelper::addMessage(JText::_('FWMG_FILE_TO_DELETE_NOT_FOUND'), 'warning');
			} else fwgHelper::addMessage(JText::_('FWMG_NO_FILE_TO_DELETE'), 'warning');
		} else fwgHelper::addMessage(JText::_('FWMG_NO_FILE_ID'), 'warning');
	}
	function uploadVideo() {
		$input = JFactory::getApplication()->input;
		$file = JTable::getInstance('File', 'Table');
		if ($id = $input->getInt('id')) {
			$file->load($id);
		}

		$file->type = 'video';
		if ($file->check()) {
			$file->store();
		} else fwgHelper::addMessage($file->getError(), 'danger');

		if ($file->id) {
			$file->load($file->id);
			return (object)array(
				'id' => $file->id,
				'filename' => $file->_video_filename,
				'video_size' => fwgHelper::humanFileSize($file->_video_size)
			);
		}
	}
	function onshowConfigFileListingDesignExtraFields($ext, $row) {
		if ($ext != 'com_fwgallery') return;

		echo fwgHelper::loadTemplate('admin.video.show_config_file_listing_design_extra_fields', array(
			'view' => $this,
			'row' => $row
		), dirname(__FILE__).'/layouts/');
	}
	function onshowConfigFileDesignExtraFields($ext, $row) {
		if ($ext != 'com_fwgallery') return;

		echo fwgHelper::loadTemplate('admin.video.show_config_file_design_extra_fields', array(
			'view' => $this,
			'row' => $row
		), dirname(__FILE__).'/layouts/');
	}
	function onshowCategoryEditFileListingDesignExtraFields($ext, $row) {
		if ($ext != 'com_fwgallery') return;

		echo fwgHelper::loadTemplate('admin.video.show_category_edit_file_listing_design_extra_fields', array(
			'view' => $this,
			'row' => $row
		), dirname(__FILE__).'/layouts/');
	}
	function onshowCategoryEditFileDesignExtraFields($ext, $row) {
		if ($ext != 'com_fwgallery') return;

		echo fwgHelper::loadTemplate('admin.video.show_category_edit_file_design_extra_fields', array(
			'view' => $this,
			'row' => $row
		), dirname(__FILE__).'/layouts/');
	}
	function ongetFileGoogleStructuredData($ext, $row, $view, $link, &$js, $num=0) {
		if ($ext != 'com_fwgallery.video') return;
		$js .= '
{
'.($num?'':'"@context": "http://schema.org",
').'"@type": "VideoObject",
"name": "'.$this->escape($row->name).'",
"description": "'.$this->escape(str_replace('&nbsp;', ' ', strip_tags($row->desc?$row->desc:$row->name))).'"';
			if ($this->isVideoExists($row)) {
				$js .= ',
"contentUrl": "'.JURI::root(false).ltrim(fwgHelper::getImageLink($row->_video_sys_filename), '/').$row->_video_sys_filename.'",
"encodingFormat": "'.mime_content_type(fwgHelper::getImagePath($row->_video_sys_filename).$row->_video_sys_filename).'"';
			}
			if (!empty($row->_video_size)) {
				$js .= ',
"contentSize": "'.fwgHelper::humanFileSize($row->_video_size).'"';
			}
			if (!empty($row->_video_duration)) {
				$buff = explode(':', $row->_video_duration);
				$time = '';
				if ($buff[0] != 0) $time.= $buff[0].'H';
				$time .= round($buff[1]).'M'.round($buff[2]).'S';

				$js .= ',
"duration": "T'.$time.'"';
			}
			if (!empty($row->_video_width) and !empty($row->_video_height)) {
				$js .= ',
"videoFrameSize": "'.$row->_video_width.'x'.$row->_video_height.'"';
			}

			$js .= ',
"url": "'.$link.'",
"uploadDate": "'.date('c', strtotime($row->created)).'",
"thumbnailUrl": "'.fwgHelper::route('index.php?option=com_fwgallery&view=item&layout=img&format=raw&w=96&h=96&id='.$row->id.':'.JFilterOutput::stringURLSafe($row->name), true, 1).'"
}
';
	}
	function escape($text) {
		return htmlspecialchars($text);
	}
}