// ============================================================================
// DX: LOAD_MORE AJAX MODE - Lightweight HTML Response for Categories
// ============================================================================
use Tygh\Registry;
/**
* Hook: Detect load_more AJAX request and flag it
*/
fn_set_hook('dispatch_before_display', function ($dispatch, $controller, $mode, $action) {
if ($dispatch === 'categories.view' && !empty($_REQUEST['load_more'])) {
Tygh::$app['view']->assign('dx_load_more_mode', true);
if (!defined('AJAX_REQUEST')) {
define('AJAX_REQUEST', true);
}
}
});
/**
* Hook: Post-render — extract lightweight HTML for load_more
*/
fn_set_hook('view_post_render', function (&$output) {
$dx_load_more_mode = Tygh::$app['view']->getTemplateVars('dx_load_more_mode');
if (!empty($dx_load_more_mode)) {
$output = fn_dx_extract_tygh_main_container_inner_html($output);
}
});
/**
* Extract inner HTML of
...
* Returns full HTML as fallback if container not found.
*/
function fn_dx_extract_tygh_main_container_inner_html($full_html)
{
if (!is_string($full_html) || $full_html === '') {
return $full_html;
}
// Fast path: string-based extraction (faster than DOMDocument)
$start = strpos($full_html, 'id="tygh_main_container"');
if ($start === false) {
return $full_html;
}
// Find the opening tag start: "