public function __viewIndex() { $this->_driver = $this->_Parent->ExtensionManager->create('section_schemas'); $this->setPageType('form'); $this->setTitle('Symphony – Section Schema data sources'); $this->appendSubheading('Section Schema data sources'); $container = new XMLElement('fieldset'); $container->setAttribute('class', 'settings'); $container->appendChild(new XMLElement('legend', 'Sections')); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $sm = new SectionManager($this->_Parent); $sections = $sm->fetch(); $options = array(); $dsm = new DatasourceManager($this->_Parent); $datasources = $dsm->listAll(); foreach ($sections as $section) { $selected = in_array('section_schema_' . str_replace('-', '_', $section->_data['handle']), array_keys($datasources)); $options[] = array($section->_data['handle'], $selected, $section->_data['name']); } $section = Widget::Label('Create data sources for these sections:'); $section->appendChild(Widget::Select('sections[]', $options, array('multiple' => 'multiple'))); $group->appendChild($section); $container->appendChild($group); $this->Form->appendChild($container); //--------------------------------------------------------------------- $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $attr = array('accesskey' => 's'); $div->appendChild(Widget::Input('action[save]', 'Save Changes', 'submit', $attr)); $this->Form->appendChild($div); }
public function uninstall() { //CREATE THE HORRIBLE FILTER STRING $this->dsFilter = ' //PREVIEW LINK EXTENSION: Remove Filters' . PHP_EOL; $this->dsFilter .= ' if (!strpos($_SERVER[‘HTTP_USER_AGENT’],"Googlebot")) {' . PHP_EOL; $this->dsFilter .= ' if(sha1($_GET["entryid"]) == $_GET["key"]) {' . PHP_EOL; $this->dsFilter .= ' $filters = $this->dsParamFILTERS;' . PHP_EOL; $this->dsFilter .= ' foreach($filters as $key=>$filter) {' . PHP_EOL; $this->dsFilter .= ' unset($this->dsParamFILTERS[$key]);' . PHP_EOL; $this->dsFilter .= ' }' . PHP_EOL; $this->dsFilter .= ' $this->dsParamFILTERS["id"] = $_GET["entryid"];' . PHP_EOL; $this->dsFilter .= ' }' . PHP_EOL; $this->dsFilter .= ' }'; //Loop through all datasources and remove the preview code if present. if (!isset(self::$datasourceManager)) { self::$datasourceManager = new DatasourceManager(Symphony::Engine()); } $dses = self::$datasourceManager->listAll(); foreach ($dses as $ds) { $file = self::$datasourceManager->__getDriverPath($ds['handle']); //FIRST GET FILE CONTENTS $current_content = file_get_contents($file); //THEN REMOVE FILTER CODE $new_content = str_replace(PHP_EOL . PHP_EOL . $this->dsFilter, '', $current_content); //THEN REPALCE FILE CONTENTS file_put_contents($file, $new_content); } //DROP THE DB TABLE $this->_Parent->Database->query("DROP TABLE `tbl_fields_preview_url`"); }
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); }
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'; } }
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); }
public function __viewIndexDSNames($context) { $DSManager = new DatasourceManager($this->_Parent); $datasources = $DSManager->listAll(); $options = array(); foreach ($datasources as $datasource) { $selected = $this->_driver->isDSNameSelected($datasource['handle']); $options[] = array($datasource['handle'], $selected, $datasource['name']); } $section = Widget::Label('Selected'); $section->appendChild(Widget::Select('settings[ds-names][]', $options, array('multiple' => 'multiple'))); $context->appendChild($section); }
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'])); } } } } }
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; }
/** * Changes the source of navigation datasources. * * @static * * @param string $mode - flag for datasource status. */ public static function editAllNavDssTo($mode) { $datasources = array_keys(DatasourceManager::listAll()); if (is_array($datasources) && !empty($datasources)) { foreach ($datasources as $value) { $filename = WORKSPACE . '/data-sources/data.' . $value . '.php'; if (is_file($filename) && is_writable($filename)) { $old_content = file_get_contents($filename); if (self::_isDsTypeNavigation($old_content)) { if (method_exists(get_class(), "setNavDsTo{$mode}")) { $new_content = call_user_func(array(self, "setNavDsTo{$mode}"), $old_content); General::writeFile($filename, $new_content); } } } } } }
/** * 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); } }
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 – %2$s – %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('<', '<', $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); */ }
public function __viewEdit() { $this->addStylesheetToHead(URL . '/extensions/emailtemplatefilter/assets/templates.css', 'screen', 1000); // Status: ----------------------------------------------------------- if (!$this->_valid) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } // Status message: if ($this->_status) { $action = null; switch ($this->_status) { case 'saved': $action = '%1$s updated at %2$s. <a href="%3$s">Create another?</a> <a href="%4$s">View all %5$s</a>'; break; case 'created': $action = '%1$s created at %2$s. <a href="%3$s">Create another?</a> <a href="%4$s">View all %5$s</a>'; break; } if ($action) { $this->pageAlert(__($action, array(__('Template'), DateTimeObj::get(__SYM_TIME_FORMAT__), URL . '/symphony/extension/emailtemplatefilter/templates/new/', URL . '/symphony/extension/emailtemplatefilter/templates/', __('Templates'))), Alert::SUCCESS); } } // Edit: if ($this->_action == 'edit') { if ($this->_template > 0) { $row = $this->_Parent->Database->fetchRow(0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\te.*\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_etf_templates` AS e\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\te.id = {$this->_template}\n\t\t\t\t\t"); if (!empty($row)) { $this->_fields = $row; } else { $this->_editing = false; } } } // Header: ------------------------------------------------------------ $this->setPageType('form'); $this->setTitle(__('Symphony – Email Templates') . ($this->_editing ? ' – ' . $this->_fields['name'] : null)); $this->appendSubheading("<a href=\"{$this->_uri}/templates/\">Templates</a> — " . ($this->_editing ? $this->_fields['name'] : __('Untitled'))); // Form: -------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); if (!empty($this->_fields['id'])) { $fieldset->appendChild(Widget::Input("fields[id]", $this->_fields['id'], 'hidden')); } $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize(@$this->_fields['name']))); if (isset($this->_errors['name'])) { $label = Widget::wrapFormElementWithError($label, $this->_errors['name']); } $fieldset->appendChild($label); // Datasources -------------------------------------------------------- $DSManager = new DatasourceManager($this->_Parent); $datasources = $DSManager->listAll(); $handles = explode(',', $this->_fields['datasources']); $options = array(); foreach ($datasources as $about) { $handle = $about['handle']; $selected = in_array($handle, $handles); $options[] = array($handle, $selected, $about['name']); } $label = Widget::Label(__('Datasources')); $label->appendChild(Widget::Select("fields[datasources][]", $options, array('multiple' => 'multiple'))); $help = new XMLElement('p'); $help->setAttribute('class', 'help'); $help->setValue(__('The parameter <code>%s</code> can be used in the selected datasources to get related data.', array('$etf-entry-id'))); $fieldset->appendChild($label); $fieldset->appendChild($help); $this->Form->appendChild($fieldset); // Conditions ------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Conditions'))); $div = new XMLElement('div'); $div->setAttribute('class', 'subsection'); $div->appendChild(new XMLElement('h3', __('Conditions'))); $ol = new XMLElement('ol'); // Add existing conditions: foreach ($this->_conditions as $sortorder => $condition) { $wrapper = new XMLElement('li'); $this->displayCondition($wrapper, $sortorder, $condition); $ol->appendChild($wrapper); } // Add condition template: $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'template'); $this->displayCondition($wrapper, '-1', array('type' => __('XPath Condition'))); $ol->appendChild($wrapper); $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); // Footer: ------------------------------------------------------------ $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_editing ? __('Save Changes') : __('Create Template'), 'submit', array('accesskey' => 's'))); if ($this->_editing) { $button = new XMLElement('button', 'Delete'); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this template'))); $div->appendChild($button); } $this->Form->appendChild($div); }
<?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 function __viewEdit() { # Status: ----------------------------------------------------------- if (!$this->_valid) { $this->pageAlert(' An error occurred while processing this form. <a href="#error">See below for details.</a>', Alert::ERROR); } // Status message: if ($this->_status) { $action = null; switch ($this->_status) { case 'saved': $action = '%1$s updated at %2$s. <a href="%3$s">Create another?</a> <a href="%4$s">View all %5$s</a>'; break; case 'created': $action = '%1$s created at %2$s. <a href="%3$s">Create another?</a> <a href="%4$s">View all %5$s</a>'; break; } if ($action) { $this->pageAlert(__($action, array(__('Rules'), DateTimeObj::get(__SYM_TIME_FORMAT__), URL . '/symphony/extension/shrimp/rules/new/', URL . '/symphony/extension/shrimp/rules/', __('Rules'))), Alert::SUCCESS); } } // Edit: if ($this->_action == 'edit') { if ($this->_rule > 0) { $row = $this->_Parent->Database->fetchRow(0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\te.*\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_shrimp_rules` AS e\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\te.id = {$this->_rule}\n\t\t\t\t\t"); if (!empty($row)) { $this->_fields = $row; } else { $this->_editing = false; } } } # Header: ------------------------------------------------------------ $this->setPageType('form'); $this->setTitle('Symphony – Shrimp Rules' . ($this->_editing ? ' – ' . $this->_fields['name'] : null)); $this->appendSubheading("<a href=\"{$this->_uri}/rules/\">Rules</a> — " . ($this->_editing ? $this->_fields['section_name'] : 'Untitled')); # Form: -------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Details'))); if (!empty($this->_fields['id'])) { $fieldset->appendChild(Widget::Input("fields[id]", $this->_fields['id'], 'hidden')); } # Section: -------------------------------------------------------------- $label = Widget::Label(__('Section')); $sections = $this->_driver->getSections($this->_fields['section_id']); $options = array(); foreach ($sections as $section) { $selected = $this->_fields['section_id'] == $section['id'] ? true : false; $options[] = array($section['id'], $selected, $section['name']); } $label = Widget::Label(__('Section')); $label->appendChild(Widget::Select("fields[section_id]", $options)); $fieldset->appendChild($label); # Redirect: -------------------------------------------------------------- $label = Widget::Label(__('Redirect')); $label->appendChild(Widget::Input('fields[redirect]', General::sanitize(@$this->_fields['redirect']))); if (isset($this->_errors['redirect'])) { $label = Widget::wrapFormElementWithError($label, $this->_errors['redirect']); } $help = new XMLElement('p'); $help->setAttribute('class', 'help'); $help->setValue('To access the XML, use XPath expressions: <code>{datasource/entry/field-one}/static-text/{datasource/entry/field-two}</code>. You can also use the <code>{$root}</code> for your site URL or <code>{system:id}</code> if you don’t need a datasource.'); $fieldset->appendChild($label); $fieldset->appendChild($help); # Datasources -------------------------------------------------------- $DSManager = new DatasourceManager($this->_Parent); $datasources = $DSManager->listAll(); $handles = explode(',', $this->_fields['datasources']); $options = array(); foreach ($datasources as $about) { $handle = $about['handle']; $selected = in_array($handle, $handles); $options[] = array($handle, $selected, $about['name']); } $label = Widget::Label(__('Datasources')); $label->appendChild(Widget::Select("fields[datasources][]", $options, array('multiple' => 'multiple'))); $help = new XMLElement('p'); $help->setAttribute('class', 'help'); $help->setValue(__('The parameter <code>%s</code> can be used in the selected datasources to get related data.', array('$shrimp-entry-id'))); $fieldset->appendChild($label); $fieldset->appendChild($help); $this->Form->appendChild($fieldset); // Footer: ------------------------------------------------------------ $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_editing ? 'Save Changes' : 'Create Rule', 'submit', array('accesskey' => 's'))); if ($this->_editing) { $button = new XMLElement('button', 'Delete'); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => 'Delete this rule')); $div->appendChild($button); } $this->Form->appendChild($div); }
$date = $Admin->getDateObj(); if (defined("__SYM_ENTRY_MISSINGFIELDS__")) { $Admin->pageAlert("required", array(@implode(", ", $required)), false, 'error'); } if (isset($_GET['_f'])) { switch ($_GET['_f']) { case "saved": $Admin->pageAlert("saved-time", array("Master", date("h:i:sa", $date->get(true, false)))); break; } } if (!empty($_POST)) { $fields = $_POST['fields']; } $fields['body'] = General::sanitize($fields['body']); $DSM = new DatasourceManager(array('parent' => &$Admin)); $datasources = $DSM->listAll(); $EM = new EventManager(array('parent' => &$Admin)); $events = $EM->listAll(); ?> <form action="<?php print $Admin->getCurrentPageURL(); ?> &file=<?php print $_REQUEST['file']; ?> " method="post"> <h2><?php print $_REQUEST['file']; ?>
public function __viewIndexDSNames($context) { $datasources = DatasourceManager::listAll(); $options = array(); foreach ($datasources as $datasource) { $selected = $this->driver->isDSNameSelected($datasource['handle']); $options[] = array($datasource['handle'], $selected, $datasource['name']); } $section = Widget::Label(__('Selected')); $section->setAttribute('class', 'column'); $section->appendChild(Widget::Select('settings[ds-names][]', $options, array('multiple' => 'multiple'))); $context->appendChild($section); }
function view() { $this->appendSubheading(__('Components')); $utilities = General::listStructure(UTILITIES, array('xsl'), false, 'asc', UTILITIES); $utilities = $utilities['filelist']; $ul = new XMLElement('ul'); $ul->setAttribute('id', 'components'); $ul->setAttribute('class', 'triple group'); ### EVENTS ### $EventManager = new EventManager($this->_Parent); $events = $EventManager->listAll(); $li = new XMLElement('li'); $h3 = new XMLElement('h3', __('Events')); $h3->appendChild(Widget::Anchor(__('Create New'), URL . '/symphony/blueprints/events/new/', __('Create a new event'), 'create button')); $li->appendChild($h3); $list = new XMLElement('ul'); $list->setSelfClosingTag(false); if (is_array($events) && !empty($events)) { foreach ($events as $e) { $item = new XMLElement('li'); $item->appendChild(Widget::Anchor($e['name'], URL . '/symphony/blueprints/events/' . ($e['can_parse'] ? 'edit' : 'info') . '/' . strtolower($e['handle']) . '/', 'event.' . $e['handle'] . '.php')); $item->setAttribute('class', 'external'); $list->appendChild($item); } } $li->appendChild($list); $ul->appendChild($li); ###### ### DATASOURCES ### $DSManager = new DatasourceManager($this->_Parent); $datasources = $DSManager->listAll(); $li = new XMLElement('li'); $h3 = new XMLElement('h3', __('Data Sources')); $h3->appendChild(Widget::Anchor(__('Create New'), URL . '/symphony/blueprints/datasources/new/', __('Create a new data source'), 'create button')); $li->appendChild($h3); $list = new XMLElement('ul'); $list->setSelfClosingTag(false); if (is_array($datasources) && !empty($datasources)) { foreach ($datasources as $ds) { $item = new XMLElement('li'); if ($ds['can_parse']) { $item->appendChild(Widget::Anchor($ds['name'], URL . '/symphony/blueprints/datasources/edit/' . strtolower($ds['handle']) . '/', 'data.' . $ds['handle'] . '.php')); } else { $item->appendChild(Widget::Anchor($ds['name'], URL . '/symphony/blueprints/datasources/info/' . strtolower($ds['handle']) . '/', 'data.' . $ds['handle'] . '.php')); } $list->appendChild($item); } } $li->appendChild($list); $ul->appendChild($li); ###### ### UTILITIES ### $li = new XMLElement('li'); $h3 = new XMLElement('h3', __('Utilities')); $h3->appendChild(Widget::Anchor(__('Create New'), URL . '/symphony/blueprints/utilities/new/', __('Create a new utility'), 'create button')); $li->appendChild($h3); $list = new XMLElement('ul'); $list->setSelfClosingTag(false); if (is_array($utilities) && !empty($utilities)) { foreach ($utilities as $u) { $item = new XMLElement('li'); $item->appendChild(Widget::Anchor($u, URL . '/symphony/blueprints/utilities/edit/' . str_replace('.xsl', '', $u) . '/')); $list->appendChild($item); } } $li->appendChild($list); $ul->appendChild($li); ###### $this->Form->appendChild($ul); }
/** * 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); } }
/** * 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); } }
public function __viewEdit() { $this->setPageType('form'); $fields = array(); $nesting = Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes'; // Verify page exists: if ($this->_context[0] == 'edit') { if (!($page_id = $this->_context[1])) { redirect(SYMPHONY_URL . '/blueprints/pages/'); } $existing = Symphony::Database()->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tp.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_pages` AS p\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tp.id = '{$page_id}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t"); if (!$existing) { Administration::instance()->errorPageNotFound(); } } // Status message: $flag = $this->_context[2]; if (isset($flag)) { if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $link_suffix = "?parent=" . $_REQUEST['parent']; } elseif ($nesting == true && isset($existing) && !is_null($existing['parent'])) { $link_suffix = '?parent=' . $existing['parent']; } switch ($flag) { case 'saved': $this->pageAlert(__('Page updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Pages</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/pages/new/' . $link_suffix, SYMPHONY_URL . '/blueprints/pages/' . $link_suffix)), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Page created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Pages</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/pages/new/' . $link_suffix, SYMPHONY_URL . '/blueprints/pages/' . $link_suffix)), Alert::SUCCESS); break; } } // Find values: if (isset($_POST['fields'])) { $fields = $_POST['fields']; } elseif ($this->_context[0] == 'edit') { $fields = $existing; $types = Symphony::Database()->fetchCol('type', "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tp.type\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_pages_types` AS p\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tp.page_id = '{$page_id}'\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\tp.type ASC\n\t\t\t\t"); $fields['type'] = @implode(', ', $types); $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); } elseif (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $fields['parent'] = $_REQUEST['parent']; } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Pages'), $title))); if ($existing) { $template_name = $fields['handle']; if ($existing['parent']) { $parents = $this->__getParent($existing['parent']); $template_name = $parents . '_' . $fields['handle']; } $this->appendSubheading(__($title ? $title : __('Untitled')), Widget::Anchor(__('Edit Template'), SYMPHONY_URL . '/blueprints/pages/template/' . $template_name, __('Edit Page Template'), 'button', NULL, array('accesskey' => 't'))); } else { $this->appendSubheading($title ? $title : __('Untitled')); } // Title -------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Settings'))); $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); if (isset($this->_errors['title'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['title']); } $fieldset->appendChild($label); // Handle ------------------------------------------------------------- $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $column = new XMLElement('div'); $label = Widget::Label(__('URL Handle')); $label->appendChild(Widget::Input('fields[handle]', $fields['handle'])); if (isset($this->_errors['handle'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['handle']); } $column->appendChild($label); // Parent --------------------------------------------------------- $label = Widget::Label(__('Parent Page')); $pages = Symphony::Database()->fetch("\n\t\t\t\tSELECT\n\t\t\t\t\tp.*\n\t\t\t\tFROM\n\t\t\t\t\t`tbl_pages` AS p\n\t\t\t\tWHERE\n\t\t\t\t\tp.id != '{$page_id}'\n\t\t\t\tORDER BY\n\t\t\t\t\tp.title ASC\n\t\t\t"); $options = array(array('', false, '/')); if (is_array($pages) && !empty($pages)) { if (!function_exists('__compare_pages')) { function __compare_pages($a, $b) { return strnatcasecmp($a[2], $b[2]); } } foreach ($pages as $page) { $options[] = array($page['id'], $fields['parent'] == $page['id'], '/' . Administration::instance()->resolvePagePath($page['id'])); } usort($options, '__compare_pages'); } $label->appendChild(Widget::Select('fields[parent]', $options)); $column->appendChild($label); $group->appendChild($column); // Parameters --------------------------------------------------------- $column = new XMLElement('div'); $label = Widget::Label(__('URL Parameters')); $label->appendChild(Widget::Input('fields[params]', $fields['params'])); $column->appendChild($label); // Type ----------------------------------------------------------- $label = Widget::Label(__('Page Type')); $label->appendChild(Widget::Input('fields[type]', $fields['type'])); if (isset($this->_errors['type'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['type']); } $column->appendChild($label); $tags = new XMLElement('ul'); $tags->setAttribute('class', 'tags'); if ($types = $this->__fetchAvailablePageTypes()) { foreach ($types as $type) { $tags->appendChild(new XMLElement('li', $type)); } } $column->appendChild($tags); $group->appendChild($column); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Events ------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Resources'))); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Events')); $manager = new EventManager($this->_Parent); $events = $manager->listAll(); $options = array(); if (is_array($events) && !empty($events)) { if (!is_array($fields['events'])) { $fields['events'] = array(); } foreach ($events as $name => $about) { $options[] = array($name, in_array($name, $fields['events']), $about['name']); } } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); // Data Sources ------------------------------------------------------- $label = Widget::Label(__('Data Sources')); $manager = new DatasourceManager($this->_Parent); $datasources = $manager->listAll(); $options = array(); if (is_array($datasources) && !empty($datasources)) { if (!is_array($fields['data_sources'])) { $fields['data_sources'] = array(); } foreach ($datasources as $name => $about) { $options[] = array($name, in_array($name, $fields['data_sources']), $about['name']); } } $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Controls ----------------------------------------------------------- /** * After all Page related Fields have been added to the DOM, just before the * actions. * * @delegate AppendPageContent * @param string $context * '/blueprints/pages/' * @param XMLElement $form * @param array $fields * @param array $errors */ Symphony::ExtensionManager()->notifyMembers('AppendPageContent', '/blueprints/pages/', array('form' => &$this->Form, 'fields' => &$fields, 'errors' => $this->_errors)); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this page'), 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this page?'))); $div->appendChild($button); } $this->Form->appendChild($div); if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $this->Form->appendChild(new XMLElement('input', NULL, array('type' => 'hidden', 'name' => 'parent', 'value' => $_REQUEST['parent']))); } }
public function __viewInfo() { $this->setPageType('form'); $datasource = DatasourceManager::create($this->_context[1], array(), false); $about = $datasource->about(); $this->setTitle(__('%1$s – %2$s – %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('<', '<', $example) . '</code>')); $fieldset->appendChild($p); } } break; } if ($fieldset) { $fieldset->setAttribute('class', 'settings'); $this->Form->appendChild($fieldset); } } }
/** * `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 formatElementItem($activity, $fallback = FALSE) { switch ($activity['item_type']) { // Pages and Page Templates case 'pages': // Is is a Page Template? $is_template = !is_numeric($activity['item_id']); // Fetch the page from the DB $page = Symphony::Database()->fetch(' SELECT `title` FROM `tbl_pages` WHERE `' . ($is_template ? 'handle' : 'id') . '` = "' . $activity['item_id'] . '"'); // If the page no longer exists, use the fallback description if (empty($page)) { $item = $activity['fallback_description']; } elseif ($is_template) { $item = __(' the %1s page %2s', array($page[0]['title'], $fallback ? __('template') : Widget::Anchor(__('template'), URL . '/symphony/blueprints/pages/template/' . $activity['item_id'])->generate())); // Or if it was the page config, build that description } else { $item = __(' the %1s page', array($fallback ? $page[0]['title'] : Widget::Anchor($page[0]['title'], URL . '/symphony/blueprints/pages/edit/' . $activity['item_id'])->generate())); } break; case "events": // Grab the event info $handle = EventManager::__getHandleFromFilename($activity['item_id']); $about = EventManager::about($handle); // If the event no longer exists, use the fallback description if (empty($about)) { $item = $activity['fallback_description']; } else { $item = __(' the %1s event', array($fallback ? $about['name'] : Widget::Anchor($about['name'], URL . '/symphony/blueprints/events/edit/' . $handle)->generate())); } break; case "datasources": // Grab the DS info $handle = DatasourceManager::__getHandleFromFilename($activity['item_id']); $about = DatasourceManager::about($handle); // If the DS no longer exists, use the fallback description if (empty($about)) { $item = $activity['fallback_description']; } else { $item = __(' the %1s data source', array($fallback ? $about['name'] : Widget::Anchor($about['name'], URL . '/symphony/blueprints/datasources/edit/' . $handle)->generate())); } break; case "utilities": // If the utility no longer exists, use the fallback description if (!file_exists(UTILITIES . '/' . $activity['item_id'])) { $item = $activity['fallback_description']; } else { $item = __(' the %1s utility', array($fallback ? $activity['item_id'] : Widget::Anchor($activity['item_id'], URL . '/symphony/blueprints/utilities/edit/' . str_replace('.xsl', '', $activity['item_id']))->generate())); } break; case "sections": // Grab the section info $section = SectionManager::fetch($activity['item_id']); // If the section no longer exists, use the fallback description if (!$section instanceof Section) { $item = $activity['fallback_description']; } else { $item = __(' the %1s section', array($fallback ? $section->get('name') : Widget::Anchor($section->get('name'), URL . '/symphony/blueprints/sections/edit/' . $activity['item_id'])->generate())); } break; case "authors": // Grab the author info $author = AuthorManager::fetchByID($activity['item_id']); // If the author no longer exists, use the fallback description if (!$author instanceof Author) { $item = $activity['fallback_description']; } else { // If the author edited their own record if ($activity['user_id'] == $activity['item_id']) { $item = __(' his/her %1s', array($fallback ? __('author record') : Widget::Anchor(__('author record'), URL . '/symphony/system/authors/edit/' . $activity['item_id'])->generate())); } else { $item = __(' the author record for %1s', array($fallback ? $author->getFullName() : Widget::Anchor($author->getFullName(), URL . '/symphony/system/authors/edit/' . $activity['item_id'])->generate())); } } break; case "preferences": $item = __(' the %s', array(Widget::Anchor(__('system preferences'), URL . '/symphony/system/preferences')->generate())); break; case "maintenance-mode": $item = __(' maintenance mode'); break; case "extensions": try { $about = ExtensionManager::about($activity['item_id']); } catch (Exception $e) { $about = NULL; } if (empty($about)) { $item = $activity['fallback_description']; } else { $item = __('the %1s extension', array($about['name'])); } break; case "login": $item = __(' to the back end'); break; case "password-reset": $item = __(' his/her password'); break; default: $item = NULL; break; } return $item; }
function __form() { $this->setPageType('form'); $fields = array(); if ($this->_context[0] == 'edit') { if (!($page_id = $this->_context[1])) { redirect(URL . '/symphony/blueprints/pages/'); } if (!($existing = $this->_Parent->Database->fetchRow(0, "SELECT * FROM `tbl_pages` WHERE `id` = '{$page_id}' LIMIT 1"))) { $this->_Parent->customError(E_USER_ERROR, __('Page not found'), __('The page you requested to edit does not exist.'), false, true, 'error', array('header' => 'HTTP/1.0 404 Not Found')); } } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Page updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Pages</a>', array(DateTimeObj::get(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/pages/new/', URL . '/symphony/blueprints/pages/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Page created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Pages</a>', array(DateTimeObj::get(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/pages/new/', URL . '/symphony/blueprints/pages/')), Alert::SUCCESS); break; } } if (isset($_POST['fields'])) { $fields = $_POST['fields']; } elseif ($this->_context[0] == 'edit') { $fields = $existing; $types = $this->_Parent->Database->fetchCol('type', "SELECT `type` FROM `tbl_pages_types` WHERE page_id = '{$page_id}' ORDER BY `type` ASC"); $fields['type'] = @implode(', ', $types); $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); $fields['body'] = @file_get_contents(PAGES . '/' . trim(str_replace('/', '_', $fields['path'] . '_' . $fields['handle']), '_') . ".xsl"); } else { $fields['body'] = '<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> <xsl:template match="/"> </xsl:template> </xsl:stylesheet>'; } $title = $this->_context[0] == 'edit' ? $fields['title'] : NULL; if (trim($title) == '') { $title = $existing['title']; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Pages'), $title))); $this->appendSubheading($title ? $title : __('Untitled')); $div = new XMLElement('div'); $div->setAttribute('id', 'configure'); $div->appendChild(new XMLElement('h3', __('URL Settings'))); $group = new XMLElement('div'); $group->setAttribute('class', 'triple group'); $pages = $this->_Parent->Database->fetch("SELECT * FROM `tbl_pages` " . ($this->_context[0] == 'edit' ? "WHERE `id` != '{$page_id}' " : '') . "ORDER BY `title` ASC"); $label = Widget::Label(__('Parent Page')); $options = array(array('', false, '/')); if (is_array($pages) and !empty($pages)) { if (!function_exists('__compare_pages')) { function __compare_pages($a, $b) { return strnatcasecmp($a[2], $b[2]); } } foreach ($pages as $page) { $options[] = array($page['id'], $fields['parent'] == $page['id'], '/' . $this->_Parent->resolvePagePath($page['id'])); } usort($options, '__compare_pages'); } $label->appendChild(Widget::Select('fields[parent]', $options)); $group->appendChild($label); $label = Widget::Label(__('URL Handle')); $label->appendChild(Widget::Input('fields[handle]', $fields['handle'])); $group->appendChild(isset($this->_errors['handle']) ? $this->wrapFormElementWithError($label, $this->_errors['handle']) : $label); $label = Widget::Label(__('URL Parameters')); $label->appendChild(Widget::Input('fields[params]', $fields['params'])); $group->appendChild($label); $div->appendChild($group); $div->appendChild(new XMLElement('h3', __('Page Metadata'))); $group = new XMLElement('div'); $group->setAttribute('class', 'triple group'); $label = Widget::Label(__('Events')); $EventManager = new EventManager($this->_Parent); $events = $EventManager->listAll(); $options = array(); if (is_array($events) && !empty($events)) { foreach ($events as $name => $about) { $options[] = array($name, @in_array($name, $fields['events']), $about['name']); } } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $label = Widget::Label(__('Data Sources')); $DSManager = new DatasourceManager($this->_Parent); $datasources = $DSManager->listAll(); $options = array(); if (is_array($datasources) && !empty($datasources)) { foreach ($datasources as $name => $about) { $options[] = array($name, @in_array($name, $fields['data_sources']), $about['name']); } } $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $div3 = new XMLElement('div'); $label = Widget::Label(__('Page Type')); $label->appendChild(Widget::Input('fields[type]', $fields['type'])); $div3->appendChild(isset($this->_errors['type']) ? $this->wrapFormElementWithError($label, $this->_errors['type']) : $label); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); if ($types = $this->__fetchAvailablePageTypes()) { foreach ($types as $type) { $ul->appendChild(new XMLElement('li', $type)); } } $div3->appendChild($ul); $group->appendChild($div3); $div->appendChild($group); $this->Form->appendChild($div); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary'); $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); $fieldset->appendChild(isset($this->_errors['title']) ? $this->wrapFormElementWithError($label, $this->_errors['title']) : $label); $label = Widget::Label(__('Body')); $label->appendChild(Widget::Textarea('fields[body]', '25', '50', General::sanitize($fields['body']), array('class' => 'code'))); $fieldset->appendChild(isset($this->_errors['body']) ? $this->wrapFormElementWithError($label, $this->_errors['body']) : $label); $this->Form->appendChild($fieldset); $utilities = General::listStructure(UTILITIES, array('xsl'), false, 'asc', UTILITIES); $utilities = $utilities['filelist']; if (is_array($utilities) && !empty($utilities)) { $div = new XMLElement('div'); $div->setAttribute('class', 'secondary'); $h3 = new XMLElement('h3', __('Utilities')); $h3->setAttribute('class', 'label'); $div->appendChild($h3); $ul = new XMLElement('ul'); $ul->setAttribute('id', 'utilities'); foreach ($utilities as $util) { $li = new XMLElement('li'); $li->appendChild(Widget::Anchor($util, URL . '/symphony/blueprints/utilities/edit/' . str_replace('.xsl', '', $util) . '/', NULL)); $ul->appendChild($li); } $div->appendChild($ul); $this->Form->appendChild($div); } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this page'))); $div->appendChild($button); } $this->Form->appendChild($div); }
public function __viewEdit() { $this->setPageType('form'); $fields = array(); // Verify page exists: if ($this->_context[0] == 'edit') { if (!($page_id = $this->_context[1])) { redirect(URL . '/symphony/blueprints/pages/'); } $existing = $this->_Parent->Database->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tp.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_pages` AS p\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tp.id = '{$page_id}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t"); if (!$existing) { $this->_Parent->customError(E_USER_ERROR, __('Page not found'), __('The page you requested to edit does not exist.'), false, true, 'error', array('header' => 'HTTP/1.0 404 Not Found')); } } // Status message: if (isset($this->_context[2])) { $this->pageAlert(__('%s %s at %s. <a href="%s">Create another?</a> <a href="%s">View all %s</a>', array(__('Page'), $this->_context[2] == 'saved' ? 'updated' : 'created', DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/pages/new/', URL . '/symphony/blueprints/pages/', __('Pages'))), Alert::SUCCESS); } // Find values: if (isset($_POST['fields'])) { $fields = $_POST['fields']; } else { if ($this->_context[0] == 'edit') { $fields = $existing; $types = $this->_Parent->Database->fetchCol('type', "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tp.type\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_pages_types` AS p\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tp.page_id = '{$page_id}'\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\tp.type ASC\n\t\t\t\t"); $fields['type'] = @implode(', ', $types); $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); } } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Pages'), $title))); $this->appendSubheading($title ? $title : __('Untitled')); // Title -------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Settings'))); $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); if (isset($this->_errors['title'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['title']); } $fieldset->appendChild($label); // Handle ------------------------------------------------------------- $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $column = new XMLElement('div'); $label = Widget::Label(__('URL Handle')); $label->appendChild(Widget::Input('fields[handle]', $fields['handle'])); if (isset($this->_errors['handle'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['handle']); } $column->appendChild($label); // Parent --------------------------------------------------------- $label = Widget::Label(__('Parent Page')); $pages = $this->_Parent->Database->fetch("\n\t\t\t\tSELECT\n\t\t\t\t\tp.*\n\t\t\t\tFROM\n\t\t\t\t\t`tbl_pages` AS p\n\t\t\t\tWHERE\n\t\t\t\t\tp.id != '{$page_id}'\n\t\t\t\tORDER BY\n\t\t\t\t\tp.title ASC\n\t\t\t"); $options = array(array('', false, '/')); if (is_array($pages) && !empty($pages)) { if (!function_exists('__compare_pages')) { function __compare_pages($a, $b) { return strnatcasecmp($a[2], $b[2]); } } foreach ($pages as $page) { $options[] = array($page['id'], $fields['parent'] == $page['id'], '/' . $this->_Parent->resolvePagePath($page['id'])); } usort($options, '__compare_pages'); } $label->appendChild(Widget::Select('fields[parent]', $options)); $column->appendChild($label); $group->appendChild($column); // Parameters --------------------------------------------------------- $column = new XMLElement('div'); $label = Widget::Label(__('URL Parameters')); $label->appendChild(Widget::Input('fields[params]', $fields['params'])); $column->appendChild($label); // Type ----------------------------------------------------------- $label = Widget::Label(__('Page Type')); $label->appendChild(Widget::Input('fields[type]', $fields['type'])); if (isset($this->_errors['type'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['type']); } $column->appendChild($label); $tags = new XMLElement('ul'); $tags->setAttribute('class', 'tags'); if ($types = $this->__fetchAvailablePageTypes()) { foreach ($types as $type) { $tags->appendChild(new XMLElement('li', $type)); } } $column->appendChild($tags); $group->appendChild($column); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Events ------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Resources'))); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Events')); $manager = new EventManager($this->_Parent); $events = $manager->listAll(); $options = array(); if (is_array($events) && !empty($events)) { foreach ($events as $name => $about) { $options[] = array($name, @in_array($name, $fields['events']), $about['name']); } } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); // Data Sources ------------------------------------------------------- $label = Widget::Label(__('Data Sources')); $manager = new DatasourceManager($this->_Parent); $datasources = $manager->listAll(); $options = array(); if (is_array($datasources) && !empty($datasources)) { foreach ($datasources as $name => $about) { $options[] = array($name, @in_array($name, $fields['data_sources']), $about['name']); } } $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Controls ----------------------------------------------------------- $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this page'))); $div->appendChild($button); } $this->Form->appendChild($div); }
public function __viewInfo() { $this->setPageType('form'); $datasource = DatasourceManager::create($this->_context[1], array(), false); $about = $datasource->about(); $this->setTitle(__('%1$s – %2$s – %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('<', '<', $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); } }
/** * Check if $dbinfo provided the connection details for a Yioop/SeekQuarry * database. If it does provide a valid db connection but no data then try * to recreate the database from the default copy stored in /data dir. * * @param array $dbinfo has fields for DBMS, DB_USER, DB_PASSWORD, DB_HOST * and DB_NAME * @param array $skip_list an array of table or index names not to bother * creating or copying * @return bool returns true if can connect to/create a valid database; * returns false otherwise */ function migrateDatabaseIfNecessary($dbinfo, $skip_list = array()) { $test_dbm = $this->testDatabaseManager($dbinfo); if ($test_dbm === false || $test_dbm === true) { return $test_dbm; } $this->initializeSql($test_dbm, $dbinfo); $copy_tables = array_diff(array_keys($this->create_statements), $skip_list); if (!($create_ok = $this->createDatabaseTables($test_dbm, $dbinfo))) { return false; } require_once BASE_DIR . "/models/datasources/sqlite3_manager.php"; $default_dbm = new Sqlite3Manager(); $default_dbm->connect("", "", "", BASE_DIR . "/data/default.db"); if (!$default_dbm) { return false; } foreach ($copy_tables as $table_or_index) { if ($table_or_index != "CURRENT_WEB_INDEX" && stristr($table_or_index, "_INDEX")) { continue; } if (!DatasourceManager::copyTable($table_or_index, $default_dbm, $table_or_index, $test_dbm)) { return false; } } if (stristr($dbinfo["DB_HOST"], "pgsql") !== false) { /* For postgres count initial values of SERIAL sequences will be screwed up unless do */ $auto_tables = array("ACTIVITY" => "ACTIVITY_ID", "GROUP_ITEM" => "GROUP_ITEM_ID", "GROUP_PAGE" => "GROUP_PAGE_ID", "GROUPS" => "GROUP_ID", "LOCALE" => "LOCALE_ID", "ROLE" => "ROLE_ID", "TRANSLATION" => "TRANSLATION_ID", "USERS" => "USER_ID"); foreach ($auto_tables as $table => $auto_column) { $sql = "SELECT MAX({$auto_column}) AS NUM FROM {$table}"; $result = $test_dbm->execute($sql); $row = $test_dbm->fetchArray($result); $next = $row['NUM']; $sequence = strtolower("{$table}_{$auto_column}_seq"); $sql = "SELECT setval('{$sequence}', {$next})"; $test_dbm->execute($sql); } } return true; }
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; } }