Skip to content

Instantly share code, notes, and snippets.

View CanRau's full-sized avatar
🤓
coding

Can Rau CanRau

🤓
coding
View GitHub Profile
<?php
/**
* Roskis
*
* Adds custom trash view that can be also accessed by defined roles
* Pages in trash can be searched, sorted and restored.
*
*
* Copyright 2013 by Antti Peisa
// Override limit based on user input
if($userLimit = (int) $input->get->limit) {
$remeberLimit = "?limit=$userLimit";
$limit = $userLimit;
$input->whitelist('limit', $limit);
}
// Get year filter
if($userYear = (int) $sanitizer->selectorValue($input->get->year)) {
$year = $userYear;
<?php
/* Batch delete all fields containing order_ in name */
foreach($fields->find("name%=order_") as $field) {
$fields->delete($field);
if (!$fields->get($field)) echo "<p>field {$field->name} was deleted.</p>";
}
/* list all templates and provide ability to delete unused ones */
if ($input->post->submit) {
@CanRau
CanRau / gist:9f70d68066983e669167
Last active October 23, 2017 04:49
Get Pinterest full size images
$json = file_get_contents('https://api.pinterest.com/v3/pidgets/boards/Globetrawter/natural-homes/pins/');
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key) {
// get only url you can var_dump($key) and see what you like ;-)
if(isset($key['url']) && strpos($key['url'], '.jpg') !== false) {
@CanRau
CanRau / jquery-to-vanilla-js.md
Last active August 29, 2015 14:26 — forked from jhafner/jquery-to-vanilla-js.md
jQuery methods in vanilla JavaScript.

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
<?php namespace ProcessWire;
/**
* An Inputfield for handling relational Page inputs
*
* Delegates the actual input control to a user-defined Inputfield derived from InputfieldSelect
*
* @method PageArray getSelectablePages(Page $page)
* @method PageArray findPagesCode(Page $page)
*
@CanRau
CanRau / TextformatterBlogImages.module
Last active April 18, 2019 10:48
Please read https://processwire.com/talk/topic/13471-better-ckeditor-image-insertion-at-least-for-me/ I'm fixing some bugs right now and am rearranging the whole thing
<?php
/**
* Add to any textarea field from field settings
* or place the following code into any template file
*
* $modules->TextformatterBlogImages->formatValue($page, new Field(), $page->body);
* where $page->body is your textarea
*
* make sure to review path to simple_html_dom.php
*
@CanRau
CanRau / git-notes
Last active August 14, 2016 15:13
git notes
/**
* Git create empty branch
*/
git checkout --orphan <branchname> # branch without parents
git rm --cached -r . # clear the working directory
/**
* rename git branch locally and remotely
* @from https://gist.github.com/lttlrck/9628955
@CanRau
CanRau / fix-homebrew-npm.md
Created November 3, 2016 13:22 — forked from DanHerbert/fix-homebrew-npm.md
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

Solution

This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

<?php
$field = $fields->get("field_name_here"); // Insert system field i.e. roles
$field->flags = Field::flagSystemOverride;
$field->flags = 0;
$field->save();