Subscribe to Syndicate

Drupal Developer and Systems Administrator

Support for your Drupal Website

Code snippets

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;
}
paulbooker's picture

Implementation of hook_views_plugins().

/**
* Implementation of hook_views_plugins().
*/
function flickr_group_photos_views_plugins() {
  $plugin = array();
  $plugin['query']['flickr_group_photos_plugin_query'] = array(
    'title' => t('Flickr Groups Query'),
    'help' => t('Flickr Groups query object.'),
    'handler' => 'flickr_group_photos_plugin_query',
  );
  return $plugin;
}

[module = flickr_group_photos].views.inc

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

Toadcast 22

Toadcast 22 hosted an All-Star cast including: Dave Bellous, co-owner of Yellow Pencil, Jacob Redding, Open Source Manager at Accenture's Emerging Technology Innovation Labs, Jeff Walpole, CEO of Phase2, and Joaquin Lippincott, President of Metal Toad Media to discuss Open Source, Oracle, and and the healthcare web-tech industry (Cover Oregon).

ToadCast can be found on iTunes. Check us out and give us a review/rating.

We have a handy form for you to submit questions, topic ideas, and tips that we'll read on the air! Yay. Give it a try.

Thanks For Listening!

Filed under podcast, drupal, Opensource, Cover Oregon.

Pages