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`");
 }
Esempio n. 2
0
 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 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);
 }
 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);
                     }
                 }
             }
         }
     }
 }
Esempio 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);
 }
 public function flushCache($context)
 {
     $this->__fetchSectionsFromContext($context);
     $cacheDir = CACHE . '/cacheabledatasource/';
     try {
         foreach (DatasourceManager::listAll() as $ds) {
             if (!in_array($ds['source'], $this->_sectionsToFlush)) {
                 continue;
             }
             $cache = glob($cacheDir . $ds['handle'] . '_*.xml');
             if (empty($cache)) {
                 continue;
             }
             foreach ($cache as $file) {
                 unlink($file);
             }
         }
     } catch (Exception $e) {
         Symphony::Log()->writeToLog(date('d.m.y H:i:s') . ' > CacheableDatasource: ' . $e->getMessage(), true);
     }
 }
 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 __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 &ndash; %2$s &ndash; %3$s' : '%1$s &ndash; %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);
 }
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();
?>
&amp;file=<?php 
print $_REQUEST['file'];
?>
" method="post">
  	<h2><?php 
print $_REQUEST['file'];
?>
 <a class="button configure" href="#config" title="Configure master settings">Configure</a></h2>
 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);
 }
 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);
 }
 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 &ndash; %2$s &ndash; %3$s' : '%1$s &ndash; %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'])));
     }
 }
Esempio n. 14
0
 public function __getDataSources()
 {
     $DSManager = new DatasourceManager($this->_Parent);
     return $DSManager->listAll();
 }
    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 &ndash; %2$s &ndash; %3$s' : '%1$s &ndash; %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 __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);
 }
Esempio 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;
     }
 }
 function view()
 {
     $this->setPageType('form');
     $this->addStylesheetToHead(URL . '/extensions/pages_editor_minimal/assets/screen.css', 'screen', 1200);
     $fields = array();
     if (!($page_id = $this->_context[0])) {
         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[1])) {
         switch ($this->_context[1]) {
             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'];
     } else {
         $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");
     }
     $title = $fields['title'];
     if (trim($title) == '') {
         $title = $existing['title'];
     }
     $this->setTitle(__($title ? '%1$s &ndash; %2$s &ndash; %3$s' : '%1$s &ndash; %2$s', array(__('Symphony'), __('Pages'), $title)));
     #			$this->appendSubheading(($title ? $title : __('Untitled')));
     $label = Widget::Label(__('Title'));
     $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title'])));
     $this->Form->appendChild(isset($this->_errors['title']) ? $this->wrapFormElementWithError($label, $this->_errors['title']) : $label);
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'primary');
     $group = new XMLElement('div');
     $group->setAttribute('class', '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);
     $fieldset->appendChild($group);
     $this->Form->appendChild($fieldset);
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'secondary');
     $label = Widget::Label(__('URL Handle'));
     $label->appendChild(Widget::Input('fields[handle]', $fields['handle']));
     $fieldset->appendChild(isset($this->_errors['handle']) ? $this->wrapFormElementWithError($label, $this->_errors['handle']) : $label);
     $pages = $this->_Parent->Database->fetch("SELECT * FROM `tbl_pages` 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));
     $fieldset->appendChild($label);
     $label = Widget::Label(__('URL Parameters'));
     $label->appendChild(Widget::Input('fields[params]', $fields['params']));
     $fieldset->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);
     $fieldset->appendChild($div3);
     $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');
     			
     				$i = 0;
     				foreach($utilities as $util){
     					$li = new XMLElement('li');
     
     					if ($i++ % 2 != 1) {
     						$li->setAttribute('class', 'odd');
     					}
     
     					$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]', __('Save Changes'), 'submit', array('accesskey' => 's')));
     $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);
 }
Esempio n. 19
0
    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 &ndash; Shrimp Rules' . ($this->_editing ? ' &ndash; ' . $this->_fields['name'] : null));
        $this->appendSubheading("<a href=\"{$this->_uri}/rules/\">Rules</a> &mdash; " . ($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&#8217;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);
    }
 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 &ndash; Email Templates') . ($this->_editing ? ' &ndash; ' . $this->_fields['name'] : null));
     $this->appendSubheading("<a href=\"{$this->_uri}/templates/\">Templates</a> &mdash; " . ($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);
 }
 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;
 }