Skip to content

Instantly share code, notes, and snippets.

View sepiariver's full-sized avatar

YJ Tso sepiariver

View GitHub Profile
@sepiariver
sepiariver / sample_json_export.php
Last active December 22, 2023 12:26
Example of export script from MODX Resources to JSON, for importing to another site.
<?php
// Only executable via SSH
if (PHP_SAPI !== 'cli') exit();
// Instantiate MODX
@include(dirname(__FILE__) . '/config.core.php');
if (!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', dirname(__FILE__) . '/core/');
include_once (MODX_CORE_PATH . "model/modx/modx.class.php");
$modx= new modX();
$modx->initialize('web');
@sepiariver
sepiariver / rootResource.php
Last active December 19, 2023 12:48
Get the ID of the "Root Resource", aka "Ultimate Parent", with slightly different feature set.
<?php
/*
* @author @sepiariver
*
* GPL license, no warranties, no liability, etc.
*
* USAGE EXAMPLE:
* [[rootResource? &toPlaceholder=`root_resource`]]
* //followed by something like
@sepiariver
sepiariver / sample_csv_export.php
Last active January 16, 2023 11:53
Example export script to turn MODX Resources into CSV entries for importing in another site.
<?php
// Only run this via SSH
if (PHP_SAPI !== 'cli') return;
// Sometimes helpful if processing lots of Resources
ini_set('memory_limit', '2048M');
// Init @modx
@include(dirname(__FILE__) . '/config.core.php');
if (!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', dirname(__FILE__) . '/core/');
include_once (MODX_CORE_PATH . "model/modx/modx.class.php");
$modx= new modX();
@sepiariver
sepiariver / sample_csv_import.php
Last active May 31, 2022 21:03
Consumes CSV as output by the sample_csv_export.php script
<?php
// Only ssh users can execute
if (PHP_SAPI !== 'cli') return;
// Comes in handy sometimes
ini_set('memory_limit', '2048M');
// Instantiate MODX
@include(dirname(__FILE__) . '/config.core.php');
if (!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', dirname(__FILE__) . '/core/');
include_once (MODX_CORE_PATH . "model/modx/modx.class.php");
$modx= new modX();
@sepiariver
sepiariver / cbGetLayoutSetting.snippet.php
Last active August 20, 2021 06:16
Gets a ContentBlocks Layout setting.
<?php
/**
* Use the cbGetLayoutSetting snippet to get a setting from a particular layout.
* @author YJ Tso @sepiariver <yj@modx.com>
* @param (id) &resource allows checking for fields on other resources.
* @param (bool) &showDebug return debugging info as JSON.
* @param (string) &toPlaceholder set a placeholder with this string as key, instead of returning.
* @param required (int) &layout - ID of ContentBlocks layout from which to fetch the setting.
* @param required (string) &setting - key of layout setting to return.
*
@sepiariver
sepiariver / performance.conf
Created February 7, 2021 20:03 — forked from JamiesonRoberts/performance.conf
Apache Security Headers Setup for Serverpilot
Header set Connection keep-alive
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/svg+xml "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
@sepiariver
sepiariver / twog-modx.html
Last active February 26, 2020 15:01
Twitter/OG Meta Tags for MODX
<!-- Open Graph Tags -->
<meta property="og:site_name" content="[[++site_name]]" />
<meta property="og:type" content="article" />
<meta property="og:title" content="[[*longtitle:default=`[[*pagetitle]]`]]" />
<meta property="og:description" content="[[*description:default=`[[++site_description]]`]]" />
<meta property="og:url" content="[[~[[*id]]? &scheme=`full`]]" />
<meta property="og:image" content="[[*image:default=`[[++site_image]]`]]" />
<meta property="fb:app_id" content="[[++fb_app_id]]" />
<meta property="article:publisher" content="[[++fb_url]]" />
<!-- Twitter Tags -->
<?php
$input = $modx->getOption('input', $scriptProperties, '', true);
$output = $modx->getOption('options', $scriptProperties, '', true);
$classnames = explode(' ', $input);
$results = [];
foreach ($classnames as $token) {
// Strip out any % encoded octets
$normalized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $token);
// Replace _ with - and lowercase for old times' sake
.box
{
text-align:center;
padding:0px;
box-shadow:none;
}
.thing,.box-header,.box-footer,.box-bit
{
background:#39f;

Keybase proof

I hereby claim:

  • I am sepiariver on github.
  • I am sepiariver (https://keybase.io/sepiariver) on keybase.
  • I have a public key ASD1X6kMkDJf-qfi4YYBtldsTf2jTVPO46PCj5ur4w6sSQo

To claim this, I am signing this object: