public function execute(array &$param_pool = null)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     try {
         $filePath = $this->getJSONFilePath();
         if (file_exists($filePath)) {
             $fileString = @file_get_contents($filePath);
             $json = @json_decode($fileString, true);
             if (is_array($json)) {
                 $this->decode($result, $json);
             } else {
                 throw new Exception(__('Could not read json from %s', array($filePath)));
             }
         } else {
             throw new Exception(__('File %s not found', array($filePath)));
         }
     } catch (FrontendPageNotFoundException $e) {
         // Work around. This ensures the 404 page is displayed and
         // is not picked up by the default catch() statement below
         FrontendPageNotFoundExceptionHandler::render($e);
     } catch (Exception $e) {
         $result->appendChild(new XMLElement('error', $e->getMessage() . ' on ' . $e->getLine() . ' of file ' . $e->getFile()));
         return $result;
     }
     return $result;
 }
Example #2
0
 public function render(Register $ParameterOutput)
 {
     $doc = new XMLDocument();
     $root = $doc->createElement($this->parameters()->{'root-element'});
     try {
         $static = new XMLDocument();
         $node = $static->loadXML($this->parameters()->xml);
         $root->appendChild($doc->importNode($static->documentElement, true));
     } catch (FrontendPageNotFoundException $error) {
         FrontendPageNotFoundExceptionHandler::render($error);
     } catch (Exception $error) {
         $root->appendChild($doc->createElement('error', General::sanitize($error->getMessage())));
     }
     $doc->appendChild($root);
     return $doc;
 }
 public function grab(&$param_pool = NULL)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     try {
         include TOOLKIT . '/data-sources/datasource.section.php';
     } catch (FrontendPageNotFoundException $e) {
         // Work around. This ensures the 404 page is displayed and
         // is not picked up by the default catch() statement below
         FrontendPageNotFoundExceptionHandler::render($e);
     } catch (Exception $e) {
         $result->appendChild(new XMLElement('error', $e->getMessage()));
         return $result;
     }
     if ($this->_force_empty_result) {
         $result = $this->emptyXMLSet();
     }
     return $result;
 }
 public function execute(array &$param_pool = null)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     try {
         $result = parent::execute($param_pool);
     } catch (FrontendPageNotFoundException $e) {
         // Work around. This ensures the 404 page is displayed and
         // is not picked up by the default catch() statement below
         FrontendPageNotFoundExceptionHandler::render($e);
     } catch (Exception $e) {
         $result->appendChild(new XMLElement('error', $e->getMessage() . ' on ' . $e->getLine() . ' of file ' . $e->getFile()));
         return $result;
     }
     if ($this->_force_empty_result) {
         $result = $this->emptyXMLSet();
     }
     return $result;
 }
 public function grab(&$param_pool = NULL)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     try {
         $result = "<site-sections>\r\n\t\t  <section branch=\"parent\">\r\n\t\t    <title lowercase=\"menus\" handle=\"menus\">Menus</title>\r\n\t\t    <type lowercase=\"menu\" handle=\"menu\">Menu</type>\r\n\t\t    <form method=\"post\" action=\"\" enctype=\"multipart/form-data\">\r\n\t\t      <input name=\"MAX_FILE_SIZE\" type=\"hidden\" value=\"5242880\" />\r\n\t\t      <label class=\"show\">Title\r\n\t\t        <input name=\"fields[title]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label class=\"show\">Description\r\n\t\t        <textarea name=\"fields[description]\" rows=\"15\" cols=\"50\"></textarea>\r\n\t\t      </label>\r\n\t\t      <label>Deleted\r\n\t\t        <input name=\"fields[deleted]\" type=\"checkbox\" />\r\n\t\t      </label>\r\n\t\t      <input name=\"action[publish-menu]\" type=\"submit\" value=\"Submit\" />\r\n\t\t    </form>\r\n\t\t  </section>\r\n\t\t  <section branch=\"self\">\r\n\t\t    <title lowercase=\"sections\" handle=\"sections\">Sections</title>\r\n\t\t    <type lowercase=\"section\" handle=\"section\">Section</type>\r\n\t\t    <form method=\"post\" action=\"\" enctype=\"multipart/form-data\">\r\n\t\t      <input name=\"MAX_FILE_SIZE\" type=\"hidden\" value=\"5242880\" />\r\n\t\t      <label class=\"show\">Title\r\n\t\t        <input name=\"fields[title]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label class=\"show\">Menu\r\n\t\t        <select name=\"fields[menu]\" class=\"section-link\"/>\r\n\t\t      </label>\r\n\t\t      <label class=\"show\">URL\r\n\t\t        <input name=\"fields[url]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label class=\"show\">Sort\r\n\t\t        <input name=\"fields[sort]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label>Heading\r\n\t\t        <input name=\"fields[heading]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label>Description\r\n\t\t        <textarea name=\"fields[description]\" rows=\"8\" cols=\"50\"></textarea>\r\n\t\t      </label>\r\n\t\t      <label>Body\r\n\t\t        <textarea name=\"fields[body]\" rows=\"16\" cols=\"50\"></textarea>\r\n\t\t      </label>\r\n\t\t      <label>Deleted\r\n\t\t        <input name=\"fields[deleted]\" type=\"checkbox\" />\r\n\t\t      </label>\r\n\t\t      <input name=\"action[publish-section]\" type=\"submit\" value=\"Submit\" />\r\n\t\t    </form>\r\n\t\t  </section>\r\n\t\t  <section branch=\"child\">\r\n\t\t    <title lowercase=\"pages\" handle=\"pages\">Pages</title>\r\n\t\t    <type lowercase=\"page\" handle=\"page\">Page</type>\r\n\t\t    <form method=\"post\" action=\"\" enctype=\"multipart/form-data\">\r\n\t\t      <input name=\"MAX_FILE_SIZE\" type=\"hidden\" value=\"5242880\" />\r\n\t\t      <label class=\"show\">Title\r\n\t\t        <input name=\"fields[title]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label class=\"show\">Section\r\n\t\t        <select name=\"fields[section]\" class=\"section-link\"/>\r\n\t\t      </label>\r\n\t\t      <label class=\"show\">URL\r\n\t\t        <input name=\"fields[url]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label class=\"show\">Sort\r\n\t\t        <input name=\"fields[sort]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label>Heading\r\n\t\t        <input name=\"fields[heading]\" type=\"text\" />\r\n\t\t      </label>\r\n\t\t      <label>Description\r\n\t\t        <textarea name=\"fields[description]\" rows=\"8\" cols=\"50\"></textarea>\r\n\t\t      </label>\r\n\t\t      <label>Body\r\n\t\t        <textarea name=\"fields[body]\" rows=\"16\" cols=\"50\"></textarea>\r\n\t\t      </label>\r\n\t\t      <label>Deleted\r\n\t\t        <input name=\"fields[deleted]\" type=\"checkbox\" />\r\n\t\t      </label>\r\n\t\t      <input name=\"action[publish-page]\" type=\"submit\" value=\"Submit\" />\r\n\t\t    </form>\r\n\t\t  </section>\r\n\t\t</site-sections>";
     } catch (FrontendPageNotFoundException $e) {
         // Work around. This ensures the 404 page is displayed and
         // is not picked up by the default catch() statement below
         FrontendPageNotFoundExceptionHandler::render($e);
     } catch (Exception $e) {
         $result->appendChild(new XMLElement('error', $e->getMessage()));
         return $result;
     }
     if ($this->_force_empty_result) {
         $result = $this->emptyXMLSet();
     }
     return $result;
 }
 public function grab(&$param_pool = NULL)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     try {
         $extension = $this->_Parent->ExtensionManager->create('section_schemas');
         $extension->getSectionSchema($result, $this->getSource());
     } catch (FrontendPageNotFoundException $e) {
         // Work around. This ensures the 404 page is displayed and
         // is not picked up by the default catch() statement below
         FrontendPageNotFoundExceptionHandler::render($e);
     } catch (Exception $e) {
         $result->appendChild(new XMLElement('error', $e->getMessage()));
         return $result;
     }
     if ($this->_force_empty_result) {
         $result = $this->emptyXMLSet();
     }
     return $result;
 }
 public function execute(array &$param_pool = null)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     if (isset($_GET['page'])) {
         $this->dsParamSTARTPAGE = $_GET['page'];
     }
     $this->dsParamLIMIT = Symphony::Configuration()->get('re-index-per-page', 'search_index');
     try {
         $result = parent::execute($param_pool);
     } catch (FrontendPageNotFoundException $e) {
         // Work around. This ensures the 404 page is displayed and
         // is not picked up by the default catch() statement below
         FrontendPageNotFoundExceptionHandler::render($e);
     } catch (Exception $e) {
         $result->appendChild(new XMLElement('error', $e->getMessage() . ' on ' . $e->getLine() . ' of file ' . $e->getFile()));
         return $result;
     }
     if ($this->_force_empty_result) {
         $result = $this->emptyXMLSet();
     }
     return $result;
 }
