Skip to content

Instantly share code, notes, and snippets.

View hampusn's full-sized avatar

Hampus Nordin hampusn

View GitHub Profile
@hampusn
hampusn / predefinedsearch-hits-template.vm
Created April 3, 2019 11:01
Söklistning: Standardmall med "skapad av"
##
## Utility API
#set ($outputUtil = $sitevisionUtils.outputUtil)
#set ($portletContextUtil = $sitevisionUtils.portletContextUtil)
#set ($resourceLocatorUtil = $sitevisionUtils.resourceLocatorUtil)
#set ($scriptUtil = $sitevisionUtils.scriptUtil)
#set ($docTypeUtil = $sitevisionUtils.docTypeUtil)
##
## Portlet properties
@hampusn
hampusn / queryobject.js
Last active September 29, 2017 12:17
Get query parameters as literal object.
// Get query parameters as literal object.
var queryObject = (function (queryParams, k, v) {
return queryParams.reduce(function (params, p) {
if ((p = p.split('=')).length) {
k = p[0];
v = p[0];
params[k] = (typeof params[k] !== 'undefined') ? (Array.isArray(params[k]) ? params[k] : [params[k]]).concat(v) : v;
}
return params;
}, {});
@hampusn
hampusn / query.vm
Last active February 4, 2017 09:19
sv-fb-predefined-search-portlet-velocity-example
#set( $propertyUtil = $sitevisionUtils.propertyUtil )
#set( $currentPage = $sitevisionUtils.portletContextUtil.currentPage )
#set( $metadataValue = $propertyUtil.getString($currentPage, 'META', '') )
#if( "$!metadataValue" != "" )
+metadata.META:"$metadataValue"
#end
@hampusn
hampusn / script-module-client.js
Last active December 15, 2016 13:48
script-module
/**
* [MODULE NAME]
*
* Limepark AB, 2016
*/
(function (window, document, $) {
// ...
// Document Ready
@hampusn
hampusn / dummy
Created June 9, 2016 21:22
Bash-script to download an image from placehold.it
#!/usr/bin/env bash
####################################################
# Script to download a dummy/placeholder image.
####################################################
if [ -z "$1" ]; then
echo "Missing argument with the pixel dimensions (try 'dummy 250x200')"
exit 1
fi
@hampusn
hampusn / svv
Created June 4, 2016 23:58
Bash-script to get the current SiteVision version for a URL
#!/usr/bin/env bash
####################################################
# Script to get the SiteVision version of a URL.
# This depends on the linked assets having the
# version number in their URLs.
####################################################
if [ -z "$1" ]; then
echo "Missing argument (URL)"
@hampusn
hampusn / functions.php
Last active December 13, 2015 11:44
FB: ACF field to body_class() via filter
<?php
/**
* WP Filter which adds acf field value to body classes for all pages but home.
*
* @see https://codex.wordpress.org/Plugin_API/Filter_Reference/body_class
*/
function THEME_NAME_body_class( $classes ) {
if ( function_exists( 'get_field' ) && ! is_home() ) {
$classes[] = get_field( 'page_background' );
@hampusn
hampusn / wpml-detach-duplicates.sql
Created June 11, 2015 07:39
SQL queries to detach WPML duplicates and translate them separately.
# Select all posts which are duplicates of a language.
# The language parameter is to only select by the new language (not the original duplication language).
SET @lang_code = 'da';
SELECT pm.*, p.post_title, p.post_type, icl.language_code
FROM wp_postmeta pm
INNER JOIN wp_icl_translations icl ON icl.element_id = pm.post_id
INNER JOIN wp_posts p ON p.`ID` = pm.post_id
WHERE meta_key='_icl_lang_duplicate_of' AND icl.language_code = @lang_code;
@hampusn
hampusn / cleanup-xliffs.php
Last active August 29, 2015 14:21
PHP CLI script for removing specific XMLNodes from WPML Xliff files.
<?php
/**
* Cleanup Xliffs
*
* This file can be called through the php cli and clean up xliff files.
*
* The script takes directories and/or xliff files and removes XML nodes which
* matches the XPath query.
*
* @author Hampus Nordin <hej@hampusnord.in>
@hampusn
hampusn / wp-switch-domain.sql
Last active September 30, 2015 08:15
SQL queries to switch domain on WP site.
# If you get an error about illegal mixes of collation you might need to force the collation.
# SET NAMES 'utf8' COLLATE 'utf8_unicode_ci';
SET @old_url = 'http://www.oldurl.com';
SET @new_url = 'http://www.newurl.com';
UPDATE wp_options SET option_value = replace(option_value, @old_url, @new_url) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, @old_url, @new_url);
UPDATE wp_posts SET post_content = replace(post_content, @old_url, @new_url);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @old_url, @new_url);