Skip to content

Instantly share code, notes, and snippets.

@argnist
argnist / ajax-chunk.php
Created April 7, 2014 07:35
Вывод содержимого чанка, например в Ajax.
if (!$modx->resource) {
$modx->resource = $modx->newObject('modResource');
$modx->resource->set('id', 5);
$modx->resource->set('pagetitle', 'isAPI');
$modx->resource->set('content', $modx->getChunk('Film.Search.Results'));
}
$modx->getResponse();
$modx->response->outputContent();
@argnist
argnist / upload.php
Created January 27, 2014 09:03
Самый простой способ загрузки файлов
$source = modMediaSource::getDefaultSource($modx);
$source->initialize();
$success = $source->uploadObjectsToContainer($path,$_FILES);
@argnist
argnist / twitterstyles.js
Last active January 3, 2016 16:49
Приятные стили для твиттера
// ==UserScript==
// @name Twitter Styles
// @namespace twitter
// @include https://twitter.com*
// @version 1
// @grant none
// ==/UserScript==
document.getElementsByTagName('head')[0].innerHTML += "<style>.content-main{width:880px;}.wrapper,.wrapper-narrow{width:1190px;}.nav > li{color:#CCCCCC;}.global-nav-inner{background:none repeat scroll 0 0 #333;}.content-header .header-inner,.content-no-header .no-header-inner{padding:2px 15px;}.content-header .header-inner h2{font-size:15px;}.stats > li > a *{color:#444444;font-size:17px;}.profile-card.profile-header{margin-right: 145px;}</style>";
@argnist
argnist / units.snippet.php
Created January 10, 2014 13:38
Snippet Units for multiple declinations
<?php
$forms = explode(',', $scriptProperties['forms']);
$n = $scriptProperties['count'];
if (count($forms) < 3) return;
if (($n % 10 == 1) && ($n % 100 != 11)) {
$return = $forms[0];
} elseif (($n % 10 >= 2) && ($n %10 <= 4) && ($n % 100 < 10 || $n % 100 >= 20)) {
$return = $forms[1];
@argnist
argnist / printPlaceholders.php
Created December 26, 2013 11:48
printPlaceholders snippet
<?php
if (!$modx->user->isAuthenticated('mgr')) return;
$placeholders = $prefix ? array() : $modx->placeholders;
if ($prefix) {
foreach ($modx->placeholders as $key => $ph) {
if (strpos($key, $prefix) === 0) {
$placeholders[$key] = $ph;
}
@argnist
argnist / email.html
Created December 24, 2013 04:10
Responsive emails
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Really Simple HTML Email Template</title>
<style>
/* -------------------------------------
GLOBAL
------------------------------------- */
<?php
// change:
/* handle file fields */
foreach ($origFields as $k => $v) {
$attachmentIndex = 0;
if (is_array($v) && !empty($v['tmp_name']) && isset($v['error']) && $v['error'] == UPLOAD_ERR_OK) {
if (empty($v['name'])) {
$v['name'] = 'attachment'.$attachmentIndex;
}
$this->modx->mail->mailer->AddAttachment($v['tmp_name'],$v['name'],'base64',!empty($v['type']) ? $v['type'] : 'application/octet-stream');
@argnist
argnist / orRequired.php
Last active December 30, 2015 02:49
Валидатор на заполненность телефона либо почты
<?php
if (($validator->required($param, $validator->fields[$param]) === true) || ($validator->required($key, $value) === true))
{
return true;
}
$validator->addError($key,'Почта и телефон пусты');
return false;
/*
@argnist
argnist / templatizerX.php
Created November 26, 2013 03:26
TemplatizerX - Дополнительно к кастомизации форм устанавливает шаблон в зависимости от шаблона родителя
<?php
switch ($modx->event->name) {
case 'OnDocFormRender':
if (!isset($_GET['template'])) {
$parent = isset($_GET['parent']) ? intval($_GET['parent']) : 0;
$templates = array(1 => 4, 6 => 13, 8 => 6, 5 => 6, 4 => 15, 7 => 11, 17 => array(16, 17));
if (isset($templates[$parent])) {
$template = $templates[$parent];
if (is_array($template)) {
@argnist
argnist / msorderbyphonehandler.class.php
Created July 4, 2013 10:22
Minishop2 OrderHandler с привязкой к телефону вместо емейла
<?php
class msOrderByPhoneHandler extends msOrderHandler {
public function getCustomerId() {
$order = $this->ms2->order->get();
if (empty($order['phone'])) {return false;}
if ($this->modx->user->isAuthenticated()) {
$profile = $this->modx->user->Profile;