Esempio n. 1
0
 protected function getInput()
 {
     $params = JUDownloadHelper::getParams();
     $max_upload = ini_get('upload_max_filesize');
     $src = JUri::root() . JUDownloadFrontHelper::getDirectory("collection_icon_directory", "media/com_judownload/images/collection/", true) . $this->value;
     $html = "<div class=\"avatar\" style=\"float: left;\">";
     if ($this->value) {
         $html .= "<div class=\"clearfix\"><img src=\"" . $src . "\" width=\"" . $params->get('collection_icon_width', 100) . "px\" height=\"" . $params->get('collection_icon_height', 100) . "px\" /></div>";
         $html .= "<label><input type=\"checkbox\" name=\"remove_icon\" value=\"1\" />&nbsp;" . JText::_('COM_JUDOWNLOAD_REMOVE_ICON') . "</label>";
     }
     $html .= "<div class=\"clearfix\"><input type=\"file\" name=\"collection_icon\"  id=\"" . $this->id . "\" />";
     $html .= "<input type=\"hidden\" name=\"" . $this->name . "\" value=\"" . $this->value . "\" /></div>";
     $html .= "<div class=\"clearfix\"><i>" . JText::_('COM_JUDOWNLOAD_MAX_UPLOAD_FILESIZE') . " <strong>" . JUDownloadHelper::formatBytes($this->convertBytes($max_upload)) . "</strong></i></div>";
     $html .= "</div>";
     return $html;
 }
Esempio n. 2
0
 protected function getInput()
 {
     $params = JUDownloadHelper::getParams();
     $max_upload = ini_get('upload_max_filesize');
     if ($this->value) {
         $src = JUri::root(true) . "/" . JUDownloadFrontHelper::getDirectory("avatar_directory", "media/com_judownload/images/avatar/", true) . $this->value;
     } else {
         $src = JUri::root(true) . "/" . JUDownloadFrontHelper::getDirectory("avatar_directory", "media/com_judownload/images/avatar/", true) . "default/" . $params->get('default_avatar', 'default-avatar.png');
     }
     $html = '<div class="avatar" style="float: left;">';
     $html .= '<div class="clearfix"><img src="' . $src . '" alt="Avatar" style="width:' . $params->get("avatar_width", 120) . 'px; height:' . $params->get("avatar_height", 120) . 'px;" /></div>';
     if ($this->value) {
         $html .= '<label for="remove-avatar">' . JText::_("COM_JUDOWNLOAD_REMOVE_AVATAR") . '&nbsp;<input id="remove-avatar" type="checkbox" name="remove_avatar" value="1" /></label>';
     }
     $html .= '<div class="clearfix"><input type="file" name="avatar"  id="' . $this->id . '" />';
     $html .= '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '" /></div>';
     $html .= '<div class="clearfix"><i>' . JText::_("COM_JUDOWNLOAD_MAX_UPLOAD_FILESIZE") . ' <strong>' . JUDownloadHelper::formatBytes($this->convertBytes($max_upload)) . '</strong></i></div>';
     $html .= '</div>';
     return $html;
 }
Esempio n. 3
0
        ?>
][rename]" id="file-name-<?php 
        echo $key;
        ?>
" class="file-name validate-filename required" type="text" value="<?php 
        echo $file['rename'];
        ?>
" placeholder="<?php 
        echo JText::_('COM_JUDOWNLOAD_FILE_NAME');
        ?>
"/>
                                    <span class="file-size add-on" title="<?php 
        echo JText::_('COM_JUDOWNLOAD_MIME_TYPE') . ': ' . $file['mime_type'];
        ?>
"><?php 
        echo JUDownloadHelper::formatBytes($file['size']);
        ?>
</span>
	                                <input type="hidden" name="judlfiles[<?php 
        echo $key;
        ?>
][size]" class="file-size-value" value="<?php 
        echo $file['size'];
        ?>
