Skip to content

Instantly share code, notes, and snippets.

View bangpound's full-sized avatar

Benjamin Doherty bangpound

View GitHub Profile
@bangpound
bangpound / gist:4744600
Created February 9, 2013 08:35
Written for oEmbed module (but not committed), this snippet extracts script elements from the html property of oEmbed responses that are "video" or "rich." The scripts are added to a the render array as #attached. This also suggests a way to create produce opengraph meta tags from oEmbed media by using #attached['html_head']
<?php
$embed = $element['#embed'];
// Check if the oEmbed response provides a thumbnail image.
if (empty($embed['html'])) {
$element['#printed'] = TRUE;
return $element;
}
{
"created_at": "Tue Jun 04 13:33:08 +0000 2013",
"id": "341910491351904258",
"id_str": "341910491351904258",
"text": "Ben Bir Ceviz agaciyim GEZİ PARKİNDAYİM. #direngeziparkı http://t.co/eI2Ae4BSO7",
"source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
@bangpound
bangpound / gist:5799683
Last active December 18, 2015 14:49
use secure token in action emal.
<?php
/**
* Implements hook_action_info().
*/
function MODULE_action_info() {
return array(
'MODULE_send_email_secure_tokens_action' => array(
'type' => 'system',
'label' => t('Send e-mail with user secure tokens'),
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bangpound
bangpound / gist:6117279
Created July 30, 2013 21:43
Render Drupal fields inside the rendered markup of other Drupal fields.
<?php
/**
* Implement hook_file_view_alter().
*
* @param type $build
* @param type $entity_type
*/
function MODULE_file_view_alter(&$build, $entity_type) {
$qp = QueryPath::withHTML($build['field_caption']['0']['#markup']);
@bangpound
bangpound / gist:6117282
Created July 30, 2013 21:43
Render Drupal fields inside the rendered markup of other Drupal fields.
<?php
/**
* Implement hook_file_view_alter().
*
* @param type $build
* @param type $entity_type
*/
function MODULE_file_view_alter(&$build, $entity_type) {
$qp = QueryPath::withHTML($build['field_caption']['0']['#markup']);
// One way converter from E4X XML to JSON
// 1) turns <body><item>1</item><item>2</item></body> into
// body: {item: ["1", "2"]} so that lists are easier to work with
// 2) turns things like: <body a="a">whatever</body> into
// body: {_a: "a", _: "whatever"}
// however <body>whatever</body> becomes simply body: "whatever
// - attributes specified by ignored are ignored
function E4XtoJSON(xml, ignored) {
var r, children = xml.*, attributes = xml.@*, length = children.length();
if(length == 0) {
<?php
namespace Bangpound\Bundle\DrupalBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
/**
@bangpound
bangpound / GlobalsApplication.php
Created December 31, 2013 18:08
Silex application concept which uses the PHP $GLOBALS array as the service container.
<?php
use Silex\Application;
class GlobalsApplication extends Application
{
public function __construct(array $values = array())
{
// Set up the Silex services.
parent::__construct($values);