Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
d1i1m1o1n / gallery css
Created June 9, 2015 06:43
Simple portfolio using default Bootstrap elements plus some minor extra CSS enhancements. Including the modal box!
@d1i1m1o1n
d1i1m1o1n / get_folder
Created June 9, 2015 13:36
Get some folder from tar.gz archive
tar -zxvf archive.tar.gz ./folder
@d1i1m1o1n
d1i1m1o1n / addXML.php
Last active August 29, 2015 14:23
Work with xml using simpleXML
$xml = simplexml_load_file("news.xml") or die("Error: Cannot create object");
$id = count($xml->channel->item);
$item = $xml->channel->addChild('item', '');
$item->addAttribute('id', $id);
$item->addChild('date', $_POST['date']);
$item->addChild('title', $_POST['title']);
$item->addChild('description', $_POST['description']);
$xml->asXml('news.xml');
@d1i1m1o1n
d1i1m1o1n / echo_html_comment_print_r.sublime-snippet
Last active November 4, 2015 09:12
PHP snippet echo pre print_r for sublime text
<snippet>
<content><![CDATA[
echo '<!-- '; print_r(\$${1:foo}); echo ' -->';
]]></content>
<description>PHP: echo html comment print_r</description>
<scope>source.php</scope>
<tabTrigger>dump html comment</tabTrigger>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
@d1i1m1o1n
d1i1m1o1n / gist:705f43b6bf126a6444dd
Created November 4, 2015 14:41
Отладка в CMS 1C-Bitrix(AddMessage2Log)
//в файлах init.php или в dbconn.php
define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/log.txt");
//Используем
AddMessage2Log('$arFields = '.print_r($arFields, true),'');
@d1i1m1o1n
d1i1m1o1n / gist:0fb73df491d8fd3d8596
Last active November 15, 2015 21:27 — forked from marvell/gist:8330935
Bitrix: получение оптимальной цены (с учетом скидок) #snippet
CModule::IncludeModule("catalog");
global $USER;
//Цена
$arPrice = CCatalogProduct::GetOptimalPrice($arResult['ID'], 1, $USER->GetUserGroupArray());
$arResult['PRICE'] = $arPrice;
$arResult['DISCOUNT_PRICE'] = SaleFormatCurrency($arPrice["DISCOUNT_PRICE"], $arPrice["RESULT_PRICE"]["CURRENCY"]);
@d1i1m1o1n
d1i1m1o1n / template.php
Created November 5, 2015 18:26
Bitrix template with rows
<?foreach($arResult["ITEMS"] as $cell=>$arItem):?>
<?
$this->AddEditAction($arItem['ID'], $arItem['EDIT_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_EDIT"));
$this->AddDeleteAction($arItem['ID'], $arItem['DELETE_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BNL_ELEMENT_DELETE_CONFIRM')));
?>
<?if($cell%$arParams["LINE_ELEMENT_COUNT"] == 0):?>
<p>
<?endif;?>
<img id="<?=$this->GetEditAreaId($arItem['ID']);?>" src="<?=$arItem["PREVIEW_PICTURE"]["SRC"]?>" alt="<?=$arItem["NAME"]?>"/>
<?$cell++;
@d1i1m1o1n
d1i1m1o1n / result_modifier.php
Created November 5, 2015 19:23
Битрикс — добавляем название новости в цепочку навигации (хлебные крошки). В шаблоне news.detail добавим файл result_modifier.php.
<?
if($arParams['ADD_SECTIONS_CHAIN'] && !empty($arResult['NAME'])) {
$arResult['SECTION']['PATH'][] = array(
'NAME' => $arResult['NAME'],
'PATH' => ''
);
}
?>
@d1i1m1o1n
d1i1m1o1n / chain_template.php
Created November 5, 2015 19:28
Шаблон навигационной цепочки (хлебные крошки). /bitrix/templates/ID текущего шаблона сайта/chain_template.php
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<?
$sChainProlog = "<nav class='breadcrumbs'><ul><li><a href='/'>Главная</a> /</li>";
if( strlen($LINK) > 0 && $arChain[count($arCHAIN)-1]['LINK'] != $LINK ) {
$sChainBody .= "<li><a href=\"".$LINK."\" class=\"chain\">".htmlspecialchars($TITLE)."</a> /</li>"; // если указана ссылка то выводим ссылку
} else {
$sChainBody .= "<li>".htmlspecialchars($TITLE)."</li>"; // иначе текст, или последний пункт
}
$sChainEpilog = "</ul></nav>";
@d1i1m1o1n
d1i1m1o1n / add2cart.php
Created November 11, 2015 21:05
For bitrix ajax cart. Perform add and buy actions
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("sale");
if (($_GET["action"] == "ADD2BASKET" || $_GET["action"] == "BUY") && IntVal($_GET["id"])>0) {
$arFields = array(
"FUSER_ID"=>CSaleBasket::GetBasketUserID(),
"CURRENCY" => "RUB",
"PRODUCT_ID" => $_GET["id"],