1<?php
2
3/**
4 * JSCreator is a class that writes a js file to a specific
5 * location, overriding the createFeed method of the parent HTMLCreator.
6 *
7 * @author  Pascal Van Hecke
8 */
9class JSCreator extends HTMLCreator
10{
11    protected $contentType = "text/javascript";
12
13    /**
14     * writes the javascript
15     *
16     * @inheritdoc
17     */
18    public function createFeed()
19    {
20        $feed = parent::createFeed();
21        $feedArray = explode("\n", $feed);
22
23        $jsFeed = "";
24        foreach ($feedArray as $value) {
25            $jsFeed .= "document.write('".trim(addslashes($value))."');\n";
26        }
27
28        return $jsFeed;
29    }
30
31    /**
32     * Overrides parent to produce .js extensions
33     *
34     * @return string the feed cache filename
35     * @since  1.4
36     * @access private
37     */
38    protected function _generateFilename()
39    {
40        $fileInfo = pathinfo($_SERVER["SCRIPT_NAME"]);
41
42        return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".js";
43    }
44}
45