Example #1
0
 public function render(Register $Parameters, XMLDocument &$Document = NULL, DocumentHeaders &$Headers = NULL)
 {
     $ParameterOutput = new Register();
     if (!is_null($Headers)) {
         $Headers->append('Content-Type', $this->{'content-type'});
     } else {
         header('Content-Type: ' . $this->{'content-type'});
     }
     if (is_null($Document)) {
         $Document = new XMLDocument();
         $Document->appendChild($Document->createElement('data'));
     }
     $root = $Document->documentElement;
     $datasources = $events = array();
     $events_wrapper = $Document->createElement('events');
     $root->appendChild($events_wrapper);
     if (is_array($this->about()->{'events'}) && !empty($this->about()->{'events'})) {
         $events = $this->about()->{'events'};
     }
     if (is_array($this->about()->{'data-sources'}) && !empty($this->about()->{'data-sources'})) {
         $datasources = $this->about()->{'data-sources'};
     }
     ####
     # Delegate: FrontendEventsAppend
     # Description: Append additional Events.
     # Global: Yes
     Extension::notify('FrontendEventsAppend', '/frontend/', array('events' => &$events));
     if (!empty($events)) {
         $postdata = General::getPostData();
         $events_ordered = array();
         foreach ($events as $handle) {
             $events_ordered[] = Event::loadFromHandle($handle);
         }
         uasort($events_ordered, array($this, '__cbSortEventsByPriority'));
         foreach ($events_ordered as $e) {
             if (!$e->canTrigger($postdata)) {
                 continue;
             }
             $fragment = $e->trigger($ParameterOutput, $postdata);
             if ($fragment instanceof DOMDocument && !is_null($fragment->documentElement)) {
                 $node = $Document->importNode($fragment->documentElement, true);
                 $events_wrapper->appendChild($node);
             }
         }
     }
     ####
     # Delegate: FrontendDataSourceAppend
     # Description: Append additional DataSources.
     # Global: Yes
     Extension::notify('FrontendDataSourcesAppend', '/frontend/', array('datasources' => &$datasources));
     //	Find dependancies and order accordingly
     $datasource_pool = array();
     $dependency_list = array();
     $datasources_ordered = array();
     $all_dependencies = array();
     foreach ($datasources as $handle) {
         $datasource_pool[$handle] = Datasource::loadFromHandle($handle);
         $dependency_list[$handle] = $datasource_pool[$handle]->parameters()->dependencies;
     }
     $datasources_ordered = $this->__sortByDependencies($dependency_list);
     if (!empty($datasources_ordered)) {
         foreach ($datasources_ordered as $handle) {
             $ds = $datasource_pool[$handle];
             try {
                 $fragment = $ds->render($ParameterOutput);
             } catch (FrontendPageNotFoundException $e) {
                 FrontendPageNotFoundExceptionHandler::render($e);
             }
             if ($fragment instanceof DOMDocument && !is_null($fragment->documentElement)) {
                 $node = $Document->importNode($fragment->documentElement, true);
                 $root->appendChild($node);
             }
         }
     }
     if ($ParameterOutput->length() > 0) {
         foreach ($ParameterOutput as $p) {
             $Parameters->{$p->key} = $p->value;
         }
     }
     ####
     # Delegate: FrontendParamsPostResolve
     # Description: Access to the resolved param pool, including additional parameters provided by Data Source outputs
     # Global: Yes
     Extension::notify('FrontendParamsPostResolve', '/frontend/', array('params' => $Parameters));
     $element = $Document->createElement('parameters');
     $root->appendChild($element);
     foreach ($Parameters as $key => $parameter) {
         if (is_array($parameter->value) && count($parameter->value) > 1) {
             $p = $Document->createElement($key);
             $p->setAttribute('value', (string) $parameter);
             foreach ($parameter->value as $v) {
                 $p->appendChild($Document->createElement('item', (string) $v));
             }
             $element->appendChild($p);
         } else {
             $element->appendChild($Document->createElement($key, (string) $parameter));
         }
     }
     $template = $this->template;
     ####
     # Delegate: FrontendTemplatePreRender
     # Description: Access to the template source, before it is rendered.
     # Global: Yes
     Extension::notify('FrontendTemplatePreRender', '/frontend/', array('document' => $Document, 'template' => &$template));
     $this->template = $template;
     // When the XSLT executes, it uses the CWD as set here
     $cwd = getcwd();
     chdir(WORKSPACE);
     $output = XSLProc::transform($Document, $this->template, XSLProc::XML, $Parameters->toArray(), array());
     chdir($cwd);
     if (XSLProc::hasErrors()) {
         throw new XSLProcException('Transformation Failed');
     }
     /*
     header('Content-Type: text/plain; charset=utf-8');
     $Document->formatOutput = true;
     print $Document->saveXML();
     die();
     */
     return $output;
 }
 protected function __prepareForm()
 {
     $this->editing = isset($this->_context[1]);
     if (!$this->editing) {
         $this->type = $_REQUEST['type'];
         if (is_null($this->type)) {
             $this->type = Symphony::Configuration()->core()->{'default-datasource-type'};
         }
         // Should the default type or the selected type no longer be valid, choose the first available one instead
         if (!in_array($this->type, array_keys($this->types))) {
             $this->type = current(array_keys($this->types));
         }
         foreach ($this->types as $type) {
             if ($type->class != $this->type) {
                 continue;
             }
             $this->datasource = new $type->class();
             $this->datasource->prepare(isset($_POST['fields']) ? $_POST['fields'] : NULL);
             break;
         }
     } else {
         $this->handle = $this->_context[1];
         // Status message:
         $callback = Administration::instance()->getPageCallback();
         if (isset($callback['flag']) && !is_null($callback['flag'])) {
             $this->status = $callback['flag'];
         }
         $this->datasource = Datasource::loadFromHandle($this->handle);
         $this->type = $this->datasource->getType();
         $this->datasource->prepare(isset($_POST['fields']) ? $_POST['fields'] : NULL);
         if (!$this->datasource->allowEditorToParse()) {
             redirect(ADMIN_URL . '/blueprints/datasources/info/' . $this->handle . '/');
         }
     }
 }
 public function delete($datasource)
 {
     /*
     	TODO:
     	Upon deletion of the event, views need to be updated to remove
     	it's associated with the event
     */
     if (!$datasource instanceof DataSource) {
         $datasource = Datasource::loadFromHandle($datasource);
     }
     $handle = $datasource->handle;
     if (!$datasource->allowEditorToParse()) {
         throw new DataSourceException(__('Datasource cannot be deleted, the Editor does not have permission.'));
     }
     return General::deleteFile(DATASOURCES . "/{$handle}.php");
 }
 public function buildOutput()
 {
     $ParameterOutput = new Register();
     $root = $this->document->documentElement;
     $this->buildContextXML($root);
     $datasources = $events = array();
     $events_wrapper = $this->document->createElement('events');
     $root->appendChild($events_wrapper);
     if (is_array($this->about()->{'events'}) && !empty($this->about()->{'events'})) {
         $events = $this->about()->{'events'};
     }
     if (is_array($this->about()->{'data-sources'}) && !empty($this->about()->{'data-sources'})) {
         $datasources = $this->about()->{'data-sources'};
     }
     ####
     # Delegate: FrontendEventsAppend
     # Description: Append additional Events.
     # Global: Yes
     Extension::notify('FrontendEventsAppend', '/frontend/', array('events' => &$events));
     if (!empty($events)) {
         $postdata = General::getPostData();
         $events_ordered = array();
         foreach ($events as $handle) {
             $events_ordered[] = Event::loadFromHandle($handle);
         }
         uasort($events_ordered, array($this, '__cbSortEventsByPriority'));
         foreach ($events_ordered as $e) {
             if (!$e->canTrigger($postdata)) {
                 continue;
             }
             $fragment = $e->trigger($ParameterOutput, $postdata);
             if ($fragment instanceof DOMDocument && !is_null($fragment->documentElement)) {
                 $node = $this->document->importNode($fragment->documentElement, true);
                 $events_wrapper->appendChild($node);
             }
         }
     }
     ####
     # Delegate: FrontendDataSourceAppend
     # Description: Append additional DataSources.
     # Global: Yes
     Extension::notify('FrontendDataSourcesAppend', '/frontend/', array('datasources' => &$datasources));
     //	Find dependancies and order accordingly
     $datasource_pool = array();
     $dependency_list = array();
     $datasources_ordered = array();
     $all_dependencies = array();
     foreach ($datasources as $handle) {
         $datasource_pool[$handle] = Datasource::loadFromHandle($handle);
         $dependency_list[$handle] = $datasource_pool[$handle]->parameters()->dependencies;
     }
     $datasources_ordered = General::dependenciesSort($dependency_list);
     $data = $this->document->createElement('data');
     if (!empty($datasources_ordered)) {
         foreach ($datasources_ordered as $handle) {
             $ds = $datasource_pool[$handle];
             try {
                 $fragment = $ds->render($ParameterOutput);
             } catch (FrontendPageNotFoundException $e) {
                 FrontendPageNotFoundExceptionHandler::render($e);
             }
             if ($fragment instanceof DOMDocument && !is_null($fragment->documentElement)) {
                 $node = $this->document->importNode($fragment->documentElement, true);
                 $data->appendChild($node);
             }
         }
     }
     $root->appendChild($data);
     /*
     			if($ParameterOutput->length() > 0){
     				foreach($ParameterOutput as $p){
     					$Parameters->{$p->key} = $p->value;
     				}
     			}
     
     			####
     			# Delegate: FrontendParamsPostResolve
     			# Description: Access to the resolved param pool, including additional parameters provided by Data Source outputs
     			# Global: Yes
     			Extension::notify('FrontendParamsPostResolve', '/frontend/', array('params' => $Parameters));
     
     
     			####
     			# Delegate: FrontendTemplatePreRender
     			# Description: Access to the template source, before it is rendered.
     			# Global: Yes
     			Extension::notify(
     				'FrontendTemplatePreRender', '/frontend/', array(
     					'document'	=> $Document,
     					'template'	=> &$template
     				)
     			);
     */
     return $this->transform();
 }