Skip to content

Instantly share code, notes, and snippets.

View somatonic's full-sized avatar

Philipp Urlich somatonic

View GitHub Profile
@somatonic
somatonic / PageListActionHook.module
Created March 11, 2014 20:04
PageListActionHook example module to hook into page list actions
<?php
/**
* ProcessWire example demonstration module
*
* PageListActionHook autoload module once installed will remove "new" action from second level pages
* using the template "basic-page"
*
*/
@somatonic
somatonic / MyHelper.module
Created January 15, 2014 23:24
Example helper module that adds a new system variable "$helper" with a method to generate FontAwesome markup for use in templates
<?php
class MyHelper extends WireData implements Module {
/**
* getModuleInfo is a method required by all modules to tell ProcessWire about them
* @return array
*/
public static function getModuleInfo() {
return array(
'title' => 'My Helper Module',
@somatonic
somatonic / mylist.php
Last active January 3, 2016 05:49
page list select indent
<?php
$children = $pages->get("/shop/")->children();
$list = new PageArray();
function mylist($children, $ind='', $arr){
$ind .= "";
foreach($children as $cat) {
@somatonic
somatonic / get_field_settings.php
Last active January 2, 2016 15:29
get field settings via API
<?php
// via field settings
$field = $fields->get("title");
echo "width:" . $field->columnWidth;
// via template context
$tpl = $templates->get("basic-page");
$field = $tpl->fieldgroup->getField("title", true);
echo "width:" . $field->columnWidth;
@somatonic
somatonic / creat_zip_download.php
Last active March 6, 2018 17:33
create a zip file and send to browser
<?php
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
if(file_exists($destination) && !$overwrite) { return false; }
if(is_array($files)) {
foreach($files as $name => $file) {
if(!file_exists($file)) unset($files[$name]);
}
}
<?php
// stripped down code
$old_name = 'lizard.jpg';
$new_name = 'wizard';
$p = $pages->find("image.data=$old_name")->first();
$p->of(false); // outputformatting off, single and multiple image fields are from now on wire array's
@somatonic
somatonic / createTemplatesFields.php
Last active November 1, 2018 09:53
Create templates and fields using array.
<?php
// .... module
// create fields and templates using arrays
public function getTemplatesConfig() {
// title | field1 | field2 ...
$templatesArray = array(
'category' => array('title'),
@somatonic
somatonic / pw-multilevelnavbar-boostrap.php
Last active February 4, 2019 11:20
MarkupSimpleNavigation Example for Bootstrap 2.3.2 Multilevel Navbar
<?php
/*
MarkupSimpleNavigation Example for Bootstrap 2.3.2 Multilevel Navbar
*/
// load MarkupSimpleNavigation module
$nav = $modules->get("MarkupSimpleNavigation");
@somatonic
somatonic / image_tags.php
Last active December 18, 2015 16:09
Collect all tags from images field and create a link list to then filter pages with images that have the selected tag
<?php
/**
* collect all tags
* ======================================
*/
$alltags = array(); // container
$use_urlsegments = false;
@somatonic
somatonic / ImageCreateThumbs.module
Last active January 31, 2017 13:08
create thumbs when uploading image
<?php
class ImageCreateThumbs extends WireData implements Module {
public static function getModuleInfo() {
return array(
'title' => 'ImageCreateThumbs',
'version' => 100,
'summary' => '',