Skip to content

Instantly share code, notes, and snippets.

View joshuaadickerson's full-sized avatar

Joshua Dickerson joshuaadickerson

View GitHub Profile
<?php
function viewExit(array $context, $status_code = 200, $template = false)
{
call_integration_hook('integrate_pre_view_exit', array(&$context, &$status_code, &$template));
switch ($GLOBALS['output_strategy'])
{
case 'json':
$content_type = 'text/json';
<?php
/**
* Check if a user can see a board based on the board groups
* A PHP equivalent to {query_see_board}
*
* @param array $board_groups
* @param array $board_deny_groups (optional)
* @return boolean
*/
@joshuaadickerson
joshuaadickerson / Membergroups.subs.php
Created May 8, 2013 18:15
Refactor to use loadMemberGroups()
<?php
function membergroupsById($group_id, $limit = 1, $detailed = false, $assignable = false, $protected = false)
{
global $context;
if (!isset($group_id))
return false;
if (empty($context['membergroups']))
@joshuaadickerson
joshuaadickerson / gist:5541980
Last active December 17, 2015 03:19
Load all of the membergroups instead of loading them individually
<?php
/**
* Load all of the membergroups
*
* @global array $smcFunc
* @global array $context
* @global array $modSettings
*/
function loadMemberGroups($force = false)
{
@joshuaadickerson
joshuaadickerson / gist:5538182
Created May 8, 2013 04:23
An interface to implement for caching
<?php
/**
* An interface for caches to implement
*/
interface iCache
{
public function connect();
public function setOptions($options);
public function getKey($key, $parameters);
@joshuaadickerson
joshuaadickerson / gist:5536962
Created May 7, 2013 23:16
Abstract deletes from the database
<?php
/**
* Delete from one|multiple tables in the database
*
* @param string $identifier = ''
* @param array|string $tables
* @param string $where
* @param array $options = array()
* @param resource $connection = null
<?php
function toggleTopicSticky($topics)
{
global $smcFunc;
$topics = is_array($topics) ? $topics : array($topics);
$smcFunc['db_query']('', '
UPDATE {db_prefix}topics
<?php
/**
* Update a row in multiple tables in the database
*
* @param string $identifier = ''
* @param array|string $tables
* @param array $columns
* @param array $options = array()
* @param resource $connection = null
*
@joshuaadickerson
joshuaadickerson / schema.xml
Created April 27, 2013 05:49
Solr Places Schema
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is the schema for places (to be used for autocomplete)
Here are some more reference links:
https://github.com/wikimedia/mediawiki-extensions-WikibaseSolr/blob/master/schema.solr4.xml
-->
<schema name="places.solr.schema" version="1.5">
<types>
@joshuaadickerson
joshuaadickerson / gist:5465556
Created April 26, 2013 07:37
Match the state code with the string. Should match somerset but not "me" in there.
<?php
// Should match:
$string = 'somerset nj';
$string = 'nj somerset';
$string = 'nj';
$string = 'NJ ';
// Should NOT match
$string = 'somersetnj';