' . "\n "; } else { $include .= '' . "\n"; } return $include; } /** * Generates new PMA_Scripts objects * * @return PMA_Scripts object */ public function __construct() { $this->_files = array(); $this->_code = ''; $this->_events = array(); } /** * Adds a new file to the list of scripts * * @param string $filename The name of the file to include * @param bool $conditional_ie Whether to wrap the script tag in * conditional comments for IE * * @return void */ public function addFile($filename, $conditional_ie = false) { $filename = 'js/' . $filename; $hash = md5($filename); if (empty($this->_files[$hash])) { $timestamp = null; if (strpos($filename, '?') === false) { $timestamp = filemtime($filename); } $this->_files[$hash] = array( 'filename' => $filename, 'timestamp' => $timestamp, 'conditional_ie' => $conditional_ie ); } } /** * Adds a new code snippet to the code to be executed * * @param string $code The JS code to be added * * @return void */ public function addCode($code) { $this->_code .= "$code\n"; } /** * Adds a new event to the list of events * * @param string $event The name of the event to register * @param string $function The code to execute when the event fires * E.g: 'function () { doSomething(); }' * or 'doSomething' * * @return void */ public function addEvent($event, $function) { $this->_events[] = array( 'event' => $event, 'function' => $function ); } /** * Renders all the JavaScript file inclusions, code and events * * @return string */ public function getDisplay() { $retval = ''; foreach ($this->_files as $file) { $retval .= $this->_includeFile( $file['filename'], $file['conditional_ie'] ); } $retval .= ''; return $retval; } }