Skip to content

Instantly share code, notes, and snippets.

@ig0r74
ig0r74 / redirect.php
Created August 26, 2016 11:32
Редирект с index.php на /
<?php
switch($modx->event->name){
case 'OnMODXInit':
if(strpos($_SERVER['REQUEST_URI'], '/index.php') === 0){
$modx->sendRedirect($modx->getOption("base_url", null, '/'), array(
'responseCode' => 'HTTP/1.1 301 Moved Permanently'
));
return;
}
@ig0r74
ig0r74 / pars_category.php
Created September 2, 2016 17:33
Парсер сайта на примере poverka-ndt.ru
<?php
print '<pre>';
class parserXPath extends DOMXPath {
private function getPage($url){
$ch = curl_init();
curl_setopt ($ch , CURLOPT_URL , $url);
curl_setopt ($ch , CURLOPT_USERAGENT , "Mozilla/5.0");
curl_setopt ($ch , CURLOPT_RETURNTRANSFER , 1 );
// можете добавить кучу других опций
@ig0r74
ig0r74 / SmartyForms.php
Last active May 23, 2020 16:53
Настройка AJAX форм
<?php
//***************************************************
//ModxSitecore/processors/web/public/action.class.php
//Добавить:
//***************************************************
case 'forms/callback':
require_once dirname(dirname(__FILE__)) . '/forms/callback.class.php';
self::$actualClassName = "modWebFormsCallbackProcessor";
break;
@ig0r74
ig0r74 / ChangeTemplate.php
Created October 9, 2016 18:26
Плагин для автоматического назначения шаблона дочерним ресурсам
<?php
/**
* =========================
* ChangeTemplate
* =========================
*
* Plugin for MODX Revolution
* Set which template is inherited by children
* documents of a certain parent document
*
@ig0r74
ig0r74 / tvfilter.tpl
Last active September 8, 2019 19:58
Как в MODX (pdoResources) сортировать/выводить данные по диапазону чисел в TV-параметре?
[[pdoResources?
&tpl=`showList`
&includeTVs=`number,image`
&limit=`10`
&prepareTVs=`number`
&where=`{"number:>=":"010","number:<=":"100"}`
]]
[[!pdoPage?
&limit=`5`
@ig0r74
ig0r74 / del.php
Created March 25, 2017 00:03
Удаление старых версий пакетов MODX (запускать из консоли "php del.php")
<?php
define('MODX_API_MODE', true);
require 'index.php';
$modx->getService('error', 'error.modError');
$modx->setLogLevel(modX::LOG_LEVEL_ERROR);
$modx->setLogTarget('ECHO');
if (!XPDO_CLI_MODE) {
echo '<pre>';
}
@ig0r74
ig0r74 / convert.php
Created April 27, 2017 14:47
Преобразование из windows-1252 в utf-8
<?php
$text = 'Ìàðèíà';
$text = iconv("utf-8", "windows-1252", $text);
$text = iconv("windows-1251", "utf-8", $text);
echo $text;
@ig0r74
ig0r74 / csv-to-php.php
Created June 19, 2017 20:02
CSV to PHP
<?php
$csvData = file_get_contents($fileName);
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line);
}
print_r($array);
@ig0r74
ig0r74 / acetv.plugin.php
Created August 10, 2017 09:19
ACE Editot TV-type. Plugin listen OnDocFormRender event and must be execute after Ace plugin, so set priority something like 10 or higher. TV type must be textarea.
<?php
//Apply ace editor to TV with id 5 and 7
$tvs = array(
array(
'id' => 5,
'height' => '600px',
'mimeType' => 'application/json'
),
array(
'id' => 7,
@ig0r74
ig0r74 / gallery_ajax_pagination.tpl
Last active February 23, 2018 17:28
AJAX-пагинация MODX Gallery + leftJoin