Tag Archive for drupal

Drupal print url args

<?php

print '<div align="left">';
print '<br/>arg-0 :' .arg(0);
print '<br/>arg-1 :' .arg(1);
print '<br/>arg-2 :' .arg(2);
print '<br/>q:' . $_GET['q'];

$view = $GLOBALS['current_view'];
$args = $view->args;

print '<br/>args-0 :' .$args[0];
print '<br/>args-1 :' .$args[1];

print '</div>';

?>

source

Programatically create imagecache image with html ( etc)

<?php print theme('imagecache', $preset, $image['filepath'], $alt, $title,  $attributes); ?>

source

function TF2007Theme_content_view_multiple_field

/**
* remove divs from multiple fields when grouping terms
*
*/ 
//this might cause errors cause we only want to avoid them for the speaker field. also this should be changed to an implode to get the list right

function MYtheme_content_view_multiple_field($items, $field, $values) {
if 
($field['field_name'] == 'field_speaker'){
  $output = implode(',', $items);
  return $output;}

else {$output = '';
  $i = 0;
  foreach ($items as $item) {
    if (!empty($item) || $item == '0') {
      $output .= '<p class="field-item field-item-'. $i .'">'. $item .'</p>';
      $i++;
    }
  }
  return $output;}
}

source

Usar funcion l()

<?php print l(t('Comprar en España'), 'varios/como_comprar',array('attributes' =>
            array(
                'class' => 'boton',
                'title' => t('Comprar en España'),
            )));
?>

source

Insertar Bloque

<?php
// Drupal 7

$block = module_invoke('views', 'block_view', 'blog-block');
print render($block); 

?>

<?php
   print '<div class="block_inter">';
/*otro
$block = module_invoke('block' ,'block', 'view', 2)
   $block = module_invoke('views', 'block', 'view', 'explore_menu-block_1');
*/
$block = module_invoke('simplenews' ,'block','view', 1);
   print '<h2>' . $block['subject'] . '</h2>';
   print $block['content'];
   print '</div>';

//OR

 print views_embed_view('mapa', 'block_2',$node->field_promocion[0]['nid']);
?>

source

Get Internal URL from URL Alias

<?php drupal_lookup_path('source',$url_alias); ?>

source

Drupal htaccess php_values (increase limits)

# PHP 4, Apache 1.
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
  php_value memory_limit                    96M
  php_value post_max_size                   32M
  php_value upload_max_filesize             32M
  php_value max_input_time                  180  
</IfModule>

# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
  php_value memory_limit                    96M
  php_value post_max_size                   32M
  php_value upload_max_filesize             32M
  php_value max_input_time                  180
</IfModule>

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
  php_value memory_limit                    96M
  php_value post_max_size                   32M
  php_value upload_max_filesize             32M
  php_value max_input_time                  180
</IfModule>

source

Set allowed integer values in CCK select list using PHP

$rows = array();
for ($i = -15; $i <= 15; $i++) {
  $rows[$i] = $i;
}
return $rows;

source

drupal – update core

wget drupal-x.xx.tar.gz; tar -xzf drupal-x.xx.tar.gz; cd drupal-x-xx;
rm -rf sites; rm .htaccess; rm robots.txt; 
cp -r ./* ../;

source

Remove style tags from Drupal node

<?php

$results = db_query("SELECT DISTINCT nid from node_revisions WHERE body REGEXP '<style>.*</style>' OR body REGEXP '<style>.*</style>'");

while($nid = db_result($results)) {
  $node = node_load($nid);
  unset($node->teaser);
  $node->body = preg_replace('@<style[^>]*?>.*?</style>@siu', '',$node->body);
  node_save($node);
}
?>

source