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 / sidebar_embed.php
Created June 4, 2012 17:37
Embed Sidebars In Content - WordPress
<?php
/**
* This code will allow you to embed a sidebar
* into a post or page or anywhere that shortcodes
* are parsed in your WordPress theme / site.
* It pairs well with Sidebar Generator
* http://wordpress.org/extend/plugins/sidebar-generator/
* Otherwise, be sure to register_sidebar('name')
*
@dongilbert
dongilbert / fixed.php
Created September 5, 2012 21:20
Not Enough Defines
<?php
$uri = parse_url($_SERVER['REQUEST_URI']);
$path = explode('/', $uri['path']);
define('IS_HOME', (empty($path[1])));
define('IS_ADMIN', ($path[1] === 'admin'));
define('IS_NEWS', ($path[1] === 'news'));
define('IS_CONTACT', ($path[1] === 'contact'));
@dongilbert
dongilbert / sqlnono.php
Created September 5, 2012 21:18
How NOT to use SQL
<?php
$sql = sprintf( "SELECT `Password`, `DealerID`
FROM `DLMAST`
WHERE `DealerID` = %d
AND LOWER(`Password`) = '%s'",
mysql_real_escape_string( $_POST['Username'] ),
mysql_real_escape_string( strtolower( $_POST['Password'] ) ) );
$db->Execute( $sql, 'user_pass' );
@dongilbert
dongilbert / index.php
Created November 28, 2012 16:38
Joomla Namespace Example
<?php // File: index.php
const JPATH_BASE = __DIR__;
require_once JPATH_BASE . '/libraries/joomla/loader.php';
Joomla\Loader::registerNamespace('Joomla', JPATH_BASE . '/libraries/joomla');
Joomla\Application\Web::getInstance('\\Joomla\\Application\\Web')->execute();
@dongilbert
dongilbert / composer.json
Created November 29, 2012 01:03
Joomla Composer
{
"require": {
"joomla/platform": ">=13.2"
},
"minimum-stability": "dev",
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"config": {
"bin-dir": "bin",
@dongilbert
dongilbert / example.md
Last active October 13, 2015 13:57
JHtml::asset()

Joomla Asset Management with JHtml

// To load a css file for a component, from within the component
EEHtml::asset('style.css');

// To load a js file for a module
EEHtml::asset('slide.js', 'mod_menu');

// To load an image for a module
echo EEHtml::asset('search.png', 'mod_product_search');
@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');