public function processDependencies(array $params = array())
 {
     $datasources = $this->getDependencies();
     if (!is_array($datasources) || empty($datasources)) {
         return;
     }
     $datasources = array_map(create_function('$a', "return str_replace('\$ds-', '', \$a);"), $datasources);
     $datasources = array_map(create_function('$a', "return str_replace('-', '_', \$a);"), $datasources);
     $env = array('today' => DateTimeObj::get('Y-m-d'), 'current-time' => DateTimeObj::get('H:i'), 'this-year' => DateTimeObj::get('Y'), 'this-month' => DateTimeObj::get('m'), 'this-day' => DateTimeObj::get('d'), 'timezone' => DateTimeObj::get('P'), 'enm-newsletter-id' => $this->newsletter_id);
     $this->_env['param'] = $env;
     $this->_env['env']['pool'] = $params;
     $dependencies = array();
     foreach ($datasources as $handle) {
         $profiler = Symphony::Profiler();
         $profiler->seed();
         $pool[$handle] =& DatasourceManager::create($handle, NULL, false);
         $dependencies[$handle] = $pool[$handle]->getDependencies();
     }
     $dsOrder = $this->__findDatasourceOrder($dependencies);
     foreach ($dsOrder as $handle) {
         $ds = $pool[$handle];
         $ds->processParameters($this->_env);
         $ds->grab($this->_env['env']['pool']);
         unset($ds);
     }
     $this->processParameters($this->_env);
 }
 public function view()
 {
     $params = array('{$today}', '{$current-time}', '{$this-year}', '{$this-month}', '{$this-day}', '{$timezone}', '{$website-name}', '{$page-title}', '{$root}', '{$workspace}', '{$root-page}', '{$current-page}', '{$current-page-id}', '{$current-path}', '{$current-query-string}', '{$current-url}', '{$cookie-username}', '{$cookie-pass}', '{$page-types}', '{$upload-limit}');
     // Get page parameters
     $pages = PageManager::fetch(true, array('params'));
     foreach ($pages as $key => $pageparams) {
         if (empty($pageparams['params'])) {
             continue;
         }
         $pageparams = explode('/', $pageparams['params']);
         foreach ($pageparams as $pageparam) {
             $param = '{$' . $pageparam . '}';
             if (!in_array($param, $params)) {
                 $params[] = $param;
             }
         }
     }
     // Get Data Sources output parameters
     $datasources = DatasourceManager::listAll();
     foreach ($datasources as $datasource) {
         $current = DatasourceManager::create($datasource['handle'], array(), false);
         $prefix = '{$ds-' . Lang::createHandle($datasource['name']) . '.';
         $suffix = '}';
         // Get parameters
         if (is_array($current->dsParamPARAMOUTPUT)) {
             foreach ($current->dsParamPARAMOUTPUT as $id => $param) {
                 $params[] = $prefix . $param . $suffix;
             }
         }
     }
     sort($params);
     $this->_Result = json_encode($params);
 }
 /**
  * Returns the source value for display in the Datasources index
  *
  * @param string $file
  *  The path to the Datasource file
  * @return string
  */
 public static function getSourceColumn($handle)
 {
     $datasource = DatasourceManager::create($handle, array(), false);
     if (isset($datasource->dsParamURL)) {
         return Widget::Anchor(str_replace('http://www.', '', $datasource->dsParamURL), $datasource->dsParamURL);
     } else {
         return 'Remote Datasource';
     }
 }
