Get and print media templates from all types

@since   0.2.0
@since   0.9.0  Deprecate menu_icons_media_templates filter.
@wp_hook action print_media_templates
11609
public static function _media_templates() {
		$id_prefix = 'tmpl-menu-icons';

		// Deprecated.
		$templates = apply_filters( 'menu_icons_media_templates', array() );

		if ( ! empty( $templates ) ) {
			if ( WP_DEBUG ) {
				_deprecated_function( 'menu_icons_media_templates', '0.9.0', 'menu_icons_js_templates' );
			}

			foreach ( $templates as $key => $template ) {
				$id = sprintf( '%s-%s', $id_prefix, $key );
				self::_print_tempate( $id, $template );
			}
		}

		require_once dirname( __FILE__ ) . '/media-template.php';
	}
795098
public function getWidgetMapsForViewAndTemplates()
    {
        $widgetMaps = [];

        foreach ($this->getWidgetMaps() as $_widgetMap) {
            $widgetMaps[] = $_widgetMap;
        }

        if ($template = $this->getTemplate()) {
            $templateWidgetMaps = $template->getWidgetMapsForViewAndTemplates();
            $widgetMaps = array_merge($widgetMaps, $templateWidgetMaps);
        }

        return $widgetMaps;
    }
473217
public static function getTypes()
    {
        if (!self::$types) {
            $grav = Grav::instance();

            $scanBlueprintsAndTemplates = function () use ($grav) {
                // Scan blueprints
                $event = new Event();
                $event->types = self::$types;
                $grav->fireEvent('onGetPageBlueprints', $event);

                self::$types->scanBlueprints('theme://blueprints/');

                // Scan templates
                $event = new Event();
                $event->types = self::$types;
                $grav->fireEvent('onGetPageTemplates', $event);

                self::$types->scanTemplates('theme://templates/');
            };

            if ($grav['config']->get('system.cache.enabled')) {
                /** @var Cache $cache */
                $cache = $grav['cache'];

                // Use cached types if possible.
                $types_cache_id = md5('types');
                self::$types = $cache->fetch($types_cache_id);

                if (!self::$types) {
                    self::$types = new Types();
                    $scanBlueprintsAndTemplates();
                    $cache->save($types_cache_id, self::$types);
                }

            } else {
                self::$types = new Types();
                $scanBlueprintsAndTemplates();
            }

            // Register custom paths to the locator.
            $locator = $grav['locator'];
            foreach (self::$types as $type => $paths) {
                foreach ($paths as $k => $path) {
                    if (strpos($path, 'blueprints://') === 0) {
                        unset($paths[$k]);
                    }
                }
                if ($paths) {
                    $locator->addPath('blueprints', "pages/$type.yaml", $paths);
                }
            }
        }

        return self::$types;
    }
495732
private function printMenuTree() {
		/*
		* The elements in the array are :
		*   0: Menu item name
		*   1: Minimum level or capability required.
		*   2: The URL of the item's file
		*   3: Class
		*   4: ID
		*   5: Icon for top level menu
		*/
		global $menu, $submenu;
		if ( ! is_iterable( $menu ) ) {
			return;
		}

		echo '<ul class="ul-disc">';
		foreach ( $menu as $arr1 ) {
			if ( empty( $arr1[0] ) ) {
				continue;
			}
			$menu_hook = get_plugin_page_hook( $arr1[2], null );
			if ( $menu_hook ) {
				$href = 'admin.php?page=' . $arr1[2];
			} else {
				$href = $arr1[2];
			}
			echo "<li><a href='{$href}'>{$arr1[0]}</a>";
			foreach ( $submenu as $k => $arr2 ) {
				if ( $k === $arr1[2] ) {
					echo '<ul class="ul-disc">';
					foreach ( $arr2 as $arr3 ) {
						$menu_hook = get_plugin_page_hook( $arr3[2], $k );
						if ( $menu_hook ) {
							if ( str_ends_with( $k, '.php' ) ) {
								$href = "{$k}?page={$arr3[2]}";
							} else {
								$href = "admin.php?page={$arr3[2]}";
							}
						} else {
							$href = $arr3[2];
						}
						echo "<li><a href='{$href}'>{$arr3[0]}</a>";
					}
					echo '</ul>';
					continue;
				}
			}
		}
		echo '</ul>';
	}
