Skip to content

Instantly share code, notes, and snippets.

View jreviews's full-sized avatar

JReviews jreviews

View GitHub Profile
@jreviews
jreviews / htmx-loading-states-extension.md
Last active April 1, 2024 22:22
htmx loading states extension

htmx loading states extension

The loading-states extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes.

Using the extension

Add the hx-ext="loading-states" attribute to the body tag or to any parent element containing your htmx attributes.

Add the following class to your stylesheet to make sure elements are hidden by default:

@jreviews
jreviews / modal-behavior._hs
Last active January 23, 2024 09:27
Hyperscript modal behavior
behavior Modal
init
set my focusRing to (<a, button, input:not([type=hidden]), textarea, select, details/> in me) as Array
end
on open
remove .hide
add { overflow: 'hidden' } to the <body/>
transition <[data-backdrop], [data-content]/> in me opacity from 0 to 1 over 0.3s
focus() the first <input/> in me
@jreviews
jreviews / mod_security.md
Created November 24, 2023 12:16
mod_security issues

The following was shared by a client having problems with uploads in JReviews not working:

Never disable all rules !! This could cause serious security issues!

The easiest way to disable individual mod_security rules if you are using cPanel is to install ConfigServer ModSecurity Control and use it to disable individual mod_security rules by ID or via a specific directory.

Otherwise you will need to review and edit specific Apache server files as follows: (Windows Web Server not addressed here)

The mod_security ID's I whitelisted for JReviews Joomla are:

@jreviews
jreviews / forseo_functions.md
Last active September 21, 2023 21:37
Disable 4SEO in JReviews Listings

JReviews has always had a strong focus in SEO and comes with functionality to add Schema.org markup, Open Graph and Twitter tags. It also allows using internal features like media and custom fields as part of this functionality which is something 3rd party solutions cannot do unless support is added specifically for them.

If you are using 4SEO for your site, it will add all these SEO features for core functionality and some 3rd party solutions. However, this creates a problem with duplication in JReviews listings. JReviews has it's own data and in some cases may do things differently. So in this case, the recommended solution is to disable the 4SEO tags in JReviews listings to avoid duplication.

This can be done programatically using 4SEO hooks

If you are not using hooks yet, you'll need to create the file at:

  • /libraries/weeblr/forseo_functions.php (when using Joomla)
@jreviews
jreviews / vivaz-hover-dropdowns.md
Last active July 25, 2023 11:42
Vivaz template - open dropdowns on hover
<script>
window.addEventListener('DOMContentLoaded', (event) => {

  // Iterate through each main link in the topbar navigation. 
  document.querySelectorAll('.mod-menu > li > a').forEach((mainLink) => {
    const mainLi = mainLink.closest('li'); // Find the closest parent 'li'.
    const mainDropdownElement = mainLi.querySelector('.dropdown-menu'); // Select the dropdown menu of the main link.

    // Execute if both the main link and associated dropdown menu exist.
@jreviews
jreviews / Zip.md
Last active March 13, 2023 22:25
Joomla Zip::extractNative replacement

The following method is a replacement for Joomla's unzip method to overcome a server's ulimit setting that prevents large packages from unzipping.

The original method can be found in following path. You can open the file and replace the extractNative function with the one below.

  • libraries/vendor/joomla/archive/src/Zip.php

The new function overcomes the server restrictions on the number of simultaneous open files because it doesn't try to extract based on the number of files in the zip archive that could cause issues with ulimit; instead, it extracts everything to a temporary folder using the extractTo method, which reduces the number of simultaneous open files.

Once extraction is completed, it loops over each file in the zip archive and moves files one by one from the temporary directory to the final destination. This approach has good performance because it solves the issue by reducing the maximum number of open files simultaneously, irrespective of the number of files in the zip archive.

@jreviews
jreviews / ga4-custom-report.md
Last active December 14, 2022 15:13
Generate GA4 custom report for specific path, event and timeframe using Google Analytics Data API

This code example uses Laravel's Http client.

You need to generate the private key from your service account in a Google Cloud Platform project. Then grant access to your GA4 property to the service account client email.

There are some instructions for doing that in the JReviews Dashboard Addon documentation, which is where the code below comes from.

function getAuthToken($clientEmail, $privateKey)
{          
      $base64URLEncode = function($data) {
<?php
namespace JReviews\Listeners;
defined( 'MVC_FRAMEWORK') or die;
use cmsFramework;
use S2Array;
use JReviews\Listeners\Traits\ListenerSetting;
use Clickfwd\Listener\QueueableListener;
use Clickfwd\Event\EventInterface;
@jreviews
jreviews / peepso-search-member-profiles.md
Last active September 14, 2022 18:20
PeepSo: Allow searching member profiles with multi-select fields

Within PeepSo fields it's only possible to enable single select lists as searchable. The following code uses PeepSo filters to allow you to include multi-select fields in the members search area by converting them to single select and including the selected value in the database query.

Create a peepso-search-member-profiles.php file in /wp-content/mu-plugins with the following code:

<?php

/**
 * Find the field IDs under PeepSo Manage Fields
 * Add the field IDs of multiple select fields you want to show for member search
@jreviews
jreviews / filter_functions.php
Last active December 11, 2021 10:49
Add listing labels with custom CSS classes for multiple custom fields
<?php
defined('_JEXEC') or die;
Clickfwd\Hook\Filter::add('listing_status_labels', 'jreviews_custom_labels');
function jreviews_custom_labels($labels, $params)
{
$listing = $params['listing'];