Skip to content

Instantly share code, notes, and snippets.

View dongilbert's full-sized avatar
😍
Mautic WOOOO

Don Gilbert dongilbert

😍
Mautic WOOOO
View GitHub Profile
@dongilbert
dongilbert / example.php
Created December 4, 2012 20:48
Auto Loading Custom Libraries
<?php
/**
* Proposal to auto load custom libraries and register them with the
* application for use. Assume the directory structure below:
*
* /libraries
* - import.php
* - /joomla
* - /easel // The custom library
@dongilbert
dongilbert / magic.php
Created December 12, 2012 19:44
Abstract class containing magic __set and __get methods to alleviate B/C issues with removing underscore from protected properties.
<?php
abstract class JFixProtected
{
public function __set($name, $value)
{
$name = $this->cleanPropertyName($name);
$this->$name = $value;
}
@dongilbert
dongilbert / SQLInjection.php
Created December 18, 2012 12:55
Read this today on a developer thread. I was horrified, but then I realized he was working on his local machine - so no issue there. But, then I read the rest of his email/question, and in his signature, it said "Senior PHP Developer." NNNOOOOOO
<?php
mysql_connect("localhost", "uname", "pass@3") or die(mysql_error());
echo "Connected to MySQL<br />"; // working fine
mysql_select_db("dbname") or die(mysql_error());
echo "Connected to Database"; // working fine
@dongilbert
dongilbert / chapter.php
Last active December 10, 2015 17:49 — forked from drmmr763/chapter.php
Moved the query from the loop into a sub query and then optimized a little.
<?php
public function getSubmits()
{
$cid = JFactory::getApplication()->input->getInt('cid');
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('a.*, i.username');
$query->select('(SELECT SUM(v.vote) FROM #__rootflick_vote AS v WHERE v.sub_id = a.id) AS vote');
@dongilbert
dongilbert / README.md
Created February 7, 2013 18:01
Build body classes for your template from common available variables.

BodyClass Generator

This method will create a string of body classes based on common variables, like the currently active option, view, and layout. It also splits the path of the currently loaded URL and puts it into the class string.

The advantages of this is that it allows you to style views as well as layouts and specific pages on your site.

Usage

@dongilbert
dongilbert / Joomla Events
Last active December 12, 2015 10:29
List of Joomla Events found in 3.0.3 core via `grep -r "trigger('on" *` and `grep -r "triggerEvent('on" *`
onAfterDispatch
onAfterExecute
onAfterInitialise
onAfterRender
onAfterRespond
onAfterRoute
onAfterSessionStart
onBeforeCompileHead
onBeforeExecute
onBeforeIndex
foreach (array_chunk($this->item->sizes, 5) as $chunk)
{
$chunk = array_pad($chunk, 5);
echo '<tr>';
for ($i=0;$i<5;$i++)
{
$s = $chunk[$i];
$link = JRoute::_('index.php');
echo '<td><a href="">' . $s->size . '</a></td>';
@dongilbert
dongilbert / loadClass.php
Last active December 14, 2015 16:09
An (potentially) improved loadClass method for the PSR-0 autoloader that eliminates naming collisions at the (potential) sake of performance. Untested.
<?php
public function loadClass($className)
{
if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
$fileName = '';
$namespace = '';
if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
@dongilbert
dongilbert / test.php
Last active December 17, 2015 02:28
DateTime weirdness. When passing a timestamp to the constructor, if it's a Unix timestamp, you must prepend it with an @.
<?php
print_r(new DateTime('01/01/2012'));
/*
Good
DateTime Object
(
[date] => 2012-01-01 00:00:00
[timezone_type] => 3
[timezone] => America/Chicago
@dongilbert
dongilbert / Container.php
Last active December 17, 2015 03:19
Joomla\DI\Container
<?php
/**
* Potentially Part of the Joomla Framework DI Package
*
* @copyright Copyright (C) 2013 Don Gilbert. All rights reserved.
* @license LGPL version 2 or later; see http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html
*/
namespace Joomla\DI;