262475
public function get_button_labels() {
		// Get just the mime type and strip the mime subtype if present.
		$mime_type = ! empty( $this->mime_type )
			? strtok( ltrim( $this->mime_type, '/' ), '/' )
			: 'default';

		switch ( $mime_type ) {
			case 'video':
				return [
					'select'       => esc_html__( 'Select video', 'wplibs-form' ),
					'change'       => esc_html__( 'Change video', 'wplibs-form' ),
					'default'      => esc_html__( 'Default', 'wplibs-form' ),
					'remove'       => esc_html__( 'Remove', 'wplibs-form' ),
					'placeholder'  => esc_html__( 'No video selected', 'wplibs-form' ),
					'frame_title'  => esc_html__( 'Select video', 'wplibs-form' ),
					'frame_button' => esc_html__( 'Choose video', 'wplibs-form' ),
				];
			case 'audio':
				return [
					'select'       => esc_html__( 'Select audio', 'wplibs-form' ),
					'change'       => esc_html__( 'Change audio', 'wplibs-form' ),
					'default'      => esc_html__( 'Default', 'wplibs-form' ),
					'remove'       => esc_html__( 'Remove', 'wplibs-form' ),
					'placeholder'  => esc_html__( 'No audio selected', 'wplibs-form' ),
					'frame_title'  => esc_html__( 'Select audio', 'wplibs-form' ),
					'frame_button' => esc_html__( 'Choose audio', 'wplibs-form' ),
				];
			case 'image':
				return [
					'select'       => esc_html__( 'Select image', 'wplibs-form' ),
					'change'       => esc_html__( 'Change image', 'wplibs-form' ),
					'default'      => esc_html__( 'Default', 'wplibs-form' ),
					'remove'       => esc_html__( 'Remove', 'wplibs-form' ),
					'placeholder'  => esc_html__( 'No image selected', 'wplibs-form' ),
					'frame_title'  => esc_html__( 'Select image', 'wplibs-form' ),
					'frame_button' => esc_html__( 'Choose image', 'wplibs-form' ),
				];
			default:
				return [
					'select'       => esc_html__( 'Select file', 'wplibs-form' ),
					'change'       => esc_html__( 'Change file', 'wplibs-form' ),
					'default'      => esc_html__( 'Default', 'wplibs-form' ),
					'remove'       => esc_html__( 'Remove', 'wplibs-form' ),
					'placeholder'  => esc_html__( 'No file selected', 'wplibs-form' ),
					'frame_title'  => esc_html__( 'Select file', 'wplibs-form' ),
					'frame_button' => esc_html__( 'Choose file', 'wplibs-form' ),
				];
		} // End switch().
	}
396960
protected function get_media_types() {
		$media_types = array();
		foreach ( get_allowed_mime_types() as $mime_type ) {
			$parts = explode( '/', $mime_type );
			if ( ! isset( $media_types[ $parts[0] ] ) ) {
				$media_types[ $parts[0] ] = array();
			}
			$media_types[ $parts[0] ][] = $mime_type;
		}
		return $media_types;
	}
1288084
public function get_template_titles() {

		static $template_titles;

		if ( empty( $template_titles ) ) {
			$all_templates = (array) pods_api()->load_templates( array() );

			$template_titles = array();

			foreach ( $all_templates as $template ) {
				$template_titles[] = $template['name'];
			}
		}

		return $template_titles;

	}
1156667
public function template($template = false, $layout = false)
    {
        deprecationWarning(
            'Email::template() is deprecated. ' .
            'Use $email->viewBuilder()->getTemplate()/setTemplate() ' .
            'and $email->viewBuilder()->getLayout()/setLayout() instead.'
        );

        if ($template === false) {
            return [
                'template' => $this->getTemplate(),
                'layout' => $this->getLayout()
            ];
        }
        $this->setTemplate($template);
        if ($layout !== false) {
            $this->setLayout($layout);
        }

        return $this;
    }
786714
public function listAction()
    {
        $repository = $this->get('phlexible_media_template.template_manager');

        $allTemplates = $repository->findAll();

        $templates = [];
        foreach ($allTemplates as $template) {
            if (substr($template->getKey(), 0, 4) === '_mm_') {
                continue;
            }

            $templates[] = [
                'key' => $template->getKey(),
                'type' => $template->getType(),
            ];
        }

        return new JsonResponse(['templates' => $templates]);
    }
1025076
public function renderTemplates()
    {
        $html = '';

        if ($this->getOption('debug')) {
            $html .= "\n\n<!-- Start Asset Template -->\n\n";
        }

        foreach ($this->templates as $name => $template) {
            if ($this->getOption('debug')) {
                $html .= sprintf("\n<!-- $name -->\n");
            }

            $html .= $template;
        }

        return $html;
    }
1291111
def media_types():
    
    if not hasattr(media_types, 'typelist'):
        tlist = []
        categories = [
            'application',
            'audio',
            'font',
            'image',
            'message',
            'model',
            'multipart',
            'text',
            'video'
        ]
        for cat in categories:
            try:
                data = requests.get('http://www.iana.org/assignments/'
                                    'media-types/%s.csv' % cat)
            except requests.exceptions.RequestException:
                return []

            types = []
            for line in data.iter_lines():
                if line:
                    line = line.decode("utf-8")
                    if line.count(',') > 0:
                        reg_template = line.split(',')[1]
                        if reg_template:
                            types.append(reg_template)
                        else:
                            types.append(cat + '/' + line.split(',')[0])

            tlist.extend(types)
        media_types.typelist = tlist
    return media_types.typelist
