/** * @param FTL_Binding $tag * * @return string * */ public function tag_media(FTL_Binding $tag) { $parentName = $tag->getDataParentName(); // Standalone tag : Only one media is wished if ($parentName != 'medias') { $index = $tag->getAttribute('index', 0); $medias = $media = NULL; // Try to find medias if (!is_null($parentName)) { $medias = $tag->getParent()->getValue('medias', $parentName); } else { $article = self::registry('article'); $page = self::registry('page'); if (!empty($article['medias'])) { $medias = $article['medias']; } else { if (!empty($page['medias'])) { $medias = $article['medias']; } } } // Filter them, as usual if (!empty($medias)) { $medias = self::filter_medias($tag, $medias); } // Set the asked media if (!empty($medias) && isset($medias[$index])) { $tag->set('media', $medias[$index]); } } return $tag->expand(); }