Skip to content

Instantly share code, notes, and snippets.

View Burick's full-sized avatar
🏠
Работаю из дома

Burick Burick

🏠
Работаю из дома
View GitHub Profile
@Burick
Burick / sample_csv_export.php
Created December 21, 2017 12:29 — forked from sepiariver/sample_csv_export.php
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();
@Burick
Burick / sample_csv_import.php
Created December 21, 2017 12:29 — forked from sepiariver/sample_csv_import.php
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();
@Burick
Burick / sample_json_export.php
Created December 21, 2017 12:28 — forked from sepiariver/sample_json_export.php
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');
@Burick
Burick / sample_json_import.php
Created December 21, 2017 12:28 — forked from sepiariver/sample_json_import.php
Imports a JSON file as output from the sample_json_export.php script.
<?php
// Only run 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');
@Burick
Burick / sample_json_export_config.json
Created December 21, 2017 12:27 — forked from sepiariver/sample_json_export_config.json
Example of JSON config file consumed by sample_json_export.php script.
[
{
"class": "modSnippet",
"where": [
{
"name:=": "SomeCustomSnippet"
}
],
"toWhere": "create"
},
<?php
/**
* getResourcesColumns
* @author @sepiariver
*
* &parent optional ID of Resource from which to fetch children. Defaults to current resource.
* &fields optional Resource field(s) from which to fetch values. Defaults to 'pagetitle,longtitle,introtext,parent,hidemenu'.
* &columns optional Number of columns to sort Resources into and wrap with colWrapper_n;
* &columnDirection optionalVertical or horizontal column sorting. Defaults to horizontal
* &depth optional Depth to seek children via getChildIds(). Defaults to 1
@Burick
Burick / quicklist.snippet.php
Created December 21, 2017 12:25 — forked from sepiariver/quicklist.snippet.php
Fast snippet for listing MODX Resources. Outputs generic HTML list with link to each Resource. Not template-able except wrapper.
<?php
/**
* quickList
*
* Lists Resourcs super fast. Uses code by Garry Nutting of the MODX Core Team.
*
* @author YJ Tso <[email protected]>, Garry Nutting <[email protected]>
*
*
* quickList is free software; you can redistribute it and/or modify it
@Burick
Burick / filterpathsegment.snippet.php
Created December 21, 2017 12:25 — forked from sepiariver/filterpathsegment.snippet.php
Use the MODX filterPathSegment method to filter a string value into valid URL syntax. Useful for HTML attribute values as well.
<?php
$options = $modx->getOption('options', $scriptProperties, $modx->getOption('friendly_alias_restrict_chars_pattern'), true);
return $modx->filterPathSegment($input, array('friendly_alias_restrict_chars_pattern' => $options));
@Burick
Burick / client_preview.plugin.php
Created December 21, 2017 12:25 — forked from sepiariver/client_preview.plugin.php
MODX Client Preview Plugin
<?php
if ($modx->context->get('key') === 'mgr') return;
$key = $modx->getOption('key', $scriptProperties, 'my-secret-key');
$val = $modx->getOption('val', $scriptProperties, 'my-secret-value');
switch ($modx->event->name) {
case 'OnHandleRequest':
if (!$modx->getOption('site_status')) {
if ($_GET[$key] === $val) {
$modx->config['site_status'] = 1;
@Burick
Burick / readtime.snippet.php
Created December 21, 2017 12:24 — forked from sepiariver/readtime.snippet.php
Reading time MODX output filter.
<?php
$options = (int) $modx->getOption('options', $scriptProperties, 200, true); // 200 words per minute
$wordCount = (int) str_word_count(strip_tags($input)); // To display word count set options to 0
if ($options === 0) return $wordCount;
return ceil($wordCount / abs($options));