Skip to content

Instantly share code, notes, and snippets.

View esolitos's full-sized avatar

Marlon (Esolitos) Saglia esolitos

View GitHub Profile
@esolitos
esolitos / MigrationClass.php
Created December 4, 2014 13:47
Migrate Add Field Collection
<?php
/**
* Attaches a (group) of field collections to an node entity
*
* @param stdClass $node_entity The loaded node object.
* @param array $field_collections the array of structures describing the entity collections
* keyed by the entity collection field name.
* @return void
*/
public function attachFieldCollections(&$node_entity, $field_collections)
@esolitos
esolitos / index.php
Created December 4, 2014 23:17
Language redirect in php with javascript fallback.
<?php
if ( isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2 )
{
$allowLang = array('en', 'it', 'de', 'fr');
$base_url = $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if ( !in_array($lang, $allowLang) ) {
$lang = 'en';
}
# While inside a drupal site directory creates a SQL backup with the name of the site's directory and the current date.
drush sql-dump | gzip > ~/SQL-Backup/${PWD##*/}.$(date +%y%m%d).gz
# More advanced example:
# From the `drupal/sites` directory do a SQL backup of all the sites available
for dir in $(ls | egrep -v 'all|default'); do
if [ -d $dir ]; then
cd $dir
echo "Backup of site: $dir"
drush sql-dump | gzip > ~/SQL/${pwd##/}.$(date +%Y-%m-%d).gz
@esolitos
esolitos / OUTDATED # Drupal + RamsaltMedia Settings
Last active February 19, 2020 13:46
OUTDATED # Devel settings for Drupal + RamsaltMedia platforms - MOVED to https://github.com/esolitos/drupal-utility
This config assumes that:
- `platform.settings.php` is placed in the `sites/` directory
- you have a `sites/files` directory in your drupal installation.
- you have a `ramsalt` user that can access all your databases starting with `ramsalt_`
- the files on the "live" site are placed in the drupal's default directory: `sites/hostname.tld/files`
@esolitos
esolitos / drush
Last active February 9, 2016 14:53
Drush Base Modules
# Disable default core modules that probably are not required (I suggest running also `drush pm-uninstall -y` on the same module list)
drush dis -y toolbar overlay color comment dashboard dblog help rdf
# Enable most used modules
drush en -y absolute_messages admin_views backup_migrate chosen ckeditor ckeditor_link save_edit module_filter page_manager field_ui image link field_collection entityreference email ds_ui date_views date_popup path pathauto globalredirect node navbar list options taxonomy features field_group media l10n_update date focal_point menu rules_admin strongarm views_ui jquery_update redirect transliteration ultimate_cron variable
# In case you are developing the site you can also enable those modules
drush en -y devel devel_contrib ds_devel metatag_devel performance
@esolitos
esolitos / instructions.md
Last active August 29, 2015 14:17
Create SSL Certificate Authority and Device Certificates

Note: Since I believe that sudo it's evil (contact me fore more info about it) I'm not going to assume that all the commands are run as root, ese at your own risk. Remember, with great powers...

Generate CA Certificate

In this part we will egnerate the key and the certificate for the CA, that are going to be used asto issue the device certificates.

Step 0. Move in a secure location: #: mkdir /root/certs/CA && cd /root/certs/CA

Step 1. Gen. CA Key: #: openssl genrsa -des3 -out rootCA.key 2048

@esolitos
esolitos / reconfig-local-drupal.sh
Last active June 22, 2019 08:07
Fixes a drupal site after the migration to local development. | Now available in: https://github.com/esolitos/drupal-utility/blob/master/bin/reconfig-local-drupal
#!/bin/sh
#
# WARNING: The content of this script might be outdated!
#
# This was the initial developement, now the script can be found on github:
# https://github.com/esolitos/drupal-utility/blob/master/bin/reconfig-local-drupal
#
drush_cmd=`which drush`
@esolitos
esolitos / gist:4b7a9919454c7eccab2e
Created April 29, 2015 13:39
Enable XDebug on OS.X

Each machine that has Apple's XCode installed has also XDebug, so we don't need to add it with pecl, brew, macports, or any similar package manager, simply add it to your php.ini file!

To simply do it, I give you this one-liner solution:

  sudo sh -c 'echo zend_extension=$(find /usr/lib/php/extensions -name "xdebug.so") >> $(php -qr "echo php_ini_loaded_file();") && apachectl restart'

If you're familiar with bash you probably have already understood, but if you need extra info about what's happening (and you should) there's the explaination:

@esolitos
esolitos / README.md
Last active December 7, 2018 19:20 — forked from magnetikonline/README.md
@esolitos
esolitos / Full Version
Created June 15, 2015 19:39
HDAccess Expand Poster Script
function findPosterLink(baseElement) {
if ( !baseElement ) {
return false;
}
// console.warn('findPosterLink');
var linkCells = baseElement.getElementsByClassName('torrents');
if ( linkCells.length ) {
var linkElem = linkCells[0].getElementsByTagName('a');