Skip to content

Instantly share code, notes, and snippets.

@ijy
ijy / sym-merge-get-param-arrays.php
Last active December 21, 2015 14:19
A Symphony Event (for 2.3x) which looks at the query string produced from a front-end form submission using a GET request and for any keys which have multiple values it wraps them up into a single XML element in the parameter pool for use within datasources. The numeric ones are left in place.
<?php
require_once(TOOLKIT.'/class.event.php');
Class eventmerge_get_param_arrays extends Event {
public $eParamFILTERS = array(
);
@ijy
ijy / store-shipping-zones.php
Created August 26, 2013 12:01
A custom shipping plugin for Exp:resso Store (v1) allowing you to group shipping rules for various countries. Place this class in a file named: store/libraries/store_shipping/store_shipping_zones.php
class Store_shipping_zones extends Store_shipping_driver
{
/**
* Calculate the shipping total for an order.
* Use print_r($order) to see all the fields available to you.
* The fields available also match those in the Checkout tag:
* http://exp-resso.com/docs/store/tags/checkout.html
*
* @param array $order
*/
@ijy
ijy / 1.pagination.xsl
Last active December 23, 2015 03:09
Original Symphony CMS pagination utility by Nick Dunn. Add the pagination utiltity, import it into your page template, pass in required (and optional) paramaters, style with CSS. Examples included.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Name: DATA SOURCE PAGINATION
Version: 1.4 with custom elements
Author: Nick Dunn <[email protected]>, extended by Nils Hörrmann <[email protected]>
URL: http://symphony-cms.com/downloads/xslt/file/20482/
Required Parameters:
@ijy
ijy / 1.pagination.xsl
Created September 15, 2013 16:24
Modified pagination utility for Symphony CMS to (optionally) allow it to work with other query string parameters. Add the pagination utiltity, import it into your page template, pass in required (and optional) paramaters, style with CSS. Examples included.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Name: DATA SOURCE PAGINATION
Version: 1.5
Author: Nick Dunn <[email protected]>,
Nils Hörrmann <[email protected]>,
Ian Young <[email protected]>
URL: https://gist.github.com/ijy/6572186
@ijy
ijy / search-and-replace.xsl
Created September 15, 2013 16:35
XSLT 1.0 search and replace template.
<!--
SEARCH & REPLACE
string: The text to be evaluated
search: The character or string to look for in the above string
replace: What to replace it with
The output will neatly concatenate the string with replacements made.
-->
<xsl:template name="search-and-replace">
@ijy
ijy / search-and-replace-2.xsl
Created September 15, 2013 16:56
Alternative search and replace template for XSLT 1.0.
<!--
ALTERNATIVE SEARCH & REPLACE
string: The text to be evaluated
replace: The character or string to look for in the above string
with: What to replace it with
Slightly more long winded approach if that's how you prefer to roll.
-->
<xsl:template name="string-replace">
@ijy
ijy / check-null-empty.xsl
Created September 15, 2013 17:14
XSLT: Check if a string is null or empty.
<!--
CHECK IF A STRING IS NULL OR EMPTY
-->
<!-- Example XML -->
<group>
<item>
<id>item 1</id>
<CategoryName>blue</CategoryName>
</item>
@ijy
ijy / 1.nodestring.xsl
Last active December 23, 2015 03:39
Converts a node-set into a string (allows you to insert code blocks as text rather than being interpreted). Useful for things such as JSON conversions and displaying code snippets. @href: http://www.getsymphony.com/download/xslt-utilities/view/103039/ @href: http://www.getsymphony.com/discuss/thread/103015/
<xsl:variable name="html-ready">
<!-- prepare the HTML as you want it -->
</xsl:variable>
<!-- stringify it -->
<xsl:call-template name="nodetostring">
<xsl:with-param name="node" select="$html-ready"/>
<xsl:with-param name="esc-dblq" select="true()"/>
</xsl:template>
@ijy
ijy / xsl-output-html5.xsl
Created September 15, 2013 22:02
Force use of a dummy DTD (about:legacy-compat), which is the W3C recommended way of not using a standard DTD URI. Now the W3C validator will happily validate against the HTML5 specification rather than the XHTML 1.0 specification.
<xsl:output
method="xml"
doctype-system="about:legacy-compat"
encoding="UTF-8"
indent="yes" />
@ijy
ijy / xslt-random-bg-image.xml
Created September 18, 2013 20:07
Generate a random background image with XSLT, CSS, and Symphony CMS.
<!-- Add the 'math' namespace to your XML stylesheet (so we can use 'math:random') -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:math="http://exslt.org/math"
extension-element-prefixes="math">
<!-- Pick a random number between 1 - 10 and set as a variable -->
<xsl:variable name="random-bg">
<xsl:value-of select="(floor(math:random()*10) mod 10) + 1" />
</xsl:variable>