Skip to content

Instantly share code, notes, and snippets.

View davidpede's full-sized avatar

David Pede davidpede

View GitHub Profile
@davidpede
davidpede / .htaccess
Last active February 5, 2025 16:41
Disable caching using .htaccess
<IfModule mod_headers.c>
# Disable caching by sending no-cache headers
Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
Header set Pragma "no-cache" # Adds compatibility for older HTTP 1.0 caches
Header set Expires 0
</IfModule>
@davidpede
davidpede / .htaccess
Last active February 5, 2025 16:26
File caching using .htaccess
RewriteEngine On
RewriteBase /
### ---REWRITE DYNAMIC CACHE VERSION URL--- ###
# EXAMPLE: http://domain.com/css/prp-styles_ver<timestamp>.css
# RewriteRule (.*)_ver\d+\.(.*)$ $1.$2 [L]
### ---REWRITE DYNAMIC CACHE VERSION URL--- ###
### ---CACHE HEADER CONTROL--- ###
@davidpede
davidpede / gist:1f3c2f76967e655668b28b035dd9c4af
Last active March 1, 2024 09:25
Usergroup membership check
<?php
/**
* Checks current users group membership
*
* @var modX $modx
* @var array $scriptProperties
*/
/* set default properties */
$usergroup = $modx->getOption('usergroup',$scriptProperties);
$sendError = $modx->getOption('sendError',$scriptProperties) == 1 || null;
@davidpede
davidpede / gist:548603972d82db6ee6c6c8737b18adec
Created July 28, 2020 10:45
CSS calc image aspect ratio in percentage from pThumb placeholders
padding-top: padding-top:calc( ([[+height]]% / [[+width]]) * 100 );
$c->where("CAST(width AS DECIMAL(5,3)) = {$_REQUEST['width']}");
$query = $this->modx->newQuery('modUser');
//checks
$query->where(array(
'active' => 1,
'Profile.blocked' => 0
));
//by usergroup
$query->where(array('primary_group:IN' => array(1,2,3)));
//by id
$query->where(array('id:IN' => array(1,2,3)),xPDOQuery::SQL_OR); //<-- uses OR condition
$query = $this->modx->newQuery('modUser');
$query->innerJoin('modUserProfile','Profile');
//Select ALL fields from both tables
$query->select(array('modUser.*, Profile.*'));
---
$query->select(array('modUser.*'));
$query->select($this->modx->getSelectColumns('modUserProfile','Profile','profile_'));
//Select SPECIFIC fields from both tables
@davidpede
davidpede / gist:89ea36465147074e32210bba5a4e7f10
Created July 14, 2017 11:07
Load lexicons in controller examples
public function render() {
//$this->modx->controller->addLexiconTopic('core:dashboard');
$this->controller->addJavascript($this->modx->getOption('manager_url').'assets/modext/widgets/security/modx.grid.user.online.js');
$this->controller->addHtml('
<script type="text/javascript">
Ext.applyIf(MODx.lang, '. $this->modx->toJSON($this->modx->lexicon->loadCache('core', 'dashboard')) .');
Ext.onReady(function() {
MODx.load({
xtype: "modx-grid-user-online"
$query = $this->modx->newQuery('ClassName');
$query->where(array(
'project_id' => x
,'unit_id' => y
));
$query->select(array(
'ClassName.*',
'array_node' => 'GROUP_CONCAT(DISTINCT colname_from_joined_table SEPARATOR " , ")'
));
@davidpede
davidpede / gist:38bcdc9783edfe74bb910d2485d3b446
Created July 11, 2017 10:01
Print_r from processors to error log
$this->modx->log(xPDO::LOG_LEVEL_ERROR,'Label: ' . print_r($my_output, true));