Skip to content

Instantly share code, notes, and snippets.

View somatonic's full-sized avatar

Philipp Urlich somatonic

View GitHub Profile
@somatonic
somatonic / TextAreaCounter.js
Created December 10, 2012 20:01
TextAreaCounter JScript
(function($){
$(function(){
$('textarea[data-maxlength]').each(function(){
$(this).bind("keyup change", function(){
var count = $(this).attr('data-maxlength') - $(this).val().replace(/\r?\n/g, '\r\n').length;
$(this).parent().find("span.counter span").text(count);
});
});
@somatonic
somatonic / MapPageField.module
Created December 19, 2012 08:32
maps two page fields POC
<?php
class MapPageField extends WireData implements Module{
public static function getModuleInfo(){
return array(
'title' => 'MapPageField',
'version' => 100,
'singular' => true,
'autoload' => true
@somatonic
somatonic / TextDomainHelper.module
Last active December 11, 2015 00:59
textdomain infos
<?php
class TextDomainHelper extends Wire implements Module {
public static function getModuleInfo() {
return array(
'title' => 'TextDomainHelper',
'version' => 1,
@somatonic
somatonic / pw_bootstrap_menu.php
Last active December 12, 2015 08:18
function to render nested Twitter Bootstrap menu markup
<?php
/**
* render markup menu for bootstrap nested navigation
*
* @param PageArray $pa pages of the top level items
* @param Page $root root page optional, if you use other root than home page (id:1)
* @param string $output for returned string collection
* @param integer $level internally used to count levels
* @return string menu html string
@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 / prev_next_day_posts.php
Last active December 14, 2015 09:49
example to render today posts with prev day next day links if found . with url segments for category and day date
<?php
/*
* as per http://processwire.com/talk/topic/2928-pagination-by-date/
* list posts by day, show prev next day if any posts found
*
* - posts have a date field "publish_from"
* with no time selection but only days
* this will save the timestamp of today 00:00 (starting) so we can simply
* use "publish_from=$prevday" in selectors
@somatonic
somatonic / posts.php
Created March 1, 2013 23:29
This script generates a list of post with a prev next pagination to show posts of a specified day and category through urls segments
<?php
// include("./head.inc");
/**
* Script Example
*
* This script generates a prev next pagination to show posts per day of a specified date
* The category is set by the first url segment the date in the second
@somatonic
somatonic / language_switch.php
Last active December 14, 2015 18:39
language switch for LanguageLocalizedURL module example
<?php
/* somehwere in the top of your template code */
// save current user language
$user_lang = $user->language;
// get the language name example
$curr_langname = $user_lang->name == 'default' ? 'en' : $user_lang->name;
@somatonic
somatonic / AddPageFieldProperty.module
Last active December 14, 2015 23:29
add page field as property to page example
<?php
/**
* ProcessWire AddPageFieldProperty demonstration module
*
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
@somatonic
somatonic / form-process.php
Last active May 24, 2023 18:26
ProcessWire example front-end form with file upload and fields
<?php
// ------------------------------ FORM Processing ---------------------------------------
$errors = null;
$success = false;
// helper function to format form errors
function showError($e){
return "<p class='error'>$e</p>";