Skip to content

Instantly share code, notes, and snippets.

View cgi-caesar's full-sized avatar

Andrey Yerokhin cgi-caesar

View GitHub Profile
@cgi-caesar
cgi-caesar / site.php
Last active February 9, 2024 21:42
aMember (site.php): Make chosen Link item active in user menu
<?php
Am_Di::getInstance()->hook->add(Am_Event::USER_MENU, function(Am_Event $e) {
$menu = $e->getMenu();
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if ($_ = $e->getDi()->linkTable->findFirstByUrl($url)) {
$menu->findOneById("link-{$_->pk()}")->setActive(true);
}
});
@cgi-caesar
cgi-caesar / site.php
Last active March 24, 2022 14:29
aMember (site.php): Sort Items in Active Resources Widget Alphabetically
<?php
Am_Di::getInstance()->hook->add(Am_Event::BEFORE_RENDER, function (Am_Event $e) {
if (stripos($e->getTemplateName(), 'blocks/member-main-resources.phtml') !== false) {
usort($e->getView()->resources, function ($a, $b) {return strtolower($a->title) <=> strtolower($b->title);});
}
});
@cgi-caesar
cgi-caesar / dashboard.php
Created October 13, 2021 15:00
Dashboard Plugin (replace standard controller with custom one)
<?php
class Am_Plugin_Dashboard extends Am_Plugin
{
const PLUGIN_STATUS = self::STATUS_PRODUCTION;
const PLUGIN_COMM = self::COMM_COMMERCIAL;
const PLUGIN_REVISION = '@@VERSION@@';
protected $_configPrefix = 'misc.';
@cgi-caesar
cgi-caesar / site.js
Created April 30, 2021 15:03
aMember (site.js): change absolute dates to relative in Active Subscription widget
jQuery(function(){
jQuery('.am-list-subscriptions-date_expires_date, .am-list-subscriptions-date_rebill_date, .am-list-subscriptions-date_future_date').each(function(){
if (jQuery(this).data('date') == '2037-12-31') return;
const today = new Date().toISOString().slice(0, 10)
const diffInDays = 1 + (new Date(jQuery(this).data('date')) - new Date(today)) / (1000 * 60 * 60 * 24);
jQuery(this).attr('title', jQuery(this).html());
jQuery(this).html(`in ${diffInDays} ${diffInDays == 1 ? 'day' : 'days'}`);
});
});
@cgi-caesar
cgi-caesar / site.php
Last active March 31, 2021 07:21
aMember (site.php): Add Open Graph Meta to Login Page
<?php
Am_Di::getInstance()->blocks->add('login/form/before', new Am_Block_Base(null, 'og-login', null, function(Am_View $v) {
$meta = [
'og:image' => '/path/to/image.png',
];
$out = '';
foreach ($meta as $property => $content) {
$out .= sprintf(
@cgi-caesar
cgi-caesar / site.css
Last active March 22, 2021 14:17
aMember (site.php): align "login with" buttons
.am-google-button-wrapper.am-google-login-form-after::before {
content: none;
}
.am-google-button-wrapper.am-google-login-form-after {
border: none;
margin:0;
padding:0;
}
.am-fb-signup-button-wrapper {
@cgi-caesar
cgi-caesar / site.php
Last active March 12, 2021 15:46
aMember (site.php): extend standard filter for payments grid
<?php
Am_Di::getInstance()->hook->add('gridPaymentInitGrid', function(Am_Event_Grid $e) {
$e->getGrid()->setFilter(new Am_Grid_Filter_PaymentsAdv);
});
class Am_Grid_Filter_PaymentsAdv extends Am_Grid_Filter_Payments
{
public function renderInputs()
{
@cgi-caesar
cgi-caesar / README.md
Last active March 4, 2021 13:42
Pay As You Wish (Above Product Price)

Pay As You Wish (Above Product Price)

  • Add Product brick
  • Add donation Brick for each product that you want user can choose price for
  • Add JavScript brick with code (you need to correct map array to map products to donation bricks)
  • Add Code to site.php
@cgi-caesar
cgi-caesar / site.php
Created December 25, 2020 08:47
aMember (site.php): Hide sidebar for some products in shopping cart catalogue
<?php
Am_Di::getInstance()->productTable->customFields()
->add(new Am_CustomFieldSingle_Checkbox('remove_sidebar', 'Remove Sidebar?'));
Am_Di::getInstance()->front->registerPlugin(new class extends Zend_Controller_Plugin_Abstract {
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if ($request->getModuleName() == 'cart'
&& $request->getControllerName() == 'index'
@cgi-caesar
cgi-caesar / site.php
Last active November 4, 2020 15:27
aMember (site.php): Add CSRF token to login form
<?php
function _csrf_hash($tm)
{
$sesid = Am_Di::getInstance()->session->getId();
$id = 'login';
return Am_Di::getInstance()->security->hash("{$tm}:{$id}:{$sesid}", 10);
}
function _csrf_token()