Expresión regular para encontrar vídeos de YouTube en un texto
Con la siguiente expresión regular podremos encontrar los identificadores de los vídeos que se encuentren en vídeos de youtube (tanto como links como si están incrustados):
/youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)[&\w;=\+_\-]*/
Esto permite extraer el identificador único del vídeo, que sirve para enlazarlo, incrustarlo u obtener su imagen. Por ejemplo, para obtener la URL de la imagen thumnail del vídeo podremos usar:
preg_match('/youtube\.com\/watch\?v=([A-Za-z0-9._%-]*)[&\w;=\+_\-]*/',$texto);
$img="http://i2.ytimg.com/vi/{$match[1]}/default.jpg";
Vía | d0t101101 en el Foro de Drupal.
Mostrar un listado anidado de términos de taxonomía en Drupal
Buscando cómo mostrar un listado aninado de los términos (terms) de un vocabulario (una categoría de Drupal, o taxonomy), encontré este útil fragmento de código en Drupal.org. Para que funcione esto es necesario usar el módulo Taxonomy.
<?php
// El ID del vocabulario de la taxonomia del que queremos crear la lista de terminos
$vid = 10;
$depth = 0;
$num_at_depth = 0;
$tree = taxonomy_get_tree($vid);
print "<ul class=\"menu\">\n<li>";
foreach ($tree as $term) {
$diffdepth=0;
if ($term->depth > $depth) {
print "\n<ul>\n<li>";
$depth = $term->depth;
$num_at_depth = 0;
}
if ($term->depth < $depth) {
$diffdepth= $depth -$term->depth;
while ($diffdepth > 0){
print "</li>\n</ul>\n";
$diffdepth -- ;
}
$depth = $term->depth;
}
if (($term->depth == $depth) && ($num_at_depth > 0)) {
print "</li>\n<li>";
}
print l($term->name, 'taxonomy/term/' . $term->tid);
$num_at_depth ++;
}
print "</li>\n</ul>\n";
?> |
El crédito va al autor, billyboylindien