Skip to content

Instantly share code, notes, and snippets.

@timkelty
timkelty / Custom_ElementApiHelper.php
Last active January 22, 2019 06:55
Standardize Element API requests
<?php
namespace Craft;
class Custom_ElementApiHelper
{
public static function getParams($params)
{
$requestParams = array_filter([
'elementType' => craft()->request->getParam('elementType'),
'criteria' => Custom_ElementApiHelper::prepCriteria(craft()->request->getParam('criteria')),
@lukeholder
lukeholder / import.php
Last active January 10, 2018 09:58
Basic example to import Products and their variants into Craft Commerce
<?php
namespace Craft;
// This file could be placed into your public_html folder and visited to import a cheese product.
$craft = require '../craft/app/bootstrap.php';
$craft->plugins->loadPlugins();
$newProduct = new Commerce_ProductModel();
@peterknolle
peterknolle / FileController.cls
Last active January 30, 2023 20:40
Lightning File Upload Component
public class FileController {
@AuraEnabled
public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) {
base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
Attachment a = new Attachment();
a.parentId = parentId;
a.Body = EncodingUtil.base64Decode(base64Data);

###Edit this file

/etc/nginx/nginx.conf

###Add this line anywhere inside the http { } block:

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

###Go to your Forge panel and restart Nginx

@gruber
gruber / Liberal Regex Pattern for Web URLs
Last active March 20, 2024 20:28
Liberal, Accurate Regex Pattern for Matching Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
@brandonkelly
brandonkelly / gist:8672116
Created January 28, 2014 17:26
A function for converting an entry in Craft to JSON
<?php
public function getEntryJson(EntryModel $entry)
{
$entryData = array();
foreach ($entry->getType()->getFieldLayout()->getFields() as $field)
{
$field = $field->getField();
$handle = $field->handle;
@brandonkelly
brandonkelly / templating.md
Last active February 7, 2024 15:20
Templating in EE vs. Craft
@kenzie
kenzie / craft.conf
Last active May 17, 2018 17:48
Nginx virtual host configuration for Craft CMS, PHP5-FPM, NGINX 1.2.1 and craft/config/general.php for friendly URLs.
server {
listen 80;
root /var/www/craft.dev/public;
index index.php index.html index.htm;
server_name craft.dev;
location / {
try_files $uri $uri/ @rewrites;
@joshbirk
joshbirk / rsshandler.java
Created October 30, 2012 19:54
RSS Handler
global class RSSHandler implements Schedulable {
global RSSHandler() {
}
global void execute(SchedulableContext c) {
updateDeveloperBlog();
}
@aknosis
aknosis / calendar.twig
Created October 22, 2012 15:52
Table based calendar only using Twig
{#
time can be any string acceptable by http://www.php.net/strtotime, the
template will output that time's month.
If you don't want to pass in a date you can set time like this:
{% set time = "now"|date("U") %}
{% set time = "December 2012"|date("U") %}
How ever you want to output items onto the calendar is a different issue,
but I'd assume pushing everything into an array numerically indexed by that day: