Ejemplo n.º 1
0
// MODX CSS and JS resources by using context 'setting_services'
$css_in = filter_input(INPUT_GET, 'css');
$js_in = filter_input(INPUT_GET, 'js');
$extra = filter_input(INPUT_GET, 'extra');
// Choose the right variable
$mime_type = !empty($css_in) ? 'text/css' : 'text/javascript';
$in_str = !empty($css_in) ? $css_in : $js_in;
// Prepare empty output
$output = array("header" => $mime_type, "content" => '');
// Include Extra Class
$ldpath = MODX_CORE_PATH . 'components/' . $PKG_NAME_LOWER . '/model/';
if (!$modx->loadClass($PKG_NAME, $ldpath, true, true)) {
    return 'There was a problem adding the ' . $PKG_NAME . ' package!  Check the logs for more info!';
} else {
    // Load Class
    $lsu = new LudwigSpeedUp($modx);
    if (!empty($in_str)) {
        // Is Plugin Cache activated?
        $cache_plugin = $modx->getOption($PKG_NAME_LOWER . '.plugin-cache_enabled', null, false, true);
        // Is the content already cached?
        if (!$lsu->is_cached($in_str, $cache_plugin)) {
            // Get plugin or snippet assets
            if (!empty($extra) && intval($in_str)) {
                $lsu->get_extra_content($in_str, $mime_type);
                // Get MODX service resource assets
            } else {
                // Is it an extra asset?
                $raw_str = gzinflate(base64_decode(urldecode($in_str)));
                if (strlen($raw_str) > 6 && substr($raw_str, -6) === '_extra') {
                    $extra = 1;
                    $raw_str = substr($raw_str, 0, -6);
Ejemplo n.º 2
0
 case 'OnLoadWebDocument':
     break;
     // This fires after all tags have been parsed (before the page is delivered to the browser)
 // This fires after all tags have been parsed (before the page is delivered to the browser)
 case 'OnWebPagePrerender':
     // Get System Setting Options for activation
     $activated = array('extra' => $modx->getOption($PKG_NAME_LOWER . '.activated', null, false, true), 'minify_html' => $modx->getOption($PKG_NAME_LOWER . '.collectassets.minify_html', null, true, true), 'collectassets' => $modx->getOption($PKG_NAME_LOWER . '.use_collectassets', null, true, true));
     // Check if package is installed and activated
     $ldpath = MODX_CORE_PATH . 'components/' . $PKG_NAME_LOWER . '/model/';
     if (!$modx->loadClass($PKG_NAME, $ldpath, true, true) || !$activated['extra'] || !$activated['collectassets']) {
         return 'There was a problem adding the ' . $PKG_NAME . ' package!  Check the logs for more info!';
     } else {
         // Get MODX content
         $content =& $modx->resource->_output;
         // Load Class
         $lsu = new LudwigSpeedUp($modx, $content);
         // Add extra assets like CSS and JS from plugins or snippets to your content
         $lsu->add_extra_assets();
         // Add service assets like CSS and JS to your content
         $service_id = $modx->context->getOption('services', null, 0, true);
         // Get setting_services in your context
         $lsu->add_service_assets($service_id);
         // Clean HTML
         if ($activated['minify_html']) {
             $lsu->minify_html();
         }
     }
     break;
     // This event fires right before the cache is written to.
 // This event fires right before the cache is written to.
 case 'OnBeforeSaveWebPageCache':