<commit_before><?php
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

class Tracker_Field_Files extends Tracker_Field_Abstract
{
	public static function getTypes()
	{
		return array(
			'FG' => array(
				'name' => tr('Files'),
				'description' => tr('Attached and upload files stored in the file galleries to the tracker item.'),
				'prefs' => array('trackerfield_files', 'feature_file_galleries'),
				'tags' => array('advanced'),
				'help' => 'Files Tracker Field',
				'default' => 'y',
				'params' => array(
					'galleryId' => array(
						'name' => tr('Gallery ID'),
						'description' => tr('File gallery to upload new files into.'),
						'filter' => 'int',
					),
					'filter' => array(
						'name' => tr('MIME Type Filter'),
						'description' => tr('Mask for accepted MIME types in the field'),
						'filter' => 'text',
					),
					'count' => array(
						'name' => tr('File Count'),
						'description' => tr('Maximum number of files to be attached on the field.'),
						'filter' => 'int',
					),
					'displayImages' => array(
						'name' => tr('Display Images'),
						'description' => tr('Show files as images or object links'),
						'filter' => 'int',
						'options' => array(
							0 => tr('Links'),
							1 => tr('Images'),
						),
					),
					'imageParams' => array(
						'name' => tr('Image parameters'),
						'description' => tr('URL encoded params used as in the {img} plugin. e.g.') . ' max=400&desc=namedesc&stylebox=block"',
						'filter' => 'text',
					),
					'imageParamsForLists' => array(
						'name' => tr('Image parameters for lists'),
						'description' => tr('URL encoded params used as in the {img} plugin. e.g.') . ' "thumb=mouseover&rel="',
						'filter' => 'text',
					),
					'deepGallerySearch' => array(
						'name' => tr('Include Child Galleries'),
						'description' => tr('Use files from child galleries as well.'),
						'filter' => 'int',
						'options' => array(
							0 => tr('No'),
							1 => tr('Yes'),
						),
					),
				),
			),
		);
	}

