Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
GreatPotato / gist:7566206
Created November 20, 2013 16:29
Validates and sends an email
<?php
class ContactForm {
public function send_contact_form() {
$validation = new Phpr_Validation();
$validation->add('name')->fn('trim')->required('Please enter your name');
$validation->add('email')->fn('trim')->required('Please enter your email address')->email(false, 'Please enter a valid email address');
@GreatPotato
GreatPotato / gist:7560604
Created November 20, 2013 09:55
A marginally better WordPress config file
<?php define('WP_CACHE', true);
define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
@GreatPotato
GreatPotato / gist:7120080
Last active December 26, 2015 08:09
Create a slug from any string
<?php
class Slug {
private function slugify($slug)
{
// convert all dodgey foreign characters
$table = array(
'Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c',
'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O',
@GreatPotato
GreatPotato / gist:6902395
Created October 9, 2013 14:41
Gets best selling products in the current category - LemonStand
<?php
$obj = new Shop_Product();
$obj->select('count(shop_order_items.id) AS "sold"');
$obj->join('shop_products_categories', 'shop_products.id = shop_products_categories.shop_product_id');
$obj->join('shop_order_items', 'shop_products.id = shop_order_items.shop_product_id');
$obj->join('shop_orders', 'shop_order_items.shop_order_id = shop_orders.id');
$best_selling = $obj->where('shop_products_categories.shop_category_id=? AND shop_orders.payment_processed IS NOT NULL', $category->id)->group('shop_products.id')->order('count(shop_order_items.id) DESC')->limit(3)->find_all();
@GreatPotato
GreatPotato / gist:6882259
Created October 8, 2013 09:44
Send an email with validation in LemonStand
<?php
function send_contact_form() {
$validation = new Phpr_Validation();
$validation->add('name')->fn('trim')->required('Please enter your name');
$validation->add('email')->fn('trim')->required('Please enter your email address')->email(false, 'Please enter a valid email address');
$validation->add('subject')->fn('trim');
$validation->add('order_no')->fn('trim');
@GreatPotato
GreatPotato / gist:6534738
Created September 12, 2013 08:59
Override the default error handling in LemonStand
window.Phpr.response.popupError = window.LS.response.popupError = function(message) {
console.log(message);
}
@GreatPotato
GreatPotato / gist:6163423
Created August 6, 2013 10:29
Search by custom column in the backend order search
<?php
public function subscribeEvents()
{
Backend::$events->addEvent('backend:onControllerReady', $this, 'on_backend_controller_ready');
}
public function on_backend_controller_ready($controller)
{
$controller->list_search_fields[] = 'x_custom_column';
@GreatPotato
GreatPotato / gist:5959098
Created July 9, 2013 16:58
Gets the current currency in use for LemonStand
<?php
$obj = new Shop_CurrencySettings;
$obj = $obj::get();
$currency = $obj->sign;
@GreatPotato
GreatPotato / gist:5766738
Created June 12, 2013 16:07
Get a list of all font awesome icons
<?php
$pattern = '/\.(icon-(?:\w+(?:-)?)+):before\s+{\s*content:\s*"(.+)";\s+}/';
$subject = file_get_contents('css/font-awesome.css');
preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER);
$icons = array();
echo '<ul>';
<?php
function gp_empty_paragraph_fix($content) {
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
return $content;