Exemplo n.º 4
0
 public function addJavaScriptAndCSS()
 {
     $callback = Symphony::Engine()->getPageCallback();
     if ($callback['driver'] != 'blueprintsdatasources' || !is_array($callback['context'])) {
         return;
     }
     // Find data source handle.
     $handle = NULL;
     if ($callback['context'][0] == 'edit' && !empty($callback['context'][1])) {
         $handle = $callback['context'][1];
     }
     // Find current XPath values.
     $parametrisator = array('xslt' => false, 'xpaths' => array());
     if (isset($_POST['parametrisator'])) {
         $parametrisator['xslt'] = $_POST['parametrisator']['xslt'];
         if (isset($_POST['parametrisator']['xpaths']) && isset($_POST['parametrisator']['xpaths']['name'])) {
             $parametrisator['xpaths'] = array_combine($_POST['parametrisator']['xpaths']['name'], $_POST['parametrisator']['xpaths']['xpath']);
         } else {
             $parametrisator['xpaths'] = array();
         }
     } else {
         if (!empty($handle)) {
             $datasourceManager = new DatasourceManager(Symphony::Engine());
             $existing =& $datasourceManager->create($handle, NULL, false);
             if (!empty($existing)) {
                 if (is_array($existing->dsParamParametrisator)) {
                     $parametrisator = $existing->dsParamParametrisator;
                 }
                 if (!empty($existing->dsParamROOTELEMENT)) {
                     $handle = $existing->dsParamROOTELEMENT;
                 }
             }
         }
     }
     // Remove empty values
     $parametrisator['xpaths'] = array_filter($parametrisator['xpaths']);
     // Get list of utilities
     $xsltfile = $parametrisator['xslt'];
     $parametrisator['xslt'] = '<option value="">' . __('Disabled') . '</option>';
     $utilities = General::listStructure(UTILITIES, array('xsl'), false, 'asc', UTILITIES);
     if (is_array($utilities) && is_array($utilities['filelist'])) {
         foreach ($utilities['filelist'] as $utility) {
             $parametrisator['xslt'] .= '<option value="' . $utility . '"' . ($xsltfile == $utility ? ' selected="selected"' : '') . '>' . $utility . '</option>';
         }
     }
     // Let our script know sort and order values.
     Administration::instance()->Page->addElementToHead(new XMLElement('script', "Symphony.Context.add('parametrisator', " . json_encode(array('xslt' => $parametrisator['xslt'], 'xpaths' => $parametrisator['xpaths'], 'handle' => $handle)) . ");", array('type' => 'text/javascript')), 100);
     // Append scripts and styles for field settings pane
     Administration::instance()->Page->addScriptToHead(URL . '/extensions/parametrisator/assets/parametrisator.settings.js', 101, false);
 }
Exemplo n.º 5
0
 private function __getDSParams()
 {
     $params = array();
     $datasources = DatasourceManager::listAll();
     foreach ($datasources as $datasource) {
         $current = DatasourceManager::create($datasource['handle'], array(), false);
         // Get parameters
         if (is_array($current->dsParamPARAMOUTPUT)) {
             foreach ($current->dsParamPARAMOUTPUT as $id => $param) {
                 $params[] = sprintf($this->template, 'ds-' . Lang::createHandle($datasource['name']) . '.' . Lang::createHandle($param));
             }
         }
     }
     return $params;
 }
