Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*======================================================================*\
- || #################################################################### ||
- || # Php Ajax Multimedia website framework, or just "Pam" # ||
- || # ---------------------------------------------------------------- # ||
- || # Copyright ©2008 Digital Media Graphix LLC. All Rights Reserved. # ||
- || # ---------------------------------------------------------------- # ||
- || # Version 1.0.0 RC1 February 25 2008 # ||
- || #################################################################### ||
- \*======================================================================*/
- /**
- * Templates Controller. Segregates the view files from the controller code
- * and also determines whether to send HTML out or send XML out for
- * javascript Ajax requests.
- */
- class PAMWF_Templates_prototype extends PAMWF_HTMLOut
- {
- protected $coreJS = array(
- 'lib/prototype',
- 'src/scriptaculous',
- 'PAMWF'
- );
- protected $localJS = array();
- /**
- * Array of elements to be parsed into the scope of the phtml file.
- * Controllers should assign outgoing values into members of this
- * class where they can be picked up by the template files and
- * sent out.
- *
- * @var array
- */
- protected $output = array();
- /**
- * Array of parsed XML tags.
- *
- * @var array
- */
- protected $xmlOutput = array();
- /**
- * Print XML output.
- *
- */
- protected function printXML()
- {
- PAMWF::setHeader('type', 'Content-Type: application/xml;');
- $this->printFinalOutput('<pamwf>'.implode("\n",$this->xmlOutput).'</pamwf>');
- }
- /**
- * Build an XML tag using the specified template and output.
- *
- * @param string XML tag
- * @param string Template to use. Default PAMWF::$targetFile
- * @param array Output to use. Default $this->output
- */
- protected function buildTag( $tag, $template = null, $output = null )
- {
- $this->xmlOutput[$tag] = "<$tag><![CDATA[".$this->parseTemplate( $template, $output )."]]></$tag>";
- }
- /**
- * Parse a phtml file into an html file.
- *
- * @param string Template to use, default PAMWF::$targetFile
- * @param array Output to use, default $this->output
- * @return string
- */
- protected function parseTemplate( $template = null, $output = null )
- {
- if ($template == null)
- {
- $template = PAMWF::$targetFile;
- }
- else
- {
- $template = PAMWF_DIR_PROJECT.DIRECTORY_SEPARATOR.$template;
- }
- if (is_array($output))
- {
- extract($output);
- }
- else
- {
- extract($this->output);
- }
- @ob_start();
- include( $template );
- return @ob_get_clean();
- }
- /**
- * Parse out Javascript files used on the clientview of the pages this
- * controller is responsible for.
- *
- * @param array output to use to affect the javascripts of this controller. (default $this->output)
- * @return return string
- */
- protected function parseJS( $output = null )
- {
- if (is_array($output))
- {
- extract($output);
- }
- else
- {
- extract($this->output);
- }
- @ob_start();
- $this->startUpJS();
- return @ob_get_clean();
- }
- /**
- * Print output to the browser. Ajax requests receive XML from this function.
- *
- */
- public function printOutput()
- {
- if (!PAMWF::isEmpty($this->xmlOutput))
- {
- $this->printXML();
- }
- else
- {
- $output = $this->parseTemplate();
- $js = $this->parseJS();
- if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest')
- {
- if ($js)
- {
- $js = str_replace('</script>', '', str_replace('<script type="text/javascript">', '', $js));
- }
- $js = $this->linkJS() . '<script type="text/javascript">' . $js . '</script>';
- $this->printFinalOutput(str_replace('<head>', '<head>'.$js, $output));
- }
- else
- {
- if ($js)
- {
- $this->xmlOutput['javascript'] = "<javascript><![CDATA[".$js."]]></javascript>";
- }
- $this->xmlOutput['response'] = "<response><![CDATA[".$output."]]></response>";
- $this->printXML();
- }
- }
- }
- protected function linkJS()
- {
- $js = array_merge($this->coreJS, $this->localJS);
- $output = '';
- foreach ($js as $script)
- {
- $output .= '<script type="text/javascript" src="'.PAMWF_WEBROOT.'js/'.$script.".js\"></script>\n";
- }
- return $output;
- }
- // This empty function is in place so children can extend it as necessary, and place their
- // attendant javascripts in the controller where they can be read alongside the php side
- // customizations the page requires.
- protected function startUpJS() {}
- }
- ?>
Add Comment
Please, Sign In to add comment