Subscribe to Syndicate

Drupal Developer and Systems Administrator

Support for your Drupal Website

Code snippets

paulbooker's picture

Adding body classes based on taxonomy terms (template.php)

function mytheme_preprocess_html(&$variables) {
  if(arg(0)=='node' && is_numeric(arg(1))) {
    $node = node_load(arg(1));  
    $results = _mytheme_taxonomy_node_get_terms($node); 
    if(is_array($results)) {
      foreach ($results as $item) { 
        $variables['classes_array'][] = "taxonomy-".strtolower(drupal_clean_css_identifier($item->name));
      }
    }
  }
}

function _mytheme_taxonomy_node_get_terms($node, $key = 'tid') {
  static $terms;
  if (!isset($terms[$node->vid][$key])) {
    $query = db_select('taxonomy_index', 'r');
paulbooker's picture

Determining if the browser is safari using the user agent.

$ua = $_SERVER["HTTP_USER_AGENT"];      // Get user-agent of browser

$safariorchrome = strpos($ua, 'Safari') ? true : false;     // Browser is either Safari or Chrome (since Chrome User-Agent includes the word 'Safari')
$chrome = strpos($ua, 'Chrome') ? true : false;             // Browser is Chrome

if ($safariorchrome == true AND $chrome == false) { $safari = true; }     // Browser should be Safari, because there is no 'Chrome' in the User-Agent
paulbooker's picture

Create a table of data with a pager in Drupal 8

$table = array(
  '#type' => 'table',
  '#header' => $header,
  '#rows' => $rows,
  '#attributes' => array(
    'id' => 'foo',
  ),
);
$markup = drupal_render($table);
// Pager is not an element type, use #theme directly.
$pager = array('#theme' => 'pager');
$markup .= drupal_render($pager);
paulbooker's picture

Implementation of hook_views_data().

/**
* Implementation of hook_views_data().
*/
function flickr_group_photos_views_data() {
  $data = array();

  // Base data
  $data['flickr_group_photos']['table']['group']  = t('Flickr Groups');
  $data['flickr_group_photos']['table']['base'] = array(
    'title' => t('Flickr Groups'),
    'help' => t('Query Flickr groups.'),
    'query class' => 'flickr_group_photos_plugin_query'
  );
  return $data;
}

Pages

Shell command snippets

openssl s_client -connect transitionnetwork.org:443 < /dev/null 2>/dev/null | openssl x509 -fingerprint -noout -in /dev/stdin
SHA1 Fingerprint=DE:E6:11:E6:81:E5:ED:2E:FB:ED:54:39:22:9A:A6:1D:C4:5B:FB:C3
cd  /etc/php5/fpm/pool.d
mv  www www1
cp  www1 www2
cp  www1 www3
vi /www1

line 4 - rename www to www1
line 33 - put listen path to: /var/run/php5-fpm-www1.sock

Repeat for www2 and www3.

​mv /etc/nginx /etc/nginx.old
cd /etc
git clone https://github.com/troubleshooter/drupal7-with-nginx.git​
mv drupal7-with-nginx nginx
​cd nginx/sites-available
mv example.com.conf  yourdomain.com.conf
vi yourdomain.com.conf

.. adjust to your needs.

mkdir /var/cache/nginx/
mkdir /var/cache/nginx/microcache/
chown www-data:www-data /var/cache/nginx/microcache
mkdir /etc/nginx/ssl
openssl genrsa -des3 -out ssl.key 1024
openssl req -new -key ssl.key -out server.csr
cp ssl.key ssl.key.org
openssl rsa -in ssl.key.org -out ssl.key
openssl x509 -req -days 365 -in server.csr -signkey ssl.key -out ssl-unified.crt
mkdir /etc/nginx/ssl/certs/
mv ssl-unified.crt /etc/nginx/ssl/certs/ssl-unified.crt
mkdir /etc/nginx/ssl/private
mv ssl.key /etc/nginx/ssl/private/ssl.key
mkdir /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/000-default.conf /etc/nginx/sites-enabled/000-default.conf
ln -s /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled/yourdomain.com.conf
/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart

Installing drupal ..

mkdir /var/www
chown www-data:www-data /var/www
su www-data
cd /var/www
wget http://ftp.drupal.org/files/projects/drupal-7.XX.tar.gz
tar -xzvf drupal-7.XX.tar.gz
mv drupal-7.XX yourdomain.com
apt-get update 
apt-get upgrade
dpkg-reconfigure tzdata
vi /etc/apt/sources.list
deb http://packages.dotdeb.org wheezy all
​deb-src http://packages.dotdeb.org wheezy all
wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | sudo apt-key add -
apt-get update 
apt-get upgrade
apt-get install nginx-extras mysql-server mysql-client memcached
apt-get install php5-fpm php5-gd php5-mysql php-apc php-pear php5-cli php5-common php5-curl php5-mcrypt php5-cgi php5-memcached
pear channel-discover pear.drush.org
pear install drush/drush
drush version
/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart
grep -l 'libssl.*deleted' /proc/*/maps | tr -cd 0-9\\n | xargs -r ps u
sudo dpkg -l openssl  #version installed
ii  openssl                         1.0.1-4ubuntu5.11 Secure Socket Layer (SSL) binary and related cryptographic tools 
sudo apt-get update && sudo apt-get install openssl
sudo service apache2 restart 
sudo dpkg -l openssl
ii  openssl                         1.0.1-4ubuntu5.12 Secure Socket Layer (SSL) binary and related cryptographic tools
sudo service nginx restart
paulbooker's picture

Say No Say Yes [Ben's Productivity Podcast]

Learning How to Say No and Yes in the Right Situations

Transcript:
Hi, welcome to the podcast. I'm recording this podcast with a rain storm going on behind me so if you hear a little bit of rain or lightning or thunder, I guess you can't hear lightning, but if you hear the thunder then just know that's what's going on. Hopefully we won't be disturbed too much and I have what I think is a really interesting...

Pages