Skip to content

Instantly share code, notes, and snippets.

View paulhuisman's full-sized avatar

Paul Huisman paulhuisman

View GitHub Profile
@paulhuisman
paulhuisman / php_image_upload.php
Created November 30, 2012 15:53
Image upload in PHP
<?php
function save($category) {
$packageguide = JRequest::get( 'POST' );
$files = JRequest::get( 'FILES' );
if (isset($files['image_upload']) && !$files['image_upload']['error']) {
$dir = JPATH_ROOT.DS.'media'.DS.'packageguide'.DS.$category;
if(!file_exists($dir)) {
mkdir($dir, 0777, true);
}
move_uploaded_file($files['image_upload']['tmp_name'], $dir.DS.$files['image_upload']['name']);
@paulhuisman
paulhuisman / cookies_timer.php
Created November 30, 2012 15:55
Cookies check PHP
<?php
$cookie_value = NULL;
if (!isset($_COOKIE['overlay_display'])) {
$cookie_value = TRUE;
setcookie("overlay_display", $cookie_value, time()+31536000); // Expire in one year
}
else {
$cookie_value = intval($_COOKIE['overlay_display'])+1;
setcookie("overlay_display", $cookie_value, time()+31536000);
@paulhuisman
paulhuisman / modulo_end.php
Created November 30, 2012 15:56
Modulo and End PHP
<div class="block_content">
<?php $c = 0; foreach ($dossiers as $k => $dossier):
if ($c % 4 == 0) print '<div class="clearfix">';?>
<div class="dossier <?php if ($k % 4 == 3) print 'last'; ?>">
<?php if (!empty($dossier->article_image_filepath)): ?>
<a href="<?php print url('node/'.$dossier->nid); ?>"><?php print theme('imagecache', 'op_list', $dossier->article_image_filepath, '', '', array('class' => 'dossier_img')); ?></a>
<?php endif; ?>
<h4><a href="<?php print url('node/'.$dossier->nid); ?>"><?php print $dossier->title; ?></a></h4>
</div>
<?php if ($c % 4 == 3 || $count == (count($dossiers))) print '</div>';
@paulhuisman
paulhuisman / basic_html.html
Created December 12, 2012 09:49
Indenting test
<!DOCTYPE html>
<html>
<head>
<title>Moo test</title>
</head>
<body>
<h1>Moo</h1>
<p>Lorem ipsum..</p>
</body>
</html>
@paulhuisman
paulhuisman / ajax_callback_drupal.php
Last active December 15, 2015 04:49
Ajax Callbacks in Drupal Forms API
<?php
function partners_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
if ($entity_type != 'field_collection_item' || $entity->field_name != 'field_partner_products') {
return;
}
$form['#after_build'][] = 'partners_products_after_build';
$id = drupal_html_id('partners_field');
$form['#prefix'] = '<div id="'. $id .'">';
<?php
$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', array('column','blog'))
->propertyCondition('uid', $user->uid)
->propertyCondition('status', 1)
->propertyOrderBy('created', 'DESC')
->range(0, 3)
->execute();
@paulhuisman
paulhuisman / git commands
Last active August 29, 2015 13:57
Fancy git commands
// Cherry pick; edit message
git cherry-pick --edit 3fbd473
// Cherry pick; see where its cherry picked from
git cherry-pick -x bdf9578
// Cherry pick; put your username on the cherry pick
git cherry-pick --signoff bdf9578
@paulhuisman
paulhuisman / register_post_type.php
Created December 16, 2014 09:42
Register post type in WordPress
<?php
/* Register custom post types on the 'init' hook. */
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 0.1.0
* @access public
@paulhuisman
paulhuisman / simpleform_mails
Last active August 29, 2015 14:16
Simpleform Mailform Rails
# model; quotations.rb
class Quotation < MailForm::Base
attribute :name, :validate => true
attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :organisation, :validate => true
attribute :telephone, :validate => true
attribute :attachment, :attachment => true
attribute :message
# Declare the e-mail headers. It accepts anything the mail method
@paulhuisman
paulhuisman / flickr_field_example.php
Last active August 29, 2015 14:20
Flickr field code example
<?php $flickr_photostream = get_field('flickr_photoset'); ?>
<?php if (isset($flickr_photostream['items'])): ?>
<ul class="flickr-items">
<?php foreach ($flickr_photostream['items'] as $id => $photo): ?>
<li>
<a href="<?php echo $photo['large']; ?>" title="<?php echo $photo['title']; ?>">
<img src="<?php echo $photo['thumb']; ?>" />
</a>
</li>