Skip to content

Instantly share code, notes, and snippets.

View adamfranco's full-sized avatar

Adam Franco adamfranco

View GitHub Profile
@adamfranco
adamfranco / VisibilityFieldAccessControl.php
Last active November 10, 2023 21:23
Extending the Drupal Group module with an AccessControl decorator for a node visibility field
<?php
namespace Drupal\middlebury_course_hub\Plugin\Group\RelationHandler;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\group\Plugin\Group\RelationHandler\AccessControlTrait;
use Drupal\group\Plugin\Group\RelationHandler\AccessControlInterface;
@adamfranco
adamfranco / fix-image-paths.php
Created July 20, 2023 13:20
Fix image paths in an archive of sites.middlebury.edu/middmag-old/ produced by HTTrack
#!/usr/bin/env php
<?php
$file = $argv[1];
if (!preg_match('#\.html$#', $file)) {
throw new Exception("$file must be a .html file.");
}
if (preg_match('#(.+)sites.middlebury.edu/middmag-old/(.+)#', $file, $pathMatches)) {
$directory = dirname($pathMatches[2]);
@adamfranco
adamfranco / maplibre-gl.css
Last active February 7, 2022 20:33
Maplibre fork for Americana build. Testing Parcel bundling of this customized version.
.mapboxgl-map,.maplibregl-map{-webkit-tap-highlight-color:rgba(0,0,0,0);font:12px/20px Helvetica Neue,Arial,Helvetica,sans-serif;overflow:hidden;position:relative}.mapboxgl-canvas,.maplibregl-canvas{left:0;position:absolute;top:0}.mapboxgl-map:-webkit-full-screen,.maplibregl-map:-webkit-full-screen{height:100%;width:100%}.mapboxgl-canvas-container.mapboxgl-interactive,.mapboxgl-ctrl-group button.mapboxgl-ctrl-compass,.maplibregl-canvas-container.maplibregl-interactive,.maplibregl-ctrl-group button.maplibregl-ctrl-compass{cursor:-webkit-grab;cursor:-moz-grab;cursor:grab;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}.mapboxgl-canvas-container.mapboxgl-interactive.mapboxgl-track-pointer,.maplibregl-canvas-container.maplibregl-interactive.maplibregl-track-pointer{cursor:pointer}.mapboxgl-canvas-container.mapboxgl-interactive:active,.mapboxgl-ctrl-group button.mapboxgl-ctrl-compass:active,.maplibregl-canvas-container.maplibregl-interactive:active,.maplibregl-ctrl-group button
@adamfranco
adamfranco / midd-wpcas.php
Created November 18, 2019 18:37
Custom callback functions to execute on user login.
// this function gets executed
// if the CAS username doesn't match a username in WordPress
function wpcas_nowpuser( $user_name ) {
midd_wpcas_nowpuser($user_name);
// Authenticate again now that the user exists
$wpCAS = new wpCAS;
$wpCAS->authenticate();
}
function midd_wpcas_nowpuser($username) {
require_once( ABSPATH . WPINC . '/registration.php' );
@adamfranco
adamfranco / DynamicAddUsers.php
Last active May 21, 2021 21:00
A WordPress-MU plugin which replaces the "Add User" screen with a dynamic search for users and groups.
<?php
/*
Plugin Name: DynamicAddUsers
Plugin URI:
Description: Replaces the 'Add User' screen with a dynamic search for users and groups
Author: Adam Franco
Author URI: http://www.adamfranco.com/
*/
global $dynaddusers_db_version;
$nids = \Drupal::entityQuery('node')->condition('type', 'event')->condition('status', 0)->execute();
$nodes = entity_load_multiple('node', $nids);
foreach ($nodes as $entity) {
$entity->set('moderation_state', 'published');
if ($entity instanceof RevisionLogInterface) {
$entity->setRevisionLogMessage('Programatically updating workflow state.');
$entity->setRevisionUserId(\Drupal::currentUser()->id());
}
$entity->save();
}
@adamfranco
adamfranco / show_stories_in_newsroom.php
Created January 16, 2018 14:39
Short script to bulk-update story nodes in Drupal. Execute with `drush8 php-script show_stories_in_newsroom.php`
<?php
$query = \Drupal::entityQuery('node');
$query->condition('type', 'story');
$nids = $query->execute();
echo "Updating " . count($nids) . " stories:\n";
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
$node->field_aggregate = TRUE;
@adamfranco
adamfranco / atom-focus-file-access.log
Last active March 29, 2016 17:50
Log of the file-system access over Samba when focusing the Atom editor on a 3-file project.
lstat("/home/afranco/directory", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat("/home/afranco/directory/.git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat("/home/afranco/directory/.git/index", {st_mode=S_IFREG|0664, st_size=346, ...}) = 0
lstat("/home/afranco/directory", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat("/home/afranco/directory/.git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
open("directory/.git", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 36
lstat("directory/.git/index", {st_mode=S_IFREG|0664, st_size=346, ...}) = 0
lstat("/home/afranco/directory", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat("/home/afranco/directory/.git", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat("/home/afranco/directory/.git/index", {st_mode=S_IFREG|0664, st_size=346, ...}) = 0
@adamfranco
adamfranco / deployerConfigContext.xml
Last active August 29, 2015 14:07
Adam's CAS Ldap authentication section in deployerConfigContext.xml
...
<!-- LDAP Authentication Configuration -->
<bean id="ldapAuthenticationHandler"
class="org.jasig.cas.authentication.LdapAuthenticationHandler"
p:principalIdAttribute="middleburyCollegeUID"
c:authenticator-ref="authenticator">
<property name="principalAttributeMap">
<map>
<!--| This map provides a simple attribute resolution mechanism.
/**
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Jasig licenses this file to you 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:
*
* http://www.apache.org/licenses/LICENSE-2.0