" />
                                </div>
								<?php 
        if ($file['id']) {
            ?>
									<div class="file-replace-uploader" style="display: none">
										<div class="upload-message"><?php 
Esempio n. 4
0
	public function getInput($fieldValue = null)
	{
		if (!$this->isPublished())
		{
			return "";
		}

		$this->loadDefaultAssets();

		
		if (isset($this->doc) && $this->doc->cat_id)
		{
			$params = JUDownloadHelper::getParams($this->doc->cat_id);
		}
		else
		{
			$params = JUDownloadHelper::getParams(null, $this->doc_id);
		}

		$max_upload = ini_get('upload_max_filesize');
		$max_upload = JUDownloadHelper::formatBytes(self::convertBytes($max_upload));

		$value    = !is_null($fieldValue) ? $fieldValue : $this->value;
		$icon_src = JUDownloadHelper::getDocumentIcon($value);

		$this->setAttribute("type", "file", "input");
		
		if (!$this->value)
		{
			$this->addAttribute("class", "validate-images", "input");
			$this->addAttribute("class", $this->getInputClass(), "input");
		}

		$this->setVariable('icon_src', $icon_src);
		$this->setVariable('max_upload', $max_upload);
		$this->setVariable('params', $params);
		$this->setVariable('value', $value);

		return $this->fetch('input.php', __CLASS__);
	}
Esempio n. 5
0
	public static function getFilesByDocumentId($docId)
	{
		$db    = JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from('#__judownload_files');
		$query->where('doc_id = ' . $docId);
		$query->where('published = 1');
		$db->setQuery($query);
		$files = $db->loadObjectList();

		foreach ($files AS $key => $file)
		{
			$file->size  = JUDownloadHelper::formatBytes($file->size);
			$files[$key] = $file;
		}

		return $files;
	}
Esempio n. 6
0
	public static function validateImageFile($file)
	{
		$app = JFactory::getApplication();
		if (empty($file['name']))
		{
			return false;
		}
		if (!JFile::exists($file['tmp_name']))
		{
			$app->enqueueMessage(JText::_('COM_JUDOWNLOAD_FILE_NOT_FOUND'), 'error');

			return false;
		}

		$format = strtolower(JFile::getExt($file['name']));

		
		$executable = array(
			'php', 'js', 'exe', 'phtml', 'java', 'perl', 'py', 'asp', 'dll', 'go', 'ade', 'adp', 'bat', 'chm', 'cmd', 'com', 'cpl', 'hta', 'ins', 'isp',
			'jse', 'lib', 'mde', 'msc', 'msp', 'mst', 'pif', 'scr', 'sct', 'shb', 'sys', 'vb', 'vbe', 'vbs', 'vxd', 'wsc', 'wsf', 'wsh'
		);

		$explodedFileName = explode('.', $file['name']);
		if (count($explodedFileName) > 2)
		{
			foreach ($executable AS $extensionName)
			{
				if (in_array($extensionName, $explodedFileName))
				{
					$app->enqueueMessage(JText::_('COM_JUDOWNLOAD_INVALID_FILE_TYPE'), 'error');

					return false;
				}
			}
		}

		$params = JUDownloadHelper::getParams();

		$allowable = $params->get('upload_extensions', 'bmp,gif,jpg,png');
		$allowable = explode(',', strtolower(str_replace("\n", ",", trim($allowable))));
		if ($format == '' || $format == false || (!in_array($format, $allowable)))
		{
			$app->enqueueMessage(JText::sprintf('COM_JUDOWNLOAD_INVALID_FILE_TYPE', $format), 'error');

			return false;
		}

		
		$maxSize          = (int) ($params->get('image_max_size', 400) * 1024);
		$maxSizeFormatted = JUDownloadHelper::formatBytes($maxSize);
		if ($maxSize > 0 && (int) $file['size'] > $maxSize)
		{
			$app->enqueueMessage(JText::sprintf('COM_JUDOWNLOAD_REACH_MAX_FILE_SIZE', $maxSizeFormatted), 'error');

			return false;
		}

		$imgInfo = null;

		
		if (!empty($file['tmp_name']))
		{
			if (($imgInfo = getimagesize($file['tmp_name'])) === false)
			{
				$app->enqueueMessage(JText::_('COM_JUDOWNLOAD_INVALID_IMAGE_FILE'), 'error');

				return false;
			}
		}
		else
		{
			$app->enqueueMessage(JText::sprintf('COM_JUDOWNLOAD_REACH_MAX_FILE_SIZE', $maxSizeFormatted), 'error');

			return false;
		}

		$xss_check = JFile::read($file['tmp_name'], false, 256);
		$html_tags = array('abbr', 'acronym', 'address', 'applet', 'area', 'audioscope', 'base', 'basefont', 'bdo', 'bgsound', 'big', 'blackface', 'blink', 'blockquote', 'body', 'bq', 'br', 'button', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'comment', 'custom', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'fn', 'font', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'iframe', 'ilayer', 'img', 'input', 'ins', 'isindex', 'keygen', 'kbd', 'label', 'layer', 'legend', 'li', 'limittext', 'link', 'listing', 'map', 'marquee', 'menu', 'meta', 'multicol', 'nobr', 'noembed', 'noframes', 'noscript', 'nosmartquotes', 'object', 'ol', 'optgroup', 'option', 'param', 'plaintext', 'pre', 'rt', 'ruby', 's', 'samp', 'script', 'select', 'server', 'shadow', 'sidebar', 'small', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', 'ul', 'var', 'wbr', 'xml', 'xmp', '!DOCTYPE', '!--');
		foreach ($html_tags AS $tag)
		{
			
			if (stristr($xss_check, '<' . $tag . ' ') || stristr($xss_check, '<' . $tag . '>'))
			{
				$app->enqueueMessage(JText::_('COM_JUDOWNLOAD_IEXSS_WARNING'), 'error');

				return false;
			}
		}

		return true;
	}
Esempio n. 7
0
										<i class="fa fa-close"></i> <?php echo JText::_('COM_JUDOWNLOAD_PUBLISH'); ?>
									<?php
									}?>
								</span>
								<input type="hidden" name="judlfiles[<?php echo $key; ?>][published]" class="file-published-value" value="<?php echo $file['published'] ? 1 : 0 ?>" />

								<span class="remove btn btn-mini" data-iconremove="fa fa-trash-o" data-iconunremove="fa fa-undo">
									<i class="fa fa-trash-o"></i> <?php echo JText::_('COM_JUDOWNLOAD_DELETE'); ?>
								</span>
								<input type="hidden" name="judlfiles[<?php echo $key; ?>][remove]" class="file-remove-value" value="0" />
							</div>

							<div class="file-row">
                                <div class="file-name-info input-append">
                                    <input name="judlfiles[<?php echo $key; ?>][rename]" id="file-name-<?php echo $key; ?>" class="file-name validate-filename required" type="text" value="<?php echo $file['rename'] ?>" placeholder="<?php echo JText::_('COM_JUDOWNLOAD_FILE_NAME'); ?>"/>
                                    <span class="file-size add-on" title="<?php echo JText::_('COM_JUDOWNLOAD_MIME_TYPE') . ': ' . $file['mime_type']; ?>"><?php echo JUDownloadHelper::formatBytes($file['size']); ?></span>
	                                <input type="hidden" name="judlfiles[<?php echo $key; ?>][size]" class="file-size-value" value="<?php echo $file['size']; ?>" />
                                </div>
								<?php
								if($file['id'])
								{?>
									<div class="file-replace-uploader" style="display: none">
										<div class="upload-message"><?php echo JText::_("COM_JUDOWNLOAD_YOUR_BROWSER_DOESNT_HAVE_FLASH_SILVERLIGHT_OR_HTML5_SUPPORT"); ?></div>
										<div class="upload-progress progress progress-striped active" style="margin-bottom: 5px;">
											<div class="bar">
												<div class="upload-file-name"></div>
											</div>
										</div>
										<div class="file-replace-container">
											<span class="pickfiles btn btn-mini"><i class="fa fa-plus"></i> <?php echo JText::_('COM_JUDOWNLOAD_SELECT_FILE'); ?></span>
											<span class="uploadfiles disabled btn btn-mini"><i class="fa fa-upload"></i> <?php echo JText::_('COM_JUDOWNLOAD_UPLOAD'); ?></span>
Esempio n. 8
0
	public function filterField($values)
	{
		$oldImages = $values;
		$app       = JFactory::getApplication();
		$newImages = $app->input->files->get('field_' . $this->id);

		$gallery = $gallery['old'] = $gallery['new'] = array();

		$params         = JUDownloadHelper::getParams(null, $this->doc_id);
		$maxUploadImage = 4;
		$count          = 0;

		if ($this->doc_id)
		{
			$db    = JFactory::getDbo();
			$query = 'SELECT id FROM #__judownload_images WHERE doc_id = ' . (int) $this->doc_id;
			$db->setQuery($query);
			$imageIds = $db->loadColumn();

			foreach ($oldImages AS $key => $image)
			{
				if (!in_array($image['id'], $imageIds))
				{
					continue;
				}

				if ($maxUploadImage > 0 && $count >= $maxUploadImage)
				{
					break;
				}

				$gallery['old'][] = $image;

				if (!$image['remove'])
				{
					$count++;
				}
			}
		}

		$error = array();
		if ($newImages && (($count < $maxUploadImage && $maxUploadImage > 0) || $maxUploadImage <= 0))
		{
			$legal_extensions            = "jpeg,jpg,png,gif,bmp";
			$legal_mime                  = "image/jpeg,image/pjpeg,image/png,image/gif,image/bmp,image/x-windows-bmp";
			$image_min_width             = $params->get("image_min_width", 50);
			$image_min_height            = $params->get("image_min_height", 50);
			$image_max_width             = $params->get("image_max_width", 1024);
			$image_max_height            = $params->get("image_max_height", 1024);
			$image_max_size              = $params->get("image_max_size", 400) * 1024;
			$num_files_exceed_limit      = 0;
			$num_files_invalid_dimension = 0;
			foreach ($newImages AS $image)
			{
				if ($image['name'])
				{
					$image['name'] = str_replace(' ', '_', JFile::makeSafe($image['name']));

					if ($count >= $maxUploadImage)
					{
						$num_files_exceed_limit++;
						continue;
					}

					if (!JUDownloadFrontHelperPermission::canUpload($image, $error, $legal_extensions, $image_max_size, true, $legal_mime, '', $legal_extensions))
					{
						continue;
					}

					$image_dimension = getimagesize($image['tmp_name']);

					if ($image_dimension[0] < $image_min_width || $image_dimension[1] < $image_min_height || $image_dimension[0] > $image_max_width || $image_dimension[1] > $image_max_height)
					{
						$num_files_invalid_dimension++;
						continue;
					}

					$gallery['new'][] = $image;
					$count++;
				}
			}

			$app = JFactory::getApplication();

			if ($error)
			{
				foreach ($error AS $key => $count)
				{
					switch ($key)
					{
						case 'WARN_SOURCE':
						case 'WARN_FILENAME':
						case 'WARN_FILETYPE':
						case 'WARN_FILETOOLARGE' :
						case 'WARN_INVALID_IMG' :
						case 'WARN_INVALID_MIME' :
						case 'WARN_IEXSS' :
							$error_str = JText::plural("COM_JUDOWNLOAD_N_FILE_" . $key, $count);
							break;
					}

					$app->enqueueMessage($error_str, 'notice');
				}
			}

			if ($num_files_exceed_limit)
			{
				$image_upload_limit = JUDownloadHelper::formatBytes($image_max_size * 1024);
				$app->enqueueMessage(JText::plural('COM_JUDOWNLOAD_N_IMAGES_ARE_NOT_SAVED_BECAUSE_THEY_EXCEEDED_FILE_SIZE_LIMIT', $num_files_exceed_limit, $image_upload_limit), 'notice');
			}

			if ($num_files_invalid_dimension)
			{
				$app->enqueueMessage(JText::plural('COM_JUDOWNLOAD_N_IMAGES_ARE_NOT_SAVED_BECAUSE_THEY_ARE_NOT_VALID_DIMENSION', $num_files_invalid_dimension, $image_min_width, $image_max_width, $image_min_height, $image_max_height), 'notice');
			}
		}

		$gallery['count'] = $count;

		return $gallery;
	}