486842
protected function render_media(): string
    {
        \add_action('admin_enqueue_scripts', function () {
            \wp_enqueue_media();
        });

        $this->meta['disabled'] = 'disabled';

        $html = '<input id="'.\esc_attr($this->id).'" type="hidden" name="'.\esc_attr($this->name).'" value="'.
            \esc_attr($this->value).'" />';

        $html .= '<input '.$this->metaString().' id="'.
            \esc_attr($this->id).'-url" type="text" name="" value="'.
            \esc_attr(\wp_get_attachment_url($this->value)).'" />';

        $html .= ' <button id="'.
            \esc_attr($this->id).'-button" class="button">'.
            \esc_html__('Select', 'grotto-wp-field').
        '</button>';

        $html .= ' <button id="'.\esc_attr($this->id).
            '-delete" class="button submitdelete">'.
            \esc_html__('Delete', 'grotto-wp-field').
        '</button>';

        $html .= '
        <script type="text/javascript">
            (function($) {
                var grotto_uploader, attachment;';

                $html .= '
                $("#'.\esc_attr($this->id).'-button").click(function(e) {
                    e.preventDefault();';

                    $html .= '
                    if (grotto_uploader) {
                        grotto_uploader.open();
                        return;
                    }';

                    $html .= '
                    grotto_uploader = wp.media.frames.file_frame = wp.media({
                        title: "'.\esc_html__('Upload file', 'grotto-wp-field').'",
                        button: {
                            text: "'.\esc_html__('Use file', 'grotto-wp-field').'"
                        },
                        multiple: false
                    });';

                    $html .= '
                    grotto_uploader.on("select", function() {
                        attachment = grotto_uploader.state().get("selection").first().toJSON();
                        $("#'.\esc_attr($this->id).'-url").val(attachment.url);
                        $("#'.\esc_attr($this->id).'").val(attachment.id);
                    });';

                    $html .= '
                    grotto_uploader.open();
                });';

                $html .= '
                $("#'.\esc_attr($this->id).'-delete").click(function(e) {
                    e.preventDefault();';

                    $html .= '
                    $("#'.\esc_attr($this->id).'").val(0);
                    $("#'.\esc_attr($this->id).'-url").val("");
                });
            })(jQuery);
        </script>';

        return $html;
    }
678167
private function getMediaTypes()
    {
        $counter = 1;

        $types = [];
        $types[$counter++] = 'None';
        $types[$counter++] = 'File';
        $types[$counter++] = 'Image';
        $types[$counter++] = 'Video';

        return $types;
    }
481517
public function featureEmojicons()
    {
        remove_action('wp_head', 'print_emoji_detection_script', 7);
        remove_action('admin_print_scripts', 'print_emoji_detection_script');
        remove_action('wp_print_styles', 'print_emoji_styles');
        remove_action('admin_print_styles', 'print_emoji_styles');
        remove_filter('the_content_feed', 'wp_staticize_emoji');
        remove_filter('comment_text_rss', 'wp_staticize_emoji');
        remove_filter('wp_mail', 'wp_staticize_emoji_for_email');

        add_filter('tiny_mce_plugins', function ($plugins) {
            return is_array($plugins) ? array_diff($plugins, ['wpemoji']) : [];
        });

        add_filter('wp_resource_hints', function ($urls, $relation_type) {
            if ('dns-prefetch' === $relation_type) {
                $emoji_url = 'https://s.w.org/images/core/emoji/';

                foreach ($urls as $key => $url) {
                    if (false !== strpos($url, $emoji_url)) {
                        unset($urls[$key]);
                    }
                }
            }

            return $urls;
        }, 10, 2);
    }
641355
public function postFormatMeta()
    {
        $output = [];

        $format = get_post_format();
        if (current_theme_supports('post-formats', $format)) {
            $output[] = '<div class="meta-format">';
            $output[] = sprintf(
                '<span class="entry-format">%s<a href="%s">%s</a></span>',
                sprintf('<span class="sr-only">%s</span>', _x('Format', 'Used before post format', 'novusopress')),
                esc_url(get_post_format_link($format)),
                get_post_format_string($format)
            );
            $output[] = '</div>';
        }

        return apply_filters('novusopress_view_post_format_meta_output', implode('', $output));
    }
1118035
public function getMediaType() : ?string 
    {
        if ( ! $this->hasMediaType()) {
            $this->setMediaType($this->getDefaultMediaType());
        }
        return $this->mediaType;
    }
1220523
function mf_metabox_template () {
    global $post;

    if ( 0 != count( get_page_templates() ) ) {

      $template = get_post_meta($post->ID, '_wp_mf_page_template', TRUE);
      $template =  ($template != '') ? $template : false;
    ?>
      <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select name="page_template" id="page_template">
      <option value='default'><?php _e('Default Template'); ?></option>
      <?php page_template_dropdown($template); ?>
      </select>
    <?php
    }
  }