summaryrefslogtreecommitdiff
path: root/platform/www/vendor/openpsa/universalfeedcreator/lib/Creator/JSCreator.php
blob: 5aa31faa00d8d73bcaaf9ef52d99b05427914eb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

/**
 * JSCreator is a class that writes a js file to a specific
 * location, overriding the createFeed method of the parent HTMLCreator.
 *
 * @author  Pascal Van Hecke
 */
class JSCreator extends HTMLCreator
{
    protected $contentType = "text/javascript";

    /**
     * writes the javascript
     *
     * @inheritdoc
     */
    public function createFeed()
    {
        $feed = parent::createFeed();
        $feedArray = explode("\n", $feed);

        $jsFeed = "";
        foreach ($feedArray as $value) {
            $jsFeed .= "document.write('".trim(addslashes($value))."');\n";
        }

        return $jsFeed;
    }

    /**
     * Overrides parent to produce .js extensions
     *
     * @return string the feed cache filename
     * @since  1.4
     * @access private
     */
    protected function _generateFilename()
    {
        $fileInfo = pathinfo($_SERVER["PHP_SELF"]);

        return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".js";
    }
}