Skip to content

Instantly share code, notes, and snippets.

Philipp Urlich somatonic

View GitHub Profile
@somatonic
somatonic / creat_zip_download.php
Last active Mar 6, 2018
create a zip file and send to browser
View creat_zip_download.php
<?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 Mar 11, 2014
PageListActionHook example module to hook into page list actions
View PageListActionHook.module
<?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 / upload_images_to_page_form.php
Created Nov 26, 2012
Upload Images to new created Page Form Example
View upload_images_to_page_form.php
<?php
// front-end form example with multiple images upload
// add new page created on the fly and adding images
$message = '';
if($input->post->submit){
// tmp upload folder for additional security
@somatonic
somatonic / ImageCreateThumbs.module
Last active Jan 31, 2017
create thumbs when uploading image
View ImageCreateThumbs.module
<?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
Download PHP Class
View download.php
<?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 Aug 29, 2016
form with fields rendered in a table example
View form_with_fields_in_table.php
<?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 Mar 22, 2016
manual pagination example for in memory page arrays
View paginator.php
<?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 Jun 5, 2012
Add link from page reference fields - Module example
View PageReferenceLink.module
@somatonic
somatonic / MyHelper.module
Created Jan 15, 2014
Example helper module that adds a new system variable "$helper" with a method to generate FontAwesome markup for use in templates
View MyHelper.module
<?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 Jan 3, 2016
page list select indent
View mylist.php
<?php
$children = $pages->get("/shop/")->children();
$list = new PageArray();
function mylist($children, $ind='', $arr){
$ind .= "– ";
foreach($children as $cat) {
You can’t perform that action at this time.