HEX
Server: LiteSpeed
System: Linux dviragis.serveriai.lt 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User: lyrlavhsb (1106)
PHP: 8.3.19
Disabled: link, symlink, exec, passthru, proc_close, proc_get_status, proc_open, shell_exec, system, popen, pclose, dl, show_source, highlight_file, pcntl_exec, ini_restore, ini_alter, chgrp
Upload Files
File: /home/lyrlavhsb/public_html/wp-content/plugins/extendify/src/Library/util/replace-pattern-images.js
const formatImageUrl = (image) =>
	image?.includes('?q=80&w=1470') ? image : `${image}?q=80&w=1470`;

const hashString = (s) => {
	let h = 0;
	for (let i = 0; i < s.length; i++) {
		h = (h * 31 + s.charCodeAt(i)) | 0;
	}
	return Math.abs(h);
};

const seededShuffle = (arr, seed) => {
	const result = [...arr];
	let h = hashString(String(seed));
	for (let i = result.length - 1; i > 0; i--) {
		h = (h * 1103515245 + 12345) | 0;
		const j = Math.abs(h) % (i + 1);
		[result[i], result[j]] = [result[j], result[i]];
	}
	return result;
};

export const replacePatternImages = (content, images, seed) => {
	if (!images?.length) return content;
	const matches =
		content.match(/https:\/\/images\.unsplash\.com\/[^\s"]+/g) || [];
	const uniqueUrls = [...new Set(matches)];
	const order = seededShuffle(images, seed);
	return uniqueUrls.reduce(
		(updated, url, i) =>
			updated.replaceAll(url, formatImageUrl(order[i] || url)),
		content,
	);
};