Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
d1i1m1o1n / debug.php
Created February 19, 2016 08:18
Bitrix(d7). Debug
<?php
use Bitrix\Main\Diag\Debug;
use Bitrix\Main\Diag\Helper;
/*Write in file*/
//Debug::writeToFile($variable, $varName, $file);
Debug::writeToFile(['ID' => $ID, 'fields' => $arResult ], null, "log.log");
Debug::dumpToFile(['ID' => $ID, 'fields' => $arResult ], null, "log.log");
/*Time label*/
@d1i1m1o1n
d1i1m1o1n / functions.php
Created February 19, 2016 08:24
Is phone function
<?php
function isPhone($val){
if (!preg_match('/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/iu', $val))
return false;
return true;
}
//allow
@d1i1m1o1n
d1i1m1o1n / functions.php
Last active March 11, 2016 14:56
Plural froms сколнения
<?php
function plural_form($n, $forms) {
return $n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]);
}
//usage
$ends = [
"банан",
"банана",
"бананов"
@d1i1m1o1n
d1i1m1o1n / file.php
Created February 19, 2016 08:30
Bitrix. Clear cahce by tag
<?php
if(defined('BX_COMP_MANAGED_CACHE'))
$GLOBALS['CACHE_MANAGER']->ClearByTag('iblock_id_4'); //clear cache for iblock with ID = 4
@d1i1m1o1n
d1i1m1o1n / d7.php
Created February 19, 2016 08:38
Bitrix(d7). DB query
<?php
use Bitrix\Main\Application;
$connection = Application::getConnection();
$sqlHelper = $connection->getSqlHelper();
$sql = "SELECT ID FROM b_user WHERE LOGIN = '".$sqlHelper->forSql($login, 50)."'";
//$connection->query($sql, $limit);
//$connection->query($sql, $offset, $limit);
@d1i1m1o1n
d1i1m1o1n / index.php
Created July 5, 2016 09:14
Bitrix. New order d7
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
global $USER;
use Bitrix\Main,
Bitrix\Main\Loader,
Bitrix\Main\Config\Option,
Bitrix\Sale,
Bitrix\Sale\Order,
Bitrix\Sale\DiscountCouponsManager;
@d1i1m1o1n
d1i1m1o1n / TimeWeb - SSH RSA Key
Created November 9, 2016 06:53 — forked from zetrider/TimeWeb - SSH RSA Key
Авторизация SSH по RSA ключу - TimeWeb
user - имя пользователя
server.timeweb.ru - сервер
1. На машине ssh-keygen -t rsa
2. Копируем, можно по FTP или одной из команд
2.1. ssh-copy-id -i ~/.ssh/id_rsa user@server.timeweb.ru
2.2. scp ~/.ssh/id_rsa.pub user@server.timeweb.ru:~
3. На сервере
[ -d ~/.ssh ] || (mkdir ~/.ssh; chmod 711 ~/.ssh) # создание директории и изменение прав
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys # добавление открытого ключа
@d1i1m1o1n
d1i1m1o1n / header.pug
Created February 23, 2018 21:12 — forked from lineharo/header.pug
PUG - auto version .css or another files in HTML head
- function pDate() {
- return new Date().getTime();
- }
doctype html
html(lang="ru")
head
meta(charset="utf-8")
title TITLE