Skip to content

Instantly share code, notes, and snippets.

View josephdpurcell's full-sized avatar

Joseph D. Purcell josephdpurcell

View GitHub Profile
@josephdpurcell
josephdpurcell / prepare-commit-msg
Last active August 29, 2015 14:07 — forked from aczietlow/prepare-commit-msg
Make Mac friendly
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg" and
@josephdpurcell
josephdpurcell / attaching-closures-to-objects-in-php.php
Created January 3, 2013 15:58
Attaching PHP Closures/Anonymous Functions a Class/Object
<?php
/**
* references:
* http://www.murraypicton.com/2010/09/extending-objects-using-anonymous-functions-in-php/
* http://php.net/manual/en/functions.anonymous.php
* http://php.net/manual/en/function.is-callable.php
*/
class Foo {
public $bar;
@josephdpurcell
josephdpurcell / bootstrap-modal.js
Created May 20, 2013 13:40
The "bootstrap-modal.js" includes a fix for the modal pull request https://github.com/twitter/bootstrap/pull/6793. However, that was a fix for the code as it was 3 months ago. The "modal.js" file includes the same code, but is adapted for the latest 3.0.0-wip (5/20/13).
/* =========================================================
* bootstrap-modal.js v3.0.0
* http://twitter.github.com/bootstrap/javascript.html#modals
* =========================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@josephdpurcell
josephdpurcell / commit-54d285f083563faef6a56818454bdd560352b490.patch
Created January 26, 2016 23:10
RESTful patch: Do not take the anon user as a valid authentication
diff --git a/src/Authentication/AuthenticationManager.php b/src/Authentication/AuthenticationManager.php
index 460815c..2f0e059 100644
--- a/src/Authentication/AuthenticationManager.php
+++ b/src/Authentication/AuthenticationManager.php
@@ -96,13 +96,13 @@ class AuthenticationManager implements AuthenticationManagerInterface {
$account = NULL;
foreach ($this->plugins as $provider) {
/* @var \Drupal\restful\Plugin\authentication\AuthenticationInterface $provider */
- if ($provider->applies($request) && $account = $provider->authenticate($request)) {
+ if ($provider->applies($request) && ($account = $provider->authenticate($request)) && $account->uid) {
@josephdpurcell
josephdpurcell / 819-access-token-hyphen.patch
Last active January 27, 2016 20:21
Ref 833 Hotfix for hyphen/dash auth headers issue
diff --git a/modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php b/modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php
index 331281a..9d33d7a 100644
--- a/modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php
+++ b/modules/restful_token_auth/src/Plugin/authentication/TokenAuthentication.php
@@ -93,7 +93,7 @@ class TokenAuthentication extends Authentication {
// If we don't have a $key_name on either the URL or the in the headers,
// then check again using a hyphen instead of an underscore. This is due to
// new versions of Apache not accepting headers with underscores.
- if (empty($input[$key_name]) && $request->getHeaders()->get($key_name)->getValueString()) {
+ if (!$input[$key_name] && !$request->getHeaders()->get($key_name)->getValueString()) {
@josephdpurcell
josephdpurcell / replace-cookie-with-token-auth-for-login-token.patch
Created March 4, 2016 22:16
Replace cookie authentication with token authentication on login token for RESTful 2.x
@josephdpurcell
josephdpurcell / disable-cookie-for-login-token-example.module
Created February 23, 2016 23:07
Disable cookie auth on login token for RESTful 1.x
@josephdpurcell
josephdpurcell / disable-cookie-for-login-token.patch
Created February 23, 2016 23:02
Disable cookie auth on login token for RESTful 2.x
@josephdpurcell
josephdpurcell / rebuild_module_paths.php
Last active May 6, 2016 21:25
Rebuild Drupal 7 module paths.
<?php
if (basename(getcwd()) !== 'docroot') {
echo "You must run this in docroot.\n";
exit(1);
}
if (count($argv) < 4) {
echo "Usage: php rebuild_module_paths.php hostname dbname username password\n";
exit(1);
}
@josephdpurcell
josephdpurcell / phpmd_drupal_ruleset.xml
Created March 3, 2016 21:32
PHP Mess Detector Ruleset for Drupal.
<?xml version="1.0"?>
<ruleset
name="PMD Ruleset for Drupal"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
>
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/codesize.xml">
<exclude name="ExcessiveMethodLength" />