'; require( $file ); echo ''; } } /** * display_js function * * Renders the given script inline. If script has already been displayed * once before with the same set of $args, does not display it again. * * @param string $file * @param array $args * * @return void **/ function display_js( $file = false, $args = array() ) { static $displayed = array(); if( ! $file || empty( $file ) ) { throw new Ai1ec_File_Not_Provided( "You need to specify a js file." ); } $file = AI1EC_JS_PATH . "/" . $file; if( $displayed[$file] === $args) // Skip if already displayed return; if( ! file_exists( $file ) ) { throw new Ai1ec_File_Not_Found( "The specified js file doesn't exist." ); } else { $displayed[$file] = $args; // Flag that we've displayed this file with these args extract( $args ); echo ''; } } /** * get_view function * * Return the output of a view as a string rather than output to response. * * @param string $file * @param array $args * * @return void **/ function get_view( $file = false, $args = array() ) { ob_start(); $this->display( $file, $args ); return ob_get_clean(); } /** * json_response function * * Utility for properly outputting JSON data as an AJAX response. * * @param array $data * * @return void **/ function json_response( $data ) { header( 'Cache-Control: no-cache, must-revalidate' ); header( 'Pragma: no-cache' ); header( 'Content-type: application/json' ); // Output JSON-encoded result and quit echo json_encode( $data ); exit; } } // END class