Skip to content

Instantly share code, notes, and snippets.

View Da-Fecto's full-sized avatar

Martijn Geerts Da-Fecto

View GitHub Profile
@Da-Fecto
Da-Fecto / HideUneditablePages.module
Last active August 29, 2015 14:13
Module to hide pages that are not editable by the logged in user.
<?php
/**
* This module is build by Adrian, tnx Adrian.
*
*
* Module to hide pages that are not editable by the logged in user.
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
@Da-Fecto
Da-Fecto / fractural-grid.php
Last active August 29, 2015 14:15
Build a CSS fractural grid.
<?php
/**
* Build a CSS fractural grid.
*
* @var (int) $columns, Amount of columns, 10 columns means 10 columns of 10% width
* @var (string) $prefix, Classname prefix
*/
@Da-Fecto
Da-Fecto / templates-folder-switch.php
Last active May 6, 2016 05:23
Templates folder switch for ProcessWire
<?php
/**
* Switch ProcessWire templates directory on $_SERVER['HTTP_HOST']. Type the
* Hostname as key and the name of the new templates folder as value.
*
*/
$config->templates = array(
'mobile.domain.dev' => 'templates-mobile', // domain => templates folder name
@Da-Fecto
Da-Fecto / bidirectional
Last active August 29, 2015 14:18
Bidirectional save & remove of products & groups (Fieltype pages)
<?php
/**
* Groups & Products references guard.
*
* Bidirectional save & remove of products & groups
*
* templates:
* - 'group', pagefield: page_products
* - 'product', pagefield: page_groups
@Da-Fecto
Da-Fecto / gist:53b68d309fe98f3a15df
Last active August 29, 2015 14:22
Work in progress
<?php
/**
* JSON response with a “standardized” structure
*
* @author ©2015 Martijn Geerts
*
* ---------------------------------------------------------------------------------------
*
* 4 types: success, redirect, fail, error
@Da-Fecto
Da-Fecto / gist:c7c3f236f83e6690e0af
Last active August 29, 2015 14:24
Formbuilder Handler.php
<?php
$config->form = array(
// Name of the formbuilder form
'formName' => $form_name,
// Redirect to here after successful submit.
'successUrl' => $success_url,
// Global error message after faulty submit.
'errorMessage' => $error_message,
);
// Stolen code, thanks Soma !
public function init() {
$this->addHookAfter("ProcessPageView::pageNotFound", $this, "hook404Page");
}
public function hook404Page($event){
header("HTTP/1.1 404 Page Not Found");
$page = wire("pages")->get("/404/"); // get your 404 page
$this->wire('page', $page);
$event->return = $page->render(); // render and return that page
// author: http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
<?php
// Module from ryan....
class CustomPageRoles extends WireData implements Module {
/**
* Provide information about this module to ProcessWire
*
*/
<?php
array('icon-glass','music','search','envelope-alt','heart','star','star-empty','user','film','th-large','zoom-out','off','signal','cog','trash','home','file-alt','time','road','download-alt','refresh','list-alt','lock','flag','headphones','volume-off','volume-down','volume-up','qrcode','camera','font','bold','italic','text-height','text-width','align-left',''align-center','align-right','align-justify','pencil','map-marker','adjust','tint','edit','share','check','move','step-backward','fast-backward','fast-forward','step-forward','eject','chevron-left','chevron-right','plus-sign','minus-sign','remove-sign','ok-sign','question-sign','arrow-left','arrow-right','arrow-up','arrow-down','share-alt','resize-full','resize-small','plus','minus','asterisk','eye-close','warning-sign','plane','calendar','random','comment','magnet','chevron-up','chevron-down','retweet','bar-chart','twitter-sign','facebook-sign','camera-retro','key','cogs','comments','thumbs-up-alt','thumbs-down-alt','star-half','signin','trophy','gi