Skip to content

Instantly share code, notes, and snippets.

View somatonic's full-sized avatar

Philipp Urlich somatonic

View GitHub Profile
@somatonic
somatonic / from.php
Last active June 26, 2018 19:23
Create a page edit form on frontend using PW API and fields from the template of the page
<?php
// get a page
$editpage = $pages->get("/editme/");
$ignorefields = array("isOld","language_published");
$form = $modules->get("InputfieldForm");
$form->method = 'post';
$form->action = './';
@somatonic
somatonic / HiddenAdminPages.module
Last active June 18, 2018 13:27
Hide page in the admin per user per page/branch
<?php
/**
* UserWorkspaces
*
* Example module to hide page in the admin per user per page.
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
@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]);
}
}
@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 / 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' => '',
@somatonic
somatonic / download.php
Created May 23, 2012 15:25
Download PHP Class
<?php
class download{
public function startDownload( $vFilePath, $vDownloadName=""){
$vFilename = basename( $vFilePath);
$vNewFilename = $vDownloadName == "" ? $vFilename : $vDownloadName;
$vFileType = $this->getFileType( $vFilename);
$vContentType = $this->GetContentType( $vFileType);
// Fix IE bug [0]
@somatonic
somatonic / form_with_fields_in_table.php
Last active August 29, 2016 13:52
form with fields rendered in a table example
<?php
/**
* Example form using PW API
*
* A workaround to get fields display in a table
* Those fields are marked with a property added to the fields $field->tablerow
*
* Approach is to grab those fields after form is put together and maybe processed,
* loop each row and render out the fields along with possible errors and add it to a string variable $table
* while we remove the field from the form at the same time.
@somatonic
somatonic / paginator.php
Last active March 22, 2016 01:46
manual pagination example for in memory page arrays
<?php
/**
* include paginator class from ProcessWire core, $config->paths->Modulename can
* be used to get the path of any module in PW.
*/
require_once($config->paths->MarkupPagerNav . "PagerNav.php");
/**
@somatonic
somatonic / PageReferenceLink.module
Created June 5, 2012 22:04
Add link from page reference fields - Module example
@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',