Example #8
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;
 }
 /**
  * Given an array of all the Datasources for this page, sort them into the
  * correct execution order and append the Datasource results to the
  * page XML. If the Datasource provides any parameters, they will be
  * added to the `$env` pool for use by other Datasources and eventual
  * inclusion into the page parameters.
  *
  * @param string $datasources
  *  A string of Datasource's attached to this page, comma separated.
  * @param XMLElement $wrapper
  *  The XMLElement to append the Datasource results to. Datasource
  *  results are contained in a root XMLElement that is the handlised
  *  version of their name.
  * @param array $params
  *  Any params to automatically add to the `$env` pool, by default this
  *  is an empty array. It looks like Symphony does not utilise this parameter
  *  at all
  */
 public function processDatasources($datasources, XMLElement &$wrapper, array $params = array())
 {
     if (trim($datasources) == '') {
         return;
     }
     $datasources = preg_split('/,\\s*/i', $datasources, -1, PREG_SPLIT_NO_EMPTY);
     $datasources = array_map('trim', $datasources);
     if (!is_array($datasources) || empty($datasources)) {
         return;
     }
     $this->_env['pool'] = $params;
     $pool = $params;
     $dependencies = array();
     foreach ($datasources as $handle) {
         $pool[$handle] = DatasourceManager::create($handle, array(), false);
         $dependencies[$handle] = $pool[$handle]->getDependencies();
     }
     $dsOrder = $this->__findDatasourceOrder($dependencies);
     foreach ($dsOrder as $handle) {
         Symphony::Profiler()->seed();
         $queries = Symphony::Database()->queryCount();
         // default to no XML
         $xml = null;
         $ds = $pool[$handle];
         // Handle redirect on empty setting correctly RE: #1539
         try {
             $ds->processParameters(array('env' => $this->_env, 'param' => $this->_param));
         } catch (FrontendPageNotFoundException $e) {
             // Work around. This ensures the 404 page is displayed and
             // is not picked up by the default catch() statement below
             FrontendPageNotFoundExceptionHandler::render($e);
         }
         /**
          * Allows extensions to execute the data source themselves (e.g. for caching)
          * and providing their own output XML instead
          *
          * @since Symphony 2.3
          * @delegate DataSourcePreExecute
          * @param string $context
          * '/frontend/'
          * @param DataSource $datasource
          *  The Datasource object
          * @param mixed $xml
          *  The XML output of the data source. Can be an `XMLElement` or string.
          * @param array $param_pool
          *  The existing param pool including output parameters of any previous data sources
          */
         Symphony::ExtensionManager()->notifyMembers('DataSourcePreExecute', '/frontend/', array('datasource' => &$ds, 'xml' => &$xml, 'param_pool' => &$this->_env['pool']));
         // if the XML is still null, an extension has not run the data source, so run normally
         if (is_null($xml)) {
             $xml = $ds->grab($this->_env['pool']);
         }
         if ($xml) {
             /**
              * After the datasource has executed, either by itself or via the
              * `DataSourcePreExecute` delegate, and if the `$xml` variable is truthy,
              * this delegate allows extensions to modify the output XML and parameter pool
              *
              * @since Symphony 2.3
              * @delegate DataSourcePostExecute
              * @param string $context
              * '/frontend/'
              * @param DataSource $datasource
              *  The Datasource object
              * @param mixed $xml
              *  The XML output of the data source. Can be an `XMLElement` or string.
              * @param array $param_pool
              *  The existing param pool including output parameters of any previous data sources
              */
             Symphony::ExtensionManager()->notifyMembers('DataSourcePostExecute', '/frontend/', array('datasource' => $ds, 'xml' => &$xml, 'param_pool' => &$this->_env['pool']));
             if ($xml instanceof XMLElement) {
                 $wrapper->appendChild($xml);
             } else {
                 $wrapper->setValue($wrapper->getValue() . PHP_EOL . '	  ' . trim($xml));
             }
         }
         $queries = Symphony::Database()->queryCount() - $queries;
         Symphony::Profiler()->sample($handle, PROFILE_LAP, 'Datasource', $queries);
         unset($ds);
     }
 }