	function getFieldData(array $requestData = array())
	{
		$galleryId = (int) $this->getOption(0);
		$count = (int) $this->getOption(2);
		$deepGallerySearch = (boolean) $this->getOption(6);

		$value = '';
		$ins_id = $this->getInsertId();
		if (isset($requestData[$ins_id])) {
			// Incoming data from form

			// Get the list of selected file IDs from the text field
			$value = $requestData[$ins_id];
			$fileIds = explode(',', $value);

			// Add manually uploaded files (non-HTML5 browsers only)
			foreach (array_keys($_FILES[$ins_id]['name']) as $index) {
				$fileIds[] = $this->handleUpload($galleryId, array(
					'name' => $_FILES[$ins_id]['name'][$index],
					'type' => $_FILES[$ins_id]['type'][$index],
					'size' => $_FILES[$ins_id]['size'][$index],
					'tmp_name' => $_FILES[$ins_id]['tmp_name'][$index],
				));
			}

			// Remove missed uploads
			$fileIds = array_filter($fileIds);

			// Keep only the first files if a limit is applied
			if ($count) {
				$fileIds = array_slice($fileIds, 0, $count);
			}

			// Obtain the info for display and filter by type if specified
			$fileInfo = $this->getFileInfo($fileIds);
			$fileInfo = array_filter($fileInfo, array($this, 'filterFile'));

			// Rebuild the database value
			$value = implode(',', array_keys($fileInfo));
		} else {
			$value = $this->getValue();

			// Obtain the information from the database for display
			$fileIds = array_filter(explode(',', $value));
			$fileInfo = $this->getFileInfo($fileIds);
			
			//this should probably be an option, this automatically updates the file to the latest file from a set of archives if there is one found
			foreach($fileInfo as $key => $file) {
				if ($file['archiveId'] > 0) {
					$newFile = $this->getFileInfo(array($file['archiveId']));
					unset($fileInfo[$key]);
					$fileInfo[$file['archiveId']] = $newFile[$file['archiveId']];
				}
			}
		}

		if ($deepGallerySearch) {
			$gallery_list = null;
			TikiLib::lib('filegal')->getGalleryIds($gallery_list, $galleryId, 'list');
			$gallery_list = implode( ' or ', $gallery_list );
		} else {<commit_msg>[DEL] Rollback of dynamic version updating fix<commit_after><?php
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

class Tracker_Field_Files extends Tracker_Field_Abstract
{
	public static function getTypes()
	{
		return array(
			'FG' => array(
				'name' => tr('Files'),
				'description' => tr('Attached and upload files stored in the file galleries to the tracker item.'),
				'prefs' => array('trackerfield_files', 'feature_file_galleries'),
				'tags' => array('advanced'),
				'help' => 'Files Tracker Field',
				'default' => 'y',
				'params' => array(
					'galleryId' => array(
						'name' => tr('Gallery ID'),
						'description' => tr('File gallery to upload new files into.'),
						'filter' => 'int',
					),
					'filter' => array(
						'name' => tr('MIME Type Filter'),
						'description' => tr('Mask for accepted MIME types in the field'),
						'filter' => 'text',
					),
					'count' => array(
						'name' => tr('File Count'),
						'description' => tr('Maximum number of files to be attached on the field.'),
						'filter' => 'int',
					),
					'displayImages' => array(
						'name' => tr('Display Images'),
						'description' => tr('Show files as images or object links'),
						'filter' => 'int',
						'options' => array(
							0 => tr('Links'),
							1 => tr('Images'),
						),
					),
					'imageParams' => array(
						'name' => tr('Image parameters'),
						'description' => tr('URL encoded params used as in the {img} plugin. e.g.') . ' max=400&desc=namedesc&stylebox=block"',
						'filter' => 'text',
					),
					'imageParamsForLists' => array(
						'name' => tr('Image parameters for lists'),
						'description' => tr('URL encoded params used as in the {img} plugin. e.g.') . ' "thumb=mouseover&rel="',
						'filter' => 'text',
					),
					'deepGallerySearch' => array(
						'name' => tr('Include Child Galleries'),
						'description' => tr('Use files from child galleries as well.'),
						'filter' => 'int',
						'options' => array(
							0 => tr('No'),
							1 => tr('Yes'),
						),
					),
				),
			),
		);
	}

	function getFieldData(array $requestData = array())
	{
		$galleryId = (int) $this->getOption(0);
		$count = (int) $this->getOption(2);
		$deepGallerySearch = (boolean) $this->getOption(6);

		$value = '';
		$ins_id = $this->getInsertId();
		if (isset($requestData[$ins_id])) {
			// Incoming data from form

			// Get the list of selected file IDs from the text field
			$value = $requestData[$ins_id];
			$fileIds = explode(',', $value);

			// Add manually uploaded files (non-HTML5 browsers only)
			foreach (array_keys($_FILES[$ins_id]['name']) as $index) {
				$fileIds[] = $this->handleUpload($galleryId, array(
					'name' => $_FILES[$ins_id]['name'][$index],
					'type' => $_FILES[$ins_id]['type'][$index],
					'size' => $_FILES[$ins_id]['size'][$index],
					'tmp_name' => $_FILES[$ins_id]['tmp_name'][$index],
				));
			}

			// Remove missed uploads
			$fileIds = array_filter($fileIds);

			// Keep only the first files if a limit is applied
			if ($count) {
				$fileIds = array_slice($fileIds, 0, $count);
			}

			// Obtain the info for display and filter by type if specified
			$fileInfo = $this->getFileInfo($fileIds);
			$fileInfo = array_filter($fileInfo, array($this, 'filterFile'));

			// Rebuild the database value
			$value = implode(',', array_keys($fileInfo));
		} else {
			$value = $this->getValue();

			// Obtain the information from the database for display
			$fileIds = array_filter(explode(',', $value));
			$fileInfo = $this->getFileInfo($fileIds);
			
		}

		if ($deepGallerySearch) {
			$gallery_list = null;
			TikiLib::lib('filegal')->getGalleryIds($gallery_list, $galleryId, 'list');
			$gallery_list = implode( ' or ', $gallery_list );
		} else {
{'fraction_non_alphanumeric': 0.1779865125240848, 'fraction_numerical': 0.0049373795761079, 'mean_word_length': 3.1838790931989926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 116, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4916554', 'n_tokens_mistral': 3377, 'n_tokens_neox': 2630, 'n_words': 735}