Skip to content

Instantly share code, notes, and snippets.

View zaigham's full-sized avatar
🌏

Zaigham R. zaigham

🌏
View GitHub Profile
<?php
/**
* A custom FormIt hook for CSRF Protection
*
* Usage:
* Append this Plugin as PreHook and Hook
*
* [[!FormIt?
* &preHooks=`FormItCSRF`
* &hooks=`spam,FormItCSRF,email`
@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');
@Mark-H
Mark-H / PoweredBy.php
Created January 26, 2016 18:27
MODX X-Powered-By header
<?php
/**
* Add as a plugin
* System Event: OnHandleRequest
*/
if (!headers_sent()) {
header('X-Powered-By: MODX Revolution');
}
@MikeNGarrett
MikeNGarrett / wp-config.php
Last active July 17, 2024 18:02
All those damned wp-config constants you can never remember.
<?php
// PHP memory limit for this site
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' ); // Increase admin-side memory limit.
// Database
define( 'WP_ALLOW_REPAIR', true ); // Allow WordPress to automatically repair your database.
define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true ); // Don't make database upgrades on global tables (like users)
// Explicitely setting url
@sottwell
sottwell / Messages
Last active February 2, 2019 10:27
Dashboard Widget to display the number of internal Manager messages the user has - MODX Revoluition
// Dashboard widget to show number of Manager messages
$id = $modx->user->get('id');
$output = 'No messages.';
$total = $modx->getCount('modUserMessage',array(
'recipient' => $id,
));
if($total) {
$output = 'You have ' . $total . ' messages';
$unread = $modx->getCount('modUserMessage',array(
'recipient' => $id,
@goldsky
goldsky / includeFile.snippet.php
Last active July 20, 2016 12:46
includeFile snippet is to include any file in MODX's page, either in resource, template, or chunk
<?php
/**
* includeFile snippet is to include any file in MODX's page, either in resource, template, or chunk
*
* @author goldsky <goldsky@virtudraft.com>
* @copyright Copyright (c) 2015, goldsky
* @example [[!includeFile? &file=`[[++core_path]]statics/chunks/mychunk.chunk.tpl`]]
* [[!includeFile? &file=`[[++core_path]]statics/snippets/mysnippet.snippet.php`]]
*
@ghalusa
ghalusa / youtube_id_regex.php
Created June 20, 2015 23:14
Extract the YouTube Video ID from a URL in PHP
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
@sottwell
sottwell / ErrorLog
Last active August 11, 2017 05:45
Dashboard Widget to report on Manager error log - MODX Revolution
<?php
// Dashboard widget to report on the number of errors in the Error Log
$logfile = MODX_CORE_PATH . 'cache/logs/error.log';
if(!$f = fopen($logfile, 'rb')) return 'Could not open log file.';
$lines = 0;
while (!feof($f)) {
$lines += substr_count(fread($f, 8192), "(ERROR ");
}
@sottwell
sottwell / SiteSummary
Last active May 12, 2017 21:20
Pretty Site Summary dashboard widget - original by W. Shawn Wilkerson - MODX Revolution
<?php
// SiteSummary snippet for Dashboard widget
// W. Shawn Wilkerson
$o = '<table class="classy" style="width:100%;"><thead><tr style="background:#DDE3EA;color:#000;">';
$o .= '<th style="width:50%;padding:8px 0;text-align:center;">Resources</th>';
$o .= '<th style="width:50%;padding:8px 0;text-align:center;">Elements</th>';
$o .= '</tr></thead><tbody><tr><td style="padding:0 1em;">';
$o .= 'Published Resources: ' . $modx->getCount('modResource', array('published' => '1'));
$o .= '<br>Unpublished Resources: ' . $modx->getCount('modResource', array('published' => '0'));