Skip to content

Instantly share code, notes, and snippets.

@mrclay
mrclay / elgg-password-change.php
Created March 28, 2013 19:19
Allows Elgg site owners to change their account password in case the "Lost password" function fails (running on platform where e-mail doesn't work or lost access to the e-mail account)
<?php
// Allows changing password without e-mail.
// Place this script in the root of your Elgg install
$maxAge = 60;
if ((time() - filemtime(__FILE__)) > $maxAge) {
die("Touch this file for $maxAge seconds of use. You'll need a valid username and the value of the password"
." column in the users_entity table.");
} else {
@mrclay
mrclay / stringify_callable.php
Last active December 16, 2015 01:39
Describe a callable value (particularly non-string ones)
<?php
/**
* Get a string of useful info about a callback
*
* E.g. "function_name", "Static::method", "(Dynamic)->method", "(Closure path/to/file.php:23)"
*
* @param callable $callable
* @param string $file_root If provided, this will be stripped from the beginning of the file path for Closures
* @return string
# Use git in /usr/local/git (not the xcode installed one)
PATH=/usr/local/git/bin:$PATH
export PATH
# enable git completion and the __git_ps1 function
if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then
source /usr/local/git/contrib/completion/git-completion.bash
fi
if [ -f /usr/local/git/contrib/completion/git-prompt.sh ]; then
@mrclay
mrclay / start.php
Created August 13, 2013 15:32
Elgg 1.9 migration: setting entity URLs
<?php
// Set entity URLs in both Elgg 1.8 and 1.9 without deprecation notices
if (function_exists('elgg_get_version')) {
elgg_register_plugin_hook_handler('entity:url', 'object', function ($h, $t, $v, $p) {
if ($p['entity']->subtype === 'my_subtype') {
return my_subtype_url_handler($p['entity']);
}
});
} else {
@mrclay
mrclay / GuidPreloader.php
Created August 23, 2013 21:12
Preload Elgg entities that are related to a propert(y|ies) of a given list of entities
<?php
namespace UFCOE\Elgg;
/**
* Preload entities that are related to a propert(y|ies) of a given list of entities
*
* E.g. You need to display 10 blog posts, you know you're going to need to load the owners
* and containers, but Elgg is not smart enough to know that; it has to make a bunch of individual
* queries as those needs are discovered. This allows scanning the fetched blog objects and preloading
@mrclay
mrclay / 19-autoloader.php
Created August 26, 2013 12:32
PSR-0 class autoloader shim for Elgg 1.8
<?php
/**
* Enables full PSR-0 class autoloading out of /classes directory
*
* Usage in start.php:
*
* if (!function_exists('elgg_get_version')) {
* require_once __DIR__ . '/19-autoloader.php';
* }
*/
@mrclay
mrclay / MetadataSet.php
Created August 26, 2013 13:20
Elgg: Allows modeling a unique set of integers on top of entity metadata
<?php
namespace UFCOE\Elgg;
/**
* Allows modeling a unique set of integers on top of entity metadata
*/
class MetadataSet
{
/**
@mrclay
mrclay / CookiePersistedUserMetadata.php
Created August 26, 2013 13:28
Elgg: Keep a signed cookie in sync with user metadata. If the user is logged out, allow using the signed cookie value.
<?php
namespace UFCOE\Elgg;
/**
* Keep a signed cookie in sync with user metadata. If the user is logged out, allow using
* the signed cookie value.
*
* Note: stored metadata names are prefixed.
*
@mrclay
mrclay / TagUtil.php
Created August 26, 2013 13:38
Elgg: Utilities for altering queries based on matching optional/required tags
<?php
namespace UFCOE\Elgg;
/**
* Utilities for altering queries based on matching optional/required tags
*/
class TagUtil {
/**
@mrclay
mrclay / AclPopulator.php
Created August 26, 2013 13:41
Elgg: Populate an ACL based on users and existing ACLs (bypasses Elgg API: does not induce plugin hooks)
<?php
namespace UFCOE\Elgg;
/**
* Populate an ACL based on users and existing ACLs (bypasses Elgg API: does not induce plugin hooks)
*
* <code>
* $populator = new AclPopulator(23); // target
* $populator->addAcls(array(123, 456)); // merge in a couple existing lists