1572dd708SAndreas Gohr<?php 2572dd708SAndreas Gohr 3572dd708SAndreas Gohr/** 4572dd708SAndreas Gohr * JSCreator is a class that writes a js file to a specific 5572dd708SAndreas Gohr * location, overriding the createFeed method of the parent HTMLCreator. 6572dd708SAndreas Gohr * 7572dd708SAndreas Gohr * @author Pascal Van Hecke 8572dd708SAndreas Gohr */ 9572dd708SAndreas Gohrclass JSCreator extends HTMLCreator 10572dd708SAndreas Gohr{ 11572dd708SAndreas Gohr protected $contentType = "text/javascript"; 12572dd708SAndreas Gohr 13572dd708SAndreas Gohr /** 14572dd708SAndreas Gohr * writes the javascript 15572dd708SAndreas Gohr * 16572dd708SAndreas Gohr * @inheritdoc 17572dd708SAndreas Gohr */ 18572dd708SAndreas Gohr public function createFeed() 19572dd708SAndreas Gohr { 20572dd708SAndreas Gohr $feed = parent::createFeed(); 21572dd708SAndreas Gohr $feedArray = explode("\n", $feed); 22572dd708SAndreas Gohr 23572dd708SAndreas Gohr $jsFeed = ""; 24572dd708SAndreas Gohr foreach ($feedArray as $value) { 25572dd708SAndreas Gohr $jsFeed .= "document.write('".trim(addslashes($value))."');\n"; 26572dd708SAndreas Gohr } 27572dd708SAndreas Gohr 28572dd708SAndreas Gohr return $jsFeed; 29572dd708SAndreas Gohr } 30572dd708SAndreas Gohr 31572dd708SAndreas Gohr /** 32572dd708SAndreas Gohr * Overrides parent to produce .js extensions 33572dd708SAndreas Gohr * 34572dd708SAndreas Gohr * @return string the feed cache filename 35572dd708SAndreas Gohr * @since 1.4 36572dd708SAndreas Gohr * @access private 37572dd708SAndreas Gohr */ 38572dd708SAndreas Gohr protected function _generateFilename() 39572dd708SAndreas Gohr { 40*d3233986SAndreas Gohr $fileInfo = pathinfo($_SERVER["SCRIPT_NAME"]); 41572dd708SAndreas Gohr 42572dd708SAndreas Gohr return substr($fileInfo["basename"], 0, -(strlen($fileInfo["extension"]) + 1)).".js"; 43572dd708SAndreas Gohr } 44572dd708SAndreas Gohr} 45