Mai 12 2012

Drupal 7: Using Rate Widget in Blocks or Panels

<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && ($node = node_load(arg(1)))) {
  print rate_embed($node, 'NAME');
}
?>

Replace NAME by the widget’s machine readable name.


Mai 11 2012

Facebook: Anzahl der Freunde ohne Widget


<?php
$page_id = "123456xxxxxx";
 $xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&amp;amp;amp;query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("a lot");
$fans = $xml->page->fan_count;

echo $fans;
?>

gefunden auf http://www.perun.net/


Mai 8 2012

Drupal 7 Panels: leeres Feld per visibility rule ausblenden

visibility rule type: PHP Code

$node = $contexts['argument_entity_id:node_1']->data;
if(count($node->field_fieldname) !=0
{
   return TRUE;
}

Mai 8 2012

line spacing fix – sup and sub

<style type="text/css">
sup,
sub {
	height: 0;
	line-height: 1;
	vertical-align: baseline;
	_vertical-align: bottom;
	position: relative;
}
sup {
	bottom: 1ex;
}
sub {
	top: .5ex;
}
</style>

Aug 8 2011

Drupal: Facebook ‘Like’ Button wird im Internet Explorer nicht angezeigt

You (in fact module) should include this code in page.tpl.php to work with IE. Do not remove other xml related things in html tag if exist, just add this two xmlns defs then.

<html xmlns:og="http://opengraphprotocol.org/schema/"
      xmlns:fb="http://www.facebook.com/2008/fbml">

Aug 5 2011

Drupal Views: Tabellen – leere Spalten ausblenden

views-view-table.tpl.php

<?php
/**
* Product Table View customized so that any columns with no data are omitted from display.
*/
foreach ($rows as $count => $row):
    foreach ($row as $field => $content):
      if ($content) $column_has_content[ $field ] = true;
    endforeach;
endforeach;
?>

<table class="<?php print $class; ?>">
  <?php if (!empty($title)) : ?>
    <caption><?php print $title; ?></caption>
  <?php endif; ?>
  <thead>
    <tr>
      <?php foreach ( $header as $field => $label ): ?>
        <?php if ( $column_has_content[ $field ] ): ?>
          <th class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print $label; ?>
          </th>
        <?php endif;?>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
        <?php foreach ($row as $field => $content): ?>
          <?php if ( $column_has_content[ $field ] ): ?>
            <td class="views-field views-field-<?php print $fields[$field]; ?>">
              <?php print $content; ?>
            </td>
          <?php endif; ?>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>

ODER

template.php

<?php
/**
* Removes column headers for columns that do not have content.
*/
function THEME-NAME_preprocess_views_view_table__VIEW-NAME(&$vars) {
  $rows = $vars['rows'];
  $column_has_content = array();
  foreach ($rows as $count => $row) {
    foreach ($row as $field => $content) {
      if (!empty($content)) {
        $column_has_content[$field] = TRUE;
      }
    }
  }
  $vars['column_has_content'] = $column_has_content;
}
?>

views-view-table–VIEW-NAME.tpl.php

<table class="<?php print $class; ?>">
  <?php if (!empty($title)) : ?>
    <caption><?php print $title; ?></caption>
  <?php endif; ?>
  <thead>
    <tr>
      <?php foreach ($header as $field => $label): ?>
      <?php if (  $column_has_content[$field]  ):  ?>
        <th class="views-field views-field-<?php print $fields[$field]; ?>">
          <?php print $label; ?>
        </th>
      <?php endif; ?>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
        <?php foreach ($row as $field => $content): ?>
        <?php if (  $column_has_content[$field]  ):  ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print $content; ?>
          </td>
        <?php endif; ?>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>

Aug 1 2011

zusätzlichen space unter img in xhtml strict entfernen

entweder durch

img {display:block;}

oder

img {vertical-align:bottom;}

Jul 26 2011

Drupal 7: PHP Memory Limit erhöhen

ini_set('memory_limit', '16M');

to your sites/default/settings.php file

php_value memory_limit 16M

to your .htaccess file in the Drupal root


Jul 11 2011

php: eindeutige id

$sid=md5(uniqid(rand(), true).uniqid(rand(), true));

Jul 2 2011

php: Dynamische Variablennamen

${variable.$dynamisch} = "inhalt";