application/libraries/Tagmanager/Media.php
/**
	 * Filters the medias regarding the type, extension, range.
	 *
	 */
Filters the medias regarding the type, extension, range.
Filters the medias regarding the type extension range .
public static function filter_medias(FTL_Binding $tag, $medias)
	{
		$type = $tag->getAttribute('type');
		$extension = $tag->getAttribute('extension');
		$provider = $tag->getAttribute('provider');
		$limit = $tag->getAttribute('limit');
		if (is_null($limit))
			$limit = $tag->getAttribute('num');
		$range = $tag->getAttribute('range');
		if (!is_null($range))
			$range = explode(',', $range);
		$from = $to = FALSE;
		if (is_array($range))
		{
			$from = $range[0];
			$to = (isset($range[1]) && $range[1] >= $range[0]) ? $range[1] : FALSE;
		}
		$return = $tag->getAttribute('return', FALSE);
		$i = 0;
		if ( ! is_null($type))
		{
			$filtered_medias = array();
			if ( ! empty($medias))
			{
				foreach($medias as $media)
				{
					if ($media['type'] == $type && ($i < $limit OR is_null($limit)) )
					{
						if ( ! empty($media['lang_display']))
						{
							if ($media['lang_display'] == Settings::get_lang('current'))
								$filtered_medias[] = $media;						
						}
						else
							$filtered_medias[] = $media;
					}
				}
				if (!is_null($extension))
				{
					$extension = explode(',', $extension);
					$tmp_medias = $filtered_medias;
					$filtered_medias = array();
					foreach($tmp_medias as $media)
					{
						if (in_array($media['extension'], $extension))
						{
							$filtered_medias[] = $media;
						}
					}
				}
								if (!is_null($provider))
				{
					$tmp_medias = $filtered_medias;
					$filtered_medias = array();
					if ($provider == 'all')
					{
						foreach($tmp_medias as $media)
						{
							if ($media['provider'] != '')
								$filtered_medias[] = $media;
						}
					}
					else
					{
						foreach($tmp_medias as $media)
						{
							if ($media['provider'] == $provider)
								$filtered_medias[] = $media;
						}
					}
				}
				if ( ! empty($filtered_medias))
				{
					$attributes = $tag->getAttributes();
					$attributes = array_diff(array_keys($attributes), array('provider', 'type', 'size', 'method', 'limit', 'filter'));
					if ( ! empty($attributes))
					{
						foreach($attributes as $attribute)
						{
							$attribute_value = $tag->getAttribute($attribute);
							$tmp_medias = $filtered_medias;
							$filtered_medias = array();
							foreach($tmp_medias as $media)
							{
								if (isset($media[$attribute]))
								{
									if ($media[$attribute] == $attribute_value)
										$filtered_medias[] = $media;
								}
								else
									$filtered_medias[] = $media;
							}
						}
					}
				}
								if ( ! is_null($range))
				{
					$length = ($to !== FALSE) ? $to + 1 - $from  : count($filtered_medias) + 1 - $from;
					if ($limit > 0 && $limit < $length) $length = $limit;
					$from = $from -1;
					$filtered_medias = array_slice($filtered_medias, $from, $length);
				}
				else if ($limit > 0)
				{
					$filtered_medias = array_slice($filtered_medias, 0, $limit);
				}
			}
			return $filtered_medias;
		}
		return $medias;
	}
public static function filter_medias ( FTL_Binding $ tag , $ medias ) { $ type = $ tag -> getAttribute ( 'type' ) ; $ extension = $ tag -> getAttribute ( 'extension' ) ; $ provider = $ tag -> getAttribute ( 'provider' ) ; $ limit = $ tag -> getAttribute ( 'limit' ) ; if ( is_null ( $ limit ) ) $ limit = $ tag -> getAttribute ( 'num' ) ; $ range = $ tag -> getAttribute ( 'range' ) ; if ( ! is_null ( $ range ) ) $ range = explode ( ',' , $ range ) ; $ from = $ to = FALSE ; if ( is_array ( $ range ) ) { $ from = $ range [ 0 ] ; $ to = ( isset ( $ range [ 1 ] ) && $ range [ 1 ] >= $ range [ 0 ] ) ? $ range [ 1 ] : FALSE ; } $ return = $ tag -> getAttribute ( 'return' , FALSE ) ; $ i = 0 ; if ( ! is_null ( $ type ) ) { $ filtered_medias = array ( ) ; if ( ! empty ( $ medias ) ) { foreach ( $ medias as $ media ) { if ( $ media [ 'type' ] == $ type && ( $ i < $ limit OR is_null ( $ limit ) ) ) { if ( ! empty ( $ media [ 'lang_display' ] ) ) { if ( $ media [ 'lang_display' ] == Settings :: get_lang ( 'current' ) ) $ filtered_medias [ ] = $ media ; } else $ filtered_medias [ ] = $ media ; } } if ( ! is_null ( $ extension ) ) { $ extension = explode ( ',' , $ extension ) ; $ tmp_medias = $ filtered_medias ; $ filtered_medias = array ( ) ; foreach ( $ tmp_medias as $ media ) { if ( in_array ( $ media [ 'extension' ] , $ extension ) ) { $ filtered_medias [ ] = $ media ; } } } if ( ! is_null ( $ provider ) ) { $ tmp_medias = $ filtered_medias ; $ filtered_medias = array ( ) ; if ( $ provider == 'all' ) { foreach ( $ tmp_medias as $ media ) { if ( $ media [ 'provider' ] != '' ) $ filtered_medias [ ] = $ media ; } } else { foreach ( $ tmp_medias as $ media ) { if ( $ media [ 'provider' ] == $ provider ) $ filtered_medias [ ] = $ media ; } } } if ( ! empty ( $ filtered_medias ) ) { $ attributes = $ tag -> getAttributes ( ) ; $ attributes = array_diff ( array_keys ( $ attributes ) , array ( 'provider' , 'type' , 'size' , 'method' , 'limit' , 'filter' ) ) ; if ( ! empty ( $ attributes ) ) { foreach ( $ attributes as $ attribute ) { $ attribute_value = $ tag -> getAttribute ( $ attribute ) ; $ tmp_medias = $ filtered_medias ; $ filtered_medias = array ( ) ; foreach ( $ tmp_medias as $ media ) { if ( isset ( $ media [ $ attribute ] ) ) { if ( $ media [ $ attribute ] == $ attribute_value ) $ filtered_medias [ ] = $ media ; } else $ filtered_medias [ ] = $ media ; } } } } if ( ! is_null ( $ range ) ) { $ length = ( $ to !== FALSE ) ? $ to + 1 - $ from : count ( $ filtered_medias ) + 1 - $ from ; if ( $ limit > 0 && $ limit < $ length ) $ length = $ limit ; $ from = $ from - 1 ; $ filtered_medias = array_slice ( $ filtered_medias , $ from , $ length ) ; } else if ( $ limit > 0 ) { $ filtered_medias = array_slice ( $ filtered_medias , 0 , $ limit ) ; } } return $ filtered_medias ; } return $ medias ; }
Filters the medias regarding the type, extension, range.
Filters the medias regarding the type extension range .
// Media type // Media extension // Provider : For external medias // Number of wished displayed medias // DEPRECATED : Use limit instead. For compat. reasons // Range : Start and stop index, coma separated // Return list ?
 // If set to "list", will return the media list, coma separated. // Usefull for javascript // Not yet implemented // First get the correct media type // filter by type // Only filter on lang if lang_display is set for the media // Filter by extension if needed // Provider ?
 // Other filters // $keys = array_keys($filtered_medias[0]); // Range / Limit ?