Example #10
0
 public function render(Register $ParameterOutput)
 {
     $result = new XMLDocument();
     $root = $result->createElement($this->parameters()->{'root-element'});
     try {
         $filter_parent = isset($this->parameters()->parent) && $this->parameters()->parent != "";
         $filter_type = isset($this->parameters()->type) && $this->parameters()->type != "";
         if ($filter_parent && $filter_type) {
             $filtered_by_parent = new ViewIterator('/' . $this->parameters()->parent . '/');
             $iterator = array();
             foreach ($filtered_by_parent as $v) {
                 if (@in_array($type, $v->types)) {
                     $iterator[$v->guid] = $v;
                 }
             }
         } else {
             if ($filter_parent) {
                 $iterator = new ViewIterator('/' . $this->parameters()->parent . '/', false);
             } else {
                 if ($filter_type) {
                     $iterator = View::findFromType($this->parameters()->type);
                 } else {
                     $iterator = new ViewIterator(null, false);
                 }
             }
         }
         if (count($iterator) <= 0) {
             throw new DatasourceException("No views found.");
         } else {
             foreach ($iterator as $index => $view) {
                 if ($filter_parent) {
                     $view = $view->parent();
                 }
                 $node = $this->__buildPageXML($view);
                 if (!is_null($node)) {
                     $root->appendChild($result->importNode($node, true));
                 }
             }
         }
     } catch (FrontendPageNotFoundException $error) {
         FrontendPageNotFoundExceptionHandler::render($error);
     } catch (Exception $error) {
         $root->appendChild($result->createElement('error', General::sanitize($error->getMessage())));
     }
     $result->appendChild($root);
     return $result;
 }
 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();
 }
 /**
  * Executes the given query and returns target_handle or false if no match
  *
  * @param string $query
  * @param int    &$last_parent
  * @param string $target_handle - $target_handle desired
  *
  * @static
  *
  * @return mixed - Translated handle or false if no handle found.
  */
 private static function _getPageHandle($query, &$last_parent, $target_handle)
 {
     try {
         $page = Symphony::Database()->fetch($query);
     } catch (DatabaseException $e) {
         //table column "$lhandle" doesn't exist. redirect to 404.
         if ($e->getDatabaseErrorCode() == 1054) {
             FrontendPageNotFoundExceptionHandler::render($e);
         } else {
             throw $e;
         }
     }
     // page handle exists, store it
     if (!empty($page) && $last_parent == $page[0]['parent']) {
         $last_parent = $page[0]['id'];
         return $page[0][$target_handle];
     }
     return false;
 }