Exemplo n.º 6
0
 function view()
 {
     $this->setPageType('table');
     $heading = new XMLElement('h2', 'Data Source Cache');
     $this->Form->appendChild($heading);
     $aTableHead = array(array('Data Source', 'col'), array('Cache files', 'col'), array('Cache size', 'col'));
     $dsm = new DatasourceManager($this->_Parent);
     $datasources = $dsm->listAll();
     $cachedata = $this->driver->buildCacheFileList();
     $aTableBody = array();
     if (!is_array($datasources) || empty($datasources)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', NULL, count($aTableHead)))));
     } else {
         $bEven = false;
         foreach ($datasources as $ds) {
             $datasource = $dsm->create($ds['handle']);
             if (isset($datasource->dsParamCACHE) && is_numeric($datasource->dsParamCACHE) && $datasource->dsParamCACHE > 0 && is_numeric($datasource->getSource())) {
                 $name = Widget::TableData($ds['name']);
                 $name->appendChild(Widget::Input("items[{$ds['handle']}]", null, 'checkbox'));
                 $files = Widget::TableData(isset($cachedata[$ds['handle']]['count']) ? $cachedata[$ds['handle']]['count'] : '0');
                 if (isset($cachedata[$ds['handle']]['size'])) {
                     if ($cachedata[$ds['handle']]['size'] < 1024) {
                         $size_str = $cachedata[$ds['handle']]['size'] . "b";
                     } else {
                         $size_str = floor($cachedata[$ds['handle']]['size'] / 1024) . "kb";
                     }
                 } else {
                     $size_str = "0kb";
                 }
                 $size = Widget::TableData($size_str);
                 $aTableBody[] = Widget::TableRow(array($name, $files, $size), $bEven ? 'even' : NULL);
                 $bEven = !$bEven;
             }
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody));
     $this->Form->appendChild($table);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(null, false, __('With Selected...')), array('clear', false, __('Clear Cache')));
     $tableActions->appendChild(Widget::Select('with-selected', $options));
     $tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit'));
     $this->Form->appendChild($tableActions);
 }
 /**
  * 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) {
         Frontend::instance()->Profiler->seed();
         $pool[$handle] =& $this->DatasourceManager->create($handle, NULL, false);
         $dependencies[$handle] = $pool[$handle]->getDependencies();
         unset($ds);
     }
     $dsOrder = $this->__findDatasourceOrder($dependencies);
     foreach ($dsOrder as $handle) {
         Frontend::instance()->Profiler->seed();
         $dbstats = Symphony::Database()->getStatistics();
         $queries = $dbstats['queries'];
         $ds = $pool[$handle];
         $ds->processParameters(array('env' => $this->_env, 'param' => $this->_param));
         if ($xml = $ds->grab($this->_env['pool'])) {
             if (is_object($xml)) {
                 $wrapper->appendChild($xml);
             } else {
                 $wrapper->setValue($wrapper->getValue() . self::CRLF . '	' . trim($xml));
             }
         }
         $dbstats = Symphony::Database()->getStatistics();
         $queries = $dbstats['queries'] - $queries;
         Frontend::instance()->Profiler->sample($handle, PROFILE_LAP, 'Datasource', $queries);
         unset($ds);
     }
 }
Exemplo n.º 8
0
 public function __refresh($context)
 {
     /*
     	Cear the DS cache when its associated Section is edited
     */
     $sm = new SectionManager($this->_Parent);
     $section_handle = Administration::instance()->Page->_context['section_handle'];
     $section_id = $sm->fetchIDFromHandle($section_handle);
     // find all native data sources (not added via Extensions)
     $dsm = new DatasourceManager($this->_Parent);
     $datasources = $dsm->listAll();
     if (is_array($datasources) && !empty($datasources)) {
         foreach ($datasources as $ds) {
             // check they are "Section" DSs and not Dynamic/Static XML, Authors or Navigation
             if (is_numeric($ds['type']) && $ds['type'] == $section_id) {
                 // instantiate the DS class and see if it has caching enabled
                 $datasource = $dsm->create($ds['handle']);
                 if ($datasource->dsParamCACHE) {
                     $this->clearCache(array($ds['handle']));
                 }
             }
         }
     }
 }
 public function __viewInfo()
 {
     $this->setPageType('form');
     $datasource = DatasourceManager::create($this->_context[1], array(), false);
     $about = $datasource->about();
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array($about['name'], __('Data Source'), __('Symphony'))));
     $this->appendSubheading($about['name']);
     $this->Form->setAttribute('id', 'controller');
     $link = $about['author']['name'];
     if (isset($about['author']['website'])) {
         $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
     } elseif (isset($about['author']['email'])) {
         $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
     }
     foreach ($about as $key => $value) {
         $fieldset = NULL;
         switch ($key) {
             case 'author':
                 if ($link) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', __('Author')));
                     $fieldset->appendChild(new XMLElement('p', $link->generate(false)));
                 }
                 break;
             case 'version':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', __('Version')));
                 if (preg_match('/^\\d+(\\.\\d+)*$/', $value)) {
                     $fieldset->appendChild(new XMLElement('p', __('%1$s released on %2$s', array($value, DateTimeObj::format($about['release-date'], __SYM_DATE_FORMAT__)))));
                 } else {
                     $fieldset->appendChild(new XMLElement('p', __('Created by %1$s at %2$s', array($value, DateTimeObj::format($about['release-date'], __SYM_DATE_FORMAT__)))));
                 }
                 break;
             case 'description':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', __('Description')));
                 $fieldset->appendChild(is_object($about['description']) ? $about['description'] : new XMLElement('p', $about['description']));
             case 'example':
                 if (is_callable(array($datasource, 'example'))) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', __('Example XML')));
                     $example = $datasource->example();
                     if (is_object($example)) {
                         $fieldset->appendChild($example);
                     } else {
                         $p = new XMLElement('p');
                         $p->appendChild(new XMLElement('pre', '<code>' . str_replace('<', '&lt;', $example) . '</code>'));
                         $fieldset->appendChild($p);
                     }
                 }
                 break;
         }
         if ($fieldset) {
             $fieldset->setAttribute('class', 'settings');
             $this->Form->appendChild($fieldset);
         }
     }
 }
 function __viewInfo()
 {
     $this->setPageType('form');
     $DSManager = new DatasourceManager($this->_Parent);
     $datasource = $DSManager->create($this->_context[1], NULL, false);
     $about = $datasource->about();
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array(__('Symphony'), __('Data Source'), $about['name'])));
     $this->appendSubheading($about['name']);
     $this->Form->setAttribute('id', 'controller');
     $link = $about['author']['name'];
     if (isset($about['author']['website'])) {
         $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
     } elseif (isset($about['author']['email'])) {
         $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
     }
     foreach ($about as $key => $value) {
         $fieldset = NULL;
         switch ($key) {
             case 'author':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', 'Author'));
                 $fieldset->appendChild(new XMLElement('p', $link->generate(false)));
                 break;
             case 'version':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', 'Version'));
                 $fieldset->appendChild(new XMLElement('p', $value . ', released on ' . DateTimeObj::get(__SYM_DATE_FORMAT__, strtotime($about['release-date']))));
                 break;
             case 'description':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', 'Description'));
                 $fieldset->appendChild(is_object($about['description']) ? $about['description'] : new XMLElement('p', $about['description']));
             case 'example':
                 if (is_callable(array($datasource, 'example'))) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', 'Example XML'));
                     $example = $datasource->example();
                     if (is_object($example)) {
                         $fieldset->appendChild($example);
                     } else {
                         $p = new XMLElement('p');
                         $p->appendChild(new XMLElement('pre', '<code>' . str_replace('<', '&lt;', $example) . '</code>'));
                         $fieldset->appendChild($p);
                     }
                 }
                 break;
         }
         if ($fieldset) {
             $fieldset->setAttribute('class', 'settings');
             $this->Form->appendChild($fieldset);
         }
     }
     /*
     $dl->appendChild(new XMLElement('dt', __('URL Parameters')));
     if(!is_array($about['recognised-url-param']) || empty($about['recognised-url-param'])){
     	$dl->appendChild(new XMLElement('dd', '<code>'.__('None').'</code>'));
     }			
     else{
     	$dd = new XMLElement('dd');
     	$ul = new XMLElement('ul');
     	
     	foreach($about['recognised-url-param'] as $f) $ul->appendChild(new XMLElement('li', '<code>' . $f . '</code>'));
     
     	$dd->appendChild($ul);
     	$dl->appendChild($dd);
     }			
     $fieldset->appendChild($dl);
     */
 }
 /**
  * Returns the source value for display in the Datasources index
  *
  * @param string $file
  *  The path to the Datasource file
  * @return string
  */
 public function getSourceColumn($handle)
 {
     $datasource = DatasourceManager::create($handle, array(), false);
     return 'Section Schema: ' . $datasource->dsParamSECTION;
 }
 /**
  * Fetch associated entries using a custom Data Source
  *
  * @param array $settings
  *  An array of field settings
  * @param array $entry_ids
  *  An array of associated entry ids
  * @return XMLElement
  */
 private function fetchAssociatedEntries($parentsource, $settings, $section_id, $entry_ids = array())
 {
     $childsource = DatasourceManager::create('associations', null, false);
     $childsource->dsParamSOURCE = $settings['section_id'];
     $childsource->dsParamFILTERS['system:id'] = implode($entry_ids, ', ');
     $childsource->dsParamINCLUDEDELEMENTS = $settings['elements'];
     if ($parentsource->dsParamHTMLENCODE === 'yes') {
         $childsource->dsParamHTMLENCODE = 'yes';
     }
     return $childsource->execute();
 }
 public function __viewInfo()
 {
     $this->setPageType('form');
     $datasource = DatasourceManager::create($this->_context[1], array(), false);
     $about = $datasource->about();
     $this->setTitle(__('%1$s &ndash; %2$s &ndash; %3$s', array($about['name'], __('Data Source'), __('Symphony'))));
     $this->appendSubheading($this->_context[0] == 'info' ? $about['name'] : __('Untitled'));
     $this->insertBreadcrumbs(array(Widget::Anchor(__('Data Sources'), SYMPHONY_URL . '/blueprints/datasources/')));
     $this->Form->setAttribute('id', 'controller');
     $link = $about['author']['name'];
     if (isset($about['author']['website'])) {
         $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
     } elseif (isset($about['author']['email'])) {
         $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
     }
     foreach ($about as $key => $value) {
         $fieldset = null;
         switch ($key) {
             case 'author':
                 if ($link) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', __('Author')));
                     $fieldset->appendChild(new XMLElement('p', $link->generate(false)));
                 }
                 break;
             case 'version':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', __('Version')));
                 $release_date = array_key_exists('release-date', $about) ? $about['release-date'] : filemtime(DatasourceManager::__getDriverPath($this->_context[1]));
                 if (preg_match('/^\\d+(\\.\\d+)*$/', $value)) {
                     $fieldset->appendChild(new XMLElement('p', __('%1$s released on %2$s', array($value, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__)))));
                 } else {
                     $fieldset->appendChild(new XMLElement('p', __('Created by %1$s at %2$s', array($value, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__)))));
                 }
                 break;
             case 'description':
                 $fieldset = new XMLElement('fieldset');
                 $fieldset->appendChild(new XMLElement('legend', __('Description')));
                 $fieldset->appendChild(is_object($about['description']) ? $about['description'] : new XMLElement('p', $about['description']));
                 break;
             case 'example':
                 if (is_callable(array($datasource, 'example'))) {
                     $fieldset = new XMLElement('fieldset');
                     $fieldset->appendChild(new XMLElement('legend', __('Example XML')));
                     $example = $datasource->example();
                     if (is_object($example)) {
                         $fieldset->appendChild($example);
                     } else {
                         $p = new XMLElement('p');
                         $p->appendChild(new XMLElement('pre', '<code>' . str_replace('<', '&lt;', $example) . '</code>'));
                         $fieldset->appendChild($p);
                     }
                 }
                 break;
         }
         if ($fieldset) {
             $fieldset->setAttribute('class', 'settings');
             $this->Form->appendChild($fieldset);
         }
     }
     // Display source
     $file = DatasourceManager::__getClassPath($this->_context[1]) . '/data.' . $this->_context[1] . '.php';
     if (file_exists($file)) {
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', __('Source')));
         $source = file_get_contents($file);
         $code = new XMLElement('code', htmlspecialchars($source));
         $pre = new XMLElement('pre');
         $pre->appendChild($code);
         $fieldset->appendChild($pre);
         $this->Form->appendChild($fieldset);
     }
 }
 /**
  * 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) {
         Symphony::Profiler()->seed();
         $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();
         $ds = $pool[$handle];
         $ds->processParameters(array('env' => $this->_env, 'param' => $this->_param));
         // default to no XML
         $xml = NULL;
         /**
          * 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 boolean $datasource
          *  The Datasource object
          * @param mixed $xml
          *  The XML output of the data source. Can be an XMLElement or string.
          * @param mixed $paral_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) {
             if (is_object($xml)) {
                 $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);
     }
 }
Exemplo n.º 15
0
 /**
  * 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);
     }
 }
            $Site->togglePreviewMode();
        }
        #Render the page
        $output = $Site->display(array(), 'TRANSFORMED', false);
        $xml = $Site->buildXML(NULL, NULL, true, false);
        $xsl = $Site->display(array(), "XSL", false);
        #Record the render time
        $profiler->sample("Total Page Render Time");
        break;
    case "datasource":
        $DSM = new DatasourceManager(array('parent' => &$Admin));
        $obXML = new XMLElement("data");
        $obXML->setIncludeHeader(true);
        ##DATASOURCES
        $dsParam = array("indent-depth" => 2, "caching" => false, "indent" => true, "preview" => true);
        $ds =& $DSM->create($page_handle, array('parent' => $this, 'env' => array()));
        $result = $ds->preview($dsParam);
        if (@is_object($result)) {
            $xml = trim($result->generate(true, 0));
        } else {
            $xml = trim($result);
        }
        $page_name = $page_handle;
        $active = "xml";
        if ($xml == "") {
            $output = $xml = $xsl = "No Datasource by the name '{$page_handle}' was found.";
        }
        break;
}
$xml = trim($xml);
$xml = General::sanitize($xml);
Exemplo n.º 17
0
 public function render_panel($context)
 {
     $config = $context['config'];
     switch ($context['type']) {
         case 'datasource_to_table':
             $ds = DatasourceManager::create($config['datasource'], NULL, false);
             if (!$ds) {
                 $context['panel']->appendChild(new XMLElement('div', __('The Data Source with the name <code>%s</code> could not be found.', array($config['datasource']))));
                 return;
             }
             $param_pool = array();
             $xml = $ds->grab($param_pool);
             if (!$xml) {
                 return;
             }
             $xml = $xml->generate();
             require_once TOOLKIT . '/class.xsltprocess.php';
             $proc = new XsltProcess();
             $data = $proc->process($xml, file_get_contents(EXTENSIONS . '/dashboard/lib/datasource-to-table.xsl'));
             $context['panel']->appendChild(new XMLElement('div', $data));
             break;
         case 'rss_reader':
             require_once TOOLKIT . '/class.gateway.php';
             require_once CORE . '/class.cacheable.php';
             $cache_id = md5('rss_reader_cache' . $config['url']);
             $cache = new Cacheable(Administration::instance()->Database());
             $data = $cache->check($cache_id);
             if (!$data) {
                 $ch = new Gateway();
                 $ch->init();
                 $ch->setopt('URL', $config['url']);
                 $ch->setopt('TIMEOUT', 6);
                 $new_data = $ch->exec();
                 $writeToCache = true;
                 if ((int) $config['cache'] > 0) {
                     $cache->write($cache_id, $new_data, $config['cache']);
                 }
                 $xml = $new_data;
                 if (empty($xml) && $data) {
                     $xml = $data['data'];
                 }
             } else {
                 $xml = $data['data'];
             }
             if (!$xml) {
                 $xml = '<error>' . __('Error: could not retrieve panel XML feed.') . '</error>';
             }
             require_once TOOLKIT . '/class.xsltprocess.php';
             $proc = new XsltProcess();
             $data = $proc->process($xml, file_get_contents(EXTENSIONS . '/dashboard/lib/rss-reader.xsl'), array('show' => $config['show']));
             $context['panel']->appendChild(new XMLElement('div', $data));
             break;
         case 'html_block':
             require_once TOOLKIT . '/class.gateway.php';
             require_once CORE . '/class.cacheable.php';
             $cache_id = md5('html_block_' . $config['url']);
             $cache = new Cacheable(Administration::instance()->Database());
             $data = $cache->check($cache_id);
             if (!$data) {
                 $ch = new Gateway();
                 $ch->init();
                 $ch->setopt('URL', $config['url']);
                 $ch->setopt('TIMEOUT', 6);
                 $new_data = $ch->exec();
                 $writeToCache = true;
                 if ((int) $config['cache'] > 0) {
                     $cache->write($cache_id, $new_data, $config['cache']);
                 }
                 $html = $new_data;
                 if (empty($html) && $data) {
                     $html = $data['data'];
                 }
             } else {
                 $html = $data['data'];
             }
             if (!$html) {
                 $html = '<p class="invalid">' . __('Error: could not retrieve panel HTML.') . '</p>';
             }
             $context['panel']->appendChild(new XMLElement('div', $html));
             break;
         case 'symphony_overview':
             $container = new XMLElement('div');
             $dl = new XMLElement('dl');
             $dl->appendChild(new XMLElement('dt', __('Website Name')));
             $dl->appendChild(new XMLElement('dd', Symphony::Configuration()->get('sitename', 'general')));
             $current_version = Symphony::Configuration()->get('version', 'symphony');
             require_once TOOLKIT . '/class.gateway.php';
             $ch = new Gateway();
             $ch->init();
             $ch->setopt('URL', 'https://api.github.com/repos/symphonycms/symphony-2/tags');
             $ch->setopt('TIMEOUT', $timeout);
             $repo_tags = $ch->exec();
             // tags request found
             if (is_array($repo_tags)) {
                 $repo_tags = json_decode($repo_tags);
                 $tags = array();
                 foreach ($repo_tags as $tag) {
                     // remove tags that contain strings
                     if (preg_match('/[a-zA]/i', $tag->name)) {
                         continue;
                     }
                     $tags[] = $tag->name;
                 }
                 natsort($tags);
                 rsort($tags);
                 $latest_version = reset($tags);
             } else {
                 $latest_version = $current_version;
             }
             $needs_update = version_compare($latest_version, $current_version, '>');
             $dl->appendChild(new XMLElement('dt', __('Version')));
             $dl->appendChild(new XMLElement('dd', $current_version . ($needs_update ? ' (<a href="http://getsymphony.com/download/releases/version/' . $latest_version . '/">' . __('Latest is %s', array($latest_version)) . "</a>)" : '')));
             $container->appendChild(new XMLElement('h4', __('Configuration')));
             $container->appendChild($dl);
             $entries = 0;
             foreach (SectionManager::fetch() as $section) {
                 $entries += EntryManager::fetchCount($section->get('id'));
             }
             $dl = new XMLElement('dl');
             $dl->appendChild(new XMLElement('dt', __('Sections')));
             $dl->appendChild(new XMLElement('dd', (string) count(SectionManager::fetch())));
             $dl->appendChild(new XMLElement('dt', __('Entries')));
             $dl->appendChild(new XMLElement('dd', (string) $entries));
             $dl->appendChild(new XMLElement('dt', __('Data Sources')));
             $dl->appendChild(new XMLElement('dd', (string) count(DatasourceManager::listAll())));
             $dl->appendChild(new XMLElement('dt', __('Events')));
             $dl->appendChild(new XMLElement('dd', (string) count(EventManager::listAll())));
             $dl->appendChild(new XMLElement('dt', __('Pages')));
             $dl->appendChild(new XMLElement('dd', (string) count(PageManager::fetch())));
             $container->appendChild(new XMLElement('h4', __('Statistics')));
             $container->appendChild($dl);
             $context['panel']->appendChild($container);
             break;
         case 'markdown_text':
             $formatter = TextformatterManager::create($config['formatter']);
             $html = $formatter->run($config['text']);
             $context['panel']->appendChild(new XMLElement('div', $html));
             break;
     }
 }
 /**
  * `InitaliseAdminPageHead` delegate callback function
  * Appends script assets and context to page head
  *
  * @param mixed $context
  *  Delegate context including page object
  */
 public function initaliseAdminPageHead($context)
 {
     $page = Administration::instance()->Page;
     if (!$page instanceof contentBlueprintsDatasources) {
         return;
     }
     $url_context = $page->getContext();
     if (!in_array($url_context[0], array('new', 'edit'))) {
         return;
     }
     $cache = 0;
     // if editing an existing data source, instantiate the DS object
     // to retrieve the dsParamCACHE property if it exists
     if ($url_context[0] == 'edit') {
         $ds = $url_context[1];
         $dsm = new DatasourceManager(Symphony::Engine());
         $datasource = $dsm->create($ds, null, false);
         $cache = $datasource->dsParamCACHE;
     }
     if (is_null($cache)) {
         $cache = 0;
     }
     Administration::instance()->Page->addElementToHead(new XMLElement('script', "Symphony.Context.add('cacheabledatasource', " . json_encode(array('cache' => isset($_POST['fields']['cache']) ? $_POST['fields']['cache'] : $cache)) . ");", array('type' => 'text/javascript')), time());
     Administration::instance()->Page->addScriptToHead(URL . '/extensions/cacheabledatasource/assets/cacheabledatasource.blueprintsdatasources.js', time());
 }
 public function appendConditionalizer(&$context)
 {
     /*
     			'oPage' => &$this->Page
     */
     $callback = Symphony::Engine()->getPageCallback();
     if ($callback['driver'] != 'blueprintsdatasources' || !is_array($callback['context']) || empty($callback['context'])) {
         return;
     }
     // Find data source handle.
     $handle = NULL;
     if ($callback['context'][0] == 'edit' && !empty($callback['context'][1])) {
         $handle = $callback['context'][1];
     }
     // Find current Expression values.
     $data = '';
     if (isset($_POST['conditionalizer'])) {
         $data = $_POST['conditionalizer'];
     } else {
         if (!empty($handle)) {
             $existing = DatasourceManager::create($handle, NULL, false);
             if (!empty($existing)) {
                 if (isset($existing->dsParamConditionalizer)) {
                     $data = $existing->dsParamConditionalizer;
                 }
                 if (!empty($existing->dsParamROOTELEMENT)) {
                     $handle = $existing->dsParamROOTELEMENT;
                 }
             }
         }
     }
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'settings conditionalizer');
     $fieldset->appendChild(new XMLElement('legend', __('Conditionalizer')));
     $fieldset->appendChild(new XMLElement('script', NULL, array('src' => URL . '/extensions/conditionalizer/assets/conditionalizer.js', 'type' => 'text/javascript')));
     $label = Widget::Label(__('Expression'));
     $label->appendChild(Widget::Textarea('conditionalizer', 6, 50, General::sanitize($data), array('class' => 'code')));
     if (!class_exists('Conditionalizer')) {
         require_once EXTENSIONS . '/conditionalizer/lib/class.conditionalizer.php';
     }
     $e = Conditionalizer::parse($data);
     if (empty($e)) {
         // Strip all parameters just to see if there was invalid expression there or none at all
         $e = preg_replace(array('@{(([^}:]+)|[^}]+?:([^}:]+))?}@i', '@{\\$[^}]+}@i', '@{([^}\\$]+)}@i'), array('{$2$3}', 'yes', '$1'), $data);
         $e = array_map('trim', preg_split('/(?<!\\\\)[,\\+] /', $e, -1, PREG_SPLIT_NO_EMPTY));
         if (!empty($e)) {
             $e = array_diff($e, array('yes', 'no'));
             // Make array non-empty if all values are either 'yes' or 'no', otherwise make it empty to mark wrong syntax
             $e = count($e) > 0 ? array() : array('ok');
         }
     }
     if (empty($e) && !empty($data)) {
         $fieldset->appendChild(Widget::Error($label, __('Invalid syntax')));
     } else {
         $fieldset->appendChild($label);
     }
     // Add list of parameters that may be available.
     $params = Conditionalizer::listParams();
     if (!empty($params)) {
         $optionlist = new XMLElement('ul');
         $optionlist->setAttribute('class', 'tags');
         $optionlist->appendChild(new XMLElement('li', 'yes', array('title' => 'Exact string value')));
         $optionlist->appendChild(new XMLElement('li', 'no', array('title' => 'Exact string value')));
         foreach ($params as $param => $value) {
             $optionlist->appendChild(new XMLElement('li', $param, array('class' => '{' . $param . '}', 'title' => $value ? __('Value of %s returned from another data source', array($value)) : __('Value found in URL path'))));
         }
         $fieldset->appendChild($optionlist);
     }
     $nodes = $context['oPage']->Form->getChildren();
     for ($i = count($nodes) - 1; $i >= 0; $i--) {
         if ($nodes[$i]->getName() == 'div' && preg_match('/(^|\\s)actions(\\s|$)/i', $nodes[$i]->getAttribute('class'))) {
             $context['oPage']->Form->insertChildAt($i, $fieldset);
             break;
         }
     }
 }
