Skip to content

Instantly share code, notes, and snippets.

@itchief
itchief / breadcrumb.php
Created August 14, 2022 12:14
JSON-LD breadcrumb for MODX
<?php
$siteId = $modx->getOption('site_start');
$siteUrl = $modx->getOption('site_url');
// добавляем текущую страницу
$crumbs[] = ['name' => $modx->resource->pagetitle, 'item' => $modx->makeUrl($modx->resource->id, '', '', 'full')];
// получаем родительский ресурс
$parent = $modx->getObject('modResource', $modx->resource->parent);
// пока родительский ресурс не равен null выполняем...
while ($parent != null) {
@itchief
itchief / slider.php
Created September 20, 2021 13:36
slider.php
<?php
$template = <<<HTML
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ChiefSlider</title>
@itchief
itchief / insert_ad_on_page.js
Last active March 14, 2021 05:08
Скрипт для динамического добавления AdSense и РСЯ рекламы на сайт
(function () {
// функция для создания элемента, который в дальнейшем будет использоваться сервисами AdSense и РСЯ для размещения в нём рекламы
function createAd(id, className) {
var hasYandex = className === 'adsbyyandex';
var tag = hasYandex ? 'div' : 'ins';
var $element = document.createElement(tag);
$element.className = className;
if (hasYandex) {
$element.id = id;
} else {
@itchief
itchief / process.php
Created February 6, 2021 13:02
process.php for feedback-form
<?php
/*
* Форма обратной связи (https://itchief.ru/lessons/php/feedback-form-for-website)
* Copyright 2016-2020 Alexander Maltsev
* Licensed under MIT (https://github.com/itchief/feedback-form/blob/master/LICENSE)
*/
header('Content-Type: application/json');
<?php
// id опроосов
$polls = array('pool-1');
// Если запрос не AJAX (XMLHttpRequest), то завершить работу
if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {return;}
if (empty($_POST['id'])) {exit();}
// удаляем теги и кодируем специальные символы
@itchief
itchief / get_pageviews_from_ga.php
Created December 15, 2019 12:52
How to get pageviews of resource from Google Analytics Reporting API v4 and save them to file in JSON format
<?php
// Загрузим PHP клиентскую библиотеку для Google API.
require_once __DIR__ . '/vendor/autoload.php';
$analytics = initializeAnalytics();
$response = getReport($analytics);
//printResults($response);
printResultInFile($response);
@itchief
itchief / get_views_from_ga.php
Created December 15, 2019 12:41
How to get pageviews of resource from Google Analytics Reporting API v4
<?php
// Загрузим PHP клиентскую библиотеку для Google API.
require_once __DIR__ . '/vendor/autoload.php';
$analytics = initializeAnalytics();
$response = getReport($analytics);
printResults($response);
/**
@itchief
itchief / get_top_pages_from_ga.php
Last active February 28, 2021 06:51
How to get top 7 pageviews from Google Analytics Reporting API v4
<?php
// Загрузим PHP клиентскую библиотеку для Google API.
require_once __DIR__ . '/vendor/autoload.php';
$analytics = initializeAnalytics();
$response = getReport($analytics);
printResults($response);
//printResultsAsJson($response);
@itchief
itchief / font-glyphicons.css
Created February 25, 2019 11:28
Gist for Bootstrap 4
@font-face {
font-family: "Glyphicons Halflings";
src: url("../fonts/glyphicons-halflings-regular.eot");
src: url("../fonts/glyphicons-halflings-regular.eot?#iefix") format("embedded-opentype"), url("../fonts/glyphicons-halflings-regular.woff2") format("woff2"), url("../fonts/glyphicons-halflings-regular.woff") format("woff"), url("../fonts/glyphicons-halflings-regular.ttf") format("truetype"), url("../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular") format("svg");
}
.glyphicon {
position: relative;
top: 1px;
display: inline-block;
font-family: "Glyphicons Halflings";
@itchief
itchief / script.js
Last active July 24, 2018 14:36
js-amsterdam
$('.circle-slider').find('.slider-arrow.next').on('click', function () {
$this = $(this).closest('.circle-slider');
var index = parseInt($this.attr('data-state')) + 1;
if (index <= $this.find('.item').length) {
$this.attr('data-state', index);
} else {
$this.attr('data-state', 1);
}
});