<commit_before><?php
namespace Grav\Plugin;

use \Grav\Common\Plugin;
use \Grav\Common\Grav;
use \Grav\Common\Page\Page;

class AssetsPlugin extends Plugin
{
    protected $assets;

    /**
     * @return array
     */
    public static function getSubscribedEvents() {
        return [
            'onPageInitialized' => ['onPageInitialized', 0]
        ];
    }

    /**
     * Find inline assets in the following format:
     *
     * {assets:inline_css}
     * h1 {color: red !important;}
     * {/assets}
     *
     * {assets:css order:5}
     * //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css
     * //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1141.css
     * //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1142.css
     * {/assets}
     *
     * {assets:js}
     * //cdnjs.cloudflare.com/ajax/libs/angularFire/0.5.0/angularfire.min.js
     * {/assets}
     *
     * {assets:inline_js}
     * function initialize() {
     *   var mapCanvas = document.getElementById('map_canvas');
     *   var mapOptions = {
     *     center: new google.maps.LatLng(44.5403, -78.5463),
     *     zoom: 8,
     *     mapTypeId: google.maps.MapTypeId.ROADMAP
     *   }
     *   var map = new google.maps.Map(mapCanvas, mapOptions);
     * }
     * {/assets}
     */
    public function onPageInitialized()
    {
        if ($this->isAdmin()) {
            $this->active = false;
            return;
        }

        $page = $this->grav['page'];

        $content = $page->content();

        preg_match_all('#(?:<p>)?{assets:(.+?)(?: order:(.+?))?}(.*?){\/assets}(?:</p>)?(?:\n)?#smi', $content, $matches);

        $count = count($matches[0]);
        if ($count) {
            for ($x=0; $x<$count; $x++) {
                $action = $matches[1][$x];
                $order = $matches[2][$x] ?: null;
                $data = trim(strip_tags($matches[3][$x], '<link><script>'));
                $content = str_replace($matches[0][$x],'',$content);

                if ($action == 'css' || $action == 'js') {
                    $entries = explode("\n", $data);
                    foreach ($entries as $entry) {
                        $this->grav['assets']->add($entry, $order);
                    }
                } elseif ($action == 'inline_css') {
                    $this->grav['assets']->addInlineCss($data);<commit_msg>PSR fixes<commit_after><?php
namespace Grav\Plugin;

use \Grav\Common\Plugin;
use \Grav\Common\Grav;
use \Grav\Common\Page\Page;

class AssetsPlugin extends Plugin
{
    protected $assets;

    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return [
            'onPageInitialized' => ['onPageInitialized', 0]
        ];
    }

    /**
     * Find inline assets in the following format:
     *
     * {assets:inline_css}
     * h1 {color: red !important;}
     * {/assets}
     *
     * {assets:css order:5}
     * //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1140.css
     * //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1141.css
     * //cdnjs.cloudflare.com/ajax/libs/1140/2.0/1142.css
     * {/assets}
     *
     * {assets:js}
     * //cdnjs.cloudflare.com/ajax/libs/angularFire/0.5.0/angularfire.min.js
     * {/assets}
     *
     * {assets:inline_js}
     * function initialize() {
     *   var mapCanvas = document.getElementById('map_canvas');
     *   var mapOptions = {
     *     center: new google.maps.LatLng(44.5403, -78.5463),
     *     zoom: 8,
     *     mapTypeId: google.maps.MapTypeId.ROADMAP
     *   }
     *   var map = new google.maps.Map(mapCanvas, mapOptions);
     * }
     * {/assets}
     */
    public function onPageInitialized()
    {
        if ($this->isAdmin()) {
            $this->active = false;
            return;
        }

        $page = $this->grav['page'];

        $content = $page->content();

        preg_match_all('#(?:<p>)?{assets:(.+?)(?: order:(.+?))?}(.*?){\/assets}(?:</p>)?(?:\n)?#smi', $content, $matches);

        $count = count($matches[0]);
        if ($count) {
            for ($x=0; $x<$count; $x++) {
                $action = $matches[1][$x];
                $order = $matches[2][$x] ?: null;
                $data = trim(strip_tags($matches[3][$x], '<link><script>'));
                $content = str_replace($matches[0][$x], '', $content);

                if ($action == 'css' || $action == 'js') {
                    $entries = explode("\n", $data);
                    foreach ($entries as $entry) {
                        $this->grav['assets']->add($entry, $order);
                    }
                } elseif ($action == 'inline_css') {
                    $this->grav['assets']->addInlineCss($data);
{'fraction_non_alphanumeric': 0.18828091339939682, 'fraction_numerical': 0.023696682464454975, 'mean_word_length': 1.8589901477832513, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2293986', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1523, 'n_words': 243}