Skip to content

Instantly share code, notes, and snippets.

View pnomolos's full-sized avatar

Phil Schalm pnomolos

  • Jane.app
  • British Columbia, BC
  • 16:55 (UTC -12:00)
  • X @pnomolos
View GitHub Profile
@pnomolos
pnomolos / MasterWidget.php
Created November 9, 2011 07:58 — forked from jonathonbyrdziak/CustomWidgetFile.php
Plugin code to create a single widget in wordpress.
<?php
/**
* @Author Jonathon byrd
* @link http://www.jonathonbyrd.com
* @Package Wordpress
* @SubPackage Widgets
* @copyright Proprietary Software, Copyright Byrd Incorporated. All Rights Reserved
* @Since 1.0.0
*
* Plugin Name: Master Widget
@pnomolos
pnomolos / functions.php
Created September 4, 2011 00:29
Set post featured thumbnail and duration field automatically from youtube/vimeo thumbnail image pulled from embed code.
<?php
function set_video_info($post_id) {
$id = wp_is_post_revision($post_id);
$post_id = $id ? $id : $post_id;
$post = get_post($post_id);
if (get_the_post_thumbnail($post_id) || $post->post_type != 'videos')
return;
$upload_dir = wp_upload_dir();
<? $this->render_partial('shop:product_options'); ?>
<? if (PSInventory_Inventory::out_of_stock( $product, post('product_options') )): ?>
<p>
<strong>
<? $options_string = PSInventory_Data::create_option_string(post('product_options', array()), $product->id);
$data = PSInventory_Data::create()->where('product_id=? AND options_string=?', $product->id, $options_string)->find();
$extended_sku = $data->extended_sku;
?>
We're sorry, the item (size/color/style) you've selected is temporarily out-of-stock.
<a href="<?= site_url('out-of-stock-contact-form') ?>?item=<?= urlencode($extended_sku); ?>" rel="lightbox[external 900 300]" title="Out of Stock Contact Form" id="oosLink" class="button">Notify me</a> when this item becomes available.
<?
class ArclightML_Settings extends Backend_SettingsController
{
public $implement = 'Db_ListBehavior, Db_FormBehavior';
public $form_model_class = '';
protected $access_for_groups = array(Users_Groups::admin);
public function config() {
$this->app_page_title = 'Mailing List Settings';
@pnomolos
pnomolos / Example conditions.php
Created July 21, 2011 21:18
LS DB ActiveRecord HABTM extension for conditional joins
<?php
public $has_and_belongs_to_many = array(
'add_on_order_status'=>array(
'class_name'=>'Shop_StatusTransition',
'primary_key'=>'psinventory_param_id',
'foreign_key' => 'shop_status_transition_id',
'join_table' => 'psinventory_params_shop_status_transitions',
'join_fields' => array(
'transition_flag' => 'active'
)
public function add_field($code, $title, $side = 'full', $type = db_text, $just_column = false)
{
$this->custom_columns[$code] = $type;
$this->_columns_def = null;
$col = $this->define_column($code, $title)->validation();
if ( !$just_column ) {
$form_field = $this->add_form_field($code, $side)->optionsMethod('get_added_field_options');
$this->added_fields[$code] = $form_field;
return $form_field;
#26907620 - About 10 minutes from the end. Phar mummies to SS ult
namespace :admin do
resources :services
end
# Get all the properties that aren't fulltext (which will cause the query to break)
props = Product.properties.reject{|p| p.type == DataMapper::Types::Text }.map{|p| "`products`.`#{p.name}`" }.join(', ')
# Get categories before hand as it tends to be a little faster.
@categories = Category.all( :name.like => "%#{params[:search]}%" )
# Do the massive query.
# You'll notice the << -1 on the queries. Since @category.id is an autoincrement it'll never be -1 and this is easier than a messey ternary statement. I'd imagine the messy statement could be a little faster, however.
@t_products = Product.find_by_sql(["SELECT " + props + "
FROM products
LEFT JOIN categories_products ON categories_products.product_id = products.id
module DataMapper
class Query
alias :old_assert_valid_order :assert_valid_order
def assert_valid_order(order, fields)
old_assert_valid_order(order, fields) unless !order.nil? && order.any? { |p| p.is_a?(Direction) && p.property.name == :sort_order }
end
end
end