<?php

/***
 *
 * Symphony web publishing system
 *
 * Copyright 2004–2006 Twenty One Degrees Pty. Ltd.
 *
 * @version 1.7
 * @licence https://github.com/symphonycms/symphony-1.7/blob/master/LICENCE
 *
 ***/
$DSM = new DatasourceManager(array('parent' => &$Admin));
$oDataSource = $DSM->create($_REQUEST['file']);
$about = $oDataSource->about();
$date = $Admin->getDateObj();
$GLOBALS['pageTitle'] = 'Data Sources > ' . $about['name'];
$link = $about['author']['name'];
if (isset($about['author']['website'])) {
    $link = '<a href="' . General::validateURL($about['author']['website']) . '">' . $about['author']['name'] . '</a>';
} elseif (isset($about['author']['email'])) {
    $link = '<a href="mailto:' . $about['author']['email'] . '">' . $about['author']['name'] . '</a>';
}
?>

<form id="controller" action="/" method="post">
  	<h2><?php 
print $about['name'];
?>
</h2>
	<fieldset>
 public static function listParams()
 {
     $params = array();
     // It's no fun without Symphony
     if (!defined('TOOLKIT') || !class_exists('Symphony') || !Symphony::Database()) {
         return $params;
     }
     // Get page params
     $pages = Symphony::Database()->fetch('SELECT params FROM tbl_pages WHERE params IS NOT NULL');
     if (is_array($pages) && !empty($pages)) {
         foreach ($pages as $page => $data) {
             if ($data = trim($data['params'])) {
                 foreach (explode('/', $data) as $p) {
                     $params['$' . $p] = '';
                 }
             }
         }
     }
     // Get datasource generated params
     if (!class_exists('DatasourceManager')) {
         require_once TOOLKIT . '/class.datasourcemanager.php';
     }
     foreach (DatasourceManager::listAll() as $name => $info) {
         $ds = DatasourceManager::create($name, NULL, false);
         // Support Symphony's section fields
         if (isset($ds->dsParamPARAMOUTPUT) && !empty($ds->dsParamPARAMOUTPUT)) {
             if (!is_array($ds->dsParamPARAMOUTPUT)) {
                 $params['$ds-' . $ds->dsParamROOTELEMENT] = $ds->dsParamPARAMOUTPUT;
             } else {
                 foreach ($ds->dsParamPARAMOUTPUT as $field) {
                     $params['$ds-' . $ds->dsParamROOTELEMENT . '.' . $field] = $field;
                 }
             }
         }
         // Support Parametrisator's xpaths
         if (isset($ds->dsParamParametrisator) && is_array($ds->dsParamParametrisator) && isset($ds->dsParamParametrisator['xpaths'])) {
             foreach ($ds->dsParamParametrisator['xpaths'] as $name => $xpath) {
                 $params['$ds-' . $ds->dsParamROOTELEMENT . '-' . $name] = $name;
             }
         }
     }
     return $params;
 }