Skip to content

Instantly share code, notes, and snippets.

View y3llbts's full-sized avatar
:electron:
WEB Developer

Mikhail Sidorchuk y3llbts

:electron:
WEB Developer
View GitHub Profile
@y3llbts
y3llbts / article_search.php
Created November 13, 2019 12:32
Активный поиск по артикулу
<?
// bitrix/php_interface/init.php
if (!function_exists('mb_ucfirst') && extension_loaded('mbstring')):
/**
* mb_ucfirst - преобразует первый символ в верхний регистр
* @param string $str - строка
* @param string $encoding - кодировка, по-умолчанию UTF-8
* @return string
@y3llbts
y3llbts / delete_all.php
Created November 12, 2019 06:14
Удаление всех элементов инфоблока
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
set_time_limit(0);
ini_set('max_execution_time', '3600');
ini_set('memory_limit', '512M');
$c_elem = 0;
$c_sect = 0;
@y3llbts
y3llbts / function.php
Last active November 29, 2019 12:08
Проверка многомерного массива на уникальность
<?
/*
* Убирает дублирующиеся элементы в многомерном массиве по одному ключу.
*
* @param {array} - многомерный массив;
* @param [key] - ключ по которому нужно убрать дубликаты.
*/
function dropsDuplicates($array, $key) {
$tmp = $key_array = array();
$i = 0;
@y3llbts
y3llbts / Транслитерация имени.php
Last active May 8, 2019 08:53
Транслитерация имени в символьный код и замена всего, кроме букв и цифр на "_" для элементов и разделов (Bitrix)
<?
AddEventHandler("iblock", "OnBeforeIBlockElementAdd", array("CodeUpdate", "IBlockElementUpdate"));
AddEventHandler("iblock", "OnBeforeIBlockElementUpdate", array("CodeUpdate", "IBlockElementUpdate"));
AddEventHandler("iblock", "OnBeforeIBlockSectionUpdate", array("CodeUpdate", "IBlockElementUpdate"));
AddEventHandler("iblock", "OnBeforeIBlockSectionAdd", array("CodeUpdate", "IBlockElementUpdate"));
AddEventHandler("catalog", "OnPriceAdd", array("CodeUpdate", "IBlockElementUpdate"));
AddEventHandler("catalog", "OnPriceUpdate", array("CodeUpdate", "IBlockElementUpdate"));
@y3llbts
y3llbts / validation-wpcf.js
Last active June 27, 2019 05:07
Валидатор для форм сделанных с помощью WPCF.
jQuery('.wpcf7-submit').click(function (e) {
var submit = jQuery(this),
wrongInputs = [],
reqInputs = submit.parents('form.wpcf7-form').find('[aria-required=true]'),
testPhone = /^\d\s\(\d{3}\)\s\d{3}\-\d{2}\-\d{2}$/,
testMail = /^[\w-\.]+@[\w-]+\.[a-z]{2,4}$/i;
reqInputs.each(function () {
@y3llbts
y3llbts / rsc.php
Last active May 6, 2019 11:55
Замена для символа пробела Bitrix
<?php
define("NEED_AUTH", true);
global $USER;
if (!$USER -> IsAdmin()) LocalRedirect("/");
set_time_limit(600); // Limits the execution time
$IBLOCK_TYPE = 'catalog'; // Put one IBlock or an array of types
function repSymCode($code) {
if(strripos($code, '_') !== false) {
<?php
function cl_print_r ($var, $label = '') {
$str = json_encode(print_r ($var, true));
echo "<script>console.group('".$label."');console.log('".$str."');console.groupEnd();</script>";
}
function cl_var_dump ($var, $label = '') {
ob_start();
var_dump($var);
$result = json_encode(ob_get_clean());
echo "<script>console.group('".$label."');console.log('".$result."');console.groupEnd();</script>";
@y3llbts
y3llbts / .htaccess
Last active December 18, 2020 09:09
Almost perfect default apache settings.
RewriteEngine On
# WWW to non-WWW redirect
RewriteCond %{HTTP_HOST} ^www.SITE.ru$ [NC]
RewriteRule ^(.*)$ http://SITE.ru/$1 [R=301,L]
# HTTP to HTTPS redirect
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<?php
// Create init.php, or just open it in '/bitrix/php_interface' and put this script in EOF;
// Replaces type="text/javascript" with empty string.
AddEventHandler("main", "OnEndBufferContent", "ChangeMyContent");
function ChangeMyContent(&$content) {
$content = sanitize_output($content);
}
function sanitize_output($buffer) {
$buffer = str_replace('type="text/javascript"', '', $buffer);
<?php
// Removes type from css linked styles.
add_filter('style_loader_tag', 'clean_style_tag');
function clean_style_tag($src) {
return str_replace("type='text/css'", '', $src);
}
// Removes type from linked scripts.
add_filter('script_loader_tag', 'clean_script_tag');