Les avertissements suivants se sont produits :
Warning [2] Undefined array key 0 - Line: 1640 - File: showthread.php PHP 8.2.18 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 1640 errorHandler->error_callback
/showthread.php 915 buildtree




Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5
appeler deux fois le même udt!
#5
+1 Jean ta technique fonctionne...

voici l'udt , avec lequel on peut appeler soit une vignette, soit l'image, soit l'iframe de la vidéo. Cela peut-être cool pour une gallery video, un carroussel (avec list2it par exemple) ou encore pour content-perso , un champ d'article etc...
  • {videos link="liensyoutube"} retourne l'id
  • {videos link="liensyoutube" action="default"}retourne l'id
  • {videos link="liensyoutube" action="thumb"}retourne une vignette
  • {videos link="liensyoutube" action="img"}retourne l'image
  • {videos link="liensyoutube" action="iframe"}retourne un iframe

Code :
[== PHP ==]
if (!function_exists(parse_youtube)) {
    function parse_youtube($link){

        $regexstr = '~
            # Match Youtube link and embed code
            (?:                             # Group to match embed codes
                (?:<iframe [^>]*src=")?       # If iframe match up to first quote of src
                |(?:                        # Group to match if older embed
                    (?:<object .*>)?      # Match opening Object tag
                    (?:<param .*</param>)*  # Match all param tags
                    (?:<embed [^>]*src=")?  # Match embed tag to the first quote of src
                )?                          # End older embed code group
            )?                              # End embed code groups
            (?:                             # Group youtube url
                https?:\/\/                 # Either http or https
                (?:[\w]+\.)*                # Optional subdomains
                (?:                         # Group host alternatives.
                youtu\.be/                  # Either youtu.be,
                | youtube\.com              # or youtube.com
                | youtube-nocookie\.com     # or youtube-nocookie.com
                )                           # End Host Group
                (?:\S*[^\w\-\s])?           # Extra stuff up to VIDEO_ID
                ([\w\-]{11})                # $1: VIDEO_ID is numeric
                [^\s]*                      # Not a space
            )                               # End group
            "?                              # Match end quote if part of src
            (?:[^>]*>)?                       # Match any extra stuff up to close brace
            (?:                             # Group to match last embed code
                </iframe>                 # Match the end of the iframe
                |</embed></object>          # or Match the end of the older embed
            )?                              # End Group of last bit of embed code
            ~ix';

        preg_match($regexstr, $link, $matches);

        return $matches[1];

    }
}
if(isset($params['link']) && $params['link'] !=""){
    $id=parse_youtube($params['link']);
    if($params['action'] =="thumb"){

        echo "<img src='http://img.youtube.com/vi/".$id."/2.jpg'>";

    }else if($params['action'] =="img"){
        echo "<img src='http://img.youtube.com/vi/".$id."/0.jpg'>";
    }else if($params['action'] =="iframe"){
        echo '<iframe width="560" height="315" src="//www.youtube.com/embed/'.$id.'" frameborder="0" allowfullscreen></iframe>';
    }else if($params['action'] =="default" || empty($params['action'])){
        echo $id;
    }
}

désolé par contre l'expression régulière n'est pas de moi et je trouve plus la source
Des chercheurs qui cherchent on en trouve mais des chercheurs qui trouvent on en cherche!!!!
Répondre


Messages dans ce sujet

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)