Skip to content

Instantly share code, notes, and snippets.

View AlekVolsk's full-sized avatar

AlekVolsk AlekVolsk

View GitHub Profile
<?php
function file_size($bytes)
{
$sfx = [ 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ];
$base = 1024;
$class = min((int)log($bytes, $base), count($sfx) - 1);
return sprintf('%1.2f' , $bytes / pow($base, $class)) . ' ' . $sfx[$class];
}
@AlekVolsk
AlekVolsk / grid-css.css
Created February 10, 2019 10:19
Smart grid
.grid {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(12, 1fr);
margin: 0 auto;
width: 100%;
max-width: 1280px;
}
.one, .two, .three, .four, .five, .six, .seven, .eight, .nine, .ten, .eleven, .twelve {
@AlekVolsk
AlekVolsk / optimize.php
Last active April 12, 2020 21:48
Класс минификации html на выходе
<?php
/*
Usage
$html = Optimize::html($html);
*/
class Optimize
{
private static $_html_is_js, $_html_is_css;
@AlekVolsk
AlekVolsk / thmb_image.php
Created February 10, 2019 10:37
Нарезка тумбочек для Joomla
<?php
/*
Usage
$imgIn = str_replace('\\', '/', $imgIn );
$imgOut = str_replace('\\', '/', str_replace(JPATH_ROOT . DIRECTORY_SEPARATOR, '', JPATH_CACHE) . DIRECTORY_SEPARATOR . $imgIn );
if (!file_exists( JPATH_ROOT . DIRECTORY_SEPARATOR . $imgOut )) {
getCacheImageSquare($imgIn, $imgOut);
}
@AlekVolsk
AlekVolsk / get_fields.php
Last active February 10, 2019 10:45
Получение допполей Joomla для элемента в читабельном виде
<?php
// === begin: если в $item полей нет ===
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
$item->jcfields = FieldsHelper::getFields('com_content.article', $item, true);
// === end: если в $item полей нет ===
$fields = [];
foreach($item->jcfields as $jcfield) {
$fields[$jcfield->name] = $jcfield;
@AlekVolsk
AlekVolsk / info_browser.php
Last active January 10, 2022 01:32
getInfoBrowser()
<?php
function getInfoBrowser($agent = '')
{
if (empty($agent)) {
$agent = $_SERVER['HTTP_USER_AGENT'];
}
$browserInfo = [];
$browserInfo['ip'] = $_SERVER['REMOTE_ADDR'];
@AlekVolsk
AlekVolsk / breadcrumb_schema.html
Last active April 6, 2022 10:10
Correct markup for breadcrumbs
<ul itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem">
<a title="Наименование сайта" itemprop="item" content="https://site.ru/" href="/">
<span itemprop="name">Главная</span>
</a>
<meta itemprop="position" content="1">
</li>
<li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem">
<a title="Наименование раздела" itemprop="item" content="https://site.ru/category" href="/category">
<span itemprop="name">Раздел</span>
@AlekVolsk
AlekVolsk / table_search.js
Last active May 30, 2019 15:29
Search on table
function tableSearch(searchId, tableId) {
var phrase = document.getElementById(searchId);
var table = document.getElementById(tableId);
var regPhrase = new RegExp(phrase.value, 'i');
for (var i = 1; i < table.rows.length; i++) {
flag = regPhrase.test(table.rows[i].cells[0].innerHTML);
if (flag) {
table.rows[i].style.display = '';
} else {
table.rows[i].style.display = 'none';
@AlekVolsk
AlekVolsk / number.html
Last active May 30, 2019 17:36
Number field
<div class="tm-number-input">
<button type="button" class="tm-number-input-minus">–</button>
<input type="number" min="1" value="1" class="uk-input">
<button type="button" class="tm-number-input-plus">+</button>
</div>
@AlekVolsk
AlekVolsk / polyfills.js
Created May 31, 2019 16:15
IE11 polyfill's: matches, closest, forEach
(function () {
// matches
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.matchesSelector ||
Element.prototype.webkitMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector;
}